Commit 1324ad8a authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Ajout classe SensorModelBase.

Ajout de tests supplémentaires dans "Projections"
parent 477000ea
......@@ -48,19 +48,33 @@ operator=(const Self& p)
void
ImageKeywordlist::
Print(std::ostream& os) const
convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const
{
ossimKeywordlist kwl;
convertToOSSIMKeywordlist(kwl);
os << " Ossim Keyword list:"<<std::endl;
os << kwl ;
kwl.getMap() = m_Keywordlist;
}
void
ImageKeywordlist::
convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const
Print(std::ostream& os, itk::Indent indent) const
{
kwl.getMap() = m_Keywordlist;
this->PrintSelf(os, indent.GetNextIndent());
}
void
ImageKeywordlist::
PrintSelf(std::ostream& os, itk::Indent indent) const
{
ossimKeywordlist kwl;
convertToOSSIMKeywordlist(kwl);
os << indent << " Ossim Keyword list:"<<std::endl;
os << indent << kwl ;
}
std::ostream &
operator<<(std::ostream &os, const ImageKeywordlist &kwl)
{
kwl.Print(os);
return os;
}
......
......@@ -18,12 +18,9 @@
#ifndef __otbImageKeywordlist_h
#define __otbImageKeywordlist_h
#include <iostream>
#include "itkObject.h"
#include "itkObjectFactory.h"
//#include "itkSize.h"
//#include "itkImageRegion.h"
//#include "itkDefaultConvertPixelTraits.h"
#include "base/ossimString.h"
#include "base/ossimKeywordlist.h"
......@@ -53,17 +50,29 @@ public:
{
m_Keywordlist = kwl.getMap();
}
void Clear(void)
{
m_Keywordlist.clear();
}
virtual void convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const;
virtual void Print(std::ostream& os, itk::Indent indent=0) const;
ImageKeywordlist() ;
virtual ~ImageKeywordlist() ;
void Print(std::ostream& os) const ;
ImageKeywordlist(const Self&);
void operator=(const Self&);
protected:
/** Methods invoked by Print() to print information about the object
* Typically not called by the user (use Print()
* instead) but used in the hierarchical print process to combine the
* output of several classes. */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
/** Geo informations are in this map */
......@@ -75,6 +84,7 @@ private:
};
ITK_EXPORT std::ostream & operator<<(std::ostream &os, const ImageKeywordlist &kwl);
} //namespace otb
......
......@@ -18,23 +18,11 @@
#ifndef __otbForwardSensorModel_h
#define __otbForwardSensorModel_h
#include <sstream>
#include <stdio.h>
#include <iostream>
#include "itkExceptionObject.h"
#include "itkTransform.h"
#include "itkExceptionObject.h"
#include "otbSensorModelBase.h"
#include "itkMacro.h"
#include "projection/ossimSensorModelFactory.h"
#include "projection/ossimProjection.h"
#include "projection/ossimProjectionFactoryRegistry.h"
#include "base/ossimKeywordlist.h"
#include "imaging/ossimImageHandlerRegistry.h"
#include "imaging/ossimImageHandler.h"
#include "itkSmartPointer.h"
#include "itkObject.h"
namespace otb
{
/**otbForwardSensorModel.h
......@@ -45,9 +33,10 @@ template <class TScalarType,
unsigned int NInputDimensions=2,
unsigned int NOutputDimensions=2,
unsigned int NParametersDimensions=3>
class ITK_EXPORT ForwardSensorModel : public itk::Transform<TScalarType,
class ITK_EXPORT ForwardSensorModel : public SensorModelBase<TScalarType,
NInputDimensions,
NOutputDimensions>
NOutputDimensions,
NParametersDimensions>
{
public :
......@@ -55,39 +44,33 @@ public :
/* Dclaration des types utiliss: */
/******************************************/
typedef ForwardSensorModel Self;
typedef itk::Transform< TScalarType,
typedef SensorModelBase< TScalarType,
NInputDimensions,
NOutputDimensions > Superclass;
NOutputDimensions,
NParametersDimensions > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkTypeMacro( ForwardSensorModel, Transform );
itkNewMacro( Self );
itkTypeMacro( ForwardSensorModel, SensorModelBase );
itkNewMacro( Self );
typedef itk::Point<TScalarType, NInputDimensions > InputPointType;
typedef itk::Point<TScalarType, NOutputDimensions > OutputPointType;
typedef typename Superclass::InputPointType InputPointType;
typedef typename Superclass::OutputPointType OutputPointType;
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
itkStaticConstMacro(ParametersDimension, unsigned int, NParametersDimensions); //A voir!!
/******************************************/
/* Dclaration des mthodes: */
/******************************************/
//Pour lire les kwl.
ossimKeywordlist GetImageGeometryKeywordlist(char *src);
//Pour construire le modle.
void SetImageGeometry(ossimKeywordlist &geom_kwl);
// Pour projeter le point au sol.
OutputPointType TransformPoint(const InputPointType &point) const;
/** Projection point */
OutputPointType TransformPoint(const InputPointType &point) const;
protected:
ForwardSensorModel();
virtual ~ForwardSensorModel();
ForwardSensorModel();
virtual ~ForwardSensorModel();
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
//Variables protgs:
ossimKeywordlist m_geom_kwl;
ossimProjection* m_Model;
};
}//Fin header
......
......@@ -26,6 +26,8 @@
**/
#include "otbForwardSensorModel.h"
#include "itkExceptionObject.h"
#include "otbMacro.h"
namespace otb
{ /************************************/
......@@ -38,10 +40,8 @@ template < class TScalarType,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::ForwardSensorModel():
Superclass(OutputSpaceDimension, ParametersDimension)
::ForwardSensorModel()
{
m_Model = NULL;
}
// Destructeur
......@@ -52,65 +52,47 @@ template < class TScalarType,
ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::~ForwardSensorModel()
{
delete m_Model;
}
/******************************************/
/* Dclaration des mthodes: */
/******************************************/
/// Mthode GetGeometryKeywordlist :
///Mthode TransformPoint:
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
ossimKeywordlist
typename ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>::OutputPointType
ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::GetImageGeometryKeywordlist(char *src)
::TransformPoint(const InputPointType &point) const
{
return m_geom_kwl;
//On transforme le type "itk::point" en type "ossim::ossimDpt"
ossimDpt ossimPoint(point[0], point[1]);
//On calcule
ossimGpt ossimGPoint;
if( this->m_Model == NULL)
{
itkExceptionMacro(<<"TransformPoint(): Invalid Model pointer m_Model == NULL !");
}
this->m_Model->lineSampleToWorld(ossimPoint, ossimGPoint); //Projection par la mthode "lineSampleToWorld" de la classe ossimSensorModel
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimGPoint.lat;
outputPoint[1]=ossimGPoint.lon;
return outputPoint;
}
/// Mthode SetGeometry : Crer et instancier le modle de capteur grce aux metadata.
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
void
ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::SetImageGeometry(ossimKeywordlist& geom_kwl)
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
//m_geom_kwl = geom_kwl;
if(m_Model)
{
delete m_Model;
}
m_Model = ossimProjectionFactoryRegistry::instance()->createProjection(geom_kwl);
Superclass::PrintSelf(os,indent);
}
///Mthode TransformPoint:
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
typename ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>::OutputPointType
ForwardSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::TransformPoint(const InputPointType &point) const
{//On transforme le type "itk::point" en type "ossim::ossimDpt"
ossimDpt ossimPoint(point[0], point[1]);
//On calcule
ossimGpt ossimGPoint;
m_Model->lineSampleToWorld(ossimPoint, ossimGPoint); //Projection par la mthode "lineSampleToWorld" de la classe ossimSensorModel
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimGPoint.lat;
outputPoint[1]=ossimGPoint.lon;
return outputPoint;
}
}//fin namespace
#endif
......
......@@ -18,19 +18,8 @@
#ifndef __otbInverseSensorModel_h
#define __otbInverseSensorModel_h
#include <sstream>
#include <stdio.h>
#include <iostream>
#include "itkExceptionObject.h"
#include "itkTransform.h"
#include "itkExceptionObject.h"
#include "otbSensorModelBase.h"
#include "itkMacro.h"
#include "projection/ossimSensorModelFactory.h"
#include "projection/ossimProjection.h"
#include "projection/ossimProjectionFactoryRegistry.h"
#include "base/ossimKeywordlist.h"
#include "imaging/ossimImageHandlerRegistry.h"
#include "imaging/ossimImageHandler.h"
#include "itkSmartPointer.h"
#include "itkObject.h"
......@@ -43,9 +32,10 @@ template <class TScalarType,
unsigned int NInputDimensions=2,
unsigned int NOutputDimensions=2,
unsigned int NParametersDimensions=3>
class ITK_EXPORT InverseSensorModel : public itk::Transform<TScalarType,
class ITK_EXPORT InverseSensorModel : public SensorModelBase<TScalarType,
NInputDimensions,
NOutputDimensions>
NOutputDimensions,
NParametersDimensions>
{
public :
......@@ -53,41 +43,35 @@ public :
/* Dclaration des types utiliss: */
/******************************************/
typedef InverseSensorModel Self;
typedef itk::Transform< TScalarType,
typedef SensorModelBase< TScalarType,
NInputDimensions,
NOutputDimensions > Superclass;
NOutputDimensions,
NParametersDimensions > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkTypeMacro( InverseSensorModel, Transform );
itkNewMacro( Self );
itkTypeMacro( InverseSensorModel, SensorModelBase );
itkNewMacro( Self );
typedef itk::Point<TScalarType, NInputDimensions > InputPointType;
typedef itk::Point<TScalarType, NOutputDimensions > OutputPointType;
typedef typename Superclass::InputPointType InputPointType;
typedef typename Superclass::OutputPointType OutputPointType;
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
itkStaticConstMacro(ParametersDimension, unsigned int, NParametersDimensions); //A voir!!
/******************************************/
/* Dclaration des mthodes: */
/******************************************/
//Pour lire les kwl.
ossimKeywordlist GetImageGeometryKeywordlist(char *src);
//Pour construire le modle.
void SetImageGeometry(ossimKeywordlist &geom_kwl);
// Pour projeter un point go sur l'image en gomtrie capteur.
OutputPointType InverseTransformPoint(const InputPointType &point) const;
// Pour projeter un point go connaissant son altitude.
OutputPointType InverseTransformPoint(const InputPointType &point, double height) const;
// Pour projeter un point go sur l'image en gomtrie capteur.
OutputPointType TransformPoint(const InputPointType &point) const;
// Pour projeter un point go connaissant son altitude.
OutputPointType TransformPoint(const InputPointType &point, double height) const;
protected:
InverseSensorModel();
virtual ~InverseSensorModel();
InverseSensorModel();
virtual ~InverseSensorModel();
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
//Variables protgs:
ossimKeywordlist m_geom_kwl;
ossimProjection* m_Model;
};
}//Fin header
......
......@@ -25,6 +25,8 @@
* (lat,lon) -> (i,j) ou (lat,lon,h) -> (i,j)
**/
#include "otbInverseSensorModel.h"
#include "itkExceptionObject.h"
#include "otbMacro.h"
namespace otb
{ /************************************/
......@@ -37,9 +39,8 @@ template < class TScalarType,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::InverseSensorModel(): Superclass(OutputSpaceDimension, ParametersDimension)
::InverseSensorModel()
{
m_Model = NULL;
}
// Destructeur
......@@ -50,88 +51,77 @@ template < class TScalarType,
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::~InverseSensorModel()
{
delete m_Model;
}
/******************************************/
/* Dclaration des mthodes: */
/******************************************/
/// Mthode GetGeometryKeywordlist
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
ossimKeywordlist
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::GetImageGeometryKeywordlist(char *src)
{
return m_geom_kwl;
}
/// Mthode SetGeometry :Crer et instancier le modle de capteur grce aux metadata.
///Mthode InverseTransformPoint:
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
void
typename InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>::OutputPointType
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::SetImageGeometry(ossimKeywordlist& geom_kwl)
::TransformPoint(const InputPointType &point) const
{
//m_geom_kwl = geom_kwl;
if(m_Model)
{
delete m_Model;
}
m_Model = ossimProjectionFactoryRegistry::instance()->createProjection(geom_kwl);
//On transforme le type "itk::point" en type "ossim::ossimGpt"
ossimGpt ossimGPoint(point[0], point[1]);
//On calcule
ossimDpt ossimDPoint;
if( this->m_Model == NULL)
{
itkExceptionMacro(<<"TransformPoint(): Invalid Model pointer m_Model == NULL !");
}
this->m_Model->worldToLineSample(ossimGPoint, ossimDPoint);
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimDPoint.x;
outputPoint[1]=ossimDPoint.y;
return outputPoint;
}
///Mthode InverseTransformPoint:
///Mthode InverseTransformPoint en tenant compte de l'altitude:
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
typename InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>::OutputPointType
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::InverseTransformPoint(const InputPointType &point) const
{//On transforme le type "itk::point" en type "ossim::ossimGpt"
ossimGpt ossimGPoint(point[0], point[1]);
::TransformPoint(const InputPointType &point, double height) const
{
//On transforme le type "itk::point" en type "ossim::ossimGpt"
ossimGpt ossimGPoint(point[0], point[1], height);
//On calcule
ossimDpt ossimDPoint;
m_Model->worldToLineSample(ossimGPoint, ossimDPoint);
//On calcule
ossimDpt ossimDPoint;
if( this->m_Model == NULL)
{
itkExceptionMacro(<<"TransformPoint(): Invalid Model pointer m_Model == NULL !");
}
this->m_Model->worldToLineSample(ossimGPoint, ossimDPoint); //"worldToLineSample" appelle la mthode "lineSampleHeightToWorld" pour prendre en compte l'lvation.
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimDPoint.x;
outputPoint[1]=ossimDPoint.y;
return outputPoint;
}
///Mthode InverseTransformPoint en tenant compte de l'altitude:
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimDPoint.x;
outputPoint[1]=ossimDPoint.y;
return outputPoint;
}
template < class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions,
unsigned int NParametersDimensions >
typename InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>::OutputPointType
void
InverseSensorModel< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimensions>
::InverseTransformPoint(const InputPointType &point, double height) const
{//On transforme le type "itk::point" en type "ossim::ossimGpt"
ossimGpt ossimGPoint(point[0], point[1], height);
//On calcule
ossimDpt ossimDPoint;
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
}
m_Model->worldToLineSample(ossimGPoint, ossimDPoint); //"worldToLineSample" appelle la mthode "lineSampleHeightToWorld" pour prendre en compte l'lvation.
//On stocke le resultat dans un "OutputPointType"
OutputPointType outputPoint;
outputPoint[0]=ossimDPoint.x;
outputPoint[1]=ossimDPoint.y;
return outputPoint;
}
}//fin namespace
#endif
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbSensorModelBase_h
#define __otbSensorModelBase_h
#include <iostream>
#include "itkTransform.h"
#include "otbMacro.h"
#include "otbImageKeywordlist.h"
#include "projection/ossimProjection.h"
#include "itkSmartPointer.h"
#include "itkObject.h"
namespace otb
{
//On dfinit le template avec un type gnrique.
//Cette classe hrite de itk::Transform
template <class TScalarType,
unsigned int NInputDimensions=2,
unsigned int NOutputDimensions=2,
unsigned int NParametersDimensions=3>
class ITK_EXPORT SensorModelBase : public itk::Transform<TScalarType,
NInputDimensions,
NOutputDimensions>
{
public :
/******************************************/
/* Dclaration des types utiliss: */
/******************************************/
typedef SensorModelBase Self;
typedef itk::Transform< TScalarType,
NInputDimensions,
NOutputDimensions > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkTypeMacro( SensorModelBase, Transform );
itkNewMacro( Self );
typedef itk::Point<TScalarType, NInputDimensions > InputPointType;
typedef itk::Point<TScalarType, NOutputDimensions > OutputPointType;
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
itkStaticConstMacro(ParametersDimension, unsigned int, NParametersDimensions); //A voir!!
/* Get the ImageKeywordlist */
ImageKeywordlist & GetImageGeometryKeywordlist(void) const;
/* Get an ossimKeywordlist */
ossimKeywordlist GetOssimKeywordlist(void);
/* Set the Imagekeywordlist and affect the ossim projection ( m_Model) */
virtual void SetImageGeometry(ImageKeywordlist image_kwl);
/* Set the Imagekeywordlist and affect the ossim projection ( m_Model) */
virtual void SetImageGeometry(ossimKeywordlist &geom_kwl);
protected:
SensorModelBase();
virtual ~SensorModelBase();
/** Create the projection ( m_Model). Called by the SetImageGeometry methods */
void CreateProjection(const ImageKeywordlist & image_kwl);
/** PrintSelf method */