marParameters.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003  Program:   wxMaracas
00004  Module:    $RCSfile: marParameters.cpp,v $
00005  Language:  C++
00006  Date:      $Date: 2010/04/20 14:42:44 $
00007  Version:   $Revision: 1.3 $
00008  
00009   Copyright: (c) 2002, 2003
00010   License:
00011   
00012    This software is distributed WITHOUT ANY WARRANTY; without even 
00013    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014    PURPOSE.  See the above copyright notice for more information.
00015    
00016 =========================================================================*/
00017 
00018 #include "marParameters.h"
00019 #include <math.h>
00020 #include <wx/log.h>
00021 
00022 static const char* BoolParamNames[] = {
00023         // PS ->     "e_debug_window_visible"  ,
00024         // PS ->        "e_debug_console_visible"     ,
00025         // PS ->        "e_calculate_mip_default"    ,
00026         // PS ->        "e_choose_all_slices_default" ,
00027         "e_debug_isocontour"          ,
00028         "e_debug_diameters"           ,
00029         "e_debug_fill_area"           ,
00030         "e_invest_slice_order"           ,
00031         // PS ->        "e_show_cell"                 ,
00032         // PS ->        "e_show_int_cell"
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         // PS ->        "e_sampling"                      ,
00047         "e_threshold_isocontour"          ,
00048         "e_threshold_snake_isocontour"    ,
00049         "e_sigma"                         ,
00050         // PS ->        "e_gradient_coeficient"           ,
00051         // PS ->        "e_extern_coeficient"             ,
00052         // PS ->        "e_ballon_coeficient"             ,
00053         // PS ->        "e_back_color_3D_r"               ,
00054         // PS ->        "e_back_color_3D_g"               ,
00055         // PS ->        "e_back_color_3D_b"               ,
00056         // PS ->        "e_axis_color_r"                  ,
00057         // PS ->        "e_axis_color_g"                  ,
00058         // PS ->        "e_axis_color_b"
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         // PS ->        "e_number_of_iterations_snake_isocontour" ,
00074         // PS ->        "e_number_of_iterations_snake_deriche"    ,
00075         "e_voxel_type"                            ,
00076         // PS ->        "e_coef_cell_max_int"
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 /* OLD CODE:
00088 
00089  double ret = 1.0;
00090  
00091   if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
00092   
00093    ret = _doubleValues[ e_voxel_x_dimension ];
00094    ret = GTM_MIN( _doubleValues[ e_voxel_y_dimension ], ret );
00095    ret = GTM_MIN( _doubleValues[ e_voxel_z_dimension ], ret );
00096    
00097     } // fi
00098     return( ret );
00099         */
00100 
00101 
00102 //EEDx1 
00103     double ret = 1.0;
00104     //Juan Carrillo 03/06/2005
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     } // fi
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     //  TODO : There should be a formal way to calculate a good image size.
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         // PS ->     _boolValues[ e_debug_window_visible ]      = false;
00183         // PS ->     _boolValues[ e_debug_console_visible ]     = false;
00184         // PS ->     _boolValues[ e_calculate_mip_default ]     = false;
00185         // PS ->     _boolValues[ e_choose_all_slices_default ] = true;
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         // PS ->     _boolValues[ e_show_cell ]                 = true;
00191         // PS ->     _boolValues[ e_show_int_cell ]             = true;
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         // PS ->     _doubleValues[ e_sampling ]         = 4.0;
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         // PS ->     _doubleValues[ e_extern_coeficient ]             = 0.3;
00210         // PS ->     _doubleValues[ e_gradient_coeficient ]           = 0.3;
00211         // PS ->     _doubleValues[ e_ballon_coeficient ]             = 0.02;
00212         // PS ->     _doubleValues[ e_back_color_3D_r ]               = 0.0;
00213         // PS ->     _doubleValues[ e_back_color_3D_g ]               = 0.0;
00214         // PS ->     _doubleValues[ e_back_color_3D_b ]               = 0.0;
00215         // PS ->     _doubleValues[ e_axis_color_r ]                  = 1.0;
00216         // PS ->     _doubleValues[ e_axis_color_g ]                  = 0.0;
00217         // PS ->     _doubleValues[ e_axis_color_b ]                  = 0.0;
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         // PS ->     _intValues[ e_number_of_iterations_snake_isocontour ] = 5;
00230         // PS ->     _intValues[ e_number_of_iterations_snake_deriche ]    = 700;
00231 
00232 
00233     _intValues[ e_voxel_type ]                            = VOX_TYPE_NORMAL;
00234 
00235 
00236         // PS ->     _intValues[ e_coef_cell_max_int ]                     = 2;
00237         
00238      _stringValues[ e_installation_directory ]  = _T("NO_DIRECTORY");
00239      _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
00240         
00241          //MAZV CT compatibility
00242         _contourThresh          = 10;
00243         _lumenPercentage        = 86;
00244         _calcPercentage         = 90;
00245         _standardDeviation      = 3;
00246         _radius                 = 3;
00247         //end MAZV CT compatibility
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                 } // rof
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                 } // rof
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 //EEDxx2.4 DEBuG
00305 //      wxLogDebug("Saving parameters to file " + nw);
00306         
00307     if( os==NULL ) 
00308         {
00309                 wxString errorMsg;
00310                 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
00311 //EEDxx2.4 DEBuG
00312 //              wxLogDebug(errorMsg);
00313                 return( false );
00314         }
00315         if (save( os ))
00316         {
00317                 os.close( );
00318 //EEDxx2.4 DEBuG
00319 //              wxLogDebug("Parameters saved to file " + nw);
00320                 return( true );
00321         }
00322         else
00323         {
00324                 os.close( );
00325 //EEDxx2.4 DEBuG
00326 //              wxLogDebug("Error : Cannot save parameters to file "+nw);
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 //EEDxx2.4 DEBuG
00337 //      wxLogDebug("Laoding parameters from file " + nr);
00338     if( is==NULL ) 
00339         {
00340                 wxString errorMsg;
00341                 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
00342 //EEDxx2.4 DEBuG
00343 //              wxLogDebug(errorMsg);
00344                 return( false );
00345         }
00346         if (load( is ))
00347         {
00348                 is.close( );
00349 //EEDxx2.4 DEBuG
00350 //              wxLogDebug("Parameters loaded from file " + nr);
00351                 return( true );
00352         }
00353         else
00354         {
00355                 is.close( );
00356 //EEDxx2.4 DEBuG
00357 //              wxLogDebug("Error : Cannot load parameters from file "+nr+": file may be corrupted");
00358                 return(false);
00359         }
00360 }
00361 
00362 // ----------------------------------------------------------------------------
00363 wxArrayString marParameters::getRelationalArray( )
00364 {
00365     // Allocate memory for pairs of data plus one end NULL array
00366         //    wxStringList ret;
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     } // rof
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     } // rof
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     } // rof
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      } // rof
00397 
00398 
00399     return( ret );
00400         
00401 }
00402 
00403 // ----------------------------------------------------------------------------
00404 //void marParameters::setRelationalArray( wxStringList& arr )
00405 void marParameters::setRelationalArray( wxArrayString& arr )
00406 {
00407         
00408     int i = 0, j;
00409     bool cont;
00410         
00411         //    while( arr[ i ] != NULL ) {
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                         } // fi
00420                 } // rof
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                         } // fi
00429                         
00430                 } // rof
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                         } // fi
00439                         
00440                 } // rof
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                         } // fi
00449                         
00450                 } // rof
00451                 i += 2;
00452                 
00453     } // fwhile
00454         
00455 }
00456 
00457 
00458 bool marParameters::getInvestSliceOrder(){
00459   return _boolValues[ e_invest_slice_order ];
00460 }
00461 
00462 //MAZV - Added for CT compatibility
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 //MAZV end of addition
00512 // eof - parameters.cxx

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1