]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/volume.hxx
3e3c056ee43471ec1fcc243ba0840dfaaedcd883
[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: 2009/01/26 11:22:49 $
7   Version:   $Revision: 1.4 $
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_IDO
25 //extern "C"
26 //{
27 //#include <idvol.h>
28 //};
29 //#endif // KGFO_USE_IDO
30
31 #ifdef KGFO_USE_VTK
32 #include <vtkImageData.h>
33 #endif // KGFO_USE_VTK
34
35 class creaMaracasVisu_EXPORT kVolume
36 {
37     public:
38
39     enum Creator{ VTK, IDO, SELF };
40     enum Coord{ CX = 0, CY = 1, CZ = 2 };
41     enum Type{ CHAR = 0, FLOAT = 1, DOUBLE = 2,
42                INT = 3, SHORT = 4, UCHAR = 5,
43                UINT = 6, USHORT = 7 };
44
45     static const int SIZETypes[];
46     static const void* BLANK;
47     static const void* NOALLOC;
48 #ifdef KGFO_USE_VTK
49
50     static const vtkIdType VTKTypes[];
51
52 #endif // KGFO_USE_VTK
53 //#ifdef KGFO_USE_IDO
54 //
55 //    static const int IDOTypes[];
56 //
57 //#endif // KGFO_USE_IDO
58
59     public:
60
61     kVolume( );
62
63     kVolume( Type type,
64              uint xdim, uint ydim, uint zdim,
65              double xsize = 1, double ysize = 1, double zsize = 1,
66              void* data = 0 );
67     kVolume( Type type,
68              const uint *dims,
69              const double *sizes,
70              void* data = 0 );
71
72     kVolume( const kVolume& org );
73     kVolume& operator=( const kVolume& org );
74     void copyFrom( const kVolume& org );
75
76     virtual ~kVolume( ) { deallocate( ); }
77
78     Type getType( ) const { return( _type ); }
79
80     bool sameDimension( const kVolume& comp );
81
82     const uint* getDimensions( ) const { return( _dims ); }
83     uint getWidth( ) const { return( _dims[ CX ] ); }
84     uint getHeight( ) const { return( _dims[ CY ] ); }
85     uint getDepth( ) const { return( _dims[ CZ ] ); }
86     uint getNcols( ) const { return( _dims[ CX ] ); }
87     uint getNrows( ) const { return( _dims[ CY ] ); }
88     uint getNplanes( ) const { return( _dims[ CZ ] ); }
89     uint getXdim( ) const { return( _dims[ CX ] ); }
90     uint getYdim( ) const { return( _dims[ CY ] ); }
91     uint getZdim( ) const { return( _dims[ CZ ] ); }
92
93     void setDimensions( uint* dims )
94     {
95         memcpy( _dims, dims, 3 * sizeof( uint ) );
96     }
97     void setWidth( uint w ) { _dims[ CX ] = w; }
98     void setHeight( uint h ) { _dims[ CY ] = h; }
99     void setDepth( uint d ) { _dims[ CZ ] = d; }
100     void setNcols( uint c ) { _dims[ CX ] = c; }
101     void setNrows( uint r ) { _dims[ CY ] = r; }
102     void setNplanes( uint p ) { _dims[ CZ ] = p; }
103     void setXdim( uint x ) { _dims[ CX ] = x; }
104     void setYdim( uint y ) { _dims[ CY ] = y; }
105     void setZdim( uint z ) { _dims[ CZ ] = z; }
106
107     const double *getSizes( ) const { return( _sizes ); }
108     double getXsize( ) const { return( _sizes[ CX ] ); }
109     double getYsize( ) const { return( _sizes[ CY ] ); }
110     double getZsize( ) const { return( _sizes[ CZ ] ); }
111
112     void setSizes( double* sizes )
113     {
114         memcpy( _sizes, sizes, 3 * sizeof( double ) );
115     }
116     void setXsize( double x ) { _sizes[ CX ] = x; }
117     void setYsize( double y ) { _sizes[ CY ] = y; }
118     void setZsize( double z ) { _sizes[ CZ ] = z; }
119
120     void* getData1D( ) { return( _raw ); }
121     const void* getData1D( ) const { return( _raw ); }
122
123     void** getData2D( ) { return( _columns ); }
124     void** const getData2D( ) const { return( _columns ); }
125
126     void*** getData3D( ) { return( _images ); }
127     void*** const getData3D( ) const { return( _images ); }
128
129     void reset( ) { memset( _raw, 0, getRawSizeInBytes( ) ); }
130
131     ulong getRawSize( ) const
132     {
133         return( ( ulong )_dims[ CX ] *
134                 ( ulong )_dims[ CY ] *
135                 ( ulong )_dims[ CZ ] );
136     }
137     ulong getRawSizeInBytes( ) const
138     {
139         return( SIZETypes[ _type ] * getRawSize( ) );
140     }
141
142     double getPixel( uint x, uint y, uint z ) const;
143     void setPixel( double v, uint x, uint y, uint z );
144
145     void convertCast( Type type );
146     void convertScale( Type type, double min, double max );
147     void normalize( double min, double max )
148     {
149         convertScale( _type, min, max );
150     }
151
152     void getMinMax( double& min, double& max ) const;
153     double getMin( ) const;
154     double getMax( ) const;
155     //double GetMaxIntSphere( double* p, const double r ) const;
156     unsigned short GetMaxIntSphere2( double* p, const double r );
157
158   private:
159
160     void allocate( );
161     void buildIndex( );
162     void deallocate( );
163
164   protected:
165
166     Type _type;
167     Creator _creator;
168
169     uint _dims[ 3 ];
170     double _sizes[ 3 ];
171     void* _raw;
172     void** _columns;
173     void*** _images;
174
175 #ifdef KGFO_USE_VTK
176
177     public:
178
179     /**
180      * Creators/copiers from a vtkImageData object.
181      * C++ creators allows you to create a kVolume cast to you vtkImageData
182      * object, but if extent != bounds, you can expect a weird behaviour.
183      * If you want to forget all about extents, then crop your volume or
184      * use either the operator= or the copyFrom method.
185      */
186     kVolume( vtkImageData* org );
187     kVolume& operator=( vtkImageData* org );
188     void copyFrom( vtkImageData* org ); 
189
190     vtkImageData* castVtk( ) const { return( _vtk ); }
191     operator vtkImageData*( ) const { return( _vtk ); }
192
193     protected:
194
195     vtkImageData* _vtk;
196
197 #endif // KGFO_USE_VTK
198
199
200 //#ifdef KGFO_USE_IDO
201
202 //    public:
203 //
204 //    kVolume( PPPVOLUME org );
205 //
206 //    kVolume& operator=( PPPVOLUME org );
207 //    void copyFrom( PPPVOLUME org ); 
208 //
209 //    PPPVOLUME castIdo( ) const
210 //    {
211 //      return( ( PPPVOLUME )( &_privateIdo[ 1 ] ) );
212 //    }
213 //    operator PPPVOLUME( ) const
214 //    {
215 //      return( ( PPPVOLUME )( &_privateIdo[ 1 ] ) );
216 //    }
217 //    operator PPPVOLUME_CHAR( ) const
218 //    {
219 //      return( ( PPPVOLUME_CHAR )( &_privateIdo[ 1 ] ) );
220 //    }
221 //    operator PPPVOLUME_FLOAT( ) const
222 //    {
223 //      return( ( PPPVOLUME_FLOAT )( &_privateIdo[ 1 ] ) );
224 //    }
225 //    operator PPPVOLUME_DOUBLE( ) const
226 //    {
227 //      return( ( PPPVOLUME_DOUBLE )( &_privateIdo[ 1 ] ) );
228 //    }
229 //    operator PPPVOLUME_LONG( ) const
230 //    {
231 //      return( ( PPPVOLUME_LONG )( &_privateIdo[ 1 ] ) );
232 //    }
233 //    operator PPPVOLUME_SHORT( ) const
234 //    {
235 //      return( ( PPPVOLUME_SHORT )( &_privateIdo[ 1 ] ) );
236 //    }
237 //    operator PPPVOLUME_UCHAR( ) const
238 //    {
239 //      return( ( PPPVOLUME_UCHAR )( &_privateIdo[ 1 ] ) );
240 //    }
241 //    operator PPPVOLUME_ULONG( ) const
242 //    {
243 //      return( ( PPPVOLUME_ULONG )( &_privateIdo[ 1 ] ) );
244 //    }
245 //    operator PPPVOLUME_USHORT( ) const
246 //    {
247 //      return( ( PPPVOLUME_USHORT )( &_privateIdo[ 1 ] ) );
248 //    }
249 //      
250 //    protected:
251 //
252 //    PRIVATE_VOLUME* _privateIdo;
253 //
254 //#endif // KGFO_USE_IDO
255 };
256
257 #endif // KGFO__VOLUME__HXX
258
259 // eof - volume.hxx