Grid3
Grid3.h
1 #ifndef GRID_3_H
2 #define GRID_3_H
3 
4 #include "Vector3.h"
5 #include "MetaDataContainer.h"
6 #include <algorithm>
7 #include <string>
8 #include <stdint.h>
9 #include <vector>
10 using namespace std;
11 
51 template<class T>
53 class Grid3{
54 
55 protected:
56  std::vector<T> data;
57  int _width, _height, _depth;
58  double _spacingX, _spacingY, _spacingZ;
59  MetaDataContainer metadata;
60 
61 public:
63  Grid3(){}
64 
66  Grid3(int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0);
67 
69  Grid3(Vec3i dimensions, Vec3d spacing=Vec3d(1.0,1.0,1.0));
70 
72  void Init(int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0);
73 
75  int GetWidth(){ return _width;}
76 
78  int GetHeight(){ return _height;}
79 
81  int GetDepth(){ return _depth; }
82 
84  Vec3i GetDimensions(){return Vec3i(_width, _height, _depth);}
85 
87  double GetSpacingX(){return _spacingX;}
88 
90  double GetSpacingY(){return _spacingY;}
91 
93  double GetSpacingZ(){return _spacingZ;}
94 
96  Vec3d GetSpacing(){return Vec3d(_spacingX, _spacingY, _spacingZ);}
97 
99  void SetSpacing(double x_spacing, double y_spacing, double z_spacing);
100 
102  void SetSpacing(Vec3d spacing);
103 
105  Vec3d WorldToGrid(Vec3d p);
106 
108  Vec3d GridToWorld(Vec3d p);
109 
110 
112  MetaDataContainer GetMetaData(){return metadata;}
113 
115  void SetMetaData(MetaDataContainer md){metadata=md;}
116 
118  int NumberOfElements();
119 
121  T* Data();
122 
124  std::string GetDataType();
125 
127  int Offset(int x, int y, int z);
128 
130  int Offset(Vec3i p){ return Offset(p.x,p.y,p.z); }
131 
133  Vec3i Coordinate(long index);
134 
136  bool IsInside(int x, int y, int z);
137 
139  bool IsInside(Vec3i p);
140 
142  T& operator[](long index);
143 
145  T& operator()(int x,int y, int z=0, bool Safe=false);
146 
148  T& operator()(Vec3i p, bool Safe=false);
149 
151  T LinearAt(double x, double y, double z);
152 
154  T LinearAt(Vec3d p);
155 
157  void Get6Neighbors(long index, vector<long>& n);
158 
160  void Get6Neighbors(Vec3i p, vector<Vec3i>& n);
161 
163  void Fill(T value);
164 
166  T GetMaxValue();
167 
169  T GetMinValue();
170 
171  /*
173  Grid3<T> operator*(double x);
174 
176  Grid3<T> operator/(double x);
177 
179  Grid3<T> operator+(T x);
180 
182  Grid3<T> operator-(T x);*/
183 
185  void CopyDataFrom(Grid3<T>& src);
186 
188  void SwapContentsWith(Grid3<T>& v);
189 
191  bool CreateFromFile(std::string filename);
192 
194  bool ReadVTK(std::string filename);
195 
197  bool WriteVTK(std::string filename);
198 
199  /*
201  bool ReadAmira(std::string filename);
202 
204  bool WriteAmira(std::string filename);*/
205 
206 
208  bool ReadMetaImage(std::string filename);
209 
211  bool WriteMetaImage(std::string filename);
212 
214  bool ReadNIFTI(std::string filename);
215 
217  bool WriteNIFTI(std::string filename);
218 
220  bool ReadDICOM(std::string filename);
221 
222 };
223 
224 #include "Grid3_i.h"
225 
226 
227 #endif
int GetHeight()
Return the number of grid rows.
Definition: Grid3.h:78
int GetWidth()
Return the number of grid columns.
Definition: Grid3.h:75
Class representing 3D vectors, with elements of type T.
Definition: Vector3.h:9
Grid3()
Default constructor.
Definition: Grid3.h:63
MetaDataContainer GetMetaData()
Returns a MetaDataContainer with the current image meta data.
Definition: Grid3.h:112
Class representing a 3D image grid, each voxel being of type T.
Definition: Grid3.h:53
Class for storing meta data related to a volume image.
Definition: MetaDataContainer.h:8
int Offset(Vec3i p)
Returns the index of a specified coordinate in the internal data array.
Definition: Grid3.h:130
Vec3i GetDimensions()
Return a vector containing the grid dimensions.
Definition: Grid3.h:84
double GetSpacingZ()
Return the spacing along Z.
Definition: Grid3.h:93
Vec3d GetSpacing()
Return the spacing along all three dimesions.
Definition: Grid3.h:96
void SetMetaData(MetaDataContainer md)
Set image meta data. All current meta data is overwritten.
Definition: Grid3.h:115
double GetSpacingX()
Return the spacing along X.
Definition: Grid3.h:87
int GetDepth()
Return the number of grid slices.
Definition: Grid3.h:81
double GetSpacingY()
Return the spacing along Y.
Definition: Grid3.h:90