Orfeo Toolbox  4.0
otbPhysicalToRPCSensorModelImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbPhysicalToRPCSensorModelImageFilter_txx
19 #define __otbPhysicalToRPCSensorModelImageFilter_txx
20 
22 #include "otbDEMHandler.h"
23 
24 namespace otb {
25 
26 template <class TImage>
29 {
30  // This filter does not modify the image buffer, but only its
31  // metadata.Therefore, it can be run inplace to reduce memory print.
32  // CastImageFilter has InPlaceOff by default (see UnaryFunctorImgeFilter constructor)
33  this->InPlaceOn();
34 
35  // Initialize the rpc estimator
36  m_GCPsToSensorModelFilter = GCPsToSensorModelType::New();
37 
38  // Initialize the gridSize : 16 points to have a correct estimation
39  // of the model
40  m_GridSize.Fill(4);
41 
42  // Flag initilalisation
43  m_OutputInformationGenerated = false;
44 }
45 
46 template <class TImage>
49 {
50 }
51 
52 template <class TImage>
53 void
56 {
57  Superclass::GenerateOutputInformation();
58 
59  if(!m_OutputInformationGenerated)
60  {
61 
62  // Get the input
63  ImageType * input = const_cast<ImageType*>(this->GetInput());
64 
65  // Build the grid
66  // Generate GCPs from physical sensor model
67  RSTransformPointerType rsTransform = RSTransformType::New();
68  rsTransform->SetInputKeywordList(input->GetImageKeywordlist());
69  rsTransform->InstanciateTransform();
70 
71  // Compute the size of the grid
72  typename ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
73  double gridSpacingX = size[0]/m_GridSize[0];
74  double gridSpacingY = size[1]/m_GridSize[1];
75 
76  for(unsigned int px = 0; px<m_GridSize[0]; ++px)
77  {
78  for(unsigned int py = 0; py<m_GridSize[1]; ++py)
79  {
80  PointType inputPoint = input->GetOrigin();
81  inputPoint[0] += (px * gridSpacingX + 0.5) * input->GetSpacing()[0];
82  inputPoint[1] += (py * gridSpacingY + 0.5) * input->GetSpacing()[1];
83  PointType outputPoint = rsTransform->TransformPoint(inputPoint);
84  m_GCPsToSensorModelFilter->AddGCP(inputPoint, outputPoint);
85  }
86  }
87 
88  m_GCPsToSensorModelFilter->SetInput(input);
89  m_GCPsToSensorModelFilter->UpdateOutputInformation();
90 
91  otbGenericMsgDebugMacro(<<"RPC model estimated. RMS ground error: "<<m_GCPsToSensorModelFilter->GetRMSGroundError()
92  <<", Mean error: "<<m_GCPsToSensorModelFilter->GetMeanError());
93 
94  // Encapsulate the keywordlist
95  itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary();
96  itk::EncapsulateMetaData<ImageKeywordlist>(dict, MetaDataKey::OSSIMKeywordlistKey,
97  m_GCPsToSensorModelFilter->GetKeywordlist());
98 
99  // put the flag to true
100  m_OutputInformationGenerated = true;
101  }
102 }
103 
104 template <class TImage>
105 void
108 {
109  Superclass::Modified();
110  m_OutputInformationGenerated= false;
111 }
112 
113 template <class TImage>
114 void
116 ::PrintSelf(std::ostream& os, itk::Indent indent) const
117 {
118  Superclass::PrintSelf(os, indent);
119 }
120 
121 } // end of namespace otb
122 
123 #endif

Generated at Sat Mar 8 2014 16:13:02 for Orfeo Toolbox with doxygen 1.8.3.1