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 vtkMatrix3x3;
36 class vtkMatrix4x4;
37 class vtkPixel;
38 class vtkVertex;
39 class vtkVoxel;
40 
41 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet
42 {
43 public:
44  static vtkImageData* New();
45 
46  vtkTypeMacro(vtkImageData, vtkDataSet);
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
53  void CopyStructure(vtkDataSet* ds) override;
54 
58  int GetDataObjectType() override { return VTK_IMAGE_DATA; }
59 
61 
68  vtkIdType GetNumberOfCells() override;
69  vtkIdType GetNumberOfPoints() override;
70  double* GetPoint(vtkIdType ptId) VTK_SIZEHINT(3) override;
71  void GetPoint(vtkIdType id, double x[3]) override;
72  vtkCell* GetCell(vtkIdType cellId) override;
73  vtkCell* GetCell(int i, int j, int k) override;
74  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
75  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
76  virtual vtkIdType FindPoint(double x, double y, double z)
77  {
78  return this->vtkDataSet::FindPoint(x, y, z);
79  }
80  vtkIdType FindPoint(double x[3]) override;
81  vtkIdType FindCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
82  double pcoords[3], double* weights) override;
83  vtkIdType FindCell(double x[3], vtkCell* cell, vtkGenericCell* gencell, vtkIdType cellId,
84  double tol2, int& subId, double pcoords[3], double* weights) override;
85  vtkCell* FindAndGetCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
86  double pcoords[3], double* weights) override;
87  int GetCellType(vtkIdType cellId) override;
88  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override
89  {
90  vtkStructuredData::GetCellPoints(cellId, ptIds, this->DataDescription, this->GetDimensions());
91  }
92  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override
93  {
94  vtkStructuredData::GetPointCells(ptId, cellIds, this->GetDimensions());
95  }
96  void ComputeBounds() override;
97  int GetMaxCellSize() override { return 8; } // voxel is the largest
99 
103  void Initialize() override;
104 
108  virtual void SetDimensions(int i, int j, int k);
109 
113  virtual void SetDimensions(const int dims[3]);
114 
121  virtual int* GetDimensions() VTK_SIZEHINT(3);
122 
129  virtual void GetDimensions(int dims[3]);
130 #if VTK_ID_TYPE_IMPL != VTK_INT
131  virtual void GetDimensions(vtkIdType dims[3]);
132 #endif
133 
140  virtual int ComputeStructuredCoordinates(const double x[3], int ijk[3], double pcoords[3]);
141 
151  virtual void GetVoxelGradient(int i, int j, int k, vtkDataArray* s, vtkDataArray* g);
152 
159  virtual void GetPointGradient(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  {
171  return vtkStructuredData::ComputePointIdForExtent(this->Extent, ijk);
172  }
173 
177  virtual vtkIdType ComputeCellId(int ijk[3])
178  {
179  return vtkStructuredData::ComputeCellIdForExtent(this->Extent, ijk);
180  }
181 
183 
186  virtual void SetAxisUpdateExtent(
187  int axis, int min, int max, const int* updateExtent, int* axisUpdateExtent);
188  virtual void GetAxisUpdateExtent(int axis, int& min, int& max, const int* updateExtent);
190 
192 
203  virtual void SetExtent(int extent[6]);
204  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
205  vtkGetVector6Macro(Extent, int);
207 
209 
213  virtual double GetScalarTypeMin(vtkInformation* meta_data);
214  virtual double GetScalarTypeMin();
215  virtual double GetScalarTypeMax(vtkInformation* meta_data);
216  virtual double GetScalarTypeMax();
218 
220 
223  virtual int GetScalarSize(vtkInformation* meta_data);
224  virtual int GetScalarSize();
226 
228 
234  virtual vtkIdType* GetIncrements() VTK_SIZEHINT(3);
235  virtual void GetIncrements(vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
236  virtual void GetIncrements(vtkIdType inc[3]);
237  virtual vtkIdType* GetIncrements(vtkDataArray* scalars) VTK_SIZEHINT(3);
238  virtual void GetIncrements(
239  vtkDataArray* scalars, vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
240  virtual void GetIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
242 
244 
257  virtual void GetContinuousIncrements(
258  int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
259  virtual void GetContinuousIncrements(
260  vtkDataArray* scalars, int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
262 
264 
267  virtual void* GetScalarPointerForExtent(int extent[6]);
268  virtual void* GetScalarPointer(int coordinates[3]);
269  virtual void* GetScalarPointer(int x, int y, int z);
270  virtual void* GetScalarPointer();
272 
274 
277  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
278  virtual void SetScalarComponentFromFloat(int x, int y, int z, int component, float v);
279  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
280  virtual void SetScalarComponentFromDouble(int x, int y, int z, int component, double v);
282 
288  virtual void AllocateScalars(int dataType, int numComponents);
289 
296  virtual void AllocateScalars(vtkInformation* pipeline_info);
297 
299 
305  virtual void CopyAndCastFrom(vtkImageData* inData, int extent[6]);
306  virtual void CopyAndCastFrom(vtkImageData* inData, int x0, int x1, int y0, int y1, int z0, int z1)
307  {
308  int e[6];
309  e[0] = x0;
310  e[1] = x1;
311  e[2] = y0;
312  e[3] = y1;
313  e[4] = z0;
314  e[5] = z1;
315  this->CopyAndCastFrom(inData, e);
316  }
318 
324  void Crop(const int* updateExtent) override;
325 
334  unsigned long GetActualMemorySize() override;
335 
337 
341  vtkGetVector3Macro(Spacing, double);
342  virtual void SetSpacing(double i, double j, double k);
343  virtual void SetSpacing(const double ijk[3]);
345 
347 
355  vtkGetVector3Macro(Origin, double);
356  virtual void SetOrigin(double i, double j, double k);
357  virtual void SetOrigin(const double ijk[3]);
359 
361 
365  vtkGetObjectMacro(DirectionMatrix, vtkMatrix3x3);
366  virtual void SetDirectionMatrix(vtkMatrix3x3* m);
367  virtual void SetDirectionMatrix(const double elements[9]);
368  virtual void SetDirectionMatrix(double e00, double e01, double e02, double e10, double e11,
369  double e12, double e20, double e21, double e22);
371 
373 
377  vtkGetObjectMacro(IndexToPhysicalMatrix, vtkMatrix4x4);
379 
381 
384  virtual void TransformContinuousIndexToPhysicalPoint(double i, double j, double k, double xyz[3]);
385  virtual void TransformContinuousIndexToPhysicalPoint(const double ijk[3], double xyz[3]);
386  virtual void TransformIndexToPhysicalPoint(int i, int j, int k, double xyz[3]);
387  virtual void TransformIndexToPhysicalPoint(const int ijk[3], double xyz[3]);
388  static void TransformContinuousIndexToPhysicalPoint(double i, double j, double k,
389  double const origin[3], double const spacing[3], double const direction[9], double xyz[3]);
391 
393 
397  vtkGetObjectMacro(PhysicalToIndexMatrix, vtkMatrix4x4);
399 
401 
404  virtual void TransformPhysicalPointToContinuousIndex(double x, double y, double z, double ijk[3]);
405  virtual void TransformPhysicalPointToContinuousIndex(const double xyz[3], double ijk[3]);
407 
408  static void ComputeIndexToPhysicalMatrix(
409  double const origin[3], double const spacing[3], double const direction[9], double result[16]);
410 
412 
415  virtual void TransformPhysicalNormalToContinuousIndex(const double xyz[3], double ijk[3]);
417 
421  virtual void TransformPhysicalPlaneToContinuousIndex(double const pplane[4], double iplane[4]);
422 
423  static void SetScalarType(int, vtkInformation* meta_data);
424  static int GetScalarType(vtkInformation* meta_data);
425  static bool HasScalarType(vtkInformation* meta_data);
426  int GetScalarType();
427  const char* GetScalarTypeAsString() { return vtkImageScalarTypeNameMacro(this->GetScalarType()); }
428 
430 
434  static void SetNumberOfScalarComponents(int n, vtkInformation* meta_data);
435  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
436  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
437  int GetNumberOfScalarComponents();
439 
444  void CopyInformationFromPipeline(vtkInformation* information) override;
445 
451  void CopyInformationToPipeline(vtkInformation* information) override;
452 
458  void PrepareForNewData() override;
459 
461 
464  void ShallowCopy(vtkDataObject* src) override;
465  void DeepCopy(vtkDataObject* src) override;
467 
468  //--------------------------------------------------------------------------
469  // Methods that apply to any array (not just scalars).
470  // I am starting to experiment with generalizing imaging filters
471  // to operate on more than just scalars.
472 
474 
479  void* GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
480  void* GetArrayPointer(vtkDataArray* array, int coordinates[3]);
482 
487  void GetArrayIncrements(vtkDataArray* array, vtkIdType increments[3]);
488 
495  void ComputeInternalExtent(int* intExt, int* tgtExt, int* bnds);
496 
500  int GetExtentType() override { return VTK_3D_EXTENT; }
501 
503 
507  static vtkImageData* GetData(vtkInformationVector* v, int i = 0);
509 
510 protected:
511  vtkImageData();
512  ~vtkImageData() override;
513 
514  // The extent of what is currently in the structured grid.
515  // Dimensions is just an array to return a value.
516  // Its contents are out of data until GetDimensions is called.
517  int Dimensions[3];
518  vtkIdType Increments[3];
519 
520  // Variables used to define dataset physical orientation
521  double Origin[3];
522  double Spacing[3];
526 
527  int Extent[6];
528 
529  // The first method assumes Active Scalars
530  void ComputeIncrements();
531  // This one is given the number of components of the
532  // scalar field explicitly
533  void ComputeIncrements(int numberOfComponents);
534  void ComputeIncrements(vtkDataArray* scalars);
535 
536  // The first method assumes Acitive Scalars
537  void ComputeIncrements(vtkIdType inc[3]);
538  // This one is given the number of components of the
539  // scalar field explicitly
540  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
541  void ComputeIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
542 
543  // for the index to physical methods
544  void ComputeTransforms();
545 
546  // Cell utilities
547  vtkCell* GetCellTemplateForDataDescription();
548  bool GetCellTemplateForDataDescription(vtkGenericCell* cell);
549  bool GetIJKMinForCellId(vtkIdType cellId, int ijkMin[3]);
550  bool GetIJKMaxForIJKMin(int ijkMin[3], int ijkMax[3]);
551  void AddPointsToCellTemplate(vtkCell* cell, int ijkMin[3], int ijkMax[3]);
552 
554 
555  void SetDataDescription(int desc);
556  int GetDataDescription() { return this->DataDescription; }
557 
558 private:
559  void InternalImageDataCopy(vtkImageData* src);
560 
561 private:
562  friend class vtkUniformGrid;
563 
564  // for the GetCell method
565  vtkVertex* Vertex;
566  vtkLine* Line;
567  vtkPixel* Pixel;
568  vtkVoxel* Voxel;
569 
570  // for the GetPoint method
571  double Point[3];
572 
573  int DataDescription;
574 
575  vtkImageData(const vtkImageData&) = delete;
576  void operator=(const vtkImageData&) = delete;
577 };
578 
579 //----------------------------------------------------------------------------
581 {
582  this->ComputeIncrements(this->Increments);
583 }
584 
585 //----------------------------------------------------------------------------
586 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
587 {
588  this->ComputeIncrements(numberOfComponents, this->Increments);
589 }
590 
591 //----------------------------------------------------------------------------
593 {
594  this->ComputeIncrements(scalars, this->Increments);
595 }
596 
597 //----------------------------------------------------------------------------
599 {
600  this->GetPoint(id, this->Point);
601  return this->Point;
602 }
603 
604 //----------------------------------------------------------------------------
606 {
607  const int* extent = this->Extent;
608  vtkIdType dims[3];
609  dims[0] = extent[1] - extent[0] + 1;
610  dims[1] = extent[3] - extent[2] + 1;
611  dims[2] = extent[5] - extent[4] + 1;
612 
613  return dims[0] * dims[1] * dims[2];
614 }
615 
616 //----------------------------------------------------------------------------
618 {
619  return vtkStructuredData::GetDataDimension(this->DataDescription);
620 }
621 
622 #endif
vtkDataSet::GetNumberOfPoints
virtual vtkIdType GetNumberOfPoints()=0
Determine the number of points composing the dataset.
vtkDataSet::GetActualMemorySize
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
vtkStructuredData::GetDataDimension
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
vtkDataSet::ShallowCopy
void ShallowCopy(vtkDataObject *src) override
Shallow and Deep copy.
vtkImageData::GetCellPoints
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Topological inquiry to get points defining cell.
Definition: vtkImageData.h:88
vtkImageData::IndexToPhysicalMatrix
vtkMatrix4x4 * IndexToPhysicalMatrix
Definition: vtkImageData.h:524
vtkX3D::component
Definition: vtkX3D.h:181
vtkImageData::GetMaxCellSize
int GetMaxCellSize() override
Convenience method returns largest cell size in dataset.
Definition: vtkImageData.h:97
vtkIdType
int vtkIdType
Definition: vtkType.h:349
vtkImageData::ExtentComputeTime
vtkTimeStamp ExtentComputeTime
Definition: vtkImageData.h:553
vtkX3D::direction
Definition: vtkX3D.h:266
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkImageData::ComputePointId
virtual vtkIdType ComputePointId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the point id.
Definition: vtkImageData.h:169
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
VTK_IMAGE_DATA
#define VTK_IMAGE_DATA
Definition: vtkType.h:97
vtkUniformGrid
image data with blanking
Definition: vtkUniformGrid.h:34
vtkDataSet::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkImageData::GetExtentType
int GetExtentType() override
The extent type is a 3D extent.
Definition: vtkImageData.h:500
vtkDataObject::CopyInformationFromPipeline
virtual void CopyInformationFromPipeline(vtkInformation *vtkNotUsed(info))
Copy from the pipeline information to the data object's own information.
Definition: vtkDataObject.h:145
vtkDataSet::GetData
static vtkDataSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkVertex
a cell that represents a 3D point
Definition: vtkVertex.h:30
vtkMatrix3x3
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:33
vtkDataSet::FindCell
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.
vtkLine
cell represents a 1D line
Definition: vtkLine.h:29
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkImageData::Extent
int Extent[6]
Definition: vtkImageData.h:527
VTK_3D_EXTENT
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:55
vtkImageData::PhysicalToIndexMatrix
vtkMatrix4x4 * PhysicalToIndexMatrix
Definition: vtkImageData.h:525
vtkDataSet::ComputeBounds
virtual void ComputeBounds()
Compute the data bounding box from data points.
vtkStructuredData.h
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkStructuredData::GetCellPoints
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
vtkImageData::ComputeCellId
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:177
vtkDataSet::FindPoint
vtkIdType FindPoint(double x, double y, double z)
Locate the closest point to the global coordinate x.
Definition: vtkDataSet.h:191
vtkImageData::FindPoint
virtual vtkIdType FindPoint(double x, double y, double z)
Definition: vtkImageData.h:76
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:56
vtkStructuredData::GetPointCells
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
vtkImageData::GetPoint
double * GetPoint(vtkIdType ptId) override
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
Definition: vtkImageData.h:598
vtkDataObject::PrepareForNewData
virtual void PrepareForNewData()
make the output data ready for new data to be inserted.
Definition: vtkDataObject.h:216
vtkDataSet::Initialize
void Initialize() override
Restore data object to initial state.
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkImageData::GetPointCells
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Topological inquiry to get cells using point.
Definition: vtkImageData.h:92
vtkImageData::GetNumberOfPoints
vtkIdType GetNumberOfPoints() override
Determine the number of points composing the dataset.
Definition: vtkImageData.h:605
vtkDataObject::Crop
virtual void Crop(const int *updateExtent)
This method crops the data object (if necessary) so that the extent matches the update extent.
vtkDataObject::CopyInformationToPipeline
virtual void CopyInformationToPipeline(vtkInformation *vtkNotUsed(info))
Copy information from this data object to the pipeline information.
Definition: vtkDataObject.h:152
vtkDataSet.h
vtkX3D::spacing
Definition: vtkX3D.h:487
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:64
vtkX3D::info
Definition: vtkX3D.h:382
vtkDataSet::GetPoint
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
vtkPixel
a cell that represents an orthogonal quadrilateral
Definition: vtkPixel.h:34
vtkDataSet::CopyStructure
virtual void CopyStructure(vtkDataSet *ds)=0
Copy the geometric and topological structure of an object.
vtkImageData::GetDataDescription
int GetDataDescription()
Definition: vtkImageData.h:556
vtkImageData::GetDataDimension
virtual int GetDataDimension()
Return the dimensionality of the data.
Definition: vtkImageData.h:617
vtkGenericCell
provides thread-safe access to cells
Definition: vtkGenericCell.h:36
vtkImageData::Increments
vtkIdType Increments[3]
Definition: vtkImageData.h:518
vtkImageData::DirectionMatrix
vtkMatrix3x3 * DirectionMatrix
Definition: vtkImageData.h:523
vtkX3D::extent
Definition: vtkX3D.h:351
vtkDataSet::GetNumberOfCells
virtual vtkIdType GetNumberOfCells()=0
Determine the number of cells composing the dataset.
vtkImageData::GetDataObjectType
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkImageData.h:58
vtkStructuredData::ComputeCellIdForExtent
static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset,...
Definition: vtkStructuredData.h:381
vtkImageData::ComputeIncrements
void ComputeIncrements()
Definition: vtkImageData.h:580
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:58
vtkDataSet::GetCellType
virtual int GetCellType(vtkIdType cellId)=0
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkDataSet::GetCellBounds
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkImageData::GetScalarTypeAsString
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:427
vtkDataSet::FindAndGetCell
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.
vtkStructuredData::ComputePointIdForExtent
static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset,...
Definition: vtkStructuredData.h:368
vtkDataSet::DeepCopy
void DeepCopy(vtkDataObject *src) override
vtkImageData::vtkImageData
vtkImageData()
vtkDataObject::New
static vtkDataObject * New()
vtkDataSet::GetCell
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkVoxel
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:38