]> Creatis software - creaBruker.git/blobdiff - lib/src1/brukerobjectvaryingproperties.cpp
Added CMake configuration to enable CDash tests.
[creaBruker.git] / lib / src1 / brukerobjectvaryingproperties.cpp
index 69ddf7f64ddf8778dbbe05af2dd50246c1bbf694..66af40deab0839f351a6cb96a7f83a10d173331d 100644 (file)
@@ -1,3 +1,29 @@
+/*
+       # ---------------------------------------------------------------------
+       #
+       # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
+       #                        pour la Santé)
+       # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+       # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+       # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+       #
+       #  This software is governed by the CeCILL-B license under French law and 
+       #  abiding by the rules of distribution of free software. You can  use, 
+       #  modify and/ or redistribute the software under the terms of the CeCILL-B 
+       #  license as circulated by CEA, CNRS and INRIA at the following URL 
+       #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+       #  or in the file LICENSE.txt.
+       #
+       #  As a counterpart to the access to the source code and  rights to copy,
+       #  modify and redistribute granted by the license, users are provided only
+       #  with a limited warranty  and the software's author,  the holder of the
+       #  economic rights,  and the successive licensors  have only  limited
+       #  liability. 
+       #
+       #  The fact that you are presently reading this means that you have had
+       #  knowledge of the CeCILL-B license and that you accept its terms.
+       # ------------------------------------------------------------------------
+*/
 //
 // C++ Implementation: brukerobjectvaryingproperties
 //
@@ -10,7 +36,7 @@
 //
 //
 #include "brukerobjectvaryingproperties.h"
-
+#include "brukerexception.h"
 
 
 BrukerObjectVaryingProperties::BrukerObjectVaryingProperties()
@@ -24,94 +50,105 @@ BrukerObjectVaryingProperties::~BrukerObjectVaryingProperties()
 
 
 
-void BrukerObjectVaryingProperties::setPositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
+void BrukerObjectVaryingProperties::computePositionS(std::map<std::string, BrukerFieldData> & BrukerHM){
    std::vector<double> PosiS =BrukerHM[(std::string) "ACQ_slice_offset"].GetDoubleValue();
    PositionS =PosiS;
 };
 
-void BrukerObjectVaryingProperties::setPositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
+void BrukerObjectVaryingProperties::computePositionR(std::map<std::string, BrukerFieldData> & BrukerHM){
    PositionR =BrukerHM[(std::string) "ACQ_read_offset"].GetDoubleValue() ;
 };
 
-void BrukerObjectVaryingProperties::setPositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
+void BrukerObjectVaryingProperties::computePositionP(std::map<std::string, BrukerFieldData> & BrukerHM){
    PositionP =BrukerHM[(std::string) "ACQ_phase1_offset"].GetDoubleValue();
 };
 
-void BrukerObjectVaryingProperties::setTE(std::map<std::string, BrukerFieldData> & BrukerHM){
+void BrukerObjectVaryingProperties::computeTE(std::map<std::string, BrukerFieldData> & BrukerHM){
    TE = BrukerHM[(std::string) "ACQ_echo_time"].GetDoubleValue();
 };
 
-double BrukerObjectVaryingProperties::getTE(int theValue) const{
-   if (theValue < TE.size() && theValue >=0) {return TE[theValue];}
-   else throw 0;
+double BrukerObjectVaryingProperties::getTE(unsigned int theValue) const{
+   if (theValue < TE.size() ) {return TE[theValue];}
+   //else throw 0;
+   else throw BrukerSizeException("TE", theValue, TE.size() ); 
 }
 
-/*void BrukerObjectVaryingProperties::setTE(const std::vector< double >& theValue)
+/*void BrukerObjectVaryingProperties::computeTE(const std::vector< double >& theValue)
 {
   TE = theValue;
 }*/
 
-double  BrukerObjectVaryingProperties::getPositionP(int theValue) const{
-   if (theValue < PositionP.size() && theValue >=0) return PositionP[theValue];
-   else throw 0;
+double  BrukerObjectVaryingProperties::getPositionP(unsigned int theValue) const{
+   if (theValue < PositionP.size() ) return PositionP[theValue];
+//   else throw 1;
+   else throw BrukerSizeException("PositionP", theValue, PositionP.size() );    
 }
   
-/*void BrukerObjectVaryingProperties::setPositionP(const std::vector< double >& theValue)
+/*void BrukerObjectVaryingProperties::computePositionP(const std::vector< double >& theValue)
 {
   PositionP = theValue;
 }*/
 
-double  BrukerObjectVaryingProperties::getPositionR(int theValue) const{
-   if (theValue < PositionR.size() && theValue >=0) return PositionR[theValue];
-   else throw 0;
+double  BrukerObjectVaryingProperties::getPositionR(unsigned int theValue) const{
+   if (theValue < PositionR.size() ) return PositionR[theValue];
+//   else throw 2;
+   else throw BrukerSizeException("PositionR", theValue, PositionR.size() );
 }
 
-/*void BrukerObjectVaryingProperties::setPositionR(const std::vector< double >& theValue)
+/*void BrukerObjectVaryingProperties::computePositionR(const std::vector< double >& theValue)
 {
   PositionP = theValue;
 }*/
 
-double  BrukerObjectVaryingProperties::getPositionS(int theValue) const{
-   if (theValue < PositionS.size() && theValue >=0)  return PositionS[theValue];
-   else throw 0;
+double  BrukerObjectVaryingProperties::getPositionS(unsigned int theValue) const{
+   if (theValue < PositionS.size() )  return PositionS[theValue];
+//   else throw 3;
+   else throw BrukerSizeException("PositionS", theValue, PositionS.size() );
 }
 
-/*void BrukerObjectVaryingProperties::setPositionS(const std::vector< double >& theValue)
+/*void BrukerObjectVaryingProperties::computePositionS(const std::vector< double >& theValue)
 {
   PositionP = theValue;
 }*/
 
-int  BrukerObjectVaryingProperties::getAcquisitionOrder(int theValue) const{
-   if (theValue <AcquisitionOrder.size() && theValue >=0)  return AcquisitionOrder[theValue];
-   else throw 0;
+int  BrukerObjectVaryingProperties::getAcquisitionOrder(unsigned int theValue) const{
+   if (theValue <AcquisitionOrder.size())  return AcquisitionOrder[theValue];
+   //else throw 4;
+   else throw BrukerSizeException("AcquisitionOrder", theValue, AcquisitionOrder.size() );
 }
 
-/*void BrukerObjectVaryingProperties::setAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
+/*void BrukerObjectVaryingProperties::computeAcquisitionOrder(const std::vector< int >& theValue1, const std::vector< int >& theValue2)
 {
    AcquisitionOrder.clear();
-   if (theValue1.size() != theValue2[3]*theValue2[1]) throw 0;
-   if (theValue2.size() < 4 ) throw 0;
+   if (theValue1.size() != theValue2[3]*theValue2[1]) throw 5;
+   if (theValue2.size() < 4 ) throw 6;
    for (int i =0 ;i<theValue2[3];i++)AcquisitionOrder.push_back()=(int) theValue1[i*theValue2[1]]/theValue2[1];
 }*/
 
-void BrukerObjectVaryingProperties::setAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
-   std::vector<int> AcqOrder;
-  if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) throw 0;
-  if (LoopStruct.size() < 4 ) throw 0;
+void BrukerObjectVaryingProperties::computeAcquisitionOrder(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
+  std::vector<int> AcqOrder;
+  
+  if (BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() != LoopStruct[3]*LoopStruct[1]) {
+     std::cout << "BrukerHM[(std::string) 'ACQ_obj_order'].GetIntValue().size() " << BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue().size() 
+               << " LoopStruct[3] : " << LoopStruct[3] << " * LoopStruct[1] : " << LoopStruct[1] << " = " << LoopStruct[3]*LoopStruct[1] << std::endl;  
+     throw 7;
+  }
+  if (LoopStruct.size() < 4 ) throw 8;
   for (int i =0 ;i<LoopStruct[3];i++)
      AcqOrder.push_back((int) BrukerHM[(std::string) "ACQ_obj_order"].GetIntValue()[i*LoopStruct[1]]/LoopStruct[1]);
   AcquisitionOrder=AcqOrder;
 };
 
-std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(int theValue) const{
-   if (theValue <Orientation.size() && theValue >=0)return Orientation[theValue];
-   else throw 0;
+std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOrientation(unsigned int theValue) const {
+   if (theValue < Orientation.size())return Orientation[theValue];
+   //else throw 9;
+   else throw BrukerSizeException("Orientation", theValue, Orientation.size() );
 }
 
-/*void BrukerObjectVaryingProperties::setOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
+/*void BrukerObjectVaryingProperties::computeOrientation( std :: vector < double > & theValue1,const std::vector< int >& theValue2)
 {
-   if (theValue1.size() != theValue2[3]*9) throw 0;
-   if (theValue2.size() < 4 ) throw 0;
+   if (theValue1.size() != theValue2[3]*9) throw 10;
+   if (theValue2.size() < 4 ) throw 11;
    int counter=0;
    for(int i=0;i<theValue2[3];i++){
       for(int j=0;j<3;j++){
@@ -123,10 +160,12 @@ std :: vector < std :: vector < double > >  BrukerObjectVaryingProperties::getOr
    }
 }*/
 
-void BrukerObjectVaryingProperties::setOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
-   if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 0;
-   if (LoopStruct.size() < 4 ) throw 0;
-
+void BrukerObjectVaryingProperties::computeOrientation(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
+   if (BrukerHM[(std::string) "ACQ_grad_matrix"].GetDoubleValue().size() != LoopStruct[3]*9) throw 12;
+   if (LoopStruct.size() < 4 ) 
+   //throw 13;
+      throw BrukerSizeException("LoopStruct", 4, LoopStruct.size() );
+      
    std::vector<double> Temp1D(3,0.0);
    std::vector<std::vector<double> > Temp2D;
    std::vector<std::vector<std::vector<double> > > Temp3D;
@@ -149,12 +188,12 @@ void BrukerObjectVaryingProperties::setOrientation(std::map<std::string, BrukerF
    Orientation=Temp3D;
 };
 
-double  BrukerObjectVaryingProperties::getPositionTimePerNR(int theValue) const{
-   if (theValue <PositionTimePerNR.size() && theValue >=0) return PositionTimePerNR[theValue];
-   else throw 0;
+double BrukerObjectVaryingProperties::getPositionTimePerNR(unsigned int theValue) const{
+   if (theValue <PositionTimePerNR.size() ) return PositionTimePerNR[theValue];
+   else throw 14;
 }
 
-void BrukerObjectVaryingProperties::setPositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
+void BrukerObjectVaryingProperties::computePositionTimePerNR(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct){
    double FloatPositionTimePerNR=BrukerHM[(std::string) "ACQ_repetition_time"].GetDoubleValue()[0];
    int i=0;
    int NA=BrukerHM[(std::string) "NA"].GetIntValue()[0];
@@ -162,8 +201,8 @@ void BrukerObjectVaryingProperties::setPositionTimePerNR(std::map<std::string, B
    double temp;
 
 /*
- les loop de 0 a  3 ne sont pas conceres par le temps car ils creent presque systematiquement
-un melange temporel des donnees, c'est pour cela que je ne calcule q'un temps moyen a  partir de celles -ci
+ les loop de 0 a  3 ne sont pas concernes par le temps car ils creent presque systematiquement
+ un melange temporel des donnees, c'est pour cela que je ne calcule qu'un temps moyen a  partir de celles -ci
 */
    for (i=4; i<(LoopStruct.size()-1);i++)
    { 
@@ -181,7 +220,7 @@ un melange temporel des donnees, c'est pour cela que je ne calcule q'un temps mo
 
    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=(LoopStruct.back()-1))
    {
-      throw 0;
+      throw 15;
    }
    if (BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()!=1&& BrukerHM[(std::string) "ACQ_temporal_delay"].GetDoubleValue().size()==(LoopStruct.back()-1))
    {
@@ -197,16 +236,30 @@ un melange temporel des donnees, c'est pour cela que je ne calcule q'un temps mo
 /*!
     \fn BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> BrukerHM,std::vector<int> LoopStruct)
  */
-bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> & BrukerHM, std::vector<int> & LoopStruct)
+bool BrukerObjectVaryingProperties::init(std::map<std::string, BrukerFieldData> &BrukerHM, std::vector<int> &LoopStruct)
 {
-   setAcquisitionOrder( BrukerHM, LoopStruct);
-   setOrientation(BrukerHM, LoopStruct);
-   setPositionP(BrukerHM);
-   setPositionR(BrukerHM);
-   setPositionS(BrukerHM);
-   setPositionTimePerNR(BrukerHM, LoopStruct);
-   setTE(BrukerHM);
-
+   try {
+      computeAcquisitionOrder (BrukerHM, LoopStruct);
+      computeOrientation      (BrukerHM, LoopStruct);
+      computePositionP        (BrukerHM);
+      computePositionR        (BrukerHM);
+      computePositionS        (BrukerHM);
+      computePositionTimePerNR(BrukerHM, LoopStruct);
+      computeTE               (BrukerHM);
+   }
+   catch (int i)
+   {
+      std::cout << "Failure during BrukerObjectVaryingProperties::init err code : " << i << std::endl;
+      if (i==7)
+         std::cout << "Probabely non standard acquisition (extra loop not yet dealt with)" << std::endl;
+      return false;   
+   }   
+   catch (...)
+   {
+      std::cout << "Failure during BrukerObjectVaryingProperties::init " << std::endl;
+      return false;
+   }
+   
    return true;
 }