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 
236  virtual vtkIdType *GetIncrements();
237  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
238  virtual void GetIncrements(vtkIdType inc[3]);
239  virtual vtkIdType *GetIncrements(vtkDataArray *scalars);
240  virtual void GetIncrements(vtkDataArray *scalars,
241  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
242  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
244 
246 
259  virtual void GetContinuousIncrements(
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);
280  virtual void SetScalarComponentFromFloat(
281  int x, int y, int z, int component, float v);
282  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
283  virtual void SetScalarComponentFromDouble(
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);
368  static int GetNumberOfScalarComponents(vtkInformation* meta_data);
369  static bool HasNumberOfScalarComponents(vtkInformation* meta_data);
370  int GetNumberOfScalarComponents();
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 
440  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
442 
443 protected:
444  vtkImageData();
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
#define VTK_IMAGE_DATA
Definition: vtkType.h:93
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.
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
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
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.
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:91
int vtkIdType
Definition: vtkType.h:287
virtual vtkIdType ComputeCellId(int ijk[3])
Given a location in structured coordinates (i-j-k), return the cell id.
Definition: vtkImageData.h:180
static vtkDataSet * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
provides thread-safe access to cells
void GetPoint(const int i, const int j, const int k, double pnt[3])
vtkIdType GetNumberOfPoints() override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:526
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:519
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:310
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.
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIdType Increments[3]
Definition: vtkImageData.h:451
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.
void ComputeIncrements()
Definition: vtkImageData.h:501
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) override
Standard vtkDataSet API methods.
Definition: vtkImageData.h:94
virtual void CopyStructure(vtkDataSet *ds)=0
Copy the geometric and topological structure of an object.
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:192
#define max(a, b)
virtual int GetDataDimension()
Return the dimensionality of the data.
Definition: vtkImageData.h:538
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.