Grid3
Grid3.h
Go to the documentation of this file.
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 
50  enum BoundaryMode { REPLICATE , CONSTANT };
52 
53 
55 template<class T>
56 class Grid3{
57 
58 protected:
59  std::vector<T> data;
61  int _width, _height, _depth;
62  double _spacingX, _spacingY, _spacingZ;
64 
65 public:
67  Grid3(){}
68 
70  Grid3(int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0);
71 
73  Grid3(Vec3i dimensions, Vec3d spacing=Vec3d(1.0,1.0,1.0));
74 
76  void Init(int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0);
77 
79  int GetWidth(){ return _width;}
80 
82  int GetHeight(){ return _height;}
83 
85  int GetDepth(){ return _depth; }
86 
88  Vec3i GetDimensions(){return Vec3i(_width, _height, _depth);}
89 
91  double GetSpacingX(){return _spacingX;}
92 
94  double GetSpacingY(){return _spacingY;}
95 
97  double GetSpacingZ(){return _spacingZ;}
98 
100  Vec3d GetSpacing(){return Vec3d(_spacingX, _spacingY, _spacingZ);}
101 
103  void SetSpacing(double x_spacing, double y_spacing, double z_spacing);
104 
106  void SetSpacing(Vec3d spacing);
107 
109  Vec3d WorldToGrid(Vec3d p);
110 
112  Vec3d GridToWorld(Vec3d p);
113 
114 
116  MetaDataContainer GetMetaData(){return metadata;}
117 
119  void SetMetaData(MetaDataContainer md){metadata=md;}
120 
122  int NumberOfElements();
123 
125  T* Data();
126 
128  std::string GetDataType();
129 
131  int Offset(int x, int y, int z);
132 
134  int Offset(Vec3i p){ return Offset(p.x,p.y,p.z); }
135 
137  Vec3i Coordinate(long index);
138 
140  bool IsInside(int x, int y, int z);
141 
143  bool IsInside(Vec3i p);
144 
146  T& Background();
147 
149  T& operator[](long index);
150 
152  T& operator()(int x,int y, int z=0, bool Safe=false, BoundaryMode mode=REPLICATE);
153 
155  T& operator()(Vec3i p, bool Safe=false, BoundaryMode mode=REPLICATE);
156 
158  T LinearAt(double x, double y, double z, BoundaryMode mode=REPLICATE);
159 
161  T LinearAt(Vec3d p, BoundaryMode mode=REPLICATE);
162 
164  void Get6Neighbors(long index, vector<long>& n);
165 
167  void Get6Neighbors(Vec3i p, vector<Vec3i>& n);
168 
170  void Fill(T value);
171 
173  T GetMaxValue();
174 
176  T GetMinValue();
177 
178  /*
180  Grid3<T> operator*(double x);
181 
183  Grid3<T> operator/(double x);
184 
186  Grid3<T> operator+(T x);
187 
189  Grid3<T> operator-(T x);*/
190 
192  void CopyDataFrom(Grid3<T>& src);
193 
195  void SwapContentsWith(Grid3<T>& v);
196 
198  bool CreateFromFile(std::string filename);
199 
201  bool ReadVTK(std::string filename);
202 
204  bool WriteVTK(std::string filename);
205 
206  /*
208  bool ReadAmira(std::string filename);
209 
211  bool WriteAmira(std::string filename);*/
212 
213 
215  bool ReadMetaImage(std::string filename);
216 
218  bool WriteMetaImage(std::string filename);
219 
221  bool ReadNIFTI(std::string filename);
222 
224  bool WriteNIFTI(std::string filename);
225 
227  bool ReadDICOM(std::string filename);
228 
229 };
230 
231 #include "Grid3_i.h"
232 
233 
234 #endif
T background_value
Definition: Grid3.h:60
BoundaryMode
Options for reading grid data outside the grid bounds.
Definition: Grid3.h:51
std::vector< T > data
Definition: Grid3.h:59
double _spacingZ
Definition: Grid3.h:62
T z
Definition: Vector3.h:13
int GetHeight()
Return the number of grid rows.
Definition: Grid3.h:82
int GetWidth()
Return the number of grid columns.
Definition: Grid3.h:79
Class representing 3D vectors, with elements of type T.
Definition: Vector3.h:9
MetaDataContainer metadata
Definition: Grid3.h:63
Grid3()
Default constructor.
Definition: Grid3.h:67
Definition: Grid3.h:51
MetaDataContainer GetMetaData()
Returns a MetaDataContainer with the current image meta data.
Definition: Grid3.h:116
Vec3< int > Vec3i
Definition: Vector3.h:150
T x
Definition: Vector3.h:11
int _width
Definition: Grid3.h:61
Class representing a 3D image grid, each voxel being of type T.
Definition: Grid3.h:56
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:134
Vec3i GetDimensions()
Return a vector containing the grid dimensions.
Definition: Grid3.h:88
double GetSpacingZ()
Return the spacing along Z.
Definition: Grid3.h:97
Vec3d GetSpacing()
Return the spacing along all three dimesions.
Definition: Grid3.h:100
void SetMetaData(MetaDataContainer md)
Set image meta data. All current meta data is overwritten.
Definition: Grid3.h:119
Vec3< double > Vec3d
Definition: Vector3.h:149
T y
Definition: Vector3.h:12
double GetSpacingX()
Return the spacing along X.
Definition: Grid3.h:91
Definition: Grid3.h:51
int GetDepth()
Return the number of grid slices.
Definition: Grid3.h:85
double GetSpacingY()
Return the spacing along Y.
Definition: Grid3.h:94