VAPOR3 3.9.4
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 "vapor/VAssert.h"
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
21namespace VAPoR {
22
23//
33
35public:
37
48 SignificanceMap(size_t nx, size_t ny = 1, size_t nz = 1, size_t nt = 1);
49 SignificanceMap(std::vector<size_t> dims);
50
51 //
62 //
63 SignificanceMap(const unsigned char *map, size_t nx, size_t ny = 1, size_t nz = 1, size_t nt = 1);
64 SignificanceMap(const unsigned char *map, std::vector<size_t> dims);
65
69
71
82 int Reshape(std::vector<size_t> dims);
83 int Reshape(size_t nx, size_t ny = 1, size_t nz = 1, size_t nt = 1);
84
87 void GetShape(std::vector<size_t> &dims) const { dims = _dimsVec; };
88
105 int Set(size_t idx);
106 int SetXYZT(size_t x, size_t y = 0, size_t z = 0, size_t t = 0);
107
117 bool inline Test(size_t idx) const;
118 bool inline TestXYZT(size_t x, size_t y = 0, size_t z = 0, size_t t = 0) const;
119
126 int Clear(size_t idx);
127 int ClearXYZT(size_t x, size_t y = 0, size_t z = 0, size_t t = 0);
128
131 void Clear();
132
135 size_t GetNumSignificant() const { return (_sigMapVec.size()); };
136
148 //
149 int GetCoordinatesXYZT(size_t i, size_t *x, size_t *y = NULL, size_t *z = NULL, size_t *t = NULL) const;
150 int GetCoordinates(size_t i, size_t *idx) const;
151
158 //
160
161 //
174 //
175 int GetNextEntry(size_t *idx);
176 int GetNextEntryXYZT(size_t *x, size_t *y, size_t *z, size_t *t);
177
184 //
185 static size_t GetMapSize(vector<size_t> dims, size_t num_entries);
186
200 //
201 size_t GetMapSize(size_t num_entries) const;
202
209 //
210 size_t GetMapSize() const { return (GetMapSize(GetNumSignificant())); };
211
217 //
218 void GetMap(const unsigned char **map, size_t *maplen);
219
226 //
227 void GetMap(unsigned char *map);
228
229 //
239 //
240 int SetMap(const unsigned char *map);
241
257 //
258 int Append(const SignificanceMap &smap);
259
268 //
269 void Invert();
270
279 //
280 void Sort();
281
283
284 friend std::ostream &operator<<(std::ostream &o, const SignificanceMap &sigmap);
285
286private:
287 static const int HEADER_SIZE = 64;
288 static const int VDF_VERSION = 2;
289 size_t _nx;
290 size_t _ny;
291 size_t _nz;
292 size_t _nt; // dimensions of map (when # dims < 5)
293
294 bool _sorted; // true if the map is sorted in ascending order
295
296 std::vector<size_t> _dimsVec; // Map dimensions
297 size_t _sigMapSize; // product of dimensions (max coordinate index)
298 std::vector<size_t> _sigMapVec; // The signficance map
299
300 int _bits_per_idx; // # bits needed to encode a coordinate
301 unsigned char *_sigMapEncode; // compactly encoded version of _sigMapVec
302 size_t _sigMapEncodeSize; // size of _sigMapEncode in bytes
303
304 size_t _idxentry; // Counter for sequential access to sig. map
305
306 int _SignificanceMap(std::vector<size_t> dims);
307 int _SignificanceMap(const unsigned char *map, std::vector<size_t> dims);
308
309 static size_t _GetBitsPerIdx(vector<size_t> dims);
310};
311
312bool inline SignificanceMap::Test(size_t idx) const
313{
314 if (idx > _sigMapSize) return (0); // Invalid coordinate
315
316 if (_sorted) { return (binary_search(_sigMapVec.begin(), _sigMapVec.end(), idx)); }
317
318 for (size_t i = 0; i < _sigMapVec.size(); i++) {
319 if (_sigMapVec[i] == idx) return (1);
320 }
321 return (0);
322}
323
324bool inline SignificanceMap::TestXYZT(size_t x, size_t y, size_t z, size_t t) const
325{
326 size_t idx = (t * _nz * _ny * _nx) + (z * _ny * _nx) + (y * _nx) + x;
327
328 return (this->Test(idx));
329}
330
331} // namespace VAPoR
332
333#endif
Implements a significance map.
size_t GetMapSize() const
int Clear(size_t idx)
int GetNextEntryXYZT(size_t *x, size_t *y, size_t *z, size_t *t)
void GetMap(const unsigned char **map, size_t *maplen)
int Set(size_t idx)
SignificanceMap(size_t nx, size_t ny=1, size_t nz=1, size_t nt=1)
friend std::ostream & operator<<(std::ostream &o, const SignificanceMap &sigmap)
int GetCoordinatesXYZT(size_t i, size_t *x, size_t *y=NULL, size_t *z=NULL, size_t *t=NULL) const
SignificanceMap & operator=(const SignificanceMap &map)
SignificanceMap(std::vector< size_t > dims)
static size_t GetMapSize(vector< size_t > dims, size_t num_entries)
int GetNextEntry(size_t *idx)
int SetMap(const unsigned char *map)
int Reshape(size_t nx, size_t ny=1, size_t nz=1, size_t nt=1)
SignificanceMap(const unsigned char *map, std::vector< size_t > dims)
SignificanceMap(const SignificanceMap &)
void GetMap(unsigned char *map)
size_t GetMapSize(size_t num_entries) const
int Append(const SignificanceMap &smap)
bool TestXYZT(size_t x, size_t y=0, size_t z=0, size_t t=0) const
SignificanceMap(const unsigned char *map, size_t nx, size_t ny=1, size_t nz=1, size_t nt=1)
size_t GetNumSignificant() const
int Reshape(std::vector< size_t > dims)
bool Test(size_t idx) const
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)
void GetShape(std::vector< size_t > &dims) const
int GetCoordinates(size_t i, size_t *idx) const
Wasp base class.
Definition: MyBase.h:67
#define WASP_API
Definition: common.h:74