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