OTB  6.7.0
Orfeo Toolbox
otbImageToOSMVectorDataGenerator.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 // constructor
31 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 >
45 void
47 ::SetInput( const ImageType * input )
48 {
49  // Process object is not const-correct so the const_cast is required here
51  const_cast< ImageType* >( input ) );
52 }
53 
54 // Method to get the SampleList as DataObject
55 template < class TImage>
57 ::ImageType *
59 ::GetInput() const
60 {
61  if (this->GetNumberOfInputs() < 1)
62  {
63  return nullptr;
64  }
65 
66  return static_cast<const ImageType* >
67  (this->itk::ProcessObject::GetInput(0) );
68 }
69 
70 
71 template < class TImage>
72 void
75 {
76  // Get the extent of the image
77  this->EstimateImageExtent();
78 
79  this->SetWest(m_ImageExtent.minX);
80  this->SetSouth(m_ImageExtent.minY);
81  this->SetEast(m_ImageExtent.maxX);
82  this->SetNorth(m_ImageExtent.maxY);
83 
84  Superclass::GenerateData();
85 }
86 
87 template < class TImage>
88 void
91 {
92  // Get the input image
93  typename ImageType::ConstPointer input = this->GetInput();
94 
95  // Local generic RS Transform to project the 4 corners to WGS84
96  typedef otb::GenericRSTransform<> TransformType;
97  typename TransformType::Pointer transform = TransformType::New();
98  transform->SetInputKeywordList(input->GetImageKeywordlist());
99  transform->SetInputProjectionRef(input->GetProjectionRef());
100  transform->SetOutputProjectionRef(otb::SpatialReference::FromWGS84().ToWkt());
101  transform->InstantiateTransform();
102 
103  // Compute the 4 corners in the cartographic coordinate system
104  std::vector< IndexType> vindex;
105  std::vector<PointType> voutput;
106 
107  IndexType index1, index2, index3, index4;
108  SizeType size;
109 
110  // Image size
111  size = input->GetLargestPossibleRegion().GetSize();
112 
113  // project the 4 corners
114  index1 = input->GetLargestPossibleRegion().GetIndex();
115  index2 = input->GetLargestPossibleRegion().GetIndex();
116  index3 = input->GetLargestPossibleRegion().GetIndex();
117  index4 = input->GetLargestPossibleRegion().GetIndex();
118 
119  index2[0] += size[0] - 1;
120  index3[0] += size[0] - 1;
121  index3[1] += size[1] - 1;
122  index4[1] += size[1] - 1;
123 
124  vindex.push_back(index1);
125  vindex.push_back(index2);
126  vindex.push_back(index3);
127  vindex.push_back(index4);
128 
129  for (unsigned int i = 0; i < vindex.size(); ++i)
130  {
131  PointType physicalPoint;
132  input->TransformIndexToPhysicalPoint(vindex[i], physicalPoint);
133  otbMsgDevMacro( << " physical point "<< physicalPoint << " --> Transform "
134  << transform->TransformPoint(physicalPoint));
135  voutput.push_back(transform->TransformPoint(physicalPoint));
136  }
137 
138  // Compute the boundaries
139  double minX = voutput[0][0];
140  double maxX = voutput[0][0];
141  double minY = voutput[0][1];
142  double maxY = voutput[0][1];
143 
144  for (unsigned int i = 0; i < voutput.size(); ++i)
145  {
146  // Origins
147  if (minX > voutput[i][0])
148  minX = voutput[i][0];
149  if (minY > voutput[i][1])
150  minY = voutput[i][1];
151 
152  // Sizes
153  if (maxX < voutput[i][0])
154  maxX = voutput[i][0];
155 
156  if (maxY < voutput[i][1])
157  maxY = voutput[i][1];
158  }
159 
160  // Edit the output image extent type
161  m_ImageExtent.maxX = maxX;
162  m_ImageExtent.minX = minX;
163  m_ImageExtent.maxY = maxY;
164  m_ImageExtent.minY = minY;
165 }
166 
167 
168 } // End namespace otb
169 
170 #endif
static SpatialReference FromWGS84()
DataObject * GetInput(const DataObjectIdentifierType &key)
This is the class to handle generic remote sensing transform.
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
Helper class to compute the extent of the input image and use it to fill the bbox for the OSM request...
#define otbMsgDevMacro(x)
Definition: otbMacro.h:66