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) VTK_OVERRIDE;
52 
57  void CopyStructure(vtkDataSet *ds) VTK_OVERRIDE;
58 
62  int GetDataObjectType() VTK_OVERRIDE {return VTK_IMAGE_DATA;};
63 
65 
68  vtkIdType GetNumberOfCells() VTK_OVERRIDE;
69  vtkIdType GetNumberOfPoints() VTK_OVERRIDE;
70  double *GetPoint(vtkIdType ptId) VTK_OVERRIDE;
71  void GetPoint(vtkIdType id, double x[3]) VTK_OVERRIDE;
72  vtkCell *GetCell(vtkIdType cellId) VTK_OVERRIDE;
73  void GetCell(vtkIdType cellId, vtkGenericCell *cell) VTK_OVERRIDE;
74  void GetCellBounds(vtkIdType cellId, double bounds[6]) VTK_OVERRIDE;
75  virtual vtkIdType FindPoint(double x, double y, double z)
76  {
77  return this->vtkDataSet::FindPoint(x, y, z);
78  }
79  vtkIdType FindPoint(double x[3]) VTK_OVERRIDE;
81  double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
82  int& subId, double pcoords[3], double *weights) VTK_OVERRIDE;
84  double x[3], vtkCell *cell, vtkGenericCell *gencell,
85  vtkIdType cellId, double tol2, int& subId,
86  double pcoords[3], double *weights) VTK_OVERRIDE;
87  vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
88  double tol2, int& subId, double pcoords[3],
89  double *weights) VTK_OVERRIDE;
90  int GetCellType(vtkIdType cellId) VTK_OVERRIDE;
91  void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) VTK_OVERRIDE
92  {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
93  this->GetDimensions());}
94  void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) VTK_OVERRIDE
95  {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
96  void ComputeBounds() VTK_OVERRIDE;
97  int GetMaxCellSize() VTK_OVERRIDE {return 8;}; //voxel is the largest
99 
103  void Initialize() VTK_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();
122 
129  virtual void GetDimensions(int dims[3]);
130 
137  virtual int ComputeStructuredCoordinates(
138  const double x[3], int ijk[3], double pcoords[3]);
139 
140  static int ComputeStructuredCoordinates( const double x[3], int ijk[3], double pcoords[3],
141  const int* extent,
142  const double* spacing,
143  const double* origin,
144  const double* bounds);
154  virtual void GetVoxelGradient(
155  int i,int j,int k, vtkDataArray *s, vtkDataArray *g);
156 
163  virtual void GetPointGradient(
164  int i, int j, int k, vtkDataArray *s, double g[3]);
165 
169  virtual int GetDataDimension();
170 
174  virtual vtkIdType ComputePointId(int ijk[3]) {
175  return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);};
176 
180  virtual vtkIdType ComputeCellId(int ijk[3]) {
181  return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);};
182 
184 
187  virtual void SetAxisUpdateExtent(int axis, int min, int max,
188  const int* updateExtent,
189  int* axisUpdateExtent);
190  virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int* updateExtent);
192 
194 
205  virtual void SetExtent(int extent[6]);
206  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
207  vtkGetVector6Macro(Extent, int);
209 
211 
215  virtual double GetScalarTypeMin(vtkInformation* meta_data);
216  virtual double GetScalarTypeMin();
217  virtual double GetScalarTypeMax(vtkInformation* meta_data);
218  virtual double GetScalarTypeMax();
220 
222 
225  virtual int GetScalarSize(vtkInformation* meta_data);
226  virtual int GetScalarSize();
228 
230 
237  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
238  virtual void GetIncrements(vtkIdType inc[3]);
240  virtual void GetIncrements(vtkDataArray *scalars,
241  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
242  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
244 
246 
260  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
261  virtual void GetContinuousIncrements(vtkDataArray *scalars,
262  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
264 
266 
269  virtual void *GetScalarPointerForExtent(int extent[6]);
270  virtual void *GetScalarPointer(int coordinates[3]);
271  virtual void *GetScalarPointer(int x, int y, int z);
272  virtual void *GetScalarPointer();
274 
276 
279  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
281  int x, int y, int z, int component, float v);
282  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
284  int x, int y, int z, int component, double v);
286 
292  virtual void AllocateScalars(int dataType, int numComponents);
293 
300  virtual void AllocateScalars(vtkInformation* pipeline_info);
301 
303 
309  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
310  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
311  int y0, int y1, int z0, int z1)
312  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
313  this->CopyAndCastFrom(inData, e);}
315 
321  void Crop(const int* updateExtent) VTK_OVERRIDE;
322 
331  unsigned long GetActualMemorySize() VTK_OVERRIDE;
332 
334 
338  vtkSetVector3Macro(Spacing,double);
339  vtkGetVector3Macro(Spacing,double);
341 
343 
351  vtkSetVector3Macro(Origin,double);
352  vtkGetVector3Macro(Origin,double);
354 
355  static void SetScalarType(int, vtkInformation* meta_data);
356  static int GetScalarType(vtkInformation* meta_data);
357  static bool HasScalarType(vtkInformation* meta_data);
358  int GetScalarType();
359  const char* GetScalarTypeAsString()
360  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
361 
363 
367  static void SetNumberOfScalarComponents( int n, vtkInformation* meta_data);
372 
377  void CopyInformationFromPipeline(vtkInformation* information) VTK_OVERRIDE;
378 
384  void CopyInformationToPipeline(vtkInformation* information) VTK_OVERRIDE;
385 
391  void PrepareForNewData() VTK_OVERRIDE;
392 
394 
397  void ShallowCopy(vtkDataObject *src) VTK_OVERRIDE;
398  void DeepCopy(vtkDataObject *src) VTK_OVERRIDE;
400 
401  //--------------------------------------------------------------------------
402  // Methods that apply to any array (not just scalars).
403  // I am starting to experiment with generalizing imaging fitlers
404  // to operate on more than just scalars.
405 
407 
412  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
413  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
415 
420  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
421 
428  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
429 
433  int GetExtentType() VTK_OVERRIDE { return VTK_3D_EXTENT; };
434 
436 
442 
443 protected:
445  ~vtkImageData() VTK_OVERRIDE;
446 
447  // The extent of what is currently in the structured grid.
448  // Dimensions is just an array to return a value.
449  // Its contents are out of data until GetDimensions is called.
450  int Dimensions[3];
451  vtkIdType Increments[3];
452 
453  double Origin[3];
454  double Spacing[3];
455 
456  int Extent[6];
457 
458  // The first method assumes Active Scalars
459  void ComputeIncrements();
460  // This one is given the number of components of the
461  // scalar field explicitly
462  void ComputeIncrements(int numberOfComponents);
463  void ComputeIncrements(vtkDataArray *scalars);
464 
465  // The first method assumes Acitive Scalars
466  void ComputeIncrements(vtkIdType inc[3]);
467  // This one is given the number of components of the
468  // scalar field explicitly
469  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
470  void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
471  void CopyOriginAndSpacingFromPipeline(vtkInformation* info);
472 
473  vtkTimeStamp ExtentComputeTime;
474 
475  void SetDataDescription(int desc);
476  int GetDataDescription() { return this->DataDescription; }
477 
478 private:
479  void InternalImageDataCopy(vtkImageData *src);
480 private:
481 
482  friend class vtkUniformGrid;
483 
484  // for the GetCell method
485  vtkVertex *Vertex;
486  vtkLine *Line;
487  vtkPixel *Pixel;
488  vtkVoxel *Voxel;
489 
490  // for the GetPoint method
491  double Point[3];
492 
493  int DataDescription;
494 
495  vtkImageData(const vtkImageData&) VTK_DELETE_FUNCTION;
496  void operator=(const vtkImageData&) VTK_DELETE_FUNCTION;
497 };
498 
499 
500 //----------------------------------------------------------------------------
502 {
503  this->ComputeIncrements(this->Increments);
504 }
505 
506 //----------------------------------------------------------------------------
507 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
508 {
509  this->ComputeIncrements(numberOfComponents, this->Increments);
510 }
511 
512 //----------------------------------------------------------------------------
514 {
515  this->ComputeIncrements(scalars, this->Increments);
516 }
517 
518 //----------------------------------------------------------------------------
520 {
521  this->GetPoint(id, this->Point);
522  return this->Point;
523 }
524 
525 //----------------------------------------------------------------------------
527 {
528  const int *extent = this->Extent;
529  vtkIdType dims[3];
530  dims[0] = extent[1] - extent[0] + 1;
531  dims[1] = extent[3] - extent[2] + 1;
532  dims[2] = extent[5] - extent[4] + 1;
533 
534  return dims[0]*dims[1]*dims[2];
535 }
536 
537 //----------------------------------------------------------------------------
539 {
540  return vtkStructuredData::GetDataDimension(this->DataDescription);
541 }
542 
543 #endif
void GetPoint(const int i, const int j, const int k, double pnt[3])
abstract class to specify cell behavior
Definition: vtkCell.h:60
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
general representation of visualization data
Definition: vtkDataObject.h:65
abstract class to specify dataset behavior
Definition: vtkDataSet.h:63
vtkIdType FindPoint(double x, double y, double z)
Locate the closest point to the global coordinate x.
Definition: vtkDataSet.h:192
provides thread-safe access to cells
list of point or cell ids
Definition: vtkIdList.h:37
topologically and geometrically regular array of data
Definition: vtkImageData.h:46
void Crop(const int *updateExtent) override
Reallocates and copies to set the Extent to updateExtent.
virtual int GetDataDimension()
Return the dimensionality of the data.
Definition: vtkImageData.h:538
vtkIdType FindCell(double x[3], vtkCell *cell, vtkGenericCell *gencell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights) override
This is a version of the above method that can be used with multithreaded applications.
virtual vtkIdType * GetIncrements(vtkDataArray *scalars)
virtual void * GetScalarPointer(int coordinates[3])
void CopyInformationToPipeline(vtkInformation *information) override
Copy information from this data object to the pipeline information.
vtkCell * FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights) override
Locate the cell that contains a point and return the cell.
virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, int y0, int y1, int z0, int z1)
Definition: vtkImageData.h:310
virtual vtkIdType * GetIncrements()
Different ways to get the increments for moving around the data.
virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6])
This method is passed a input and output region, and executes the filter algorithm to fill the output...
virtual float GetScalarComponentAsFloat(int x, int y, int z, int component)
For access to data from tcl.
static vtkImageData * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
virtual double GetScalarTypeMin()
void ComputeIncrements()
Definition: vtkImageData.h:501
virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3])
void ComputeBounds() override
Compute the data bounding box from data points.
double * GetPoint(vtkIdType ptId) override
Get point coordinates with ptId such that: 0 <= ptId < NumberOfPoints.
Definition: vtkImageData.h:519
virtual void * GetScalarPointer()
static vtkImageData * New()
virtual double GetScalarTypeMin(vtkInformation *meta_data)
These returns the minimum and maximum values the ScalarType can hold without overflowing.
virtual int GetScalarSize(vtkInformation *meta_data)
Get the size of the scalar type in bytes.
virtual void SetExtent(int extent[6])
Set/Get the extent.
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Topological inquiry to get points defining cell.
Definition: vtkImageData.h:91
virtual void GetIncrements(vtkDataArray *scalars, vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
virtual double GetScalarTypeMax(vtkInformation *meta_data)
int GetNumberOfScalarComponents()
vtkIdType GetNumberOfPoints() override
Determine the number of points composing the dataset.
Definition: vtkImageData.h:526
vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights) override
Locate cell based on global coordinate x and tolerance squared.
virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int *updateExtent)
virtual void GetIncrements(vtkIdType inc[3])
virtual void AllocateScalars(int dataType, int numComponents)
Allocate the point scalars for this dataset.
virtual void SetScalarComponentFromFloat(int x, int y, int z, int component, float v)
static void SetNumberOfScalarComponents(int n, vtkInformation *meta_data)
Set/Get the number of scalar components for points.
vtkIdType Increments[3]
Definition: vtkImageData.h:451
int GetCellType(vtkIdType cellId) override
Get type of cell with cellId such that: 0 <= cellId < NumberOfCells.
vtkIdType GetNumberOfCells() override
Standard vtkDataSet API methods.
virtual void GetContinuousIncrements(int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
Different ways to get the increments for moving around the data.
virtual int GetScalarSize()
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkImageData.h:62
void CopyInformationFromPipeline(vtkInformation *information) override
Override these to handle origin, spacing, scalar type, and scalar number of components.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual double GetScalarComponentAsDouble(int x, int y, int z, int component)
virtual void GetContinuousIncrements(vtkDataArray *scalars, int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
vtkIdType FindPoint(double x[3]) override
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
virtual void AllocateScalars(vtkInformation *pipeline_info)
Allocate the point scalars for this dataset.
void Initialize() override
Restore data object to initial state.
static vtkImageData * GetData(vtkInformationVector *v, int i=0)
virtual void SetScalarComponentFromDouble(int x, int y, int z, int component, double v)
virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
virtual void * GetScalarPointer(int x, int y, int z)
virtual double GetScalarTypeMax()
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Topological inquiry to get cells using point.
Definition: vtkImageData.h:94
virtual void SetAxisUpdateExtent(int axis, int min, int max, const int *updateExtent, int *axisUpdateExtent)
Set / Get the extent on just one axis.
static bool HasNumberOfScalarComponents(vtkInformation *meta_data)
~vtkImageData() override
void PrepareForNewData() override
make the output data ready for new data to be inserted.
virtual void * GetScalarPointerForExtent(int extent[6])
Access the native pointer for the scalar data.
virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2)
void CopyStructure(vtkDataSet *ds) override
Copy the geometric and topological structure of an input image data object.
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:180
a simple class to control print indentation
Definition: vtkIndent.h:40
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
cell represents a 1D line
Definition: vtkLine.h:36
a cell that represents an orthogonal quadrilateral
Definition: vtkPixel.h:41
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.
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
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,...
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
image data with blanking
a cell that represents a 3D point
Definition: vtkVertex.h:37
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:45
@ component
Definition: vtkX3D.h:175
@ info
Definition: vtkX3D.h:376
@ extent
Definition: vtkX3D.h:345
@ spacing
Definition: vtkX3D.h:481
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
#define VTK_3D_EXTENT
Definition: vtkDataObject.h:61
int vtkIdType
Definition: vtkType.h:287
#define VTK_IMAGE_DATA
Definition: vtkType.h:93
#define max(a, b)