]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBaseAnalyzerFilter.txx
Remove warnings
[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(unsigned 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 direction
65     std::vector<clitk::RelativePositionDirectionType> m_ListOfDirections;
66     db.GetListOfDirections(GetStationName(), index.object, m_ListOfDirections);
67     
68     // Loop over direction
69     for(unsigned int j=0; j<m_ListOfDirections.size(); j++) {
70       // DD(j);
71       // m_ListOfDirections[j].Println();
72       // Set current index
73       index.direction = m_ListOfDirections[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_ListOfDirections[j].Print();
83         std::cout << " " << threshold << " " << ok << std::endl;
84         */
85         std::cout << "# -----------------------" << std::endl
86                   << "object = " << m_ListOfObjects[i] << std::endl;
87         m_ListOfDirections[j].PrintOptions();
88         std::cout << "threshold = " << threshold << std::endl
89                   << "sliceBySlice" << std::endl << std::endl; // FIXME spacing ?
90       }
91     }
92   }
93 }    
94 //--------------------------------------------------------------------
95     
96
97 //--------------------------------------------------------------------
98 bool
99 clitk::RelativePositionDataBaseAnalyzerFilter::
100 ComputeOptimalThreshold(RelativePositionDataBaseIndexType & index, double & threshold) 
101 {
102   // Get list of patient
103   std::vector<std::string> & ListOfPatients = db.GetListOfPatients(index);
104   //  DD(ListOfPatients.size());
105   // index.direction.Println();
106
107   // For a given station, object, direction
108   bool stop=false;
109   unsigned int i=0;
110   if (index.direction.notFlag) threshold = 0.0;
111   else threshold = 1.0;
112   while (!stop && (i<ListOfPatients.size())) {
113     index.patient = ListOfPatients[i];
114     // Check index
115     if (!db.CheckIndex(index)) {
116       std::cout << "Warning index does not exist in the DB. index = "; 
117       index.Println(std::cout);
118     }
119     else {
120       if (index.direction.notFlag) threshold = std::max(db.GetThreshold(index), threshold);
121       else threshold = std::min(db.GetThreshold(index), threshold);
122     }
123     ++i;
124   } // end while
125
126   if (index.direction.notFlag)  {
127     if (threshold >=1) return false; // not useful
128   }
129   else {
130     if (threshold <=0) return false; // not useful
131   }
132   return true;
133 }
134 //--------------------------------------------------------------------