OTB  9.0.0
Orfeo Toolbox
otbPhysicalToRPCSensorModelImageFilter.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 otbPhysicalToRPCSensorModelImageFilter_hxx
22 #define otbPhysicalToRPCSensorModelImageFilter_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TImage>
31 {
32  // This filter does not modify the image buffer, but only its
33  // metadata.Therefore, it can be run inplace to reduce memory print.
34  // CastImageFilter has InPlaceOff by default (see UnaryFunctorImgeFilter constructor)
35  this->InPlaceOn();
36 
37  // Initialize the rpc estimator
38  m_GCPsToSensorModelFilter = GCPsToSensorModelType::New();
39 
40  // Initialize the gridSize : 16 points to have a correct estimation
41  // of the model
42  m_GridSize.Fill(4);
43 
44  // Flag initilalisation
45  m_OutputInformationGenerated = false;
46 }
47 
48 template <class TImage>
50 {
51 }
52 
53 template <class TImage>
55 {
56  Superclass::GenerateOutputInformation();
57 
58  if (!m_OutputInformationGenerated)
59  {
60 
61  // Get the input
62  ImageType* input = const_cast<ImageType*>(this->GetInput());
63 
64  // Build the grid
65  // Generate GCPs from physical sensor model
66  RSTransformPointerType rsTransform = RSTransformType::New();
67  rsTransform->SetInputImageMetadata(&(input->GetImageMetadata()));
68  rsTransform->InstantiateTransform();
69 
70  // Compute the size of the grid
71  typename ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
72  double gridSpacingX = size[0] / m_GridSize[0];
73  double gridSpacingY = size[1] / m_GridSize[1];
74 
75  for (unsigned int px = 0; px < m_GridSize[0]; ++px)
76  {
77  for (unsigned int py = 0; py < m_GridSize[1]; ++py)
78  {
79  PointType inputPoint = input->GetOrigin();
80  inputPoint[0] += (px * gridSpacingX + 0.5) * input->GetSignedSpacing()[0];
81  inputPoint[1] += (py * gridSpacingY + 0.5) * input->GetSignedSpacing()[1];
82  PointType outputPoint = rsTransform->TransformPoint(inputPoint);
83  m_GCPsToSensorModelFilter->AddGCP(inputPoint, outputPoint);
84  }
85  }
86 
87  m_GCPsToSensorModelFilter->SetInput(input);
88  m_GCPsToSensorModelFilter->UpdateOutputInformation();
89 
90  otbGenericMsgDebugMacro(<< "RPC model estimated. RMS ground error: " << m_GCPsToSensorModelFilter->GetRMSGroundError()
91  << ", Mean error: " << m_GCPsToSensorModelFilter->GetMeanError());
92 
93 
94  this->GetOutput()->SetImageMetadata(m_GCPsToSensorModelFilter->GetOutput()->GetImageMetadata());
95 
96  // put the flag to true
97  m_OutputInformationGenerated = true;
98  }
99 }
100 
101 template <class TImage>
103 {
104  Superclass::Modified();
105  m_OutputInformationGenerated = false;
106 }
107 
108 template <class TImage>
109 void PhysicalToRPCSensorModelImageFilter<TImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
110 {
111  Superclass::PrintSelf(os, indent);
112 }
113 
114 } // end of namespace otb
115 
116 #endif
otb::PhysicalToRPCSensorModelImageFilter::Modified
void Modified() const override
Definition: otbPhysicalToRPCSensorModelImageFilter.hxx:102
otb::PhysicalToRPCSensorModelImageFilter::PhysicalToRPCSensorModelImageFilter
PhysicalToRPCSensorModelImageFilter()
Definition: otbPhysicalToRPCSensorModelImageFilter.hxx:30
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PhysicalToRPCSensorModelImageFilter::~PhysicalToRPCSensorModelImageFilter
~PhysicalToRPCSensorModelImageFilter() override
Definition: otbPhysicalToRPCSensorModelImageFilter.hxx:49
otb::PhysicalToRPCSensorModelImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbPhysicalToRPCSensorModelImageFilter.hxx:109
otbGenericMsgDebugMacro
#define otbGenericMsgDebugMacro(x)
Definition: otbMacro.h:63
otb::PhysicalToRPCSensorModelImageFilter::RSTransformPointerType
RSTransformType::Pointer RSTransformPointerType
Definition: otbPhysicalToRPCSensorModelImageFilter.h:93
otb::PhysicalToRPCSensorModelImageFilter::ImageType
TImage ImageType
Definition: otbPhysicalToRPCSensorModelImageFilter.h:75
otb::PhysicalToRPCSensorModelImageFilter::PointType
ImageType::PointType PointType
Definition: otbPhysicalToRPCSensorModelImageFilter.h:79
otb::PhysicalToRPCSensorModelImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbPhysicalToRPCSensorModelImageFilter.hxx:54
otbPhysicalToRPCSensorModelImageFilter.h