OTB  10.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-2024 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 
25 #include "itkConfigure.h"
26 
28 #include "otbImage.h"
29 #include "otbPolygon.h"
31 #include "otbFlusserPathFunction.h"
32 #include "otbSimplifyPathFunctor.h"
33 
34 namespace otb
35 {
36 
37 namespace Functor
38 {
48 template< unsigned int VOffsetDimension >
50 {
51 public:
52  bool operator()(itk::Offset< VOffsetDimension > const & l,
53  itk::Offset< VOffsetDimension > const & r) const
54  {
55  for ( unsigned int i = 0; i < VOffsetDimension; ++i ) {
56  if ( l[i] < r[i] ) {
57  return true;
58  }
59  else if ( l[i] > r[i] ) {
60  return false;
61  }
62  }
63  return false;
64  }
65 };
66 
74 template <class TLabelObject, class TLabelImage>
76 {
77 public:
80 
82  typedef TLabelObject LabelObjectType;
83 
85  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
86 
88  typedef TLabelImage LabelImageType;
89 
91  typedef typename TLabelObject::PolygonType PolygonType;
95 
96  typedef unsigned int DimensionType;
97 
99  itkStaticConstMacro(ImageDimension, unsigned int, TLabelObject::ImageDimension);
100  typedef itk::ImageRegion< TLabelObject::ImageDimension > RegionType;
101  typedef itk::Offset< TLabelObject::ImageDimension > OffsetType;
103 
106 
109  {
110  }
111 
113  bool operator!=(const Self& self);
114  bool operator==(const Self& self);
116 
118  void SetComputePerimeter(bool flag);
119 
121  bool GetComputePerimeter() const;
122 
124  void SetComputeFlusser(bool flag);
125 
127  bool GetComputeFlusser() const;
128 
130  void SetComputePolygon(bool flag);
131 
133  bool GetComputePolygon() const;
134 
136  void SetComputeFeretDiameter(bool flag);
137 
139  bool GetComputeFeretDiameter() const;
140 
142  void SetReducedAttributeSet(bool flag);
143 
145  bool GetReducedAttributeSet() const;
146 
149  void SetLabelImage(const TLabelImage* image);
150 
152  const TLabelImage* GetLabelImage() const;
153 
157  inline void operator()(LabelObjectType* lo);
158 
159 private:
161  static long factorial(long n);
162 
164  static long doubleFactorial(long n);
165 
167  static double gammaN2p1(long n);
168 
170  static double hyperSphereVolume(double radius);
171 
173  static double hyperSpherePerimeter(double radius);
174 
176  static double hyperSphereRadiusFromVolume(double volume);
177 
178  double ComputePerimeter(LabelObjectType* labelObject, const RegionType& region);
179 
180  typedef itk::Offset<2> Offset2Type;
181  typedef itk::Offset<3> Offset3Type;
182  typedef itk::Vector<double, 2> Spacing2Type;
183  typedef itk::Vector<double, 3> Spacing3Type;
186  typedef std::map<Offset2Type, itk::SizeValueType, OffsetLexicographicCompare2> MapIntercept2Type;
187  typedef std::map<Offset3Type, itk::SizeValueType, OffsetLexicographicCompare3> MapIntercept3Type;
188  template<class TMapIntercept, class TSpacing> double PerimeterFromInterceptCount( TMapIntercept & intercepts, const TSpacing & spacing );
189 
190 #if !defined(ITK_DO_NOT_USE_PERIMETER_SPECIALIZATION)
191  double PerimeterFromInterceptCount(MapIntercept2Type& intercepts, const Spacing2Type spacing);
192  double PerimeterFromInterceptCount(MapIntercept3Type& intercepts, const Spacing3Type spacing);
193 #endif
194 
197 
200 
203 
206 
209 
211  typename LabelImageType::ConstPointer m_LabelImage;
212 };
213 
214 } // End namespace Functor
215 
241 template <class TImage, class TLabelImage = Image<typename TImage::PixelType, TImage::ImageDimension>>
243  : public otb::LabelMapFeaturesFunctorImageFilter<TImage, typename Functor::ShapeAttributesLabelObjectFunctor<typename TImage::LabelObjectType, TLabelImage>>
244 {
245 public:
247  typedef TImage ImageType;
248  typedef typename ImageType::LabelObjectType LabelObjectType;
249  typedef typename ImageType::RegionType InputImageRegionType;
250  typedef TLabelImage LabelImageType;
252 
256  typedef itk::SmartPointer<Self> Pointer;
257  typedef itk::SmartPointer<const Self> ConstPointer;
258 
259  typedef typename ImageType::Pointer ImagePointer;
260 
262  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
263 
265  itkNewMacro(Self);
266 
269 
274  void SetComputeFeretDiameter(bool flag);
275  bool GetComputeFeretDiameter() const;
276  itkBooleanMacro(ComputeFeretDiameter);
278 
283  void SetComputePerimeter(bool flag);
284  bool GetComputePerimeter() const;
285  itkBooleanMacro(ComputePerimeter);
287 
292  void SetComputePolygon(bool flag);
293  bool GetComputePolygon() const;
294  itkBooleanMacro(ComputePolygon);
296 
301  void SetComputeFlusser(bool flag);
302  bool GetComputeFlusser() const;
303  itkBooleanMacro(ComputeFlusser);
305 
306 
308  void SetReducedAttributeSet(bool flag);
309  bool GetReducedAttributeSet() const;
310  itkBooleanMacro(ReducedAttributeSet);
312 
315  void SetLabelImage(const TLabelImage*);
316  const TLabelImage* GetLabelImage() const;
318 
319 protected:
322  {
323  }
324 
327  {
328  }
329 
331  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
332 
333  void AllocateOutputs() override;
334 
336  void BeforeThreadedGenerateData() override;
337 
338  void GenerateInputRequestedRegion() override;
339 
340  void EnlargeOutputRequestedRegion(itk::DataObject*) override{};
341 
342 private:
344  void operator=(const Self&) = delete;
345 
346 }; // end of class
347 
348 } // end namespace otb
349 
350 #ifndef OTB_MANUAL_INSTANTIATION
352 #endif
353 
354 #endif
Calculate the Flusser's invariant parameters.
This class vectorizes a LabelObject to a Polygon.
Order Offset instances lexicographically.
bool operator()(itk::Offset< VOffsetDimension > const &l, itk::Offset< VOffsetDimension > const &r) const
Functor to compute shape attributes of one LabelObject.
std::map< Offset2Type, itk::SizeValueType, OffsetLexicographicCompare2 > MapIntercept2Type
Functor::LabelObjectToPolygonFunctor< LabelObjectType, PolygonType > PolygonFunctorType
otb::Functor::OffsetLexicographicCompare< 3 > OffsetLexicographicCompare3
double ComputePerimeter(LabelObjectType *labelObject, const RegionType &region)
itk::ImageRegion< TLabelObject::ImageDimension > RegionType
itk::Offset< TLabelObject::ImageDimension > OffsetType
otb::Functor::OffsetLexicographicCompare< TLabelObject::ImageDimension > OffsetLexicographicCompare
otb::Functor::OffsetLexicographicCompare< 2 > OffsetLexicographicCompare2
SimplifyPathFunctor< PolygonType, PolygonType > SimplifyPolygonFunctorType
double PerimeterFromInterceptCount(TMapIntercept &intercepts, const TSpacing &spacing)
std::map< Offset3Type, itk::SizeValueType, OffsetLexicographicCompare3 > MapIntercept3Type
This class applies a functor to compute new features.
This class is a fork of the itk::ShapeLabelMapFilter working with AttributesMapLabelObject.
LabelMapFeaturesFunctorImageFilter< ImageType, FunctorType > Superclass
Functor::ShapeAttributesLabelObjectFunctor< LabelObjectType, LabelImageType > FunctorType
ShapeAttributesLabelMapFilter(const Self &)=delete
void EnlargeOutputRequestedRegion(itk::DataObject *) override
void operator=(const Self &)=delete
This filter performs a simplification of the input path.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.