VTK
vtkImageData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkImageData.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 =========================================================================*/
30 #ifndef vtkImageData_h
31 #define vtkImageData_h
32 
33 #include "vtkCommonDataModelModule.h" // For export macro
34 #include "vtkDataSet.h"
35 
36 #include "vtkStructuredData.h" // Needed for inline methods
37 
38 class vtkDataArray;
39 class vtkLine;
40 class vtkPixel;
41 class vtkVertex;
42 class vtkVoxel;
43 
45 {
46 public:
47  static vtkImageData *New();
48 
49  vtkTypeMacro(vtkImageData,vtkDataSet);
50  void PrintSelf(ostream& os, vtkIndent indent);
51 
54  virtual void CopyStructure(vtkDataSet *ds);
55 
57  virtual int GetDataObjectType() {return VTK_IMAGE_DATA;};
58 
60 
61  virtual vtkIdType GetNumberOfCells();
62  virtual vtkIdType GetNumberOfPoints();
63  virtual double *GetPoint(vtkIdType ptId);
64  virtual void GetPoint(vtkIdType id, double x[3]);
65  virtual vtkCell *GetCell(vtkIdType cellId);
66  virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell);
67  virtual void GetCellBounds(vtkIdType cellId, double bounds[6]);
68  virtual vtkIdType FindPoint(double x, double y, double z)
69  {
70  return this->vtkDataSet::FindPoint(x, y, z);
71  }
72  virtual vtkIdType FindPoint(double x[3]);
73  virtual vtkIdType FindCell(
74  double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
75  int& subId, double pcoords[3], double *weights);
76  virtual vtkIdType FindCell(
77  double x[3], vtkCell *cell, vtkGenericCell *gencell,
78  vtkIdType cellId, double tol2, int& subId,
79  double pcoords[3], double *weights);
80  virtual vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
81  double tol2, int& subId, double pcoords[3],
82  double *weights);
83  virtual int GetCellType(vtkIdType cellId);
84  virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
85  {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
86  this->GetDimensions());}
87  virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
88  {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
89  virtual void ComputeBounds();
90  virtual int GetMaxCellSize() {return 8;}; //voxel is the largest
92 
94  virtual void Initialize();
95 
98  virtual void SetDimensions(int i, int j, int k);
99 
103  virtual void SetDimensions(const int dims[3]);
104 
106 
109  virtual int *GetDimensions();
110  virtual void GetDimensions(int dims[3]);
112 
114 
119  virtual int ComputeStructuredCoordinates(
120  const double x[3], int ijk[3], double pcoords[3]);
122 
123  static int ComputeStructuredCoordinates( const double x[3], int ijk[3], double pcoords[3],
124  const int* extent,
125  const double* spacing,
126  const double* origin,
127  const double* bounds);
129 
137  virtual void GetVoxelGradient(
138  int i,int j,int k, vtkDataArray *s, vtkDataArray *g);
140 
142 
147  virtual void GetPointGradient(
148  int i, int j, int k, vtkDataArray *s, double g[3]);
150 
152  virtual int GetDataDimension();
153 
155 
157  virtual vtkIdType ComputePointId(int ijk[3]) {
158  return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);};
160 
162 
164  virtual vtkIdType ComputeCellId(int ijk[3]) {
165  return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);};
167 
169 
170  virtual void SetAxisUpdateExtent(int axis, int min, int max,
171  const int* updateExtent,
172  int* axisUpdateExtent);
173  virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int* updateExtent);
175 
177 
185  virtual void SetExtent(int extent[6]);
186  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
187  vtkGetVector6Macro(Extent, int);
189 
191 
193  virtual double GetScalarTypeMin(vtkInformation* meta_data);
194  virtual double GetScalarTypeMin();
195  virtual double GetScalarTypeMax(vtkInformation* meta_data);
196  virtual double GetScalarTypeMax();
198 
200 
201  virtual int GetScalarSize(vtkInformation* meta_data);
202  virtual int GetScalarSize();
204 
206 
211  virtual vtkIdType *GetIncrements();
212  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
213  virtual void GetIncrements(vtkIdType inc[3]);
214  virtual vtkIdType *GetIncrements(vtkDataArray *scalars);
215  virtual void GetIncrements(vtkDataArray *scalars,
216  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
217  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
219 
221 
232  virtual void GetContinuousIncrements(
233  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
234  virtual void GetContinuousIncrements(vtkDataArray *scalars,
235  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
237 
239 
240  virtual void *GetScalarPointerForExtent(int extent[6]);
241  virtual void *GetScalarPointer(int coordinates[3]);
242  virtual void *GetScalarPointer(int x, int y, int z);
243  virtual void *GetScalarPointer();
245 
247 
248  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
249  virtual void SetScalarComponentFromFloat(
250  int x, int y, int z, int component, float v);
251  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
252  virtual void SetScalarComponentFromDouble(
253  int x, int y, int z, int component, double v);
255 
259  virtual void AllocateScalars(int dataType, int numComponents);
260 
265  virtual void AllocateScalars(vtkInformation* pipeline_info);
266 
268 
272  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
273  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
274  int y0, int y1, int z0, int z1)
275  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
276  this->CopyAndCastFrom(inData, e);}
278 
282  virtual void Crop(const int* updateExtent);
283 
289  virtual unsigned long GetActualMemorySize();
290 
292 
294  vtkSetVector3Macro(Spacing,double);
295  vtkGetVector3Macro(Spacing,double);
297 
299 
305  vtkSetVector3Macro(Origin,double);
306  vtkGetVector3Macro(Origin,double);
308 
309  static void SetScalarType(int, vtkInformation* meta_data);
310  static int GetScalarType(vtkInformation* meta_data);
311  static bool HasScalarType(vtkInformation* meta_data);
312  int GetScalarType();
313  const char* GetScalarTypeAsString()
314  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
315 
317 
319  static void SetNumberOfScalarComponents( int n, vtkInformation* meta_data);
320  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
321  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
322  int GetNumberOfScalarComponents();
324 
327  virtual void CopyInformationFromPipeline(vtkInformation* information);
328 
332  virtual void CopyInformationToPipeline(vtkInformation* information);
333 
337  virtual void PrepareForNewData();
338 
340 
341  virtual void ShallowCopy(vtkDataObject *src);
342  virtual void DeepCopy(vtkDataObject *src);
344 
345  //--------------------------------------------------------------------------
346  // Methods that apply to any array (not just scalars).
347  // I am starting to experiment with generalizing imaging fitlers
348  // to operate on more than just scalars.
349 
351 
354  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
355  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
357 
360  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
361 
366  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
367 
369  virtual int GetExtentType() { return VTK_3D_EXTENT; };
370 
371  //BTX
373 
375  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
376  //ETX
378 
379 protected:
380  vtkImageData();
381  ~vtkImageData();
382 
383  // The extent of what is currently in the structured grid.
384  // Dimensions is just an array to return a value.
385  // Its contents are out of data until GetDimensions is called.
386  int Dimensions[3];
387  vtkIdType Increments[3];
388 
389  double Origin[3];
390  double Spacing[3];
391 
392  int Extent[6];
393 
394  // The first method assumes Active Scalars
395  void ComputeIncrements();
396  // This one is given the number of components of the
397  // scalar field explicitly
398  void ComputeIncrements(int numberOfComponents);
399  void ComputeIncrements(vtkDataArray *scalars);
400 
401  // The first method assumes Acitive Scalars
402  void ComputeIncrements(vtkIdType inc[3]);
403  // This one is given the number of components of the
404  // scalar field explicitly
405  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
406  void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
407  void CopyOriginAndSpacingFromPipeline(vtkInformation* info);
408 
410 
411  void SetDataDescription(int desc);
412  int GetDataDescription() { return this->DataDescription; }
413 
414 private:
415  void InternalImageDataCopy(vtkImageData *src);
416 private:
417 
418  //BTX
419  friend class vtkUniformGrid;
420  //ETX
421 
422  // for the GetCell method
423  vtkVertex *Vertex;
424  vtkLine *Line;
425  vtkPixel *Pixel;
426  vtkVoxel *Voxel;
427 
428  // for the GetPoint method
429  double Point[3];
430 
431  int DataDescription;
432 
433  vtkImageData(const vtkImageData&); // Not implemented.
434  void operator=(const vtkImageData&); // Not implemented.
435 };
436 
437 
438 //----------------------------------------------------------------------------
440 {
441  this->ComputeIncrements(this->Increments);
442 }
443 
444 //----------------------------------------------------------------------------
445 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
446 {
447  this->ComputeIncrements(numberOfComponents, this->Increments);
448 }
449 
450 //----------------------------------------------------------------------------
452 {
453  this->ComputeIncrements(scalars, this->Increments);
454 }
455 
456 //----------------------------------------------------------------------------
458 {
459  this->GetPoint(id, this->Point);
460  return this->Point;
461 }
462 
463 //----------------------------------------------------------------------------
465 {
466  const int *extent = this->Extent;
467  vtkIdType dims[3];
468  dims[0] = extent[1] - extent[0] + 1;
469  dims[1] = extent[3] - extent[2] + 1;
470  dims[2] = extent[5] - extent[4] + 1;
471 
472  return dims[0]*dims[1]*dims[2];
473 }
474 
475 //----------------------------------------------------------------------------
477 {
478  return vtkStructuredData::GetDataDimension(this->DataDescription);
479 }
480 
481 #endif
virtual int GetExtentType()
Definition: vtkImageData.h:369
virtual int GetMaxCellSize()
Definition: vtkImageData.h:90
#define VTK_IMAGE_DATA
Definition: vtkType.h:72
virtual vtkCell * FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)
virtual vtkIdType GetNumberOfCells()=0
unsigned long GetActualMemorySize()
static vtkDataObject * New()
virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)=0
Store vtkAlgorithm input/output information.
virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
Definition: vtkImageData.h:87
virtual vtkIdType GetNumberOfPoints()=0
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
a cell that represents a 3D point
Definition: vtkVertex.h:35
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:61
record modification and/or execution time
Definition: vtkTimeStamp.h:34
static int GetDataDimension(int dataDescription)
a cell that represents an orthogonal quadrilateral
Definition: vtkPixel.h:39
virtual void ComputeBounds()
virtual void PrepareForNewData()
virtual vtkIdType FindPoint(double x, double y, double z)
Definition: vtkImageData.h:68
int vtkIdType
Definition: vtkType.h:275
virtual vtkIdType ComputeCellId(int ijk[3])
Definition: vtkImageData.h:164
static vtkDataSet * GetData(vtkInformation *info)
provides thread-safe access to cells
virtual vtkIdType ComputePointId(int ijk[3])
Definition: vtkImageData.h:157
virtual void Crop(const int *updateExtent)
cell represents a 1D line
Definition: vtkLine.h:34
abstract class to specify cell behavior
Definition: vtkCell.h:61
void PrintSelf(ostream &os, vtkIndent indent)
virtual int GetDataObjectType()
Definition: vtkImageData.h:57
virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, int y0, int y1, int z0, int z1)
Definition: vtkImageData.h:273
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:43
a simple class to control print indentation
Definition: vtkIndent.h:38
static vtkIdType ComputeCellIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
list of point or cell ids
Definition: vtkIdList.h:35
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual double * GetPoint(vtkIdType ptId)
Definition: vtkImageData.h:457
virtual void CopyInformationFromPipeline(vtkInformation *vtkNotUsed(info))
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
Definition: vtkImageData.h:84
int GetDataDescription()
Definition: vtkImageData.h:412
void DeepCopy(vtkDataObject *src)
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
vtkIdType Increments[3]
Definition: vtkImageData.h:387
image data with blanking
static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:313
void ComputeIncrements()
Definition: vtkImageData.h:439
void Initialize()
virtual void CopyStructure(vtkDataSet *ds)=0
Store zero or more vtkInformation instances.
virtual double * GetPoint(vtkIdType ptId)=0
general representation of visualization data
Definition: vtkDataObject.h:64
virtual void CopyInformationToPipeline(vtkInformation *vtkNotUsed(info))
vtkIdType FindPoint(double x, double y, double z)
Definition: vtkDataSet.h:154
virtual vtkIdType GetNumberOfPoints()
Definition: vtkImageData.h:464
#define VTKCOMMONDATAMODEL_EXPORT
virtual vtkCell * GetCell(vtkIdType cellId)=0
#define max(a, b)
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
virtual int GetDataDimension()
Definition: vtkImageData.h:476
virtual int GetCellType(vtkIdType cellId)=0
void ShallowCopy(vtkDataObject *src)
vtkTimeStamp ExtentComputeTime
Definition: vtkImageData.h:409