UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
u3d_data_cube.hpp
1 /* u3d_data_cube.hpp */
2 /* $Id: u3d_data_cube.hpp,v 1.2 2008/09/29 11:15:15 ibadm Exp $ */
3 #ifndef __u3d_data_cube_hpp
4 #define __u3d_data_cube_hpp
5 
6 //#include <vector>
7 #include <map>
8 #include <ios>
9 #include <string.h>
10 
11 #include "u3d_migr.hpp"
12 #include <mix/u3d_progress.hpp>
13 
14 typedef unsigned short ushort;
15 
16 
17 
18 
20 enum PlaneOrient {PT_X, PT_Y, PT_Z};
21 
22 
23 
24 
25 //--------------------------------------------------------------------------------
26 using std::size_t;
27 
28 //--------------------------------------------------------------------------------
30 template<class T>
31 class U3dArray3D {
32 
33  // These two inner classes were made for provide classical access style for 3d arrays with operator[]
34  class InnerArray; // Inner class incapsulates linear array;
35  class SliceAccessor; // Inner class that provide access to specified "squair slice"
36 public:
37 
38 
39 
40  U3dArray3D() :
41  innerArrayAccessor(0, 0 ,0),
42  sliceAccessor(innerArrayAccessor)
43  {}
44 
45 
46  U3dArray3D(size_t width, size_t height, size_t depth) :
47  innerArrayAccessor(width, height, depth),
48  sliceAccessor(innerArrayAccessor)
49  {}
50 
51 
52  U3dArray3D(const U3dArray3D& that) :
53  innerArrayAccessor(that.innerArrayAccessor),
54  sliceAccessor(innerArrayAccessor)
55  {}
56 
57 
58  U3dArray3D& operator=(const U3dArray3D& that)
59  {
60  innerArrayAccessor.~InnerArray();
61  new(&innerArrayAccessor) InnerArray(that.innerArrayAccessor);
62  sliceAccessor.~SliceAccessor();
63  new(&sliceAccessor) SliceAccessor(innerArrayAccessor);
64  }
65 
66 
67  // Classic style access:
68  inline SliceAccessor& operator[](const size_t& slNdx) { return sliceAccessor(slNdx); }
69  inline const SliceAccessor& operator[](const size_t& slNdx) const { return sliceAccessor(slNdx); }
70 
71 
72  // Not classic style access:
73  T& element(size_t i, size_t j, size_t k) {
74  assert(i<innerArrayAccessor.m_width &&
75  j<innerArrayAccessor.m_height &&
76  k<innerArrayAccessor.m_depth);
77  return innerArrayAccessor.m_array[innerArrayAccessor.m_depth*(i*innerArrayAccessor.m_height + j) + k];
78  }
79  const T& element(size_t i, size_t j, size_t k) const {
80  assert(i<innerArrayAccessor.m_width &&
81  j<innerArrayAccessor.m_height &&
82  k<innerArrayAccessor.m_depth);
83  return innerArrayAccessor.m_array[innerArrayAccessor.m_depth*(i*innerArrayAccessor.m_height + j) + k];
84  }
85 
86 
87  // Set new dimensions of array. Old content will be deleted.
88  void setDimensions(size_t width, size_t height, size_t depth) {
89  innerArrayAccessor.~InnerArray();
90  new(&innerArrayAccessor) InnerArray(width, height, depth);
91  sliceAccessor.~SliceAccessor();
92  new(&sliceAccessor) SliceAccessor(innerArrayAccessor);
93  }
94 
95 
96  // Assigns all elements in array to t
97  void assign(T t) {
98  for (size_t i=0; i<innerArrayAccessor.m_size; innerArrayAccessor.m_array[i++] = t);
99  }
100 
101 
102  // Return pointer to inner array
103  T* innerArray() { return innerArrayAccessor.m_array; }
104  const T* innerArray() const { return innerArrayAccessor.m_array; }
105 
106 
107  // returns width*height*depth
108  size_t size() const { return innerArrayAccessor.m_size; }
109 
110 
111  size_t width() const { return innerArrayAccessor.m_width; }
112  size_t height() const { return innerArrayAccessor.m_height;}
113  size_t depth() const { return innerArrayAccessor.m_depth; }
114 
115 
116  void clear() { setDimensions(0,0,0); }
117 
118 
119 private:
120 
121 
122  class InnerArray {
123  public:
124 
125  InnerArray(size_t width, size_t height, size_t depth) :
126  m_width(width), m_height(height), m_depth(depth),
127  m_size(width*height*depth), m_array(new T[m_size])
128  {}
129 
130  InnerArray(const InnerArray& that) :
131  m_width(that.m_width), m_height(that.m_height), m_depth(that.m_depth),
132  m_size(that.m_size), m_array(new T[m_size])
133  {
134  std::copy(that.m_array, that.m_array + that.m_size, m_array);
135  }
136 
137  ~InnerArray() { delete[] m_array; }
138 
139  inline InnerArray& operator()(const size_t& colNum) {
140  offset = colNum*m_depth; return *this;
141  }
142  inline const InnerArray& operator()(const size_t& colNum) const {
143  offset = colNum*m_depth; return *this;
144  }
145  inline T& operator[](const size_t& depthNdx) {
146  assert(depthNdx < m_depth);
147  return m_array[offset+depthNdx];
148  }
149  inline const T& operator[](const size_t& depthNdx) const {
150  assert(depthNdx < m_depth);
151  return m_array[offset+depthNdx];
152  }
153 
154  // private: // No private! U3dArray3D is my best friend!
155  size_t m_width;
156  size_t m_height;
157  size_t m_depth;
158  size_t m_size;
159  T* m_array;
160  mutable size_t offset;
161  };
162 
163 
164 
165 
166  class SliceAccessor {
167  public:
168  SliceAccessor(InnerArray& inArr) : colsPerSlice(inArr.m_height), innerArrayAccessor(inArr) {}
169  inline SliceAccessor& operator()(const size_t& slNum) {
170  assert(slNum < innerArrayAccessor.m_width);
171  offsetInColumns = slNum*colsPerSlice; return *this;
172  }
173  inline const SliceAccessor& operator()(const size_t& slNum) const {
174  assert(slNum < innerArrayAccessor.m_width);
175  offsetInColumns = slNum*colsPerSlice; return *this;
176  }
177  inline InnerArray& operator[](const size_t& colNum) {
178  assert(colNum < innerArrayAccessor.m_height);
179  return innerArrayAccessor(offsetInColumns + colNum);
180  }
181  inline const InnerArray& operator[](const size_t& colNum) const {
182  assert(colNum < innerArrayAccessor.m_height);
183  return innerArrayAccessor(offsetInColumns + colNum);
184  }
185 
186  // private: // No private! U3dArray3D is my best friend also!
187  mutable size_t offsetInColumns;
188  size_t colsPerSlice;
189  InnerArray& innerArrayAccessor;
190  };
191 
192 
193  InnerArray innerArrayAccessor;
194  SliceAccessor sliceAccessor;
195 };
196 
197 
198 
199 
200 
201 
202 
203 
204 //----------------------------------------------------------------------------------------------------
207 {
208 public:
209 
210 
213  class badcontent : public std::exception {
214  public:
215  badcontent();
216  badcontent(const char* str) { strncpy(message, str, 127); };
217  const char* what() const throw() { return message; };
218  private:
219  char message[128];
220  };
221 
222 
223 
224  U3dDataCube();
225 
227  U3dDataCube(ushort i_size, ushort j_size, ushort k_size, float x_max, float y_max, float z_max);
228 
230  U3dDataCube(U3dModel* model, U3D_WAVE_TYPE wt, ushort isize, ushort jsize, ushort ksize, U3dProgress *prg=NULL);
231 
232  U3dDataCube(const U3dDataCube& other);
233 
234  /* Allocates memory for amplitudes data, calculates coordinate steps */
235  bool initialize(ushort i_size, ushort j_size, ushort k_size, float x_max, float y_max, float z_max);
236 
238  void loadFromFile(const char* fileName) throw(std::ios_base::failure, badcontent);
239 
240 
242  void generate(ushort i_max, ushort j_max, ushort k_max, float x_max, float y_max, float z_max);
243 
245  void getDimensions(ushort* widthX, ushort* heightY, ushort* depthZ);
246 
248  void getCubeCoordLimits(float &xmax, float &ymax, float &zmax);
249 
250  void saveToFile(const char* fname);
251 
252  unsigned getImageSize();
253 
255  bool getPlaneFacet(const PlaneOrient& op, const float& coord, float*& images);
256 
257 
259  bool getPlaneAxeSimple(float xn, float yn, float xk, float yk, float*& images,
260  ushort* width, ushort* depth);
261 
263  bool getPlaneAxeIntrpl(float xn, float yn, float xk, float yk, float*& images,
264  ushort* width, ushort* depth);
265 
266 
267  unsigned size();
268 
270  bool getReady(){ return m_ready; }
271 
273  void setValue(const int& i, const int& j, const int& k, const float& ampl);
274 
276  void averageAmpls();
277 
279  float getValue(const int& i, const int& j, const int& k) { return m_ampl[i][j][k]; }
280 
281  float getMaxValue() { return m_vmax; }
282  float getMinValue() { return m_vmin; }
283 
284 
285 
287  bool saveImage(char *OutMod, U3dBox *image_box = NULL);
288 
289  virtual bool save(char *OutMod) { UMessage::error("Not allowed here."); return false; }
290 
291  U3dDataCube* interpData(double* factor);
292  void smData(int* epsilon);
293 
294 
295  // const float*** getInnerAmpls() { return m_ampl; }
296 
297  virtual ~U3dDataCube();
298 
299 protected:
300 
302  virtual U3dDataCube* clone() { return new U3dDataCube(*this); }
303 
304  void clean();
305 
306  bool m_ready;
308  ushort m_width;
309  ushort m_height;
310  ushort m_depth;
316  float m_stepX;
317  float m_stepY;
318  float m_stepZ;
320  float m_vmax, m_vmin;
321 
322 };
323 
324 
325 #endif // __u3d_data_cube_hpp
bool m_ready
Definition: u3d_data_cube.hpp:306
Definition: u3d_data_cube.hpp:206
bool getPlaneFacet(const PlaneOrient &op, const float &coord, float *&images)
bool getReady()
Definition: u3d_data_cube.hpp:270
void generate(ushort i_max, ushort j_max, ushort k_max, float x_max, float y_max, float z_max)
bool getPlaneAxeIntrpl(float xn, float yn, float xk, float yk, float *&images, ushort *width, ushort *depth)
Definition: u3d_box.hpp:24
Definition: u3d_data_cube.hpp:213
void getDimensions(ushort *widthX, ushort *heightY, ushort *depthZ)
static void error(const char *format,...)
float getValue(const int &i, const int &j, const int &k)
Definition: u3d_data_cube.hpp:279
ushort m_width
Definition: u3d_data_cube.hpp:308
float m_stepX
Definition: u3d_data_cube.hpp:316
ushort m_depth
Definition: u3d_data_cube.hpp:310
float m_stepY
Definition: u3d_data_cube.hpp:317
bool saveImage(char *OutMod, U3dBox *image_box=NULL)
U3dArray3D< float > m_ampl
Definition: u3d_data_cube.hpp:313
ushort m_height
Definition: u3d_data_cube.hpp:309
bool getPlaneAxeSimple(float xn, float yn, float xk, float yk, float *&images, ushort *width, ushort *depth)
Definition: u3d_model.hpp:15
Definition: u3d_progress.hpp:10
Definition: u3d_data_cube.hpp:31
void setValue(const int &i, const int &j, const int &k, const float &ampl)
float m_stepZ
Definition: u3d_data_cube.hpp:318
void getCubeCoordLimits(float &xmax, float &ymax, float &zmax)
U3dArray3D< ushort > m_ampl_num
Definition: u3d_data_cube.hpp:314
virtual U3dDataCube * clone()
Definition: u3d_data_cube.hpp:302
void averageAmpls()
void loadFromFile(const char *fileName)