Commit d763b6a7 authored by Luc Hermitte's avatar Luc Hermitte
Browse files

ENH: Upgrade to use OTB8 API

parent 557ff3aa
......@@ -101,7 +101,8 @@ private:
{
// Clear and reset the DEM Handler
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
otb::DEMHandler::GetInstance().ClearDEMs();
// TODO: private function... can't be cleared
// otb::DEMHandler::GetInstance().ClearDEMs();
#else
otb::DEMHandler::Instance()->ClearDEMs();
#endif
......
......@@ -27,7 +27,6 @@
#include "otbWrapperApplicationFactory.h"
#include "otbFunctorImageFilter.h"
#include "otbDEMHandler.h"
#include "otbSarSensorModelAdapter.h"
// Elevation handler
#include "otbWrapperElevationParametersHandler.h"
#include "otbStringHelpers.h"
......@@ -62,7 +61,11 @@ struct XYZ_t
explicit XYZ_t(InputImageType & image)
{
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto const kwl = image.GetImageMetadata();
#else
auto const kwl = image.GetImageKeywordlist();
#endif
xband = value_or_unless(kwl, otb::bands::k_id_X, "extracting number of X band", 0);
yband = value_or_unless(kwl, otb::bands::k_id_Y, "extracting number of Y band", 1);
zband = value_or_unless(kwl, otb::bands::k_id_Z, "extracting number of Z band", 2);
......
......@@ -142,7 +142,11 @@ private:
// to estimate cartesian coordonates mean image)
FilterType::Pointer filterCartesianMeanEstimation = FilterType::New();
m_Ref.push_back(filterCartesianMeanEstimation.GetPointer());
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
filterCartesianMeanEstimation->SetSARImageMetadata(SARPtr->GetImageMetadata());
#else
filterCartesianMeanEstimation->SetSARImageKeyWorList(SARPtr->GetImageKeywordlist());
#endif
filterCartesianMeanEstimation->SetSARImagePtr(SARPtr);
filterCartesianMeanEstimation->SetDEMImagePtr(DEMPtr);
filterCartesianMeanEstimation->SetDEMInformation(0, DEMScanDirectionC, DEMScanDirectionL);
......
......@@ -22,7 +22,11 @@
#define otbPositionHelpers_h
#include "otbRepack.h"
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#include "otbSarSensorModel.h"
#else
#include "otbSarSensorModelAdapter.h"
#endif
#include <itkContinuousIndex.h>
namespace otb
......@@ -55,8 +59,12 @@ inline
auto WorldToCartesian(Point3DType const& lat_lon_hgt)
{
auto const p = otb::auto_repack(lat_lon_hgt);
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto xyz = Projection::WorldToEcef(p);
#else
itk::Point<double, 3> xyz;
otb::SarSensorModelAdapter::WorldToCartesian(p, xyz);
#endif
return xyz;
}
......
......@@ -24,9 +24,13 @@
#include "otbMacro.h"
// #include "ossim/ossimSarSensorModel.h"
// #define private public
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#include "otbSarSensorModel.h"
#else
#include "otbSarSensorModelAdapter.h"
// #undef private
#include "otbImageKeywordlist.h"
#endif
// #undef private
namespace otb
{
......@@ -45,7 +49,11 @@ namespace otb
* \internal The parameter is taken by value to permit internally copy-elision
* & move.
*/
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
std::unique_ptr<SarSensorModel> make_sensor_model(ImageMetadata const& kwl);
#else
SarSensorModelAdapter::Pointer make_sensor_model(ImageKeywordlist const& kwl);
#endif
using Point3DType = ::itk::Point<double,3>;
......@@ -80,7 +88,11 @@ auto distance(Point3DType const& p1, Point3DType const& p2)
* eventually.
*/
inline
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto position(SarSensorModel const& model, double line)
#else
auto position(SarSensorModelAdapter const& model, double line)
#endif
{
Point3DType pos, vel;
......
......@@ -190,7 +190,11 @@ private:
this->::itk::ProcessObject::GetInput(unsigned(idx)));
}
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
std::vector<VNLPoint3DType> InterpolatedAntennaPositions(ImageMetadata const& kwl) const;
#else
std::vector<VNLPoint3DType> InterpolatedAntennaPositions(ImageKeywordlist const& kwl) const;
#endif
std::vector<VNLPoint3DType> m_AntennaPositions;
......
......@@ -106,6 +106,22 @@ otb::SARComputeLocalIncidenceAngle<TInputImage,TOutputImage, TOutputLIAImage>
auto xyzImage = this->GetXYZInputImage();
assert(xyzImage);
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto kwl = xyzImage->GetImageMetadata();
// TODO: how can we clear anything that starts w/ "support_data.band."?
kwl.Remove(bands::k_id_X);
kwl.Remove(bands::k_id_Y);
kwl.Remove(bands::k_id_Z);
#if 0
kwl.Add(bands::k_id_LIA, "0");
kwl.Add(bands::k_id_abs_sin_LIA, "1");
#endif
outputSin->SetImageMetadata(kwl);
outputLIA->SetImageMetadata(kwl);
#else
auto kwl = xyzImage->GetImageKeywordlist();
// TODO: how can we clear anything that starts w/ "support_data.band."?
......@@ -120,13 +136,18 @@ otb::SARComputeLocalIncidenceAngle<TInputImage,TOutputImage, TOutputLIAImage>
outputSin->SetImageKeywordList(kwl);
outputLIA->SetImageKeywordList(kwl);
#endif
}
template <typename TInputImage, typename TOutputImage, typename TOutputLIAImage>
inline
std::vector<typename otb::SARComputeLocalIncidenceAngle<TInputImage, TOutputImage, TOutputLIAImage>::VNLPoint3DType>
otb::SARComputeLocalIncidenceAngle<TInputImage, TOutputImage, TOutputLIAImage>
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
::InterpolatedAntennaPositions(ImageMetadata const& kwl) const
#else
::InterpolatedAntennaPositions(ImageKeywordlist const& kwl) const
#endif
{
// Workaround just in case, force support_data.product_type to SLC
// kwl.AddKey("support_data.product_type", "SLC");
......@@ -146,7 +167,11 @@ otb::SARComputeLocalIncidenceAngle<TInputImage, TOutputImage, TOutputLIAImage>
{
// Note: ITK SmartPointer::operator* doesn't return a lvalue reference...
// Hence the convoluted `*shr.GetPointer()`...
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto const pos = repack<VNLPoint3DType>(position(*antennaSSM, line));
#else
auto const pos = repack<VNLPoint3DType>(position(*antennaSSM.GetPointer(), line));
#endif
res.push_back(pos);
}
return res;
......@@ -166,7 +191,11 @@ otb::SARComputeLocalIncidenceAngle<TInputImage,TOutputImage, TOutputLIAImage>
auto xyzImage = this->GetXYZInputImage();
assert(xyzImage);
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto const& kwlXYZ = xyzImage->GetImageMetadata();
#else
auto const& kwlXYZ = xyzImage->GetImageKeywordlist();
#endif
m_XBand = value_or_unless(kwlXYZ, bands::k_id_X, "extracting number of X band", 0);
m_YBand = value_or_unless(kwlXYZ, bands::k_id_Y, "extracting number of Y band", 1);
m_ZBand = value_or_unless(kwlXYZ, bands::k_id_Z, "extracting number of Z band", 2);
......@@ -174,7 +203,11 @@ otb::SARComputeLocalIncidenceAngle<TInputImage,TOutputImage, TOutputLIAImage>
auto normalImage = this->GetNormalInputImage();
assert(normalImage);
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto const& kwlNormal = xyzImage->GetImageMetadata();
#else
auto const& kwlNormal = xyzImage->GetImageKeywordlist();
#endif
m_nXBand = value_or_unless(kwlNormal, bands::k_id_X, "extracting number of nX band", 0);
m_nYBand = value_or_unless(kwlNormal, bands::k_id_Y, "extracting number of nY band", 1);
m_nZBand = value_or_unless(kwlNormal, bands::k_id_Z, "extracting number of nZ band", 2);
......
......@@ -22,8 +22,10 @@
#define otbSARDEMPolygonsAnalysisImageFilter2_h
#include "otbSpan.h"
#include "otbSarSensorModelAdapter.h"
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#else
#include "otbImageKeywordlist.h"
#endif
#include "otbGenericRSTransform.h"
#include "itkImageToImageFilter.h"
......@@ -150,7 +152,11 @@ public:
using OutputOptIterator = itk::ImageRegionIterator< ImageOutType >;
// Setter
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
void SetSARImageMetadata(ImageMetadata sarImageKWL);
#else
void SetSARImageKeyWorList(ImageKeywordlist const& sarImageKWL);
#endif
void SetSARImagePtr(ImageSARPointer sarPtr);
void SetDEMImagePtr(ImageDEMPointer demPtr);
void SetDEMInformation(double gain, int DEMDirC, int DEMDirL);
......@@ -237,17 +243,19 @@ private:
SARDEMPolygonsAnalysisImageFilter(const Self&) = delete;
Self& operator=(const Self &) = delete;
// Instance of SarSensorModelAdapter
SarSensorModelAdapter::Pointer m_SarSensorModelAdapter = nullptr;
// SAR Image (only metadata)
ImageSARPointer m_SarImagePtr;
// DEM Image (only metadata)
ImageDEMPointer m_DemImagePtr;
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
// SAR Image metadata
ImageMetadata m_SarImageKwl;
#else
// SAR Image KeyWorldList
ImageKeywordlist m_SarImageKwl;
#endif
// Multiplying gain to obtain a mean radiometry at 100
double m_Gain = 100.;
......
......@@ -86,10 +86,17 @@ auto as_ptr(itk::VariableLengthVector<T> const& vlv)
template<class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
void
SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
:: SetSARImageMetadata(ImageMetadata sarImageKWL)
{
m_SarImageKwl = std::move(sarImageKWL);
}
#else
::SetSARImageKeyWorList(ImageKeywordlist const& sarImageKWL)
{
m_SarImageKwl = sarImageKWL;
}
#endif
/**
* Set Sar Image Ptr
......@@ -157,7 +164,11 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TF
{
// Initialize the GenericRSTransform
m_RSTransform = RSTransformType2D::New();
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
m_RSTransform->SetInputImageMetadata( &(m_SarImagePtr->GetImageMetadata()) );
#else
m_RSTransform->SetInputKeywordList( m_SarImagePtr->GetImageKeywordlist() );
#endif
m_RSTransform->SetInputProjectionRef( m_SarImagePtr->GetProjectionRef() );
m_RSTransform->SetOutputProjectionRef(m_DemImagePtr->GetProjectionRef());
m_RSTransform->InstantiateTransform();
......@@ -209,7 +220,11 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
ImageInConstPointer inputPtr = this->GetInput();
ImageOutPointer outputPtr = this->GetOutput();
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto const& inputKwl = inputPtr->GetImageMetadata();
#else
ImageKeywordlist inputKwl = inputPtr->GetImageKeywordlist();
#endif
// SAR dimensions
m_NbLinesSAR = m_SarImagePtr->GetLargestPossibleRegion().GetSize()[1];
......@@ -258,7 +273,12 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
////////// Check the nature of Components into projeted DEM //////////
// The functor requires several components (with GetRequiredComponents). These components have to be into
// projeted DEM and correspond to a band into our input.
std::string BandKey = "support_data.band.";
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
std::string const RootKey = "band.";
#else
std::string const RootKey = "support_data.";
#endif
std::string const BandKey = RootKey + "band.";
std::vector<std::string> vecRequiredComponents = m_FunctionOnPolygon->GetRequiredComponents();
std::map<std::string, int> mapRequiredComponents;
......@@ -266,14 +286,23 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
{
std::string component = BandKey + requiredComponent;
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
if (!inputKwl.Has(component))
#else
if (!inputKwl.HasKey(component))
#endif
{
itkExceptionMacro(<<"Missing Component into Projeted DEM.");
return;
}
else
{
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
mapRequiredComponents[requiredComponent] = to<int>(inputKwl[component], "converting metadata "+component+ " (PolygonsAnalysisImageFilter)");
#else
mapRequiredComponents[requiredComponent] = to<int>(inputKwl.GetMetadataByKey(component), "converting metadata "+component+ " (PolygonsAnalysisImageFilter)");
#endif
}
}
......@@ -303,7 +332,11 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
outputPtr->SetDirection(m_SarImagePtr->GetDirection());
// Set new keyword list to output image
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
outputPtr->SetImageMetadata(m_SarImageKwl);
#else
outputPtr->SetImageKeywordList(m_SarImageKwl);
#endif
}
else if (m_OutGeometry == "ML")
{
......@@ -327,12 +360,21 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
outputPtr->SetSignedSpacing(outSP);
outputPtr->SetDirection(m_SarImagePtr->GetDirection());
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
// Add ML factors into keyWordList
m_SarImageKwl.Add(RootKey + "ml_ran", std::to_string(m_MLRan));
m_SarImageKwl.Add(RootKey + "ml_azi", std::to_string(m_MLAzi));
// Set new keyword list to output image
outputPtr->SetImageMetadata(m_SarImageKwl);
#else
// Add ML factors into keyWordList
m_SarImageKwl.AddKey("support_data.ml_ran", std::to_string(m_MLRan));
m_SarImageKwl.AddKey("support_data.ml_azi", std::to_string(m_MLAzi));
m_SarImageKwl.AddKey(RootKey + "ml_ran", std::to_string(m_MLRan));
m_SarImageKwl.AddKey(RootKey + "ml_azi", std::to_string(m_MLAzi));
// Set new keyword list to output image
outputPtr->SetImageKeywordList(m_SarImageKwl);
#endif
}
else
{
......@@ -342,15 +384,27 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
////////// Add the estimated bands to keywordList //////////
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
auto outputKwl = outputPtr->GetImageMetadata();
#else
ImageKeywordlist outputKwl = outputPtr->GetImageKeywordlist();
#endif
std::vector<std::string> vecEstimatedComponents = m_FunctionOnPolygon->GetEstimatedComponents();
for (unsigned int i = 0; i < vecEstimatedComponents.size(); i++)
{
std::string key = BandKey + vecEstimatedComponents[i];
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
outputKwl.Add(key, std::to_string(i));
#else
outputKwl.AddKey(key, std::to_string(i));
#endif
}
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
outputPtr->SetImageMetadata(outputKwl);
#else
outputPtr->SetImageKeywordList(outputKwl);
#endif
// Change Projection to fit with SAR image
outputPtr->SetProjectionRef(m_SarImagePtr->GetProjectionRef());
......
......@@ -20,7 +20,11 @@
#ifndef otbStringHelpers_h
#define otbStringHelpers_h
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
#include "otbImageMetadata.h"
#else
#include "otbImageKeywordlist.h"
#endif
#include "otbStringUtilities.h"
#include <string>
......@@ -65,6 +69,26 @@ inline std::string sto<std::string>(std::string const& s)
* \return the metadata found associated to the `key` decoded as a `T` type.
* \todo move this function to `StringUtilities.h`
*/
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
template <typename T>
inline
T value_or_unless(
otb::ImageMetadata const& kwl,
std::string const& key,
otb::string_view context,
T default_value)
{
if (kwl.Has(key))
{
auto const& value = kwl[key];
return to<T>(value, context);
}
else
{
return default_value;
}
}
#else
template <typename T>
inline
T value_or_unless(
......@@ -83,6 +107,7 @@ T value_or_unless(
return default_value;
}
}
#endif
}
// otb namespace
......
......@@ -22,6 +22,13 @@
namespace otb
{
#if defined(DRAFT_OTB8) || OTB_VERSION_MAJOR >= 8
std::unique_ptr<SarSensorModel> make_sensor_model(ImageMetadata const& kwl)
{
auto res = std::make_unique<SarSensorModel>(kwl);
return res;
}
#else
SarSensorModelAdapter::Pointer make_sensor_model(ImageKeywordlist const& kwl)
{ // parameter taken by value to permit copy elision & move-semantics
SarSensorModelAdapter::Pointer res = SarSensorModelAdapter::New();
......@@ -33,6 +40,7 @@ SarSensorModelAdapter::Pointer make_sensor_model(ImageKeywordlist const& kwl)
return res;
}
#endif
} // otb namespace
Supports Markdown
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