1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: volume.hxx,v $
31 Date: $Date: 2012/11/15 14:16:12 $
32 Version: $Revision: 1.9 $
34 Copyright: (c) 2002, 2003
37 This software is distributed WITHOUT ANY WARRANTY; without even
38 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39 PURPOSE. See the above copyright notice for more information.
41 =========================================================================*/
43 #ifndef KGFO__VOLUME__HXX
44 #define KGFO__VOLUME__HXX
50 #include <vtkImageData.h>
51 #endif // KGFO_USE_VTK
53 class creaMaracasVisu_EXPORT kVolume
57 enum Creator{ VTK, IDO, SELF };
58 enum Coord{ CX = 0, CY = 1, CZ = 2 };
59 enum Type{ CHAR = 0, FLOAT = 1, DOUBLE = 2,
60 INT = 3, SHORT = 4, UCHAR = 5,
61 UINT = 6, USHORT = 7 };
63 static const int SIZETypes[];
64 static const void* BLANK;
65 static const void* NOALLOC;
68 static const vtkIdType VTKTypes[];
70 #endif // KGFO_USE_VTK
77 uint32_t xdim, uint32_t ydim, uint32_t zdim,
78 double xsize = 1, double ysize = 1, double zsize = 1,
85 kVolume( const kVolume& org );
86 kVolume& operator=( const kVolume& org );
87 void copyFrom( const kVolume& org );
89 virtual ~kVolume( ) { deallocate( ); }
91 Type getType( ) const { return( _type ); }
93 bool sameDimension( const kVolume& comp );
95 const uint32_t* getDimensions( ) const { return( _dims ); }
96 uint32_t getWidth( ) const { return( _dims[ CX ] ); }
97 uint32_t getHeight( ) const { return( _dims[ CY ] ); }
98 uint32_t getDepth( ) const { return( _dims[ CZ ] ); }
99 uint32_t getNcols( ) const { return( _dims[ CX ] ); }
100 uint32_t getNrows( ) const { return( _dims[ CY ] ); }
101 uint32_t getNplanes( ) const { return( _dims[ CZ ] ); }
102 uint32_t getXdim( ) const { return( _dims[ CX ] ); }
103 uint32_t getYdim( ) const { return( _dims[ CY ] ); }
104 uint32_t getZdim( ) const { return( _dims[ CZ ] ); }
106 void setDimensions( uint32_t* dims )
108 memcpy( _dims, dims, 3 * sizeof( uint32_t ) );
110 void setWidth( uint32_t w ) { _dims[ CX ] = w; }
111 void setHeight( uint32_t h ) { _dims[ CY ] = h; }
112 void setDepth( uint32_t d ) { _dims[ CZ ] = d; }
113 void setNcols( uint32_t c ) { _dims[ CX ] = c; }
114 void setNrows( uint32_t r ) { _dims[ CY ] = r; }
115 void setNplanes( uint32_t p ) { _dims[ CZ ] = p; }
116 void setXdim( uint32_t x ) { _dims[ CX ] = x; }
117 void setYdim( uint32_t y ) { _dims[ CY ] = y; }
118 void setZdim( uint32_t z ) { _dims[ CZ ] = z; }
120 const double *getSizes( ) const { return( _sizes ); }
121 double getXsize( ) const { return( _sizes[ CX ] ); }
122 double getYsize( ) const { return( _sizes[ CY ] ); }
123 double getZsize( ) const { return( _sizes[ CZ ] ); }
125 void setSizes( double* sizes )
127 memcpy( _sizes, sizes, 3 * sizeof( double ) );
129 void setXsize( double x ) { _sizes[ CX ] = x; }
130 void setYsize( double y ) { _sizes[ CY ] = y; }
131 void setZsize( double z ) { _sizes[ CZ ] = z; }
133 void* getData1D( ) { return( _raw ); }
134 const void* getData1D( ) const { return( _raw ); }
136 void** getData2D( ) { return( _columns ); }
137 void** const getData2D( ) const { return( _columns ); }
139 void*** getData3D( ) { return( _images ); }
140 void*** const getData3D( ) const { return( _images ); }
142 void reset( ) { memset( _raw, 0, getRawSizeInBytes( ) ); }
144 ulong getRawSize( ) const
146 return( ( ulong )_dims[ CX ] *
147 ( ulong )_dims[ CY ] *
148 ( ulong )_dims[ CZ ] );
150 ulong getRawSizeInBytes( ) const
152 return( SIZETypes[ _type ] * getRawSize( ) );
155 double getPixel( uint x, uint y, uint z ) const;
156 void setPixel( double v, uint x, uint y, uint z );
158 void convertCast( Type type );
159 void convertScale( Type type, double min, double max );
160 void normalize( double min, double max )
162 convertScale( _type, min, max );
165 void getMinMax( double& min, double& max ) const;
166 double getMin( ) const;
167 double getMax( ) const;
168 //double GetMaxIntSphere( double* p, const double r ) const;
169 unsigned short GetMaxIntSphere2( double* p, const double r );
193 * Creators/copiers from a vtkImageData object.
194 * C++ creators allows you to create a kVolume cast to you vtkImageData
195 * object, but if extent != bounds, you can expect a weird behaviour.
196 * If you want to forget all about extents, then crop your volume or
197 * use either the operator= or the copyFrom method.
199 kVolume( vtkImageData* org );
200 kVolume& operator=( vtkImageData* org );
201 void copyFrom( vtkImageData* org );
203 vtkImageData* castVtk( ) const { return( _vtk ); }
204 operator vtkImageData*( ) const { return( _vtk ); }
210 #endif // KGFO_USE_VTK
214 #endif // KGFO__VOLUME__HXX