1 /*=========================================================================
4 Module: $RCSfile: marParameters.cpp,v $
6 Date: $Date: 2010/04/20 14:42:44 $
7 Version: $Revision: 1.3 $
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 const 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"
35 static const char* DoubleParamNames[] = {
36 "e_gravity_distance" ,
37 "e_axis_discret_step" ,
38 "e_distance_to_maximum_intensity" ,
40 "e_flexion_coeficient" ,
41 "e_tension_coeficient" ,
42 "e_voxel_x_dimension" ,
43 "e_voxel_y_dimension" ,
44 "e_voxel_z_dimension" ,
46 // PS -> "e_sampling" ,
47 "e_threshold_isocontour" ,
48 "e_threshold_snake_isocontour" ,
50 // PS -> "e_gradient_coeficient" ,
51 // PS -> "e_extern_coeficient" ,
52 // PS -> "e_ballon_coeficient" ,
53 // PS -> "e_back_color_3D_r" ,
54 // PS -> "e_back_color_3D_g" ,
55 // PS -> "e_back_color_3D_b" ,
56 // PS -> "e_axis_color_r" ,
57 // PS -> "e_axis_color_g" ,
58 // PS -> "e_axis_color_b"
59 "e_RescaleIntercept" ,
63 static const char* IntParamNames[] = {
70 "e_number_of_points_for_snake" ,
71 "e_quantification_type" ,
73 // PS -> "e_number_of_iterations_snake_isocontour" ,
74 // PS -> "e_number_of_iterations_snake_deriche" ,
76 // PS -> "e_coef_cell_max_int"
79 static const char* StringParamNames[] = {
80 "e_installation_directory" ,
81 "e_dicom_images_directory"
84 // -------------------------------------------------------------------------
85 double marParameters::getVoxelSize( )
91 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
93 ret = _doubleValues[ e_voxel_x_dimension ];
94 ret = GTM_MIN( _doubleValues[ e_voxel_y_dimension ], ret );
95 ret = GTM_MIN( _doubleValues[ e_voxel_z_dimension ], ret );
104 //Juan Carrillo 03/06/2005
105 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
107 ret = _doubleValues[ e_voxel_x_dimension ];
108 ret = ( _doubleValues[ e_voxel_y_dimension ] < ret )?
109 _doubleValues[ e_voxel_y_dimension ]: ret;
110 ret = ( _doubleValues[ e_voxel_z_dimension ] < ret )?
111 _doubleValues[ e_voxel_z_dimension ]: ret;
116 // -------------------------------------------------------------------------
117 double marParameters::getDimIma( )
119 double scale = _doubleValues[ e_scale ];
120 double roiDim = ( double )( _intValues[ e_roi_dimension ] );
121 return( scale * roiDim );
124 // -------------------------------------------------------------------------
125 int marParameters::getSizeIma( )
127 // TODO : There should be a formal way to calculate a good image size.
131 // -------------------------------------------------------------------------
132 double marParameters::getImaRatio( )
134 return( getDimIma( ) / ( double )( getSizeIma( ) ) );
137 // -------------------------------------------------------------------------
138 void marParameters::setROIStep( double width )
140 _intValues[ e_roi_dimension ] =
141 ( int )ceil( _doubleValues[ e_cell_coeficient ] * width );
142 _intValues[ e_step ] =
143 ( int )floor( ( double )_intValues[ e_roi_dimension ] /
144 ( double )_intValues[ e_step_coeficient ] );
148 // -------------------------------------------------------------------------
149 float marParameters::getRescaleSlope(){
150 return (float) _doubleValues[ e_RescaleSlope ];
152 // -------------------------------------------------------------------------
153 float marParameters::getRescaleIntercept(){
154 return (float) _doubleValues[ e_RescaleIntercept ];
156 // -------------------------------------------------------------------------
157 void marParameters::setRescaleSlope(float slope){
158 _doubleValues[ e_RescaleSlope ]= slope;
160 // -------------------------------------------------------------------------
161 void marParameters::setRescaleIntercept(float intercept){
162 _doubleValues[ e_RescaleIntercept ]= intercept;
164 // -------------------------------------------------------------------------
165 void marParameters::copyFrom( const marParameters& from )
169 memcpy( _boolValues, from._boolValues, e_bool_cont * sizeof( bool ) );
170 memcpy( _intValues, from._intValues, e_int_cont * sizeof( int ) );
171 memcpy( _doubleValues,
173 e_double_cont * sizeof( double ) );
175 for( i = 0; i < e_string_cont; i++ )
176 _stringValues[ i ] = from._stringValues[ i ];
179 // -------------------------------------------------------------------------
180 void marParameters::reset( )
182 // PS -> _boolValues[ e_debug_window_visible ] = false;
183 // PS -> _boolValues[ e_debug_console_visible ] = false;
184 // PS -> _boolValues[ e_calculate_mip_default ] = false;
185 // PS -> _boolValues[ e_choose_all_slices_default ] = true;
186 _boolValues[ e_debug_isocontour ] = true;
187 _boolValues[ e_debug_diameters ] = true;
188 _boolValues[ e_debug_fill_area ] = false;
189 _boolValues[ e_invest_slice_order ] = false;
190 // PS -> _boolValues[ e_show_cell ] = true;
191 // PS -> _boolValues[ e_show_int_cell ] = true;
193 _doubleValues[ e_gravity_distance ] = 1.0;
194 _doubleValues[ e_axis_discret_step ] = 2.0;
195 _doubleValues[ e_distance_to_maximum_intensity ] = 0.0;
196 _doubleValues[ e_cell_coeficient ] = 1.2;
197 _doubleValues[ e_flexion_coeficient ] = 0.1;
198 _doubleValues[ e_tension_coeficient ] = 0.3;
199 _doubleValues[ e_voxel_x_dimension ] = 1.0;
200 _doubleValues[ e_voxel_y_dimension ] = 1.0;
201 _doubleValues[ e_voxel_z_dimension ] = 1.0;
202 _doubleValues[ e_scale ] = 4.0;
203 // PS -> _doubleValues[ e_sampling ] = 4.0;
204 _doubleValues[ e_threshold_isocontour ] = 40.0;
205 _doubleValues[ e_threshold_snake_isocontour ] = 40.0;
206 _doubleValues[ e_sigma ] = 0.1;
207 _doubleValues[ e_RescaleIntercept ] = 0;
208 _doubleValues[ e_RescaleSlope ] = 1;
209 // PS -> _doubleValues[ e_extern_coeficient ] = 0.3;
210 // PS -> _doubleValues[ e_gradient_coeficient ] = 0.3;
211 // PS -> _doubleValues[ e_ballon_coeficient ] = 0.02;
212 // PS -> _doubleValues[ e_back_color_3D_r ] = 0.0;
213 // PS -> _doubleValues[ e_back_color_3D_g ] = 0.0;
214 // PS -> _doubleValues[ e_back_color_3D_b ] = 0.0;
215 // PS -> _doubleValues[ e_axis_color_r ] = 1.0;
216 // PS -> _doubleValues[ e_axis_color_g ] = 0.0;
217 // PS -> _doubleValues[ e_axis_color_b ] = 0.0;
220 _intValues[ e_roi_dimension ] = 10;
221 _intValues[ e_step ] = 3;
222 _intValues[ e_step_coeficient ] = 2;
223 _intValues[ e_mass_power ] = 2;
224 _intValues[ e_algorithm_type ] = ISOCONTOURS;
225 _intValues[ e_mask_size ] = 5;
226 _intValues[ e_number_of_points_for_snake ] = 20;
227 _intValues[ e_quantification_type ] = TYPE_AREA;
228 _intValues[ e_stenosis_type ] = TYPE_AREA;
229 // PS -> _intValues[ e_number_of_iterations_snake_isocontour ] = 5;
230 // PS -> _intValues[ e_number_of_iterations_snake_deriche ] = 700;
233 _intValues[ e_voxel_type ] = VOX_TYPE_NORMAL;
236 // PS -> _intValues[ e_coef_cell_max_int ] = 2;
238 _stringValues[ e_installation_directory ] = _T("NO_DIRECTORY");
239 _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
241 //MAZV CT compatibility
243 _lumenPercentage = 86;
244 _calcPercentage = 90;
245 _standardDeviation = 3;
247 //end MAZV CT compatibility
251 // -------------------------------------------------------------------------
252 bool marParameters::save( std::ofstream& os )
257 os.write( ( const char* )_boolValues, e_bool_cont * sizeof( bool ) );
258 os.write( ( char* )_intValues, e_int_cont * sizeof( int ) );
259 os.write( ( const char* )_doubleValues, e_double_cont * sizeof( double ) );
260 for( i = 0; i < e_string_cont; i++ ) {
261 s = _stringValues[ i ].length( );
262 os.write( ( const char* )&s, sizeof( int ) );
263 os.write( ( const char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
274 // -------------------------------------------------------------------------
275 bool marParameters::load( std::ifstream& is )
280 is.read( ( char* )_boolValues, e_bool_cont * sizeof( bool ) );
281 is.read( ( char* )_intValues, e_int_cont * sizeof( int ) );
282 is.read( ( char* )_doubleValues, e_double_cont * sizeof( double ) );
283 for( i = 0; i < e_string_cont; i++ )
285 is.read( ( char* )&s, sizeof( int ) );
286 _stringValues[ i ].resize( s );
287 is.read( ( char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
299 // -------------------------------------------------------------------------
300 bool marParameters::save( wxString& nw )
302 std::ofstream os( (const char*)nw.mb_str( ) ,std::ios::out |std::ios::binary );
305 // wxLogDebug("Saving parameters to file " + nw);
310 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
312 // wxLogDebug(errorMsg);
319 // wxLogDebug("Parameters saved to file " + nw);
326 // wxLogDebug("Error : Cannot save parameters to file "+nw);
331 // -------------------------------------------------------------------------
332 bool marParameters::load( wxString& nr )
334 std::ifstream is( (const char*)nr.mb_str( ),std::ios::binary|std::ios::in);
337 // wxLogDebug("Laoding parameters from file " + nr);
341 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
343 // wxLogDebug(errorMsg);
350 // wxLogDebug("Parameters loaded from file " + nr);
357 // wxLogDebug("Error : Cannot load parameters from file "+nr+": file may be corrupted");
362 // ----------------------------------------------------------------------------
363 wxArrayString marParameters::getRelationalArray( )
365 // Allocate memory for pairs of data plus one end NULL array
371 for( i = 0, j = 0; i < e_bool_cont; i++, j += 2 ) {
373 ret.Add( wxString( BoolParamNames[ i ], wxConvUTF8) );
374 str.Printf( _T("%d"), ( _boolValues[ i ] )? 1: 0 );
378 for( i = 0; i < e_double_cont; i++, j += 2 ) {
380 ret.Add( wxString( DoubleParamNames[ i ], wxConvUTF8) );
381 str.Printf( _T("%f"), _doubleValues[ i ] );
385 for( i = 0; i < e_int_cont; i++, j += 2 ) {
387 ret.Add( wxString( IntParamNames[ i ], wxConvUTF8) );
388 str.Printf( _T("%d"), _intValues[ i ] );
393 for( i = 0; i < e_string_cont; i++, j += 2 ) {
394 ret.Add( wxString( StringParamNames[ i ], wxConvUTF8) );
395 ret.Add( wxString( _stringValues[ i ].c_str( ), wxConvUTF8 ) );
403 // ----------------------------------------------------------------------------
404 //void marParameters::setRelationalArray( wxStringList& arr )
405 void marParameters::setRelationalArray( wxArrayString& arr )
411 // while( arr[ i ] != NULL ) {
412 while( !arr.IsEmpty() ) {
415 for( j = 0; j < e_string_cont && cont; j++ ) {
416 if( strcmp( StringParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
417 _stringValues[ j ] = ( wxString )arr[ i + 1 ];
421 for( j = 0; j < e_bool_cont && cont; j++ ) {
423 if( strcmp( BoolParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
425 _boolValues[ j ] = ( strcmp( (const char*)arr[ i + 1 ].mb_str(), "1" ) == 0 );
431 for( j = 0; j < e_int_cont && cont; j++ ) {
433 if( strcmp( IntParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
435 _intValues[ j ] = atoi( (const char*)arr[ i + 1 ].mb_str() );
441 for( j = 0; j < e_double_cont && cont; j++ ) {
443 if( strcmp( DoubleParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
445 ( ( wxString )arr[ i + 1 ] ).ToDouble( &_doubleValues[ j ] );
458 bool marParameters::getInvestSliceOrder(){
459 return _boolValues[ e_invest_slice_order ];
462 //MAZV - Added for CT compatibility
463 // ----------------------------------------------------------------------------
464 int marParameters::getContourThresh() {
465 return _contourThresh;
468 // ----------------------------------------------------------------------------
469 void marParameters::setContourThresh( int thresh ) {
470 _contourThresh = thresh;
473 // ----------------------------------------------------------------------------
474 double marParameters::getStandardDeviation() {
475 return _standardDeviation;
478 // ----------------------------------------------------------------------------
479 double marParameters::getRadius() {
483 // ----------------------------------------------------------------------------
484 void marParameters::setStandardDeviation( double dev ) {
485 _standardDeviation = dev;
488 // ----------------------------------------------------------------------------
489 void marParameters::setRadius( double rad ) {
493 // ----------------------------------------------------------------------------
494 void marParameters::setLumenPercentage(int percentage) {
495 _lumenPercentage = percentage;
497 // ----------------------------------------------------------------------------
498 void marParameters::setCalcPercentage(int percentage) {
499 _calcPercentage = percentage;
502 // ----------------------------------------------------------------------------
503 int marParameters::getLumenPercentage() {
504 return _lumenPercentage;
507 // ----------------------------------------------------------------------------
508 int marParameters::getCalcPercentage() {
509 return _calcPercentage;
511 //MAZV end of addition
512 // eof - parameters.cxx