]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBase.h
Be compatible with itk 3.20 with debug on
[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   //--------------------------------------------------------------------
114
115
116   //--------------------------------------------------------------------
117   class RelativePositionDataBase {
118     
119   public:    
120     RelativePositionDataBase() {}
121     ~RelativePositionDataBase() {}
122
123     typedef RelativePositionDataBaseIndexType IndexType;
124
125     void Read(const std::string & filename);
126     double GetAreaGain(const IndexType & index) const;
127     double GetThreshold(const IndexType & index) const;
128     int GetNumberOfPatient(const IndexType & index) const;
129     std::vector<std::string> & GetListOfPatients(const IndexType & index) const;
130     void GetListOfObjects(const std::string & station, std::vector<std::string> & objects) const;
131     void GetListOfDirections(const std::string & station, 
132                                const std::string & object, 
133                                std::vector<RelativePositionDirectionType> & directions) const;
134     bool CheckIndex(const IndexType & index) const;
135
136   protected:
137     typedef std::map<std::string, RelativePositionInformationType> MapByPatientType;
138     typedef std::map<RelativePositionDirectionType, MapByPatientType> MapByDirectionType;
139     typedef std::map<std::string, MapByDirectionType> MapByObjectType;
140     typedef std::map<std::string, MapByObjectType> MapByStationType;
141     MapByStationType m_DB;
142     
143     void ReadIndex(std::istream & is, IndexType & index);
144     void ReadInformation(std::istream & is, RelativePositionInformationType & v);
145
146     const MapByDirectionType & GetMapByDirection(const IndexType & index) const;
147     const MapByPatientType & GetMapByPatient(const IndexType & index) const;
148     const RelativePositionInformationType & GetInformation(const IndexType & index) const;
149     const MapByObjectType & GetMapByObject(const std::string & station) const;
150
151   }; // end class
152   //--------------------------------------------------------------------
153
154 } // end namespace clitk
155 //--------------------------------------------------------------------
156
157 #endif