VTK  9.0.1
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
int GetExtentType() override
The extent type is a 3D extent.
Definition: vtkImageData.h:500
vtkMatrix3x3 * DirectionMatrix
Definition: vtkImageData.h:523
#define VTK_IMAGE_DATA
Definition: vtkType.h:91
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:58
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:35
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:56
a cell that represents a 3D point
Definition: vtkVertex.h:30
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:56
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
vtkMatrix4x4 * PhysicalToIndexMatrix
Definition: vtkImageData.h:525
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:97
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:88
virtual vtkIdType FindPoint(double x, double y, double z)
Standard vtkDataSet API methods.
Definition: vtkImageData.h:76
vtkMatrix4x4 * IndexToPhysicalMatrix
Definition: vtkImageData.h:524
int vtkIdType
Definition: vtkType.h:338
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:177
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:605
virtual vtkIdType ComputePointId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the point id.
Definition: vtkImageData.h:169
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:598
cell represents a 1D line
Definition: vtkLine.h:29
abstract class to specify cell behavior
Definition: vtkCell.h:56
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 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:41
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
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.
#define VTK_SIZEHINT(...)
int GetDataDescription()
Definition: vtkImageData.h:556
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIdType Increments[3]
Definition: vtkImageData.h:518
image data with blanking
void Initialize() override
Restore data object to initial state.
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:427
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:580
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:92
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:33
general representation of visualization data
Definition: vtkDataObject.h:59
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:193
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:617
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:553