VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkImageData.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00030 #ifndef __vtkImageData_h 00031 #define __vtkImageData_h 00032 00033 #include "vtkCommonDataModelModule.h" // For export macro 00034 #include "vtkDataSet.h" 00035 00036 #include "vtkStructuredData.h" // Needed for inline methods 00037 00038 class vtkDataArray; 00039 class vtkLine; 00040 class vtkPixel; 00041 class vtkVertex; 00042 class vtkVoxel; 00043 00044 class VTKCOMMONDATAMODEL_EXPORT vtkImageData : public vtkDataSet 00045 { 00046 public: 00047 static vtkImageData *New(); 00048 00049 vtkTypeMacro(vtkImageData,vtkDataSet); 00050 void PrintSelf(ostream& os, vtkIndent indent); 00051 00054 virtual void CopyStructure(vtkDataSet *ds); 00055 00057 virtual int GetDataObjectType() {return VTK_IMAGE_DATA;}; 00058 00060 00061 virtual vtkIdType GetNumberOfCells(); 00062 virtual vtkIdType GetNumberOfPoints(); 00063 virtual double *GetPoint(vtkIdType ptId); 00064 virtual void GetPoint(vtkIdType id, double x[3]); 00065 virtual vtkCell *GetCell(vtkIdType cellId); 00066 virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell); 00067 virtual void GetCellBounds(vtkIdType cellId, double bounds[6]); 00068 virtual vtkIdType FindPoint(double x, double y, double z) 00069 { 00070 return this->vtkDataSet::FindPoint(x, y, z); 00071 } 00072 virtual vtkIdType FindPoint(double x[3]); 00073 virtual vtkIdType FindCell( 00074 double x[3], vtkCell *cell, vtkIdType cellId, double tol2, 00075 int& subId, double pcoords[3], double *weights); 00076 virtual vtkIdType FindCell( 00077 double x[3], vtkCell *cell, vtkGenericCell *gencell, 00078 vtkIdType cellId, double tol2, int& subId, 00079 double pcoords[3], double *weights); 00080 virtual vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, 00081 double tol2, int& subId, double pcoords[3], 00082 double *weights); 00083 virtual int GetCellType(vtkIdType cellId); 00084 virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) 00085 {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription, 00086 this->GetDimensions());} 00087 virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) 00088 {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());} 00089 virtual void ComputeBounds(); 00090 virtual int GetMaxCellSize() {return 8;}; //voxel is the largest 00092 00094 virtual void Initialize(); 00095 00098 virtual void SetDimensions(int i, int j, int k); 00099 00103 virtual void SetDimensions(const int dims[3]); 00104 00106 00109 virtual int *GetDimensions(); 00110 virtual void GetDimensions(int dims[3]); 00112 00114 00119 virtual int ComputeStructuredCoordinates( 00120 const double x[3], int ijk[3], double pcoords[3]); 00122 00123 static int ComputeStructuredCoordinates( const double x[3], int ijk[3], double pcoords[3], 00124 const int* extent, 00125 const double* spacing, 00126 const double* origin, 00127 const double* bounds); 00129 00137 virtual void GetVoxelGradient( 00138 int i,int j,int k, vtkDataArray *s, vtkDataArray *g); 00140 00142 00147 virtual void GetPointGradient( 00148 int i, int j, int k, vtkDataArray *s, double g[3]); 00150 00152 virtual int GetDataDimension(); 00153 00155 00157 virtual vtkIdType ComputePointId(int ijk[3]) { 00158 return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);}; 00160 00162 00164 virtual vtkIdType ComputeCellId(int ijk[3]) { 00165 return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);}; 00167 00169 00170 virtual void SetAxisUpdateExtent(int axis, int min, int max, 00171 const int* updateExtent, 00172 int* axisUpdateExtent); 00173 virtual void GetAxisUpdateExtent(int axis, int &min, int &max, const int* updateExtent); 00175 00177 00185 virtual void SetExtent(int extent[6]); 00186 virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2); 00187 vtkGetVector6Macro(Extent, int); 00189 00191 00193 virtual double GetScalarTypeMin(vtkInformation* meta_data); 00194 virtual double GetScalarTypeMin(); 00195 virtual double GetScalarTypeMax(vtkInformation* meta_data); 00196 virtual double GetScalarTypeMax(); 00198 00200 00201 virtual int GetScalarSize(vtkInformation* meta_data); 00202 virtual int GetScalarSize(); 00204 00206 00211 virtual vtkIdType *GetIncrements(); 00212 virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00213 virtual void GetIncrements(vtkIdType inc[3]); 00214 virtual vtkIdType *GetIncrements(vtkDataArray *scalars); 00215 virtual void GetIncrements(vtkDataArray *scalars, 00216 vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00217 virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]); 00219 00221 00232 virtual void GetContinuousIncrements( 00233 int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00234 virtual void GetContinuousIncrements(vtkDataArray *scalars, 00235 int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00237 00239 00240 virtual void *GetScalarPointerForExtent(int extent[6]); 00241 virtual void *GetScalarPointer(int coordinates[3]); 00242 virtual void *GetScalarPointer(int x, int y, int z); 00243 virtual void *GetScalarPointer(); 00245 00247 00248 virtual float GetScalarComponentAsFloat(int x, int y, int z, int component); 00249 virtual void SetScalarComponentFromFloat( 00250 int x, int y, int z, int component, float v); 00251 virtual double GetScalarComponentAsDouble(int x, int y, int z, int component); 00252 virtual void SetScalarComponentFromDouble( 00253 int x, int y, int z, int component, double v); 00255 00259 virtual void AllocateScalars(int dataType, int numComponents); 00260 00265 virtual void AllocateScalars(vtkInformation* pipeline_info); 00266 00268 00272 virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]); 00273 virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, 00274 int y0, int y1, int z0, int z1) 00275 {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1; 00276 this->CopyAndCastFrom(inData, e);} 00278 00282 virtual void Crop(const int* updateExtent); 00283 00289 virtual unsigned long GetActualMemorySize(); 00290 00292 00294 vtkSetVector3Macro(Spacing,double); 00295 vtkGetVector3Macro(Spacing,double); 00297 00299 00305 vtkSetVector3Macro(Origin,double); 00306 vtkGetVector3Macro(Origin,double); 00308 00309 static void SetScalarType(int, vtkInformation* meta_data); 00310 static int GetScalarType(vtkInformation* meta_data); 00311 static bool HasScalarType(vtkInformation* meta_data); 00312 int GetScalarType(); 00313 const char* GetScalarTypeAsString() 00314 { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); }; 00315 00317 00319 static void SetNumberOfScalarComponents( int n, vtkInformation* meta_data); 00320 static int GetNumberOfScalarComponents(vtkInformation* meta_data); 00321 static bool HasNumberOfScalarComponents(vtkInformation* meta_data); 00322 int GetNumberOfScalarComponents(); 00324 00327 virtual void CopyInformationFromPipeline(vtkInformation* information); 00328 00332 virtual void PrepareForNewData(); 00333 00335 00336 virtual void ShallowCopy(vtkDataObject *src); 00337 virtual void DeepCopy(vtkDataObject *src); 00339 00340 //-------------------------------------------------------------------------- 00341 // Methods that apply to any array (not just scalars). 00342 // I am starting to experiment with generalizing imaging fitlers 00343 // to operate on more than just scalars. 00344 00346 00349 void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]); 00350 void *GetArrayPointer(vtkDataArray* array, int coordinates[3]); 00352 00355 void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]); 00356 00361 void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds); 00362 00364 virtual int GetExtentType() { return VTK_3D_EXTENT; }; 00365 00366 //BTX 00368 00369 static vtkImageData* GetData(vtkInformation* info); 00370 static vtkImageData* GetData(vtkInformationVector* v, int i=0); 00371 //ETX 00373 00374 protected: 00375 vtkImageData(); 00376 ~vtkImageData(); 00377 00378 // The extent of what is currently in the structured grid. 00379 // Dimensions is just an array to return a value. 00380 // Its contents are out of data until GetDimensions is called. 00381 int Dimensions[3]; 00382 vtkIdType Increments[3]; 00383 00384 double Origin[3]; 00385 double Spacing[3]; 00386 00387 int Extent[6]; 00388 00389 // The first method assumes Active Scalars 00390 void ComputeIncrements(); 00391 // This one is given the number of components of the 00392 // scalar field explicitly 00393 void ComputeIncrements(int numberOfComponents); 00394 void ComputeIncrements(vtkDataArray *scalars); 00395 00396 // The first method assumes Acitive Scalars 00397 void ComputeIncrements(vtkIdType inc[3]); 00398 // This one is given the number of components of the 00399 // scalar field explicitly 00400 void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]); 00401 void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]); 00402 void CopyOriginAndSpacingFromPipeline(vtkInformation* info); 00403 00404 vtkTimeStamp ExtentComputeTime; 00405 00406 void SetDataDescription(int desc); 00407 int GetDataDescription() { return this->DataDescription; } 00408 00409 private: 00410 void InternalImageDataCopy(vtkImageData *src); 00411 private: 00412 00413 //BTX 00414 friend class vtkUniformGrid; 00415 //ETX 00416 00417 // for the GetCell method 00418 vtkVertex *Vertex; 00419 vtkLine *Line; 00420 vtkPixel *Pixel; 00421 vtkVoxel *Voxel; 00422 00423 // for the GetPoint method 00424 double Point[3]; 00425 00426 int DataDescription; 00427 00428 vtkImageData(const vtkImageData&); // Not implemented. 00429 void operator=(const vtkImageData&); // Not implemented. 00430 }; 00431 00432 00433 //---------------------------------------------------------------------------- 00434 inline void vtkImageData::ComputeIncrements() 00435 { 00436 this->ComputeIncrements(this->Increments); 00437 } 00438 00439 //---------------------------------------------------------------------------- 00440 inline void vtkImageData::ComputeIncrements(int numberOfComponents) 00441 { 00442 this->ComputeIncrements(numberOfComponents, this->Increments); 00443 } 00444 00445 //---------------------------------------------------------------------------- 00446 inline void vtkImageData::ComputeIncrements(vtkDataArray *scalars) 00447 { 00448 this->ComputeIncrements(scalars, this->Increments); 00449 } 00450 00451 //---------------------------------------------------------------------------- 00452 inline double * vtkImageData::GetPoint(vtkIdType id) 00453 { 00454 this->GetPoint(id, this->Point); 00455 return this->Point; 00456 } 00457 00458 //---------------------------------------------------------------------------- 00459 inline vtkIdType vtkImageData::GetNumberOfPoints() 00460 { 00461 const int *extent = this->Extent; 00462 vtkIdType dims[3]; 00463 dims[0] = extent[1] - extent[0] + 1; 00464 dims[1] = extent[3] - extent[2] + 1; 00465 dims[2] = extent[5] - extent[4] + 1; 00466 00467 return dims[0]*dims[1]*dims[2]; 00468 } 00469 00470 //---------------------------------------------------------------------------- 00471 inline int vtkImageData::GetDataDimension() 00472 { 00473 return vtkStructuredData::GetDataDimension(this->DataDescription); 00474 } 00475 00476 #endif