]> Creatis software - creaBruker.git/blob - lib/src1/brukerobjectvaryingproperties.cpp
f33a396bb10a6754262e0d281d0867d8968e5a8b
[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   if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) throw 7;
105   if (LoopStruct.size() < 4 ) throw 8;
106   for (int i =0 ;i<LoopStruct[3];i++)
107      AcqOrder.push_back((int) BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue()[i*LoopStruct[1]]/LoopStruct[1]);
108   AcquisitionOrder=AcqOrder;
109 };
110
111 std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const{
112    if (theValue < Orientation.size())return Orientation[theValue];
113    //else throw 9;
114    else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
115 }
116
117 /*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
118 {
119    if (theValue1.size() != theValue2[3]*9) throw 10;
120    if (theValue2.size() < 4 ) throw 11;
121    int counter=0;
122    for(int i=0;i<theValue2[3];i++){
123       for(int j=0;j<3;j++){
124          for(int k=0;k<3;k++){
125             Orientation[i][j][k]=theValue1[counter];
126             counter++;
127          }
128       }
129    }
130 }*/
131
132 void BrukerObjectVaryingProperties::computeOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
133    if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 12;
134    if (LoopStruct.size() < 4 ) 
135    //throw 13;
136       throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
137       
138    std::vector<double> Temp1D(3,0.0);
139    std::vector<std::vector<double> > Temp2D;
140    std::vector<std::vector<std::vector<double> > > Temp3D;
141    int i, j ,k;
142
143    for(i=0;i<3;i++) 
144       Temp2D.push_back(Temp1D);
145    for (i=0;i<LoopStruct[3];i++) 
146       Temp3D.push_back(Temp2D);
147
148    int counter=0;
149    for(i=0;i<LoopStruct[3];i++){
150       for(j=0;j<3;j++){
151          for(k=0;k<3;k++){
152             Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
153             counter++;
154          }
155      }
156    }
157    Orientation=Temp3D;
158 };
159
160 double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
161    if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
162    else throw 14;
163 }
164
165 void BrukerObjectVaryingProperties::computePositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
166    double FloatPositionTimePerNR=BrukerHM[(std::string) "ACQ_repetition_time"].GetDoubleValue()[0];
167    int i=0;
168    int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
169    int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
170    double temp;
171
172 /*
173  les loop de 0 a  3 ne sont pas concernes par le temps car ils creent presque systematiquement
174  un melange temporel des donnees, c'est pour cela que je ne calcule qu'un temps moyen a  partir de celles -ci
175 */
176    for (i=4; i<(LoopStruct.size()-1);i++)
177    { 
178       FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
179    }
180    FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
181    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
182    {
183       temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
184       for (i=1; i<=LoopStruct.back();i++)
185       {
186          PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
187       }
188    }
189
190    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
191    {
192       throw 15;
193    }
194    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
195    {
196       PositionTimePerNR[0] = FloatPositionTimePerNR;
197       for (int i=1; i<=LoopStruct.back();i++)
198       {  
199          PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
200       }
201    }
202 }
203
204
205 /*!
206     \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
207  */
208 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct)
209 {
210    try {
211       computeAcquisitionOrder (BrukerHM, LoopStruct);
212       computeOrientation      (BrukerHM, LoopStruct);
213       computePositionP        (BrukerHM);
214       computePositionR        (BrukerHM);
215       computePositionS        (BrukerHM);
216       computePositionTimePerNR(BrukerHM, LoopStruct);
217       computeTE               (BrukerHM);
218    }
219    
220    catch (...)
221    {
222       std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;
223       return false;
224    }
225    
226    return true;
227
228