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 =========================================================================*/
30 #ifndef __vtkImageData_h
31 #define __vtkImageData_h
32 
33 #include "vtkDataSet.h"
34 
35 #include "vtkStructuredData.h" // Needed for inline methods
36 
37 class vtkDataArray;
38 class vtkLine;
39 class vtkPixel;
40 class vtkVertex;
41 class vtkVoxel;
42 
44 {
45 public:
46  static vtkImageData *New();
47 
48  vtkTypeMacro(vtkImageData,vtkDataSet);
49  void PrintSelf(ostream& os, vtkIndent indent);
50 
53  virtual void CopyStructure(vtkDataSet *ds);
54 
56  virtual int GetDataObjectType() {return VTK_IMAGE_DATA;};
57 
59 
60  virtual vtkIdType GetNumberOfCells();
61  virtual vtkIdType GetNumberOfPoints();
62  virtual double *GetPoint(vtkIdType ptId);
63  virtual void GetPoint(vtkIdType id, double x[3]);
64  virtual vtkCell *GetCell(vtkIdType cellId);
65  virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell);
66  virtual void GetCellBounds(vtkIdType cellId, double bounds[6]);
67  virtual vtkIdType FindPoint(double x, double y, double z)
68  {
69  return this->vtkDataSet::FindPoint(x, y, z);
70  }
71  virtual vtkIdType FindPoint(double x[3]);
72  virtual vtkIdType FindCell(
73  double x[3], vtkCell *cell, vtkIdType cellId, double tol2,
74  int& subId, double pcoords[3], double *weights);
75  virtual vtkIdType FindCell(
76  double x[3], vtkCell *cell, vtkGenericCell *gencell,
77  vtkIdType cellId, double tol2, int& subId,
78  double pcoords[3], double *weights);
79  virtual vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId,
80  double tol2, int& subId, double pcoords[3],
81  double *weights);
82  virtual int GetCellType(vtkIdType cellId);
83  virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
84  {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription,
85  this->GetDimensions());}
86  virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
87  {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
88  virtual void ComputeBounds();
89  virtual int GetMaxCellSize() {return 8;}; //voxel is the largest
91 
93  virtual void Initialize();
94 
97  virtual void SetDimensions(int i, int j, int k);
98 
102  virtual void SetDimensions(const int dims[3]);
103 
105 
108  virtual int *GetDimensions();
109  virtual void GetDimensions(int dims[3]);
111 
113 
118  virtual int ComputeStructuredCoordinates(
119  double x[3], int ijk[3], double pcoords[3]);
121 
123 
131  virtual void GetVoxelGradient(
132  int i,int j,int k, vtkDataArray *s, vtkDataArray *g);
134 
136 
141  virtual void GetPointGradient(
142  int i, int j, int k, vtkDataArray *s, double g[3]);
144 
146  virtual int GetDataDimension();
147 
149 
151  virtual vtkIdType ComputePointId(int ijk[3]) {
152  return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);};
154 
156 
158  virtual vtkIdType ComputeCellId(int ijk[3]) {
159  return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);};
161 
163 
164  virtual void SetAxisUpdateExtent(int axis, int min, int max);
165  virtual void GetAxisUpdateExtent(int axis, int &min, int &max);
167 
171  virtual void UpdateInformation();
172 
174 
182  virtual void SetExtent(int extent[6]);
183  virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2);
184  vtkGetVector6Macro(Extent, int);
186 
191  virtual unsigned long GetEstimatedMemorySize();
192 
194 
196  virtual double GetScalarTypeMin();
197  virtual double GetScalarTypeMax();
199 
201  virtual int GetScalarSize();
202 
204 
207  virtual vtkIdType *GetIncrements();
208  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
209  virtual void GetIncrements(vtkIdType inc[3]);
211 
213 
222  virtual void GetContinuousIncrements(
223  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
225 
227 
228  virtual void *GetScalarPointerForExtent(int extent[6]);
229  virtual void *GetScalarPointer(int coordinates[3]);
230  virtual void *GetScalarPointer(int x, int y, int z);
231  virtual void *GetScalarPointer();
233 
235 
236  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
237  virtual void SetScalarComponentFromFloat(
238  int x, int y, int z, int component, float v);
239  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
240  virtual void SetScalarComponentFromDouble(
241  int x, int y, int z, int component, double v);
243 
245  virtual void AllocateScalars();
246 
248 
252  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
253  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
254  int y0, int y1, int z0, int z1)
255  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
256  this->CopyAndCastFrom(inData, e);}
258 
262  virtual void Crop();
263 
269  virtual unsigned long GetActualMemorySize();
270 
272 
274  vtkSetVector3Macro(Spacing,double);
275  vtkGetVector3Macro(Spacing,double);
277 
279 
285  vtkSetVector3Macro(Origin,double);
286  vtkGetVector3Macro(Origin,double);
288 
290 
295  void SetScalarTypeToFloat(){this->SetScalarType(VTK_FLOAT);};
296  void SetScalarTypeToDouble(){this->SetScalarType(VTK_DOUBLE);};
297  void SetScalarTypeToInt(){this->SetScalarType(VTK_INT);};
299  {this->SetScalarType(VTK_UNSIGNED_INT);};
300  void SetScalarTypeToLong(){this->SetScalarType(VTK_LONG);};
302  {this->SetScalarType(VTK_UNSIGNED_LONG);};
303  void SetScalarTypeToShort(){this->SetScalarType(VTK_SHORT);};
305  {this->SetScalarType(VTK_UNSIGNED_SHORT);};
307  {this->SetScalarType(VTK_UNSIGNED_CHAR);};
309  {this->SetScalarType(VTK_SIGNED_CHAR);};
311  {this->SetScalarType(VTK_CHAR);};
312  void SetScalarType(int);
313  int GetScalarType();
314  const char* GetScalarTypeAsString()
315  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
317 
319 
321  void SetNumberOfScalarComponents( int n );
322  int GetNumberOfScalarComponents();
324 
325  // Must only be called with vtkImageData (or subclass) as input
326  virtual void CopyTypeSpecificInformation( vtkDataObject *image );
327 
329 
331  virtual void CopyInformationToPipeline(vtkInformation* request,
332  vtkInformation* input,
333  vtkInformation* output,
334  int forceCopy);
335  virtual void CopyInformationFromPipeline(vtkInformation* request);
337 
341  virtual void PrepareForNewData();
342 
344 
345  virtual void ShallowCopy(vtkDataObject *src);
346  virtual void DeepCopy(vtkDataObject *src);
348 
349  //--------------------------------------------------------------------------
350  // Methods that apply to any array (not just scalars).
351  // I am starting to experiment with generalizing imaging fitlers
352  // to operate on more than just scalars.
353 
355 
358  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
359  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
361 
364  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
365 
370  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
371 
373  virtual int GetExtentType() { return VTK_3D_EXTENT; };
374 
375  //BTX
377 
378  static vtkImageData* GetData(vtkInformation* info);
379  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
380  //ETX
382 
383 protected:
384  vtkImageData();
385  ~vtkImageData();
386 
387  // The extent of what is currently in the structured grid.
388  // Dimensions is just an array to return a value.
389  // Its contents are out of data until GetDimensions is called.
390  int Dimensions[3];
391  vtkIdType Increments[3];
392 
393  double Origin[3];
394  double Spacing[3];
395 
396  int Extent[6];
397 
398  void ComputeIncrements();
399  void ComputeIncrements(vtkIdType inc[3]);
400  void CopyOriginAndSpacingFromPipeline();
401 
403 
404  void SetDataDescription(int desc);
405  int GetDataDescription() { return this->DataDescription; }
406 
407 private:
408  void InternalImageDataCopy(vtkImageData *src);
409 private:
410 
411  //BTX
412  friend class vtkUniformGrid;
413  //ETX
414 
415  // for the GetCell method
416  vtkVertex *Vertex;
417  vtkLine *Line;
418  vtkPixel *Pixel;
419  vtkVoxel *Voxel;
420 
421  int DataDescription;
422 
423  vtkImageData(const vtkImageData&); // Not implemented.
424  void operator=(const vtkImageData&); // Not implemented.
425 };
426 
427 
428 //----------------------------------------------------------------------------
430 {
431  this->ComputeIncrements(this->Increments);
432 }
433 
434 //----------------------------------------------------------------------------
435 inline void vtkImageData::GetPoint(vtkIdType id, double x[3])
436 {
437  const double *p = this->GetPoint(id);
438  x[0] = p[0]; x[1] = p[1]; x[2] = p[2];
439 }
440 
441 //----------------------------------------------------------------------------
443 {
444  const int *extent = this->Extent;
445  vtkIdType dims[3];
446  dims[0] = extent[1] - extent[0] + 1;
447  dims[1] = extent[3] - extent[2] + 1;
448  dims[2] = extent[5] - extent[4] + 1;
449 
450  return dims[0]*dims[1]*dims[2];
451 }
452 
453 //----------------------------------------------------------------------------
455 {
456  return vtkStructuredData::GetDataDimension(this->DataDescription);
457 }
458 
459 #endif
virtual int GetExtentType()
Definition: vtkImageData.h:373
void SetScalarTypeToUnsignedChar()
Definition: vtkImageData.h:306
virtual int GetMaxCellSize()
Definition: vtkImageData.h:89
void SetScalarTypeToUnsignedLong()
Definition: vtkImageData.h:301
#define VTK_IMAGE_DATA
Definition: vtkType.h:72
virtual vtkCell * FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)
void SetScalarTypeToSignedChar()
Definition: vtkImageData.h:308
virtual vtkIdType GetNumberOfCells()=0
#define VTK_UNSIGNED_INT
Definition: vtkType.h:32
unsigned long GetActualMemorySize()
static vtkIdType ComputeCellIdForExtent(int extent[6], int ijk[3])
void SetScalarTypeToChar()
Definition: vtkImageData.h:310
virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId, double tol2, int &subId, double pcoords[3], double *weights)=0
Store vtkAlgorithm input/output information.
virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
Definition: vtkImageData.h:86
#define VTK_FILTERING_EXPORT
virtual vtkIdType GetNumberOfPoints()=0
#define VTK_UNSIGNED_SHORT
Definition: vtkType.h:30
abstract class to specify dataset behavior
Definition: vtkDataSet.h:58
a cell that represents a 3D point
Definition: vtkVertex.h:34
record modification and/or execution time
Definition: vtkTimeStamp.h:33
static int GetDataDimension(int dataDescription)
void SetScalarTypeToInt()
Definition: vtkImageData.h:297
virtual void ComputeBounds()
void SetScalarTypeToDouble()
Definition: vtkImageData.h:296
virtual vtkIdType FindPoint(double x, double y, double z)
Definition: vtkImageData.h:67
int vtkIdType
Definition: vtkType.h:255
virtual vtkIdType ComputeCellId(int ijk[3])
Definition: vtkImageData.h:158
static vtkDataSet * GetData(vtkInformation *info)
provides thread-safe access to cells
virtual vtkIdType ComputePointId(int ijk[3])
Definition: vtkImageData.h:151
#define VTK_DOUBLE
Definition: vtkType.h:36
cell represents a 1D line
Definition: vtkLine.h:33
#define VTK_FLOAT
Definition: vtkType.h:35
void PrintSelf(ostream &os, vtkIndent indent)
virtual int GetDataObjectType()
Definition: vtkImageData.h:56
virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, int y0, int y1, int z0, int z1)
Definition: vtkImageData.h:253
a cell that represents a 3D orthogonal parallelepiped
Definition: vtkVoxel.h:42
void SetScalarTypeToFloat()
Definition: vtkImageData.h:295
a simple class to control print indentation
Definition: vtkIndent.h:37
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
topologically and geometrically regular array of data
Definition: vtkImageData.h:43
list of point or cell ids
Definition: vtkIdList.h:34
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
#define VTK_SHORT
Definition: vtkType.h:29
#define VTK_CHAR
Definition: vtkType.h:26
#define VTK_LONG
Definition: vtkType.h:33
virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
Definition: vtkImageData.h:83
int GetDataDescription()
Definition: vtkImageData.h:405
static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3])
void DeepCopy(vtkDataObject *src)
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
vtkIdType Increments[3]
Definition: vtkImageData.h:391
#define VTK_SIGNED_CHAR
Definition: vtkType.h:27
const char * GetScalarTypeAsString()
Definition: vtkImageData.h:314
#define VTK_UNSIGNED_CHAR
Definition: vtkType.h:28
virtual double * GetPoint(vtkIdType ptId)
void SetScalarTypeToUnsignedInt()
Definition: vtkImageData.h:298
void ComputeIncrements()
Definition: vtkImageData.h:429
void Initialize()
virtual void CopyStructure(vtkDataSet *ds)=0
Store zero or more vtkInformation instances.
virtual double * GetPoint(vtkIdType ptId)=0
#define VTK_UNSIGNED_LONG
Definition: vtkType.h:34
helper class to get VTK data object types as string and instantiate them
void SetScalarTypeToUnsignedShort()
Definition: vtkImageData.h:304
vtkIdType FindPoint(double x, double y, double z)
Definition: vtkDataSet.h:148
virtual vtkIdType GetNumberOfPoints()
Definition: vtkImageData.h:442
void SetScalarTypeToShort()
Definition: vtkImageData.h:303
#define VTK_INT
Definition: vtkType.h:31
virtual vtkCell * GetCell(vtkIdType cellId)=0
virtual void GetCellBounds(vtkIdType cellId, double bounds[6])
virtual int GetDataDimension()
Definition: vtkImageData.h:454
virtual int GetCellType(vtkIdType cellId)=0
void ShallowCopy(vtkDataObject *src)
void SetScalarTypeToLong()
Definition: vtkImageData.h:300
vtkTimeStamp ExtentComputeTime
Definition: vtkImageData.h:402