OTB  9.0.0
Orfeo Toolbox
otbShapeAttributesLabelMapFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbShapeAttributesLabelMapFilter_h
23 #define otbShapeAttributesLabelMapFilter_h
24 
26 #include "otbImage.h"
27 #include "otbPolygon.h"
29 #include "otbFlusserPathFunction.h"
30 #include "otbSimplifyPathFunctor.h"
31 
32 
33 namespace otb
34 {
35 
36 namespace Functor
37 {
45 template <class TLabelObject, class TLabelImage>
47 {
48 public:
51 
53  typedef TLabelObject LabelObjectType;
54 
56  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
57 
59  typedef TLabelImage LabelImageType;
60 
62  typedef typename TLabelObject::PolygonType PolygonType;
66 
67  typedef unsigned int DimensionType;
68 
70  itkStaticConstMacro(ImageDimension, unsigned int, TLabelObject::ImageDimension);
71  typedef itk::ImageRegion<TLabelObject::ImageDimension> RegionType;
72  typedef itk::Offset<TLabelObject::ImageDimension> OffsetType;
73 
76 
79  {
80  }
81 
83  bool operator!=(const Self& self);
84  bool operator==(const Self& self);
86 
88  void SetComputePerimeter(bool flag);
89 
91  bool GetComputePerimeter() const;
92 
94  void SetComputeFlusser(bool flag);
95 
97  bool GetComputeFlusser() const;
98 
100  void SetComputePolygon(bool flag);
101 
103  bool GetComputePolygon() const;
104 
106  void SetComputeFeretDiameter(bool flag);
107 
109  bool GetComputeFeretDiameter() const;
110 
112  void SetReducedAttributeSet(bool flag);
113 
115  bool GetReducedAttributeSet() const;
116 
119  void SetLabelImage(const TLabelImage* image);
120 
122  const TLabelImage* GetLabelImage() const;
123 
127  inline void operator()(LabelObjectType* lo);
128 
129 private:
131  static long factorial(long n);
132 
134  static long doubleFactorial(long n);
135 
137  static double gammaN2p1(long n);
138 
140  static double hyperSphereVolume(double radius);
141 
143  static double hyperSpherePerimeter(double radius);
144 
146  static double hyperSphereRadiusFromVolume(double volume);
147 
148  double ComputePerimeter(LabelObjectType* labelObject, const RegionType& region);
149 
150  typedef itk::Offset<2> Offset2Type;
151  typedef itk::Offset<3> Offset3Type;
152  typedef itk::Vector<double, 2> Spacing2Type;
153  typedef itk::Vector<double, 3> Spacing3Type;
154  typedef std::map<Offset2Type, itk::SizeValueType, Offset2Type::LexicographicCompare> MapIntercept2Type;
155  typedef std::map<Offset3Type, itk::SizeValueType, Offset3Type::LexicographicCompare> MapIntercept3Type;
156 
157  template <class TMapIntercept, class TSpacing>
158  double PerimeterFromInterceptCount(TMapIntercept& intercepts, const TSpacing& spacing);
159 
160 #if !defined(ITK_DO_NOT_USE_PERIMETER_SPECIALIZATION)
161  double PerimeterFromInterceptCount(MapIntercept2Type& intercepts, const Spacing2Type spacing);
162  double PerimeterFromInterceptCount(MapIntercept3Type& intercepts, const Spacing3Type spacing);
163 #endif
164 
167 
170 
173 
176 
179 
181  typename LabelImageType::ConstPointer m_LabelImage;
182 };
183 
184 } // End namespace Functor
185 
211 template <class TImage, class TLabelImage = Image<typename TImage::PixelType, TImage::ImageDimension>>
213  : public otb::LabelMapFeaturesFunctorImageFilter<TImage, typename Functor::ShapeAttributesLabelObjectFunctor<typename TImage::LabelObjectType, TLabelImage>>
214 {
215 public:
217  typedef TImage ImageType;
218  typedef typename ImageType::LabelObjectType LabelObjectType;
219  typedef typename ImageType::RegionType InputImageRegionType;
220  typedef TLabelImage LabelImageType;
222 
226  typedef itk::SmartPointer<Self> Pointer;
227  typedef itk::SmartPointer<const Self> ConstPointer;
228 
229  typedef typename ImageType::Pointer ImagePointer;
230 
232  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
233 
235  itkNewMacro(Self);
236 
239 
244  void SetComputeFeretDiameter(bool flag);
245  bool GetComputeFeretDiameter() const;
246  itkBooleanMacro(ComputeFeretDiameter);
248 
253  void SetComputePerimeter(bool flag);
254  bool GetComputePerimeter() const;
255  itkBooleanMacro(ComputePerimeter);
257 
262  void SetComputePolygon(bool flag);
263  bool GetComputePolygon() const;
264  itkBooleanMacro(ComputePolygon);
266 
271  void SetComputeFlusser(bool flag);
272  bool GetComputeFlusser() const;
273  itkBooleanMacro(ComputeFlusser);
275 
276 
278  void SetReducedAttributeSet(bool flag);
279  bool GetReducedAttributeSet() const;
280  itkBooleanMacro(ReducedAttributeSet);
282 
285  void SetLabelImage(const TLabelImage*);
286  const TLabelImage* GetLabelImage() const;
288 
289 protected:
292  {
293  }
294 
297  {
298  }
299 
301  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
302 
303  void AllocateOutputs() override;
304 
306  void BeforeThreadedGenerateData() override;
307 
308  void GenerateInputRequestedRegion() override;
309 
310  void EnlargeOutputRequestedRegion(itk::DataObject*) override{};
311 
312 private:
313  ShapeAttributesLabelMapFilter(const Self&) = delete;
314  void operator=(const Self&) = delete;
315 
316 }; // end of class
317 
318 } // end namespace otb
319 
320 #ifndef OTB_MANUAL_INSTANTIATION
322 #endif
323 
324 #endif
otb::ShapeAttributesLabelMapFilter
This class is a fork of the itk::ShapeLabelMapFilter working with AttributesMapLabelObject.
Definition: otbShapeAttributesLabelMapFilter.h:212
otb::Functor::ShapeAttributesLabelObjectFunctor::PolygonType
TLabelObject::PolygonType PolygonType
Definition: otbShapeAttributesLabelMapFilter.h:62
otbShapeAttributesLabelMapFilter.hxx
otb::Functor::ShapeAttributesLabelObjectFunctor::PerimeterFromInterceptCount
double PerimeterFromInterceptCount(TMapIntercept &intercepts, const TSpacing &spacing)
Definition: otbShapeAttributesLabelMapFilter.hxx:821
otb::SimplifyPathFunctor
This filter performs a simplification of the input path.
Definition: otbSimplifyPathFunctor.h:54
otb::FlusserPathFunction
Calculate the Flusser's invariant parameters.
Definition: otbFlusserPathFunction.h:66
otbPolygon.h
otb::Functor::LabelObjectToPolygonFunctor
This class vectorizes a LabelObject to a Polygon.
Definition: otbLabelObjectToPolygonFunctor.h:62
otb::Functor::ShapeAttributesLabelObjectFunctor::DimensionType
unsigned int DimensionType
Definition: otbShapeAttributesLabelMapFilter.h:67
otbImage.h
otb::Functor::ShapeAttributesLabelObjectFunctor::operator!=
bool operator!=(const Self &self)
Definition: otbShapeAttributesLabelMapFilter.hxx:53
otb::Functor::ShapeAttributesLabelObjectFunctor::GetComputeFlusser
bool GetComputeFlusser() const
Definition: otbShapeAttributesLabelMapFilter.hxx:113
otb::LabelMapFeaturesFunctorImageFilter
This class applies a functor to compute new features.
Definition: otbLabelMapFeaturesFunctorImageFilter.h:53
otb::Functor::ShapeAttributesLabelObjectFunctor::hyperSpherePerimeter
static double hyperSpherePerimeter(double radius)
Definition: otbShapeAttributesLabelMapFilter.hxx:974
otb::Functor::ShapeAttributesLabelObjectFunctor::OffsetType
itk::Offset< TLabelObject::ImageDimension > OffsetType
Definition: otbShapeAttributesLabelMapFilter.h:72
otb::Functor::ShapeAttributesLabelObjectFunctor::GetReducedAttributeSet
bool GetReducedAttributeSet() const
Definition: otbShapeAttributesLabelMapFilter.hxx:141
otb::ShapeAttributesLabelMapFilter::EnlargeOutputRequestedRegion
void EnlargeOutputRequestedRegion(itk::DataObject *) override
Definition: otbShapeAttributesLabelMapFilter.h:310
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ShapeAttributesLabelObjectFunctor::MapIntercept3Type
std::map< Offset3Type, itk::SizeValueType, Offset3Type::LexicographicCompare > MapIntercept3Type
Definition: otbShapeAttributesLabelMapFilter.h:155
otbFlusserPathFunction.h
otb::Functor::ShapeAttributesLabelObjectFunctor::m_ComputePolygon
bool m_ComputePolygon
Definition: otbShapeAttributesLabelMapFilter.h:175
otb::Functor::ShapeAttributesLabelObjectFunctor::SetReducedAttributeSet
void SetReducedAttributeSet(bool flag)
Definition: otbShapeAttributesLabelMapFilter.hxx:134
otb::Functor::ShapeAttributesLabelObjectFunctor::MapIntercept2Type
std::map< Offset2Type, itk::SizeValueType, Offset2Type::LexicographicCompare > MapIntercept2Type
Definition: otbShapeAttributesLabelMapFilter.h:154
otb::Functor::ShapeAttributesLabelObjectFunctor::SetLabelImage
void SetLabelImage(const TLabelImage *image)
Definition: otbShapeAttributesLabelMapFilter.hxx:149
otb::Functor::ShapeAttributesLabelObjectFunctor::GetComputeFeretDiameter
bool GetComputeFeretDiameter() const
Definition: otbShapeAttributesLabelMapFilter.hxx:127
otb::Functor::ShapeAttributesLabelObjectFunctor::GetComputePerimeter
bool GetComputePerimeter() const
Definition: otbShapeAttributesLabelMapFilter.hxx:85
otb::Functor::ShapeAttributesLabelObjectFunctor::m_ComputePerimeter
bool m_ComputePerimeter
Definition: otbShapeAttributesLabelMapFilter.h:169
otb::Functor::ShapeAttributesLabelObjectFunctor::SimplifyPolygonFunctorType
SimplifyPathFunctor< PolygonType, PolygonType > SimplifyPolygonFunctorType
Definition: otbShapeAttributesLabelMapFilter.h:65
otb::Functor::ShapeAttributesLabelObjectFunctor::SetComputeFeretDiameter
void SetComputeFeretDiameter(bool flag)
Definition: otbShapeAttributesLabelMapFilter.hxx:120
otb::Functor::ShapeAttributesLabelObjectFunctor::gammaN2p1
static double gammaN2p1(long n)
Definition: otbShapeAttributesLabelMapFilter.hxx:950
otb::Functor::ShapeAttributesLabelObjectFunctor::Spacing2Type
itk::Vector< double, 2 > Spacing2Type
Definition: otbShapeAttributesLabelMapFilter.h:152
otb::ShapeAttributesLabelMapFilter::~ShapeAttributesLabelMapFilter
~ShapeAttributesLabelMapFilter() override
Definition: otbShapeAttributesLabelMapFilter.h:296
otb::Functor::ShapeAttributesLabelObjectFunctor::operator()
void operator()(LabelObjectType *lo)
Definition: otbShapeAttributesLabelMapFilter.hxx:166
otb::Functor::ShapeAttributesLabelObjectFunctor::m_ComputeFlusser
bool m_ComputeFlusser
Definition: otbShapeAttributesLabelMapFilter.h:172
otb::Functor::ShapeAttributesLabelObjectFunctor::GetLabelImage
const TLabelImage * GetLabelImage() const
Definition: otbShapeAttributesLabelMapFilter.hxx:156
otb::Functor::ShapeAttributesLabelObjectFunctor::ImageDimension
static const unsigned int ImageDimension
Definition: otbShapeAttributesLabelMapFilter.h:70
otb::Functor::ShapeAttributesLabelObjectFunctor::ConstLineIteratorType
LabelObjectType::ConstLineIterator ConstLineIteratorType
Definition: otbShapeAttributesLabelMapFilter.h:56
otb::Functor::ShapeAttributesLabelObjectFunctor::m_LabelImage
LabelImageType::ConstPointer m_LabelImage
Definition: otbShapeAttributesLabelMapFilter.h:181
otb::Functor::ShapeAttributesLabelObjectFunctor::PolygonFunctorType
Functor::LabelObjectToPolygonFunctor< LabelObjectType, PolygonType > PolygonFunctorType
Definition: otbShapeAttributesLabelMapFilter.h:63
otb::Functor::ShapeAttributesLabelObjectFunctor::ComputePerimeter
double ComputePerimeter(LabelObjectType *labelObject, const RegionType &region)
Definition: otbShapeAttributesLabelMapFilter.hxx:655
otb::ShapeAttributesLabelMapFilter::Self
ShapeAttributesLabelMapFilter Self
Definition: otbShapeAttributesLabelMapFilter.h:224
otb::ShapeAttributesLabelMapFilter::FunctorType
Functor::ShapeAttributesLabelObjectFunctor< LabelObjectType, LabelImageType > FunctorType
Definition: otbShapeAttributesLabelMapFilter.h:221
otbLabelObjectToPolygonFunctor.h
otb::Functor::ShapeAttributesLabelObjectFunctor::LabelImageType
TLabelImage LabelImageType
Definition: otbShapeAttributesLabelMapFilter.h:59
otb::Functor::ShapeAttributesLabelObjectFunctor::SetComputeFlusser
void SetComputeFlusser(bool flag)
Definition: otbShapeAttributesLabelMapFilter.hxx:106
otb::Functor::ShapeAttributesLabelObjectFunctor::factorial
static long factorial(long n)
Definition: otbShapeAttributesLabelMapFilter.hxx:926
otb::ShapeAttributesLabelMapFilter::ImageType
TImage ImageType
Definition: otbShapeAttributesLabelMapFilter.h:217
otb::Functor::ShapeAttributesLabelObjectFunctor::LabelObjectType
TLabelObject LabelObjectType
Definition: otbShapeAttributesLabelMapFilter.h:53
otb::Functor::ShapeAttributesLabelObjectFunctor::Spacing3Type
itk::Vector< double, 3 > Spacing3Type
Definition: otbShapeAttributesLabelMapFilter.h:153
otb::Functor::ShapeAttributesLabelObjectFunctor::Offset3Type
itk::Offset< 3 > Offset3Type
Definition: otbShapeAttributesLabelMapFilter.h:151
otb::Functor::ShapeAttributesLabelObjectFunctor::~ShapeAttributesLabelObjectFunctor
virtual ~ShapeAttributesLabelObjectFunctor()
Definition: otbShapeAttributesLabelMapFilter.h:78
otb::Functor::ShapeAttributesLabelObjectFunctor::Self
ShapeAttributesLabelObjectFunctor Self
Definition: otbShapeAttributesLabelMapFilter.h:50
otb::Functor::ShapeAttributesLabelObjectFunctor::doubleFactorial
static long doubleFactorial(long n)
Definition: otbShapeAttributesLabelMapFilter.hxx:938
otb::Functor::ShapeAttributesLabelObjectFunctor
Functor to compute shape attributes of one LabelObject.
Definition: otbShapeAttributesLabelMapFilter.h:46
otbSimplifyPathFunctor.h
otb::ShapeAttributesLabelMapFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbShapeAttributesLabelMapFilter.h:227
otb::Functor::ShapeAttributesLabelObjectFunctor::SetComputePolygon
void SetComputePolygon(bool flag)
Definition: otbShapeAttributesLabelMapFilter.hxx:92
otb::ShapeAttributesLabelMapFilter::Superclass
LabelMapFeaturesFunctorImageFilter< ImageType, FunctorType > Superclass
Definition: otbShapeAttributesLabelMapFilter.h:225
otb::Functor::ShapeAttributesLabelObjectFunctor::RegionType
itk::ImageRegion< TLabelObject::ImageDimension > RegionType
Definition: otbShapeAttributesLabelMapFilter.h:71
otb::Functor::ShapeAttributesLabelObjectFunctor::Offset2Type
itk::Offset< 2 > Offset2Type
Definition: otbShapeAttributesLabelMapFilter.h:150
otb::Functor::ShapeAttributesLabelObjectFunctor::ShapeAttributesLabelObjectFunctor
ShapeAttributesLabelObjectFunctor()
Definition: otbShapeAttributesLabelMapFilter.hxx:46
otb::Functor::ShapeAttributesLabelObjectFunctor::operator==
bool operator==(const Self &self)
Definition: otbShapeAttributesLabelMapFilter.hxx:70
otb::Functor::ShapeAttributesLabelObjectFunctor::hyperSphereRadiusFromVolume
static double hyperSphereRadiusFromVolume(double volume)
Definition: otbShapeAttributesLabelMapFilter.hxx:981
otb::ShapeAttributesLabelMapFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbShapeAttributesLabelMapFilter.h:226
otb::Functor::ShapeAttributesLabelObjectFunctor::FlusserPathFunctionType
FlusserPathFunction< PolygonType > FlusserPathFunctionType
Definition: otbShapeAttributesLabelMapFilter.h:64
otb::Functor::ShapeAttributesLabelObjectFunctor::m_ReducedAttributeSet
bool m_ReducedAttributeSet
Definition: otbShapeAttributesLabelMapFilter.h:178
otb::Functor::ShapeAttributesLabelObjectFunctor::GetComputePolygon
bool GetComputePolygon() const
Definition: otbShapeAttributesLabelMapFilter.hxx:99
otb::Functor::ShapeAttributesLabelObjectFunctor::hyperSphereVolume
static double hyperSphereVolume(double radius)
Definition: otbShapeAttributesLabelMapFilter.hxx:966
otbLabelMapFeaturesFunctorImageFilter.h
otb::ShapeAttributesLabelMapFilter::ImagePointer
ImageType::Pointer ImagePointer
Definition: otbShapeAttributesLabelMapFilter.h:229
otb::ShapeAttributesLabelMapFilter::InputImageRegionType
ImageType::RegionType InputImageRegionType
Definition: otbShapeAttributesLabelMapFilter.h:219
otb::Functor::ShapeAttributesLabelObjectFunctor::SetComputePerimeter
void SetComputePerimeter(bool flag)
Definition: otbShapeAttributesLabelMapFilter.hxx:78
otb::ShapeAttributesLabelMapFilter::LabelObjectType
ImageType::LabelObjectType LabelObjectType
Definition: otbShapeAttributesLabelMapFilter.h:218
otb::ShapeAttributesLabelMapFilter::LabelImageType
TLabelImage LabelImageType
Definition: otbShapeAttributesLabelMapFilter.h:220
otb::ShapeAttributesLabelMapFilter::ShapeAttributesLabelMapFilter
ShapeAttributesLabelMapFilter()
Definition: otbShapeAttributesLabelMapFilter.h:291
otb::Functor::ShapeAttributesLabelObjectFunctor::m_ComputeFeretDiameter
bool m_ComputeFeretDiameter
Definition: otbShapeAttributesLabelMapFilter.h:166