marInterface.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003  Program:   wxMaracas
00004  Module:    $RCSfile: marInterface.cpp,v $
00005  Language:  C++
00006  Date:      $Date: 2009/05/14 13:55:07 $
00007  Version:   $Revision: 1.1 $
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 #ifdef _MSC_VER
00018 #pragma warning ( disable : 4786 )
00019 #pragma warning ( disable : 4251 )
00020 #endif //_MSC_VER
00021 
00022 #include "marInterface.h"
00023 #include <wx/file.h>
00024 #include <wx/log.h>
00025 
00026 
00027 
00028 
00029 // ----------------------------------------------------------------------------
00030 marInterface::marInterface( )
00031 : _parameters( NULL ), _dicom( NULL ),
00032 _experiment( NULL )
00033 {
00034         m_paramFileName=MAR_DEFAULT_FILE_PARAMETERS;
00035     _parameters = new marParameters( );
00036 //EED    _dicom = new marGdcmDicom( _parameters );
00037     _experiment = new marExperiment( _parameters );
00038         
00039     // loadParameters( ); //PS !!! dangereux de faire des opérations d'E/S 
00040         // dans des constructeurs
00041 }
00042 
00043 // ----------------------------------------------------------------------------
00044 marInterface::~marInterface( ){
00045     reset( );
00046 }
00047 
00048 // ----------------------------------------------------------------------------
00049 bool marInterface::loadParameters( std::string pFile )
00050 {
00051         std::ifstream is( pFile.c_str( ),std::ios::binary|std::ios::in);
00052 
00053 //EEDxx2.4 DEBuG
00054 //      wxLogDebug(wxString("Loading parameters from file ") 
00055 //              + wxString(pFile.c_str()));
00056         
00057         if( is==NULL )
00058         {
00059                 wxString errorMsg;
00060                 errorMsg= wxString(_T("Error : Cannot open file "))
00061                                 + wxString( pFile.c_str(), wxConvUTF8 )
00062                                 + wxString(_T(" to load parameters"));
00063 //EEDxx2.4 DEBuG
00064 //              wxLogDebug(errorMsg);
00065                 return (false);
00066         }
00067         _parameters->reset( );
00068         if (_parameters->load( is ))
00069         {
00070                 is.close( );
00071                 return( true );
00072         }
00073         else
00074         {
00075                 is.close();
00076 //EEDxx2.4 DEBuG
00077 //              wxLogDebug(wxString("Error : Cannot load parameters from file ")
00078 //                              + wxString(pFile.c_str())
00079 //                              + wxString(": file may be corrupted"));
00080                 return (false);
00081         }
00082 }
00083 
00084 // ----------------------------------------------------------------------------
00085 bool marInterface::saveParameters( std::string pFile )
00086 {
00087         std::ofstream os(pFile.c_str( ),std::ios::binary | std::ios::out);
00088         
00089 //EEDxx2.4 DEBuG
00090 //      wxLogDebug(wxString("Saving parameters to file ") 
00091 //                      + wxString(pFile.c_str()));
00092         
00093         
00094         if( os==NULL )
00095         {
00096                 wxString errorMsg;
00097                 errorMsg= wxString(_T("Error : Cannot open file "))
00098                                 + wxString(pFile.c_str(), wxConvUTF8)
00099                                 + wxString(_T(" to save parameters"));
00100 //EEDxx2.4 DEBuG
00101 //              wxLogDebug(errorMsg);
00102                 return( false );
00103         }
00104         if(_parameters->save( os ))
00105         {
00106                 os.close( );
00107                 return( true );
00108         }
00109         else
00110         {
00111                 os.close();
00112 //EEDxx2.4 DEBuG
00113 //              wxLogDebug(wxString("Error : Cannot save parameters to file ")
00114 //                              + wxString(pFile.c_str()));
00115                 return (false);
00116         }
00117 
00118 }
00119 
00120 // ----------------------------------------------------------------------------
00121 bool marInterface::initExperiment( )
00122 {
00123     _experiment->reset( );
00124     _experiment->initExperiment( _dicom->getVolume( ) );
00125     return( true );
00126         
00127 }
00128 // ----------------------------------------------------------------------------
00129 bool marInterface::saveExperiment( std::string nFile )
00130 {
00131         std::ofstream os( nFile.c_str( ),std::ios::binary | std::ios::out );
00132         
00133 //EEDxx2.4 DEBuG
00134 //      wxLogDebug(wxString("Saving experiment to file ") 
00135 //                      + wxString(nFile.c_str()));
00136         
00137         wxString errorMsg;
00138         errorMsg= wxString(_T("Cannot open file "))
00139                         + wxString(nFile.c_str(), wxConvUTF8)
00140                         + wxString(_T(" to save experiment"));
00141 
00142         
00143     if( os !=NULL ) {
00144                 
00145         _parameters->save( os );
00146         _dicom->save( os );
00147         _experiment->save( os );
00148                 os.close( );
00149                 return( true );
00150                 
00151     } // fi
00152 //EEDxx2.4 DEBuG
00153 //      wxLogDebug(errorMsg);
00154     return( false );
00155 }
00156 
00157 // ----------------------------------------------------------------------------
00158 bool marInterface::loadExperiment( std::string nFile )
00159 {
00160         std::ifstream is( nFile.c_str( ) ,std::ios::binary|std::ios::in );
00161         
00162 //EEDxx2.4 DEBuG
00163 //      wxLogDebug(wxString("Loading experiment from file ") 
00164 //                      + wxString(nFile.c_str()));
00165         
00166         wxString errorMsg;
00167         errorMsg= wxString(_T("Cannot open file "))
00168                         + wxString(nFile.c_str(), wxConvUTF8)
00169                         + wxString(_T(" to load experiment"));
00170         
00171     if( is !=NULL) {
00172                 
00173         _parameters->reset( );
00174         _dicom->reset( );
00175         _experiment->reset( );
00176                 
00177         _parameters->load( is );
00178         _dicom->load( is );
00179         _experiment->load( is );
00180                 is.close( );
00181                 return( true );
00182                 
00183     } // fi
00184 //EEDxx2.4 DEBuG
00185 //      wxLogDebug(errorMsg);
00186     return( false );
00187 }
00188 
00189 // ----------------------------------------------------------------------------
00190 void marInterface::reset( )
00191 {
00192     if( _dicom          != NULL ) delete _dicom;
00193     if( _experiment != NULL ) delete _experiment;
00194     if( _parameters != NULL ) delete _parameters;
00195 
00196     _dicom              = NULL;
00197     _experiment = NULL;
00198     _parameters = NULL;
00199 }
00200 // ----------------------------------------------------------------------------
00201 void marInterface::SetParamFileName(std::string pFileName) 
00202 { 
00203         m_paramFileName=pFileName; 
00204 }
00205 // ----------------------------------------------------------------------------
00206 std::string  marInterface::GetParamFileName() 
00207 { 
00208         return m_paramFileName;  
00209 }
00210 // ----------------------------------------------------------------------------
00211 void marInterface::SetDicom(marFilesBase *dicom) 
00212 {
00213         _dicom=dicom;                            
00214 }
00215 
00216 
00217 // eof - interface.cxx
00218 
00219 
00220 /* EED
00221 void marInterface::SetVolumeData(int dimX,int dimY,int dimZ, float spacingX, float spacingY, float spacingZ, unsigned short * pixels)
00222 {
00223         if (_dicom!=NULL)
00224                 _dicom->SetVolumeData(dimX,dimY,dimZ,spacingX,spacingY,spacingZ,pixels);
00225 }
00226 */
00227 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1