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 =========================================================================*/
31 #ifndef vtkImageData_h
32 #define vtkImageData_h
33 
34 #include "vtkCommonDataModelModule.h" // For export macro
35 #include "vtkDataSet.h"
36 
37 #include "vtkStructuredData.h" // Needed for inline methods
38 
39 class vtkDataArray;
40 class vtkLine;
41 class vtkPixel;
42 class vtkVertex;
43 class vtkVoxel;
44 
45 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet
46 {
47 public:
48  static vtkImageData *New();
49 
50  vtkTypeMacro(vtkImageData,vtkDataSet);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
57  void CopyStructure(vtkDataSet *ds) override;
58 
62  int GetDataObjectType() override {return VTK_IMAGE_DATA;};
63 
65 
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;
82  double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
83  int& subId, double pcoords[3], double *weights) override;
85  double x[3], vtkCell *cell, vtkGenericCell *gencell,
86  vtkIdType cellId, double tol2, int& subId,
87  double pcoords[3], double *weights) override;
88  vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
89  double tol2, int& subId, double pcoords[3],
90  double *weights) override;
91  int GetCellType(vtkIdType cellId) override;
92  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
93  {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
94  this->GetDimensions());}
95  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
96  {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
97  void ComputeBounds() override;
98  int GetMaxCellSize() override {return 8;}; //voxel is the largest
100 
104  void Initialize() override;
105 
109  virtual void SetDimensions(int i, int j, int k);
110 
114  virtual void SetDimensions(const int dims[3]);
115 
122  virtual int *GetDimensions() VTK_SIZEHINT(3);
123 
130  virtual void GetDimensions(int dims[3]);
131 
138  virtual int ComputeStructuredCoordinates(
139  const double x[3], int ijk[3], double pcoords[3]);
140 
141  static int ComputeStructuredCoordinates( const double x[3], int ijk[3], double pcoords[3],
142  const int* extent,
143  const double* spacing,
144  const double* origin,
145  const double* bounds);
155  virtual void GetVoxelGradient(
156  int i,int j,int k, vtkDataArray *s, vtkDataArray *g);
157 
164  virtual void GetPointGradient(
165  int i, int j, int k, vtkDataArray *s, double g[3]);
166 
170  virtual int GetDataDimension();
171 
175  virtual vtkIdType ComputePointId(int ijk[3]) {
176  return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);};
177 
181  virtual vtkIdType ComputeCellId(int ijk[3]) {
182  return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);};
183 
185 
188  virtual void SetAxisUpdateExtent(int axis, int min, int max,
189  const int* updateExtent,
190  int* axisUpdateExtent);
191  virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int* updateExtent);
193 
195 
206  virtual void SetExtent(int extent[6]);
207  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
208  vtkGetVector6Macro(Extent, int);
210 
212 
216  virtual double GetScalarTypeMin(vtkInformation* meta_data);
217  virtual double GetScalarTypeMin();
218  virtual double GetScalarTypeMax(vtkInformation* meta_data);
219  virtual double GetScalarTypeMax();
221 
223 
226  virtual int GetScalarSize(vtkInformation* meta_data);
227  virtual int GetScalarSize();
229 
231 
237  virtual vtkIdType *GetIncrements() VTK_SIZEHINT(3);
238  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
239  virtual void GetIncrements(vtkIdType inc[3]);
240  virtual vtkIdType *GetIncrements(vtkDataArray *scalars) VTK_SIZEHINT(3);
241  virtual void GetIncrements(vtkDataArray *scalars,
242  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
243  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
245 
247 
260  virtual void GetContinuousIncrements(
261  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
262  virtual void GetContinuousIncrements(vtkDataArray *scalars,
263  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
265 
267 
270  virtual void *GetScalarPointerForExtent(int extent[6]);
271  virtual void *GetScalarPointer(int coordinates[3]);
272  virtual void *GetScalarPointer(int x, int y, int z);
273  virtual void *GetScalarPointer();
275 
277 
280  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
281  virtual void SetScalarComponentFromFloat(
282  int x, int y, int z, int component, float v);
283  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
284  virtual void SetScalarComponentFromDouble(
285  int x, int y, int z, int component, double v);
287 
293  virtual void AllocateScalars(int dataType, int numComponents);
294 
301  virtual void AllocateScalars(vtkInformation* pipeline_info);
302 
304 
310  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
311  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
312  int y0, int y1, int z0, int z1)
313  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
314  this->CopyAndCastFrom(inData, e);}
316 
322  void Crop(const int* updateExtent) override;
323 
332  unsigned long GetActualMemorySize() override;
333 
335 
339  vtkSetVector3Macro(Spacing,double);
340  vtkGetVector3Macro(Spacing,double);
342 
344 
352  vtkSetVector3Macro(Origin,double);
353  vtkGetVector3Macro(Origin,double);
355 
356  static void SetScalarType(int, vtkInformation* meta_data);
357  static int GetScalarType(vtkInformation* meta_data);
358  static bool HasScalarType(vtkInformation* meta_data);
359  int GetScalarType();
360  const char* GetScalarTypeAsString()
361  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
362 
364 
368  static void SetNumberOfScalarComponents( int n, vtkInformation* meta_data);
369  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
370  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
371  int GetNumberOfScalarComponents();
373 
378  void CopyInformationFromPipeline(vtkInformation* information) override;
379 
385  void CopyInformationToPipeline(vtkInformation* information) override;
386 
392  void PrepareForNewData() override;
393 
395 
398  void ShallowCopy(vtkDataObject *src) override;
399  void DeepCopy(vtkDataObject *src) override;
401 
402  //--------------------------------------------------------------------------
403  // Methods that apply to any array (not just scalars).
404  // I am starting to experiment with generalizing imaging filters
405  // to operate on more than just scalars.
406 
408 
413  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
414  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
416 
421  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
422 
429  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
430 
434  int GetExtentType() override { return VTK_3D_EXTENT; };
435 
437 
441  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
443 
444 protected:
445  vtkImageData();
446  ~vtkImageData() override;
447 
448  // The extent of what is currently in the structured grid.
449  // Dimensions is just an array to return a value.
450  // Its contents are out of data until GetDimensions is called.
451  int Dimensions[3];
452  vtkIdType Increments[3];
453 
454  double Origin[3];
455  double Spacing[3];
456 
457  int Extent[6];
458 
459  // The first method assumes Active Scalars
460  void ComputeIncrements();
461  // This one is given the number of components of the
462  // scalar field explicitly
463  void ComputeIncrements(int numberOfComponents);
464  void ComputeIncrements(vtkDataArray *scalars);
465 
466  // The first method assumes Acitive Scalars
467  void ComputeIncrements(vtkIdType inc[3]);
468  // This one is given the number of components of the
469  // scalar field explicitly
470  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
471  void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
472  void CopyOriginAndSpacingFromPipeline(vtkInformation* info);
473 
475 
476  void SetDataDescription(int desc);
477  int GetDataDescription() { return this->DataDescription; }
478 
479 private:
480  void InternalImageDataCopy(vtkImageData *src);
481 private:
482 
483  friend class vtkUniformGrid;
484 
485  // for the GetCell method
486  vtkVertex *Vertex;
487  vtkLine *Line;
488  vtkPixel *Pixel;
489  vtkVoxel *Voxel;
490 
491  // for the GetPoint method
492  double Point[3];
493 
494  int DataDescription;
495 
496  vtkImageData(const vtkImageData&) = delete;
497  void operator=(const vtkImageData&) = delete;
498 };
499 
500 
501 //----------------------------------------------------------------------------
503 {
504  this->ComputeIncrements(this->Increments);
505 }
506 
507 //----------------------------------------------------------------------------
508 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
509 {
510  this->ComputeIncrements(numberOfComponents, this->Increments);
511 }
512 
513 //----------------------------------------------------------------------------
515 {
516  this->ComputeIncrements(scalars, this->Increments);
517 }
518 
519 //----------------------------------------------------------------------------
521 {
522  this->GetPoint(id, this->Point);
523  return this->Point;
524 }
525 
526 //----------------------------------------------------------------------------
528 {
529  const int *extent = this->Extent;
530  vtkIdType dims[3];
531  dims[0] = extent[1] - extent[0] + 1;
532  dims[1] = extent[3] - extent[2] + 1;
533  dims[2] = extent[5] - extent[4] + 1;
534 
535  return dims[0]*dims[1]*dims[2];
536 }
537 
538 //----------------------------------------------------------------------------
540 {
541  return vtkStructuredData::GetDataDimension(this->DataDescription);
542 }
543 
544 #endif
int GetExtentType() override
The extent type is a 3D extent.
Definition: vtkImageData.h:434
#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:62
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:36
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:61
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:40
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:98
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:76
int vtkIdType
Definition: vtkType.h:347
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:181
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:527
virtual vtkIdType ComputePointId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the point id.
Definition: vtkImageData.h:175
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:520
cell represents a 1D line
Definition: vtkLine.h:35
abstract class to specify cell behavior
Definition: vtkCell.h:59
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:311
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:44
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 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:45
list of point or cell ids
Definition: vtkIdList.h:36
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
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:477
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIdType Increments[3]
Definition: vtkImageData.h:452
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.
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:360
void ComputeIncrements()
Definition: vtkImageData.h:502
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:95
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.
general representation of visualization data
Definition: vtkDataObject.h:64
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:197
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:539
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:474