]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/volume.hxx
112b6a65c3b273fcd3198fac7a9f5a6dab7ef04f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / volume.hxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: volume.hxx,v $
5   Language:  C++
6   Date:      $Date: 2010/04/20 16:11:40 $
7   Version:   $Revision: 1.7 $
8
9   Copyright: (c) 2002, 2003
10   License:
11   
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18 #ifndef KGFO__VOLUME__HXX
19 #define KGFO__VOLUME__HXX
20
21 #include "marTypes.h"
22 #include <string>
23
24 #ifdef KGFO_USE_VTK
25 #include <vtkImageData.h>
26 #endif // KGFO_USE_VTK
27
28 class creaMaracasVisu_EXPORT kVolume
29 {
30     public:
31
32     enum Creator{ VTK, IDO, SELF };
33     enum Coord{ CX = 0, CY = 1, CZ = 2 };
34     enum Type{ CHAR = 0, FLOAT = 1, DOUBLE = 2,
35                INT = 3, SHORT = 4, UCHAR = 5,
36                UINT = 6, USHORT = 7 };
37
38     static const int SIZETypes[];
39     static const void* BLANK;
40     static const void* NOALLOC;
41 #ifdef KGFO_USE_VTK
42
43     static const vtkIdType VTKTypes[];
44
45 #endif // KGFO_USE_VTK
46
47     public:
48
49     kVolume( );
50
51     kVolume( Type type,
52              uint32_t xdim, uint32_t ydim, uint32_t zdim,
53              double xsize = 1, double ysize = 1, double zsize = 1,
54              void* data = 0 );
55     kVolume( Type type,
56              const uint32_t *dims,
57              const double *sizes,
58              void* data = 0 );
59
60     kVolume( const kVolume& org );
61     kVolume& operator=( const kVolume& org );
62     void copyFrom( const kVolume& org );
63
64     virtual ~kVolume( ) { deallocate( ); }
65
66     Type getType( ) const { return( _type ); }
67
68     bool sameDimension( const kVolume& comp );
69
70     const uint32_t* getDimensions( ) const { return( _dims ); }
71     uint32_t getWidth( ) const { return( _dims[ CX ] ); }
72     uint32_t getHeight( ) const { return( _dims[ CY ] ); }
73     uint32_t getDepth( ) const { return( _dims[ CZ ] ); }
74     uint32_t getNcols( ) const { return( _dims[ CX ] ); }
75     uint32_t getNrows( ) const { return( _dims[ CY ] ); }
76     uint32_t getNplanes( ) const { return( _dims[ CZ ] ); }
77     uint32_t getXdim( ) const { return( _dims[ CX ] ); }
78     uint32_t getYdim( ) const { return( _dims[ CY ] ); }
79     uint32_t getZdim( ) const { return( _dims[ CZ ] ); }
80
81     void setDimensions( uint32_t* dims )
82     {
83         memcpy( _dims, dims, 3 * sizeof( uint32_t ) );
84     }
85     void setWidth( uint32_t w ) { _dims[ CX ] = w; }
86     void setHeight( uint32_t h ) { _dims[ CY ] = h; }
87     void setDepth( uint32_t d ) { _dims[ CZ ] = d; }
88     void setNcols( uint32_t c ) { _dims[ CX ] = c; }
89     void setNrows( uint32_t r ) { _dims[ CY ] = r; }
90     void setNplanes( uint32_t p ) { _dims[ CZ ] = p; }
91     void setXdim( uint32_t x ) { _dims[ CX ] = x; }
92     void setYdim( uint32_t y ) { _dims[ CY ] = y; }
93     void setZdim( uint32_t z ) { _dims[ CZ ] = z; }
94
95     const double *getSizes( ) const { return( _sizes ); }
96     double getXsize( ) const { return( _sizes[ CX ] ); }
97     double getYsize( ) const { return( _sizes[ CY ] ); }
98     double getZsize( ) const { return( _sizes[ CZ ] ); }
99
100     void setSizes( double* sizes )
101     {
102         memcpy( _sizes, sizes, 3 * sizeof( double ) );
103     }
104     void setXsize( double x ) { _sizes[ CX ] = x; }
105     void setYsize( double y ) { _sizes[ CY ] = y; }
106     void setZsize( double z ) { _sizes[ CZ ] = z; }
107
108     void* getData1D( ) { return( _raw ); }
109     const void* getData1D( ) const { return( _raw ); }
110
111     void** getData2D( ) { return( _columns ); }
112     void** const getData2D( ) const { return( _columns ); }
113
114     void*** getData3D( ) { return( _images ); }
115     void*** const getData3D( ) const { return( _images ); }
116
117     void reset( ) { memset( _raw, 0, getRawSizeInBytes( ) ); }
118
119     ulong getRawSize( ) const
120     {
121         return( ( ulong )_dims[ CX ] *
122                 ( ulong )_dims[ CY ] *
123                 ( ulong )_dims[ CZ ] );
124     }
125     ulong getRawSizeInBytes( ) const
126     {
127         return( SIZETypes[ _type ] * getRawSize( ) );
128     }
129
130     double getPixel( uint32_t x, uint32_t y, uint32_t z ) const;
131     void setPixel( double v, uint32_t x, uint32_t y, uint32_t z );
132
133     void convertCast( Type type );
134     void convertScale( Type type, double min, double max );
135     void normalize( double min, double max )
136     {
137         convertScale( _type, min, max );
138     }
139
140     void getMinMax( double& min, double& max ) const;
141     double getMin( ) const;
142     double getMax( ) const;
143     //double GetMaxIntSphere( double* p, const double r ) const;
144     unsigned short GetMaxIntSphere2( double* p, const double r );
145
146   private:
147
148     void allocate( );
149     void buildIndex( );
150     void deallocate( );
151
152   protected:
153
154     Type _type;
155     Creator _creator;
156
157     uint32_t _dims[ 3 ];
158     double _sizes[ 3 ];
159     void* _raw;
160     void** _columns;
161     void*** _images;
162
163 #ifdef KGFO_USE_VTK
164
165     public:
166
167     /**
168      * Creators/copiers from a vtkImageData object.
169      * C++ creators allows you to create a kVolume cast to you vtkImageData
170      * object, but if extent != bounds, you can expect a weird behaviour.
171      * If you want to forget all about extents, then crop your volume or
172      * use either the operator= or the copyFrom method.
173      */
174     kVolume( vtkImageData* org );
175     kVolume& operator=( vtkImageData* org );
176     void copyFrom( vtkImageData* org ); 
177
178     vtkImageData* castVtk( ) const { return( _vtk ); }
179     operator vtkImageData*( ) const { return( _vtk ); }
180
181     protected:
182
183     vtkImageData* _vtk;
184
185 #endif // KGFO_USE_VTK
186
187 };
188
189 #endif // KGFO__VOLUME__HXX
190
191 // eof - volume.hxx