Commit 059f393c authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Simpler API for SensorModelBase::SetMetadata

parent c690f2d0
......@@ -111,7 +111,7 @@ private:
// Instantiate a ForwardSensor Model
ModelType::Pointer model = ModelType::New();
model->SetMetadataModel(inImage->GetImageMetadata()[MDGeom::RPC]);
model->SetMetadata(inImage->GetImageMetadata());
if (model->IsValidSensorModel() == false)
{
itkGenericExceptionMacro(<< "Unable to create a model");
......
......@@ -123,13 +123,13 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
typedef otb::RPCForwardTransform<double, InputSpaceDimension, OutputSpaceDimension> RPCForwardTransformType;
typename RPCForwardTransformType::Pointer sensorModel = RPCForwardTransformType::New();
sensorModel->SetMetadataModel((*m_InputImd)[MDGeom::RPC]);
sensorModel->SetMetadata(*m_InputImd);
if (sensorModel->IsValidSensorModel())
{
m_InputTransform = sensorModel.GetPointer();
inputTransformIsSensor = true;
otbMsgDevMacro(<< "Input projection set to sensor model.");
otbMsgDevMacro(<< "Input projection set to RPC model.");
}
}
......@@ -155,13 +155,13 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
typedef otb::RPCInverseTransform<double, InputSpaceDimension, OutputSpaceDimension> RPCInverseTransformType;
typename RPCInverseTransformType::Pointer sensorModel = RPCInverseTransformType::New();
sensorModel->SetMetadataModel((*m_OutputImd)[MDGeom::RPC]);
sensorModel->SetMetadata(*m_OutputImd);
if (sensorModel->IsValidSensorModel())
{
m_OutputTransform = sensorModel.GetPointer();
outputTransformIsSensor = true;
otbMsgDevMacro(<< "Output projection set to sensor model");
otbMsgDevMacro(<< "Output projection set to RPC model");
}
}
......@@ -175,6 +175,7 @@ void GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::Insta
}
m_InputTransform = itk::IdentityTransform<double, NInputDimensions>::New();
otbMsgDevMacro(<< "Input projection set to identity");
}
......
......@@ -64,11 +64,10 @@ public:
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
/*
* Set the model as it is defined in the ImageMetadata.
* Used by the factory to find the correct class.
* Provide the ImageMetadata in order to set the model.
* Return false if model not valid.
*/
bool SetMetadataModel(boost::any imdModel) override;
bool SetMetadata(const ImageMetadata& imd) override;
/** Check model validity */
bool IsValidSensorModel() const override;
......
......@@ -27,11 +27,13 @@ namespace otb
{
template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
bool RPCTransformBase<TScalarType, NInputDimensions, NOutputDimensions>::SetMetadataModel(boost::any imdModel)
bool RPCTransformBase<TScalarType, NInputDimensions, NOutputDimensions>::SetMetadata(const ImageMetadata& imd)
{
if (!imd.Has(MDGeom::RPC))
return false;
try
{
Projection::RPCParam newParam = boost::any_cast<Projection::RPCParam>(imdModel);
Projection::RPCParam newParam = boost::any_cast<Projection::RPCParam>(imd[MDGeom::RPC]);
this->m_RPCParam.reset(&newParam);
}
catch (boost::bad_any_cast)
......
......@@ -68,11 +68,10 @@ public:
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
/*
* Set the model as it is defined in the ImageMetadata.
* Used by the factory to find the correct class.
* Provide the ImageMetadata in order to set the model.
* Return false if model not valid.
*/
virtual bool SetMetadataModel(boost::any imdModel) = 0;
virtual bool SetMetadata(const ImageMetadata& imd) = 0;
/** Check model validity */
virtual bool IsValidSensorModel() const = 0;
......
......@@ -68,7 +68,7 @@ int otbCreateInverseForwardSensorModel(int argc, char* argv[])
ImageType::Pointer inputImage = reader->GetOutput();
otbGenericMsgDebugMacro(<< "Inverse model creation...");
if (inverse_rpc_model->SetMetadataModel(inputImage->GetImageMetadata()[otb::MDGeom::RPC]))
if (inverse_rpc_model->SetMetadata(inputImage->GetImageMetadata()))
{
std::cout << "Error while reading model. This is not a RPC model!" << std::endl;
return EXIT_FAILURE;
......@@ -80,7 +80,7 @@ int otbCreateInverseForwardSensorModel(int argc, char* argv[])
}
otbGenericMsgDebugMacro(<< "Forward model creation...");
if (forward_rpc_model->SetMetadataModel(inputImage->GetImageMetadata()[otb::MDGeom::RPC]))
if (forward_rpc_model->SetMetadata(inputImage->GetImageMetadata()))
{
std::cout << "Error while reading model. This is not a RPC model!" << std::endl;
return EXIT_FAILURE;
......
......@@ -90,7 +90,7 @@ int otbRegionProjectionResampler(int argc, char* argv[])
reader->GenerateOutputInformation();
ImageType::ConstPointer inputImage = reader->GetOutput();
model->SetMetadataModel(reader->GetOutput()->GetImageMetadata()[otb::MDGeom::RPC]);
model->SetMetadata(reader->GetOutput()->GetImageMetadata());
if (model->IsValidSensorModel() == false)
{
......
......@@ -57,7 +57,7 @@ int otbCompositeTransform(int argc, char* argv[])
typedef otb::RPCInverseTransform<double, 2, 2> SensorModelType;
SensorModelType::Pointer sensorModel = SensorModelType::New();
sensorModel->SetMetadataModel(reader->GetOutput()->GetImageMetadata()[otb::MDGeom::RPC]);
sensorModel->SetMetadata(reader->GetOutput()->GetImageMetadata());
if (sensorModel->IsValidSensorModel() == false)
{
......
......@@ -66,7 +66,7 @@ int produceGCP(char* outputgcpfilename, const otb::ImageMetadata& imd, bool useF
// otbForwardSensorModel
typedef otb::RPCForwardTransform<double, 2, 2> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetMetadataModel(imd[otb::MDGeom::RPC]);
forwardSensorModel->SetMetadata(imd);
if (forwardSensorModel->IsValidSensorModel() == false)
{
otbLogMacro(Warning, << "Invalid Model pointer m_Model == NULL!\n The metadata is invalid!");
......@@ -202,7 +202,7 @@ int otbSensorModel(int argc, char* argv[])
std::cerr << "Invalid sensor model (ForwardSensorModelType::Pointer is NULL)" << std::endl;
return EXIT_FAILURE;
}
forwardSensorModel->SetMetadataModel(imd[otb::MDGeom::RPC]);
forwardSensorModel->SetMetadata(imd);
if (forwardSensorModel->IsValidSensorModel() == false)
{
std::cerr << "Invalid Model pointer m_Model == NULL!\n The metadata is invalid!" << std::endl;
......@@ -217,7 +217,7 @@ int otbSensorModel(int argc, char* argv[])
std::cerr << "Invalid sensor model (InverseSensorModelType::Pointer is NULL)" << std::endl;
return EXIT_FAILURE;
}
inverseSensorModel->SetMetadataModel(imd[otb::MDGeom::RPC]);
inverseSensorModel->SetMetadata(imd);
if (inverseSensorModel->IsValidSensorModel() == false)
{
std::cerr << "Invalid Model pointer m_Model == NULL!\n The metadata is invalid!" << std::endl;
......
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