]> Creatis software - creaBruker.git/blob - lib/src1/brukerobjectvaryingproperties.cpp
Fix bug when checking incoherences
[creaBruker.git] / lib / src1 / brukerobjectvaryingproperties.cpp
1 //
2 // C++ Implementation: brukerobjectvaryingproperties
3 //
4 // Description: 
5 //
6 //
7 // Author: denis grenier <denis.grenier@creatis.univ-lyon1.fr>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #include "brukerobjectvaryingproperties.h"
13 #include "brukerexception.h"
14
15
16 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
17 {
18 }
19
20
21 BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
22 {
23 }
24
25
26
27 void BrukerObjectVaryingProperties::computePositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
28    std::vector<double> PosiS =BrukerHM[(std::string) "ACQ_slice_offset"].GetDoubleValue();
29    PositionS =PosiS;
30 };
31
32 void BrukerObjectVaryingProperties::computePositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
33    PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
34 };
35
36 void BrukerObjectVaryingProperties::computePositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
37    PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
38 };
39
40 void BrukerObjectVaryingProperties::computeTE(std::map<std::string, BrukerFieldData> & BrukerHM){
41    TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
42 };
43
44 double BrukerObjectVaryingProperties::getTE(unsigned int theValue) const{
45    if (theValue < TE.size() ) {return TE[theValue];}
46    //else throw 0;
47    else throw BrukerSizeException("TE", theValue, TE.size() ); 
48 }
49
50 /*void BrukerObjectVaryingProperties::computeTE(const std::vector< double >& theValue)
51 {
52   TE = theValue;
53 }*/
54
55 double  BrukerObjectVaryingProperties::getPositionP(unsigned int theValue) const{
56    if (theValue < PositionP.size() ) return PositionP[theValue];
57 //   else throw 1;
58    else throw BrukerSizeException("PositionP", theValue, PositionP.size() );    
59 }
60   
61 /*void BrukerObjectVaryingProperties::computePositionP(const std::vector< double >& theValue)
62 {
63   PositionP = theValue;
64 }*/
65
66 double  BrukerObjectVaryingProperties::getPositionR(unsigned int theValue) const{
67    if (theValue < PositionR.size() ) return PositionR[theValue];
68 //   else throw 2;
69    else throw BrukerSizeException("PositionR", theValue, PositionR.size() );
70 }
71
72 /*void BrukerObjectVaryingProperties::computePositionR(const std::vector< double >& theValue)
73 {
74   PositionP = theValue;
75 }*/
76
77 double  BrukerObjectVaryingProperties::getPositionS(unsigned int theValue) const{
78    if (theValue < PositionS.size() )  return PositionS[theValue];
79 //   else throw 3;
80    else throw BrukerSizeException("PositionS", theValue, PositionS.size() );
81 }
82
83 /*void BrukerObjectVaryingProperties::computePositionS(const std::vector< double >& theValue)
84 {
85   PositionP = theValue;
86 }*/
87
88 int  BrukerObjectVaryingProperties::getAcquisitionOrder(unsigned int theValue) const{
89    if (theValue <AcquisitionOrder.size())  return AcquisitionOrder[theValue];
90    //else throw 4;
91    else throw BrukerSizeException("AcquisitionOrder", theValue, AcquisitionOrder.size() );
92 }
93
94 /*void BrukerObjectVaryingProperties::computeAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
95 {
96    AcquisitionOrder.clear();
97    if (theValue1.size() != theValue2[3]*theValue2[1]) throw 5;
98    if (theValue2.size() < 4 ) throw 6;
99    for (int i =0 ;i<theValue2[3];i++)AcquisitionOrder.push_back()=(int) theValue1[i*theValue2[1]]/theValue2[1];
100 }*/
101
102 void BrukerObjectVaryingProperties::computeAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
103   std::vector<int> AcqOrder;
104   
105   if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) {
106      std::cout << "BrukerHM[(std::string) 'ACQ_obj_order'].GetIntValue().size() " << BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() 
107                << " LoopStruct[3] : " << LoopStruct[3] << " * LoopStruct[1] : " << LoopStruct[1] << " = " << LoopStruct[3]*LoopStruct[1] << std::endl;  
108      throw 7;
109   }
110   if (LoopStruct.size() < 4 ) throw 8;
111   for (int i =0 ;i<LoopStruct[3];i++)
112      AcqOrder.push_back((int) BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue()[i*LoopStruct[1]]/LoopStruct[1]);
113   AcquisitionOrder=AcqOrder;
114 };
115
116 std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const {
117    if (theValue < Orientation.size())return Orientation[theValue];
118    //else throw 9;
119    else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
120 }
121
122 /*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
123 {
124    if (theValue1.size() != theValue2[3]*9) throw 10;
125    if (theValue2.size() < 4 ) throw 11;
126    int counter=0;
127    for(int i=0;i<theValue2[3];i++){
128       for(int j=0;j<3;j++){
129          for(int k=0;k<3;k++){
130             Orientation[i][j][k]=theValue1[counter];
131             counter++;
132          }
133       }
134    }
135 }*/
136
137 void BrukerObjectVaryingProperties::computeOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
138    if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 12;
139    if (LoopStruct.size() < 4 ) 
140    //throw 13;
141       throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
142       
143    std::vector<double> Temp1D(3,0.0);
144    std::vector<std::vector<double> > Temp2D;
145    std::vector<std::vector<std::vector<double> > > Temp3D;
146    int i, j ,k;
147
148    for(i=0;i<3;i++) 
149       Temp2D.push_back(Temp1D);
150    for (i=0;i<LoopStruct[3];i++) 
151       Temp3D.push_back(Temp2D);
152
153    int counter=0;
154    for(i=0;i<LoopStruct[3];i++){
155       for(j=0;j<3;j++){
156          for(k=0;k<3;k++){
157             Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
158             counter++;
159          }
160      }
161    }
162    Orientation=Temp3D;
163 };
164
165 double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
166    if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
167    else throw 14;
168 }
169
170 void BrukerObjectVaryingProperties::computePositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
171    double FloatPositionTimePerNR=BrukerHM[(std::string) "ACQ_repetition_time"].GetDoubleValue()[0];
172    int i=0;
173    int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
174    int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
175    double temp;
176
177 /*
178  les loop de 0 a  3 ne sont pas concernes par le temps car ils creent presque systematiquement
179  un melange temporel des donnees, c'est pour cela que je ne calcule qu'un temps moyen a  partir de celles -ci
180 */
181    for (i=4; i<(LoopStruct.size()-1);i++)
182    { 
183       FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
184    }
185    FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
186    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
187    {
188       temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
189       for (i=1; i<=LoopStruct.back();i++)
190       {
191          PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
192       }
193    }
194
195    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
196    {
197       throw 15;
198    }
199    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
200    {
201       PositionTimePerNR[0] = FloatPositionTimePerNR;
202       for (int i=1; i<=LoopStruct.back();i++)
203       {  
204          PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
205       }
206    }
207 }
208
209
210 /*!
211     \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
212  */
213 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> &BrukerHM, std::vector<int> &LoopStruct)
214 {
215    try {
216       computeAcquisitionOrder (BrukerHM, LoopStruct);
217       computeOrientation      (BrukerHM, LoopStruct);
218       computePositionP        (BrukerHM);
219       computePositionR        (BrukerHM);
220       computePositionS        (BrukerHM);
221       computePositionTimePerNR(BrukerHM, LoopStruct);
222       computeTE               (BrukerHM);
223    }
224    catch (int i)
225    {
226       std::cout << "Failure during BrukerObjectVaryingProperties::init err code : " << i << std::endl;
227       if (i==7)
228          std::cout << "Probabely non standard acquisition (extra loop not yet dealt with)" << std::endl;
229       return false;   
230    }   
231    catch (...)
232    {
233       std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;
234       return false;
235    }
236    
237    return true;
238
239