2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
28 // C++ Implementation: brukerobjectvaryingproperties
33 // Author: denis grenier <denis.grenier@creatis.univ-lyon1.fr>, (C) 2009
35 // Copyright: See COPYING file that comes with this distribution
38 #include "brukerobjectvaryingproperties.h"
39 #include "brukerexception.h"
42 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
47 BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
53 void BrukerObjectVaryingProperties::computePositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
54 std::vector<double> PosiS =BrukerHM[(std::string) "ACQ_slice_offset"].GetDoubleValue();
58 void BrukerObjectVaryingProperties::computePositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
59 PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
62 void BrukerObjectVaryingProperties::computePositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
63 PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
66 void BrukerObjectVaryingProperties::computeTE(std::map<std::string, BrukerFieldData> & BrukerHM){
67 TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
70 double BrukerObjectVaryingProperties::getTE(unsigned int theValue) const{
71 if (theValue < TE.size() ) {return TE[theValue];}
73 else throw BrukerSizeException("TE", theValue, TE.size() );
76 /*void BrukerObjectVaryingProperties::computeTE(const std::vector< double >& theValue)
81 double BrukerObjectVaryingProperties::getPositionP(unsigned int theValue) const{
82 if (theValue < PositionP.size() ) return PositionP[theValue];
84 else throw BrukerSizeException("PositionP", theValue, PositionP.size() );
87 /*void BrukerObjectVaryingProperties::computePositionP(const std::vector< double >& theValue)
92 double BrukerObjectVaryingProperties::getPositionR(unsigned int theValue) const{
93 if (theValue < PositionR.size() ) return PositionR[theValue];
95 else throw BrukerSizeException("PositionR", theValue, PositionR.size() );
98 /*void BrukerObjectVaryingProperties::computePositionR(const std::vector< double >& theValue)
100 PositionP = theValue;
103 double BrukerObjectVaryingProperties::getPositionS(unsigned int theValue) const{
104 if (theValue < PositionS.size() ) return PositionS[theValue];
106 else throw BrukerSizeException("PositionS", theValue, PositionS.size() );
109 /*void BrukerObjectVaryingProperties::computePositionS(const std::vector< double >& theValue)
111 PositionP = theValue;
114 int BrukerObjectVaryingProperties::getAcquisitionOrder(unsigned int theValue) const{
115 if (theValue <AcquisitionOrder.size()) return AcquisitionOrder[theValue];
117 else throw BrukerSizeException("AcquisitionOrder", theValue, AcquisitionOrder.size() );
120 /*void BrukerObjectVaryingProperties::computeAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
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];
128 void BrukerObjectVaryingProperties::computeAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
129 std::vector<int> AcqOrder;
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;
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;
142 std :: vector < std :: vector < double > > BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const {
143 if (theValue < Orientation.size())return Orientation[theValue];
145 else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
148 /*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
150 if (theValue1.size() != theValue2[3]*9) throw 10;
151 if (theValue2.size() < 4 ) throw 11;
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];
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 )
167 throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
169 std::vector<double> Temp1D(3,0.0);
170 std::vector<std::vector<double> > Temp2D;
171 std::vector<std::vector<std::vector<double> > > Temp3D;
175 Temp2D.push_back(Temp1D);
176 for (i=0;i<LoopStruct[3];i++)
177 Temp3D.push_back(Temp2D);
180 for(i=0;i<LoopStruct[3];i++){
183 Temp3D[i][j][k]=BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue()[counter];
191 double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
192 if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
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];
199 int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
200 int NAE=BrukerHM[(std::string) "NAE"].GetIntValue()[0];
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
207 for (i=4; i<(LoopStruct.size()-1);i++)
209 FloatPositionTimePerNR=FloatPositionTimePerNR*LoopStruct[i];
211 FloatPositionTimePerNR=FloatPositionTimePerNR*NA*NAE/2000.0;
212 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==1)
214 temp=BrukerHM[(std::string)"ACQ_temporal_delay"].GetDoubleValue()[0]/1000.0;
215 for (i=1; i<=LoopStruct.back();i++)
217 PositionTimePerNR.push_back(FloatPositionTimePerNR+ (2*FloatPositionTimePerNR+temp)*(i-1));
221 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
225 if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
227 PositionTimePerNR[0] = FloatPositionTimePerNR;
228 for (int i=1; i<=LoopStruct.back();i++)
230 PositionTimePerNR[i] = PositionTimePerNR[i-1]+ (2*FloatPositionTimePerNR+BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue()[i-1]/1000.0);
237 \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
239 bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> &BrukerHM, std::vector<int> &LoopStruct)
242 computeAcquisitionOrder (BrukerHM, LoopStruct);
243 computeOrientation (BrukerHM, LoopStruct);
244 computePositionP (BrukerHM);
245 computePositionR (BrukerHM);
246 computePositionS (BrukerHM);
247 computePositionTimePerNR(BrukerHM, LoopStruct);
248 computeTE (BrukerHM);
252 std::cout << "Failure during BrukerObjectVaryingProperties::init err code : " << i << std::endl;
254 std::cout << "Probabely non standard acquisition (extra loop not yet dealt with)" << std::endl;
259 std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;