Commit 74ed995c authored by Cyrille Valladeau's avatar Cyrille Valladeau

ENH: replace exeption by boolean return in SesorModelBase::SetImageGeometry

parent 903e444e
......@@ -132,18 +132,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
typedef otb::ForwardSensorModel<double, InputSpaceDimension, InputSpaceDimension> ForwardSensorModelType;
typename ForwardSensorModelType::Pointer sensorModel = ForwardSensorModelType::New();
bool imageGeometrySet = false;
try
{
sensorModel->SetImageGeometry(m_InputKeywordList);
imageGeometrySet = true;
}
catch (itk::ExceptionObject& e)
{
itk::OStringStream oss;
oss << "Unable to instanciate a sensor model with the provided keyword list. Exception caught : " << e;
otbMsgDevMacro(<< oss );
}
bool imageGeometrySet = sensorModel->SetImageGeometry(m_InputKeywordList);
if (imageGeometrySet)
{
......@@ -212,19 +201,7 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType;
typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New();
bool imageGeometrySet = false;
try
{
sensorModel->SetImageGeometry(m_OutputKeywordList);
imageGeometrySet = true;
}
catch( itk::ExceptionObject & e )
{
itk::OStringStream oss;
oss << "Unable to instanciate a sensor model with the provided keyword list. Exception caught : " << e;
otbMsgDevMacro(<< oss );
}
bool imageGeometrySet = sensorModel->SetImageGeometry(m_OutputKeywordList);
if (imageGeometrySet)
{
......
......@@ -86,11 +86,17 @@ public:
/* Get an ossimModel */
ossimProjection* GetOssimModel(void);
/* Set the Imagekeywordlist and affect the ossim projection ( m_Model) */
virtual void SetImageGeometry(const ImageKeywordlist& image_kwl);
/* Set the Imagekeywordlist and affect the ossim projection ( m_Model) */
virtual void SetImageGeometry(const ossimKeywordlist& geom_kwl);
/*
* Set the Imagekeywordlist and affect the ossim projection ( m_Model)
* Return false if not model found.
*/
virtual bool SetImageGeometry(const ImageKeywordlist& image_kwl);
/*
* Set the Imagekeywordlist and affect the ossim projection ( m_Model)
* Return false if not model found.
*/
virtual bool SetImageGeometry(const ossimKeywordlist& geom_kwl);
/** Set/Get the average elevation if the DEM is not used*/
itkSetMacro(AverageElevation, TScalarType);
......@@ -127,7 +133,7 @@ protected:
virtual ~SensorModelBase();
/** Create the projection ( m_Model). Called by the SetImageGeometry methods */
void CreateProjection(const ImageKeywordlist& image_kwl);
bool CreateProjection(const ImageKeywordlist& image_kwl);
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
......
......@@ -96,32 +96,32 @@ SensorModelBase<TScalarType, NInputDimensions, NOutputDimensions>
template <class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
void
bool
SensorModelBase<TScalarType, NInputDimensions, NOutputDimensions>
::SetImageGeometry(const ImageKeywordlist& image_kwl)
{
m_ImageKeywordlist = image_kwl;
CreateProjection(m_ImageKeywordlist);
return CreateProjection(m_ImageKeywordlist);
}
/** Set the Imagekeywordlist and affect the ossim projection ( m_Model) */
template <class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
void
bool
SensorModelBase<TScalarType, NInputDimensions, NOutputDimensions>
::SetImageGeometry(const ossimKeywordlist& geom_kwl)
{
m_ImageKeywordlist.Clear();
m_ImageKeywordlist.SetKeywordlist(geom_kwl);
CreateProjection(m_ImageKeywordlist);
return CreateProjection(m_ImageKeywordlist);
}
/** Instatiate the sensor model from metadata. */
template <class TScalarType,
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
void
bool
SensorModelBase<TScalarType, NInputDimensions, NOutputDimensions>
::CreateProjection(const ImageKeywordlist& image_kwl)
{
......@@ -138,8 +138,9 @@ SensorModelBase<TScalarType, NInputDimensions, NOutputDimensions>
}
if (m_Model == NULL)
{
itkExceptionMacro(<< "Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!");
return false;
}
return true;
}
/**
......
......@@ -140,9 +140,9 @@ int main(int argc, char* argv[])
typedef otb::InverseSensorModel<double> ModelType;
ModelType::Pointer model = ModelType::New();
model->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
bool resInvModel = model->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
dynamic_cast<ossimplugins::ossimTileMapModel*>(model->GetOssimModel())->setDepth(depth);
if (!model)
if (!resInvModel)
{
std::cerr << "Unable to create a model" << std::endl;
return 1;
......@@ -213,10 +213,10 @@ int main(int argc, char* argv[])
typedef otb::ForwardSensorModel<double> ForwardModelType;
ForwardModelType::Pointer modelForward = ForwardModelType::New();
modelForward->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
bool resFwdModel = modelForward->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
dynamic_cast<ossimplugins::ossimTileMapModel*>(modelForward->GetOssimModel())->setDepth(
depth);
if (!modelForward)
if (!resFwdModel)
{
std::cerr << "Unable to create a forward model" << std::endl;
return 1;
......
......@@ -117,7 +117,7 @@ int main(int argc, char* argv[])
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
bool resModel = model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
......@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
if (!model)
if (!resModel)
{
std::cerr << "Unable to create a model" << std::endl;
return 1;
......
......@@ -63,7 +63,13 @@ int otbTileMapImageIOTest(int argc, char* argv[])
typedef otb::InverseSensorModel<double> ModelType;
ModelType::Pointer model = ModelType::New();
model->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
bool resModel = model->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
dynamic_cast<ossimplugins::ossimTileMapModel*>(model->GetOssimModel())->setDepth(depth);
if (!model)
{
......
......@@ -61,7 +61,13 @@ int otbCompositeTransform(int argc, char* argv[])
typedef otb::InverseSensorModel<double> SensorModelType;
SensorModelType::Pointer sensorModel = SensorModelType::New();
sensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
bool resModel = sensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
typedef otb::CompositeTransform<MapProjectionType, SensorModelType> CompositeTransformType;
CompositeTransformType::Pointer compositeTransform = CompositeTransformType::New();
......
......@@ -23,8 +23,8 @@
*
* PURPOSE:
*
* Application pour projeter une r�gion d'une image en coordonn�es g�ographiques
* en utilisant un Interpolator+regionextractor et un Iterator.
* Application to rproject an image region into gepgraphical coordinates
* usinf un Interpolator+regionextractor and an Iterator.
*
*/
......@@ -70,11 +70,22 @@ int otbCreateInverseForwardSensorModel(int argc, char* argv[])
reader->GenerateOutputInformation();
ImageType::Pointer inputImage = reader->GetOutput();
//Leve une exception si le model n'est pas cr
bool resModel = true;
otbGenericMsgDebugMacro(<< "Inverse model creation...");
inverse_model->SetImageGeometry(inputImage->GetImageKeywordlist());
resModel = inverse_model->SetImageGeometry(inputImage->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
otbGenericMsgDebugMacro(<< "Foreward model creation...");
forward_model->SetImageGeometry(inputImage->GetImageKeywordlist());
resModel = forward_model->SetImageGeometry(inputImage->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -23,8 +23,8 @@
*
* PURPOSE:
*
* Application pour projeter une r�gion d'une image en coordonn�es g�ographiques
* en utilisant un Interpolator+regionextractor et un Iterator.
* Application to rproject an image region into gepgraphical coordinates
* usinf un Interpolator+regionextractor and an Iterator.
*
*/
......@@ -78,17 +78,6 @@ int otbCreateProjectionWithOTB(int argc, char* argv[])
otbGenericMsgDebugMacro(<< "ossim Keywordlist:" << geom);
/*
typedef otb::InverseSensorModel<double> ModelType;
ModelType::Pointer model= ModelType::New();
otbGenericMsgDebugMacro(<< "Model set geometry " );
model->SetImageGeometry(geom_kwl); //Notre mod�le est cr�� � ce niveau.
if(!model)
{
otbGenericMsgDebugMacro(<< "Unable to create a model");
return 1;
}
*/
ossimGpt ossimGPoint(0, 0);
ossimDpt ossimDPoint;
ossimProjection * model = NULL;
......
......@@ -80,7 +80,13 @@ int otbForwardSensorModelGrid(int argc, char* argv[])
typedef otb::ForwardSensorModel<double> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
bool resModel = forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
forwardSensorModel->SetAverageElevation(averageElevation);
double deltaX = static_cast<double>(sizeIn[0]) / static_cast<double>(size_x);
......
......@@ -101,7 +101,13 @@ int otbRegionProjectionResampler(int argc, char* argv[])
reader->GenerateOutputInformation();
ImageType::ConstPointer inputImage = reader->GetOutput();
model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
bool resModel = model->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
start[0] = 0;
start[1] = 0;
......
......@@ -79,9 +79,16 @@ int otbSensorModel(int argc, char* argv[])
file << "\n*** TRANSFORM ***\n";
bool resModel = false;
typedef otb::ForwardSensorModel<double> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
resModel = forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
forwardSensorModel->SetAverageElevation(16.19688987731934);
itk::Point<double, 2> imagePoint;
......@@ -96,7 +103,12 @@ int otbSensorModel(int argc, char* argv[])
file << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n";
typedef otb::InverseSensorModel<double> InverseSensorModelType;
InverseSensorModelType::Pointer inverseSensorModel = InverseSensorModelType::New();
inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
resModel = inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
inverseSensorModel->SetAverageElevation(16.19688987731934);
itk::Point<double, 2> reversedImagePoint;
......
......@@ -79,14 +79,28 @@ int otbSensorModelGrid(int argc, char* argv[])
double averageElevation = 16.19688987731934;
bool resModel = true;
typedef otb::ForwardSensorModel<double> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
resModel = forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
forwardSensorModel->SetAverageElevation(averageElevation);
typedef otb::InverseSensorModel<double> InverseSensorModelType;
InverseSensorModelType::Pointer inverseSensorModel = InverseSensorModelType::New();
inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
resModel = inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( resModel == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
inverseSensorModel->SetAverageElevation(averageElevation);
double deltaX = static_cast<double>(sizeIn[0]) / static_cast<double>(size_x);
......
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