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: 2009/05/14 13:54:43 $
00007  Version:   $Revision: 1.2 $
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 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 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         // PS ->        "e_sampling"                      ,
00046         "e_threshold_isocontour"          ,
00047         "e_threshold_snake_isocontour"    ,
00048         "e_sigma"                         ,
00049         // PS ->        "e_gradient_coeficient"           ,
00050         // PS ->        "e_extern_coeficient"             ,
00051         // PS ->        "e_ballon_coeficient"             ,
00052         // PS ->        "e_back_color_3D_r"               ,
00053         // PS ->        "e_back_color_3D_g"               ,
00054         // PS ->        "e_back_color_3D_b"               ,
00055         // PS ->        "e_axis_color_r"                  ,
00056         // PS ->        "e_axis_color_g"                  ,
00057         // PS ->        "e_axis_color_b"
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         // PS ->        "e_number_of_iterations_snake_isocontour" ,
00072         // PS ->        "e_number_of_iterations_snake_deriche"    ,
00073         "e_voxel_type"                            ,
00074         // PS ->        "e_coef_cell_max_int"
00075 };
00076 static char* StringParamNames[] = {
00077         "e_installation_directory" ,
00078         "e_dicom_images_directory"
00079 };
00080 
00081 // -------------------------------------------------------------------------
00082 double marParameters::getVoxelSize( )
00083 {
00084 /* OLD CODE:
00085 
00086  double ret = 1.0;
00087  
00088   if( _intValues[ e_voxel_type ] == VOX_TYPE_MINIMUM ) {
00089   
00090    ret = _doubleValues[ e_voxel_x_dimension ];
00091    ret = GTM_MIN( _doubleValues[ e_voxel_y_dimension ], ret );
00092    ret = GTM_MIN( _doubleValues[ e_voxel_z_dimension ], ret );
00093    
00094     } // fi
00095     return( ret );
00096         */
00097 
00098 
00099 //EEDx1 
00100     double ret = 1.0;
00101     //Juan Carrillo 03/06/2005
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     } // fi
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     //  TODO : There should be a formal way to calculate a good image size.
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         // PS ->     _boolValues[ e_debug_window_visible ]      = false;
00180         // PS ->     _boolValues[ e_debug_console_visible ]     = false;
00181         // PS ->     _boolValues[ e_calculate_mip_default ]     = false;
00182         // PS ->     _boolValues[ e_choose_all_slices_default ] = true;
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         // PS ->     _boolValues[ e_show_cell ]                 = true;
00188         // PS ->     _boolValues[ e_show_int_cell ]             = true;
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         // PS ->     _doubleValues[ e_sampling ]                      = 4.0;
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         // PS ->     _doubleValues[ e_extern_coeficient ]             = 0.3;
00207         // PS ->     _doubleValues[ e_gradient_coeficient ]           = 0.3;
00208         // PS ->     _doubleValues[ e_ballon_coeficient ]             = 0.02;
00209         // PS ->     _doubleValues[ e_back_color_3D_r ]               = 0.0;
00210         // PS ->     _doubleValues[ e_back_color_3D_g ]               = 0.0;
00211         // PS ->     _doubleValues[ e_back_color_3D_b ]               = 0.0;
00212         // PS ->     _doubleValues[ e_axis_color_r ]                  = 1.0;
00213         // PS ->     _doubleValues[ e_axis_color_g ]                  = 0.0;
00214         // PS ->     _doubleValues[ e_axis_color_b ]                  = 0.0;
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         // PS ->     _intValues[ e_number_of_iterations_snake_isocontour ] = 5;
00227         // PS ->     _intValues[ e_number_of_iterations_snake_deriche ]    = 700;
00228 
00229 
00230     _intValues[ e_voxel_type ]                            = VOX_TYPE_NORMAL;
00231 
00232 
00233         // PS ->     _intValues[ e_coef_cell_max_int ]                     = 2;
00234         
00235      _stringValues[ e_installation_directory ]  = _T("NO_DIRECTORY");
00236      _stringValues[ e_dicom_images_directory ] = _T("NO_DIRECTORY");
00237         
00238          //MAZV CT compatibility
00239         _contourThresh          = 10;
00240         _lumenPercentage        = 86;
00241         _calcPercentage         = 90;
00242         _standardDeviation      = 3;
00243         _radius                 = 3;
00244         //end MAZV CT compatibility
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                 } // rof
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                 } // rof
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 //EEDxx2.4 DEBuG
00302 //      wxLogDebug("Saving parameters to file " + nw);
00303         
00304     if( os==NULL ) 
00305         {
00306                 wxString errorMsg;
00307                 errorMsg= _T("Error : Cannot open file ")+nw+_T(" to save parameters");
00308 //EEDxx2.4 DEBuG
00309 //              wxLogDebug(errorMsg);
00310                 return( false );
00311         }
00312         if (save( os ))
00313         {
00314                 os.close( );
00315 //EEDxx2.4 DEBuG
00316 //              wxLogDebug("Parameters saved to file " + nw);
00317                 return( true );
00318         }
00319         else
00320         {
00321                 os.close( );
00322 //EEDxx2.4 DEBuG
00323 //              wxLogDebug("Error : Cannot save parameters to file "+nw);
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 //EEDxx2.4 DEBuG
00334 //      wxLogDebug("Laoding parameters from file " + nr);
00335     if( is==NULL ) 
00336         {
00337                 wxString errorMsg;
00338                 errorMsg= _T("Error : Cannot open file ")+nr+_T(" to load parameters");
00339 //EEDxx2.4 DEBuG
00340 //              wxLogDebug(errorMsg);
00341                 return( false );
00342         }
00343         if (load( is ))
00344         {
00345                 is.close( );
00346 //EEDxx2.4 DEBuG
00347 //              wxLogDebug("Parameters loaded from file " + nr);
00348                 return( true );
00349         }
00350         else
00351         {
00352                 is.close( );
00353 //EEDxx2.4 DEBuG
00354 //              wxLogDebug("Error : Cannot load parameters from file "+nr+": file may be corrupted");
00355                 return(false);
00356         }
00357 }
00358 
00359 // ----------------------------------------------------------------------------
00360 wxArrayString marParameters::getRelationalArray( )
00361 {
00362     // Allocate memory for pairs of data plus one end NULL array
00363         //    wxStringList ret;
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     } // rof
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     } // rof
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     } // rof
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      } // rof
00394 
00395 
00396     return( ret );
00397         
00398 }
00399 
00400 // ----------------------------------------------------------------------------
00401 //void marParameters::setRelationalArray( wxStringList& arr )
00402 void marParameters::setRelationalArray( wxArrayString& arr )
00403 {
00404         
00405     int i = 0, j;
00406     bool cont;
00407         
00408         //    while( arr[ i ] != NULL ) {
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                         } // fi
00417                 } // rof
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                         } // fi
00426                         
00427                 } // rof
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                         } // fi
00436                         
00437                 } // rof
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                         } // fi
00446                         
00447                 } // rof
00448                 i += 2;
00449                 
00450     } // fwhile
00451         
00452 }
00453 
00454 
00455 bool marParameters::getInvestSliceOrder(){
00456   return _boolValues[ e_invest_slice_order ];
00457 }
00458 
00459 //MAZV - Added for CT compatibility
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 //MAZV end of addition
00509 // eof - parameters.cxx

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1