]> Creatis software - creaBruker.git/blob - lib/src1/brukerdataset.cpp
936696ee87ea3074d14e42dfbf0a44fc54f260fe
[creaBruker.git] / lib / src1 / brukerdataset.cpp
1 //
2 // C++ Implementation: brukerdataset
3 //
4 // Description: 
5 //
6 //
7 // Author:  <Denis Grenier>, (C) 2008
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13
14 #define DEBUG 0
15
16 #include "brukerdataset.h"
17
18 BrukerDataSet::BrukerDataSet(){}
19
20
21 BrukerDataSet::~BrukerDataSet(){}
22
23
24 bool BrukerDataSet::LoadFile(std::string fileToRead)
25 {
26
27 //std::cout <<
28 //"------------- BrukerDataSet::LoadFile() Open : [" << fileToRead << "]" << std::endl;
29   std::ifstream FID;
30   char * buffer;
31   FID.open(fileToRead.c_str(), std::ios::binary);
32   if (FID.rdstate()==std::ios::failbit) {
33     //std::cout << "BrukerDataSet::LoadFile() Cannot open : [" << fileToRead << "]" << std::endl;
34     return false;
35   }
36   
37   FID.seekg (0, std::ios::end);
38   int length = FID.tellg();
39   FID.seekg (0, std::ios::beg);
40
41   buffer = new char [length];
42   FID.read (buffer,length);
43   FID.close();
44   BrukerDataSet::WholeHeader=buffer;
45   delete [] buffer;
46   return true;
47 }
48
49
50
51 std::string BrukerDataSet::SearchBufferForText(std::string& file, const boost::regex& RegExp)
52 {
53   boost::cmatch what;
54   if (regex_search(file.c_str(), what, RegExp)) 
55     return what[1];
56   return "";
57 }
58
59
60 /**
61  * 
62  * @param file 
63  * @param RegExp 
64  * @return bool
65  */
66 bool BrukerDataSet::BoolMatchBufferForText(std::string& file, const boost::regex& RegExp)
67 {
68   boost::cmatch what;
69   if (regex_match(file.c_str(), what, RegExp)) 
70   return true;
71   return false;
72 }
73
74 std::string BrukerDataSet::RemoveNewlines(std::string file)
75 {
76     boost::regex regexNewline;
77   const char* pre_expression = "[[:cntrl:]]";
78    regexNewline.assign(pre_expression);
79
80   const char* pre_format = "";
81   std::ostringstream t(std::ios::out | std::ios::binary);
82       std::ostream_iterator<char, char> oi(t);
83   boost::regex_replace(oi, file.begin(), file.end(),
84       regexNewline, pre_format, boost::match_default | boost::format_all);
85       std::string s(t.str());
86       return s;
87  }
88  
89 std::string BrukerDataSet::RemoveSpaces(std::string file)
90 {
91     boost::regex regexSpace;
92   const char* pre_expression = "[[:space:]]";
93    regexSpace.assign(pre_expression);
94
95   const char* pre_format = "";
96   std::ostringstream t(std::ios::out | std::ios::binary);
97       std::ostream_iterator<char, char> oi(t);
98   boost::regex_replace(oi, file.begin(), file.end(),
99       regexSpace, pre_format, boost::match_default | boost::format_all);
100       std::string s(t.str());
101       return s;
102  }
103
104  
105  
106
107 std::string BrukerDataSet::MatchBufferForText(std::string& file,const boost::regex& RegExp)
108 {
109   boost::cmatch what;
110   if (regex_match(file.c_str(), what, RegExp)) 
111     return what[1];
112   return "";
113 }
114
115
116
117 std::string BrukerDataSet::GetKeyword(std::string& file)
118 {
119   return MatchBufferForText( file,KeyWord);
120 }
121
122
123
124 int BrukerDataSet::GetDimensionnality(std::string& file)
125 {
126   int iterator=0;
127   std::string DimensionnalityBuffer=SearchBufferForText(file,Dimensionnality);
128   if (DimensionnalityBuffer=="") 
129     return iterator;
130   boost::match_results<std::string::const_iterator> what;
131   boost::match_flag_type flags= boost::match_default;
132   std::string::const_iterator start,end;
133   start=DimensionnalityBuffer.begin();
134   end=DimensionnalityBuffer.end();
135
136   while (regex_search(start, end, what, UnsignedInteger))
137   {
138     iterator++;
139     start=what[0].second;
140     flags |= boost::match_prev_avail;
141     flags |= boost::match_not_bob;
142   }
143   return iterator;
144 }
145
146
147
148 int BrukerDataSet::GetIntValueOfDimN(std::string& file, int N)
149 {
150   int iterator=0;
151   std::string DimensionnalityBuffer=SearchBufferForText(file,Dimensionnality);
152   if (N < 1 || DimensionnalityBuffer=="") 
153     return 0;
154   //std::cout << DimensionnalityBuffer << std::endl;
155   boost::match_results<std::string::const_iterator> what;
156   boost::match_flag_type flags= boost::match_default;
157   std::string::const_iterator start,end;
158   start=DimensionnalityBuffer.begin();
159   end=DimensionnalityBuffer.end();
160
161   for (int i=1;i<=N;i++)
162   {
163     regex_search(start,end, what, UnsignedInteger);
164     iterator++;
165     start=what[0].second;
166     flags |= boost::match_prev_avail;
167     flags |= boost::match_not_bob;
168   }
169   return atoi(std::string(what[1].first,what[1].second).c_str());
170 }
171
172
173
174 std::string BrukerDataSet::GetValuesPart(std::string& file)
175 {
176   std::string Result;
177   Result=MatchBufferForText(file,BufferNValues);
178   if (Result !="")   
179   return RemoveNewlines(Result);
180   return MatchBufferForText(file,Buffer1Value);
181 }
182
183
184 std::string BrukerDataSet::GetContentType(std::string& file)
185 {
186   std::string ValuesPart;
187    boost::match_flag_type flags = boost::match_default; 
188    std::string::const_iterator start, end;
189   ValuesPart=GetValuesPart(file);
190   start=ValuesPart.begin();
191   end=ValuesPart.end();
192   // boost regexp_match can not handle well what we want
193   // so instead of looking for a match we will seek proof of a non int serie
194   // i.e. check if we can find something else than than -0-9
195    boost::regex isNotIntSerie("[^ \\-0-9]");
196    boost::match_results<std::string::const_iterator> whatInt;
197    if (!regex_search(start,end, whatInt, isNotIntSerie,flags)) 
198      return "int";
199    
200    // if not int serie check if it's not a floats serie !!!
201    
202    boost::regex isNotFloatSerie("[^ \\-\\+\\.eE0-9]");
203    boost::match_results<std::string::const_iterator> whatFloat;
204    if (!regex_search(start,end, whatFloat, isNotFloatSerie,flags))
205      return "float";
206    
207      // if not a float serie neither, it's a string !!!
208   return "string"; 
209 }
210
211
212
213 int BrukerDataSet::GetIntValueN(std::string& file,int N)
214 {
215   std::string ValuesPart=GetValuesPart(file);
216   int iterator=0;
217   if (N < 1 || ValuesPart=="") 
218     return -32767;
219     
220   boost::match_results<std::string::const_iterator> what;
221   boost::match_flag_type flags= boost::match_default;
222   std::string::const_iterator start,end;
223   start=ValuesPart.begin();
224   end=ValuesPart.end();
225
226   while (iterator != N)
227   {
228     regex_search(start,end, what, SignedInteger);
229     iterator++;
230     start=what[0].second;
231     flags |= boost::match_prev_avail;
232     flags |= boost::match_not_bob;
233   }
234   return (atoi((std::string(what[1].first,what[1].second)).c_str()));
235 }
236
237
238
239 double BrukerDataSet::GetDoubleValueN(std::string& file, int N)
240 {
241   std::string ValuesPart=GetValuesPart(file);
242   int iterator=0;
243   if (N < 1 || ValuesPart=="") 
244     return 0;
245   boost::match_results<std::string::const_iterator> what;
246   boost::match_flag_type flags= boost::match_default;
247   std::string::const_iterator start,end;
248   start=ValuesPart.begin();
249   end=ValuesPart.end();
250
251   while (iterator != N)
252   {
253     regex_search(start,end, what, IntOrFloat);
254     iterator++;
255     start=what[0].second;
256     flags |= boost::match_prev_avail;
257     flags |= boost::match_not_bob;
258   }
259   return (atof((std::string(what[1].first,what[1].second)).c_str()));
260 }
261
262
263
264 std::string BrukerDataSet::GetTextValueN(std::string& file, int N)
265 {
266   return GetValuesPart(file);
267 }
268
269
270
271 int BrukerDataSet::GetKeywordNumberOfElements(std::string& file)
272 {
273   int NumberOfElements=1;
274   for (int i=1;i<=GetDimensionnality(file);i++)
275       NumberOfElements*=GetIntValueOfDimN(file, i);
276   return NumberOfElements;
277 }
278
279
280  
281 /**
282  * 
283 @fn bool BrukerDataSet::FillMap()
284 @brief This method fills the Bruker headermap with everything contained in the acqp file
285
286 The map is made of BrukerFieldData containing the keywords:
287 Datatype (string, int, double)
288 DimensionNumber: The number of Dimensions of the keyword-> 0 scalar, 1-> 1D-vector, 2-> 2D-Matrix, 3->3D-Matrix, ...
289 DimensionNumberValue: Gives the size of each dimension
290 DoubleValue: return a vector of values if they are of type double
291 IntValue: return a vector of values if they are of type int
292 StringValue: return a string if the values where not identified as a serie of numbers
293 NumberOfElements: Number of elements corresponding to the keyword given
294  * @return bool
295  */
296 bool BrukerDataSet::FillMap()
297 {
298   
299   std::string ValuesBuffer, Keyword,TempString, Substring;
300   int   i;
301   int KeywordNumber=0;
302   int PositionDebut=WholeHeader.find("##");
303   int PositionFin=PositionDebut+2; 
304   int PosRel;
305   BrukerFieldData data;
306   if (PositionFin>=WholeHeader.length()) 
307     return false;
308
309   while(PositionDebut!=std::string::npos)
310   {
311     PositionFin=WholeHeader.find("##",PositionDebut+2);
312     if (-1 == PositionFin) break ;
313     Substring=WholeHeader.substr (PositionDebut,PositionFin-PositionDebut-1);
314     PosRel=Substring.find("$$",0);
315     if (-1 != PosRel) Substring=Substring.substr (0,PosRel-1);
316
317
318     if (DEBUG) std::cout<<"Substring=[" << Substring << "]" <<std::endl;
319     
320     PositionDebut=PositionFin;
321     Keyword=GetKeyword(Substring);
322     if (DEBUG) std::cout<<"Keyword="<< Keyword <<std::endl;
323     data.DimensionNumber=GetDimensionnality(Substring);
324     if (DEBUG) std::cout<<"data.DimensionNumber="<< data.DimensionNumber <<std::endl;
325
326     data.DataType=GetContentType(Substring);
327     if (DEBUG) std::cout<<"data.DataType="<< data.DataType <<std::endl;
328     data.NumberOfElements=GetKeywordNumberOfElements(Substring);
329  if(data.DataType=="string") 
330       data.DimensionNumber=0;
331     if(data.DataType=="string") 
332       data.NumberOfElements=1;
333     if (DEBUG) std::cout<<"data.NumberOfElements="<< data.NumberOfElements <<std::endl;
334     
335     i=0;
336     while (i<=data.DimensionNumber)
337     {
338       data.DimensionNumberValue.push_back(GetIntValueOfDimN(Substring,i));
339       if (DEBUG) std::cout<<"data.DimensionNumberValue["<<i<<"]="<< data.DimensionNumberValue[i] <<std::endl;
340       i++;
341     }
342
343     if (DEBUG) std::cout<< "data= ";
344
345     for(i =1;i<=data.NumberOfElements;i++)
346     {
347
348       if (data.DataType=="int") 
349       { 
350         data.IntValue.push_back(GetIntValueN(Substring,i));
351         data.DoubleValue.push_back((double) GetIntValueN(Substring,i));
352         if (DEBUG) std::cout<< data.IntValue[i-1]<<" ";
353       }
354
355       if (data.DataType=="float") 
356       { 
357         data.DoubleValue.push_back(GetDoubleValueN(Substring,i));
358         if (DEBUG) std::cout<< data.DoubleValue[i-1]<<" ";
359       }
360     }
361
362     if (data.DataType=="string")
363     { 
364       data.StringValue.push_back(GetTextValueN(Substring,0));
365       if (DEBUG) std::cout<< "[" << data.StringValue[0]<<"] ";
366     }
367
368      if (DEBUG) std::cout<< std::endl  << "---- " <<std::endl;
369
370     BrukerDataSet::BrukerHeaderMap[ Keyword ] = data;
371     data.DimensionNumberValue.clear();
372     data.IntValue.clear();
373     data.DoubleValue.clear();
374     data.StringValue.clear();
375     data.DataType.clear();
376     KeywordNumber++;
377     //std::cout<<std::endl;
378   }
379   return true;
380 }
381
382
383 void BrukerDataSet::PrintKey(std::string & KeyWord)
384 {
385   int i;
386   if(!BrukerDataSet::CheckExistKeyword(KeyWord))
387   { 
388     std::cout<< "KeyWord = "<<KeyWord <<" doesn't exist !"<<std::endl;
389   }
390   else
391   {
392     std::cout<< "KeyWord = "<<KeyWord <<std::endl;    
393     BrukerDataSet::BrukerHeaderMap[ KeyWord ].PrintSelf();
394
395   }
396 }
397
398
399
400 void BrukerDataSet::PrintSelf()
401 {
402    BrukMapType::iterator it;
403    for (it=  BrukerHeaderMap.begin();
404          it !=  BrukerHeaderMap.end();
405        ++it )
406     {
407        std::cout << std::endl << "-----------------[" <<(*it).first << "]" << std::endl;
408        std::string a =  (*it).first;
409        PrintKey(a);
410     } 
411 }
412
413
414 bool BrukerDataSet::CheckExistKeyword(std::string &KeyWord)
415 {
416  BrukMapType::iterator element;
417   element = BrukerHeaderMap.find(KeyWord);
418   if (element != BrukerHeaderMap.end() )
419     return true;
420   return false;
421 }
422
423 bool BrukerDataSet::CheckExistKeyword(const char *KeyWord)
424 {
425 std::string temp(KeyWord);
426 BrukerDataSet::CheckExistKeyword(temp);
427     return true;
428 }
429
430
431 const BrukerFieldData& BrukerDataSet::GetFieldData(std::string & kw)
432 {
433    return BrukerHeaderMap[kw];
434 }
435
436 const BrukerFieldData& BrukerDataSet::GetFieldData(const char *kw)
437 {
438    std::string str_kw(kw);
439    return BrukerHeaderMap[str_kw];
440 }    
441
442
443 bool BrukerDataSet::Getkspace(std::string &FileToRead)
444 {
445   std::string GO_raw_data_format("GO_raw_data_format");
446   if (!CheckExistKeyword(GO_raw_data_format))
447     return false;
448   std::ifstream FID;
449
450   FID.open(FileToRead.c_str(), std::ios::binary);
451   if (FID.rdstate()==std::ios::failbit) 
452     return false;
453   FID.seekg (0, std::ios::end);
454   long length = FID.tellg();
455   FID.seekg (0, std::ios::beg);
456   long NumberOfValues;
457
458
459   if (GetTextValueN(GO_raw_data_format,1)=="GO_32BIT_SGN_INT") 
460     NumberOfValues=length/4;
461   if (GetTextValueN(GO_raw_data_format,1)=="GO_16BIT_SGN_INT") 
462     NumberOfValues=length/2;
463   if (GetTextValueN(GO_raw_data_format,1)=="GO_32BIT_FLOAT") 
464     NumberOfValues=length/4;
465
466   char * buffer;
467   buffer = new char[length];
468
469   FID.read (buffer,length);
470   FID.close();
471 //for (long i=0;i<NumberOfValues;i++) BrukerDataSet::WholeKspace.pushback(buffer[i]);
472   delete [] buffer;
473   return true;
474 }
475
476
477 std::vector< int > BrukerDataSet::GetLoopStructure() const
478 {
479    return LoopStructure;
480 }
481
482 /**
483     @fn bool BrukerDataSet::SetLoopStructure (const std::vector<int> & theValue )
484  * @brief this methods provide a way to inject a userdefined loop structure, be very aware that this method is not foolproof
485  * @param theValue 
486  * @return bool
487  */
488 bool BrukerDataSet::SetLoopStructure ( const std::vector<int> & theValue )
489 {
490    LoopStructure = theValue;
491    return true;
492 }
493
494
495 /**
496    @fn bool BrukerDataSet::SetLoopStructureOld ( )
497  * @brief method to set the default Bruker loopstructure (not yet able to deal with EPI, SPIRAL or spectroscopic experiments 
498  * @return bool
499  * @todo  implement multicoil version
500  */
501 bool BrukerDataSet::SetLoopStructureOld ()
502 {
503    LoopStructure.clear();
504 /*
505 \file brukerdataset.cpp
506 \fn bool BrukerDataSet::setGenericLoopStructure ( )
507 \brief sets the loop structure of a standard Bruker experiment
508
509 NR                               (Nbre de repetitions)
510    NILoop                        (Boucle eventuelle extra (Diffusion par exemple) si NI<>(NSLICES x NECHOES) cette boucle est a� NI/(NSLICES x NECHOES)
511                                  (Attention NILoop peut masquer plusieurs boucles imbriquees !!!!!)
512       ACQ_size[1..M]             (Codage suivant les autres dimensions)
513          NSLICES                 (Nombre de tranches)
514             ACQ_phase_factor     (Facteur turbo de la sequence)
515                ACQ_ns_list_size  (Nombre d'echos)
516                   ACQ_size[0]    (Ligne acq reelle)
517
518 */
519
520
521    std::string NRStr("NR");
522    std::string NIStr("NI");
523    std::string ACQ_sizeStr("ACQ_size");
524    std::string ACQ_phase_factorStr("ACQ_phase_factor");
525    std::string ACQ_ns_listStr("ACQ_ns_list");
526    std::string ACQ_ns_list_sizeStr("ACQ_ns_list_size");
527    std::string NSLICESStr("NSLICES");
528
529    int  i, temp;
530    std::vector<int> TempIntVect;
531    TempIntVect.clear();
532
533    if (! CheckExistKeyword(NRStr))              return false;
534    if (! CheckExistKeyword(NIStr))              return false;
535    if (! CheckExistKeyword(ACQ_sizeStr))        return false;
536    if (! CheckExistKeyword(ACQ_phase_factorStr))return false;
537    if (! CheckExistKeyword(ACQ_ns_list_sizeStr))return false;
538    if (! CheckExistKeyword(NSLICESStr))         return false;
539
540    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[0]);
541    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_ns_list_size"].IntValue[0]);
542    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0]);
543    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "NSLICES"].IntValue[0]);
544    if (1<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber ){
545       TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[1]/BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0]);
546    if (2<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber )
547    {
548       for(i=2;i<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber;i++) 
549       {
550          TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[i]);
551       }
552    }
553 }
554 // Ici, boucles additionnelles si elles existent regroupees en une seule
555 //temp=GetIntValueN(NIStr,1)/(GetIntValueN(NSLICESStr,1)*GetIntValueN(NECHOESStr,1));
556    temp=BrukerDataSet::BrukerHeaderMap[ (std::string)  "NI" ].IntValue[0]/(BrukerDataSet::BrukerHeaderMap[ (std::string)  "NSLICES" ].IntValue[0]*BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_ns_list_size" ].IntValue[0]);
557    if (1 < temp) 
558       TempIntVect.push_back(temp);
559 // fin des boucles cachees
560
561    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "NR" ].IntValue[0]);
562
563    LoopStructure=TempIntVect;
564    return true;
565 }
566
567
568 /**
569    @fn bool BrukerDataSet::SetLoopStructure ( )
570  * @brief method to set the default Bruker loopstructure (not yet able to deal with EPI, SPIRAL or spectroscopic experiments 
571  * @return bool
572    @todo  implement multicoil version
573  */
574 bool BrukerDataSet::SetLoopStructure ()
575 {
576    if (! SetInnerObjectLoopStructure()) return false;
577    if (! SetOuterObjectLoopStructure()) return false;
578    std::vector<int> Inner=GetInnerObjectLoopStructure();
579    std::vector<int> Outer=GetOuterObjectLoopStructure();
580    std::vector<int> TmpVect;
581    TmpVect=Inner;
582    TmpVect.insert(TmpVect.end(),Outer.begin(),Outer.end());
583    LoopStructure=TmpVect;
584    return true;
585 }
586
587 std::vector< std :: vector < int > > BrukerDataSet::GetBrukerObjectsLineList() const
588 {
589    return BrukerObjectsLineList;
590 }
591
592
593 bool BrukerDataSet::SetBrukerObjectsLineList ()
594 {
595
596    std::vector<int> Loop =GetLoopStructure();
597    int NumberOfLines, i,j;
598    NumberOfLines=1; 
599    i=1;
600
601    while (i<Loop.size())
602    {
603       NumberOfLines=NumberOfLines*Loop[i];
604       i++;
605    }
606
607    std::vector<int> TempVect  (Loop.size()-1,0);
608    std::vector<int> k  (Loop.size()-1,0);
609    std::vector<std::vector<int> > TempLineList (NumberOfLines,TempVect);
610
611    for (i=0;i<NumberOfLines;i++){
612       for (j=1;j<=Loop.size()-1;j++) {
613          if (k[j-1] >= Loop[j]) {
614             k[j-1]=0;
615             k[j]++;
616          }
617       }
618       for (j=1;j<=Loop.size()-1;j++) 
619          TempLineList[i][j-1]=k[j-1];
620       k[0]++;
621    }
622    BrukerObjectsLineList=TempLineList;
623    return true;
624 }
625
626
627 std::vector< std::vector < int > > BrukerDataSet::GetBrukerImageList() const
628 {
629    return BrukerImageList;
630 }
631
632
633 bool BrukerDataSet::SetBrukerImageList ()
634 {
635    if (LoopStructure.size()==0)
636       SetImageLoopStructure();
637
638    std::vector<int> Loop =GetImageLoopStructure();
639    int NumberOfLines, i,j;
640    NumberOfLines=1; 
641    i=1;
642
643    while (i<Loop.size())
644    {
645       NumberOfLines=NumberOfLines*Loop[i];
646       i++;
647    }
648
649    std::vector<int> TempVect (Loop.size()-1,0);
650    std::vector<int> k (Loop.size()-1,0);
651    std::vector<std::vector<int> > TempLineList (NumberOfLines,TempVect);
652
653    for (i=0;i<NumberOfLines;i++){
654       for (j=1;j<=Loop.size()-1;j++) {
655          if (k[j-1] >= Loop[j]) {
656             k[j-1]=0;
657             k[j]++;
658          }
659       }
660       for (j=1;j<=Loop.size()-1;j++) 
661          TempLineList[i][j-1]=k[j-1];
662       k[0]++;
663    }
664    BrukerImageList=TempLineList;
665    return true;
666 }
667
668
669
670 std::map<std::string, BrukerFieldData> BrukerDataSet::GetBrukerHeaderMap() const
671 {
672    return BrukerHeaderMap;
673 }
674
675
676
677
678 //std::map<std::string, BrukerFieldData> BrukerDataSet::GetBrukerHeaderMap() const
679 //{
680 //   return BrukerHeaderMap;
681 //}
682
683
684 bool BrukerDataSet::SetInnerObjectLoopStructure()
685 {
686 /*
687  *
688  *
689  *      ACQ_size[1..M]                                  (Codage suivant les autres dimensions)
690                 NSLICES                                 (Nombre de tranches)
691                         ACQ_phase_factor                (Facteur turbo de la sequence)
692                                 ACQ_ns_list_size        (Nombre d'echos)
693                                         ACQ_size[0]     (Ligne acq reelle)
694
695 */
696
697    int  i, temp;
698    std::vector<int> TempIntVect;
699    TempIntVect.clear();
700
701
702    if (! CheckExistKeyword("ACQ_size"))        return false;
703    if (! CheckExistKeyword("ACQ_phase_factor"))return false;
704    if (! CheckExistKeyword("ACQ_ns_list_size"))return false;
705    if (! CheckExistKeyword("NSLICES"))         return false;
706
707
708 //std::cout<< "BrukerDataSet::BrukerHeaderMap[ (std::string)  ACQ_size ].IntValue[0]" <<BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[0] << std::endl;
709    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[0]);
710 //std::cout<< "BrukerDataSet::BrukerHeaderMap[ (std::string)  ACQ_size ].IntValue[0]" <<BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[0] << std::endl;
711    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_ns_list_size"].IntValue[0]);
712 //std::cout<<"BrukerDataSet::BrukerHeaderMap[(std::string)  ACQ_ns_list_size].IntValue[0]" << BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_ns_list_size"].IntValue[0] << std::endl;
713    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0]);
714 //std::cout<<"BrukerDataSet::BrukerHeaderMap[(std::string)  ACQ_phase_factor].IntValue[0]" <<  BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0]<< std::endl;
715    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[(std::string)  "NSLICES"].IntValue[0]);
716 //std::cout << "BrukerDataSet::BrukerHeaderMap[(std::string)  NSLICES].IntValue[0]" << BrukerDataSet::BrukerHeaderMap[(std::string)  "NSLICES"].IntValue[0] << std::endl;
717    if (1<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber )
718    {
719       TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[1]/BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0]);
720 //std::cout << "BrukerDataSet::BrukerHeaderMap[ (std::string)  ACQ_size ].IntValue[1]/BrukerDataSet::BrukerHeaderMap[(std::string)  ACQ_phase_factor].IntValue[0]" << BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size"
721 //].IntValue[1]/BrukerDataSet::BrukerHeaderMap[(std::string)  "ACQ_phase_factor"].IntValue[0] << std::endl;
722       if (2<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber )
723       {
724          for(i=2;i<=BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].DimensionNumber;i++) 
725          {
726             TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_size" ].IntValue[i]);
727          }
728       }
729    }
730
731    InnerObjectLoopStructure=TempIntVect;
732    return true;
733 }
734
735
736 std::vector< int > BrukerDataSet::GetInnerObjectLoopStructure() const
737 {
738    return InnerObjectLoopStructure;
739 }
740
741 std::vector< int > BrukerDataSet::GetOuterObjectLoopStructure() const
742 {
743    return OuterObjectLoopStructure;
744 }
745
746
747 bool BrukerDataSet::SetOuterObjectLoopStructure ()
748 {
749    OuterObjectLoopStructure.clear();
750    /*
751     NR      (Nbre de repetitions)
752     NILoop  (Boucle eventuelle extra (Diffusion par exemple) si NI<>(NSLICES x NECHOES) cette boucle est a� NI/(NSLICES x NECHOES)
753        (Attention NILoop peut masquer plusieurs boucles imbriquees !!!!!)
754   */
755    int  temp;
756    std::vector<int> TempIntVect;
757    TempIntVect.clear();
758    if (! CheckExistKeyword("NR")) return false;
759    if (! CheckExistKeyword("NI"))  return false;
760 // Ici, boucles additionnelles si elles existent regroupees en une seule
761 //temp=GetIntValueN(NIStr,1)/(GetIntValueN(NSLICESStr,1)*GetIntValueN(NECHOESStr,1));
762    temp=BrukerDataSet::BrukerHeaderMap[ (std::string)  "NI" ].IntValue[0]/(BrukerDataSet::BrukerHeaderMap[ (std::string)  "NSLICES" ].IntValue[0]*BrukerDataSet::BrukerHeaderMap[ (std::string)  "ACQ_ns_list_size" ].IntValue[0]);
763    if (1 < temp) 
764       TempIntVect.push_back(temp);
765 // fin des boucles cachees
766    TempIntVect.push_back(BrukerDataSet::BrukerHeaderMap[ (std::string)  "NR" ].IntValue[0]);
767    OuterObjectLoopStructure=TempIntVect;
768    return true;
769 }
770
771
772 std::vector< int > BrukerDataSet::GetImageLoopStructure() const
773 {
774    return ImageLoopStructure;
775 }
776
777
778 bool BrukerDataSet::SetImageLoopStructure ( )
779 {
780    ImageLoopStructure.clear();
781    std::vector<int> TempIntVect1=GetInnerObjectLoopStructure();
782    std::vector<int> TempIntVect2=GetOuterObjectLoopStructure();
783    std::vector<int> TempIntVect3(TempIntVect1.size(),1);
784    std::vector<int> TempIntVect4;
785    TempIntVect3[1]=TempIntVect1[1];
786    TempIntVect3[3]=TempIntVect1[3];
787    TempIntVect4=TempIntVect3;
788    TempIntVect4.insert(TempIntVect4.end(),TempIntVect2.begin(),TempIntVect2.end());
789    ImageLoopStructure = TempIntVect4;
790    return true;
791 }
792