]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBaseBuilderFilter.txx
Remove warnings
[clitk.git] / itk / clitkRelativePositionDataBaseBuilderFilter.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 template <class ImageType>
21 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
22 RelativePositionDataBaseBuilderFilter():
23   clitk::FilterBase(),
24   clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
25   itk::ImageToImageFilter<ImageType, ImageType>()
26 {
27   this->SetNumberOfRequiredInputs(0); // support
28   VerboseFlagOff();
29   SetBackgroundValue(0);
30   SetForegroundValue(1);
31   SetNumberOfBins(100);
32   SetNumberOfAngles(4);
33   SetAreaLossTolerance(0.01);
34   m_ListOfAngles.clear();
35   // SetSupportSize(0);
36   // SetTargetSize(0);
37   // SetSizeWithThreshold(0);
38   // SetSizeWithReverseThreshold(0);  
39 }
40 //--------------------------------------------------------------------
41
42
43 //--------------------------------------------------------------------
44 template <class ImageType>
45 void 
46 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
47 PrintOptions() 
48 {
49   DD("TODO");
50 }
51 //--------------------------------------------------------------------
52
53
54 //--------------------------------------------------------------------
55 template <class ImageType>
56 void 
57 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
58 GenerateOutputInformation() 
59
60   // ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
61   // ImagePointer outputImage = this->GetOutput(0);
62   // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
63 }
64 //--------------------------------------------------------------------
65
66
67 //--------------------------------------------------------------------
68 template <class ImageType>
69 void 
70 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
71 GenerateInputRequestedRegion() 
72 {
73   // Call default
74   // itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
75   // // Get input pointers and set requested region to common region
76   // ImagePointer input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
77   // input1->SetRequestedRegion(input1->GetLargestPossibleRegion());
78 }
79 //--------------------------------------------------------------------
80
81 //--------------------------------------------------------------------
82 template <class ImageType>
83 void 
84 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
85 GenerateData() 
86 {
87   // Load database of anatomical elements
88   this->LoadAFDB();
89
90   // Get some information
91   std::string patient = this->GetAFDB()->GetTagValue("PatientID");
92
93   // Get input pointers
94   m_Support = this->GetAFDB()->template GetImage <ImageType>(GetSupportName());
95   m_Target = this->GetAFDB()->template GetImage <ImageType>(GetTargetName());
96
97   // Build the list of tested directions
98   m_ListOfAngles.clear();
99   for(int i=0; i<GetNumberOfAngles(); i++) {
100     double a = i*360.0/GetNumberOfAngles();
101     if (a>180) a = 180-a;
102     m_ListOfAngles.push_back(clitk::deg2rad(a));
103     RelativePositionDirectionType r;
104     r.angle1 = clitk::deg2rad(a);
105     r.angle2 = 0;
106     r.notFlag = false;
107     m_ListOfDirections.push_back(r); // only one direction
108   }
109
110
111   // Perform the RelativePositionAnalyzerFilter for each objects
112   typedef typename clitk::RelativePositionAnalyzerFilter<ImageType> FilterType;
113   for (int i=0; i<GetNumberOfObjects(); i++) {
114     m_Object = this->GetAFDB()->template GetImage <ImageType>(GetObjectName(i));
115
116     for (unsigned int j=0; j<m_ListOfDirections.size(); j++) {
117       clitk::RelativePositionDirectionType direction = m_ListOfDirections[j];
118       
119       // Create the filter
120       typename FilterType::Pointer filter = FilterType::New();
121       filter->SetInputSupport(m_Support);
122       filter->SetInputTarget(m_Target);
123       filter->SetInputObject(m_Object); // FIXME do AndNot before + only compute supportSize once.
124       filter->SetNumberOfBins(GetNumberOfBins());
125       filter->SetAreaLossTolerance(GetAreaLossTolerance());
126       filter->SetDirection(direction);
127       filter->Update();
128
129       // Results
130       std::ostringstream s;
131       s << patient << " " 
132         << GetSupportName() << " " 
133         // << GetTargetName() << " " // No need
134         << GetObjectName(i) <<" ";
135       // Normal 
136       // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) {
137         std::ostringstream os;
138         os << s.str();
139         direction.notFlag = false;
140         direction.Print(os);
141         filter->GetInfo().Print(os);
142         std::cout << os.str() << std::endl;
143       // }
144       // Inverse
145       // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) {
146         std::ostringstream oos;
147         oos << s.str();
148         direction.notFlag = true;
149         direction.Print(oos);
150         filter->GetInfoReverse().Print(oos);
151         std::cout << oos.str() << std::endl;
152       // }
153     } // end direction
154
155   } // end object
156 }
157 //--------------------------------------------------------------------
158
159