/*========================================================================= Program: wxMaracas Module: $RCSfile: volume.hxx,v $ Language: C++ Date: $Date: 2008/11/24 10:47:12 $ Version: $Revision: 1.2 $ Copyright: (c) 2002, 2003 License: This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #ifndef KGFO__VOLUME__HXX #define KGFO__VOLUME__HXX #include "marTypes.h" #include #ifdef KGFO_USE_IDO extern "C" { #include }; #endif // KGFO_USE_IDO #ifdef KGFO_USE_VTK #include #endif // KGFO_USE_VTK class MARACASVISULIB_EXPORTS kVolume { public: enum Creator{ VTK, IDO, SELF }; enum Coord{ CX = 0, CY = 1, CZ = 2 }; enum Type{ CHAR = 0, FLOAT = 1, DOUBLE = 2, INT = 3, SHORT = 4, UCHAR = 5, UINT = 6, USHORT = 7 }; static const int SIZETypes[]; static const void* BLANK; static const void* NOALLOC; #ifdef KGFO_USE_VTK static const vtkIdType VTKTypes[]; #endif // KGFO_USE_VTK #ifdef KGFO_USE_IDO static const int IDOTypes[]; #endif // KGFO_USE_IDO public: kVolume( ); kVolume( Type type, uint xdim, uint ydim, uint zdim, double xsize = 1, double ysize = 1, double zsize = 1, void* data = 0 ); kVolume( Type type, const uint *dims, const double *sizes, void* data = 0 ); kVolume( const kVolume& org ); kVolume& operator=( const kVolume& org ); void copyFrom( const kVolume& org ); virtual ~kVolume( ) { deallocate( ); } Type getType( ) const { return( _type ); } bool sameDimension( const kVolume& comp ); const uint* getDimensions( ) const { return( _dims ); } uint getWidth( ) const { return( _dims[ CX ] ); } uint getHeight( ) const { return( _dims[ CY ] ); } uint getDepth( ) const { return( _dims[ CZ ] ); } uint getNcols( ) const { return( _dims[ CX ] ); } uint getNrows( ) const { return( _dims[ CY ] ); } uint getNplanes( ) const { return( _dims[ CZ ] ); } uint getXdim( ) const { return( _dims[ CX ] ); } uint getYdim( ) const { return( _dims[ CY ] ); } uint getZdim( ) const { return( _dims[ CZ ] ); } void setDimensions( uint* dims ) { memcpy( _dims, dims, 3 * sizeof( uint ) ); } void setWidth( uint w ) { _dims[ CX ] = w; } void setHeight( uint h ) { _dims[ CY ] = h; } void setDepth( uint d ) { _dims[ CZ ] = d; } void setNcols( uint c ) { _dims[ CX ] = c; } void setNrows( uint r ) { _dims[ CY ] = r; } void setNplanes( uint p ) { _dims[ CZ ] = p; } void setXdim( uint x ) { _dims[ CX ] = x; } void setYdim( uint y ) { _dims[ CY ] = y; } void setZdim( uint z ) { _dims[ CZ ] = z; } const double *getSizes( ) const { return( _sizes ); } double getXsize( ) const { return( _sizes[ CX ] ); } double getYsize( ) const { return( _sizes[ CY ] ); } double getZsize( ) const { return( _sizes[ CZ ] ); } void setSizes( double* sizes ) { memcpy( _sizes, sizes, 3 * sizeof( double ) ); } void setXsize( double x ) { _sizes[ CX ] = x; } void setYsize( double y ) { _sizes[ CY ] = y; } void setZsize( double z ) { _sizes[ CZ ] = z; } void* getData1D( ) { return( _raw ); } const void* getData1D( ) const { return( _raw ); } void** getData2D( ) { return( _columns ); } void** const getData2D( ) const { return( _columns ); } void*** getData3D( ) { return( _images ); } void*** const getData3D( ) const { return( _images ); } void reset( ) { memset( _raw, 0, getRawSizeInBytes( ) ); } ulong getRawSize( ) const { return( ( ulong )_dims[ CX ] * ( ulong )_dims[ CY ] * ( ulong )_dims[ CZ ] ); } ulong getRawSizeInBytes( ) const { return( SIZETypes[ _type ] * getRawSize( ) ); } double getPixel( uint x, uint y, uint z ) const; void setPixel( double v, uint x, uint y, uint z ); void convertCast( Type type ); void convertScale( Type type, double min, double max ); void normalize( double min, double max ) { convertScale( _type, min, max ); } void getMinMax( double& min, double& max ) const; double getMin( ) const; double getMax( ) const; //double GetMaxIntSphere( double* p, const double r ) const; unsigned short GetMaxIntSphere2( double* p, const double r ); private: void allocate( ); void buildIndex( ); void deallocate( ); protected: Type _type; Creator _creator; uint _dims[ 3 ]; double _sizes[ 3 ]; void* _raw; void** _columns; void*** _images; #ifdef KGFO_USE_VTK public: /** * Creators/copiers from a vtkImageData object. * C++ creators allows you to create a kVolume cast to you vtkImageData * object, but if extent != bounds, you can expect a weird behaviour. * If you want to forget all about extents, then crop your volume or * use either the operator= or the copyFrom method. */ kVolume( vtkImageData* org ); kVolume& operator=( vtkImageData* org ); void copyFrom( vtkImageData* org ); vtkImageData* castVtk( ) const { return( _vtk ); } operator vtkImageData*( ) const { return( _vtk ); } protected: vtkImageData* _vtk; #endif // KGFO_USE_VTK #ifdef KGFO_USE_IDO public: kVolume( PPPVOLUME org ); kVolume& operator=( PPPVOLUME org ); void copyFrom( PPPVOLUME org ); PPPVOLUME castIdo( ) const { return( ( PPPVOLUME )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME( ) const { return( ( PPPVOLUME )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_CHAR( ) const { return( ( PPPVOLUME_CHAR )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_FLOAT( ) const { return( ( PPPVOLUME_FLOAT )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_DOUBLE( ) const { return( ( PPPVOLUME_DOUBLE )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_LONG( ) const { return( ( PPPVOLUME_LONG )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_SHORT( ) const { return( ( PPPVOLUME_SHORT )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_UCHAR( ) const { return( ( PPPVOLUME_UCHAR )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_ULONG( ) const { return( ( PPPVOLUME_ULONG )( &_privateIdo[ 1 ] ) ); } operator PPPVOLUME_USHORT( ) const { return( ( PPPVOLUME_USHORT )( &_privateIdo[ 1 ] ) ); } protected: PRIVATE_VOLUME* _privateIdo; #endif // KGFO_USE_IDO }; #endif // KGFO__VOLUME__HXX // eof - volume.hxx