Commit ad239de1 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

BUG : negative spacing compiling version

parent 9b5d6859
......@@ -32,6 +32,49 @@
#include "otbImageMetadataInterfaceBase.h"
namespace otb
{
namespace internal
{
template < class ImageType >
typename ImageType::SpacingType GetSignedSpacing( ImageType * input)
{
typename ImageType::SpacingType spacing = input->GetSpacing();
typename ImageType::DirectionType direction = input->GetDirection();
for ( unsigned int i = 0 ; i < ImageType::ImageDimension ; i++ )
{
spacing[i] *= direction[i][i] ;
}
return spacing;
}
template < class InputImage , typename SpacingType >
void SetSignedSpacing( InputImage input , SpacingType spacing )
{
// TODO check for spacing size ==> error
typename InputImage::DirectionType direction = input->GetDirection();
for ( unsigned int i = 0 ; i < InputImage::VImageDimension ; i++ )
{
// TODO check if spacing[i] = 0 ==> error
if ( spacing[ i ] < 0 )
{
if ( direction[i][i] > 0 )
{
for ( unsigned int j = 0 ; j < InputImage::VImageDimension ; j++ )
{
direction[j][i] = - direction[j][i];
}
}
spacing[i] = -spacing[i];
}
}
input->SetDirection( direction );
input->SetSpacing( spacing );
}
}
}
namespace otb
{
/** \class Image
......
......@@ -170,11 +170,14 @@ void Image<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
if ( this->m_Direction[i][i] > 0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
......@@ -188,9 +191,12 @@ void Image<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
if ( this->m_Direction[i][i] > 0 )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
}
spacing[i] = - spacing[i];
}
......@@ -206,9 +212,12 @@ void Image<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < ImageDimension; ++j )
if ( this->m_Direction[i][i] > 0 )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
}
spacing[i] = - spacing[i];
}
......
......@@ -172,11 +172,14 @@ void VectorImage<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
if ( this->m_Direction[i][i] > 0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
spacing[i] = - spacing[i];
}
}
spacing[i] = - spacing[i];
}
}
this->SetSpacing(spacing);
......@@ -190,9 +193,12 @@ void VectorImage<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
if ( this->m_Direction[i][i] > 0 )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
}
spacing[i] = - spacing[i];
}
......@@ -208,9 +214,12 @@ void VectorImage<TPixel, VImageDimension>
{
if ( spacing[i] < 0.0 )
{
for ( unsigned j = 0; j < VImageDimension; ++j )
if ( this->m_Direction[i][i] > 0 )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
for ( unsigned j = 0; j < VImageDimension; ++j )
{
this->m_Direction[j][i] = - this->m_Direction[j][i];
}
}
spacing[i] = - spacing[i];
}
......
......@@ -113,7 +113,7 @@ PointSetToDensityImageFilter<TInputPointSet, TOutputImage, TDensityFunction>
region.SetIndex(start);
outputPtr->SetOrigin(this->GetOrigin());
outputPtr->SetSignedSpacing(this->GetSignedSpacing());
outputPtr->SetSignedSpacing(this->GetSpacing());
outputPtr->SetRegions(region);
}
......
......@@ -24,6 +24,7 @@
#include "otbGridResampleImageFilter.h"
#include "otbStreamingTraits.h"
#include "otbImage.h"
#include "itkNumericTraits.h"
#include "itkProgressReporter.h"
......@@ -68,7 +69,7 @@ GridResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecision>
::SetOutputParametersFromImage(const ImageBaseType * image)
{
this->SetOutputOrigin ( image->GetOrigin() );
this->SetOutputSpacing ( image->GetSignedSpacing() );
this->SetOutputSpacing ( internal::GetSignedSpacing( image ) );
this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
}
......
......@@ -23,6 +23,7 @@
#include "otbStreamingResampleImageFilter.h"
#include "itkProgressAccumulator.h"
#include "otbImage.h"
namespace otb
{
......@@ -121,7 +122,7 @@ StreamingResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionTy
::SetOutputParametersFromImage(const ImageBaseType * image)
{
this->SetOutputOrigin ( image->GetOrigin() );
this->SetOutputSpacing ( image->GetSignedSpacing() );
this->SetOutputSpacing ( internal::GetSignedSpacing( image ) );
this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
}
......
......@@ -324,13 +324,18 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
double origin[TOutputImage::ImageDimension];
typename TOutputImage::DirectionType direction;
std::vector<double> axis;
int spacing_sign (0);
for (unsigned int i = 0; i < TOutputImage::ImageDimension; ++i)
{
if (i < this->m_ImageIO->GetNumberOfDimensions())
{
dimSize[i] = this->m_ImageIO->GetDimensions(i);
spacing[i] = this->m_ImageIO->GetSpacing(i);
if ( this->m_ImageIO->GetSpacing(i) < 0 )
spacing_sign = -1;
else
spacing_sign = 1;
spacing[i] = spacing_sign * this->m_ImageIO->GetSpacing(i);
origin[i] = this->m_ImageIO->GetOrigin(i);
// Please note: direction cosines are stored as columns of the
// direction matrix
......@@ -339,7 +344,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
if (j < this->m_ImageIO->GetNumberOfDimensions())
{
direction[j][i] = axis[j];
direction[j][i] = spacing_sign * axis[j];
}
else
{
......@@ -387,9 +392,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
output->SetOrigin(origin); // Set the image origin
output->SetDirection(direction); // Set the image direction cosines
output->SetSignedSpacing(spacing); // Set the image spacing
// Need to set spacing after direction as we are setting a signed spacing
// it might change signes of direction column
output->SetSpacing(spacing); // Set the image spacing
if(!m_KeywordListUpToDate && !m_FilenameHelper->GetSkipGeom())
{
......
......@@ -554,15 +554,19 @@ ImageFileWriter<TInputImage>
// Setup the ImageIO with information from inputPtr
//
m_ImageIO->SetNumberOfDimensions(TInputImage::ImageDimension);
const typename TInputImage::SpacingType& spacing = inputPtr->GetSignedSpacing();
const typename TInputImage::SpacingType& spacing = inputPtr->GetSpacing();
const typename TInputImage::PointType& origin = inputPtr->GetOrigin();
const typename TInputImage::DirectionType& direction = inputPtr->GetDirection();
int direction_sign(0);
for (unsigned int i = 0; i < TInputImage::ImageDimension; ++i)
{
if ( direction[i][i] < 0 )
direction_sign = -1;
else
direction_sign = 1;
// Final image size
m_ImageIO->SetDimensions(i, inputRegion.GetSize(i));
m_ImageIO->SetSpacing(i, spacing[i]);
m_ImageIO->SetSpacing(i, direction_sign * spacing[i]);
m_ImageIO->SetOrigin(i, origin[i] + static_cast<double>(inputRegion.GetIndex()[i]) * spacing[i]);
vnl_vector<double> axisDirection(TInputImage::ImageDimension);
......@@ -570,7 +574,7 @@ ImageFileWriter<TInputImage>
// direction matrix
for (unsigned int j = 0; j < TInputImage::ImageDimension; ++j)
{
axisDirection[j] = direction[j][i];
axisDirection[j] = direction_sign * direction[j][i];
}
m_ImageIO->SetDirection(i, axisDirection);
}
......
......@@ -27,6 +27,7 @@
#include "otbImageMetadataInterfaceFactory.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbImage.h"
#include "gdal_alg.h"
#include "stdint.h" //needed for uintptr_t
......@@ -126,7 +127,7 @@ OGRDataSourceToLabelImageFilter<TOutputImage>
::SetOutputParametersFromImage(const ImageBaseType * image)
{
this->SetOutputOrigin ( image->GetOrigin() );
this->SetOutputSpacing ( image->GetSignedSpacing() );
this->SetOutputSpacing ( internal::GetSignedSpacing( image ) );
this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(image->GetMetaDataDictionary());
......
......@@ -127,7 +127,7 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>
::SetOutputParametersFromImage(const ImageBaseType * src)
{
this->SetOutputOrigin ( src->GetOrigin() );
this->SetOutputSpacing ( src->GetSignedSpacing() );
this->SetOutputSpacing ( src->GetSpacing() );
this->SetOutputSize ( src->GetLargestPossibleRegion().GetSize() );
ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(src->GetMetaDataDictionary());
this->SetOutputProjectionRef(imi->GetProjectionRef());
......@@ -301,10 +301,10 @@ VectorDataToLabelImageFilter<TVectorData, TOutputImage>::GenerateData()
OutputIndexType bufferIndexOrigin = bufferedRegion.GetIndex();
OutputOriginType bufferOrigin;
this->GetOutput()->TransformIndexToPhysicalPoint(bufferIndexOrigin, bufferOrigin);
geoTransform[0] = bufferOrigin[0] - 0.5 * this->GetOutput()->GetSignedSpacing()[0];
geoTransform[3] = bufferOrigin[1] - 0.5 * this->GetOutput()->GetSignedSpacing()[1];
geoTransform[1] = this->GetOutput()->GetSignedSpacing()[0];
geoTransform[5] = this->GetOutput()->GetSignedSpacing()[1];
geoTransform[0] = bufferOrigin[0] - 0.5 * this->GetOutput()->GetSpacing()[0];
geoTransform[3] = bufferOrigin[1] - 0.5 * this->GetOutput()->GetSpacing()[1];
geoTransform[1] = this->GetOutput()->GetSpacing()[0];
geoTransform[5] = this->GetOutput()->GetSpacing()[1];
// FIXME: Here component 1 and 4 should be replaced by the orientation parameters
geoTransform[2] = 0.;
......
......@@ -305,17 +305,17 @@ VectorDataToLabelMapFilter<TVectorData, TLabelMap>
VertexType vertex;
otbMsgDevMacro( "Polygon bounding region " << polygonExtRingBoundReg);
otbMsgDevMacro( "output origin " << this->GetOutput()->GetOrigin());
otbMsgDevMacro( "spacing " << this->GetOutput()->GetSignedSpacing());
otbMsgDevMacro( "spacing " << this->GetOutput()->GetSpacing());
// For each position in the bounding region of the polygon
for (double i = polygonExtRingBoundReg.GetOrigin(0);
i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0);
i += this->GetOutput()->GetSignedSpacing()[0])
i += this->GetOutput()->GetSpacing()[0])
{
vertex[0] = static_cast<VertexValueType>(i);
for (double j = polygonExtRingBoundReg.GetOrigin(1);
j < polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1);
j += this->GetOutput()->GetSignedSpacing()[1])
j += this->GetOutput()->GetSpacing()[1])
{
vertex[1] = static_cast<VertexValueType>(j);
......
......@@ -148,7 +148,7 @@ void VectorDataToLabelMapWithAttributesFilter<TVectorData, TLabelMap>
// Compute origin and size
SizeType size;
SpacingType spacing = this->GetInput()->GetSignedSpacing();
SpacingType spacing = this->GetInput()->GetSpacing();
OriginType origin = m_VectorDataProperties->GetBoundingRegion().GetOrigin();
for (unsigned int i=0; i<2; ++i)
{
......
......@@ -94,7 +94,7 @@ int otbVectorDataToLabelMapFilter(int argc, char * argv[])
//Set size, origin and spacing of the output labelmap
myFilter->SetSize(p->GetBoundingRegion().GetImageRegion().GetSize());
myFilter->SetOrigin(origin);
myFilter->SetSpacing(reader->GetOutput()->GetSignedSpacing());
myFilter->SetSpacing(reader->GetOutput()->GetSpacing());
// Translate the LabelMap in a labeld image
LabelMapToLabelImageFilterType::Pointer labelMapToImageFilter = LabelMapToLabelImageFilterType::New();
......
......@@ -87,7 +87,7 @@ UnaryFunctorImageFilter< TInputImage, TOutputImage, TFunction >
// dimensions to copy
unsigned int i, j;
const typename InputImageType::SpacingType &
inputSpacing = inputPtr->GetSignedSpacing();
inputSpacing = inputPtr->GetSpacing();
const typename InputImageType::PointType &
inputOrigin = inputPtr->GetOrigin();
const typename InputImageType::DirectionType &
......@@ -133,7 +133,7 @@ UnaryFunctorImageFilter< TInputImage, TOutputImage, TFunction >
}
// set the spacing and origin
outputPtr->SetSignedSpacing(outputSpacing);
outputPtr->SetSpacing( outputSpacing );
outputPtr->SetOrigin(outputOrigin);
outputPtr->SetDirection(outputDirection);
outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
......
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