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
88 static const unsigned int dim = ImageType::ImageDimension;
91 // Get some information
92 std::string patient = this->GetAFDB()->GetTagValue("PatientID");
95 m_Support = this->GetAFDB()->template GetImage <ImageType>(GetSupportName());
96 m_Target = this->GetAFDB()->template GetImage <ImageType>(GetTargetName());
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);
108 m_ListOfDirections.push_back(r); // only one direction
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));
117 for (int j=0; j<m_ListOfDirections.size(); j++) {
118 clitk::RelativePositionDirectionType direction = m_ListOfDirections[j];
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);
131 std::ostringstream s;
133 << GetSupportName() << " "
134 // << GetTargetName() << " " // No need
135 << GetObjectName(i) <<" ";
137 // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) {
138 std::ostringstream os;
140 direction.notFlag = false;
142 filter->GetInfo().Print(os);
143 std::cout << os.str() << std::endl;
146 // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) {
147 std::ostringstream oos;
149 direction.notFlag = true;
150 direction.Print(oos);
151 filter->GetInfoReverse().Print(oos);
152 std::cout << oos.str() << std::endl;
158 //--------------------------------------------------------------------