VAPoR  0.1
SignificanceMap.h
Go to the documentation of this file.
1 //
2 // $Id: SignificanceMap.h,v 1.5 2012/02/28 18:15:58 ypolius Exp $
3 //
4 
5 #ifndef _SignificanceMap_h_
6 #define _SignificanceMap_h_
7 
8 #include <vector>
9 #include <cassert>
10 #include <vapor/MyBase.h>
11 #include <algorithm>
12 
13 //using namespace std;
14 
15 //#include "MyBase.h"
16 
17 #ifndef BITSPERBYTE
18 #define BITSPERBYTE 8
19 #endif
20 
21 namespace VAPoR {
22 
23 //
33 
34 
36 public:
37 
39 
50  SignificanceMap(size_t nx, size_t ny = 1, size_t nz = 1, size_t nt = 1);
51  SignificanceMap(std::vector <size_t> dims);
52 
53  //
64  //
66  const unsigned char *map, size_t nx, size_t ny=1, size_t nz=1, size_t nt=1
67  );
68  SignificanceMap(const unsigned char *map, std::vector <size_t> dims);
69 
73 
75 
86  int Reshape(std::vector <size_t> dims);
87  int Reshape(size_t nx, size_t ny=1, size_t nz=1, size_t nt=1);
88 
91  void GetShape(std::vector <size_t> &dims) const {dims = _dimsVec;};
92 
109  int Set(size_t idx);
110  int SetXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0);
111 
121  bool inline Test(size_t idx) const;
122  bool inline TestXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0) const;
123 
130  int Clear(size_t idx);
131  int ClearXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0);
132 
135  void Clear();
136 
139  size_t GetNumSignificant() const { return(_sigMapVec.size()); };
140 
152  //
153  int GetCoordinatesXYZT(
154  size_t i, size_t *x, size_t *y=NULL, size_t *z=NULL, size_t *t=NULL
155  ) const;
156  int GetCoordinates(size_t i, size_t *idx) const;
157 
164  //
165  void GetNextEntryRestart();
166 
167 
168  //
181  //
182  int GetNextEntry(
183  size_t *idx
184  );
185  int GetNextEntryXYZT(
186  size_t *x, size_t *y, size_t *z, size_t *t
187  );
188 
195  //
196  static size_t GetMapSize(vector <size_t> dims, size_t num_entries);
197 
211  //
212  size_t GetMapSize(size_t num_entries) const;
213 
214 
221  //
222  size_t GetMapSize() const {
223  return(GetMapSize(GetNumSignificant()));
224  };
225 
231  //
232  void GetMap(const unsigned char **map, size_t *maplen);
233 
240  //
241  void GetMap(unsigned char *map);
242 
243  //
253  //
254  int SetMap(const unsigned char *map);
255 
271  //
272  int Append(const SignificanceMap &smap);
273 
282  //
283  void Invert();
284 
293  //
294  void Sort();
295 
297 
298  friend std::ostream &operator<<(
299  std::ostream &o, const SignificanceMap &sigmap
300  );
301 
302 private:
303 
304  static const int HEADER_SIZE = 64;
305  static const int VDF_VERSION = 2;
306  size_t _nx;
307  size_t _ny;
308  size_t _nz;
309  size_t _nt; // dimensions of map (when # dims < 5)
310 
311  bool _sorted; // true if the map is sorted in ascending order
312 
313  std::vector <size_t> _dimsVec; // Map dimensions
314  size_t _sigMapSize; // product of dimensions (max coordinate index)
315  std::vector<size_t> _sigMapVec; // The signficance map
316 
317  int _bits_per_idx; // # bits needed to encode a coordinate
318  unsigned char *_sigMapEncode; // compactly encoded version of _sigMapVec
319  size_t _sigMapEncodeSize; // size of _sigMapEncode in bytes
320 
321  size_t _idxentry; // Counter for sequential access to sig. map
322 
323  int _SignificanceMap(std::vector <size_t> dims);
324  int _SignificanceMap(
325  const unsigned char *map, std::vector <size_t> dims
326  );
327 
328  static size_t _GetBitsPerIdx(vector <size_t> dims);
329 
330 };
331 
332 
333 bool inline SignificanceMap::Test(size_t idx) const {
334 
335  if (idx > _sigMapSize) return(0); // Invalid coordinate
336 
337  if (_sorted) {
338  return(binary_search(_sigMapVec.begin(), _sigMapVec.end(), idx));
339  }
340 
341  for (size_t i = 0; i<_sigMapVec.size(); i++) {
342  if (_sigMapVec[i] == idx) return(1);
343  }
344  return(0);
345 }
346 
348  size_t x, size_t y, size_t z, size_t t
349 ) const {
350 
351  size_t idx = (t * _nz * _ny * _nx) + (z * _ny * _nx) + (y * _nx) + x;
352 
353  return(this->Test(idx));
354 }
355 
356 
357 }
358 
359 #endif
size_t GetNumSignificant() const
Implements a significance map.
int Reshape(std::vector< size_t > dims)
int GetCoordinatesXYZT(size_t i, size_t *x, size_t *y=NULL, size_t *z=NULL, size_t *t=NULL) const
int GetNextEntry(size_t *idx)
int GetNextEntryXYZT(size_t *x, size_t *y, size_t *z, size_t *t)
int SetXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0)
int ClearXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0)
int Set(size_t idx)
void GetMap(const unsigned char **map, size_t *maplen)
SignificanceMap & operator=(const SignificanceMap &map)
int Append(const SignificanceMap &smap)
bool TestXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0) const
size_t GetMapSize() const
VetsUtil base class.
Definition: MyBase.h:68
void GetShape(std::vector< size_t > &dims) const
bool Test(size_t idx) const
friend std::ostream & operator<<(std::ostream &o, const SignificanceMap &sigmap)
int GetCoordinates(size_t i, size_t *idx) const
int SetMap(const unsigned char *map)