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 
209  virtual vtkIdType *GetIncrements();
210  virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
211  virtual void GetIncrements(vtkIdType inc[3]);
212  virtual vtkIdType *GetIncrements(vtkDataArray *scalars);
213  virtual void GetIncrements(vtkDataArray *scalars,
214  vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
215  virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
217 
219 
230  virtual void GetContinuousIncrements(
231  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
232  virtual void GetContinuousIncrements(vtkDataArray *scalars,
233  int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
235 
237 
238  virtual void *GetScalarPointerForExtent(int extent[6]);
239  virtual void *GetScalarPointer(int coordinates[3]);
240  virtual void *GetScalarPointer(int x, int y, int z);
241  virtual void *GetScalarPointer();
243 
245 
246  virtual float GetScalarComponentAsFloat(int x, int y, int z, int component);
247  virtual void SetScalarComponentFromFloat(
248  int x, int y, int z, int component, float v);
249  virtual double GetScalarComponentAsDouble(int x, int y, int z, int component);
250  virtual void SetScalarComponentFromDouble(
251  int x, int y, int z, int component, double v);
253 
255  virtual void AllocateScalars();
256 
258 
262  virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]);
263  virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1,
264  int y0, int y1, int z0, int z1)
265  {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1;
266  this->CopyAndCastFrom(inData, e);}
268 
272  virtual void Crop();
273 
279  virtual unsigned long GetActualMemorySize();
280 
282 
284  vtkSetVector3Macro(Spacing,double);
285  vtkGetVector3Macro(Spacing,double);
287 
289 
295  vtkSetVector3Macro(Origin,double);
296  vtkGetVector3Macro(Origin,double);
298 
300 
305  void SetScalarTypeToFloat(){this->SetScalarType(VTK_FLOAT);};
306  void SetScalarTypeToDouble(){this->SetScalarType(VTK_DOUBLE);};
307  void SetScalarTypeToInt(){this->SetScalarType(VTK_INT);};
308  void SetScalarTypeToUnsignedInt()
309  {this->SetScalarType(VTK_UNSIGNED_INT);};
310  void SetScalarTypeToLong(){this->SetScalarType(VTK_LONG);};
311  void SetScalarTypeToUnsignedLong()
312  {this->SetScalarType(VTK_UNSIGNED_LONG);};
313  void SetScalarTypeToShort(){this->SetScalarType(VTK_SHORT);};
314  void SetScalarTypeToUnsignedShort()
315  {this->SetScalarType(VTK_UNSIGNED_SHORT);};
316  void SetScalarTypeToUnsignedChar()
317  {this->SetScalarType(VTK_UNSIGNED_CHAR);};
318  void SetScalarTypeToSignedChar()
319  {this->SetScalarType(VTK_SIGNED_CHAR);};
320  void SetScalarTypeToChar()
321  {this->SetScalarType(VTK_CHAR);};
322  void SetScalarType(int);
323  int GetScalarType();
324  const char* GetScalarTypeAsString()
325  { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); };
327 
329 
331  void SetNumberOfScalarComponents( int n );
332  int GetNumberOfScalarComponents();
334 
335  // Must only be called with vtkImageData (or subclass) as input
337 
339 
341  virtual void CopyInformationToPipeline(vtkInformation* request,
342  vtkInformation* input,
343  vtkInformation* output,
344  int forceCopy);
345  virtual void CopyInformationFromPipeline(vtkInformation* request);
347 
351  virtual void PrepareForNewData();
352 
354 
355  virtual void ShallowCopy(vtkDataObject *src);
356  virtual void DeepCopy(vtkDataObject *src);
358 
359  //--------------------------------------------------------------------------
360  // Methods that apply to any array (not just scalars).
361  // I am starting to experiment with generalizing imaging fitlers
362  // to operate on more than just scalars.
363 
365 
368  void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]);
369  void *GetArrayPointer(vtkDataArray* array, int coordinates[3]);
371 
374  void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]);
375 
380  void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds);
381 
383  virtual int GetExtentType() { return VTK_3D_EXTENT; };
384 
385  //BTX
387 
389  static vtkImageData* GetData(vtkInformationVector* v, int i=0);
390  //ETX
392 
393 protected:
394  vtkImageData();
395  ~vtkImageData();
396 
397  // The extent of what is currently in the structured grid.
398  // Dimensions is just an array to return a value.
399  // Its contents are out of data until GetDimensions is called.
400  int Dimensions[3];
401  vtkIdType Increments[3];
402 
403  double Origin[3];
404  double Spacing[3];
405 
406  int Extent[6];
407 
408  // The first method assumes Active Scalars
409  void ComputeIncrements();
410  // This one is given the number of components of the
411  // scalar field explicitly
412  void ComputeIncrements(int numberOfComponents);
413  void ComputeIncrements(vtkDataArray *scalars);
414 
415  // The first method assumes Acitive Scalars
416  void ComputeIncrements(vtkIdType inc[3]);
417  // This one is given the number of components of the
418  // scalar field explicitly
419  void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
420  void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
421  void CopyOriginAndSpacingFromPipeline();
422 
424 
425  void SetDataDescription(int desc);
426  int GetDataDescription() { return this->DataDescription; }
427 
428 private:
429  void InternalImageDataCopy(vtkImageData *src);
430 private:
431 
432  //BTX
433  friend class vtkUniformGrid;
434  //ETX
435 
436  // for the GetCell method
437  vtkVertex *Vertex;
438  vtkLine *Line;
439  vtkPixel *Pixel;
440  vtkVoxel *Voxel;
441 
442  int DataDescription;
443 
444  vtkImageData(const vtkImageData&); // Not implemented.
445  void operator=(const vtkImageData&); // Not implemented.
446 };
447 
448 
449 //----------------------------------------------------------------------------
451 {
452  this->ComputeIncrements(this->Increments);
453 }
454 
455 //----------------------------------------------------------------------------
456 inline void vtkImageData::ComputeIncrements(int numberOfComponents)
457 {
458  this->ComputeIncrements(numberOfComponents, this->Increments);
459 }
460 
461 //----------------------------------------------------------------------------
463 {
464  this->ComputeIncrements(scalars, this->Increments);
465 }
466 
467 //----------------------------------------------------------------------------
468 inline void vtkImageData::GetPoint(vtkIdType id, double x[3])
469 {
470  const double *p = this->GetPoint(id);
471  x[0] = p[0]; x[1] = p[1]; x[2] = p[2];
472 }
473 
474 //----------------------------------------------------------------------------
476 {
477  const int *extent = this->Extent;
478  vtkIdType dims[3];
479  dims[0] = extent[1] - extent[0] + 1;
480  dims[1] = extent[3] - extent[2] + 1;
481  dims[2] = extent[5] - extent[4] + 1;
482 
483  return dims[0]*dims[1]*dims[2];
484 }
485 
486 //----------------------------------------------------------------------------
488 {
489  return vtkStructuredData::GetDataDimension(this->DataDescription);
490 }
491 
492 #endif