]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBase.h
439c015bc3b912e8458ae9f9f94896d01c291163
[clitk.git] / itk / clitkRelativePositionDataBase.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 #ifndef CLITKRELATIVEPOSITIONDATABASE_H
20 #define CLITKRELATIVEPOSITIONDATABASE_H
21
22 // clitk
23 #include "clitkCommon.h"
24
25 namespace clitk {
26   
27   //--------------------------------------------------------------------
28   /*
29     FIXME
30    */
31   //--------------------------------------------------------------------
32   
33
34   //--------------------------------------------------------------------
35    class RelativePositionDirectionType {
36   public:
37     double angle1;
38     double angle2;
39     bool notFlag;
40
41     void Print(std::ostream & os = std::cout) const {
42       os << clitk::rad2deg(angle1) << " " << clitk::rad2deg(angle2) << " ";
43       if (notFlag) os << "true"; 
44       else os << "false";
45       os << " ";
46     }
47     
48     void PrintOptions(std::ostream & os = std::cout) const {
49       os << "angle1 = " << clitk::rad2deg(angle1) << std::endl
50          << "angle2 = " << clitk::rad2deg(angle2) << std::endl;
51       if (notFlag) os << "inverse" << std::endl;
52     }
53     
54     void Println(std::ostream & os = std::cout) const {
55       Print(os);
56       os << std::endl;
57     }
58
59     bool operator< (const RelativePositionDirectionType &compare) const
60     {
61       if (angle1 < compare.angle1) return true;
62       if (angle1 > compare.angle1) return false;
63         
64       if (angle2 < compare.angle2) return true;
65       if (angle2 > compare.angle2) return false;
66         
67       if (notFlag == true) {
68         if (compare.notFlag == false) return true;
69         else return false;
70       }
71       return false;
72     }
73   };
74   //--------------------------------------------------------------------
75  
76
77   //--------------------------------------------------------------------
78   class RelativePositionDataBaseIndexType {
79   public:
80     std::string patient;
81     std::string station;
82     std::string object;
83     RelativePositionDirectionType direction;
84     void Print(std::ostream & os = std::cout) const {
85       os << patient << " " << station << " " << object << " ";
86       direction.Print(os);
87     }
88     void Println(std::ostream & os = std::cout) const {
89       Print(os);
90       os << std::endl;
91     }
92   };
93   //--------------------------------------------------------------------
94   
95
96   //--------------------------------------------------------------------
97   class RelativePositionInformationType {
98   public:
99     double threshold;
100     int sizeBeforeThreshold;
101     int sizeAfterThreshold;
102     int sizeReference;
103     void Print(std::ostream & os = std::cout) const {
104       os << threshold << " " << sizeBeforeThreshold << " " 
105          << sizeAfterThreshold << " " << sizeReference;
106     }
107     void Println(std::ostream & os = std::cout) const {
108       Print(os);
109       os << std::endl;
110     }
111   };
112   std::ostream operator<<(std::ostream & os, const clitk::RelativePositionInformationType & rp) {
113     rp.Print(os);
114   }
115   //--------------------------------------------------------------------
116
117
118   //--------------------------------------------------------------------
119   class RelativePositionDataBase {
120     
121   public:    
122     RelativePositionDataBase() {}
123     ~RelativePositionDataBase() {}
124
125     typedef RelativePositionDataBaseIndexType IndexType;
126
127     void Read(const std::string & filename);
128     double GetAreaGain(const IndexType & index) const;
129     double GetThreshold(const IndexType & index) const;
130     int GetNumberOfPatient(const IndexType & index) const;
131     std::vector<std::string> & GetListOfPatients(const IndexType & index) const;
132     void GetListOfObjects(const std::string & station, std::vector<std::string> & objects) const;
133     void GetListOfDirections(const std::string & station, 
134                                const std::string & object, 
135                                std::vector<RelativePositionDirectionType> & directions) const;
136     bool CheckIndex(const IndexType & index) const;
137
138   protected:
139     typedef std::map<std::string, RelativePositionInformationType> MapByPatientType;
140     typedef std::map<RelativePositionDirectionType, MapByPatientType> MapByDirectionType;
141     typedef std::map<std::string, MapByDirectionType> MapByObjectType;
142     typedef std::map<std::string, MapByObjectType> MapByStationType;
143     MapByStationType m_DB;
144     
145     void ReadIndex(std::istream & is, IndexType & index);
146     void ReadInformation(std::istream & is, RelativePositionInformationType & v);
147
148     const MapByDirectionType & GetMapByDirection(const IndexType & index) const;
149     const MapByPatientType & GetMapByPatient(const IndexType & index) const;
150     const RelativePositionInformationType & GetInformation(const IndexType & index) const;
151     const MapByObjectType & GetMapByObject(const std::string & station) const;
152
153   }; // end class
154   //--------------------------------------------------------------------
155
156 } // end namespace clitk
157 //--------------------------------------------------------------------
158
159 #endif