OTB  9.0.0
Orfeo Toolbox
otbImageToOSMVectorDataGenerator.hxx
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 otbImageToOSMVectorDataGenerator_hxx
22 #define otbImageToOSMVectorDataGenerator_hxx
23 
25 #include "otbSpatialReference.h"
26 #include "otbGenericRSTransform.h"
27 
28 namespace otb
29 {
30 
31 // constructor
32 template <class TImage>
34 {
35  this->SetNumberOfRequiredInputs(1);
36  this->SetNumberOfRequiredOutputs(1);
37 
38  m_ImageExtent.minX = 0;
39  m_ImageExtent.maxX = 0;
40  m_ImageExtent.minY = 0;
41  m_ImageExtent.maxY = 0;
42 }
43 
44 template <class TImage>
46 {
47  // Process object is not const-correct so the const_cast is required here
48  this->itk::ProcessObject::SetNthInput(0, const_cast<ImageType*>(input));
49 }
50 
51 // Method to get the SampleList as DataObject
52 template <class TImage>
54 {
55  if (this->GetNumberOfInputs() < 1)
56  {
57  return nullptr;
58  }
59 
60  return static_cast<const ImageType*>(this->itk::ProcessObject::GetInput(0));
61 }
62 
63 
64 template <class TImage>
66 {
67  // Get the extent of the image
68  this->EstimateImageExtent();
69 
70  this->SetWest(m_ImageExtent.minX);
71  this->SetSouth(m_ImageExtent.minY);
72  this->SetEast(m_ImageExtent.maxX);
73  this->SetNorth(m_ImageExtent.maxY);
74 
75  Superclass::GenerateData();
76 }
77 
78 template <class TImage>
80 {
81  // Get the input image
82  typename ImageType::ConstPointer input = this->GetInput();
83 
84  // Local generic RS Transform to project the 4 corners to WGS84
85  typedef otb::GenericRSTransform<> TransformType;
86  typename TransformType::Pointer transform = TransformType::New();
87  transform->SetInputImageMetadata(&(input->GetImageMetadata()));
88  transform->SetInputProjectionRef(input->GetProjectionRef());
89  transform->SetOutputProjectionRef(otb::SpatialReference::FromWGS84().ToWkt());
90  transform->InstantiateTransform();
91 
92  // Compute the 4 corners in the cartographic coordinate system
93  std::vector<IndexType> vindex;
94  std::vector<PointType> voutput;
95 
96  IndexType index1, index2, index3, index4;
97  SizeType size;
98 
99  // Image size
100  size = input->GetLargestPossibleRegion().GetSize();
101 
102  // project the 4 corners
103  index1 = input->GetLargestPossibleRegion().GetIndex();
104  index2 = input->GetLargestPossibleRegion().GetIndex();
105  index3 = input->GetLargestPossibleRegion().GetIndex();
106  index4 = input->GetLargestPossibleRegion().GetIndex();
107 
108  index2[0] += size[0] - 1;
109  index3[0] += size[0] - 1;
110  index3[1] += size[1] - 1;
111  index4[1] += size[1] - 1;
112 
113  vindex.push_back(index1);
114  vindex.push_back(index2);
115  vindex.push_back(index3);
116  vindex.push_back(index4);
117 
118  for (unsigned int i = 0; i < vindex.size(); ++i)
119  {
120  PointType physicalPoint;
121  input->TransformIndexToPhysicalPoint(vindex[i], physicalPoint);
122  otbMsgDevMacro(<< " physical point " << physicalPoint << " --> Transform " << transform->TransformPoint(physicalPoint));
123  voutput.push_back(transform->TransformPoint(physicalPoint));
124  }
125 
126  // Compute the boundaries
127  double minX = voutput[0][0];
128  double maxX = voutput[0][0];
129  double minY = voutput[0][1];
130  double maxY = voutput[0][1];
131 
132  for (unsigned int i = 0; i < voutput.size(); ++i)
133  {
134  // Origins
135  if (minX > voutput[i][0])
136  minX = voutput[i][0];
137  if (minY > voutput[i][1])
138  minY = voutput[i][1];
139 
140  // Sizes
141  if (maxX < voutput[i][0])
142  maxX = voutput[i][0];
143 
144  if (maxY < voutput[i][1])
145  maxY = voutput[i][1];
146  }
147 
148  // Edit the output image extent type
149  m_ImageExtent.maxX = maxX;
150  m_ImageExtent.minX = minX;
151  m_ImageExtent.maxY = maxY;
152  m_ImageExtent.minY = minY;
153 }
154 
155 
156 } // End namespace otb
157 
158 #endif
otb::ImageToOSMVectorDataGenerator::ImageToOSMVectorDataGenerator
ImageToOSMVectorDataGenerator()
Definition: otbImageToOSMVectorDataGenerator.hxx:33
otbImageToOSMVectorDataGenerator.h
otb::ImageToOSMVectorDataGenerator::GetInput
const ImageType * GetInput() const
Definition: otbImageToOSMVectorDataGenerator.hxx:53
otb::ImageToOSMVectorDataGenerator::ImageType
TImage ImageType
Definition: otbImageToOSMVectorDataGenerator.h:57
otb::ImageToOSMVectorDataGenerator::PointType
ImageType::PointType PointType
Definition: otbImageToOSMVectorDataGenerator.h:63
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbSpatialReference.h
otb::ImageToOSMVectorDataGenerator::GenerateData
void GenerateData() override
Definition: otbImageToOSMVectorDataGenerator.hxx:65
otb::GenericRSTransform
This is the class to handle generic remote sensing transform.
Definition: otbGenericRSTransform.h:57
otb::ImageToOSMVectorDataGenerator::EstimateImageExtent
void EstimateImageExtent()
Definition: otbImageToOSMVectorDataGenerator.hxx:79
otb::ImageToOSMVectorDataGenerator::SetInput
void SetInput(const ImageType *input)
Definition: otbImageToOSMVectorDataGenerator.hxx:45
otbGenericRSTransform.h
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::SpatialReference::FromWGS84
static SpatialReference FromWGS84()
otb::ImageToOSMVectorDataGenerator::SizeType
ImageType::SizeType SizeType
Definition: otbImageToOSMVectorDataGenerator.h:61
otb::ImageToOSMVectorDataGenerator::IndexType
ImageType::IndexType IndexType
Definition: otbImageToOSMVectorDataGenerator.h:62