3 #ifndef __u3d_data_cube_hpp
4 #define __u3d_data_cube_hpp
11 #include <u3d_migr.hpp>
12 #include <u3d_progress.hpp>
14 typedef unsigned short ushort;
20 enum PlaneOrient {PT_X, PT_Y, PT_Z};
41 innerArrayAccessor(0, 0 ,0),
42 sliceAccessor(innerArrayAccessor)
46 U3dArray3D(
size_t width,
size_t height,
size_t depth) :
47 innerArrayAccessor(width, height, depth),
48 sliceAccessor(innerArrayAccessor)
53 innerArrayAccessor(that.innerArrayAccessor),
54 sliceAccessor(innerArrayAccessor)
60 innerArrayAccessor.~InnerArray();
61 new(&innerArrayAccessor) InnerArray(that.innerArrayAccessor);
62 sliceAccessor.~SliceAccessor();
63 new(&sliceAccessor) SliceAccessor(innerArrayAccessor);
68 inline SliceAccessor& operator[](
const size_t& slNdx) {
return sliceAccessor(slNdx); }
69 inline const SliceAccessor& operator[](
const size_t& slNdx)
const {
return sliceAccessor(slNdx); }
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];
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];
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);
98 for (
size_t i=0; i<innerArrayAccessor.m_size; innerArrayAccessor.m_array[i++] = t);
103 T* innerArray() {
return innerArrayAccessor.m_array; }
104 const T* innerArray()
const {
return innerArrayAccessor.m_array; }
108 size_t size()
const {
return innerArrayAccessor.m_size; }
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; }
116 void clear() { setDimensions(0,0,0); }
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])
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])
134 std::copy(that.m_array, that.m_array + that.m_size, m_array);
137 ~InnerArray() {
delete[] m_array; }
139 inline InnerArray& operator()(
const size_t& colNum) {
140 offset = colNum*m_depth;
return *
this;
142 inline const InnerArray& operator()(
const size_t& colNum)
const {
143 offset = colNum*m_depth;
return *
this;
145 inline T& operator[](
const size_t& depthNdx) {
146 assert(depthNdx < m_depth);
147 return m_array[offset+depthNdx];
149 inline const T& operator[](
const size_t& depthNdx)
const {
150 assert(depthNdx < m_depth);
151 return m_array[offset+depthNdx];
160 mutable size_t offset;
166 class SliceAccessor {
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;
173 inline const SliceAccessor& operator()(
const size_t& slNum)
const {
174 assert(slNum < innerArrayAccessor.m_width);
175 offsetInColumns = slNum*colsPerSlice;
return *
this;
177 inline InnerArray& operator[](
const size_t& colNum) {
178 assert(colNum < innerArrayAccessor.m_height);
179 return innerArrayAccessor(offsetInColumns + colNum);
181 inline const InnerArray& operator[](
const size_t& colNum)
const {
182 assert(colNum < innerArrayAccessor.m_height);
183 return innerArrayAccessor(offsetInColumns + colNum);
187 mutable size_t offsetInColumns;
189 InnerArray& innerArrayAccessor;
193 InnerArray innerArrayAccessor;
194 SliceAccessor sliceAccessor;
213 class badcontent :
public std::exception {
216 badcontent(
const char* str) { strncpy(message, str, 127); };
217 const char* what()
const throw() {
return message; };
227 U3dDataCube(ushort i_size, ushort j_size, ushort k_size,
float x_max,
float y_max,
float z_max);
235 bool initialize(ushort i_size, ushort j_size, ushort k_size,
float x_max,
float y_max,
float z_max);
238 void loadFromFile(
const char* fileName)
throw(std::ios_base::failure, badcontent);
242 void generate(ushort i_max, ushort j_max, ushort k_max,
float x_max,
float y_max,
float z_max);
245 void getDimensions(ushort* widthX, ushort* heightY, ushort* depthZ);
250 void saveToFile(
const char* fname);
252 unsigned getImageSize();
255 bool getPlaneFacet(
const PlaneOrient& op,
const float& coord,
float*& images);
260 ushort* width, ushort* depth);
264 ushort* width, ushort* depth);
273 void setValue(
const int& i,
const int& j,
const int& k,
const float& ampl);
279 float getValue(
const int& i,
const int& j,
const int& k) {
return m_ampl[i][j][k]; }
281 float getMaxValue() {
return m_vmax; }
282 float getMinValue() {
return m_vmin; }
289 virtual bool save(
char *OutMod) {
U3dMessage::error(
"SCHEISE!!!!!!!!!!!!!!!!!");
return false; }
292 void smData(
int* epsilon);
320 float m_vmax, m_vmin;
325 #endif // __u3d_data_cube_hpp
bool m_ready
Definition: u3d_data_cube.hpp:306
static void error(const char *format,...)
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
void getDimensions(ushort *widthX, ushort *heightY, ushort *depthZ)
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 &l)
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 loadFromFile(const char *fileName)