1 /*=========================================================================
4 Module: $RCSfile: marParameters.cpp,v $
6 Date: $Date: 2008/10/31 16:32:56 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
18 #include "marParameters.h"
22 static char* BoolParamNames[] = {
23 // PS -> "e_debug_window_visible" ,
24 // PS -> "e_debug_console_visible" ,
25 // PS -> "e_calculate_mip_default" ,
26 // PS -> "e_choose_all_slices_default" ,
27 "e_debug_isocontour" ,
30 "e_invest_slice_order" ,
31 // PS -> "e_show_cell" ,
32 // PS -> "e_show_int_cell"
34 static char* DoubleParamNames[] = {
35 "e_gravity_distance" ,
36 "e_axis_discret_step" ,
37 "e_distance_to_maximum_intensity" ,
39 "e_flexion_coeficient" ,
40 "e_tension_coeficient" ,
41 "e_voxel_x_dimension" ,
42 "e_voxel_y_dimension" ,
43 "e_voxel_z_dimension" ,
45 // PS -> "e_sampling" ,
46 "e_threshold_isocontour" ,
47 "e_threshold_snake_isocontour" ,
49 // PS -> "e_gradient_coeficient" ,
50 // PS -> "e_extern_coeficient" ,
51 // PS -> "e_ballon_coeficient" ,
52 // PS -> "e_back_color_3D_r" ,
53 // PS -> "e_back_color_3D_g" ,
54 // PS -> "e_back_color_3D_b" ,
55 // PS -> "e_axis_color_r" ,
56 // PS -> "e_axis_color_g" ,
57 // PS -> "e_axis_color_b"
58 "e_RescaleIntercept" ,
61 static char* IntParamNames[] = {
68 "e_number_of_points_for_snake" ,
69 "e_quantification_type" ,
71 // PS -> "e_number_of_iterations_snake_isocontour" ,
72 // PS -> "e_number_of_iterations_snake_deriche" ,
74 // PS -> "e_coef_cell_max_int"
76 static char* StringParamNames[] = {
77 "e_installation_directory" ,
78 "e_dicom_images_directory"
81 // -------------------------------------------------------------------------
82 double marParameters::getVoxelSize( )
88 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
90 ret = _doubleValues[ e_voxel_x_dimension ];
91 ret = GTM_MIN( _doubleValues[ e_voxel_y_dimension ], ret );
92 ret = GTM_MIN( _doubleValues[ e_voxel_z_dimension ], ret );
101 //Juan Carrillo 03/06/2005
102 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
104 ret = _doubleValues[ e_voxel_x_dimension ];
105 ret = ( _doubleValues[ e_voxel_y_dimension ] < ret )?
106 _doubleValues[ e_voxel_y_dimension ]: ret;
107 ret = ( _doubleValues[ e_voxel_z_dimension ] < ret )?
108 _doubleValues[ e_voxel_z_dimension ]: ret;
113 // -------------------------------------------------------------------------
114 double marParameters::getDimIma( )
116 double scale = _doubleValues[ e_scale ];
117 double roiDim = ( double )( _intValues[ e_roi_dimension ] );
118 return( scale * roiDim );
121 // -------------------------------------------------------------------------
122 int marParameters::getSizeIma( )
124 // TODO : There should be a formal way to calculate a good image size.
128 // -------------------------------------------------------------------------
129 double marParameters::getImaRatio( )
131 return( getDimIma( ) / ( double )( getSizeIma( ) ) );
134 // -------------------------------------------------------------------------
135 void marParameters::setROIStep( double width )
137 _intValues[ e_roi_dimension ] =
138 ( int )ceil( _doubleValues[ e_cell_coeficient ] * width );
139 _intValues[ e_step ] =
140 ( int )floor( ( double )_intValues[ e_roi_dimension ] /
141 ( double )_intValues[ e_step_coeficient ] );
145 // -------------------------------------------------------------------------
146 float marParameters::getRescaleSlope(){
147 return (float) _doubleValues[ e_RescaleSlope ];
149 // -------------------------------------------------------------------------
150 float marParameters::getRescaleIntercept(){
151 return (float) _doubleValues[ e_RescaleIntercept ];
153 // -------------------------------------------------------------------------
154 void marParameters::setRescaleSlope(float slope){
155 _doubleValues[ e_RescaleSlope ]= slope;
157 // -------------------------------------------------------------------------
158 void marParameters::setRescaleIntercept(float intercept){
159 _doubleValues[ e_RescaleIntercept ]= intercept;
161 // -------------------------------------------------------------------------
162 void marParameters::copyFrom( const marParameters& from )
166 memcpy( _boolValues, from._boolValues, e_bool_cont * sizeof( bool ) );
167 memcpy( _intValues, from._intValues, e_int_cont * sizeof( int ) );
168 memcpy( _doubleValues,
170 e_double_cont * sizeof( double ) );
172 for( i = 0; i < e_string_cont; i++ )
173 _stringValues[ i ] = from._stringValues[ i ];
176 // -------------------------------------------------------------------------
177 void marParameters::reset( )
179 // PS -> _boolValues[ e_debug_window_visible ] = false;
180 // PS -> _boolValues[ e_debug_console_visible ] = false;
181 // PS -> _boolValues[ e_calculate_mip_default ] = false;
182 // PS -> _boolValues[ e_choose_all_slices_default ] = true;
183 _boolValues[ e_debug_isocontour ] = true;
184 _boolValues[ e_debug_diameters ] = true;
185 _boolValues[ e_debug_fill_area ] = false;
186 _boolValues[ e_invest_slice_order ] = false;
187 // PS -> _boolValues[ e_show_cell ] = true;
188 // PS -> _boolValues[ e_show_int_cell ] = true;
190 _doubleValues[ e_gravity_distance ] = 1.0;
191 _doubleValues[ e_axis_discret_step ] = 2.0;
192 _doubleValues[ e_distance_to_maximum_intensity ] = 0.0;
193 _doubleValues[ e_cell_coeficient ] = 1.2;
194 _doubleValues[ e_flexion_coeficient ] = 0.1;
195 _doubleValues[ e_tension_coeficient ] = 0.3;
196 _doubleValues[ e_voxel_x_dimension ] = 1.0;
197 _doubleValues[ e_voxel_y_dimension ] = 1.0;
198 _doubleValues[ e_voxel_z_dimension ] = 1.0;
199 _doubleValues[ e_scale ] = 4.0;
200 // PS -> _doubleValues[ e_sampling ] = 4.0;
201 _doubleValues[ e_threshold_isocontour ] = 40.0;
202 _doubleValues[ e_threshold_snake_isocontour ] = 40.0;
203 _doubleValues[ e_sigma ] = 0.1;
204 _doubleValues[ e_RescaleIntercept ] = 0;
205 _doubleValues[ e_RescaleSlope ] = 1;
206 // PS -> _doubleValues[ e_extern_coeficient ] = 0.3;
207 // PS -> _doubleValues[ e_gradient_coeficient ] = 0.3;
208 // PS -> _doubleValues[ e_ballon_coeficient ] = 0.02;
209 // PS -> _doubleValues[ e_back_color_3D_r ] = 0.0;
210 // PS -> _doubleValues[ e_back_color_3D_g ] = 0.0;
211 // PS -> _doubleValues[ e_back_color_3D_b ] = 0.0;
212 // PS -> _doubleValues[ e_axis_color_r ] = 1.0;
213 // PS -> _doubleValues[ e_axis_color_g ] = 0.0;
214 // PS -> _doubleValues[ e_axis_color_b ] = 0.0;
217 _intValues[ e_roi_dimension ] = 10;
218 _intValues[ e_step ] = 3;
219 _intValues[ e_step_coeficient ] = 2;
220 _intValues[ e_mass_power ] = 2;
221 _intValues[ e_algorithm_type ] = ISOCONTOURS;
222 _intValues[ e_mask_size ] = 5;
223 _intValues[ e_number_of_points_for_snake ] = 20;
224 _intValues[ e_quantification_type ] = TYPE_AREA;
225 _intValues[ e_stenosis_type ] = TYPE_AREA;
226 // PS -> _intValues[ e_number_of_iterations_snake_isocontour ] = 5;
227 // PS -> _intValues[ e_number_of_iterations_snake_deriche ] = 700;
230 _intValues[ e_voxel_type ] = VOX_TYPE_NORMAL;
233 // PS -> _intValues[ e_coef_cell_max_int ] = 2;
235 _stringValues[ e_installation_directory ] = _T("NO_DIRECTORY");
236 _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
238 //MAZV CT compatibility
240 _lumenPercentage = 86;
241 _calcPercentage = 90;
242 _standardDeviation = 3;
244 //end MAZV CT compatibility
248 // -------------------------------------------------------------------------
249 bool marParameters::save( std::ofstream& os )
254 os.write( ( const char* )_boolValues, e_bool_cont * sizeof( bool ) );
255 os.write( ( char* )_intValues, e_int_cont * sizeof( int ) );
256 os.write( ( const char* )_doubleValues, e_double_cont * sizeof( double ) );
257 for( i = 0; i < e_string_cont; i++ ) {
258 s = _stringValues[ i ].length( );
259 os.write( ( const char* )&s, sizeof( int ) );
260 os.write( ( const char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
271 // -------------------------------------------------------------------------
272 bool marParameters::load( std::ifstream& is )
277 is.read( ( char* )_boolValues, e_bool_cont * sizeof( bool ) );
278 is.read( ( char* )_intValues, e_int_cont * sizeof( int ) );
279 is.read( ( char* )_doubleValues, e_double_cont * sizeof( double ) );
280 for( i = 0; i < e_string_cont; i++ )
282 is.read( ( char* )&s, sizeof( int ) );
283 _stringValues[ i ].resize( s );
284 is.read( ( char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
296 // -------------------------------------------------------------------------
297 bool marParameters::save( wxString& nw )
299 std::ofstream os( (const char*)nw.mb_str( ) ,std::ios::out |std::ios::binary );
302 // wxLogDebug("Saving parameters to file " + nw);
307 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
309 // wxLogDebug(errorMsg);
316 // wxLogDebug("Parameters saved to file " + nw);
323 // wxLogDebug("Error : Cannot save parameters to file "+nw);
328 // -------------------------------------------------------------------------
329 bool marParameters::load( wxString& nr )
331 std::ifstream is( (const char*)nr.mb_str( ),std::ios::binary|std::ios::in);
334 // wxLogDebug("Laoding parameters from file " + nr);
338 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
340 // wxLogDebug(errorMsg);
347 // wxLogDebug("Parameters loaded from file " + nr);
354 // wxLogDebug("Error : Cannot load parameters from file "+nr+": file may be corrupted");
359 // ----------------------------------------------------------------------------
360 wxArrayString marParameters::getRelationalArray( )
362 // Allocate memory for pairs of data plus one end NULL array
368 for( i = 0, j = 0; i < e_bool_cont; i++, j += 2 ) {
370 ret.Add( wxString( BoolParamNames[ i ], wxConvUTF8) );
371 str.Printf( _T("%d"), ( _boolValues[ i ] )? 1: 0 );
375 for( i = 0; i < e_double_cont; i++, j += 2 ) {
377 ret.Add( wxString( DoubleParamNames[ i ], wxConvUTF8) );
378 str.Printf( _T("%f"), _doubleValues[ i ] );
382 for( i = 0; i < e_int_cont; i++, j += 2 ) {
384 ret.Add( wxString( IntParamNames[ i ], wxConvUTF8) );
385 str.Printf( _T("%d"), _intValues[ i ] );
390 for( i = 0; i < e_string_cont; i++, j += 2 ) {
391 ret.Add( wxString( StringParamNames[ i ], wxConvUTF8) );
392 ret.Add( wxString( _stringValues[ i ].c_str( ), wxConvUTF8 ) );
400 // ----------------------------------------------------------------------------
401 //void marParameters::setRelationalArray( wxStringList& arr )
402 void marParameters::setRelationalArray( wxArrayString& arr )
408 // while( arr[ i ] != NULL ) {
409 while( !arr.IsEmpty() ) {
412 for( j = 0; j < e_string_cont && cont; j++ ) {
413 if( strcmp( StringParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
414 _stringValues[ j ] = ( wxString )arr[ i + 1 ];
418 for( j = 0; j < e_bool_cont && cont; j++ ) {
420 if( strcmp( BoolParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
422 _boolValues[ j ] = ( strcmp( (const char*)arr[ i + 1 ].mb_str(), "1" ) == 0 );
428 for( j = 0; j < e_int_cont && cont; j++ ) {
430 if( strcmp( IntParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
432 _intValues[ j ] = atoi( (const char*)arr[ i + 1 ].mb_str() );
438 for( j = 0; j < e_double_cont && cont; j++ ) {
440 if( strcmp( DoubleParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
442 ( ( wxString )arr[ i + 1 ] ).ToDouble( &_doubleValues[ j ] );
455 bool marParameters::getInvestSliceOrder(){
456 return _boolValues[ e_invest_slice_order ];
459 //MAZV - Added for CT compatibility
460 // ----------------------------------------------------------------------------
461 int marParameters::getContourThresh() {
462 return _contourThresh;
465 // ----------------------------------------------------------------------------
466 void marParameters::setContourThresh( int thresh ) {
467 _contourThresh = thresh;
470 // ----------------------------------------------------------------------------
471 double marParameters::getStandardDeviation() {
472 return _standardDeviation;
475 // ----------------------------------------------------------------------------
476 double marParameters::getRadius() {
480 // ----------------------------------------------------------------------------
481 void marParameters::setStandardDeviation( double dev ) {
482 _standardDeviation = dev;
485 // ----------------------------------------------------------------------------
486 void marParameters::setRadius( double rad ) {
490 // ----------------------------------------------------------------------------
491 void marParameters::setLumenPercentage(int percentage) {
492 _lumenPercentage = percentage;
494 // ----------------------------------------------------------------------------
495 void marParameters::setCalcPercentage(int percentage) {
496 _calcPercentage = percentage;
499 // ----------------------------------------------------------------------------
500 int marParameters::getLumenPercentage() {
501 return _lumenPercentage;
504 // ----------------------------------------------------------------------------
505 int marParameters::getCalcPercentage() {
506 return _calcPercentage;
508 //MAZV end of addition
509 // eof - parameters.cxx