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 "vtkDataSet.h" 00034 00035 #include "vtkStructuredData.h" // Needed for inline methods 00036 00037 class vtkDataArray; 00038 class vtkLine; 00039 class vtkPixel; 00040 class vtkVertex; 00041 class vtkVoxel; 00042 00043 class VTK_FILTERING_EXPORT vtkImageData : public vtkDataSet 00044 { 00045 public: 00046 static vtkImageData *New(); 00047 00048 vtkTypeMacro(vtkImageData,vtkDataSet); 00049 void PrintSelf(ostream& os, vtkIndent indent); 00050 00053 virtual void CopyStructure(vtkDataSet *ds); 00054 00056 virtual int GetDataObjectType() {return VTK_IMAGE_DATA;}; 00057 00059 00060 virtual vtkIdType GetNumberOfCells(); 00061 virtual vtkIdType GetNumberOfPoints(); 00062 virtual double *GetPoint(vtkIdType ptId); 00063 virtual void GetPoint(vtkIdType id, double x[3]); 00064 virtual vtkCell *GetCell(vtkIdType cellId); 00065 virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell); 00066 virtual void GetCellBounds(vtkIdType cellId, double bounds[6]); 00067 virtual vtkIdType FindPoint(double x, double y, double z) 00068 { 00069 return this->vtkDataSet::FindPoint(x, y, z); 00070 } 00071 virtual vtkIdType FindPoint(double x[3]); 00072 virtual vtkIdType FindCell( 00073 double x[3], vtkCell *cell, vtkIdType cellId, double tol2, 00074 int& subId, double pcoords[3], double *weights); 00075 virtual vtkIdType FindCell( 00076 double x[3], vtkCell *cell, vtkGenericCell *gencell, 00077 vtkIdType cellId, double tol2, int& subId, 00078 double pcoords[3], double *weights); 00079 virtual vtkCell *FindAndGetCell(double x[3], vtkCell *cell, vtkIdType cellId, 00080 double tol2, int& subId, double pcoords[3], 00081 double *weights); 00082 virtual int GetCellType(vtkIdType cellId); 00083 virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) 00084 {vtkStructuredData::GetCellPoints(cellId,ptIds,this->DataDescription, 00085 this->GetDimensions());} 00086 virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds) 00087 {vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());} 00088 virtual void ComputeBounds(); 00089 virtual int GetMaxCellSize() {return 8;}; //voxel is the largest 00091 00093 virtual void Initialize(); 00094 00097 virtual void SetDimensions(int i, int j, int k); 00098 00102 virtual void SetDimensions(const int dims[3]); 00103 00105 00108 virtual int *GetDimensions(); 00109 virtual void GetDimensions(int dims[3]); 00111 00113 00118 virtual int ComputeStructuredCoordinates( 00119 double x[3], int ijk[3], double pcoords[3]); 00121 00123 00131 virtual void GetVoxelGradient( 00132 int i,int j,int k, vtkDataArray *s, vtkDataArray *g); 00134 00136 00141 virtual void GetPointGradient( 00142 int i, int j, int k, vtkDataArray *s, double g[3]); 00144 00146 virtual int GetDataDimension(); 00147 00149 00151 virtual vtkIdType ComputePointId(int ijk[3]) { 00152 return vtkStructuredData::ComputePointIdForExtent(this->Extent,ijk);}; 00154 00156 00158 virtual vtkIdType ComputeCellId(int ijk[3]) { 00159 return vtkStructuredData::ComputeCellIdForExtent(this->Extent,ijk);}; 00161 00163 00164 virtual void SetAxisUpdateExtent(int axis, int min, int max); 00165 virtual void GetAxisUpdateExtent(int axis, int &min, int &max); 00167 00171 virtual void UpdateInformation(); 00172 00174 00182 virtual void SetExtent(int extent[6]); 00183 virtual void SetExtent(int x1, int x2, int y1, int y2, int z1, int z2); 00184 vtkGetVector6Macro(Extent, int); 00186 00191 virtual unsigned long GetEstimatedMemorySize(); 00192 00194 00196 virtual double GetScalarTypeMin(); 00197 virtual double GetScalarTypeMax(); 00199 00201 virtual int GetScalarSize(); 00202 00204 00207 virtual vtkIdType *GetIncrements(); 00208 virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00209 virtual void GetIncrements(vtkIdType inc[3]); 00211 00213 00222 virtual void GetContinuousIncrements( 00223 int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00225 00227 00228 virtual void *GetScalarPointerForExtent(int extent[6]); 00229 virtual void *GetScalarPointer(int coordinates[3]); 00230 virtual void *GetScalarPointer(int x, int y, int z); 00231 virtual void *GetScalarPointer(); 00233 00235 00236 virtual float GetScalarComponentAsFloat(int x, int y, int z, int component); 00237 virtual void SetScalarComponentFromFloat( 00238 int x, int y, int z, int component, float v); 00239 virtual double GetScalarComponentAsDouble(int x, int y, int z, int component); 00240 virtual void SetScalarComponentFromDouble( 00241 int x, int y, int z, int component, double v); 00243 00245 virtual void AllocateScalars(); 00246 00248 00252 virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]); 00253 virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, 00254 int y0, int y1, int z0, int z1) 00255 {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1; 00256 this->CopyAndCastFrom(inData, e);} 00258 00262 virtual void Crop(); 00263 00269 virtual unsigned long GetActualMemorySize(); 00270 00272 00274 vtkSetVector3Macro(Spacing,double); 00275 vtkGetVector3Macro(Spacing,double); 00277 00279 00285 vtkSetVector3Macro(Origin,double); 00286 vtkGetVector3Macro(Origin,double); 00288 00290 00295 void SetScalarTypeToFloat(){this->SetScalarType(VTK_FLOAT);}; 00296 void SetScalarTypeToDouble(){this->SetScalarType(VTK_DOUBLE);}; 00297 void SetScalarTypeToInt(){this->SetScalarType(VTK_INT);}; 00298 void SetScalarTypeToUnsignedInt() 00299 {this->SetScalarType(VTK_UNSIGNED_INT);}; 00300 void SetScalarTypeToLong(){this->SetScalarType(VTK_LONG);}; 00301 void SetScalarTypeToUnsignedLong() 00302 {this->SetScalarType(VTK_UNSIGNED_LONG);}; 00303 void SetScalarTypeToShort(){this->SetScalarType(VTK_SHORT);}; 00304 void SetScalarTypeToUnsignedShort() 00305 {this->SetScalarType(VTK_UNSIGNED_SHORT);}; 00306 void SetScalarTypeToUnsignedChar() 00307 {this->SetScalarType(VTK_UNSIGNED_CHAR);}; 00308 void SetScalarTypeToSignedChar() 00309 {this->SetScalarType(VTK_SIGNED_CHAR);}; 00310 void SetScalarTypeToChar() 00311 {this->SetScalarType(VTK_CHAR);}; 00312 void SetScalarType(int); 00313 int GetScalarType(); 00314 const char* GetScalarTypeAsString() 00315 { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); }; 00317 00319 00321 void SetNumberOfScalarComponents( int n ); 00322 int GetNumberOfScalarComponents(); 00324 00325 // Must only be called with vtkImageData (or subclass) as input 00326 virtual void CopyTypeSpecificInformation( vtkDataObject *image ); 00327 00329 00331 virtual void CopyInformationToPipeline(vtkInformation* request, 00332 vtkInformation* input, 00333 vtkInformation* output, 00334 int forceCopy); 00335 virtual void CopyInformationFromPipeline(vtkInformation* request); 00337 00341 virtual void PrepareForNewData(); 00342 00344 00345 virtual void ShallowCopy(vtkDataObject *src); 00346 virtual void DeepCopy(vtkDataObject *src); 00348 00349 //-------------------------------------------------------------------------- 00350 // Methods that apply to any array (not just scalars). 00351 // I am starting to experiment with generalizing imaging fitlers 00352 // to operate on more than just scalars. 00353 00355 00358 void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]); 00359 void *GetArrayPointer(vtkDataArray* array, int coordinates[3]); 00361 00364 void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]); 00365 00370 void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds); 00371 00373 virtual int GetExtentType() { return VTK_3D_EXTENT; }; 00374 00375 //BTX 00377 00378 static vtkImageData* GetData(vtkInformation* info); 00379 static vtkImageData* GetData(vtkInformationVector* v, int i=0); 00380 //ETX 00382 00383 protected: 00384 vtkImageData(); 00385 ~vtkImageData(); 00386 00387 // The extent of what is currently in the structured grid. 00388 // Dimensions is just an array to return a value. 00389 // Its contents are out of data until GetDimensions is called. 00390 int Dimensions[3]; 00391 vtkIdType Increments[3]; 00392 00393 double Origin[3]; 00394 double Spacing[3]; 00395 00396 int Extent[6]; 00397 00398 void ComputeIncrements(); 00399 void ComputeIncrements(vtkIdType inc[3]); 00400 void CopyOriginAndSpacingFromPipeline(); 00401 00402 vtkTimeStamp ExtentComputeTime; 00403 00404 void SetDataDescription(int desc); 00405 int GetDataDescription() { return this->DataDescription; } 00406 00407 private: 00408 void InternalImageDataCopy(vtkImageData *src); 00409 private: 00410 00411 //BTX 00412 friend class vtkUniformGrid; 00413 //ETX 00414 00415 // for the GetCell method 00416 vtkVertex *Vertex; 00417 vtkLine *Line; 00418 vtkPixel *Pixel; 00419 vtkVoxel *Voxel; 00420 00421 int DataDescription; 00422 00423 vtkImageData(const vtkImageData&); // Not implemented. 00424 void operator=(const vtkImageData&); // Not implemented. 00425 }; 00426 00427 00428 //---------------------------------------------------------------------------- 00429 inline void vtkImageData::ComputeIncrements() 00430 { 00431 this->ComputeIncrements(this->Increments); 00432 } 00433 00434 //---------------------------------------------------------------------------- 00435 inline void vtkImageData::GetPoint(vtkIdType id, double x[3]) 00436 { 00437 const double *p = this->GetPoint(id); 00438 x[0] = p[0]; x[1] = p[1]; x[2] = p[2]; 00439 } 00440 00441 //---------------------------------------------------------------------------- 00442 inline vtkIdType vtkImageData::GetNumberOfPoints() 00443 { 00444 const int *extent = this->Extent; 00445 vtkIdType dims[3]; 00446 dims[0] = extent[1] - extent[0] + 1; 00447 dims[1] = extent[3] - extent[2] + 1; 00448 dims[2] = extent[5] - extent[4] + 1; 00449 00450 return dims[0]*dims[1]*dims[2]; 00451 } 00452 00453 //---------------------------------------------------------------------------- 00454 inline int vtkImageData::GetDataDimension() 00455 { 00456 return vtkStructuredData::GetDataDimension(this->DataDescription); 00457 } 00458 00459 #endif