]> Creatis software - gdcm.git/blob - src/gdcmOrientation.h
* Improvement #2 : the CommandManager is now a static class so,
[gdcm.git] / src / gdcmOrientation.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmOrientation.h,v $
5   Language:  C++
6   Date:      $Date: 2005/11/28 16:31:23 $
7   Version:   $Revision: 1.17 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef GDCMORIENTATION_H
20 #define GDCMORIENTATION_H
21
22 #include "gdcmRefCounter.h"
23
24 #include <map>
25
26 namespace gdcm 
27 {
28 typedef struct
29 {
30    double x;
31    double y;
32    double z;
33 } vector3D;
34
35 typedef std::pair<double, double> Res;
36 class File;
37
38 typedef enum {
39    NotApplicable = 0,
40    Axial = 1,
41    AxialInvert = -1,
42    Coronal = 2,
43    CoronalInvert = -2,
44    Sagital = 3,
45    SagitalInvert = -3,
46    HeartAxial = 4,
47    HeartAxialInvert = -4,
48    HeartCoronal = 5,
49    HeartCoronalInvert = -5,
50    HeartSagital = 6,
51    HeartSagitalInvert = -6
52 } OrientationType;
53
54 //-----------------------------------------------------------------------------
55 /**
56  * \brief Orientation class for dealing with DICOM image orientation
57  *
58  * A gentle reminder for non-medical user:
59  * PatientPosition (0x0010,0x5100) tells us the way the patient was introduced in the imager
60  *  - HFS : Head First Supine
61  *  - FFS : Feet First Supine
62  *  - HFP : Head First Prone
63  *  - FFP : Feet First Prone
64  * Note: HFP and FFP are not very common values, since the position must
65  *        be pretty unconfortable for the Patient -the patient is lying on his belly; but, if he has handcuffs there is no other way ...-
66  *
67  * ImageOrientationPatient (0x0020,0x0037) gives 6 cosines (2 for each plane)
68  * Patient Orientation (as found in the optional 0x0020,0x0020, or computed by
69  * std::string Orientation::GetOrientation ( File *f ), tells us about the direction of X and Y axes.
70  * 
71  * The values can be
72  *  - A/P anterior/posterior
73  *  - L/R left/right
74  *  - H/F head/feet
75  * One can see it as "values within a 'Patient referential".
76  *
77  * Example #1:
78  * Imagine the patient, in "HFS" position.
79  * Full body sagital images are requested.
80  * All the cosines will be -1, 0, or +1;
81  * "Patient Orientation" (deduced) will be "A/F".
82  * Positive X axis is oriented 'towards patient's nose
83  * Positive Y axis  is oriented 'towards patient's feet
84  *
85  * Example #2:
86  * Imagine now that patient has a stiffneck and his head is *turned* 30 degrees towards the left.
87  * Head sagital images are requested.
88  * One of the cosines will be almost 0.5
89  * Deduced "Patient Orientation" will be "AL\F"
90  * (main X axis orientation is towards patient's nose, and a little bit towards the left)
91  * but the image looks *perfectly* sagital (for the head, not for the patient) !
92  *
93  * Imagine the patient's stiffneck causes head to be *bended* 30 degrees towards the left AND *turned* left.
94  * Sagital images are requested...
95  * You'll probabely have 3 letters for X axis and  Y axis, and the image remains *perfectly* sagital !
96  * The values are given within the 'Patient referential', *not* within the 'Organ referential' ...
97  */
98
99 class GDCM_EXPORT Orientation : public RefCounter
100 {
101    gdcmTypeMacro(Orientation);
102 public:
103 /// \brief Constructs a gdcm::Orientation with a RefCounter
104    static Orientation *New() {return new Orientation();}
105
106   OrientationType GetOrientationType( File *file );
107   std::string GetOrientation ( File *file );  
108   
109   static const char* GetOrientationTypeString(OrientationType const o);
110   
111 protected:
112 /// \brief Constructor
113   Orientation() {}
114 /// \brief Canonical Destructor
115   ~Orientation() {}
116 private:
117    Res VerfCriterion(int typeCriterion, double criterionNew, Res const &res);
118    double CalculLikelyhood2Vec(vector3D const &refA, vector3D const &refB, 
119                                vector3D const &ori1, vector3D const &ori2);
120    vector3D ProductVectorial(vector3D const &vec1, vector3D const &vec2);
121    std::string GetSingleOrientation ( float *iop);
122 };
123 } // end namespace gdcm
124 //-----------------------------------------------------------------------------
125 #endif