From 71f5411f1c5eb1a2f94dde13cda2b269b2802ecc Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@c-s.fr>
Date: Wed, 12 Dec 2007 10:15:43 +0000
Subject: [PATCH] Correction erreurs sur l'example d'orthorectif

---
 .../Projections/otbOrthoRectificationFilter.h |  7 +++-
 .../otbOrthoRectificationFilter.txx           | 29 ++++++++++----
 .../Projections/OrthoRectificationExample.cxx | 38 +++----------------
 3 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/Code/Projections/otbOrthoRectificationFilter.h b/Code/Projections/otbOrthoRectificationFilter.h
index 3ba1f67e08..e4f33b8bf9 100644
--- a/Code/Projections/otbOrthoRectificationFilter.h
+++ b/Code/Projections/otbOrthoRectificationFilter.h
@@ -55,6 +55,7 @@ class ITK_EXPORT OrthoRectificationFilter : public itk::ImageToImageFilter< TInp
         typedef typename ChangeInfoFilterType::Pointer ChangeInfoFilterPointer;
         
         typedef typename OrthoRectificationFilterBaseType::InputImageType       InputImageType;
+	typedef typename OrthoRectificationFilterBaseType::OutputImageType       OutputImageType;
         typedef typename OrthoRectificationFilterBaseType::MapProjectionType    MapProjectionType;
         typedef typename OrthoRectificationFilterBaseType::InterpolatorType     InterpolatorType;
         typedef typename OrthoRectificationFilterBaseType::IndexType            IndexType;
@@ -148,9 +149,11 @@ class ITK_EXPORT OrthoRectificationFilter : public itk::ImageToImageFilter< TInp
         
         /** Main computation method */
         virtual void GenerateData(void);
-
+	
         /** Generate Output Information */
-        virtual void GenerateOutputInformation();
+        virtual void GenerateOutputInformation(void);
+
+	 virtual void GenerateInputRequestedRegion(void);
 
   private:
         OrthoRectificationFilter(const Self&); //purposely not implemented
diff --git a/Code/Projections/otbOrthoRectificationFilter.txx b/Code/Projections/otbOrthoRectificationFilter.txx
index aa941fce5e..4970a6cb53 100644
--- a/Code/Projections/otbOrthoRectificationFilter.txx
+++ b/Code/Projections/otbOrthoRectificationFilter.txx
@@ -91,7 +91,22 @@ OrthoRectificationFilter<       TInputImage,
         m_OrthoRectificationFilter->GenerateOutputInformation();
         this->GetOutput()->CopyInformation(m_OrthoRectificationFilter->GetOutput());
 }
-
+template <      class TInputImage, 
+	    	class TOutputImage, 
+	    	class TMapProjection, 
+	    	class TInterpolatorPrecision>
+void
+OrthoRectificationFilter<       TInputImage, 
+			   	TOutputImage, 
+			   	TMapProjection, 
+			   	TInterpolatorPrecision>
+::GenerateInputRequestedRegion(void)
+{
+  Superclass::GenerateInputRequestedRegion();
+  m_OrthoRectificationFilter->GetOutput()->UpdateOutputInformation();
+  m_OrthoRectificationFilter->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
+  m_OrthoRectificationFilter->GetOutput()->PropagateRequestedRegion();
+}
 
 
 
@@ -108,12 +123,12 @@ OrthoRectificationFilter<       TInputImage,
 {
         // This is done here instead of inside the GenerateData() method so that the pipeline negociation
         // use the minipipeline instead of default ITK methods.
-        m_OrthoRectificationFilter->GraftOutput(this->GetOutput());
-        //m_OrthoRectificationFilter->GetOutput()->UpdateOutputInformation();
-        //m_OrthoRectificationFilter->GetOutput()->PropagateRequestedRegion();
-        //m_OrthoRectificationFilter->GetOutput()->UpdateOutputData();
-        m_OrthoRectificationFilter->Update();
-        this->GraftOutput(m_OrthoRectificationFilter->GetOutput());
+  m_OrthoRectificationFilter->GraftOutput(this->GetOutput());
+//         m_OrthoRectificationFilter->GetOutput()->UpdateOutputInformation();
+//         m_OrthoRectificationFilter->GetOutput()->PropagateRequestedRegion();
+//         m_OrthoRectificationFilter->GetOutput()->UpdateOutputData();
+  m_OrthoRectificationFilter->Update();
+  this->GraftOutput(m_OrthoRectificationFilter->GetOutput());
         //m_OrthoRectificationFilter->Update();
 }
   
diff --git a/Examples/Projections/OrthoRectificationExample.cxx b/Examples/Projections/OrthoRectificationExample.cxx
index 4e9a085640..cbf59c680a 100644
--- a/Examples/Projections/OrthoRectificationExample.cxx
+++ b/Examples/Projections/OrthoRectificationExample.cxx
@@ -32,7 +32,6 @@
 #include "otbImageFileReader.h"
 #include "otbStreamingImageFileWriter.h"
 
-#include "itkChangeInformationImageFilter.h"
 #include "otbPerBandVectorImageFilter.h"
 
 #include "init/ossimInit.h"
@@ -63,11 +62,11 @@ int main( int argc, char* argv[] )
 {
 
 
-  ossimInit::instance()->initialize(argc, argv);
+  //ossimInit::instance()->initialize(argc, argv);
 
   if(argc!=9)
     {
-    std::cout << argv[0] <<" <input_filename> <output_filename> <x_ground_upper_left_corner> <y_ground_upper_left_corner> <x_Size> <y_Size> <x_groundSamplingDistance> <y_groundSamplingDistance (should be negative since origin is upper left)>" 
+    std::cout << argv[0] <<" <input_filename> <output_filename> <x_ground_upper_left_corner> <y_ground_upper_left_corner> <x_Size> <y_Size> <x_groundSamplingDistance> <y_groundSamplingDistance> (should be negative since origin is upper left)>" 
 	      << std::endl;
 
     return EXIT_FAILURE;
@@ -149,38 +148,13 @@ int main( int argc, char* argv[] )
 // Software Guide : EndCodeSnippet	
 
 // Software Guide : BeginLatex
-//
-// Since the size of the output image will be fixed by the user and we
-// are working with a stream-capable, synchronized pipeline, the
-// ortho-rectification filter needs to know the input image size
-// before the reader actually accesses the pixels. In order to make
-// the pipeline aware of the input image size we execute the
-// \code{GenerateOutputInformation()} method of the reader. Then we
-// can plug the pipeline as usual.
+// 
+// Wiring the orthorectification filter into a PerBandImageFilter allows 
+// to orthrectify images with multiple bands seamlesly.
 //
 // Software Guide : EndLatex
 
-
-
-   
-
-	
-//   reader->GenerateOutputInformation();
-//   
-//   typedef itk::ChangeInformationImageFilter<VectorImageType > ChangeInfoFilterType;
-//   ChangeInfoFilterType::Pointer changeInfo = ChangeInfoFilterType::New();
-//   changeInfo->SetInput(reader->GetOutput());
-//   changeInfo->ChangeOriginOn();
-//   ImageType::PointType originNull;
-//   originNull[0]=0;
-//   originNull[1]=0;
-//   changeInfo->SetOutputOrigin(originNull);
-// 	
-//   changeInfo->GenerateOutputInformation();
-			
-//   orthoRectifFilter->SetInput(changeInfo->GetOutput());
-
-// Software Guide : BeginCodeSnippet  
+// Software Guide : BeginCodeSnippet
   typedef otb::PerBandVectorImageFilter<VectorImageType, VectorImageType, OrthoRectifFilterType> PerBandFilterType;
   PerBandFilterType::Pointer perBandFilter=PerBandFilterType::New();
   perBandFilter->SetFilter(orthoRectifFilter);
-- 
GitLab