2 // C++ Implementation: brukerobjectvaryingproperties
7 // Author: denis grenier <denis.grenier@creatis.univ-lyon1.fr>, (C) 2009
9 // Copyright: See COPYING file that comes with this distribution
12 #include "brukerobjectvaryingproperties.h"
13 #include "brukerexception.h"
16 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
21 BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
27 void BrukerObjectVaryingProperties::computePositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
28 std::vector<double> PosiS =BrukerHM[(std::string) "ACQ_slice_offset"].GetDoubleValue();
32 void BrukerObjectVaryingProperties::computePositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
33 PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
36 void BrukerObjectVaryingProperties::computePositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
37 PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
40 void BrukerObjectVaryingProperties::computeTE(std::map<std::string, BrukerFieldData> & BrukerHM){
41 TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
44 double BrukerObjectVaryingProperties::getTE(unsigned int theValue) const{
45 if (theValue < TE.size() ) {return TE[theValue];}
47 else throw BrukerSizeException("TE", theValue, TE.size() );
50 /*void BrukerObjectVaryingProperties::computeTE(const std::vector< double >& theValue)
55 double BrukerObjectVaryingProperties::getPositionP(unsigned int theValue) const{
56 if (theValue < PositionP.size() ) return PositionP[theValue];
58 else throw BrukerSizeException("PositionP", theValue, PositionP.size() );
61 /*void BrukerObjectVaryingProperties::computePositionP(const std::vector< double >& theValue)
66 double BrukerObjectVaryingProperties::getPositionR(unsigned int theValue) const{
67 if (theValue < PositionR.size() ) return PositionR[theValue];
69 else throw BrukerSizeException("PositionR", theValue, PositionR.size() );
72 /*void BrukerObjectVaryingProperties::computePositionR(const std::vector< double >& theValue)
77 double BrukerObjectVaryingProperties::getPositionS(unsigned int theValue) const{
78 if (theValue < PositionS.size() ) return PositionS[theValue];
80 else throw BrukerSizeException("PositionS", theValue, PositionS.size() );
83 /*void BrukerObjectVaryingProperties::computePositionS(const std::vector< double >& theValue)
88 int BrukerObjectVaryingProperties::getAcquisitionOrder(unsigned int theValue) const{
89 if (theValue <AcquisitionOrder.size()) return AcquisitionOrder[theValue];
91 else throw BrukerSizeException("AcquisitionOrder", theValue, AcquisitionOrder.size() );
94 /*void BrukerObjectVaryingProperties::computeAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
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];
102 void BrukerObjectVaryingProperties::computeAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
103 std::vector<int> AcqOrder;
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;
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;
116 std :: vector < std :: vector < double > > BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const {
117 if (theValue < Orientation.size())return Orientation[theValue];
119 else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
122 /*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
124 if (theValue1.size() != theValue2[3]*9) throw 10;
125 if (theValue2.size() < 4 ) throw 11;
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];
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 )
141 throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
143 std::vector<double> Temp1D(3,0.0);
144 std::vector<std::vector<double> > Temp2D;
145 std::vector<std::vector<std::vector<double> > > Temp3D;
149 Temp2D.push_back(Temp1D);
150 for (i=0;i<LoopStruct[3];i++)
151 Temp3D.push_back(Temp2D);
154 for(i=0;i<LoopStruct[3];i++){
157 Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
165 double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
166 if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
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];
173 int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
174 int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
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
181 for (i=4; i<(LoopStruct.size()-1);i++)
183 FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
185 FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
186 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
188 temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
189 for (i=1; i<=LoopStruct.back();i++)
191 PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
195 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
199 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
201 PositionTimePerNR[0] = FloatPositionTimePerNR;
202 for (int i=1; i<=LoopStruct.back();i++)
204 PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
211 \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
213 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> &BrukerHM, std::vector<int> &LoopStruct)
216 computeAcquisitionOrder (BrukerHM, LoopStruct);
217 computeOrientation (BrukerHM, LoopStruct);
218 computePositionP (BrukerHM);
219 computePositionR (BrukerHM);
220 computePositionS (BrukerHM);
221 computePositionTimePerNR(BrukerHM, LoopStruct);
222 computeTE (BrukerHM);
226 std::cout << "Failure during BrukerObjectVaryingProperties::init err code : " << i << std::endl;
228 std::cout << "Probabely non standard acquisition (extra loop not yet dealt with)" << std::endl;
233 std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;