VTK  9.3.1
vtkImageData.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
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 VTK_ABI_NAMESPACE_BEGIN
34 class vtkDataArray;
35 class vtkLine;
36 class vtkMatrix3x3;
37 class vtkMatrix4x4;
38 class vtkPixel;
39 class vtkVertex;
40 class vtkVoxel;
41 
42 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet
43 {
44 public:
45  static vtkImageData* New();
46  static vtkImageData* ExtendedNew();
47 
48  vtkTypeMacro(vtkImageData, vtkDataSet);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
55  void CopyStructure(vtkDataSet* ds) override;
56 
60  int GetDataObjectType() override { return VTK_IMAGE_DATA; }
61 
63 
70  vtkIdType GetNumberOfCells() override;
71  vtkIdType GetNumberOfPoints() override;
72  double* GetPoint(vtkIdType ptId) VTK_SIZEHINT(3) override;
73  void GetPoint(vtkIdType id, double x[3]) override;
74  vtkCell* GetCell(vtkIdType cellId) override;
75  vtkCell* GetCell(int i, int j, int k) override;
76  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
77  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
78  virtual vtkIdType FindPoint(double x, double y, double z)
79  {
80  return this->vtkDataSet::FindPoint(x, y, z);
81  }
82  vtkIdType FindPoint(double x[3]) override;
83  vtkIdType FindCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
84  double pcoords[3], double* weights) override;
85  vtkIdType FindCell(double x[3], vtkCell* cell, vtkGenericCell* gencell, vtkIdType cellId,
86  double tol2, int& subId, double pcoords[3], double* weights) override;
87  vtkCell* FindAndGetCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
88  double pcoords[3], double* weights) override;
89  int GetCellType(vtkIdType cellId) override;
90  vtkIdType GetCellSize(vtkIdType cellId) override;
92  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override
93  {
94  int dimensions[3];
95  this->GetDimensions(dimensions);
96  vtkStructuredData::GetCellPoints(cellId, ptIds, this->DataDescription, dimensions);
97  }
98  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override
99  {
100  int dimensions[3];
101  this->GetDimensions(dimensions);
102  vtkStructuredData::GetPointCells(ptId, cellIds, dimensions);
103  }
104  void ComputeBounds() override;
105  int GetMaxCellSize() override { return 8; } // voxel is the largest
106  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds) override;
108 
116  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int* seedLoc);
117 
121  void Initialize() override;
122 
128  unsigned char IsPointVisible(vtkIdType ptId);
129 
135  unsigned char IsCellVisible(vtkIdType cellId);
136 
141  bool HasAnyBlankPoints() override;
146  bool HasAnyBlankCells() override;
147 
154  void GetCellDims(int cellDims[3]);
155 
159  virtual void SetDimensions(int i, int j, int k);
160 
164  virtual void SetDimensions(const int dims[3]);
165 
172  virtual int* GetDimensions() VTK_SIZEHINT(3);
173 
180  virtual void GetDimensions(int dims[3]);
181 #if VTK_ID_TYPE_IMPL != VTK_INT
182  virtual void GetDimensions(vtkIdType dims[3]);
183 #endif
184 
191  virtual int ComputeStructuredCoordinates(const double x[3], int ijk[3], double pcoords[3]);
192 
202  virtual void GetVoxelGradient(int i, int j, int k, vtkDataArray* s, vtkDataArray* g);
203 
210  virtual void GetPointGradient(int i, int j, int k, vtkDataArray* s, double g[3]);
211 
215  virtual int GetDataDimension();
216 
220  virtual vtkIdType ComputePointId(int ijk[3])
221  {
222  return vtkStructuredData::ComputePointIdForExtent(this->Extent, ijk);
223  }
224 
228  virtual vtkIdType ComputeCellId(int ijk[3])
229  {
230  return vtkStructuredData::ComputeCellIdForExtent(this->Extent, ijk);
231  }
232 
234 
237  virtual void SetAxisUpdateExtent(
238  int axis, int min, int max, const int* updateExtent, int* axisUpdateExtent);
239  virtual void GetAxisUpdateExtent(int axis, int& min, int& max, const int* updateExtent);
241 
243 
254  virtual void SetExtent(int extent[6]);
255  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
256  vtkGetVector6Macro(Extent, int);
258 
260 
264  virtual double GetScalarTypeMin(vtkInformation* meta_data);
265  virtual double GetScalarTypeMin();
266  virtual double GetScalarTypeMax(vtkInformation* meta_data);
267  virtual double GetScalarTypeMax();
269 
271 
274  virtual int GetScalarSize(vtkInformation* meta_data);
275  virtual int GetScalarSize();
277 
279 
290  virtual vtkIdType* GetIncrements() VTK_SIZEHINT(3);
291  virtual void GetIncrements(vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
292  virtual void GetIncrements(vtkIdType inc[3]);
293  virtual vtkIdType* GetIncrements(vtkDataArray* scalars) VTK_SIZEHINT(3);
294  virtual void GetIncrements(
295  vtkDataArray* scalars, vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
296  virtual void GetIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
298 
300 
313  virtual void GetContinuousIncrements(
314  int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
315  virtual void GetContinuousIncrements(
316  vtkDataArray* scalars, int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
318 
320 
323  virtual void* GetScalarPointerForExtent(int extent[6]);
324  virtual void* GetScalarPointer(int coordinates[3]);
325  virtual void* GetScalarPointer(int x, int y, int z);
326  virtual void* GetScalarPointer();
328 
330 
333  virtual vtkIdType GetScalarIndexForExtent(int extent[6]);
334  virtual vtkIdType GetScalarIndex(int coordinates[3]);
335  virtual vtkIdType GetScalarIndex(int x, int y, int z);
337 
339 
342  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
343  virtual void SetScalarComponentFromFloat(int x, int y, int z, int component, float v);
344  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
345  virtual void SetScalarComponentFromDouble(int x, int y, int z, int component, double v);
347 
353  virtual void AllocateScalars(int dataType, int numComponents);
354 
361  virtual void AllocateScalars(vtkInformation* pipeline_info);
362 
364 
370  virtual void CopyAndCastFrom(vtkImageData* inData, int extent[6]);
371  virtual void CopyAndCastFrom(vtkImageData* inData, int x0, int x1, int y0, int y1, int z0, int z1)
372  {
373  int e[6];
374  e[0] = x0;
375  e[1] = x1;
376  e[2] = y0;
377  e[3] = y1;
378  e[4] = z0;
379  e[5] = z1;
380  this->CopyAndCastFrom(inData, e);
381  }
383 
389  void Crop(const int* updateExtent) override;
390 
399  unsigned long GetActualMemorySize() override;
400 
402 
406  vtkGetVector3Macro(Spacing, double);
407  virtual void SetSpacing(double i, double j, double k);
408  virtual void SetSpacing(const double ijk[3]);
410 
412 
420  vtkGetVector3Macro(Origin, double);
421  virtual void SetOrigin(double i, double j, double k);
422  virtual void SetOrigin(const double ijk[3]);
424 
426 
430  vtkGetObjectMacro(DirectionMatrix, vtkMatrix3x3);
431  virtual void SetDirectionMatrix(vtkMatrix3x3* m);
432  virtual void SetDirectionMatrix(const double elements[9]);
433  virtual void SetDirectionMatrix(double e00, double e01, double e02, double e10, double e11,
434  double e12, double e20, double e21, double e22);
436 
438 
442  vtkGetObjectMacro(IndexToPhysicalMatrix, vtkMatrix4x4);
444 
446 
449  virtual void TransformContinuousIndexToPhysicalPoint(double i, double j, double k, double xyz[3]);
450  virtual void TransformContinuousIndexToPhysicalPoint(const double ijk[3], double xyz[3]);
451  virtual void TransformIndexToPhysicalPoint(int i, int j, int k, double xyz[3]);
452  virtual void TransformIndexToPhysicalPoint(const int ijk[3], double xyz[3]);
453  static void TransformContinuousIndexToPhysicalPoint(double i, double j, double k,
454  double const origin[3], double const spacing[3], double const direction[9], double xyz[3]);
456 
458 
462  vtkGetObjectMacro(PhysicalToIndexMatrix, vtkMatrix4x4);
464 
466 
469  virtual void TransformPhysicalPointToContinuousIndex(double x, double y, double z, double ijk[3]);
470  virtual void TransformPhysicalPointToContinuousIndex(const double xyz[3], double ijk[3]);
472 
473  static void ComputeIndexToPhysicalMatrix(
474  double const origin[3], double const spacing[3], double const direction[9], double result[16]);
475 
477 
480  virtual void TransformPhysicalNormalToContinuousIndex(const double xyz[3], double ijk[3]);
482 
487  virtual void TransformPhysicalPlaneToContinuousIndex(double const pplane[4], double iplane[4]);
488 
489  static void SetScalarType(int, vtkInformation* meta_data);
490  static int GetScalarType(vtkInformation* meta_data);
491  static bool HasScalarType(vtkInformation* meta_data);
492  int GetScalarType();
493  const char* GetScalarTypeAsString() { return vtkImageScalarTypeNameMacro(this->GetScalarType()); }
494 
496 
500  static void SetNumberOfScalarComponents(int n, vtkInformation* meta_data);
501  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
502  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
503  int GetNumberOfScalarComponents();
505 
510  void CopyInformationFromPipeline(vtkInformation* information) override;
511 
517  void CopyInformationToPipeline(vtkInformation* information) override;
518 
524  void PrepareForNewData() override;
525 
527 
530  void ShallowCopy(vtkDataObject* src) override;
531  void DeepCopy(vtkDataObject* src) override;
533 
534  //--------------------------------------------------------------------------
535  // Methods that apply to any array (not just scalars).
536  // I am starting to experiment with generalizing imaging filters
537  // to operate on more than just scalars.
538 
540 
545  void* GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
546  void* GetArrayPointer(vtkDataArray* array, int coordinates[3]);
548 
550 
557  vtkIdType GetTupleIndex(vtkDataArray* array, int coordinates[3]);
559 
564  void GetArrayIncrements(vtkDataArray* array, vtkIdType increments[3]);
565 
572  void ComputeInternalExtent(int* intExt, int* tgtExt, int* bnds);
573 
577  int GetExtentType() override { return VTK_3D_EXTENT; }
578 
580 
584  static vtkImageData* GetData(vtkInformationVector* v, int i = 0);
586 
587 protected:
588  vtkImageData();
589  ~vtkImageData() override;
590 
591  // The extent of what is currently in the structured grid.
592  // Dimensions is just an array to return a value.
593  // Its contents are out of data until GetDimensions is called.
594  int Dimensions[3];
595  vtkIdType Increments[3];
596 
597  // Variables used to define dataset physical orientation
598  double Origin[3];
599  double Spacing[3];
603 
604  int Extent[6];
605 
606  // The first method assumes Active Scalars
607  void ComputeIncrements();
608  // This one is given the number of components of the
609  // scalar field explicitly
610  void ComputeIncrements(int numberOfComponents);
611  void ComputeIncrements(vtkDataArray* scalars);
612 
613  // The first method assumes Acitive Scalars
614  void ComputeIncrements(vtkIdType inc[3]);
615  // This one is given the number of components of the
616  // scalar field explicitly
617  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
618  void ComputeIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
619 
620  // for the index to physical methods
621  void ComputeTransforms();
622 
623  // Cell utilities
624  vtkCell* GetCellTemplateForDataDescription();
625  bool GetCellTemplateForDataDescription(vtkGenericCell* cell);
626  bool GetIJKMinForCellId(vtkIdType cellId, int ijkMin[3]);
627  bool GetIJKMaxForIJKMin(int ijkMin[3], int ijkMax[3]);
628  void AddPointsToCellTemplate(vtkCell* cell, int ijkMin[3], int ijkMax[3]);
629 
631 
632  void SetDataDescription(int desc);
633  int GetDataDescription() { return this->DataDescription; }
634 
635 private:
636  void InternalImageDataCopy(vtkImageData* src);
637 
638  friend class vtkUniformGrid;
639 
640  // for the GetCell method
641  vtkVertex* Vertex;
642  vtkLine* Line;
643  vtkPixel* Pixel;
644  vtkVoxel* Voxel;
645 
646  // for the GetPoint method
647  double Point[3];
648 
649  int DataDescription;
650 
651  vtkImageData(const vtkImageData&) = delete;
652  void operator=(const vtkImageData&) = delete;
653 };
654 
655 //----------------------------------------------------------------------------
657 {
658  this->ComputeIncrements(this->Increments);
659 }
660 
661 //----------------------------------------------------------------------------
662 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
663 {
664  this->ComputeIncrements(numberOfComponents, this->Increments);
665 }
666 
667 //----------------------------------------------------------------------------
669 {
670  this->ComputeIncrements(scalars, this->Increments);
671 }
672 
673 //----------------------------------------------------------------------------
675 {
676  this->GetPoint(id, this->Point);
677  return this->Point;
678 }
679 
680 //----------------------------------------------------------------------------
682 {
683  const int* extent = this->Extent;
684  vtkIdType dims[3];
685  dims[0] = extent[1] - extent[0] + 1;
686  dims[1] = extent[3] - extent[2] + 1;
687  dims[2] = extent[5] - extent[4] + 1;
688 
689  return dims[0] * dims[1] * dims[2];
690 }
691 
692 //----------------------------------------------------------------------------
694 {
695  return vtkStructuredData::GetDataDimension(this->DataDescription);
696 }
697 
698 VTK_ABI_NAMESPACE_END
699 #endif
int GetExtentType() override
The extent type is a 3D extent.
Definition: vtkImageData.h:577
vtkMatrix3x3 * DirectionMatrix
Definition: vtkImageData.h:600
#define VTK_IMAGE_DATA
Definition: vtkType.h:71
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:60
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
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.
virtual vtkIdType GetNumberOfPoints()=0
Determine the number of points composing the dataset.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:52
a cell that represents a 3D point
Definition: vtkVertex.h:22
virtual vtkIdType GetCellSize(vtkIdType cellId)
Get the size of cell with cellId such that: 0 <= cellId < NumberOfCells.
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:51
record modification and/or execution time
Definition: vtkTimeStamp.h:24
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:26
vtkMatrix4x4 * PhysicalToIndexMatrix
Definition: vtkImageData.h:602
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.
int GetMaxCellSize() override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:105
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:92
virtual vtkIdType FindPoint(double x, double y, double z)
Standard vtkDataSet API methods.
Definition: vtkImageData.h:78
vtkMatrix4x4 * IndexToPhysicalMatrix
Definition: vtkImageData.h:601
int vtkIdType
Definition: vtkType.h:315
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:228
virtual bool HasAnyBlankCells()
Returns 1 if there are any blanking cells 0 otherwise.
Definition: vtkDataSet.h:473
static vtkDataSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
provides thread-safe access to cells
vtkIdType GetNumberOfPoints() override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:681
virtual vtkIdType ComputePointId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the point id.
Definition: vtkImageData.h:220
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:674
cell represents a 1D line
Definition: vtkLine.h:22
abstract class to specify cell behavior
Definition: vtkCell.h:49
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:30
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:28
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
virtual bool HasAnyBlankPoints()
Returns 1 if there are any blanking points 0 otherwise.
Definition: vtkDataSet.h:479
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
list of point or cell ids
Definition: vtkIdList.h:22
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)=0
Topological inquiry to get points defining cell.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual void CopyInformationFromPipeline(vtkInformation *vtkNotUsed(info))
Copy from the pipeline information to the data object's own information.
void DeepCopy(vtkDataObject *src) override
Shallow and Deep copy.
virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds)
Topological inquiry to get all cells using list of points exclusive of cell specified (e...
#define VTK_SIZEHINT(...)
int GetDataDescription()
Definition: vtkImageData.h:633
vtkIdType Increments[3]
Definition: vtkImageData.h:595
image data with blanking
void Initialize() override
Restore data object to initial state.
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:493
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...
void ComputeIncrements()
Definition: vtkImageData.h:656
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:98
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...
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, VTK_FUTURE_CONST int dim[3])
Get the cells using a point.
virtual void CopyStructure(vtkDataSet *ds)=0
Copy the geometric and topological structure of an object.
void ShallowCopy(vtkDataObject *src) override
Shallow and Deep copy.
Store zero or more vtkInformation instances.
virtual double * GetPoint(vtkIdType ptId)=0
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:25
general representation of visualization data
Definition: vtkDataObject.h:54
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:233
virtual vtkCell * GetCell(vtkIdType cellId)=0
Get cell with cellId such that: 0 <= cellId < NumberOfCells.
#define max(a, b)
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
Get the bounds of the cell with cellId such that: 0 <= cellId < NumberOfCells.
virtual int GetDataDimension()
Return the dimensionality of the data.
Definition: vtkImageData.h:693
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.
vtkTimeStamp ExtentComputeTime
Definition: vtkImageData.h:630