]> Creatis software - clitk.git/blob - segmentation/clitkMorphoMathGenericFilter.txx
option to auto-detect motion mask's initial ellipse
[clitk.git] / segmentation / clitkMorphoMathGenericFilter.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 "clitkSegmentationUtils.h"
20
21 //--------------------------------------------------------------------
22 template<class ArgsInfoType>
23 clitk::MorphoMathGenericFilter<ArgsInfoType>::
24 MorphoMathGenericFilter():
25   ImageToImageGenericFilter<MorphoMathGenericFilter<ArgsInfoType> >("MorphMath")
26 {
27   // Default values
28   cmdline_parser_clitkMorphoMath_init(&mArgsInfo);
29   InitializeImageType<2>();
30   InitializeImageType<3>();
31   InitializeImageType<4>();
32 }
33 //--------------------------------------------------------------------
34
35
36 //--------------------------------------------------------------------
37 template<class ArgsInfoType>
38 template<unsigned int Dim>
39 void clitk::MorphoMathGenericFilter<ArgsInfoType>::
40 InitializeImageType() 
41 {  
42   ADD_DEFAULT_IMAGE_TYPES(Dim);
43   //ADD_IMAGE_TYPE(Dim, short); // 
44 }
45 //--------------------------------------------------------------------
46   
47
48 //--------------------------------------------------------------------
49 template<class ArgsInfoType>
50 void clitk::MorphoMathGenericFilter<ArgsInfoType>::
51 SetArgsInfo(const ArgsInfoType & a) 
52 {
53   mArgsInfo=a;
54   this->SetIOVerbose(mArgsInfo.verbose_flag);
55   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
56   if (mArgsInfo.input_given) this->AddInputFilename(mArgsInfo.input_arg);
57   if (mArgsInfo.output_given) this->AddOutputFilename(mArgsInfo.output_arg);
58 }
59 //--------------------------------------------------------------------
60
61
62 //--------------------------------------------------------------------
63 template<class ArgsInfoType>
64 template<class FilterType>
65 void clitk::MorphoMathGenericFilter<ArgsInfoType>::
66 SetOptionsFromArgsInfoToFilter(FilterType * f) 
67 {
68   f->SetVerboseFlag(mArgsInfo.verbose_flag);
69   f->SetExtendSupportFlag(mArgsInfo.extend_flag);
70   f->SetOperationType(mArgsInfo.type_arg);
71   f->SetBackgroundValue(mArgsInfo.bg_arg);
72   f->SetForegroundValue(mArgsInfo.fg_arg);
73   f->SetBoundaryToForegroundFlag(mArgsInfo.bound_flag);
74   if (mArgsInfo.radius_given && mArgsInfo.radiusInMM_given) {
75     clitkExceptionMacro("Please give --radius OR --radiusInMM, not both.");
76   }
77
78   if (mArgsInfo.radiusInMM_given) {
79     typename FilterType::PointType p;
80     if (mArgsInfo.radiusInMM_given) {
81       ConvertOptionMacro(mArgsInfo.radiusInMM, p, FilterType::ImageDimension, false);
82       f->SetRadiusInMM(p);
83     }
84   }
85   else {
86     typename FilterType::SizeType r;
87     if (mArgsInfo.radius_given) {
88       ConvertOptionMacro(mArgsInfo.radius, r, FilterType::ImageDimension, false);
89       f->SetRadius(r);
90     }
91   }
92 }
93
94 //--------------------------------------------------------------------
95 // Update with the number of dimensions and the pixeltype
96 //--------------------------------------------------------------------
97 template<class ArgsInfoType>
98 template<class ImageType>
99 void clitk::MorphoMathGenericFilter<ArgsInfoType>::
100 UpdateWithInputImageType() 
101
102   // Reading input
103   typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
104
105   // Create filter
106   typedef clitk::MorphoMathFilter<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   SetOptionsFromArgsInfoToFilter<FilterType>(filter);
115
116   // Go !
117   filter->Update();
118   
119   // Write/Save results
120   typename ImageType::Pointer output = filter->GetOutput();
121   this->template SetNextOutput<ImageType>(output); 
122 }
123 //--------------------------------------------------------------------
124
125