]> Creatis software - clitk.git/blob - tools/clitkRelativePositionGenericFilter.txx
66c4be47cfa9c80e9e5b687675e30ecf6f6e1061
[clitk.git] / tools / clitkRelativePositionGenericFilter.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 #include "clitkImageCommon.h"
20
21 //--------------------------------------------------------------------
22 template<class ArgsInfoType>
23 clitk::RelativePositionGenericFilter<ArgsInfoType>::
24 RelativePositionGenericFilter():
25   ImageToImageGenericFilter<Self>("RelativePosition")
26 {
27   // Default values
28   cmdline_parser_clitkRelativePosition_init(&mArgsInfo);
29   InitializeImageType<3>();
30 }
31 //--------------------------------------------------------------------
32
33
34 //--------------------------------------------------------------------
35 template<class ArgsInfoType>
36 template<unsigned int Dim>
37 void clitk::RelativePositionGenericFilter<ArgsInfoType>::
38 InitializeImageType() 
39 {  
40   ADD_IMAGE_TYPE(Dim, uchar);
41 }
42 //--------------------------------------------------------------------
43   
44
45 //--------------------------------------------------------------------
46 template<class ArgsInfoType>
47 void clitk::RelativePositionGenericFilter<ArgsInfoType>::
48 SetArgsInfo(const ArgsInfoType & a) 
49 {
50   mArgsInfo=a;
51   SetIOVerbose(mArgsInfo.verbose_flag);
52   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
53   if (mArgsInfo.input_given) AddInputFilename(mArgsInfo.input_arg);
54   if (mArgsInfo.object_given) AddInputFilename(mArgsInfo.object_arg);
55   if (mArgsInfo.output_given) AddOutputFilename(mArgsInfo.output_arg);
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 // Update with the number of dimensions and the pixeltype
62 //--------------------------------------------------------------------
63 template<class ArgsInfoType>
64 template<class FilterType>
65 void clitk::RelativePositionGenericFilter<ArgsInfoType>::
66 SetOptionsFromArgsInfoToFilter(FilterType * f) 
67 {
68   f->SetVerboseOptionFlag(mArgsInfo.verboseOptions_flag);
69   f->SetVerboseStepFlag(mArgsInfo.verboseStep_flag);
70   f->SetWriteStepFlag(mArgsInfo.writeStep_flag);
71
72   for(uint i=0; i<mArgsInfo.orientation_given; i++) {
73     f->AddOrientationTypeString(mArgsInfo.orientation_arg[i]);
74   }
75   
76   if (mArgsInfo.spacing_given) {
77     f->IntermediateSpacingFlagOn();
78     f->SetIntermediateSpacing(mArgsInfo.spacing_arg);
79   }
80   else {
81     f->IntermediateSpacingFlagOff();
82   }
83
84   f->SetFuzzyThreshold(mArgsInfo.threshold_arg);
85   f->SetRemoveObjectFlag(!mArgsInfo.doNotRemoveObject_flag);
86   f->SetAutoCropFlag(!mArgsInfo.noAutoCrop_flag);
87   f->SetCombineWithOrFlag(mArgsInfo.combineWithOr_flag);
88   f->SetInverseOrientationFlag(mArgsInfo.inverse_flag);
89   
90 }
91
92 //--------------------------------------------------------------------
93 // Update with the number of dimensions and the pixeltype
94 //--------------------------------------------------------------------
95 template<class ArgsInfoType>
96 template<class ImageType>
97 void clitk::RelativePositionGenericFilter<ArgsInfoType>::
98 UpdateWithInputImageType() 
99
100   // Reading input
101   typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
102   typename ImageType::Pointer object = this->template GetInput<ImageType>(1);
103
104   if (mArgsInfo.sliceBySlice_flag) {
105     // Create filter
106     typedef clitk::SliceBySliceRelativePositionFilter<ImageType> FilterType;
107     typename FilterType::Pointer filter = FilterType::New();
108     
109     // Set the filter (needed for example for threaded monitoring)
110     this->SetFilterBase(filter);
111     
112     // Set global Options 
113     filter->SetInput(input);
114     filter->SetInputObject(object);
115     SetOptionsFromArgsInfoToFilter<FilterType>(filter);
116
117     // Set options only for SliceBySliceRelativePositionFilter
118     filter->SetDirection(mArgsInfo.direction_arg);
119     filter->SetUniqueConnectedComponentBySliceFlag(mArgsInfo.uniqueCCL_flag);
120     if (mArgsInfo.uniqueObjectCCL_flag) {
121       filter->UseTheLargestObjectCCLFlagOn();
122     }
123     else {
124       filter->UseTheLargestObjectCCLFlagOff();
125     }
126     
127     // Go !
128     filter->Update();
129     
130     // Write/Save results
131     typename ImageType::Pointer output = filter->GetOutput();
132     this->template SetNextOutput<ImageType>(output); 
133   }
134   else {
135     // Create filter
136     typedef clitk::AddRelativePositionConstraintToLabelImageFilter<ImageType> FilterType;
137     typename FilterType::Pointer filter = FilterType::New();
138     
139     // Set the filter (needed for example for threaded monitoring)
140     this->SetFilterBase(filter);
141     
142     // Set global Options 
143     filter->SetInput(input);
144     filter->SetInputObject(object);
145     if (mArgsInfo.angle1_given && mArgsInfo.angle2_given)
146       filter->AddAngles(mArgsInfo.angle1_arg, mArgsInfo.angle2_arg);
147     SetOptionsFromArgsInfoToFilter<FilterType>(filter);
148    
149     // Go !
150     filter->Update();
151     
152     // Write/Save results
153     typename ImageType::Pointer output = filter->GetOutput();
154     this->template SetNextOutput<ImageType>(output); 
155   }
156 }
157 //--------------------------------------------------------------------
158
159