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 00209 virtual vtkIdType *GetIncrements(); 00210 virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00211 virtual void GetIncrements(vtkIdType inc[3]); 00212 virtual vtkIdType *GetIncrements(vtkDataArray *scalars); 00213 virtual void GetIncrements(vtkDataArray *scalars, 00214 vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00215 virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]); 00217 00219 00230 virtual void GetContinuousIncrements( 00231 int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00232 virtual void GetContinuousIncrements(vtkDataArray *scalars, 00233 int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ); 00235 00237 00238 virtual void *GetScalarPointerForExtent(int extent[6]); 00239 virtual void *GetScalarPointer(int coordinates[3]); 00240 virtual void *GetScalarPointer(int x, int y, int z); 00241 virtual void *GetScalarPointer(); 00243 00245 00246 virtual float GetScalarComponentAsFloat(int x, int y, int z, int component); 00247 virtual void SetScalarComponentFromFloat( 00248 int x, int y, int z, int component, float v); 00249 virtual double GetScalarComponentAsDouble(int x, int y, int z, int component); 00250 virtual void SetScalarComponentFromDouble( 00251 int x, int y, int z, int component, double v); 00253 00255 virtual void AllocateScalars(); 00256 00258 00262 virtual void CopyAndCastFrom(vtkImageData *inData, int extent[6]); 00263 virtual void CopyAndCastFrom(vtkImageData *inData, int x0, int x1, 00264 int y0, int y1, int z0, int z1) 00265 {int e[6]; e[0]=x0; e[1]=x1; e[2]=y0; e[3]=y1; e[4]=z0; e[5]=z1; 00266 this->CopyAndCastFrom(inData, e);} 00268 00272 virtual void Crop(); 00273 00279 virtual unsigned long GetActualMemorySize(); 00280 00282 00284 vtkSetVector3Macro(Spacing,double); 00285 vtkGetVector3Macro(Spacing,double); 00287 00289 00295 vtkSetVector3Macro(Origin,double); 00296 vtkGetVector3Macro(Origin,double); 00298 00300 00305 void SetScalarTypeToFloat(){this->SetScalarType(VTK_FLOAT);}; 00306 void SetScalarTypeToDouble(){this->SetScalarType(VTK_DOUBLE);}; 00307 void SetScalarTypeToInt(){this->SetScalarType(VTK_INT);}; 00308 void SetScalarTypeToUnsignedInt() 00309 {this->SetScalarType(VTK_UNSIGNED_INT);}; 00310 void SetScalarTypeToLong(){this->SetScalarType(VTK_LONG);}; 00311 void SetScalarTypeToUnsignedLong() 00312 {this->SetScalarType(VTK_UNSIGNED_LONG);}; 00313 void SetScalarTypeToShort(){this->SetScalarType(VTK_SHORT);}; 00314 void SetScalarTypeToUnsignedShort() 00315 {this->SetScalarType(VTK_UNSIGNED_SHORT);}; 00316 void SetScalarTypeToUnsignedChar() 00317 {this->SetScalarType(VTK_UNSIGNED_CHAR);}; 00318 void SetScalarTypeToSignedChar() 00319 {this->SetScalarType(VTK_SIGNED_CHAR);}; 00320 void SetScalarTypeToChar() 00321 {this->SetScalarType(VTK_CHAR);}; 00322 void SetScalarType(int); 00323 int GetScalarType(); 00324 const char* GetScalarTypeAsString() 00325 { return vtkImageScalarTypeNameMacro ( this->GetScalarType() ); }; 00327 00329 00331 void SetNumberOfScalarComponents( int n ); 00332 int GetNumberOfScalarComponents(); 00334 00335 // Must only be called with vtkImageData (or subclass) as input 00336 virtual void CopyTypeSpecificInformation( vtkDataObject *image ); 00337 00339 00341 virtual void CopyInformationToPipeline(vtkInformation* request, 00342 vtkInformation* input, 00343 vtkInformation* output, 00344 int forceCopy); 00345 virtual void CopyInformationFromPipeline(vtkInformation* request); 00347 00351 virtual void PrepareForNewData(); 00352 00354 00355 virtual void ShallowCopy(vtkDataObject *src); 00356 virtual void DeepCopy(vtkDataObject *src); 00358 00359 //-------------------------------------------------------------------------- 00360 // Methods that apply to any array (not just scalars). 00361 // I am starting to experiment with generalizing imaging fitlers 00362 // to operate on more than just scalars. 00363 00365 00368 void *GetArrayPointerForExtent(vtkDataArray* array, int extent[6]); 00369 void *GetArrayPointer(vtkDataArray* array, int coordinates[3]); 00371 00374 void GetArrayIncrements(vtkDataArray *array, vtkIdType increments[3]); 00375 00380 void ComputeInternalExtent(int *intExt, int *tgtExt, int *bnds); 00381 00383 virtual int GetExtentType() { return VTK_3D_EXTENT; }; 00384 00385 //BTX 00387 00388 static vtkImageData* GetData(vtkInformation* info); 00389 static vtkImageData* GetData(vtkInformationVector* v, int i=0); 00390 //ETX 00392 00393 protected: 00394 vtkImageData(); 00395 ~vtkImageData(); 00396 00397 // The extent of what is currently in the structured grid. 00398 // Dimensions is just an array to return a value. 00399 // Its contents are out of data until GetDimensions is called. 00400 int Dimensions[3]; 00401 vtkIdType Increments[3]; 00402 00403 double Origin[3]; 00404 double Spacing[3]; 00405 00406 int Extent[6]; 00407 00408 // The first method assumes Active Scalars 00409 void ComputeIncrements(); 00410 // This one is given the number of components of the 00411 // scalar field explicitly 00412 void ComputeIncrements(int numberOfComponents); 00413 void ComputeIncrements(vtkDataArray *scalars); 00414 00415 // The first method assumes Acitive Scalars 00416 void ComputeIncrements(vtkIdType inc[3]); 00417 // This one is given the number of components of the 00418 // scalar field explicitly 00419 void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]); 00420 void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]); 00421 void CopyOriginAndSpacingFromPipeline(); 00422 00423 vtkTimeStamp ExtentComputeTime; 00424 00425 void SetDataDescription(int desc); 00426 int GetDataDescription() { return this->DataDescription; } 00427 00428 private: 00429 void InternalImageDataCopy(vtkImageData *src); 00430 private: 00431 00432 //BTX 00433 friend class vtkUniformGrid; 00434 //ETX 00435 00436 // for the GetCell method 00437 vtkVertex *Vertex; 00438 vtkLine *Line; 00439 vtkPixel *Pixel; 00440 vtkVoxel *Voxel; 00441 00442 int DataDescription; 00443 00444 vtkImageData(const vtkImageData&); // Not implemented. 00445 void operator=(const vtkImageData&); // Not implemented. 00446 }; 00447 00448 00449 //---------------------------------------------------------------------------- 00450 inline void vtkImageData::ComputeIncrements() 00451 { 00452 this->ComputeIncrements(this->Increments); 00453 } 00454 00455 //---------------------------------------------------------------------------- 00456 inline void vtkImageData::ComputeIncrements(int numberOfComponents) 00457 { 00458 this->ComputeIncrements(numberOfComponents, this->Increments); 00459 } 00460 00461 //---------------------------------------------------------------------------- 00462 inline void vtkImageData::ComputeIncrements(vtkDataArray *scalars) 00463 { 00464 this->ComputeIncrements(scalars, this->Increments); 00465 } 00466 00467 //---------------------------------------------------------------------------- 00468 inline void vtkImageData::GetPoint(vtkIdType id, double x[3]) 00469 { 00470 const double *p = this->GetPoint(id); 00471 x[0] = p[0]; x[1] = p[1]; x[2] = p[2]; 00472 } 00473 00474 //---------------------------------------------------------------------------- 00475 inline vtkIdType vtkImageData::GetNumberOfPoints() 00476 { 00477 const int *extent = this->Extent; 00478 vtkIdType dims[3]; 00479 dims[0] = extent[1] - extent[0] + 1; 00480 dims[1] = extent[3] - extent[2] + 1; 00481 dims[2] = extent[5] - extent[4] + 1; 00482 00483 return dims[0]*dims[1]*dims[2]; 00484 } 00485 00486 //---------------------------------------------------------------------------- 00487 inline int vtkImageData::GetDataDimension() 00488 { 00489 return vtkStructuredData::GetDataDimension(this->DataDescription); 00490 } 00491 00492 #endif