]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/volume.hxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / volume.hxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: volume.hxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:16:12 $
32   Version:   $Revision: 1.9 $
33
34   Copyright: (c) 2002, 2003
35   License:
36   
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.
40
41 =========================================================================*/
42
43 #ifndef KGFO__VOLUME__HXX
44 #define KGFO__VOLUME__HXX
45
46 #include "marTypes.h"
47 #include <string>
48
49 #ifdef KGFO_USE_VTK
50 #include <vtkImageData.h>
51 #endif // KGFO_USE_VTK
52
53 class creaMaracasVisu_EXPORT kVolume
54 {
55     public:
56
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 };
62
63     static const int SIZETypes[];
64     static const void* BLANK;
65     static const void* NOALLOC;
66 #ifdef KGFO_USE_VTK
67
68     static const vtkIdType VTKTypes[];
69
70 #endif // KGFO_USE_VTK
71
72     public:
73
74     kVolume( );
75
76     kVolume( Type type,
77              uint32_t xdim, uint32_t ydim, uint32_t zdim,
78              double xsize = 1, double ysize = 1, double zsize = 1,
79              void* data = 0 );
80     kVolume( Type type,
81              const uint32_t *dims,
82              const double *sizes,
83              void* data = 0 );
84
85     kVolume( const kVolume& org );
86     kVolume& operator=( const kVolume& org );
87     void copyFrom( const kVolume& org );
88
89     virtual ~kVolume( ) { deallocate( ); }
90
91     Type getType( ) const { return( _type ); }
92
93     bool sameDimension( const kVolume& comp );
94
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 ] ); }
105
106     void setDimensions( uint32_t* dims )
107     {
108         memcpy( _dims, dims, 3 * sizeof( uint32_t ) );
109     }
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; }
119
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 ] ); }
124
125     void setSizes( double* sizes )
126     {
127         memcpy( _sizes, sizes, 3 * sizeof( double ) );
128     }
129     void setXsize( double x ) { _sizes[ CX ] = x; }
130     void setYsize( double y ) { _sizes[ CY ] = y; }
131     void setZsize( double z ) { _sizes[ CZ ] = z; }
132
133     void* getData1D( ) { return( _raw ); }
134     const void* getData1D( ) const { return( _raw ); }
135
136     void** getData2D( ) { return( _columns ); }
137     void** const getData2D( ) const { return( _columns ); }
138
139     void*** getData3D( ) { return( _images ); }
140     void*** const getData3D( ) const { return( _images ); }
141
142     void reset( ) { memset( _raw, 0, getRawSizeInBytes( ) ); }
143
144     ulong getRawSize( ) const
145     {
146         return( ( ulong )_dims[ CX ] *
147                 ( ulong )_dims[ CY ] *
148                 ( ulong )_dims[ CZ ] );
149     }
150     ulong getRawSizeInBytes( ) const
151     {
152         return( SIZETypes[ _type ] * getRawSize( ) );
153     }
154
155     double getPixel( uint x, uint y, uint z ) const;
156     void setPixel( double v, uint x, uint y, uint z );
157
158     void convertCast( Type type );
159     void convertScale( Type type, double min, double max );
160     void normalize( double min, double max )
161     {
162         convertScale( _type, min, max );
163     }
164
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 );
170
171   private:
172
173     void allocate( );
174     void buildIndex( );
175     void deallocate( );
176
177   protected:
178
179     Type _type;
180     Creator _creator;
181
182     uint32_t _dims[ 3 ];
183     double _sizes[ 3 ];
184     void* _raw;
185     void** _columns;
186     void*** _images;
187
188 #ifdef KGFO_USE_VTK
189
190     public:
191
192     /**
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.
198      */
199     kVolume( vtkImageData* org );
200     kVolume& operator=( vtkImageData* org );
201     void copyFrom( vtkImageData* org ); 
202
203     vtkImageData* castVtk( ) const { return( _vtk ); }
204     operator vtkImageData*( ) const { return( _vtk ); }
205
206     protected:
207
208     vtkImageData* _vtk;
209
210 #endif // KGFO_USE_VTK
211
212 };
213
214 #endif // KGFO__VOLUME__HXX
215
216 // eof - volume.hxx