1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkDataSet.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 vtkDataSet - abstract class to specify dataset behavior
16 // .SECTION Description
17 // vtkDataSet is an abstract class that specifies an interface for dataset
18 // objects. vtkDataSet also provides methods to provide informations about
19 // the data, such as center, bounding box, and representative length.
20 //
21 // In vtk a dataset consists of a structure (geometry and topology) and
22 // attribute data. The structure is defined implicitly or explicitly as
23 // a collection of cells. The geometry of the structure is contained in
24 // point coordinates plus the cell interpolation functions. The topology
25 // of the dataset structure is defined by cell types and how the cells
26 // share their defining points.
27 //
28 // Attribute data in vtk is either point data (data at points) or cell data
29 // (data at cells). Typically filters operate on point data, but some may
30 // operate on cell data, both cell and point data, either one, or none.
31
32 // .SECTION See Also
33 // vtkPointSet vtkStructuredPoints vtkStructuredGrid vtkUnstructuredGrid
34 // vtkRectilinearGrid vtkPolyData vtkPointData vtkCellData
35 // vtkDataObject vtkFieldData
36
37 #ifndef vtkDataSet_h
38 #define vtkDataSet_h
39
40 #include "vtkCommonDataModelModule.h" // For export macro
41 #include "vtkDataObject.h"
42
43 class vtkCell;
44 class vtkCellData;
45 class vtkCellIterator;
46 class vtkCellTypes;
47 class vtkGenericCell;
48 class vtkIdList;
49 class vtkPointData;
50
51 class VTKCOMMONDATAMODEL_EXPORT vtkDataSet : public vtkDataObject
52 {
53 public:
54 vtkTypeMacro(vtkDataSet,vtkDataObject);
55 void PrintSelf(ostream& os, vtkIndent indent);
56
57 // Description:
58 // Copy the geometric and topological structure of an object. Note that
59 // the invoking object and the object pointed to by the parameter ds must
60 // be of the same type.
61 // THIS METHOD IS NOT THREAD SAFE.
62 virtual void CopyStructure(vtkDataSet *ds) = 0;
63
64 // Description:
65 // Copy the attributes associated with the specified dataset to this
66 // instance of vtkDataSet.
67 // THIS METHOD IS NOT THREAD SAFE.
68 virtual void CopyAttributes(vtkDataSet *ds);
69
70 // Description:
71 // Determine the number of points composing the dataset.
72 // THIS METHOD IS THREAD SAFE
73 virtual vtkIdType GetNumberOfPoints() = 0;
74
75 // Description:
76 // Determine the number of cells composing the dataset.
77 // THIS METHOD IS THREAD SAFE
78 virtual vtkIdType GetNumberOfCells() = 0;
79
80 // Description:
81 // Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
82 // THIS METHOD IS NOT THREAD SAFE.
83 virtual double *GetPoint(vtkIdType ptId) = 0;
84
85 // Description:
86 // Copy point coordinates into user provided array x[3] for specified
87 // point id.
88 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
89 // THE DATASET IS NOT MODIFIED
90 virtual void GetPoint(vtkIdType id, double x[3]);
91
92 // Description:
93 // Return an iterator that traverses the cells in this data set.
94 virtual vtkCellIterator* NewCellIterator();
95
96 // Description:
97 // Get cell with cellId such that: 0 <= cellId < NumberOfCells.
98 // THIS METHOD IS NOT THREAD SAFE.
99 virtual vtkCell *GetCell(vtkIdType cellId) = 0;
100
101 // Description:
102 // Get cell with cellId such that: 0 <= cellId < NumberOfCells.
103 // This is a thread-safe alternative to the previous GetCell()
104 // method.
105 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
106 // THE DATASET IS NOT MODIFIED
107 virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell) = 0;
108
109 // Description:
110 // Get the bounds of the cell with cellId such that:
111 // 0 <= cellId < NumberOfCells.
112 // A subclass may be able to determine the bounds of cell without using
113 // an expensive GetCell() method. A default implementation is provided
114 // that actually uses a GetCell() call. This is to ensure the method
115 // is available to all datasets. Subclasses should override this method
116 // to provide an efficient implementation.
117 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
118 // THE DATASET IS NOT MODIFIED
119 virtual void GetCellBounds(vtkIdType cellId, double bounds[6]);
120
121 // Description:
122 // Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
123 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
124 // THE DATASET IS NOT MODIFIED
125 virtual int GetCellType(vtkIdType cellId) = 0;
126
127 // Description:
128 // Get a list of types of cells in a dataset. The list consists of an array
129 // of types (not necessarily in any order), with a single entry per type.
130 // For example a dataset 5 triangles, 3 lines, and 100 hexahedra would
131 // result a list of three entries, corresponding to the types VTK_TRIANGLE,
132 // VTK_LINE, and VTK_HEXAHEDRON.
133 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
134 // THE DATASET IS NOT MODIFIED
135 virtual void GetCellTypes(vtkCellTypes *types);
136
137 // Description:
138 // Topological inquiry to get points defining cell.
139 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
140 // THE DATASET IS NOT MODIFIED
141 virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) = 0;
142
143 // Description:
144 // Topological inquiry to get cells using point.
145 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
146 // THE DATASET IS NOT MODIFIED
147 virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) = 0;
148
149 // Description:
150 // Topological inquiry to get all cells using list of points exclusive of
151 // cell specified (e.g., cellId). Note that the list consists of only
152 // cells that use ALL the points provided.
153 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
154 // THE DATASET IS NOT MODIFIED
155 virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
156 vtkIdList *cellIds);
157
158 // Description:
159 // Locate the closest point to the global coordinate x. Return the
160 // point id. If point id < 0; then no point found. (This may arise
161 // when point is outside of dataset.)
162 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
163 // THE DATASET IS NOT MODIFIED
FindPoint(double x,double y,double z)164 vtkIdType FindPoint(double x, double y, double z)
165 {
166 double xyz[3];
167 xyz[0] = x; xyz[1] = y; xyz[2] = z;
168 return this->FindPoint (xyz);
169 }
170 virtual vtkIdType FindPoint(double x[3]) = 0;
171
172 // Description:
173 // Locate cell based on global coordinate x and tolerance
174 // squared. If cell and cellId is non-NULL, then search starts from
175 // this cell and looks at immediate neighbors. Returns cellId >= 0
176 // if inside, < 0 otherwise. The parametric coordinates are
177 // provided in pcoords[3]. The interpolation weights are returned in
178 // weights[]. (The number of weights is equal to the number of
179 // points in the found cell). Tolerance is used to control how close
180 // the point is to be considered "in" the cell.
181 // THIS METHOD IS NOT THREAD SAFE.
182 virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId,
183 double tol2, int& subId, double pcoords[3],
184 double *weights) = 0;
185
186 // Description:
187 // This is a version of the above method that can be used with
188 // multithreaded applications. A vtkGenericCell must be passed in
189 // to be used in internal calls that might be made to GetCell()
190 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
191 // THE DATASET IS NOT MODIFIED
192 virtual vtkIdType FindCell(double x[3], vtkCell *cell,
193 vtkGenericCell *gencell, vtkIdType cellId,
194 double tol2, int& subId, double pcoords[3],
195 double *weights) = 0;
196
197 // Description:
198 // Locate the cell that contains a point and return the cell. Also returns
199 // the subcell id, parametric coordinates and weights for subsequent
200 // interpolation. This method combines the derived class methods
201 // int FindCell and vtkCell *GetCell. Derived classes may provide a more
202 // efficient implementation. See for example vtkStructuredPoints.
203 // THIS METHOD IS NOT THREAD SAFE.
204 virtual vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
205 double tol2, int& subId, double pcoords[3],
206 double *weights);
207
208 // Description:
209 // Datasets are composite objects and need to check each part for MTime
210 // THIS METHOD IS THREAD SAFE
211 unsigned long int GetMTime();
212
213 // Description:
214 // Return a pointer to this dataset's cell data.
215 // THIS METHOD IS THREAD SAFE
GetCellData()216 vtkCellData *GetCellData() {return this->CellData;};
217
218 // Description:
219 // Return a pointer to this dataset's point data.
220 // THIS METHOD IS THREAD SAFE
GetPointData()221 vtkPointData *GetPointData() {return this->PointData;};
222
223 // Description:
224 // Reclaim any extra memory used to store data.
225 // THIS METHOD IS NOT THREAD SAFE.
226 virtual void Squeeze();
227
228 // Description:
229 // Compute the data bounding box from data points.
230 // THIS METHOD IS NOT THREAD SAFE.
231 virtual void ComputeBounds();
232
233 // Description:
234 // Return a pointer to the geometry bounding box in the form
235 // (xmin,xmax, ymin,ymax, zmin,zmax).
236 // THIS METHOD IS NOT THREAD SAFE.
237 double *GetBounds();
238
239 // Description:
240 // Return a pointer to the geometry bounding box in the form
241 // (xmin,xmax, ymin,ymax, zmin,zmax).
242 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
243 // THE DATASET IS NOT MODIFIED
244 void GetBounds(double bounds[6]);
245
246 // Description:
247 // Get the center of the bounding box.
248 // THIS METHOD IS NOT THREAD SAFE.
249 double *GetCenter();
250
251 // Description:
252 // Get the center of the bounding box.
253 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
254 // THE DATASET IS NOT MODIFIED
255 void GetCenter(double center[3]);
256
257 // Description:
258 // Return the length of the diagonal of the bounding box.
259 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
260 // THE DATASET IS NOT MODIFIED
261 double GetLength();
262
263 // Description:
264 // Restore data object to initial state.
265 // THIS METHOD IS NOT THREAD SAFE.
266 void Initialize();
267
268 // Description:
269 // Convenience method to get the range of the first component (and only
270 // the first component) of any scalars in the data set. If the data has
271 // both point data and cell data, it returns the (min/max) range of
272 // combined point and cell data. If there are no point or cell scalars
273 // the method will return (0,1). Note: It might be necessary to call
274 // Update to create or refresh the scalars before calling this method.
275 // THIS METHOD IS THREAD SAFE IF FIRST CALLED FROM A SINGLE THREAD AND
276 // THE DATASET IS NOT MODIFIED
277 virtual void GetScalarRange(double range[2]);
278
279 // Description:
280 // Convenience method to get the range of the first component (and only
281 // the first component) of any scalars in the data set. If the data has
282 // both point data and cell data, it returns the (min/max) range of
283 // combined point and cell data. If there are no point or cell scalars
284 // the method will return (0,1). Note: It might be necessary to call
285 // Update to create or refresh the scalars before calling this method.
286 // THIS METHOD IS NOT THREAD SAFE.
287 double *GetScalarRange();
288
289 // Description:
290 // Convenience method returns largest cell size in dataset. This is generally
291 // used to allocate memory for supporting data structures.
292 // THIS METHOD IS THREAD SAFE
293 virtual int GetMaxCellSize() = 0;
294
295 // Description:
296 // Return the actual size of the data in kilobytes. This number
297 // is valid only after the pipeline has updated. The memory size
298 // returned is guaranteed to be greater than or equal to the
299 // memory required to represent the data (e.g., extra space in
300 // arrays, etc. are not included in the return value). THIS METHOD
301 // IS THREAD SAFE.
302 unsigned long GetActualMemorySize();
303
304 // Description:
305 // Return the type of data object.
GetDataObjectType()306 int GetDataObjectType()
307 {return VTK_DATA_SET;}
308
309 // Description:
310 // Shallow and Deep copy.
311 void ShallowCopy(vtkDataObject *src);
312 void DeepCopy(vtkDataObject *src);
313
314 //BTX
315 enum FieldDataType
316 {
317 DATA_OBJECT_FIELD=0,
318 POINT_DATA_FIELD=1,
319 CELL_DATA_FIELD=2
320 };
321 //ETX
322
323 // Description:
324 // This method checks to see if the cell and point attributes
325 // match the geometry. Many filters will crash if the number of
326 // tupples in an array is less than the number of points/cells.
327 // This method returns 1 if there is a mismatch,
328 // and 0 if everything is ok. It prints an error if an
329 // array is too short, and a warning if an array is too long.
330 int CheckAttributes();
331
332 // Description:
333 // Normally called by pipeline executives or algoritgms only. This method
334 // computes the ghost arrays for a given dataset. The zeroExt argument
335 // specifies the extent of the region which ghost level = 0.
336 virtual void GenerateGhostLevelArray(int zeroExt[6]);
337
338 //BTX
339 // Description:
340 // Retrieve an instance of this class from an information object.
341 static vtkDataSet* GetData(vtkInformation* info);
342 static vtkDataSet* GetData(vtkInformationVector* v, int i=0);
343 //ETX
344
345 // Description:
346 // Returns the attributes of the data object as a vtkFieldData.
347 // This returns non-null values in all the same cases as GetAttributes,
348 // in addition to the case of FIELD, which will return the field data
349 // for any vtkDataObject subclass.
350 virtual vtkFieldData* GetAttributesAsFieldData(int type);
351
352 // Description:
353 // Get the number of elements for a specific attribute type (POINT, CELL, etc.).
354 virtual vtkIdType GetNumberOfElements(int type);
355
356 protected:
357 // Constructor with default bounds (0,1, 0,1, 0,1).
358 vtkDataSet();
359 ~vtkDataSet();
360
361 // Description:
362 // Compute the range of the scalars and cache it into ScalarRange
363 // only if the cache became invalid (ScalarRangeComputeTime).
364 virtual void ComputeScalarRange();
365
366 vtkCellData *CellData; // Scalars, vectors, etc. associated w/ each cell
367 vtkPointData *PointData; // Scalars, vectors, etc. associated w/ each point
368 vtkTimeStamp ComputeTime; // Time at which bounds, center, etc. computed
369 double Bounds[6]; // (xmin,xmax, ymin,ymax, zmin,zmax) geometric bounds
370 double Center[3];
371
372 // Cached scalar range
373 double ScalarRange[2];
374
375 // Time at which scalar range is computed
376 vtkTimeStamp ScalarRangeComputeTime;
377
378 private:
379 void InternalDataSetCopy(vtkDataSet *src);
380 //BTX
381 friend class vtkImageAlgorithmToDataSetFriendship;
382 //ETX
383 private:
384 vtkDataSet(const vtkDataSet&); // Not implemented.
385 void operator=(const vtkDataSet&); // Not implemented.
386 };
387
GetPoint(vtkIdType id,double x[3])388 inline void vtkDataSet::GetPoint(vtkIdType id, double x[3])
389 {
390 double *pt = this->GetPoint(id);
391 x[0] = pt[0]; x[1] = pt[1]; x[2] = pt[2];
392 }
393
394 #endif
395