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: marParameters.cpp,v $
31 Date: $Date: 2012/11/15 14:16:12 $
32 Version: $Revision: 1.4 $
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 #include "marParameters.h"
47 static const char* BoolParamNames[] = {
48 // PS -> "e_debug_window_visible" ,
49 // PS -> "e_debug_console_visible" ,
50 // PS -> "e_calculate_mip_default" ,
51 // PS -> "e_choose_all_slices_default" ,
52 "e_debug_isocontour" ,
55 "e_invest_slice_order" ,
56 // PS -> "e_show_cell" ,
57 // PS -> "e_show_int_cell"
60 static const char* DoubleParamNames[] = {
61 "e_gravity_distance" ,
62 "e_axis_discret_step" ,
63 "e_distance_to_maximum_intensity" ,
65 "e_flexion_coeficient" ,
66 "e_tension_coeficient" ,
67 "e_voxel_x_dimension" ,
68 "e_voxel_y_dimension" ,
69 "e_voxel_z_dimension" ,
71 // PS -> "e_sampling" ,
72 "e_threshold_isocontour" ,
73 "e_threshold_snake_isocontour" ,
75 // PS -> "e_gradient_coeficient" ,
76 // PS -> "e_extern_coeficient" ,
77 // PS -> "e_ballon_coeficient" ,
78 // PS -> "e_back_color_3D_r" ,
79 // PS -> "e_back_color_3D_g" ,
80 // PS -> "e_back_color_3D_b" ,
81 // PS -> "e_axis_color_r" ,
82 // PS -> "e_axis_color_g" ,
83 // PS -> "e_axis_color_b"
84 "e_RescaleIntercept" ,
88 static const char* IntParamNames[] = {
95 "e_number_of_points_for_snake" ,
96 "e_quantification_type" ,
98 // PS -> "e_number_of_iterations_snake_isocontour" ,
99 // PS -> "e_number_of_iterations_snake_deriche" ,
101 // PS -> "e_coef_cell_max_int"
104 static const char* StringParamNames[] = {
105 "e_installation_directory" ,
106 "e_dicom_images_directory"
109 // -------------------------------------------------------------------------
110 double marParameters::getVoxelSize( )
116 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
118 ret = _doubleValues[ e_voxel_x_dimension ];
119 ret = GTM_MIN( _doubleValues[ e_voxel_y_dimension ], ret );
120 ret = GTM_MIN( _doubleValues[ e_voxel_z_dimension ], ret );
129 //Juan Carrillo 03/06/2005
130 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
132 ret = _doubleValues[ e_voxel_x_dimension ];
133 ret = ( _doubleValues[ e_voxel_y_dimension ] < ret )?
134 _doubleValues[ e_voxel_y_dimension ]: ret;
135 ret = ( _doubleValues[ e_voxel_z_dimension ] < ret )?
136 _doubleValues[ e_voxel_z_dimension ]: ret;
141 // -------------------------------------------------------------------------
142 double marParameters::getDimIma( )
144 double scale = _doubleValues[ e_scale ];
145 double roiDim = ( double )( _intValues[ e_roi_dimension ] );
146 return( scale * roiDim );
149 // -------------------------------------------------------------------------
150 int marParameters::getSizeIma( )
152 // TODO : There should be a formal way to calculate a good image size.
156 // -------------------------------------------------------------------------
157 double marParameters::getImaRatio( )
159 return( getDimIma( ) / ( double )( getSizeIma( ) ) );
162 // -------------------------------------------------------------------------
163 void marParameters::setROIStep( double width )
165 _intValues[ e_roi_dimension ] =
166 ( int )ceil( _doubleValues[ e_cell_coeficient ] * width );
167 _intValues[ e_step ] =
168 ( int )floor( ( double )_intValues[ e_roi_dimension ] /
169 ( double )_intValues[ e_step_coeficient ] );
173 // -------------------------------------------------------------------------
174 float marParameters::getRescaleSlope(){
175 return (float) _doubleValues[ e_RescaleSlope ];
177 // -------------------------------------------------------------------------
178 float marParameters::getRescaleIntercept(){
179 return (float) _doubleValues[ e_RescaleIntercept ];
181 // -------------------------------------------------------------------------
182 void marParameters::setRescaleSlope(float slope){
183 _doubleValues[ e_RescaleSlope ]= slope;
185 // -------------------------------------------------------------------------
186 void marParameters::setRescaleIntercept(float intercept){
187 _doubleValues[ e_RescaleIntercept ]= intercept;
189 // -------------------------------------------------------------------------
190 void marParameters::copyFrom( const marParameters& from )
194 memcpy( _boolValues, from._boolValues, e_bool_cont * sizeof( bool ) );
195 memcpy( _intValues, from._intValues, e_int_cont * sizeof( int ) );
196 memcpy( _doubleValues,
198 e_double_cont * sizeof( double ) );
200 for( i = 0; i < e_string_cont; i++ )
201 _stringValues[ i ] = from._stringValues[ i ];
204 // -------------------------------------------------------------------------
205 void marParameters::reset( )
207 // PS -> _boolValues[ e_debug_window_visible ] = false;
208 // PS -> _boolValues[ e_debug_console_visible ] = false;
209 // PS -> _boolValues[ e_calculate_mip_default ] = false;
210 // PS -> _boolValues[ e_choose_all_slices_default ] = true;
211 _boolValues[ e_debug_isocontour ] = true;
212 _boolValues[ e_debug_diameters ] = true;
213 _boolValues[ e_debug_fill_area ] = false;
214 _boolValues[ e_invest_slice_order ] = false;
215 // PS -> _boolValues[ e_show_cell ] = true;
216 // PS -> _boolValues[ e_show_int_cell ] = true;
218 _doubleValues[ e_gravity_distance ] = 1.0;
219 _doubleValues[ e_axis_discret_step ] = 2.0;
220 _doubleValues[ e_distance_to_maximum_intensity ] = 0.0;
221 _doubleValues[ e_cell_coeficient ] = 1.2;
222 _doubleValues[ e_flexion_coeficient ] = 0.1;
223 _doubleValues[ e_tension_coeficient ] = 0.3;
224 _doubleValues[ e_voxel_x_dimension ] = 1.0;
225 _doubleValues[ e_voxel_y_dimension ] = 1.0;
226 _doubleValues[ e_voxel_z_dimension ] = 1.0;
227 _doubleValues[ e_scale ] = 4.0;
228 // PS -> _doubleValues[ e_sampling ] = 4.0;
229 _doubleValues[ e_threshold_isocontour ] = 40.0;
230 _doubleValues[ e_threshold_snake_isocontour ] = 40.0;
231 _doubleValues[ e_sigma ] = 0.1;
232 _doubleValues[ e_RescaleIntercept ] = 0;
233 _doubleValues[ e_RescaleSlope ] = 1;
234 // PS -> _doubleValues[ e_extern_coeficient ] = 0.3;
235 // PS -> _doubleValues[ e_gradient_coeficient ] = 0.3;
236 // PS -> _doubleValues[ e_ballon_coeficient ] = 0.02;
237 // PS -> _doubleValues[ e_back_color_3D_r ] = 0.0;
238 // PS -> _doubleValues[ e_back_color_3D_g ] = 0.0;
239 // PS -> _doubleValues[ e_back_color_3D_b ] = 0.0;
240 // PS -> _doubleValues[ e_axis_color_r ] = 1.0;
241 // PS -> _doubleValues[ e_axis_color_g ] = 0.0;
242 // PS -> _doubleValues[ e_axis_color_b ] = 0.0;
245 _intValues[ e_roi_dimension ] = 10;
246 _intValues[ e_step ] = 3;
247 _intValues[ e_step_coeficient ] = 2;
248 _intValues[ e_mass_power ] = 2;
249 _intValues[ e_algorithm_type ] = ISOCONTOURS;
250 _intValues[ e_mask_size ] = 5;
251 _intValues[ e_number_of_points_for_snake ] = 20;
252 _intValues[ e_quantification_type ] = TYPE_AREA;
253 _intValues[ e_stenosis_type ] = TYPE_AREA;
254 // PS -> _intValues[ e_number_of_iterations_snake_isocontour ] = 5;
255 // PS -> _intValues[ e_number_of_iterations_snake_deriche ] = 700;
258 _intValues[ e_voxel_type ] = VOX_TYPE_NORMAL;
261 // PS -> _intValues[ e_coef_cell_max_int ] = 2;
263 _stringValues[ e_installation_directory ] = _T("NO_DIRECTORY");
264 _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
266 //MAZV CT compatibility
268 _lumenPercentage = 86;
269 _calcPercentage = 90;
270 _standardDeviation = 3;
272 //end MAZV CT compatibility
276 // -------------------------------------------------------------------------
277 bool marParameters::save( std::ofstream& os )
282 os.write( ( const char* )_boolValues, e_bool_cont * sizeof( bool ) );
283 os.write( ( char* )_intValues, e_int_cont * sizeof( int ) );
284 os.write( ( const char* )_doubleValues, e_double_cont * sizeof( double ) );
285 for( i = 0; i < e_string_cont; i++ ) {
286 s = _stringValues[ i ].length( );
287 os.write( ( const char* )&s, sizeof( int ) );
288 os.write( ( const char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
299 // -------------------------------------------------------------------------
300 bool marParameters::load( std::ifstream& is )
306 is.read( ( char* )_boolValues, e_bool_cont * sizeof( bool ) );
307 is.read( ( char* )_intValues, e_int_cont * sizeof( int ) );
308 is.read( ( char* )_doubleValues, e_double_cont * sizeof( double ) );
309 for( i = 0; i < e_string_cont; i++ )
311 is.read( ( char* )&s, sizeof( int ) );
312 _stringValues[ i ].resize( s );
313 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
314 #if wxMAJOR_VERSION <= 2
315 is.read( ( char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
317 is.read( tmp , s * sizeof( char ) );
318 _stringValues[ i ]=wxString(tmp);
331 // -------------------------------------------------------------------------
332 bool marParameters::save( wxString& nw )
334 std::ofstream os( (const char*)nw.mb_str( ) ,std::ios::out |std::ios::binary );
337 // wxLogDebug("Saving parameters to file " + nw);
341 if( os.is_open()==false )
344 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
346 // wxLogDebug(errorMsg);
353 // wxLogDebug("Parameters saved to file " + nw);
360 // wxLogDebug("Error : Cannot save parameters to file "+nw);
365 // -------------------------------------------------------------------------
366 bool marParameters::load( wxString& nr )
368 std::ifstream is( (const char*)nr.mb_str( ),std::ios::binary|std::ios::in);
371 // wxLogDebug("Laoding parameters from file " + nr);
375 if( is.is_open()==false )
378 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
380 // wxLogDebug(errorMsg);
387 // wxLogDebug("Parameters loaded from file " + nr);
394 // wxLogDebug("Error : Cannot load parameters from file "+nr+": file may be corrupted");
399 // ----------------------------------------------------------------------------
400 wxArrayString marParameters::getRelationalArray( )
402 // Allocate memory for pairs of data plus one end NULL array
408 for( i = 0, j = 0; i < e_bool_cont; i++, j += 2 ) {
410 ret.Add( wxString( BoolParamNames[ i ], wxConvUTF8) );
411 str.Printf( _T("%d"), ( _boolValues[ i ] )? 1: 0 );
415 for( i = 0; i < e_double_cont; i++, j += 2 ) {
417 ret.Add( wxString( DoubleParamNames[ i ], wxConvUTF8) );
418 str.Printf( _T("%f"), _doubleValues[ i ] );
422 for( i = 0; i < e_int_cont; i++, j += 2 ) {
424 ret.Add( wxString( IntParamNames[ i ], wxConvUTF8) );
425 str.Printf( _T("%d"), _intValues[ i ] );
430 for( i = 0; i < e_string_cont; i++, j += 2 ) {
431 ret.Add( wxString( StringParamNames[ i ], wxConvUTF8) );
432 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
433 #if wxMAJOR_VERSION <= 2
434 ret.Add( wxString( _stringValues[ i ].c_str( ), wxConvUTF8 ) );
436 ret.Add( wxString( _stringValues[ i ] ) );
445 // ----------------------------------------------------------------------------
446 //void marParameters::setRelationalArray( wxStringList& arr )
447 void marParameters::setRelationalArray( wxArrayString& arr )
453 // while( arr[ i ] != NULL ) {
454 while( !arr.IsEmpty() ) {
457 for( j = 0; j < e_string_cont && cont; j++ ) {
458 if( strcmp( StringParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
459 _stringValues[ j ] = ( wxString )arr[ i + 1 ];
463 for( j = 0; j < e_bool_cont && cont; j++ ) {
465 if( strcmp( BoolParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
467 _boolValues[ j ] = ( strcmp( (const char*)arr[ i + 1 ].mb_str(), "1" ) == 0 );
473 for( j = 0; j < e_int_cont && cont; j++ ) {
475 if( strcmp( IntParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
477 _intValues[ j ] = atoi( (const char*)arr[ i + 1 ].mb_str() );
483 for( j = 0; j < e_double_cont && cont; j++ ) {
485 if( strcmp( DoubleParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
487 ( ( wxString )arr[ i + 1 ] ).ToDouble( &_doubleValues[ j ] );
500 bool marParameters::getInvestSliceOrder(){
501 return _boolValues[ e_invest_slice_order ];
504 //MAZV - Added for CT compatibility
505 // ----------------------------------------------------------------------------
506 int marParameters::getContourThresh() {
507 return _contourThresh;
510 // ----------------------------------------------------------------------------
511 void marParameters::setContourThresh( int thresh ) {
512 _contourThresh = thresh;
515 // ----------------------------------------------------------------------------
516 double marParameters::getStandardDeviation() {
517 return _standardDeviation;
520 // ----------------------------------------------------------------------------
521 double marParameters::getRadius() {
525 // ----------------------------------------------------------------------------
526 void marParameters::setStandardDeviation( double dev ) {
527 _standardDeviation = dev;
530 // ----------------------------------------------------------------------------
531 void marParameters::setRadius( double rad ) {
535 // ----------------------------------------------------------------------------
536 void marParameters::setLumenPercentage(int percentage) {
537 _lumenPercentage = percentage;
539 // ----------------------------------------------------------------------------
540 void marParameters::setCalcPercentage(int percentage) {
541 _calcPercentage = percentage;
544 // ----------------------------------------------------------------------------
545 int marParameters::getLumenPercentage() {
546 return _lumenPercentage;
549 // ----------------------------------------------------------------------------
550 int marParameters::getCalcPercentage() {
551 return _calcPercentage;
553 //MAZV end of addition
554 // eof - parameters.cxx