1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #ifndef CLITKRELATIVEPOSITIONDATABASE_CXX
20 #define CLITKRELATIVEPOSITIONDATABASE_CXX
23 #include "clitkRelativePositionDataBase.h"
27 //--------------------------------------------------------------------
28 void RelativePositionDataBase::ReadIndex(std::istream & is, IndexType & index)
33 is >> index.orientation.angle1;
34 index.orientation.angle1 = clitk::deg2rad(index.orientation.angle1);
35 is >> index.orientation.angle2;
36 index.orientation.angle2 = clitk::deg2rad(index.orientation.angle2);
39 if (s=="true") index.orientation.notFlag = true;
40 else index.orientation.notFlag = false;
42 //--------------------------------------------------------------------
45 //--------------------------------------------------------------------
46 void RelativePositionDataBase::ReadInformation(std::istream & is, RelativePositionInformationType & v)
49 is >> v.sizeBeforeThreshold;
50 is >> v.sizeAfterThreshold;
51 is >> v.sizeReference;
53 //--------------------------------------------------------------------
55 //--------------------------------------------------------------------
56 void RelativePositionDataBase::Read(const std::string & filename)
60 openFileForReading(is, filename);
64 RelativePositionInformationType v;
66 skipComment(is); /* FIXME Read Index etc */
68 ReadInformation(is, v);
70 if (is) {// FIXME INSERT
72 if (m_DB.find(index.station) == m_DB.end()) {
74 m_DB[index.station] = s;
76 MapByObjectType & s = m_DB[index.station];
78 // Get Orientation map from Object
79 if (s.find(index.object) == s.end()) {
80 MapByOrientationType r;
83 MapByOrientationType & r = s[index.object];
85 // Get Patient map from Orientation
86 if (r.find(index.orientation) == r.end()) {
88 r[index.orientation] = q;
90 MapByPatientType & q = r[index.orientation];
92 // Set value by patient
97 // GetMapByPatient(index).find(index.patient)->second.Println();
100 } // end loop reading
103 //--------------------------------------------------------------------
106 //--------------------------------------------------------------------
107 const RelativePositionDataBase::MapByOrientationType &
108 RelativePositionDataBase::GetMapByOrientation(const IndexType & index) const
110 const MapByObjectType & a = GetMapByObject(index.station);
111 if (a.find(index.object) == a.end()) {
112 clitkExceptionMacro("Could not find index in DB (object= '" << index.object << "' not found).");
114 return a.find(index.object)->second;
116 //--------------------------------------------------------------------
119 //--------------------------------------------------------------------
120 const RelativePositionDataBase::MapByObjectType &
121 RelativePositionDataBase::GetMapByObject(const std::string & station) const
123 if (m_DB.find(station) == m_DB.end()) {
124 clitkExceptionMacro("Could not find index in DB (station= '" << station << "' not found).");
126 return m_DB.find(station)->second;
128 //--------------------------------------------------------------------
131 //--------------------------------------------------------------------
132 const RelativePositionDataBase::MapByPatientType &
133 RelativePositionDataBase::GetMapByPatient(const IndexType & index) const
135 const MapByOrientationType & a = GetMapByOrientation(index);
136 if (a.find(index.orientation) == a.end()) {
137 std::ostringstream s;
138 index.orientation.Print(s);
139 clitkExceptionMacro("Could not find index in DB (orientation= '" << s.str() << "' not found).");
141 return a.find(index.orientation)->second;
143 //--------------------------------------------------------------------
146 //--------------------------------------------------------------------
147 const RelativePositionInformationType &
148 RelativePositionDataBase::GetInformation(const IndexType & index) const
150 const RelativePositionDataBase::MapByPatientType & a = GetMapByPatient(index);
151 if (a.find(index.patient) == a.end()) {
152 clitkExceptionMacro("Could not find index in DB (patient= '" << index.patient << "' not found).");
154 return a.find(index.patient)->second;
156 //--------------------------------------------------------------------
159 //--------------------------------------------------------------------
160 int RelativePositionDataBase::GetNumberOfPatient(const IndexType & index) const
162 const MapByPatientType & o = GetMapByPatient(index);
165 //--------------------------------------------------------------------
168 //--------------------------------------------------------------------
169 std::vector<std::string> & RelativePositionDataBase::GetListOfPatients(const IndexType & index) const
171 const MapByPatientType & o = GetMapByPatient(index);
172 MapByPatientType::const_iterator iter = o.begin();
173 std::vector<std::string> * v = new std::vector<std::string>;
174 MapToVecFirst(o, *v);
177 //--------------------------------------------------------------------
180 //--------------------------------------------------------------------
181 double RelativePositionDataBase::GetAreaGain(const IndexType & index) const
184 const RelativePositionInformationType & v = GetInformation(index);
185 return v.sizeAfterThreshold/v.sizeBeforeThreshold;
187 //--------------------------------------------------------------------
190 //--------------------------------------------------------------------
191 double RelativePositionDataBase::GetThreshold(const IndexType & index) const
193 const RelativePositionInformationType & v = GetInformation(index);
196 //--------------------------------------------------------------------
199 //--------------------------------------------------------------------
201 RelativePositionDataBase::GetListOfObjects(const std::string & station, std::vector<std::string> & objects) const
203 const MapByObjectType & a = GetMapByObject(station);
204 MapToVecFirst(a, objects);
206 //--------------------------------------------------------------------
209 //--------------------------------------------------------------------
211 RelativePositionDataBase::GetListOfOrientations(const std::string & station,
212 const std::string & object,
213 std::vector<RelativePositionOrientationType> & orientations) const
218 const MapByOrientationType & n = GetMapByOrientation(i);
219 MapToVecFirst(n, orientations);
221 //--------------------------------------------------------------------
224 //--------------------------------------------------------------------
225 bool RelativePositionDataBase::CheckIndex(const IndexType & index) const
228 const RelativePositionInformationType & m = GetInformation(index);
229 } catch (clitk::ExceptionObject e) {
230 // std::cout << e.what() << std::endl;
235 //--------------------------------------------------------------------
238 } // end namespace clitk
239 //--------------------------------------------------------------------