Commit 97259b15 authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch 'ice-segfault' into 'develop'

Fix segfault in Ice and Monteverdi

See merge request !859
parents 850ce475 ad2a8115
Pipeline #8861 passed with stages
in 97 minutes and 18 seconds
......@@ -165,7 +165,7 @@ struct OTBMetadata_EXPORT RPCParam
oss << " \"" << array[loop] << "\", ";
oss << "]";
return oss.str();
};
}
// Equality comparison with tolerance
template <class BinaryPredicate>
......
......@@ -106,6 +106,8 @@ public:
const boost::any & operator[](const MDGeom& key) const;
const Projection::GCPParam & GetGCPParam() const;
const Projection::RPCParam & GetRPCParam() const;
const SARParam & GetSARParam() const;
std::string GetProjectedGeometry() const;
......@@ -334,6 +336,11 @@ OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata & imd);
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string & filename);
/** Comparison test */
bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
bool HasSameSensorModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
} // end namespace otb
#endif
......@@ -206,6 +206,16 @@ struct OTBMetadata_EXPORT SARParam
/** Keywordlist import */
void FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
// Equality comparison operator (hidden friend idiom)
friend bool operator==(const SARParam & lhs, const SARParam & rhs)
{
MetaData::Keywordlist lhs_kwl;
lhs.ToKeywordlist(lhs_kwl, "");
MetaData::Keywordlist rhs_kwl;
rhs.ToKeywordlist(rhs_kwl, "");
return lhs_kwl == rhs_kwl;
}
};
/** \struct SARCalib
......
......@@ -56,6 +56,16 @@ const Projection::GCPParam & ImageMetadataBase::GetGCPParam() const
return boost::any_cast<const Projection::GCPParam &>(GeometryKeys.at(MDGeom::GCP));
}
const Projection::RPCParam & ImageMetadataBase::GetRPCParam() const
{
return boost::any_cast<const Projection::RPCParam &>(GeometryKeys.at(MDGeom::RPC));
}
const SARParam & ImageMetadataBase::GetSARParam() const
{
return boost::any_cast<const SARParam &>(GeometryKeys.at(MDGeom::SAR));
}
std::string ImageMetadataBase::GetProjectedGeometry() const
{
if (this->Has(MDGeom::ProjectionWKT))
......@@ -843,5 +853,43 @@ void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string &
}
}
bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
bool aHasRpc = a.Has(MDGeom::RPC);
bool bHasRpc = b.Has(MDGeom::RPC);
if (aHasRpc && bHasRpc)
// Both have a model
return a.GetRPCParam() == b.GetRPCParam();
else if (aHasRpc != bHasRpc)
// One has a model, not the other
return false;
// Both don't have a model
return true;
}
bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
bool aHasSar = a.Has(MDGeom::SAR);
bool bHasSar = b.Has(MDGeom::SAR);
if (aHasSar && bHasSar)
// Both have a model
return a.GetSARParam() == b.GetSARParam();
else if (aHasSar != bHasSar)
// One has a model, not the other
return false;
// Both don't have a model
return true;
}
bool HasSameSensorModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
return HasSameRPCModel(a, b) && HasSameSARModel(a, b);
}
}
......@@ -157,6 +157,7 @@ private:
SizeType m_ViewportSize;
std::string m_Wkt;
const ImageMetadataType* m_ImageMetadata;
const ImageMetadataType m_DefaultImageMetadata;
PointType m_RotationCenter;
double m_RotationAngle;
bool m_UseProjection : 1;
......
......@@ -723,9 +723,6 @@ void GlImageActor::ImageRegionToViewportExtent(const RegionType& region, double
void GlImageActor::ImageRegionToViewportQuad(const RegionType & region, PointType & ul, PointType & ur, PointType & ll, PointType & lr, bool rotate) const
{
// Retrieve settings
ViewSettings::ConstPointer settings = this->GetSettings();
itk::ContinuousIndex<double,2> cul,cur,cll,clr;
cul[0] = region.GetIndex()[0];
......@@ -780,9 +777,6 @@ void GlImageActor::ImageRegionToViewportQuad(const RegionType & region, PointTyp
void GlImageActor::ViewportExtentToImageRegion(const double& ulx, const double & uly, const double & lrx, const double & lry, RegionType & region) const
{
// Retrieve settings
ViewSettings::ConstPointer settings = this->GetSettings();
RegionType largest = m_FileReader->GetOutput()->GetLargestPossibleRegion();
PointType ul,ur,ll,lr,tul,tur,tll,tlr;
......@@ -1092,12 +1086,15 @@ void GlImageActor::UpdateTransforms()
// << std::hex << this << std::dec
// << " WKT-changed: " << isEqualOrNot << std::endl;
//TODO OSSIM: Replace KeywordList by ImageMetadata in the settings object
geometryChanged = geometryChanged
|| (m_ViewportToImageTransform.IsNotNull() && m_ViewportToImageTransform->GetInputProjectionRef() != settings->GetWkt())
|| (m_ImageToViewportTransform.IsNotNull() && m_ImageToViewportTransform->GetOutputProjectionRef() != settings->GetWkt())
|| (m_ViewportToImageTransform.IsNotNull() /*&& !(m_ViewportToImageTransform->GetInputKeywordList() == settings->GetKeywordList())*/)
|| (m_ImageToViewportTransform.IsNotNull() /*&& !(m_ImageToViewportTransform->GetOutputKeywordList() == settings->GetKeywordList())*/);
|| (m_ViewportToImageTransform.IsNotNull() && m_ViewportToImageTransform->GetInputImageMetadata() == nullptr)
|| (m_ImageToViewportTransform.IsNotNull() && m_ImageToViewportTransform->GetInputImageMetadata() == nullptr)
|| (m_ViewportToImageTransform.IsNotNull() && !HasSameSensorModel(*(m_ViewportToImageTransform->GetInputImageMetadata()),
*(settings->GetImageMetadata())))
|| (m_ImageToViewportTransform.IsNotNull() && !HasSameSensorModel(*(m_ImageToViewportTransform->GetInputImageMetadata()),
*(settings->GetImageMetadata())));
if(settings->GetUseProjection() && geometryChanged)
{
......
......@@ -28,12 +28,14 @@ ViewSettings::ViewSettings() :
m_Wkt( "" ),
m_RotationAngle( 0.0 ),
m_UseProjection( true ),
m_GeometryChanged( false )
m_GeometryChanged( false ),
m_DefaultImageMetadata()
{
m_Origin.Fill( 0 );
m_Spacing.Fill( 1 );
m_ViewportSize.Fill( 0 );
m_RotationCenter.Fill( 0 );
m_ImageMetadata = &m_DefaultImageMetadata;
}
ViewSettings::~ViewSettings()
......@@ -49,7 +51,7 @@ ViewSettings
m_Wkt = "";
m_ImageMetadata = nullptr;
m_ImageMetadata = &m_DefaultImageMetadata;;
m_UseProjection = true;
m_GeometryChanged = false;
......
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