1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkRectilinearGrid.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 // .NAME vtkRectilinearGrid - a dataset that is topologically regular with variable spacing in the three coordinate directions
16 // .SECTION Description
17 // vtkRectilinearGrid is a data object that is a concrete implementation of
18 // vtkDataSet. vtkRectilinearGrid represents a geometric structure that is
19 // topologically regular with variable spacing in the three coordinate
20 // directions x-y-z.
21 //
22 // To define a vtkRectilinearGrid, you must specify the dimensions of the
23 // data and provide three arrays of values specifying the coordinates
24 // along the x-y-z axes. The coordinate arrays are specified using three
25 // vtkDataArray objects (one for x, one for y, one for z).
26
27 // .SECTION Caveats
28 // Make sure that the dimensions of the grid match the number of coordinates
29 // in the x-y-z directions. If not, unpredictable results (including
30 // program failure) may result. Also, you must supply coordinates in all
31 // three directions, even if the dataset topology is 2D, 1D, or 0D.
32
33 #ifndef vtkRectilinearGrid_h
34 #define vtkRectilinearGrid_h
35
36 #include "vtkCommonDataModelModule.h" // For export macro
37 #include "vtkDataSet.h"
38 #include "vtkStructuredData.h" // For inline methods
39
40 class vtkVertex;
41 class vtkLine;
42 class vtkPixel;
43 class vtkVoxel;
44 class vtkDataArray;
45 class vtkPoints;
46
47 class VTKCOMMONDATAMODEL_EXPORT vtkRectilinearGrid : public vtkDataSet
48 {
49 public:
50 static vtkRectilinearGrid *New();
51
52 vtkTypeMacro(vtkRectilinearGrid,vtkDataSet);
53 void PrintSelf(ostream& os, vtkIndent indent);
54
55 // Description:
56 // Return what type of dataset this is.
GetDataObjectType()57 int GetDataObjectType() {return VTK_RECTILINEAR_GRID;};
58
59 // Description:
60 // Copy the geometric and topological structure of an input rectilinear grid
61 // object.
62 void CopyStructure(vtkDataSet *ds);
63
64 // Description:
65 // Restore object to initial state. Release memory back to system.
66 void Initialize();
67
68 // Description:
69 // Standard vtkDataSet API methods. See vtkDataSet for more information.
70 vtkIdType GetNumberOfCells();
71 vtkIdType GetNumberOfPoints();
72 double *GetPoint(vtkIdType ptId);
73 void GetPoint(vtkIdType id, double x[3]);
74 vtkCell *GetCell(vtkIdType cellId);
75 void GetCell(vtkIdType cellId, vtkGenericCell *cell);
76 void GetCellBounds(vtkIdType cellId, double bounds[6]);
FindPoint(double x,double y,double z)77 vtkIdType FindPoint(double x, double y, double z) { return this->vtkDataSet::FindPoint(x, y, z);};
78 vtkIdType FindPoint(double x[3]);
79 vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
80 int& subId, double pcoords[3], double *weights);
81 vtkIdType FindCell(double x[3], vtkCell *cell, vtkGenericCell *gencell,
82 vtkIdType cellId, double tol2, int& subId,
83 double pcoords[3], double *weights);
84 vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
85 double tol2, int& subId, double pcoords[3],
86 double *weights);
87 int GetCellType(vtkIdType cellId);
GetCellPoints(vtkIdType cellId,vtkIdList * ptIds)88 void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
89 {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
90 this->Dimensions);}
GetPointCells(vtkIdType ptId,vtkIdList * cellIds)91 void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
92 {vtkStructuredData::GetPointCells(ptId,cellIds,this->Dimensions);}
93 void ComputeBounds();
GetMaxCellSize()94 int GetMaxCellSize() {return 8;}; //voxel is the largest
95 void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
96 vtkIdList *cellIds);
97
98 // Description:
99 // Given a user-supplied vtkPoints container object, this method fills in all
100 // the points of the RectilinearGrid.
101 void GetPoints(vtkPoints* pnts);
102
103 // Description:
104 // Set dimensions of rectilinear grid dataset.
105 // This also sets the extent.
106 void SetDimensions(int i, int j, int k);
107 void SetDimensions(int dim[3]);
108
109 // Description:
110 // Get dimensions of this rectilinear grid dataset.
111 vtkGetVectorMacro(Dimensions,int,3);
112
113 // Description:
114 // Return the dimensionality of the data.
115 int GetDataDimension();
116
117 // Description:
118 // Convenience function computes the structured coordinates for a point x[3].
119 // The cell is specified by the array ijk[3], and the parametric coordinates
120 // in the cell are specified with pcoords[3]. The function returns a 0 if the
121 // point x is outside of the grid, and a 1 if inside the grid.
122 int ComputeStructuredCoordinates(double x[3], int ijk[3], double pcoords[3]);
123
124 // Description:
125 // Given a location in structured coordinates (i-j-k), return the point id.
126 vtkIdType ComputePointId(int ijk[3]);
127
128 // Description:
129 // Given a location in structured coordinates (i-j-k), return the cell id.
130 vtkIdType ComputeCellId(int ijk[3]);
131
132 // Description:
133 // Given the IJK-coordinates of the point, it returns the corresponding
134 // xyz-coordinates. The xyz coordinates are stored in the user-supplied
135 // array p.
136 void GetPoint(const int i,const int j,const int k,double p[3]);
137
138 // Description:
139 // Specify the grid coordinates in the x-direction.
140 virtual void SetXCoordinates(vtkDataArray*);
141 vtkGetObjectMacro(XCoordinates,vtkDataArray);
142
143 // Description:
144 // Specify the grid coordinates in the y-direction.
145 virtual void SetYCoordinates(vtkDataArray*);
146 vtkGetObjectMacro(YCoordinates,vtkDataArray);
147
148 // Description:
149 // Specify the grid coordinates in the z-direction.
150 virtual void SetZCoordinates(vtkDataArray*);
151 vtkGetObjectMacro(ZCoordinates,vtkDataArray);
152
153 // Description:
154 // Different ways to set the extent of the data array. The extent
155 // should be set before the "Scalars" are set or allocated.
156 // The Extent is stored in the order (X, Y, Z).
157 void SetExtent(int extent[6]);
158 void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
159 vtkGetVector6Macro(Extent, int);
160
161 // Description:
162 // Return the actual size of the data in kilobytes. This number
163 // is valid only after the pipeline has updated. The memory size
164 // returned is guaranteed to be greater than or equal to the
165 // memory required to represent the data (e.g., extra space in
166 // arrays, etc. are not included in the return value). THIS METHOD
167 // IS THREAD SAFE.
168 unsigned long GetActualMemorySize();
169
170 // Description:
171 // Shallow and Deep copy.
172 void ShallowCopy(vtkDataObject *src);
173 void DeepCopy(vtkDataObject *src);
174
175 // Description:
176 // Structured extent. The extent type is a 3D extent
GetExtentType()177 int GetExtentType() { return VTK_3D_EXTENT; };
178
179 // Description:
180 // Reallocates and copies to set the Extent to the UpdateExtent.
181 // This is used internally when the exact extent is requested,
182 // and the source generated more than the update extent.
183 virtual void Crop(const int* updateExtent);
184
185 //BTX
186 // Description:
187 // Retrieve an instance of this class from an information object.
188 static vtkRectilinearGrid* GetData(vtkInformation* info);
189 static vtkRectilinearGrid* GetData(vtkInformationVector* v, int i=0);
190 //ETX
191
192 protected:
193 vtkRectilinearGrid();
194 ~vtkRectilinearGrid();
195
196 // for the GetCell method
197 vtkVertex *Vertex;
198 vtkLine *Line;
199 vtkPixel *Pixel;
200 vtkVoxel *Voxel;
201
202 int Dimensions[3];
203 int DataDescription;
204
205 int Extent[6];
206
207 vtkDataArray *XCoordinates;
208 vtkDataArray *YCoordinates;
209 vtkDataArray *ZCoordinates;
210
211 // Hang on to some space for returning points when GetPoint(id) is called.
212 double PointReturn[3];
213
214 private:
215 void Cleanup();
216
217 private:
218 vtkRectilinearGrid(const vtkRectilinearGrid&); // Not implemented.
219 void operator=(const vtkRectilinearGrid&); // Not implemented.
220 };
221
222 //----------------------------------------------------------------------------
GetNumberOfCells()223 inline vtkIdType vtkRectilinearGrid::GetNumberOfCells()
224 {
225 vtkIdType nCells=1;
226 int i;
227
228 for (i=0; i<3; i++)
229 {
230 if (this->Dimensions[i] <= 0)
231 {
232 return 0;
233 }
234 if (this->Dimensions[i] > 1)
235 {
236 nCells *= (this->Dimensions[i]-1);
237 }
238 }
239
240 return nCells;
241 }
242
243 //----------------------------------------------------------------------------
GetNumberOfPoints()244 inline vtkIdType vtkRectilinearGrid::GetNumberOfPoints()
245 {
246 return this->Dimensions[0]*this->Dimensions[1]*this->Dimensions[2];
247 }
248
249 //----------------------------------------------------------------------------
GetDataDimension()250 inline int vtkRectilinearGrid::GetDataDimension()
251 {
252 return vtkStructuredData::GetDataDimension(this->DataDescription);
253 }
254
255 //----------------------------------------------------------------------------
ComputePointId(int ijk[3])256 inline vtkIdType vtkRectilinearGrid::ComputePointId(int ijk[3])
257 {
258 return vtkStructuredData::ComputePointId(this->Dimensions,ijk);
259 }
260
261 //----------------------------------------------------------------------------
ComputeCellId(int ijk[3])262 inline vtkIdType vtkRectilinearGrid::ComputeCellId(int ijk[3])
263 {
264 return vtkStructuredData::ComputeCellId(this->Dimensions,ijk);
265 }
266
267 #endif
268