From 538342708ea77a457ec567331e4ae5e89521927d Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Thu, 2 Jul 2009 16:01:56 +0800
Subject: [PATCH] ENH: provide information about accuracy

---
 Code/Projections/otbGenericRSTransform.h   | 14 ++---
 Code/Projections/otbGenericRSTransform.txx | 71 +++++++++-------------
 Code/Visualization/otbImageLayer.txx       | 13 +++-
 3 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/Code/Projections/otbGenericRSTransform.h b/Code/Projections/otbGenericRSTransform.h
index 1637399602..eb5e0e4cc1 100644
--- a/Code/Projections/otbGenericRSTransform.h
+++ b/Code/Projections/otbGenericRSTransform.h
@@ -25,18 +25,13 @@ PURPOSE.  See the above copyright notices for more information.
 #include "itkTransform.h"
 #include "itkExceptionObject.h"
 #include "itkMacro.h"
-// #include "base/ossimGpt.h"
-// #include "base/ossimDpt.h"
-// #include "projection/ossimProjection.h"
-// #include "base/ossimEllipsoid.h"
-// #include "base/ossimEllipsoidFactory.h"
-// #include "base/ossimString.h"
-// #include "ossimOgcWktTranslator.h"
 #include "otbCompositeTransform.h"
 
 namespace otb
 {
 
+  enum TransformAccuracy {UNKNOWN, ESTIMATE, PRECISE};
+
   /** \class GenericRSTransform
    *  \brief This is the class to handle generic remote sensing transform
    *
@@ -189,6 +184,9 @@ namespace otb
         return m_TransformUpToDate;
       }
 
+      /** Get Transform accuracy */
+      itkGetMacro(TransformAccuracy, TransformAccuracy);
+
       /** Methods prototypes */
       virtual const TransformType * GetTransform() const;
 
@@ -240,6 +238,8 @@ namespace otb
       GenericTransformPointerType m_InputTransform;
       GenericTransformPointerType m_OutputTransform;
       bool                        m_TransformUpToDate;
+      TransformAccuracy           m_TransformAccuracy;
+
     };
 
 
diff --git a/Code/Projections/otbGenericRSTransform.txx b/Code/Projections/otbGenericRSTransform.txx
index f6a093ec0a..90f6fcbea1 100644
--- a/Code/Projections/otbGenericRSTransform.txx
+++ b/Code/Projections/otbGenericRSTransform.txx
@@ -47,6 +47,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
   m_InputTransform = NULL;
   m_OutputTransform = NULL;
   m_TransformUpToDate = false;
+  m_TransformAccuracy = UNKNOWN;
 }
 
 
@@ -176,22 +177,6 @@ template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputD
 }
 
 
-
-// template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
-//     const typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::TransformType*
-// GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
-// ::GetTransform ()
-// {
-//   itkDebugMacro("returning MapProjection address " << this->m_Transform );
-//   if ((reinstanciateTransform) || (m_Transform == NULL))
-//   {
-//     this->InstanciateProjection();
-//   }
-//
-//   return this->m_Transform;
-// }
-
-
 template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
     const typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::TransformType*
 GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
@@ -220,10 +205,6 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
 {
   m_Transform = TransformType::New();
 
-  //If the information was not specified by the user, it is filled from the metadata
-  //   InputVectorDataPointer input = this->GetInput();
-  //   const itk::MetaDataDictionary & m_InputDictionary = input->GetMetaDataDictionary();
-
   if (m_InputKeywordList.GetSize()  == 0)
   {
     itk::ExposeMetaData<ImageKeywordlist>(m_InputDictionary, MetaDataKey::OSSIMKeywordlistKey, m_InputKeywordList );
@@ -233,9 +214,6 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
     itk::ExposeMetaData<std::string>(m_InputDictionary, MetaDataKey::ProjectionRefKey, m_InputProjectionRef );
   }
 
-
-
-
   otbMsgDevMacro(<< "Information to instanciate transform: ");
   otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
   otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
@@ -248,12 +226,19 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
   otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
   otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
 
+  //Make sure that the state is clean:
+  m_InputTransform = NULL;
+  m_OutputTransform = NULL;
+
   bool firstTransformGiveGeo = true;
+  bool inputTransformIsSensor = false;
+  bool inputTransformIsMap = false;
+  bool outputTransformIsSensor = false;
+  bool outputTransformIsMap = false;
 
   //*****************************
   //Set the input transformation
   //*****************************
-
   try
     {
     if (m_InputKeywordList.GetSize()  > 0)
@@ -266,6 +251,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
         sensorModel->SetDEMDirectory(m_DEMDirectory);
         }
       m_InputTransform = sensorModel.GetPointer();
+      inputTransformIsSensor = true;
       otbMsgDevMacro(<< "Input projection set to sensor model.");
       }
     }
@@ -283,6 +269,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
     if (mapTransform->GetMapProjection() != NULL)
     {
       m_InputTransform = mapTransform.GetPointer();
+      inputTransformIsMap = true;
       otbMsgDevMacro(<< "Input projection set to map transform: " << m_InputTransform);
     }
 
@@ -331,6 +318,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
         sensorModel->SetDEMDirectory(m_DEMDirectory);
         }
       m_OutputTransform = sensorModel.GetPointer();
+      outputTransformIsSensor = true;
       otbMsgDevMacro(<< "Output projection set to sensor model");
       }
     }
@@ -348,6 +336,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
     if (mapTransform->GetMapProjection() != NULL)
     {
       m_OutputTransform = mapTransform.GetPointer();
+      outputTransformIsMap = true;
       otbMsgDevMacro(<< "Output projection set to map transform: " << m_OutputTransform);
     }
 
@@ -364,27 +353,25 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
   }
 
 
-  //If the projection information for the output is provided, propagate it
-//   OutputVectorDataPointer output = this->GetOutput();
-//   itk::MetaDataDictionary & m_OutputDictionary = output->GetMetaDataDictionary();
-
-  //FIXME: this part will need to be propagated independantly in the VectorDataProjectionFilter
-//   if (m_OutputKeywordList.GetSize()  != 0)
-//   {
-//     ossimKeywordlist kwl;
-//     m_OutputKeywordList.convertToOSSIMKeywordlist (kwl);
-//     itk::EncapsulateMetaData<ossimKeywordlist>(m_OutputDictionary, MetaDataKey::OSSIMKeywordlistKey, kwl );
-//   }
-//   if ( !m_OutputProjectionRef.empty())
-//   {
-//     itk::EncapsulateMetaData<std::string>(m_OutputDictionary, MetaDataKey::ProjectionRefKey, m_OutputProjectionRef );
-//   }
-
-
   m_Transform->SetFirstTransform(m_InputTransform);
   m_Transform->SetSecondTransform(m_OutputTransform);
-
   m_TransformUpToDate = true;
+  //The acurracy information is a simplistic model for now and should be refined
+  if ((inputTransformIsSensor || outputTransformIsSensor) && (m_DEMDirectory.empty()))
+  {
+    //Sensor model without DEM
+    m_TransformAccuracy = ESTIMATE;
+  }
+  else if (!inputTransformIsSensor && !outputTransformIsSensor && !inputTransformIsMap && !outputTransformIsMap)
+  {
+    //no transform
+    m_TransformAccuracy = UNKNOWN;
+  }
+  else
+  {
+
+    m_TransformAccuracy = PRECISE;
+  }
 
 }
 
diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx
index 1473d89874..6415c8ae24 100644
--- a/Code/Visualization/otbImageLayer.txx
+++ b/Code/Visualization/otbImageLayer.txx
@@ -237,8 +237,17 @@ ImageLayer<TImage,TOutputImage>
   //the user of the class don't want to use it
   if (m_Transform->IsUpToDate())
   {
-    PointType point = this->GetPixelLocation(index);
-    oss<< setiosflags(ios::fixed) << setprecision(6) << "Lon: " << point[0] << " Lat: "<< point[1] << std::endl;
+    if (m_Transform->GetTransformAccuracy() != UNKNOWN)
+    {
+      PointType point = this->GetPixelLocation(index);
+      oss<< setiosflags(ios::fixed) << setprecision(6) << "Lon: " << point[0] << " Lat: "<< point[1] << std::endl;
+      if (m_Transform->GetTransformAccuracy() == PRECISE) oss<< "(precise location)" << std::endl;
+      if (m_Transform->GetTransformAccuracy() == ESTIMATE) oss<< "(estimated location)" << std::endl;
+    }
+    else
+    {
+      oss << "Location unknown" << std::endl;
+    }
   }
   return oss.str();
 }
-- 
GitLab