Skip to content
Snippets Groups Projects
Commit bbdada00 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

ENH : add coherence with itk positive spacing

add Get and Set SignedSpacing in image and vector image otb class
modify spacing utilisation in GDALIO
parent c6f02268
No related branches found
No related tags found
No related merge requests found
......@@ -174,6 +174,15 @@ public:
/** Get the six coefficients of affine geoTtransform. */
virtual VectorType GetGeoTransform(void) const;
/** Get signed spacing */
SpacingType GetSignedSpacing() const;
/** Set signed spacing */
virtual void SetSignedSpacing( SpacingType spacing );
virtual void SetSignedSpacing( double spacing[ VImageDimension ] );
virtual void SetSignedSpacing( float spacing[ VImageDimension ] );
/** Get image corners. */
virtual VectorType GetUpperLeftCorner(void) const;
virtual VectorType GetUpperRightCorner(void) const;
......
......@@ -148,6 +148,74 @@ Image<TPixel, VImageDimension>::GetLowerRightCorner(void) const
return (this->GetMetaDataInterface()->GetLowerRightCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::SpacingType
Image<TPixel, VImageDimension>::GetSignedSpacing() const
{
auto spacing = this->GetSpacing();
for ( unsigned int i = 0; i < Image::ImageDimension; ++i )
{
if (this->m_Direction[i][i] < 0 )
spacing[i] = - spacing[i];
}
return spacing;
}
template <class TPixel, unsigned int VImageDimension>
void Image<TPixel, VImageDimension>
::SetSignedSpacing( SpacingType spacing)
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
void Image<TPixel, VImageDimension>
::SetSignedSpacing( double spacing[ VImageDimension ])
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
void Image<TPixel, VImageDimension>
::SetSignedSpacing( float spacing[ VImageDimension ])
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < ImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::ImageKeywordlistType
Image<TPixel, VImageDimension>::GetImageKeywordlist(void)
......
......@@ -144,6 +144,14 @@ public:
/** Get the six coefficients of affine geoTtransform. */
virtual VectorType GetGeoTransform(void) const;
/** Get signed spacing */
SpacingType GetSignedSpacing() const;
/** Set signed spacing */
virtual void SetSignedSpacing( SpacingType spacing );
virtual void SetSignedSpacing( double spacing[ VImageDimension ] );
virtual void SetSignedSpacing( float spacing[ VImageDimension ] );
/** Get image corners. */
virtual VectorType GetUpperLeftCorner(void) const;
virtual VectorType GetUpperRightCorner(void) const;
......
......@@ -150,6 +150,74 @@ VectorImage<TPixel, VImageDimension>::GetLowerRightCorner(void) const
return (this->GetMetaDataInterface()->GetLowerRightCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename VectorImage<TPixel, VImageDimension>::SpacingType
VectorImage<TPixel, VImageDimension>::GetSignedSpacing() const
{
auto spacing = this->GetSpacing();
for ( unsigned int i = 0; i < VImageDimension; ++i )
{
if (this->m_Direction[i][i] < 0 )
spacing[i] = - spacing[i];
}
return spacing;
}
template <class TPixel, unsigned int VImageDimension>
void VectorImage<TPixel, VImageDimension>
::SetSignedSpacing( SpacingType spacing)
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
void VectorImage<TPixel, VImageDimension>
::SetSignedSpacing( double spacing[ VImageDimension ])
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
void VectorImage<TPixel, VImageDimension>
::SetSignedSpacing( float spacing[ VImageDimension ])
{
for ( unsigned int i = 0; i < VImageDimension; i++ )
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
}
template <class TPixel, unsigned int VImageDimension>
typename VectorImage<TPixel, VImageDimension>::ImageKeywordlistType
VectorImage<TPixel, VImageDimension>::GetImageKeywordlist(void)
......
......@@ -1686,8 +1686,8 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
if (projectionRef.empty()
&& (vcl_abs(m_Origin[0] - 0.5) > Epsilon
|| vcl_abs(m_Origin[1] - 0.5) > Epsilon
|| vcl_abs(m_Spacing[0] - 1.0) > Epsilon
|| vcl_abs(m_Spacing[1] - 1.0) > Epsilon) )
|| vcl_abs(m_Spacing[0] * m_Direction[0][0] - 1.0) > Epsilon
|| vcl_abs(m_Spacing[1] * m_Direction[1][1] - 1.0) > Epsilon) )
{
// See issue #303 :
// If there is no ProjectionRef, and the GeoTransform is not the identity,
......@@ -1768,18 +1768,18 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
/* -------------------------------------------------------------------- */
if ( vcl_abs(m_Origin[0] - 0.5) > Epsilon
|| vcl_abs(m_Origin[1] - 0.5) > Epsilon
|| vcl_abs(m_Spacing[0] - 1.0) > Epsilon
|| vcl_abs(m_Spacing[1] - 1.0) > Epsilon )
|| vcl_abs(m_Spacing[0] * m_Direction[0][0] - 1.0) > Epsilon
|| vcl_abs(m_Spacing[1] * m_Direction[1][1] - 1.0) > Epsilon )
{
// Only set the geotransform if it is not identity (it may erase GCP)
itk::VariableLengthVector<double> geoTransform(6);
/// Reporting origin and spacing
// Beware : GDAL origin is at the corner of the top-left pixel
// whereas OTB/ITK origin is at the centre of the top-left pixel
geoTransform[0] = m_Origin[0] - 0.5*m_Spacing[0];
geoTransform[3] = m_Origin[1] - 0.5*m_Spacing[1];
geoTransform[1] = m_Spacing[0];
geoTransform[5] = m_Spacing[1];
geoTransform[0] = m_Origin[0] - 0.5 * m_Spacing[0] * m_Direction[0][0];
geoTransform[3] = m_Origin[1] - 0.5 * m_Spacing[1] * m_Direction[1][1];
geoTransform[1] = m_Spacing[0] * m_Direction[0][0];
geoTransform[5] = m_Spacing[1] * m_Direction[1][1];
// FIXME: Here component 1 and 4 should be replaced by the orientation parameters
geoTransform[2] = 0.;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment