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 //--------------------------------------------------------------------
20 template <class ImageType>
21 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
22 RelativePositionDataBaseBuilderFilter():
24 clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
25 itk::ImageToImageFilter<ImageType, ImageType>()
27 this->SetNumberOfRequiredInputs(0); // support
29 SetBackgroundValue(0);
30 SetForegroundValue(1);
33 SetAreaLossTolerance(0.01);
34 m_ListOfAngles.clear();
37 // SetSizeWithThreshold(0);
38 // SetSizeWithReverseThreshold(0);
40 //--------------------------------------------------------------------
43 //--------------------------------------------------------------------
44 template <class ImageType>
46 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
51 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
55 template <class ImageType>
57 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
58 GenerateOutputInformation()
60 // ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
61 // ImagePointer outputImage = this->GetOutput(0);
62 // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
64 //--------------------------------------------------------------------
67 //--------------------------------------------------------------------
68 template <class ImageType>
70 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
71 GenerateInputRequestedRegion()
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());
79 //--------------------------------------------------------------------
81 //--------------------------------------------------------------------
82 template <class ImageType>
84 clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
87 // Load database of anatomical elements
90 // Get some information
91 std::string patient = this->GetAFDB()->GetTagValue("PatientID");
94 m_Support = this->GetAFDB()->template GetImage <ImageType>(GetSupportName());
95 m_Target = this->GetAFDB()->template GetImage <ImageType>(GetTargetName());
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);
107 m_ListOfDirections.push_back(r); // only one direction
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));
116 for (unsigned int j=0; j<m_ListOfDirections.size(); j++) {
117 clitk::RelativePositionDirectionType direction = m_ListOfDirections[j];
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);
130 std::ostringstream s;
132 << GetSupportName() << " "
133 // << GetTargetName() << " " // No need
134 << GetObjectName(i) <<" ";
136 // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) {
137 std::ostringstream os;
139 direction.notFlag = false;
141 filter->GetInfo().Print(os);
142 std::cout << os.str() << std::endl;
145 // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) {
146 std::ostringstream oos;
148 direction.notFlag = true;
149 direction.Print(oos);
150 filter->GetInfoReverse().Print(oos);
151 std::cout << oos.str() << std::endl;
157 //--------------------------------------------------------------------