00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "marParameters.h"
00019 #include <math.h>
00020 #include <wx/log.h>
00021
00022 static const char* BoolParamNames[] = {
00023
00024
00025
00026
00027 "e_debug_isocontour" ,
00028 "e_debug_diameters" ,
00029 "e_debug_fill_area" ,
00030 "e_invest_slice_order" ,
00031
00032
00033 };
00034
00035 static const char* DoubleParamNames[] = {
00036 "e_gravity_distance" ,
00037 "e_axis_discret_step" ,
00038 "e_distance_to_maximum_intensity" ,
00039 "e_cell_coeficient" ,
00040 "e_flexion_coeficient" ,
00041 "e_tension_coeficient" ,
00042 "e_voxel_x_dimension" ,
00043 "e_voxel_y_dimension" ,
00044 "e_voxel_z_dimension" ,
00045 "e_scale" ,
00046
00047 "e_threshold_isocontour" ,
00048 "e_threshold_snake_isocontour" ,
00049 "e_sigma" ,
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 "e_RescaleIntercept" ,
00060 "e_RescaleSlope" ,
00061 };
00062
00063 static const char* IntParamNames[] = {
00064 "e_roi_dimension" ,
00065 "e_step" ,
00066 "e_step_coeficient" ,
00067 "e_mass_power" ,
00068 "e_algorithm_type" ,
00069 "e_mask_size" ,
00070 "e_number_of_points_for_snake" ,
00071 "e_quantification_type" ,
00072 "e_stenosis_type" ,
00073
00074
00075 "e_voxel_type" ,
00076
00077 };
00078
00079 static const char* StringParamNames[] = {
00080 "e_installation_directory" ,
00081 "e_dicom_images_directory"
00082 };
00083
00084
00085 double marParameters::getVoxelSize( )
00086 {
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 double ret = 1.0;
00104
00105 if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
00106
00107 ret = _doubleValues[ e_voxel_x_dimension ];
00108 ret = ( _doubleValues[ e_voxel_y_dimension ] < ret )?
00109 _doubleValues[ e_voxel_y_dimension ]: ret;
00110 ret = ( _doubleValues[ e_voxel_z_dimension ] < ret )?
00111 _doubleValues[ e_voxel_z_dimension ]: ret;
00112 }
00113 return( ret*1 );
00114 }
00115
00116
00117 double marParameters::getDimIma( )
00118 {
00119 double scale = _doubleValues[ e_scale ];
00120 double roiDim = ( double )( _intValues[ e_roi_dimension ] );
00121 return( scale * roiDim );
00122 }
00123
00124
00125 int marParameters::getSizeIma( )
00126 {
00127
00128 return( 128 );
00129 }
00130
00131
00132 double marParameters::getImaRatio( )
00133 {
00134 return( getDimIma( ) / ( double )( getSizeIma( ) ) );
00135 }
00136
00137
00138 void marParameters::setROIStep( double width )
00139 {
00140 _intValues[ e_roi_dimension ] =
00141 ( int )ceil( _doubleValues[ e_cell_coeficient ] * width );
00142 _intValues[ e_step ] =
00143 ( int )floor( ( double )_intValues[ e_roi_dimension ] /
00144 ( double )_intValues[ e_step_coeficient ] );
00145 }
00146
00147
00148
00149 float marParameters::getRescaleSlope(){
00150 return (float) _doubleValues[ e_RescaleSlope ];
00151 }
00152
00153 float marParameters::getRescaleIntercept(){
00154 return (float) _doubleValues[ e_RescaleIntercept ];
00155 }
00156
00157 void marParameters::setRescaleSlope(float slope){
00158 _doubleValues[ e_RescaleSlope ]= slope;
00159 }
00160
00161 void marParameters::setRescaleIntercept(float intercept){
00162 _doubleValues[ e_RescaleIntercept ]= intercept;
00163 }
00164
00165 void marParameters::copyFrom( const marParameters& from )
00166 {
00167 int i;
00168
00169 memcpy( _boolValues, from._boolValues, e_bool_cont * sizeof( bool ) );
00170 memcpy( _intValues, from._intValues, e_int_cont * sizeof( int ) );
00171 memcpy( _doubleValues,
00172 from._doubleValues,
00173 e_double_cont * sizeof( double ) );
00174
00175 for( i = 0; i < e_string_cont; i++ )
00176 _stringValues[ i ] = from._stringValues[ i ];
00177 }
00178
00179
00180 void marParameters::reset( )
00181 {
00182
00183
00184
00185
00186 _boolValues[ e_debug_isocontour ] = true;
00187 _boolValues[ e_debug_diameters ] = true;
00188 _boolValues[ e_debug_fill_area ] = false;
00189 _boolValues[ e_invest_slice_order ] = false;
00190
00191
00192
00193 _doubleValues[ e_gravity_distance ] = 1.0;
00194 _doubleValues[ e_axis_discret_step ] = 2.0;
00195 _doubleValues[ e_distance_to_maximum_intensity ] = 0.0;
00196 _doubleValues[ e_cell_coeficient ] = 1.2;
00197 _doubleValues[ e_flexion_coeficient ] = 0.1;
00198 _doubleValues[ e_tension_coeficient ] = 0.3;
00199 _doubleValues[ e_voxel_x_dimension ] = 1.0;
00200 _doubleValues[ e_voxel_y_dimension ] = 1.0;
00201 _doubleValues[ e_voxel_z_dimension ] = 1.0;
00202 _doubleValues[ e_scale ] = 4.0;
00203
00204 _doubleValues[ e_threshold_isocontour ] = 40.0;
00205 _doubleValues[ e_threshold_snake_isocontour ] = 40.0;
00206 _doubleValues[ e_sigma ] = 0.1;
00207 _doubleValues[ e_RescaleIntercept ] = 0;
00208 _doubleValues[ e_RescaleSlope ] = 1;
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 _intValues[ e_roi_dimension ] = 10;
00221 _intValues[ e_step ] = 3;
00222 _intValues[ e_step_coeficient ] = 2;
00223 _intValues[ e_mass_power ] = 2;
00224 _intValues[ e_algorithm_type ] = ISOCONTOURS;
00225 _intValues[ e_mask_size ] = 5;
00226 _intValues[ e_number_of_points_for_snake ] = 20;
00227 _intValues[ e_quantification_type ] = TYPE_AREA;
00228 _intValues[ e_stenosis_type ] = TYPE_AREA;
00229
00230
00231
00232
00233 _intValues[ e_voxel_type ] = VOX_TYPE_NORMAL;
00234
00235
00236
00237
00238 _stringValues[ e_installation_directory ] = _T("NO_DIRECTORY");
00239 _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
00240
00241
00242 _contourThresh = 10;
00243 _lumenPercentage = 86;
00244 _calcPercentage = 90;
00245 _standardDeviation = 3;
00246 _radius = 3;
00247
00248
00249 }
00250
00251
00252 bool marParameters::save( std::ofstream& os )
00253 {
00254 int i, s;
00255 try
00256 {
00257 os.write( ( const char* )_boolValues, e_bool_cont * sizeof( bool ) );
00258 os.write( ( char* )_intValues, e_int_cont * sizeof( int ) );
00259 os.write( ( const char* )_doubleValues, e_double_cont * sizeof( double ) );
00260 for( i = 0; i < e_string_cont; i++ ) {
00261 s = _stringValues[ i ].length( );
00262 os.write( ( const char* )&s, sizeof( int ) );
00263 os.write( ( const char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
00264 }
00265 return( true );
00266 }
00267 catch (...)
00268 {
00269 return(false);
00270 }
00271
00272 }
00273
00274
00275 bool marParameters::load( std::ifstream& is )
00276 {
00277 int i, s;
00278 try
00279 {
00280 is.read( ( char* )_boolValues, e_bool_cont * sizeof( bool ) );
00281 is.read( ( char* )_intValues, e_int_cont * sizeof( int ) );
00282 is.read( ( char* )_doubleValues, e_double_cont * sizeof( double ) );
00283 for( i = 0; i < e_string_cont; i++ )
00284 {
00285 is.read( ( char* )&s, sizeof( int ) );
00286 _stringValues[ i ].resize( s );
00287 is.read( ( char* )_stringValues[ i ].c_str( ), s * sizeof( char ) );
00288 }
00289 return( true );
00290 }
00291 catch (...)
00292 {
00293
00294 return(false);
00295 }
00296
00297 }
00298
00299
00300 bool marParameters::save( wxString& nw )
00301 {
00302 std::ofstream os( (const char*)nw.mb_str( ) ,std::ios::out |std::ios::binary );
00303
00304
00305
00306
00307 if( os==NULL )
00308 {
00309 wxString errorMsg;
00310 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
00311
00312
00313 return( false );
00314 }
00315 if (save( os ))
00316 {
00317 os.close( );
00318
00319
00320 return( true );
00321 }
00322 else
00323 {
00324 os.close( );
00325
00326
00327 return(false);
00328 }
00329 }
00330
00331
00332 bool marParameters::load( wxString& nr )
00333 {
00334 std::ifstream is( (const char*)nr.mb_str( ),std::ios::binary|std::ios::in);
00335
00336
00337
00338 if( is==NULL )
00339 {
00340 wxString errorMsg;
00341 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
00342
00343
00344 return( false );
00345 }
00346 if (load( is ))
00347 {
00348 is.close( );
00349
00350
00351 return( true );
00352 }
00353 else
00354 {
00355 is.close( );
00356
00357
00358 return(false);
00359 }
00360 }
00361
00362
00363 wxArrayString marParameters::getRelationalArray( )
00364 {
00365
00366
00367 wxArrayString ret;
00368 wxString str;
00369 int i, j;
00370
00371 for( i = 0, j = 0; i < e_bool_cont; i++, j += 2 ) {
00372
00373 ret.Add( wxString( BoolParamNames[ i ], wxConvUTF8) );
00374 str.Printf( _T("%d"), ( _boolValues[ i ] )? 1: 0 );
00375 ret.Add( str );
00376
00377 }
00378 for( i = 0; i < e_double_cont; i++, j += 2 ) {
00379
00380 ret.Add( wxString( DoubleParamNames[ i ], wxConvUTF8) );
00381 str.Printf( _T("%f"), _doubleValues[ i ] );
00382 ret.Add( str );
00383
00384 }
00385 for( i = 0; i < e_int_cont; i++, j += 2 ) {
00386
00387 ret.Add( wxString( IntParamNames[ i ], wxConvUTF8) );
00388 str.Printf( _T("%d"), _intValues[ i ] );
00389 ret.Add( str );
00390
00391 }
00392
00393 for( i = 0; i < e_string_cont; i++, j += 2 ) {
00394 ret.Add( wxString( StringParamNames[ i ], wxConvUTF8) );
00395 ret.Add( wxString( _stringValues[ i ].c_str( ), wxConvUTF8 ) );
00396 }
00397
00398
00399 return( ret );
00400
00401 }
00402
00403
00404
00405 void marParameters::setRelationalArray( wxArrayString& arr )
00406 {
00407
00408 int i = 0, j;
00409 bool cont;
00410
00411
00412 while( !arr.IsEmpty() ) {
00413
00414 cont = true;
00415 for( j = 0; j < e_string_cont && cont; j++ ) {
00416 if( strcmp( StringParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
00417 _stringValues[ j ] = ( wxString )arr[ i + 1 ];
00418 cont = false;
00419 }
00420 }
00421 for( j = 0; j < e_bool_cont && cont; j++ ) {
00422
00423 if( strcmp( BoolParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
00424
00425 _boolValues[ j ] = ( strcmp( (const char*)arr[ i + 1 ].mb_str(), "1" ) == 0 );
00426 cont = false;
00427
00428 }
00429
00430 }
00431 for( j = 0; j < e_int_cont && cont; j++ ) {
00432
00433 if( strcmp( IntParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
00434
00435 _intValues[ j ] = atoi( (const char*)arr[ i + 1 ].mb_str() );
00436 cont = false;
00437
00438 }
00439
00440 }
00441 for( j = 0; j < e_double_cont && cont; j++ ) {
00442
00443 if( strcmp( DoubleParamNames[ j ], (const char*)arr[ i ].mb_str() ) == 0 ) {
00444
00445 ( ( wxString )arr[ i + 1 ] ).ToDouble( &_doubleValues[ j ] );
00446 cont = false;
00447
00448 }
00449
00450 }
00451 i += 2;
00452
00453 }
00454
00455 }
00456
00457
00458 bool marParameters::getInvestSliceOrder(){
00459 return _boolValues[ e_invest_slice_order ];
00460 }
00461
00462
00463
00464 int marParameters::getContourThresh() {
00465 return _contourThresh;
00466 }
00467
00468
00469 void marParameters::setContourThresh( int thresh ) {
00470 _contourThresh = thresh;
00471 }
00472
00473
00474 double marParameters::getStandardDeviation() {
00475 return _standardDeviation;
00476 }
00477
00478
00479 double marParameters::getRadius() {
00480 return _radius;
00481 }
00482
00483
00484 void marParameters::setStandardDeviation( double dev ) {
00485 _standardDeviation = dev;
00486 }
00487
00488
00489 void marParameters::setRadius( double rad ) {
00490 _radius = rad;
00491 }
00492
00493
00494 void marParameters::setLumenPercentage(int percentage) {
00495 _lumenPercentage = percentage;
00496 }
00497
00498 void marParameters::setCalcPercentage(int percentage) {
00499 _calcPercentage = percentage;
00500 }
00501
00502
00503 int marParameters::getLumenPercentage() {
00504 return _lumenPercentage;
00505 }
00506
00507
00508 int marParameters::getCalcPercentage() {
00509 return _calcPercentage;
00510 }
00511
00512