]> Creatis software - creaBruker.git/blob - lib/src1/brukerobjectvaryingproperties.cpp
Initial revision
[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
14
15
16 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
17 {
18 }
19
20
21 BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
22 {
23 }
24
25
26
27 void BrukerObjectVaryingProperties::setPositionS(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::setPositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
33    PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
34 };
35
36 void BrukerObjectVaryingProperties::setPositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
37    PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
38 };
39
40 void BrukerObjectVaryingProperties::setTE(std::map<std::string, BrukerFieldData> & BrukerHM){
41    TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
42 };
43
44 double BrukerObjectVaryingProperties::getTE(int theValue) const{
45    if (theValue < TE.size() && theValue >=0) {return TE[theValue];}
46    else throw 0;
47 }
48
49 /*void BrukerObjectVaryingProperties::setTE(const std::vector< double >& theValue)
50 {
51   TE = theValue;
52 }*/
53
54 double  BrukerObjectVaryingProperties::getPositionP(int theValue) const{
55    if (theValue < PositionP.size() && theValue >=0) return PositionP[theValue];
56    else throw 0;
57 }
58   
59 /*void BrukerObjectVaryingProperties::setPositionP(const std::vector< double >& theValue)
60 {
61   PositionP = theValue;
62 }*/
63
64 double  BrukerObjectVaryingProperties::getPositionR(int theValue) const{
65    if (theValue < PositionR.size() && theValue >=0) return PositionR[theValue];
66    else throw 0;
67 }
68
69 /*void BrukerObjectVaryingProperties::setPositionR(const std::vector< double >& theValue)
70 {
71   PositionP = theValue;
72 }*/
73
74 double  BrukerObjectVaryingProperties::getPositionS(int theValue) const{
75    if (theValue < PositionS.size() && theValue >=0)  return PositionS[theValue];
76    else throw 0;
77 }
78
79 /*void BrukerObjectVaryingProperties::setPositionS(const std::vector< double >& theValue)
80 {
81   PositionP = theValue;
82 }*/
83
84 int  BrukerObjectVaryingProperties::getAcquisitionOrder(int theValue) const{
85    if (theValue <AcquisitionOrder.size() && theValue >=0)  return AcquisitionOrder[theValue];
86    else throw 0;
87 }
88
89 /*void BrukerObjectVaryingProperties::setAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
90 {
91    AcquisitionOrder.clear();
92    if (theValue1.size() != theValue2[3]*theValue2[1]) throw 0;
93    if (theValue2.size() < 4 ) throw 0;
94    for (int i =0 ;i<theValue2[3];i++)AcquisitionOrder.push_back()=(int) theValue1[i*theValue2[1]]/theValue2[1];
95 }*/
96
97 void BrukerObjectVaryingProperties::setAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
98    std::vector<int> AcqOrder;
99   if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) throw 0;
100   if (LoopStruct.size() < 4 ) throw 0;
101   for (int i =0 ;i<LoopStruct[3];i++)
102      AcqOrder.push_back((int) BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue()[i*LoopStruct[1]]/LoopStruct[1]);
103   AcquisitionOrder=AcqOrder;
104 };
105
106 std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(int theValue) const{
107    if (theValue <Orientation.size() && theValue >=0)return Orientation[theValue];
108    else throw 0;
109 }
110
111 /*void BrukerObjectVaryingProperties::setOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
112 {
113    if (theValue1.size() != theValue2[3]*9) throw 0;
114    if (theValue2.size() < 4 ) throw 0;
115    int counter=0;
116    for(int i=0;i<theValue2[3];i++){
117       for(int j=0;j<3;j++){
118          for(int k=0;k<3;k++){
119             Orientation[i][j][k]=theValue1[counter];
120             counter++;
121          }
122       }
123    }
124 }*/
125
126 void BrukerObjectVaryingProperties::setOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
127    if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 0;
128    if (LoopStruct.size() < 4 ) throw 0;
129
130    std::vector<double> Temp1D(3,0.0);
131    std::vector<std::vector<double> > Temp2D;
132    std::vector<std::vector<std::vector<double> > > Temp3D;
133    int i, j ,k;
134
135    for(i=0;i<3;i++) 
136       Temp2D.push_back(Temp1D);
137    for (i=0;i<LoopStruct[3];i++) 
138       Temp3D.push_back(Temp2D);
139
140    int counter=0;
141    for(i=0;i<LoopStruct[3];i++){
142       for(j=0;j<3;j++){
143          for(k=0;k<3;k++){
144             Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
145             counter++;
146          }
147      }
148    }
149    Orientation=Temp3D;
150 };
151
152 double  BrukerObjectVaryingProperties::getPositionTimePerNR(int theValue) const{
153    if (theValue <PositionTimePerNR.size() && theValue >=0) return PositionTimePerNR[theValue];
154    else throw 0;
155 }
156
157 void BrukerObjectVaryingProperties::setPositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
158    double FloatPositionTimePerNR=BrukerHM[(std::string) "ACQ_repetition_time"].GetDoubleValue()[0];
159    int i=0;
160    int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
161    int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
162    double temp;
163
164 /*
165  les loop de 0 a  3 ne sont pas conceres par le temps car ils creent presque systematiquement
166 un melange temporel des donnees, c'est pour cela que je ne calcule q'un temps moyen a  partir de celles -ci
167 */
168    for (i=4; i<(LoopStruct.size()-1);i++)
169    { 
170       FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
171    }
172    FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
173    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
174    {
175       temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
176       for (i=1; i<=LoopStruct.back();i++)
177       {
178          PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
179       }
180    }
181
182    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
183    {
184       throw 0;
185    }
186    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
187    {
188       PositionTimePerNR[0] = FloatPositionTimePerNR;
189       for (int i=1; i<=LoopStruct.back();i++)
190       {  
191          PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
192       }
193    }
194 }
195
196
197 /*!
198     \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
199  */
200 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct)
201 {
202    setAcquisitionOrder( BrukerHM, LoopStruct);
203    setOrientation(BrukerHM, LoopStruct);
204    setPositionP(BrukerHM);
205    setPositionR(BrukerHM);
206    setPositionS(BrukerHM);
207    setPositionTimePerNR(BrukerHM, LoopStruct);
208    setTE(BrukerHM);
209
210