]> Creatis software - clitk.git/blob - itk/clitkRelativePositionDataBaseBuilderFilter.txx
af482ca71bb236584c8267c02dd9d603e632240a
[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   static const unsigned int dim = ImageType::ImageDimension;
89   this->LoadAFDB();
90
91   // Get some information
92   std::string patient = this->GetAFDB()->GetTagValue("PatientID");
93
94   // Get input pointers
95   m_Support = this->GetAFDB()->template GetImage <ImageType>(GetSupportName());
96   m_Target = this->GetAFDB()->template GetImage <ImageType>(GetTargetName());
97
98   // Build the list of tested directions
99   m_ListOfAngles.clear();
100   for(uint i=0; i<GetNumberOfAngles(); i++) {
101     double a = i*360.0/GetNumberOfAngles();
102     if (a>180) a = 180-a;
103     m_ListOfAngles.push_back(clitk::deg2rad(a));
104     RelativePositionDirectionType r;
105     r.angle1 = clitk::deg2rad(a);
106     r.angle2 = 0;
107     r.notFlag = false;
108     m_ListOfDirections.push_back(r); // only one direction
109   }
110
111
112   // Perform the RelativePositionAnalyzerFilter for each objects
113   typedef typename clitk::RelativePositionAnalyzerFilter<ImageType> FilterType;
114   for (int i=0; i<GetNumberOfObjects(); i++) {
115     m_Object = this->GetAFDB()->template GetImage <ImageType>(GetObjectName(i));
116
117     for (int j=0; j<m_ListOfDirections.size(); j++) {
118       clitk::RelativePositionDirectionType direction = m_ListOfDirections[j];
119       
120       // Create the filter
121       typename FilterType::Pointer filter = FilterType::New();
122       filter->SetInputSupport(m_Support);
123       filter->SetInputTarget(m_Target);
124       filter->SetInputObject(m_Object); // FIXME do AndNot before + only compute supportSize once.
125       filter->SetNumberOfBins(GetNumberOfBins());
126       filter->SetAreaLossTolerance(GetAreaLossTolerance());
127       filter->SetDirection(direction);
128       filter->Update();
129
130       // Results
131       std::ostringstream s;
132       s << patient << " " 
133         << GetSupportName() << " " 
134         // << GetTargetName() << " " // No need
135         << GetObjectName(i) <<" ";
136       // Normal 
137       // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) {
138         std::ostringstream os;
139         os << s.str();
140         direction.notFlag = false;
141         direction.Print(os);
142         filter->GetInfo().Print(os);
143         std::cout << os.str() << std::endl;
144       // }
145       // Inverse
146       // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) {
147         std::ostringstream oos;
148         oos << s.str();
149         direction.notFlag = true;
150         direction.Print(oos);
151         filter->GetInfoReverse().Print(oos);
152         std::cout << oos.str() << std::endl;
153       // }
154     } // end direction
155
156   } // end object
157 }
158 //--------------------------------------------------------------------
159
160