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 =========================================================================*/
25 #ifndef vtkImageData_h
26 #define vtkImageData_h
27 
28 #include "vtkCommonDataModelModule.h" // For export macro
29 #include "vtkDataSet.h"
30 
31 #include "vtkStructuredData.h" // Needed for inline methods
32 
33 class vtkDataArray;
34 class vtkLine;
35 class vtkPixel;
36 class vtkVertex;
37 class vtkVoxel;
38 
39 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet
40 {
41 public:
42  static vtkImageData *New();
43 
44  vtkTypeMacro(vtkImageData,vtkDataSet);
45  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
46 
51  void CopyStructure(vtkDataSet *ds) VTK_OVERRIDE;
52 
56  int GetDataObjectType() VTK_OVERRIDE {return VTK_IMAGE_DATA;};
57 
59 
62  vtkIdType GetNumberOfCells() VTK_OVERRIDE;
63  vtkIdType GetNumberOfPoints() VTK_OVERRIDE;
64  double *GetPoint(vtkIdType ptId) VTK_OVERRIDE;
65  void GetPoint(vtkIdType id, double x[3]) VTK_OVERRIDE;
66  vtkCell *GetCell(vtkIdType cellId) VTK_OVERRIDE;
67  vtkCell *GetCell(int i, int j, int k) VTK_OVERRIDE;
68  void GetCell(vtkIdType cellId, vtkGenericCell *cell) VTK_OVERRIDE;
69  void GetCellBounds(vtkIdType cellId, double bounds[6]) VTK_OVERRIDE;
70  virtual vtkIdType FindPoint(double x, double y, double z)
71  {
72  return this->vtkDataSet::FindPoint(x, y, z);
73  }
74  vtkIdType FindPoint(double x[3]) VTK_OVERRIDE;
76  double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
77  int& subId, double pcoords[3], double *weights) VTK_OVERRIDE;
79  double x[3], vtkCell *cell, vtkGenericCell *gencell,
80  vtkIdType cellId, double tol2, int& subId,
81  double pcoords[3], double *weights) VTK_OVERRIDE;
82  vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
83  double tol2, int& subId, double pcoords[3],
84  double *weights) VTK_OVERRIDE;
85  int GetCellType(vtkIdType cellId) VTK_OVERRIDE;
86  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) VTK_OVERRIDE
87  {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
88  this->GetDimensions());}
89  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) VTK_OVERRIDE
90  {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
91  void ComputeBounds() VTK_OVERRIDE;
92  int GetMaxCellSize() VTK_OVERRIDE {return 8;}; //voxel is the largest
94 
98  void Initialize() VTK_OVERRIDE;
99 
103  virtual void SetDimensions(int i, int j, int k);
104 
108  virtual void SetDimensions(const int dims[3]);
109 
116  virtual int *GetDimensions();
117 
124  virtual void GetDimensions(int dims[3]);
125 
132  virtual int ComputeStructuredCoordinates(
133  const double x[3], int ijk[3], double pcoords[3]);
134 
135  static int ComputeStructuredCoordinates( const double x[3], int ijk[3], double pcoords[3],
136  const int* extent,
137  const double* spacing,
138  const double* origin,
139  const double* bounds);
149  virtual void GetVoxelGradient(
150  int i,int j,int k, vtkDataArray *s, vtkDataArray *g);
151 
158  virtual void GetPointGradient(
159  int i, int j, int k, vtkDataArray *s, double g[3]);
160 
164  virtual int GetDataDimension();
165 
169  virtual vtkIdType ComputePointId(int ijk[3]) {
170  return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);};
171 
175  virtual vtkIdType ComputeCellId(int ijk[3]) {
176  return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);};
177 
179 
182  virtual void SetAxisUpdateExtent(int axis, int min, int max,
183  const int* updateExtent,
184  int* axisUpdateExtent);
185  virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int* updateExtent);
187 
189 
200  virtual void SetExtent(int extent[6]);
201  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
202  vtkGetVector6Macro(Extent, int);
204 
206 
210  virtual double GetScalarTypeMin(vtkInformation* meta_data);
211  virtual double GetScalarTypeMin();
212  virtual double GetScalarTypeMax(vtkInformation* meta_data);
213  virtual double GetScalarTypeMax();
215 
217 
220  virtual int GetScalarSize(vtkInformation* meta_data);
221  virtual int GetScalarSize();
223 
225 
231  virtual vtkIdType *GetIncrements();
232  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
233  virtual void GetIncrements(vtkIdType inc[3]);
234  virtual vtkIdType *GetIncrements(vtkDataArray *scalars);
235  virtual void GetIncrements(vtkDataArray *scalars,
236  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
237  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
239 
241 
254  virtual void GetContinuousIncrements(
255  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
256  virtual void GetContinuousIncrements(vtkDataArray *scalars,
257  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
259 
261 
264  virtual void *GetScalarPointerForExtent(int extent[6]);
265  virtual void *GetScalarPointer(int coordinates[3]);
266  virtual void *GetScalarPointer(int x, int y, int z);
267  virtual void *GetScalarPointer();
269 
271 
274  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
275  virtual void SetScalarComponentFromFloat(
276  int x, int y, int z, int component, float v);
277  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
278  virtual void SetScalarComponentFromDouble(
279  int x, int y, int z, int component, double v);
281 
287  virtual void AllocateScalars(int dataType, int numComponents);
288 
295  virtual void AllocateScalars(vtkInformation* pipeline_info);
296 
298 
304  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
305  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
306  int y0, int y1, int z0, int z1)
307  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
308  this->CopyAndCastFrom(inData, e);}
310 
316  void Crop(const int* updateExtent) VTK_OVERRIDE;
317 
326  unsigned long GetActualMemorySize() VTK_OVERRIDE;
327 
329 
333  vtkSetVector3Macro(Spacing,double);
334  vtkGetVector3Macro(Spacing,double);
336 
338 
346  vtkSetVector3Macro(Origin,double);
347  vtkGetVector3Macro(Origin,double);
349 
350  static void SetScalarType(int, vtkInformation* meta_data);
351  static int GetScalarType(vtkInformation* meta_data);
352  static bool HasScalarType(vtkInformation* meta_data);
353  int GetScalarType();
354  const char* GetScalarTypeAsString()
355  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
356 
358 
362  static void SetNumberOfScalarComponents( int n, vtkInformation* meta_data);
363  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
364  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
365  int GetNumberOfScalarComponents();
367 
372  void CopyInformationFromPipeline(vtkInformation* information) VTK_OVERRIDE;
373 
379  void CopyInformationToPipeline(vtkInformation* information) VTK_OVERRIDE;
380 
386  void PrepareForNewData() VTK_OVERRIDE;
387 
389 
392  void ShallowCopy(vtkDataObject *src) VTK_OVERRIDE;
393  void DeepCopy(vtkDataObject *src) VTK_OVERRIDE;
395 
396  //--------------------------------------------------------------------------
397  // Methods that apply to any array (not just scalars).
398  // I am starting to experiment with generalizing imaging fitlers
399  // to operate on more than just scalars.
400 
402 
407  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
408  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
410 
415  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
416 
423  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
424 
428  int GetExtentType() VTK_OVERRIDE { return VTK_3D_EXTENT; };
429 
431 
435  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
437 
438 protected:
439  vtkImageData();
440  ~vtkImageData() VTK_OVERRIDE;
441 
442  // The extent of what is currently in the structured grid.
443  // Dimensions is just an array to return a value.
444  // Its contents are out of data until GetDimensions is called.
445  int Dimensions[3];
446  vtkIdType Increments[3];
447 
448  double Origin[3];
449  double Spacing[3];
450 
451  int Extent[6];
452 
453  // The first method assumes Active Scalars
454  void ComputeIncrements();
455  // This one is given the number of components of the
456  // scalar field explicitly
457  void ComputeIncrements(int numberOfComponents);
458  void ComputeIncrements(vtkDataArray *scalars);
459 
460  // The first method assumes Acitive Scalars
461  void ComputeIncrements(vtkIdType inc[3]);
462  // This one is given the number of components of the
463  // scalar field explicitly
464  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
465  void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
466  void CopyOriginAndSpacingFromPipeline(vtkInformation* info);
467 
468  vtkTimeStamp ExtentComputeTime;
469 
470  void SetDataDescription(int desc);
471  int GetDataDescription() { return this->DataDescription; }
472 
473 private:
474  void InternalImageDataCopy(vtkImageData *src);
475 private:
476 
477  friend class vtkUniformGrid;
478 
479  // for the GetCell method
480  vtkVertex *Vertex;
481  vtkLine *Line;
482  vtkPixel *Pixel;
483  vtkVoxel *Voxel;
484 
485  // for the GetPoint method
486  double Point[3];
487 
488  int DataDescription;
489 
490  vtkImageData(const vtkImageData&) VTK_DELETE_FUNCTION;
491  void operator=(const vtkImageData&) VTK_DELETE_FUNCTION;
492 };
493 
494 
495 //----------------------------------------------------------------------------
497 {
498  this->ComputeIncrements(this->Increments);
499 }
500 
501 //----------------------------------------------------------------------------
502 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
503 {
504  this->ComputeIncrements(numberOfComponents, this->Increments);
505 }
506 
507 //----------------------------------------------------------------------------
509 {
510  this->ComputeIncrements(scalars, this->Increments);
511 }
512 
513 //----------------------------------------------------------------------------
515 {
516  this->GetPoint(id, this->Point);
517  return this->Point;
518 }
519 
520 //----------------------------------------------------------------------------
522 {
523  const int *extent = this->Extent;
524  vtkIdType dims[3];
525  dims[0] = extent[1] - extent[0] + 1;
526  dims[1] = extent[3] - extent[2] + 1;
527  dims[2] = extent[5] - extent[4] + 1;
528 
529  return dims[0]*dims[1]*dims[2];
530 }
531 
532 //----------------------------------------------------------------------------
534 {
535  return vtkStructuredData::GetDataDimension(this->DataDescription);
536 }
537 
538 #endif
#define VTK_IMAGE_DATA
Definition: vtkType.h:97
virtual vtkCell * FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)
Locate the cell that contains a point and return the cell.
virtual vtkIdType GetNumberOfCells()=0
Determine the number of cells composing the dataset.
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkImageData.h:56
static vtkDataObject * New()
virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)=0
Locate cell based on global coordinate x and tolerance squared.
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
a cell that represents a 3D point
Definition: vtkVertex.h:30
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:55
record modification and/or execution time
Definition: vtkTimeStamp.h:32
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
a cell that represents an orthogonal quadrilateral
Definition: vtkPixel.h:34
virtual void ComputeBounds()
Compute the data bounding box from data points.
virtual void PrepareForNewData()
make the output data ready for new data to be inserted.
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:86
int vtkIdType
Definition: vtkType.h:345
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:175
static vtkDataSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
provides thread-safe access to cells
void GetPoint(const int i, const int j, const int k, double pnt[3])
vtkIdType GetNumberOfPoints() override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:521
virtual void Crop(const int *updateExtent)
This method crops the data object (if necessary) so that the extent matches the update extent...
double * GetPoint(vtkIdType ptId) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:514
cell represents a 1D line
Definition: vtkLine.h:29
abstract class to specify cell behavior
Definition: vtkCell.h:56
virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, int y0, int y1, int z0, int z1)
This method is passed a input and output region, and executes the filter algorithm to fill the output...
Definition: vtkImageData.h:305
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:38
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
a simple class to control print indentation
Definition: vtkIndent.h:33
static vtkIdType ComputeCellIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset...
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
virtual void CopyInformationFromPipeline(vtkInformation *vtkNotUsed(info))
Copy from the pipeline information to the data object's own information.
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIdType Increments[3]
Definition: vtkImageData.h:446
image data with blanking
static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset...
void Initialize() override
Restore data object to initial state.
void ComputeIncrements()
Definition: vtkImageData.h:496
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:89
virtual void CopyStructure(vtkDataSet *ds)=0
Copy the geometric and topological structure of an object.
Store zero or more vtkInformation instances.
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
general representation of visualization data
Definition: vtkDataObject.h:58
virtual void CopyInformationToPipeline(vtkInformation *vtkNotUsed(info))
Copy information from this data object to the pipeline information.
vtkIdType FindPoint(double x, double y, double z)
Locate the closest point to the global coordinate x.
Definition: vtkDataSet.h:191
#define max(a, b)
virtual int GetDataDimension()
Return the dimensionality of the data.
Definition: vtkImageData.h:533
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int GetCellType(vtkIdType cellId)=0
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.