Commit 8a64b6c2 authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Test transform direction before parsing the metadata

parent 75c33ec6
......@@ -22,6 +22,7 @@
#include "otbImageMetadata.h"
#include "otbSensorTransformFactory.h"
#include "otbTransform.h"
#include "otbTransformFactories.h"
#include <functional>
......@@ -35,7 +36,8 @@ SensorTransformFactory::CreateTransform(const ImageMetadata &imd, TransformDirec
// Instanciate the factories
std::vector<
std::function<
typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>::Pointer (const ImageMetadata &)
typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>::Pointer (const ImageMetadata &,
TransformDirection direction)
>
> factories;
factories.push_back(TransformFactories::RPCForwardTransformFactory<TScalarType, NInputDimensions, NOutputDimensions>);
......@@ -44,7 +46,7 @@ SensorTransformFactory::CreateTransform(const ImageMetadata &imd, TransformDirec
typename otb::SensorTransformBase<TScalarType, NInputDimensions, NOutputDimensions>::Pointer transformPointer;
for (auto& transformFactory : factories)
{
transformPointer = transformFactory(imd);
transformPointer = transformFactory(imd, direction);
if (transformPointer)
{
if (transformPointer->IsValidSensorModel() && transformPointer->getDirection() == direction)
......
......@@ -24,6 +24,7 @@
#include "otbCast.h"
#include "otbImageMetadata.h"
#include "otbSensorTransformBase.h"
#include "otbTransform.h"
#include "otbRPCForwardTransform.h"
#include "otbRPCInverseTransform.h"
......@@ -36,8 +37,8 @@ namespace otb {
* Each function is in charge of instanciating a specific transformation classes. It is
* templated with the scalar type used in the Sensor Model, the dimension of the
* inpute space, and the dimension of the output space. It takes as parameter a
* reference to the ImageMetadata object used to instanciate the Sensor Model.
* It returns an instance of otb::SensorTransformBase.
* reference to the ImageMetadata object used to instanciate the Sensor Model, and the
* TransformDirection. It returns an instance of otb::SensorTransformBase.
*
* \ingroup OTBTransform
*/
......@@ -48,11 +49,13 @@ namespace TransformFactories {
*/
template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>::Pointer
RPCForwardTransformFactory(const ImageMetadata &imd)
RPCForwardTransformFactory(const ImageMetadata &imd, TransformDirection direction)
{
if(imd.Has(MDGeom::RPC))
{
auto transform = RPCForwardTransform<TScalarType, NInputDimensions,NOutputDimensions>::New();
if(transform->getDirection() != direction)
return nullptr;
transform->SetMetadata(imd);
return DynamicCast<typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>>(transform);
}
......@@ -64,11 +67,13 @@ RPCForwardTransformFactory(const ImageMetadata &imd)
*/
template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>::Pointer
RPCInverseTransformFactory(const ImageMetadata &imd)
RPCInverseTransformFactory(const ImageMetadata &imd, TransformDirection direction)
{
if(imd.Has(MDGeom::RPC))
{
auto transform = RPCInverseTransform<TScalarType, NInputDimensions,NOutputDimensions>::New();
if(transform->getDirection() != direction)
return nullptr;
transform->SetMetadata(imd);
return DynamicCast<typename otb::SensorTransformBase<double, NInputDimensions, NOutputDimensions>>(transform);
}
......
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