]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBaseAnalyzerFilter.txx
Add first version of clitkRelativePositionDataBaseAnalyzer
[clitk.git] / itk / clitkRelativePositionDataBaseAnalyzerFilter.txx
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 //--------------------------------------------------------------------
20 clitk::RelativePositionDataBaseAnalyzerFilter::
21 RelativePositionDataBaseAnalyzerFilter():
22   clitk::FilterBase(),
23   clitk::FilterWithAnatomicalFeatureDatabaseManagement()
24 {
25   VerboseFlagOff();
26   SetDatabaseFilename("default.dbrp");
27 }
28 //--------------------------------------------------------------------
29
30
31 //--------------------------------------------------------------------
32 void 
33 clitk::RelativePositionDataBaseAnalyzerFilter::
34 PrintOptions() 
35 {
36   DD("TODO");
37 }
38 //--------------------------------------------------------------------
39
40
41 //--------------------------------------------------------------------
42 void 
43 clitk::RelativePositionDataBaseAnalyzerFilter::
44 Update() 
45 {
46   // Load DB of relative position
47   db.Read(GetDatabaseFilename());
48
49   // Get list of objects, list of orientation
50   std::vector<std::string> m_ListOfObjects;
51   db.GetListOfObjects(GetStationName(), m_ListOfObjects);
52   
53   // Set initial index in the DB
54   clitk::RelativePositionDataBase::IndexType index;
55   index.station = GetStationName();
56
57   // Loop over objects
58   std::vector<double> m_ListOfThresholds;
59   for(int i=0; i<m_ListOfObjects.size(); i++) {
60     // DD(i);
61     // DD(m_ListOfObjects[i]);
62     // Set current index
63     index.object = m_ListOfObjects[i];
64     // Get the list of orientation
65     std::vector<clitk::RelativePositionOrientationType> m_ListOfOrientations;
66     db.GetListOfOrientations(GetStationName(), index.object, m_ListOfOrientations);
67     
68     // Loop over orientation
69     for(int j=0; j<m_ListOfOrientations.size(); j++) {
70       // DD(j);
71       // m_ListOfOrientations[j].Println();
72       // Set current index
73       index.orientation = m_ListOfOrientations[j];
74       // Compute the best RelPos parameters 
75       double threshold;
76       bool ok = ComputeOptimalThreshold(index, threshold);
77       m_ListOfThresholds.push_back(threshold);
78       
79       // Print debug FIXME
80       if (ok) {
81         std::cout << m_ListOfObjects[i] << " ";
82         m_ListOfOrientations[j].Print();
83         std::cout << " " << threshold << " " << ok << std::endl;
84       }
85     }
86   }
87 }    
88 //--------------------------------------------------------------------
89     
90
91 //--------------------------------------------------------------------
92 bool
93 clitk::RelativePositionDataBaseAnalyzerFilter::
94 ComputeOptimalThreshold(RelativePositionDataBaseIndexType & index, double & threshold) 
95 {
96   // Get list of patient
97   std::vector<std::string> & ListOfPatients = db.GetListOfPatients(index);
98   //  DD(ListOfPatients.size());
99   // index.orientation.Println();
100
101   // For a given station, object, orientation
102   bool stop=false;
103   int i=0;
104   if (index.orientation.notFlag) threshold = 0.0;
105   else threshold = 1.0;
106   while (!stop && (i<ListOfPatients.size())) {
107     // DD(i);
108     index.patient = ListOfPatients[i];
109     // std::cout << i << " " << index.patient << " ";
110     // Check index
111     if (!db.CheckIndex(index)) {
112       std::cout << "Warning index does not exist in the DB. index = "; 
113       index.Println(std::cout);
114     }
115     else {
116       // index = patient station object, orientation = angle1 angle2 notFlag
117       if (db.GetAreaGain(index) == 1.0) stop = true;
118       else {
119         if (index.orientation.notFlag) threshold = std::max(db.GetThreshold(index), threshold);
120         else threshold = std::min(db.GetThreshold(index), threshold);
121         // std::cout << db.GetThreshold(index) << " opt=" << threshold;
122       } 
123     }
124     ++i;
125   }
126   // std::cout << std::endl;
127   // DD(threshold);
128   // DD(stop);
129   return !stop; // if stop before the end, this orientation is not useful.
130 }
131 //--------------------------------------------------------------------