OTB  10.0.0
Orfeo Toolbox
otbVectorDataToLabelImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 
83  typedef itk::ImageBase<OutputImageType::ImageDimension> ImageBaseType;
84 
86  const VectorDataType* GetInput(unsigned int idx);
87 
89  virtual void AddVectorData(const VectorDataType* vd);
90 
92  itkSetMacro(OutputSize, OutputSizeType);
93 
95  itkGetConstReferenceMacro(OutputSize, OutputSizeType);
96 
100  itkSetMacro(OutputOrigin, OutputOriginType);
101  virtual void SetOutputOrigin(const double origin[2]);
102  virtual void SetOutputOrigin(const float origin[2]);
104 
105  itkGetConstReferenceMacro(OutputOrigin, OutputOriginType);
106 
110  virtual void SetOutputSpacing(const OutputSpacingType& spacing);
111  virtual void SetOutputSpacing(const double spacing[2]);
112  virtual void SetOutputSpacing(const float spacing[2]);
114 
116  itkSetStringMacro(OutputProjectionRef);
117  itkGetStringMacro(OutputProjectionRef);
119 
120  itkSetStringMacro(BurnAttribute);
121  itkGetStringMacro(BurnAttribute);
122 
124  itkSetMacro(BackgroundValue, OutputImageInternalPixelType);
125  itkGetMacro(BackgroundValue, OutputImageInternalPixelType);
127 
129  itkSetMacro(DefaultBurnValue, OutputImageInternalPixelType);
130  itkGetMacro(DefaultBurnValue, OutputImageInternalPixelType);
132 
134  itkSetMacro(AllTouchedMode, bool);
135  itkGetConstReferenceMacro(AllTouchedMode, bool);
136  itkBooleanMacro(AllTouchedMode);
138 
140  template <class ImagePointerType>
141  void SetOutputParametersFromImage(const ImagePointerType image);
142 
143 protected:
144  void GenerateData() override;
145 
148  {
149  // Destroy the geometries stored
150  for (unsigned int idx = 0; idx < m_SrcDataSetGeometries.size(); ++idx)
151  {
152  OGR_G_DestroyGeometry(m_SrcDataSetGeometries[idx]);
153  }
154 
155  if (m_OGRDataSourcePointer != nullptr)
156  {
157  GDALClose(m_OGRDataSourcePointer);
158  }
159  }
160 
161  void GenerateOutputInformation() override;
162 
163  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
164 
165 private:
167  void operator=(const Self&) = delete;
168 
170 
171  // Vector Of OGRGeometyH
172  std::vector<OGRGeometryH> m_SrcDataSetGeometries;
173 
174  std::vector<double> m_BurnValues;
175  std::vector<double> m_FullBurnValues;
176  std::vector<int> m_BandsToBurn;
177 
178  // Field used to extract the burn value
179  std::string m_BurnAttribute;
180 
181  // Default burn value
183 
184  // Background value
186 
187  // All touched mode
189 
190  // Output params
192  OutputSpacingType m_OutputSpacing{0.0};
193  OutputOriginType m_OutputOrigin{0.0};
194  OutputSizeType m_OutputSize{0,0};
196 }; // end of class VectorDataToLabelImageFilter
197 
198 } // end of namespace otb
199 
200 
201 #ifndef OTB_MANUAL_INSTANTIATION
203 #endif
204 
205 #endif
Burn geometries from the specified VectorData into raster.
OutputImageType::InternalPixelType OutputImageInternalPixelType
VectorDataToLabelImageFilter(const Self &)=delete
itk::ImageSource< TOutputImage > Superclass
void operator=(const Self &)=delete
itk::SmartPointer< const Self > ConstPointer
itk::ImageBase< OutputImageType::ImageDimension > ImageBaseType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.