VTK  9.2.6
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 =========================================================================*/
37 #ifndef vtkImageData_h
38 #define vtkImageData_h
39 
40 #include "vtkCommonDataModelModule.h" // For export macro
41 #include "vtkDataSet.h"
42 
43 #include "vtkStructuredData.h" // Needed for inline methods
44 
45 class vtkDataArray;
46 class vtkLine;
47 class vtkMatrix3x3;
48 class vtkMatrix4x4;
49 class vtkPixel;
50 class vtkVertex;
51 class vtkVoxel;
52 
53 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet
54 {
55 public:
56  static vtkImageData* New();
57  static vtkImageData* ExtendedNew();
58 
59  vtkTypeMacro(vtkImageData, vtkDataSet);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
66  void CopyStructure(vtkDataSet* ds) override;
67 
71  int GetDataObjectType() override { return VTK_IMAGE_DATA; }
72 
74 
81  vtkIdType GetNumberOfCells() override;
82  vtkIdType GetNumberOfPoints() override;
83  double* GetPoint(vtkIdType ptId) VTK_SIZEHINT(3) override;
84  void GetPoint(vtkIdType id, double x[3]) override;
85  vtkCell* GetCell(vtkIdType cellId) override;
86  vtkCell* GetCell(int i, int j, int k) override;
87  void GetCell(vtkIdType cellId, vtkGenericCell* cell) override;
88  void GetCellBounds(vtkIdType cellId, double bounds[6]) override;
89  virtual vtkIdType FindPoint(double x, double y, double z)
90  {
91  return this->vtkDataSet::FindPoint(x, y, z);
92  }
93  vtkIdType FindPoint(double x[3]) override;
94  vtkIdType FindCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
95  double pcoords[3], double* weights) override;
96  vtkIdType FindCell(double x[3], vtkCell* cell, vtkGenericCell* gencell, vtkIdType cellId,
97  double tol2, int& subId, double pcoords[3], double* weights) override;
98  vtkCell* FindAndGetCell(double x[3], vtkCell* cell, vtkIdType cellId, double tol2, int& subId,
99  double pcoords[3], double* weights) override;
100  int GetCellType(vtkIdType cellId) override;
101  vtkIdType GetCellSize(vtkIdType cellId) override;
103  void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds) override
104  {
105  int dimensions[3];
106  this->GetDimensions(dimensions);
107  vtkStructuredData::GetCellPoints(cellId, ptIds, this->DataDescription, dimensions);
108  }
109  void GetPointCells(vtkIdType ptId, vtkIdList* cellIds) override
110  {
111  int dimensions[3];
112  this->GetDimensions(dimensions);
113  vtkStructuredData::GetPointCells(ptId, cellIds, dimensions);
114  }
115  void ComputeBounds() override;
116  int GetMaxCellSize() override { return 8; } // voxel is the largest
117  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds) override;
119 
127  void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int* seedLoc);
128 
132  void Initialize() override;
133 
139  unsigned char IsPointVisible(vtkIdType ptId);
140 
146  unsigned char IsCellVisible(vtkIdType cellId);
147 
152  bool HasAnyBlankPoints() override;
157  bool HasAnyBlankCells() override;
158 
165  void GetCellDims(int cellDims[3]);
166 
170  virtual void SetDimensions(int i, int j, int k);
171 
175  virtual void SetDimensions(const int dims[3]);
176 
183  virtual int* GetDimensions() VTK_SIZEHINT(3);
184 
191  virtual void GetDimensions(int dims[3]);
192 #if VTK_ID_TYPE_IMPL != VTK_INT
193  virtual void GetDimensions(vtkIdType dims[3]);
194 #endif
195 
202  virtual int ComputeStructuredCoordinates(const double x[3], int ijk[3], double pcoords[3]);
203 
213  virtual void GetVoxelGradient(int i, int j, int k, vtkDataArray* s, vtkDataArray* g);
214 
221  virtual void GetPointGradient(int i, int j, int k, vtkDataArray* s, double g[3]);
222 
226  virtual int GetDataDimension();
227 
231  virtual vtkIdType ComputePointId(int ijk[3])
232  {
233  return vtkStructuredData::ComputePointIdForExtent(this->Extent, ijk);
234  }
235 
239  virtual vtkIdType ComputeCellId(int ijk[3])
240  {
241  return vtkStructuredData::ComputeCellIdForExtent(this->Extent, ijk);
242  }
243 
245 
248  virtual void SetAxisUpdateExtent(
249  int axis, int min, int max, const int* updateExtent, int* axisUpdateExtent);
250  virtual void GetAxisUpdateExtent(int axis, int& min, int& max, const int* updateExtent);
252 
254 
265  virtual void SetExtent(int extent[6]);
266  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
267  vtkGetVector6Macro(Extent, int);
269 
271 
275  virtual double GetScalarTypeMin(vtkInformation* meta_data);
276  virtual double GetScalarTypeMin();
277  virtual double GetScalarTypeMax(vtkInformation* meta_data);
278  virtual double GetScalarTypeMax();
280 
282 
285  virtual int GetScalarSize(vtkInformation* meta_data);
286  virtual int GetScalarSize();
288 
290 
301  virtual vtkIdType* GetIncrements() VTK_SIZEHINT(3);
302  virtual void GetIncrements(vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
303  virtual void GetIncrements(vtkIdType inc[3]);
304  virtual vtkIdType* GetIncrements(vtkDataArray* scalars) VTK_SIZEHINT(3);
305  virtual void GetIncrements(
306  vtkDataArray* scalars, vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
307  virtual void GetIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
309 
311 
324  virtual void GetContinuousIncrements(
325  int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
326  virtual void GetContinuousIncrements(
327  vtkDataArray* scalars, int extent[6], vtkIdType& incX, vtkIdType& incY, vtkIdType& incZ);
329 
331 
334  virtual void* GetScalarPointerForExtent(int extent[6]);
335  virtual void* GetScalarPointer(int coordinates[3]);
336  virtual void* GetScalarPointer(int x, int y, int z);
337  virtual void* GetScalarPointer();
339 
341 
344  virtual vtkIdType GetScalarIndexForExtent(int extent[6]);
345  virtual vtkIdType GetScalarIndex(int coordinates[3]);
346  virtual vtkIdType GetScalarIndex(int x, int y, int z);
348 
350 
353  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
354  virtual void SetScalarComponentFromFloat(int x, int y, int z, int component, float v);
355  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
356  virtual void SetScalarComponentFromDouble(int x, int y, int z, int component, double v);
358 
364  virtual void AllocateScalars(int dataType, int numComponents);
365 
372  virtual void AllocateScalars(vtkInformation* pipeline_info);
373 
375 
381  virtual void CopyAndCastFrom(vtkImageData* inData, int extent[6]);
382  virtual void CopyAndCastFrom(vtkImageData* inData, int x0, int x1, int y0, int y1, int z0, int z1)
383  {
384  int e[6];
385  e[0] = x0;
386  e[1] = x1;
387  e[2] = y0;
388  e[3] = y1;
389  e[4] = z0;
390  e[5] = z1;
391  this->CopyAndCastFrom(inData, e);
392  }
394 
400  void Crop(const int* updateExtent) override;
401 
410  unsigned long GetActualMemorySize() override;
411 
413 
417  vtkGetVector3Macro(Spacing, double);
418  virtual void SetSpacing(double i, double j, double k);
419  virtual void SetSpacing(const double ijk[3]);
421 
423 
431  vtkGetVector3Macro(Origin, double);
432  virtual void SetOrigin(double i, double j, double k);
433  virtual void SetOrigin(const double ijk[3]);
435 
437 
441  vtkGetObjectMacro(DirectionMatrix, vtkMatrix3x3);
442  virtual void SetDirectionMatrix(vtkMatrix3x3* m);
443  virtual void SetDirectionMatrix(const double elements[9]);
444  virtual void SetDirectionMatrix(double e00, double e01, double e02, double e10, double e11,
445  double e12, double e20, double e21, double e22);
447 
449 
453  vtkGetObjectMacro(IndexToPhysicalMatrix, vtkMatrix4x4);
455 
457 
460  virtual void TransformContinuousIndexToPhysicalPoint(double i, double j, double k, double xyz[3]);
461  virtual void TransformContinuousIndexToPhysicalPoint(const double ijk[3], double xyz[3]);
462  virtual void TransformIndexToPhysicalPoint(int i, int j, int k, double xyz[3]);
463  virtual void TransformIndexToPhysicalPoint(const int ijk[3], double xyz[3]);
464  static void TransformContinuousIndexToPhysicalPoint(double i, double j, double k,
465  double const origin[3], double const spacing[3], double const direction[9], double xyz[3]);
467 
469 
473  vtkGetObjectMacro(PhysicalToIndexMatrix, vtkMatrix4x4);
475 
477 
480  virtual void TransformPhysicalPointToContinuousIndex(double x, double y, double z, double ijk[3]);
481  virtual void TransformPhysicalPointToContinuousIndex(const double xyz[3], double ijk[3]);
483 
484  static void ComputeIndexToPhysicalMatrix(
485  double const origin[3], double const spacing[3], double const direction[9], double result[16]);
486 
488 
491  virtual void TransformPhysicalNormalToContinuousIndex(const double xyz[3], double ijk[3]);
493 
498  virtual void TransformPhysicalPlaneToContinuousIndex(double const pplane[4], double iplane[4]);
499 
500  static void SetScalarType(int, vtkInformation* meta_data);
501  static int GetScalarType(vtkInformation* meta_data);
502  static bool HasScalarType(vtkInformation* meta_data);
503  int GetScalarType();
504  const char* GetScalarTypeAsString() { return vtkImageScalarTypeNameMacro(this->GetScalarType()); }
505 
507 
511  static void SetNumberOfScalarComponents(int n, vtkInformation* meta_data);
512  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
513  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
514  int GetNumberOfScalarComponents();
516 
521  void CopyInformationFromPipeline(vtkInformation* information) override;
522 
528  void CopyInformationToPipeline(vtkInformation* information) override;
529 
535  void PrepareForNewData() override;
536 
538 
541  void ShallowCopy(vtkDataObject* src) override;
542  void DeepCopy(vtkDataObject* src) override;
544 
545  //--------------------------------------------------------------------------
546  // Methods that apply to any array (not just scalars).
547  // I am starting to experiment with generalizing imaging filters
548  // to operate on more than just scalars.
549 
551 
556  void* GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
557  void* GetArrayPointer(vtkDataArray* array, int coordinates[3]);
559 
561 
568  vtkIdType GetTupleIndex(vtkDataArray* array, int coordinates[3]);
570 
575  void GetArrayIncrements(vtkDataArray* array, vtkIdType increments[3]);
576 
583  void ComputeInternalExtent(int* intExt, int* tgtExt, int* bnds);
584 
588  int GetExtentType() override { return VTK_3D_EXTENT; }
589 
591 
595  static vtkImageData* GetData(vtkInformationVector* v, int i = 0);
597 
598 protected:
599  vtkImageData();
600  ~vtkImageData() override;
601 
602  // The extent of what is currently in the structured grid.
603  // Dimensions is just an array to return a value.
604  // Its contents are out of data until GetDimensions is called.
605  int Dimensions[3];
606  vtkIdType Increments[3];
607 
608  // Variables used to define dataset physical orientation
609  double Origin[3];
610  double Spacing[3];
614 
615  int Extent[6];
616 
617  // The first method assumes Active Scalars
618  void ComputeIncrements();
619  // This one is given the number of components of the
620  // scalar field explicitly
621  void ComputeIncrements(int numberOfComponents);
622  void ComputeIncrements(vtkDataArray* scalars);
623 
624  // The first method assumes Acitive Scalars
625  void ComputeIncrements(vtkIdType inc[3]);
626  // This one is given the number of components of the
627  // scalar field explicitly
628  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
629  void ComputeIncrements(vtkDataArray* scalars, vtkIdType inc[3]);
630 
631  // for the index to physical methods
632  void ComputeTransforms();
633 
634  // Cell utilities
635  vtkCell* GetCellTemplateForDataDescription();
636  bool GetCellTemplateForDataDescription(vtkGenericCell* cell);
637  bool GetIJKMinForCellId(vtkIdType cellId, int ijkMin[3]);
638  bool GetIJKMaxForIJKMin(int ijkMin[3], int ijkMax[3]);
639  void AddPointsToCellTemplate(vtkCell* cell, int ijkMin[3], int ijkMax[3]);
640 
642 
643  void SetDataDescription(int desc);
644  int GetDataDescription() { return this->DataDescription; }
645 
646 private:
647  void InternalImageDataCopy(vtkImageData* src);
648 
649 private:
650  friend class vtkUniformGrid;
651 
652  // for the GetCell method
653  vtkVertex* Vertex;
654  vtkLine* Line;
655  vtkPixel* Pixel;
656  vtkVoxel* Voxel;
657 
658  // for the GetPoint method
659  double Point[3];
660 
661  int DataDescription;
662 
663  vtkImageData(const vtkImageData&) = delete;
664  void operator=(const vtkImageData&) = delete;
665 };
666 
667 //----------------------------------------------------------------------------
669 {
670  this->ComputeIncrements(this->Increments);
671 }
672 
673 //----------------------------------------------------------------------------
674 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
675 {
676  this->ComputeIncrements(numberOfComponents, this->Increments);
677 }
678 
679 //----------------------------------------------------------------------------
681 {
682  this->ComputeIncrements(scalars, this->Increments);
683 }
684 
685 //----------------------------------------------------------------------------
687 {
688  this->GetPoint(id, this->Point);
689  return this->Point;
690 }
691 
692 //----------------------------------------------------------------------------
694 {
695  const int* extent = this->Extent;
696  vtkIdType dims[3];
697  dims[0] = extent[1] - extent[0] + 1;
698  dims[1] = extent[3] - extent[2] + 1;
699  dims[2] = extent[5] - extent[4] + 1;
700 
701  return dims[0] * dims[1] * dims[2];
702 }
703 
704 //----------------------------------------------------------------------------
706 {
707  return vtkStructuredData::GetDataDimension(this->DataDescription);
708 }
709 
710 #endif
int GetExtentType() override
The extent type is a 3D extent.
Definition: vtkImageData.h:588
vtkMatrix3x3 * DirectionMatrix
Definition: vtkImageData.h:611
#define VTK_IMAGE_DATA
Definition: vtkType.h:83
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:71
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
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:62
a cell that represents a 3D point
Definition: vtkVertex.h:33
virtual vtkIdType GetCellSize(vtkIdType cellId)
Get the size of cell with cellId such that: 0 <= cellId < NumberOfCells.
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:62
record modification and/or execution time
Definition: vtkTimeStamp.h:35
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:37
vtkMatrix4x4 * PhysicalToIndexMatrix
Definition: vtkImageData.h:613
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:116
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:103
virtual vtkIdType FindPoint(double x, double y, double z)
Standard vtkDataSet API methods.
Definition: vtkImageData.h:89
vtkMatrix4x4 * IndexToPhysicalMatrix
Definition: vtkImageData.h:612
int vtkIdType
Definition: vtkType.h:332
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:239
virtual bool HasAnyBlankCells()
Returns 1 if there are any blanking cells 0 otherwise.
Definition: vtkDataSet.h:472
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:693
virtual vtkIdType ComputePointId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the point id.
Definition: vtkImageData.h:231
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:686
cell represents a 1D line
Definition: vtkLine.h:33
abstract class to specify cell behavior
Definition: vtkCell.h:60
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:41
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:39
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:478
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
list of point or cell ids
Definition: vtkIdList.h:33
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:55
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:644
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIdType Increments[3]
Definition: vtkImageData.h:606
image data with blanking
void Initialize() override
Restore data object to initial state.
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:504
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:668
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:109
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...
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:36
general representation of visualization data
Definition: vtkDataObject.h:65
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:232
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:705
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:641