Commit e7980208 authored by Julien Osman's avatar Julien Osman
Browse files

REFAC: Update otbGenericRSTransform so it uses ImageMetadata instead of KeywordLists

parent 05eab23e
......@@ -22,7 +22,7 @@
#define otbGenericRSTransform_h
#include "otbCompositeTransform.h"
#include "otbImageKeywordlist.h"
#include "otbImageMetadata.h"
#include <string>
namespace otb
......@@ -101,42 +101,38 @@ public:
itkSetStringMacro(OutputProjectionRef);
itkGetStringMacro(OutputProjectionRef);
/** Set/Get Dictionary*/
const itk::MetaDataDictionary& GetInputDictionary() const
/** Set/Get ImageMetadata*/
const ImageMetadata* GetInputImageMetadata() const
  • Can't we avoid using pointers? Who is responsible for the memory? Can the pointers be null? Too many questions with raw pointers.

  • For the class GenericRSTransform, the metadata are kept as a pointer to avoid copying them (see attributs m_*Imd). The pointer should be owned by an otbImage or otbVectorImage object. Before using Set*ImageMetadata, the pointer is null.

    If I change the type of the attributs m_*Imd to a reference, that means the user needs to provide all the references when instantiating the object. This is a big change in the API. I know we are changing the API anyway, but at least, I try to keep the same philosophy as the previous one. (should I completely change the API?)

    Edited by Julien Osman
Please register or sign in to reply
{
return m_InputDictionary;
return m_InputImd;
}
void SetInputDictionary(const itk::MetaDataDictionary& dictionary)
void SetInputImageMetadata(const ImageMetadata* imd)
{
m_InputDictionary = dictionary;
m_InputImd = imd;
this->Modified();
}
const itk::MetaDataDictionary& GetOutputDictionary() const
void SetInputImageMetadata(const ImageMetadata imd)
{
return m_OutputDictionary;
m_InputImd = &imd;
this->Modified();
}
void SetOutputDictionary(const itk::MetaDataDictionary& dictionary)
const ImageMetadata* GetOutputImageMetadata() const
{
m_OutputDictionary = dictionary;
this->Modified();
return m_OutputImd;
}
/** Set/Get Keywordlist*/
itkGetMacro(InputKeywordList, ImageKeywordlist);
void SetInputKeywordList(const ImageKeywordlist& kwl)
void SetOutputImageMetadata(const ImageMetadata* imd)
{
this->m_InputKeywordList = kwl;
m_OutputImd = imd;
this->Modified();
}
itkGetMacro(OutputKeywordList, ImageKeywordlist);
void SetOutputKeywordList(const ImageKeywordlist& kwl)
void SetOutputImageMetadata(const ImageMetadata imd)
{
this->m_OutputKeywordList = kwl;
m_OutputImd = &imd;
this->Modified();
}
......@@ -208,11 +204,8 @@ private:
GenericRSTransform(const Self&) = delete;
void operator=(const Self&) = delete;
ImageKeywordlist m_InputKeywordList;
ImageKeywordlist m_OutputKeywordList;
itk::MetaDataDictionary m_InputDictionary;
itk::MetaDataDictionary m_OutputDictionary;
const ImageMetadata* m_InputImd;
const ImageMetadata* m_OutputImd;
std::string m_InputProjectionRef;
std::string m_OutputProjectionRef;
......
......@@ -24,8 +24,8 @@
#include "otbGenericRSTransform.h"
#include "otbMacro.h"
#include "otbMetaDataKey.h"
#include "itkMetaDataObject.h"
#include "otbRPCForwardTransform.h"
#include "otbRPCInverseTransform.h"
#include "otbSpatialReference.h"
......@@ -39,13 +39,13 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::GenericRST
{
m_InputProjectionRef.clear();
m_OutputProjectionRef.clear();
m_InputKeywordList.Clear();
m_OutputKeywordList.Clear();
m_InputSpacing.Fill(1);
m_InputOrigin.Fill(0);
m_OutputSpacing.Fill(1);
m_OutputOrigin.Fill(0);
m_InputImd = nullptr;
m_OutputImd = nullptr;
m_Transform = nullptr;
m_InputTransform = nullptr;
m_OutputTransform = nullptr;
......@@ -74,21 +74,12 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
{
m_Transform = TransformType::New();
if (m_InputKeywordList.GetSize() == 0)
{
itk::ExposeMetaData<ImageKeywordlist>(m_InputDictionary, MetaDataKey::OSSIMKeywordlistKey, m_InputKeywordList);
}
if (m_InputProjectionRef.empty())
{
itk::ExposeMetaData<std::string>(m_InputDictionary, MetaDataKey::ProjectionRefKey, m_InputProjectionRef);
}
otbMsgDevMacro(<< "Information to instantiate transform: ");
otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
otbMsgDevMacro(<< " * Input keyword list: " << ((m_InputKeywordList.GetSize() == 0) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Input metadata: " << ((m_InputImd == nullptr) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Input projection: " << m_InputProjectionRef);
otbMsgDevMacro(<< " * Output keyword list: " << ((m_OutputKeywordList.GetSize() == 0) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Output metadata: " << ((m_OutputImd == nullptr) ? "Empty" : "Full"));
otbMsgDevMacro(<< " * Output projection: " << m_OutputProjectionRef);
otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
......@@ -121,17 +112,17 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
}
}
// If not, try to make a sensor model
if ((m_InputTransform.IsNull()) && (m_InputKeywordList.GetSize() > 0))
// If not, try to make a RPC sensor model
if ((m_InputTransform.IsNull()) && (m_InputImd->Has(MDGeom::RPC)))
{
typedef otb::RPCForwardTransform<double, InputSpaceDimension, InputSpaceDimension> ForwardSensorModelType;
typename ForwardSensorModelType::Pointer sensorModel = ForwardSensorModelType::New();
typedef otb::RPCForwardTransform<double, InputSpaceDimension, OutputSpaceDimension> RPCForwardTransformType;
typename RPCForwardTransformType::Pointer sensorModel = RPCForwardTransformType::New();
sensorModel->SetMetadataModel(m_InputKeywordList);
sensorModel->SetMetadataModel((*m_InputImd)[MDGeom::RPC]);
if (sensorModel->IsValidSensorModel())
{
m_InputTransform = sensorModel.GetPointer();
//TODO: m_InputTransform = sensorModel.GetPointer();
inputTransformIsSensor = true;
otbMsgDevMacro(<< "Input projection set to sensor model.");
}
......@@ -153,17 +144,17 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
}
}
// If not, try to make a sensor model
if ((m_OutputTransform.IsNull()) && (m_OutputKeywordList.GetSize() > 0))
// If not, try to make a RPC sensor model
if ((m_OutputTransform.IsNull()) && (m_OutputImd->Has(MDGeom::RPC)))
{
typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType;
typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New();
typedef otb::RPCInverseTransform<double, InputSpaceDimension, OutputSpaceDimension> RPCInverseTransformType;
typename RPCInverseTransformType::Pointer sensorModel = RPCInverseTransformType::New();
sensorModel->SetImageGeometry(m_OutputKeywordList);
sensorModel->SetMetadataModel((*m_OutputImd)[MDGeom::RPC]);
if (sensorModel->IsValidSensorModel())
{
m_OutputTransform = sensorModel.GetPointer();
//TODO: m_OutputTransform = sensorModel.GetPointer();
outputTransformIsSensor = true;
otbMsgDevMacro(<< "Output projection set to sensor model");
}
......@@ -258,13 +249,9 @@ bool GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::GetIn
inverseTransform->SetInputProjectionRef(m_OutputProjectionRef);
inverseTransform->SetOutputProjectionRef(m_InputProjectionRef);
// Switch keywordlists
inverseTransform->SetInputKeywordList(m_OutputKeywordList);
inverseTransform->SetOutputKeywordList(m_InputKeywordList);
// Switch dictionnaries
inverseTransform->SetInputDictionary(m_OutputDictionary);
inverseTransform->SetOutputDictionary(m_InputDictionary);
// Switch ImageMetadatas
inverseTransform->SetInputImageMetadata(m_OutputImd);
inverseTransform->SetOutputImageMetadata(m_InputImd);
// Switch spacings
inverseTransform->SetInputSpacing(m_OutputSpacing);
......
......@@ -49,7 +49,8 @@ class ITK_EXPORT SensorModelBase : public Transform<TScalarType, NInputDimension
{
public:
/** Standard class typedefs. */
/** @name Standard class type definitions */
//@{
using Self = SensorModelBase;
using Superclass = Transform<TScalarType, NInputDimensions, NOutputDimensions>;
using Pointer = itk::SmartPointer<Self>;
......@@ -58,6 +59,7 @@ public:
using InputPointType = itk::Point<TScalarType, NInputDimensions>;
using OutputPointType = itk::Point<TScalarType, NOutputDimensions>;
using PixelType =TScalarType;
//@}
/** Run-time type information (and related methods). */
itkTypeMacro(Self, Superclass);
......@@ -73,7 +75,7 @@ public:
virtual bool SetMetadataModel(boost::any imdModel) = 0;
/** Check model validity */
virtual bool IsValidSensorModel() = 0;
virtual bool IsValidSensorModel() const = 0;
protected:
SensorModelBase() = default;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment