]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/include/marInterface.cpp
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / include / marInterface.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28  Program:   wxMaracas
29  Module:    $RCSfile: marInterface.cpp,v $
30  Language:  C++
31  Date:      $Date: 2012/11/15 14:15:31 $
32  Version:   $Revision: 1.2 $
33  
34   Copyright: (c) 2002, 2003
35   License:
36   
37    This software is distributed WITHOUT ANY WARRANTY; without even 
38    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
39    PURPOSE.  See the above copyright notice for more information.
40    
41 =========================================================================*/
42 #ifdef _MSC_VER
43 #pragma warning ( disable : 4786 )
44 #pragma warning ( disable : 4251 )
45 #endif //_MSC_VER
46
47 #include "marInterface.h"
48 #include <wx/file.h>
49 #include <wx/log.h>
50
51
52
53
54 // ----------------------------------------------------------------------------
55 marInterface::marInterface( )
56 : _parameters( NULL ), _dicom( NULL ),
57 _experiment( NULL )
58 {
59         m_paramFileName=MAR_DEFAULT_FILE_PARAMETERS;
60     _parameters = new marParameters( );
61 //EED    _dicom = new marGdcmDicom( _parameters );
62     _experiment = new marExperiment( _parameters );
63         
64     // loadParameters( ); //PS !!! dangereux de faire des op�rations d'E/S 
65         // dans des constructeurs
66 }
67
68 // ----------------------------------------------------------------------------
69 marInterface::~marInterface( ){
70     reset( );
71 }
72
73 // ----------------------------------------------------------------------------
74 bool marInterface::loadParameters( std::string pFile )
75 {
76         std::ifstream is( pFile.c_str( ),std::ios::binary|std::ios::in);
77
78 //EEDxx2.4 DEBuG
79 //      wxLogDebug(wxString("Loading parameters from file ") 
80 //              + wxString(pFile.c_str()));
81         
82         if( is==NULL )
83         {
84                 wxString errorMsg;
85                 errorMsg= wxString(_T("Error : Cannot open file "))
86                                 + wxString( pFile.c_str(), wxConvUTF8 )
87                                 + wxString(_T(" to load parameters"));
88 //EEDxx2.4 DEBuG
89 //              wxLogDebug(errorMsg);
90                 return (false);
91         }
92         _parameters->reset( );
93         if (_parameters->load( is ))
94         {
95                 is.close( );
96                 return( true );
97         }
98         else
99         {
100                 is.close();
101 //EEDxx2.4 DEBuG
102 //              wxLogDebug(wxString("Error : Cannot load parameters from file ")
103 //                              + wxString(pFile.c_str())
104 //                              + wxString(": file may be corrupted"));
105                 return (false);
106         }
107 }
108
109 // ----------------------------------------------------------------------------
110 bool marInterface::saveParameters( std::string pFile )
111 {
112         std::ofstream os(pFile.c_str( ),std::ios::binary | std::ios::out);
113         
114 //EEDxx2.4 DEBuG
115 //      wxLogDebug(wxString("Saving parameters to file ") 
116 //                      + wxString(pFile.c_str()));
117         
118         
119         if( os==NULL )
120         {
121                 wxString errorMsg;
122                 errorMsg= wxString(_T("Error : Cannot open file "))
123                                 + wxString(pFile.c_str(), wxConvUTF8)
124                                 + wxString(_T(" to save parameters"));
125 //EEDxx2.4 DEBuG
126 //              wxLogDebug(errorMsg);
127                 return( false );
128         }
129         if(_parameters->save( os ))
130         {
131                 os.close( );
132                 return( true );
133         }
134         else
135         {
136                 os.close();
137 //EEDxx2.4 DEBuG
138 //              wxLogDebug(wxString("Error : Cannot save parameters to file ")
139 //                              + wxString(pFile.c_str()));
140                 return (false);
141         }
142
143 }
144
145 // ----------------------------------------------------------------------------
146 bool marInterface::initExperiment( )
147 {
148     _experiment->reset( );
149     _experiment->initExperiment( _dicom->getVolume( ) );
150     return( true );
151         
152 }
153 // ----------------------------------------------------------------------------
154 bool marInterface::saveExperiment( std::string nFile )
155 {
156         std::ofstream os( nFile.c_str( ),std::ios::binary | std::ios::out );
157         
158 //EEDxx2.4 DEBuG
159 //      wxLogDebug(wxString("Saving experiment to file ") 
160 //                      + wxString(nFile.c_str()));
161         
162         wxString errorMsg;
163         errorMsg= wxString(_T("Cannot open file "))
164                         + wxString(nFile.c_str(), wxConvUTF8)
165                         + wxString(_T(" to save experiment"));
166
167         
168     if( os !=NULL ) {
169                 
170         _parameters->save( os );
171         _dicom->save( os );
172         _experiment->save( os );
173                 os.close( );
174                 return( true );
175                 
176     } // fi
177 //EEDxx2.4 DEBuG
178 //      wxLogDebug(errorMsg);
179     return( false );
180 }
181
182 // ----------------------------------------------------------------------------
183 bool marInterface::loadExperiment( std::string nFile )
184 {
185         std::ifstream is( nFile.c_str( ) ,std::ios::binary|std::ios::in );
186         
187 //EEDxx2.4 DEBuG
188 //      wxLogDebug(wxString("Loading experiment from file ") 
189 //                      + wxString(nFile.c_str()));
190         
191         wxString errorMsg;
192         errorMsg= wxString(_T("Cannot open file "))
193                         + wxString(nFile.c_str(), wxConvUTF8)
194                         + wxString(_T(" to load experiment"));
195         
196     if( is !=NULL) {
197                 
198         _parameters->reset( );
199         _dicom->reset( );
200         _experiment->reset( );
201                 
202         _parameters->load( is );
203         _dicom->load( is );
204         _experiment->load( is );
205                 is.close( );
206                 return( true );
207                 
208     } // fi
209 //EEDxx2.4 DEBuG
210 //      wxLogDebug(errorMsg);
211     return( false );
212 }
213
214 // ----------------------------------------------------------------------------
215 void marInterface::reset( )
216 {
217     if( _dicom          != NULL ) delete _dicom;
218     if( _experiment != NULL ) delete _experiment;
219     if( _parameters != NULL ) delete _parameters;
220
221     _dicom              = NULL;
222     _experiment = NULL;
223     _parameters = NULL;
224 }
225 // ----------------------------------------------------------------------------
226 void marInterface::SetParamFileName(std::string pFileName) 
227
228         m_paramFileName=pFileName; 
229 }
230 // ----------------------------------------------------------------------------
231 std::string  marInterface::GetParamFileName() 
232
233         return m_paramFileName;  
234 }
235 // ----------------------------------------------------------------------------
236 void marInterface::SetDicom(marFilesBase *dicom) 
237 {
238         _dicom=dicom;                            
239 }
240
241
242 // eof - interface.cxx
243
244
245 /* EED
246 void marInterface::SetVolumeData(int dimX,int dimY,int dimZ, float spacingX, float spacingY, float spacingZ, unsigned short * pixels)
247 {
248         if (_dicom!=NULL)
249                 _dicom->SetVolumeData(dimX,dimY,dimZ,spacingX,spacingY,spacingZ,pixels);
250 }
251 */
252