]> Creatis software - creaBruker.git/blob - lib/src1/brukerobjectvaryingproperties.cpp
Added CMake configuration to enable CDash tests.
[creaBruker.git] / lib / src1 / brukerobjectvaryingproperties.cpp
1 /*
2         # ---------------------------------------------------------------------
3         #
4         # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5         #                        pour la Santé)
6         # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7         # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8         # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9         #
10         #  This software is governed by the CeCILL-B license under French law and 
11         #  abiding by the rules of distribution of free software. You can  use, 
12         #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13         #  license as circulated by CEA, CNRS and INRIA at the following URL 
14         #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15         #  or in the file LICENSE.txt.
16         #
17         #  As a counterpart to the access to the source code and  rights to copy,
18         #  modify and redistribute granted by the license, users are provided only
19         #  with a limited warranty  and the software's author,  the holder of the
20         #  economic rights,  and the successive licensors  have only  limited
21         #  liability. 
22         #
23         #  The fact that you are presently reading this means that you have had
24         #  knowledge of the CeCILL-B license and that you accept its terms.
25         # ------------------------------------------------------------------------
26 */
27 //
28 // C++ Implementation: brukerobjectvaryingproperties
29 //
30 // Description: 
31 //
32 //
33 // Author: denis grenier <denis.grenier@creatis.univ-lyon1.fr>, (C) 2009
34 //
35 // Copyright: See COPYING file that comes with this distribution
36 //
37 //
38 #include "brukerobjectvaryingproperties.h"
39 #include "brukerexception.h"
40
41
42 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
43 {
44 }
45
46
47 BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
48 {
49 }
50
51
52
53 void BrukerObjectVaryingProperties::computePositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
54    std::vector<double> PosiS =BrukerHM[(std::string) "ACQ_slice_offset"].GetDoubleValue();
55    PositionS =PosiS;
56 };
57
58 void BrukerObjectVaryingProperties::computePositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
59    PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
60 };
61
62 void BrukerObjectVaryingProperties::computePositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
63    PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
64 };
65
66 void BrukerObjectVaryingProperties::computeTE(std::map<std::string, BrukerFieldData> & BrukerHM){
67    TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
68 };
69
70 double BrukerObjectVaryingProperties::getTE(unsigned int theValue) const{
71    if (theValue < TE.size() ) {return TE[theValue];}
72    //else throw 0;
73    else throw BrukerSizeException("TE", theValue, TE.size() ); 
74 }
75
76 /*void BrukerObjectVaryingProperties::computeTE(const std::vector< double >& theValue)
77 {
78   TE = theValue;
79 }*/
80
81 double  BrukerObjectVaryingProperties::getPositionP(unsigned int theValue) const{
82    if (theValue < PositionP.size() ) return PositionP[theValue];
83 //   else throw 1;
84    else throw BrukerSizeException("PositionP", theValue, PositionP.size() );    
85 }
86   
87 /*void BrukerObjectVaryingProperties::computePositionP(const std::vector< double >& theValue)
88 {
89   PositionP = theValue;
90 }*/
91
92 double  BrukerObjectVaryingProperties::getPositionR(unsigned int theValue) const{
93    if (theValue < PositionR.size() ) return PositionR[theValue];
94 //   else throw 2;
95    else throw BrukerSizeException("PositionR", theValue, PositionR.size() );
96 }
97
98 /*void BrukerObjectVaryingProperties::computePositionR(const std::vector< double >& theValue)
99 {
100   PositionP = theValue;
101 }*/
102
103 double  BrukerObjectVaryingProperties::getPositionS(unsigned int theValue) const{
104    if (theValue < PositionS.size() )  return PositionS[theValue];
105 //   else throw 3;
106    else throw BrukerSizeException("PositionS", theValue, PositionS.size() );
107 }
108
109 /*void BrukerObjectVaryingProperties::computePositionS(const std::vector< double >& theValue)
110 {
111   PositionP = theValue;
112 }*/
113
114 int  BrukerObjectVaryingProperties::getAcquisitionOrder(unsigned int theValue) const{
115    if (theValue <AcquisitionOrder.size())  return AcquisitionOrder[theValue];
116    //else throw 4;
117    else throw BrukerSizeException("AcquisitionOrder", theValue, AcquisitionOrder.size() );
118 }
119
120 /*void BrukerObjectVaryingProperties::computeAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
121 {
122    AcquisitionOrder.clear();
123    if (theValue1.size() != theValue2[3]*theValue2[1]) throw 5;
124    if (theValue2.size() < 4 ) throw 6;
125    for (int i =0 ;i<theValue2[3];i++)AcquisitionOrder.push_back()=(int) theValue1[i*theValue2[1]]/theValue2[1];
126 }*/
127
128 void BrukerObjectVaryingProperties::computeAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
129   std::vector<int> AcqOrder;
130   
131   if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) {
132      std::cout << "BrukerHM[(std::string) 'ACQ_obj_order'].GetIntValue().size() " << BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() 
133                << " LoopStruct[3] : " << LoopStruct[3] << " * LoopStruct[1] : " << LoopStruct[1] << " = " << LoopStruct[3]*LoopStruct[1] << std::endl;  
134      throw 7;
135   }
136   if (LoopStruct.size() < 4 ) throw 8;
137   for (int i =0 ;i<LoopStruct[3];i++)
138      AcqOrder.push_back((int) BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue()[i*LoopStruct[1]]/LoopStruct[1]);
139   AcquisitionOrder=AcqOrder;
140 };
141
142 std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const {
143    if (theValue < Orientation.size())return Orientation[theValue];
144    //else throw 9;
145    else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
146 }
147
148 /*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
149 {
150    if (theValue1.size() != theValue2[3]*9) throw 10;
151    if (theValue2.size() < 4 ) throw 11;
152    int counter=0;
153    for(int i=0;i<theValue2[3];i++){
154       for(int j=0;j<3;j++){
155          for(int k=0;k<3;k++){
156             Orientation[i][j][k]=theValue1[counter];
157             counter++;
158          }
159       }
160    }
161 }*/
162
163 void BrukerObjectVaryingProperties::computeOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
164    if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 12;
165    if (LoopStruct.size() < 4 ) 
166    //throw 13;
167       throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
168       
169    std::vector<double> Temp1D(3,0.0);
170    std::vector<std::vector<double> > Temp2D;
171    std::vector<std::vector<std::vector<double> > > Temp3D;
172    int i, j ,k;
173
174    for(i=0;i<3;i++) 
175       Temp2D.push_back(Temp1D);
176    for (i=0;i<LoopStruct[3];i++) 
177       Temp3D.push_back(Temp2D);
178
179    int counter=0;
180    for(i=0;i<LoopStruct[3];i++){
181       for(j=0;j<3;j++){
182          for(k=0;k<3;k++){
183             Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
184             counter++;
185          }
186      }
187    }
188    Orientation=Temp3D;
189 };
190
191 double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
192    if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
193    else throw 14;
194 }
195
196 void BrukerObjectVaryingProperties::computePositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
197    double FloatPositionTimePerNR=BrukerHM[(std::string) "ACQ_repetition_time"].GetDoubleValue()[0];
198    int i=0;
199    int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
200    int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
201    double temp;
202
203 /*
204  les loop de 0 a  3 ne sont pas concernes par le temps car ils creent presque systematiquement
205  un melange temporel des donnees, c'est pour cela que je ne calcule qu'un temps moyen a  partir de celles -ci
206 */
207    for (i=4; i<(LoopStruct.size()-1);i++)
208    { 
209       FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
210    }
211    FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
212    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
213    {
214       temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
215       for (i=1; i<=LoopStruct.back();i++)
216       {
217          PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
218       }
219    }
220
221    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
222    {
223       throw 15;
224    }
225    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
226    {
227       PositionTimePerNR[0] = FloatPositionTimePerNR;
228       for (int i=1; i<=LoopStruct.back();i++)
229       {  
230          PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
231       }
232    }
233 }
234
235
236 /*!
237     \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
238  */
239 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> &BrukerHM, std::vector<int> &LoopStruct)
240 {
241    try {
242       computeAcquisitionOrder (BrukerHM, LoopStruct);
243       computeOrientation      (BrukerHM, LoopStruct);
244       computePositionP        (BrukerHM);
245       computePositionR        (BrukerHM);
246       computePositionS        (BrukerHM);
247       computePositionTimePerNR(BrukerHM, LoopStruct);
248       computeTE               (BrukerHM);
249    }
250    catch (int i)
251    {
252       std::cout << "Failure during BrukerObjectVaryingProperties::init err code : " << i << std::endl;
253       if (i==7)
254          std::cout << "Probabely non standard acquisition (extra loop not yet dealt with)" << std::endl;
255       return false;   
256    }   
257    catch (...)
258    {
259       std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;
260       return false;
261    }
262    
263    return true;
264
265