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.direction.angle1;
34 index.direction.angle1 = clitk::deg2rad(index.direction.angle1);
35 is >> index.direction.angle2;
36 index.direction.angle2 = clitk::deg2rad(index.direction.angle2);
39 if (s=="true") index.direction.notFlag = true;
40 else index.direction.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)
59 openFileForReading(is, filename);
63 RelativePositionInformationType v;
65 skipComment(is); /* FIXME Read Index etc */
67 ReadInformation(is, v);
69 if (is) {// FIXME INSERT
71 if (m_DB.find(index.station) == m_DB.end()) {
73 m_DB[index.station] = s;
75 MapByObjectType & s = m_DB[index.station];
77 // Get Direction map from Object
78 if (s.find(index.object) == s.end()) {
82 MapByDirectionType & r = s[index.object];
84 // Get Patient map from Direction
85 if (r.find(index.direction) == r.end()) {
87 r[index.direction] = q;
89 MapByPatientType & q = r[index.direction];
91 // Set value by patient
96 // GetMapByPatient(index).find(index.patient)->second.Println();
101 //--------------------------------------------------------------------
104 //--------------------------------------------------------------------
105 const RelativePositionDataBase::MapByDirectionType &
106 RelativePositionDataBase::GetMapByDirection(const IndexType & index) const
108 const MapByObjectType & a = GetMapByObject(index.station);
109 if (a.find(index.object) == a.end()) {
110 clitkExceptionMacro("Could not find index in DB (object= '" << index.object << "' not found).");
112 return a.find(index.object)->second;
114 //--------------------------------------------------------------------
117 //--------------------------------------------------------------------
118 const RelativePositionDataBase::MapByObjectType &
119 RelativePositionDataBase::GetMapByObject(const std::string & station) const
121 if (m_DB.find(station) == m_DB.end()) {
122 clitkExceptionMacro("Could not find index in DB (station= '" << station << "' not found).");
124 return m_DB.find(station)->second;
126 //--------------------------------------------------------------------
129 //--------------------------------------------------------------------
130 const RelativePositionDataBase::MapByPatientType &
131 RelativePositionDataBase::GetMapByPatient(const IndexType & index) const
133 const MapByDirectionType & a = GetMapByDirection(index);
134 if (a.find(index.direction) == a.end()) {
135 std::ostringstream s;
136 index.direction.Print(s);
137 clitkExceptionMacro("Could not find index in DB (direction= '" << s.str() << "' not found).");
139 return a.find(index.direction)->second;
141 //--------------------------------------------------------------------
144 //--------------------------------------------------------------------
145 const RelativePositionInformationType &
146 RelativePositionDataBase::GetInformation(const IndexType & index) const
148 const RelativePositionDataBase::MapByPatientType & a = GetMapByPatient(index);
149 if (a.find(index.patient) == a.end()) {
150 clitkExceptionMacro("Could not find index in DB (patient= '" << index.patient << "' not found).");
152 return a.find(index.patient)->second;
154 //--------------------------------------------------------------------
157 //--------------------------------------------------------------------
158 int RelativePositionDataBase::GetNumberOfPatient(const IndexType & index) const
160 const MapByPatientType & o = GetMapByPatient(index);
163 //--------------------------------------------------------------------
166 //--------------------------------------------------------------------
167 std::vector<std::string> & RelativePositionDataBase::GetListOfPatients(const IndexType & index) const
169 const MapByPatientType & o = GetMapByPatient(index);
170 MapByPatientType::const_iterator iter = o.begin();
171 std::vector<std::string> * v = new std::vector<std::string>;
172 MapToVecFirst(o, *v);
175 //--------------------------------------------------------------------
178 //--------------------------------------------------------------------
179 double RelativePositionDataBase::GetAreaGain(const IndexType & index) const
182 const RelativePositionInformationType & v = GetInformation(index);
183 return v.sizeAfterThreshold/v.sizeBeforeThreshold;
185 //--------------------------------------------------------------------
188 //--------------------------------------------------------------------
189 double RelativePositionDataBase::GetThreshold(const IndexType & index) const
191 const RelativePositionInformationType & v = GetInformation(index);
194 //--------------------------------------------------------------------
197 //--------------------------------------------------------------------
199 RelativePositionDataBase::GetListOfObjects(const std::string & station, std::vector<std::string> & objects) const
201 const MapByObjectType & a = GetMapByObject(station);
202 MapToVecFirst(a, objects);
204 //--------------------------------------------------------------------
207 //--------------------------------------------------------------------
209 RelativePositionDataBase::GetListOfDirections(const std::string & station,
210 const std::string & object,
211 std::vector<RelativePositionDirectionType> & directions) const
216 const MapByDirectionType & n = GetMapByDirection(i);
217 MapToVecFirst(n, directions);
219 //--------------------------------------------------------------------
222 //--------------------------------------------------------------------
223 bool RelativePositionDataBase::CheckIndex(const IndexType & index) const
226 const RelativePositionInformationType & m = GetInformation(index);
227 } catch (clitk::ExceptionObject e) {
228 // std::cout << e.what() << std::endl;
233 //--------------------------------------------------------------------
235 //--------------------------------------------------------------------
236 std::ostream& operator<<(std::ostream & os, const clitk::RelativePositionInformationType & rp)
241 //--------------------------------------------------------------------
243 } // end namespace clitk
244 //--------------------------------------------------------------------