OTB  9.0.0
Orfeo Toolbox
otbVectorDataToLabelImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbVectorDataToLabelImageFilter_h
22 #define otbVectorDataToLabelImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
25 #include "itkImageRegionIterator.h"
26 #include "otbMacro.h"
27 
28 #include "otbVectorData.h"
29 
30 #include "gdal.h"
31 #include "ogr_api.h"
32 #include <string>
33 
34 namespace otb
35 {
36 
53 template <class TVectorData, class TOutputImage>
54 class ITK_EXPORT VectorDataToLabelImageFilter : public itk::ImageSource<TOutputImage>
55 {
56 public:
59  typedef itk::ImageSource<TOutputImage> Superclass;
60  typedef itk::SmartPointer<Self> Pointer;
61  typedef itk::SmartPointer<const Self> ConstPointer;
62 
64  itkTypeMacro(VectorDataToLabelImageFilter, itk::ImageSource);
65 
67  itkNewMacro(Self);
68 
69  typedef TOutputImage OutputImageType;
70  typedef typename OutputImageType::Pointer OutputImagePointer;
71  typedef typename OutputImageType::SizeType OutputSizeType;
72  typedef typename OutputImageType::IndexType OutputIndexType;
73  typedef typename OutputImageType::SpacingType OutputSpacingType;
74  typedef typename OutputImageType::PointType OutputOriginType;
75  typedef typename OutputImageType::RegionType OutputImageRegionType;
76  typedef typename OutputImageType::PixelType OutputImagePixelType;
77  typedef typename OutputImageType::InternalPixelType OutputImageInternalPixelType;
78 
80  typedef TVectorData VectorDataType;
81  typedef typename VectorDataType::DataTreeType DataTreeType;
82  typedef typename DataTreeType::TreeNodeType InternalTreeNodeType;
83  typedef typename DataTreeType::Pointer DataTreePointerType;
84  typedef typename DataTreeType::ConstPointer DataTreeConstPointerType;
85 
86  typedef itk::ImageBase<OutputImageType::ImageDimension> ImageBaseType;
87 
89  const VectorDataType* GetInput(unsigned int idx);
90 
92  virtual void AddVectorData(const VectorDataType* vd);
93 
95  itkSetMacro(OutputSize, OutputSizeType);
96 
98  itkGetConstReferenceMacro(OutputSize, OutputSizeType);
99 
103  itkSetMacro(OutputOrigin, OutputOriginType);
104  virtual void SetOutputOrigin(const double origin[2]);
105  virtual void SetOutputOrigin(const float origin[2]);
107 
108  itkGetConstReferenceMacro(OutputOrigin, OutputOriginType);
109 
113  virtual void SetOutputSpacing(const OutputSpacingType& spacing);
114  virtual void SetOutputSpacing(const double spacing[2]);
115  virtual void SetOutputSpacing(const float spacing[2]);
117 
119  itkSetStringMacro(OutputProjectionRef);
120  itkGetStringMacro(OutputProjectionRef);
122 
123  itkSetStringMacro(BurnAttribute);
124  itkGetStringMacro(BurnAttribute);
125 
127  itkSetMacro(BackgroundValue, OutputImageInternalPixelType);
128  itkGetMacro(BackgroundValue, OutputImageInternalPixelType);
130 
132  itkSetMacro(DefaultBurnValue, OutputImageInternalPixelType);
133  itkGetMacro(DefaultBurnValue, OutputImageInternalPixelType);
135 
137  itkSetMacro(AllTouchedMode, bool);
138  itkGetConstReferenceMacro(AllTouchedMode, bool);
139  itkBooleanMacro(AllTouchedMode);
141 
143  template <class ImagePointerType>
144  void SetOutputParametersFromImage(const ImagePointerType image);
145 
146 protected:
147  void GenerateData() override;
148 
151  {
152  // Destroy the geometries stored
153  for (unsigned int idx = 0; idx < m_SrcDataSetGeometries.size(); ++idx)
154  {
155  OGR_G_DestroyGeometry(m_SrcDataSetGeometries[idx]);
156  }
157 
158  if (m_OGRDataSourcePointer != nullptr)
159  {
160  GDALClose(m_OGRDataSourcePointer);
161  }
162  }
163 
164  void GenerateOutputInformation() override;
165 
166  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
167 
168 private:
169  VectorDataToLabelImageFilter(const Self&) = delete;
170  void operator=(const Self&) = delete;
171 
173 
174  // Vector Of OGRGeometyH
175  std::vector<OGRGeometryH> m_SrcDataSetGeometries;
176 
177  std::vector<double> m_BurnValues;
178  std::vector<double> m_FullBurnValues;
179  std::vector<int> m_BandsToBurn;
180 
181  // Field used to extract the burn value
182  std::string m_BurnAttribute;
183 
184  // Default burn value
186 
187  // Background value
189 
190  // All touched mode
192 
193  // Output params
195  OutputSpacingType m_OutputSpacing{0.0};
196  OutputOriginType m_OutputOrigin{0.0};
197  OutputSizeType m_OutputSize{0,0};
199 }; // end of class VectorDataToLabelImageFilter
200 
201 } // end of namespace otb
202 
203 
204 #ifndef OTB_MANUAL_INSTANTIATION
206 #endif
207 
208 #endif
otb::VectorDataToLabelImageFilter::OutputSpacingType
OutputImageType::SpacingType OutputSpacingType
Definition: otbVectorDataToLabelImageFilter.h:73
otb::VectorDataToLabelImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbVectorDataToLabelImageFilter.h:75
otb::VectorDataToLabelImageFilter::OutputSizeType
OutputImageType::SizeType OutputSizeType
Definition: otbVectorDataToLabelImageFilter.h:71
otb::VectorDataToLabelImageFilter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbVectorDataToLabelImageFilter.h:70
otb::VectorDataToLabelImageFilter::m_SrcDataSetGeometries
std::vector< OGRGeometryH > m_SrcDataSetGeometries
Definition: otbVectorDataToLabelImageFilter.h:175
otb::VectorDataToLabelImageFilter::DataTreePointerType
DataTreeType::Pointer DataTreePointerType
Definition: otbVectorDataToLabelImageFilter.h:83
otb::VectorDataToLabelImageFilter::m_AllTouchedMode
bool m_AllTouchedMode
Definition: otbVectorDataToLabelImageFilter.h:191
otb::VectorDataToLabelImageFilter::DataTreeType
VectorDataType::DataTreeType DataTreeType
Definition: otbVectorDataToLabelImageFilter.h:81
otb::VectorDataToLabelImageFilter::m_BandsToBurn
std::vector< int > m_BandsToBurn
Definition: otbVectorDataToLabelImageFilter.h:179
otb::VectorDataToLabelImageFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbVectorDataToLabelImageFilter.h:76
otb::VectorDataToLabelImageFilter::m_FullBurnValues
std::vector< double > m_FullBurnValues
Definition: otbVectorDataToLabelImageFilter.h:178
otb::VectorDataToLabelImageFilter::VectorDataType
TVectorData VectorDataType
Definition: otbVectorDataToLabelImageFilter.h:80
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VectorDataToLabelImageFilter::m_BurnAttribute
std::string m_BurnAttribute
Definition: otbVectorDataToLabelImageFilter.h:182
otb::VectorDataToLabelImageFilter::~VectorDataToLabelImageFilter
~VectorDataToLabelImageFilter() override
Definition: otbVectorDataToLabelImageFilter.h:150
otbMacro.h
otb::VectorDataToLabelImageFilter::m_OGRDataSourcePointer
GDALDataset * m_OGRDataSourcePointer
Definition: otbVectorDataToLabelImageFilter.h:172
otb::VectorDataToLabelImageFilter::ImageBaseType
itk::ImageBase< OutputImageType::ImageDimension > ImageBaseType
Definition: otbVectorDataToLabelImageFilter.h:86
otb::VectorDataToLabelImageFilter::m_BurnValues
std::vector< double > m_BurnValues
Definition: otbVectorDataToLabelImageFilter.h:177
otb::VectorDataToLabelImageFilter::m_OutputProjectionRef
std::string m_OutputProjectionRef
Definition: otbVectorDataToLabelImageFilter.h:194
otb::VectorDataToLabelImageFilter::DataTreeConstPointerType
DataTreeType::ConstPointer DataTreeConstPointerType
Definition: otbVectorDataToLabelImageFilter.h:84
otb::VectorDataToLabelImageFilter::m_DefaultBurnValue
double m_DefaultBurnValue
Definition: otbVectorDataToLabelImageFilter.h:185
otb::VectorDataToLabelImageFilter
Burn geometries from the specified VectorData into raster.
Definition: otbVectorDataToLabelImageFilter.h:54
otb::VectorDataToLabelImageFilter::InternalTreeNodeType
DataTreeType::TreeNodeType InternalTreeNodeType
Definition: otbVectorDataToLabelImageFilter.h:82
otb::VectorDataToLabelImageFilter::m_OutputStartIndex
OutputIndexType m_OutputStartIndex
Definition: otbVectorDataToLabelImageFilter.h:198
otb::VectorDataToLabelImageFilter::m_BackgroundValue
OutputImageInternalPixelType m_BackgroundValue
Definition: otbVectorDataToLabelImageFilter.h:188
otbVectorData.h
otb::VectorDataToLabelImageFilter::Superclass
itk::ImageSource< TOutputImage > Superclass
Definition: otbVectorDataToLabelImageFilter.h:59
otb::VectorDataToLabelImageFilter::OutputIndexType
OutputImageType::IndexType OutputIndexType
Definition: otbVectorDataToLabelImageFilter.h:72
otb::VectorDataToLabelImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbVectorDataToLabelImageFilter.h:67
otb::VectorDataToLabelImageFilter::Self
VectorDataToLabelImageFilter Self
Definition: otbVectorDataToLabelImageFilter.h:58
otb::VectorDataToLabelImageFilter::OutputImageInternalPixelType
OutputImageType::InternalPixelType OutputImageInternalPixelType
Definition: otbVectorDataToLabelImageFilter.h:77
otb::VectorDataToLabelImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbVectorDataToLabelImageFilter.h:61
otb::VectorDataToLabelImageFilter::OutputOriginType
OutputImageType::PointType OutputOriginType
Definition: otbVectorDataToLabelImageFilter.h:74
otb::VectorDataToLabelImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVectorDataToLabelImageFilter.h:60
otbVectorDataToLabelImageFilter.hxx