]> Creatis software - gdcm.git/commitdiff
ENH: Refactorize code, from PrintFile into the class, to allow user to reuse the...
authormalaterre <malaterre>
Sat, 1 Oct 2005 19:39:14 +0000 (19:39 +0000)
committermalaterre <malaterre>
Sat, 1 Oct 2005 19:39:14 +0000 (19:39 +0000)
Example/PrintFile.cxx
Testing/TestPrintAllDocument.cxx
src/gdcmOrientation.cxx
src/gdcmOrientation.h

index 3cdfabf980e219a288df5859d7c582649dd4c9a6..f1868e72b3c550ae0e176673b980a1abd263f5d9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PrintFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/09/30 17:42:17 $
-  Version:   $Revision: 1.60 $
+  Date:      $Date: 2005/10/01 19:39:14 $
+  Version:   $Revision: 1.61 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -207,21 +207,6 @@ int main(int argc, char *argv[])
 
    // ----------- End Arguments Manager ---------
 
-   std::string tabOrientation[13] = { 
-       "Not Applicable",
-       "Axial",
-       "Coronal",
-       "Sagital",
-       "Heart Axial",
-       "Heart Coronal",
-       "Heart Sagital",
-       "Axial invert",
-       "Coronal invert",
-       "Sagital invert",
-       "Heart Axial invert",
-       "Heart Coronal invert",
-       "Heart Sagital invert"
-   };
  
    if (ddict)
    {
@@ -353,13 +338,10 @@ int main(int argc, char *argv[])
            strImageOrientationRET     != gdcm::GDCM_UNFOUND )
       {
   
-         double orient = o.TypeOrientation( f );
-         int k = (int)orient;
-         if (k < 0) 
-            k = -k + 6;
+         gdcm::OrientationType orient = o.GetOrientationType( f );
  
          std::cout << "TypeOrientation = " << orient << " (-> " 
-                   << tabOrientation[k] << " )" << std::endl;
+                   << o.GetOrientationTypeString(orient) << " )" << std::endl;
       }
 
       std::string ori = o.GetOrientation ( f );
@@ -521,13 +503,10 @@ int main(int argc, char *argv[])
          if (ori != gdcm::GDCM_UNFOUND )
             std::cout << "- Orientation [" << ori << "]" << std::endl;
 
-         double d = o.TypeOrientation( f );
-         int k = (int)d;
-         if (k < 0) 
-            k = -k + 6;
+         gdcm::OrientationType d = o.GetOrientationType( f );
  
          std::cout << "TypeOrientation = " << d << " (-> " 
-                   << tabOrientation[k] << std::endl;
+                   << o.GetOrientationTypeString(d) << std::endl;
         
          if (f->IsReadable())
             std::cout <<std::endl<<it->c_str()<<" is Readable"<<std::endl;
index 31ce5c9dae3db27882962e8790f04d0837059ec8..26af718ebb4856a4c7e15e47b8ce487afd1215a7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestPrintAllDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/09/16 17:19:24 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2005/10/01 19:39:15 $
+  Version:   $Revision: 1.8 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -104,7 +104,7 @@ int TestPrintAllDocument(int, char *[])
       if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND )
       {
          gdcm::Orientation o;
-         double orient = o.TypeOrientation( f );
+         gdcm::OrientationType orient = o.GetOrientationType( f );
          std::cout << " ---------------------- Orientation " << orient
                    << std::endl;
       }
index 47fd0b2789a543e896485cd4b4771573053df808..5516c6bd857207d99974677418d8d7a36fb630a9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmOrientation.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/09/30 17:45:01 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2005/10/01 19:39:16 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -51,21 +51,42 @@ namespace gdcm
  *   #   6 : Heart Sagital
  *   #  -6 : Heart Sagital invert
  */
-double Orientation::TypeOrientation( File *f )
+
+static const char  *OrientationTypeStrings[] = { 
+  "Not Applicable",
+  "Axial",
+  "Coronal",
+  "Sagital",
+  "Heart Axial",
+  "Heart Coronal",
+  "Heart Sagital",
+  "Axial invert",
+  "Coronal invert",
+  "Sagital invert",
+  "Heart Axial invert",
+  "Heart Coronal invert",
+  "Heart Sagital invert",
+  NULL
+};
+
+const char* Orientation::GetOrientationTypeString(OrientationType const o)
+{
+  int k = (int)o;
+  if (k < 0) 
+       k = -k + 6;
+
+  return OrientationTypeStrings[k];
+}
+
+OrientationType Orientation::GetOrientationType( File *f )
 {
    float iop[6];
    bool succ = f->GetImageOrientationPatient( iop );
    if ( !succ )
    {
-      gdcmErrorMacro( "No Image Orientation (0020,0037) found in the file, cannot proceed." )
-      return 0;
+      gdcmErrorMacro( "No Image Orientation (0020,0037)/(0020,0032) found in the file, cannot proceed." )
+      return NotApplicable;
    }
-/*
-std::cout << " iop : ";
-for(int i=0;i<6;i++)
-   std::cout << iop[i] << "  ";
-std::cout << std::endl;
-*/
    vector3D ori1;
    vector3D ori2;
 
@@ -103,18 +124,8 @@ std::cout << std::endl;
        res=VerfCriterion(  i, CalculLikelyhood2Vec(refA,refB,ori1,ori2), res );
        res=VerfCriterion( -i, CalculLikelyhood2Vec(refB,refA,ori1,ori2), res );
    }
-   return res.first;
-/*
-//  i=0
-//  res=[0,99999]  ## [ <result> , <memory of the last succes calculus> ]
-//  for plane in dicPlane:
-//      i=i+1
-//      refA=plane[0]
-//      refB=plane[1]
-//      res=self.VerfCriterion(  i , self.CalculLikelyhood2Vec(refA,refB,ori1,ori2) , res )
-//      res=self.VerfCriterion( -i , self.CalculLikelyhood2Vec(refB,refA,ori1,ori2) , res )
-//  return res[0]
-*/
+   gdcmAssertMacro( res.first <= 6 && res.first >= -6);
+   return (OrientationType)res.first;
 }
 
 Res 
@@ -131,16 +142,6 @@ Orientation::VerfCriterion(int typeCriterion, double criterionNew, Res const &in
    res.first  = type;
    res.second = criterion;
    return res;
-/*
-//   type = res[0]
-//   criterion = res[1]
-// #     if criterionNew<0.1 and criterionNew<criterion:
-//   if criterionNew<criterion:
-//      criterion=criterionNew
-//      type=typeCriterion
-//   return [ type , criterion ]
-*/
-
 } 
 
 inline double square_dist(vector3D const &v1, vector3D const &v2)
index 7a69aa101dacf9ccfdf537b7434f1acb0a717b95..1fa4b8a6e1d8ad7546a467791bbafd66599a860c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmOrientation.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/01 15:51:42 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2005/10/01 19:39:16 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -76,15 +76,33 @@ class File;
  * You'll probabely have 3 letters for X axis and  Y axis, and the image remains *perfectly* sagital !
  * The values are given within the 'imager referential', better than within the 'Patient Referential' ...
  */
+typedef enum {
+   NotApplicable = 0,
+   Axial = 1,
+   AxialInvert = -1,
+   Coronal = 2,
+   CoronalInvert = -2,
+   Sagital = 3,
+   SagitalInvert = -3,
+   HeartAxial = 4,
+   HeartAxialInvert = -4,
+   HeartCoronal = 5,
+   HeartCoronalInvert = -5,
+   HeartSagital = 6,
+   HeartSagitalInvert = -6
+} OrientationType;
+
 class GDCM_EXPORT Orientation : public Base
 {
 public:
   Orientation() {}
   ~Orientation() {}
 
-  double TypeOrientation( File *file );
+  OrientationType GetOrientationType( File *file );
   std::string GetOrientation ( File *file );  
   
+  static const char* GetOrientationTypeString(OrientationType const o);
+
 private:
    Res VerfCriterion(int typeCriterion, double criterionNew, Res const &res);
    double CalculLikelyhood2Vec(vector3D const &refA, vector3D const &refB,