Commit 73357bfb authored by Julien Michel's avatar Julien Michel

TEST: Add a failing test to demonstrate issue 1963

parent 569686e4
Pipeline #2579 passed with stages
in 5 minutes and 53 seconds
......@@ -126,6 +126,8 @@ otb_add_test(NAME dmTvStreamingWarpImageFilter COMMAND otbTransformTestDriver
5
)
otb_add_test(NAME dmTvStreamingWarpImageFilterEmtpyRegion COMMAND otbTransformTestDriver
otbStreamingWarpImageFilterEmptyRegion)
# Forward / Backward projection consistency checking
set(FWDBWDChecking_INPUTS
......
......@@ -25,6 +25,17 @@
#include "otbImageFileWriter.h"
#include "otbStreamingWarpImageFilter.h"
// Images definition
const unsigned int Dimension = 2;
typedef double PixelType;
typedef otb::Image<PixelType, Dimension> ImageType;
typedef itk::Vector<PixelType, 2> DisplacementValueType;
typedef otb::Image<DisplacementValueType, Dimension> DisplacementFieldType;
// Warper
typedef otb::StreamingWarpImageFilter<ImageType, ImageType, DisplacementFieldType> ImageWarperType;
int otbStreamingWarpImageFilter(int argc, char* argv[])
{
if (argc != 5)
......@@ -39,20 +50,11 @@ int otbStreamingWarpImageFilter(int argc, char* argv[])
const char * outfname = argv[3];
const double maxdef = atoi(argv[4]);
// Images definition
const unsigned int Dimension = 2;
typedef double PixelType;
typedef otb::Image<PixelType, Dimension> ImageType;
typedef itk::Vector<PixelType, 2> DisplacementValueType;
typedef otb::Image<DisplacementValueType, Dimension> DisplacementFieldType;
// Change default output origin
ImageType::PointType origin;
origin.Fill(0.5);
// Warper
typedef otb::StreamingWarpImageFilter<ImageType, ImageType, DisplacementFieldType> ImageWarperType;
// Reader/Writer
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileReader<DisplacementFieldType> DisplacementReaderType;
......@@ -83,3 +85,75 @@ int otbStreamingWarpImageFilter(int argc, char* argv[])
return EXIT_SUCCESS;
}
int otbStreamingWarpImageFilterEmptyRegion(int, char**)
{
ImageType:: Pointer inputPtr = ImageType::New();
ImageType::RegionType largestRegion;
ImageType::SizeType largestSize = {{10,10}};
ImageType::IndexType largestIndex = {{1,1}};
largestRegion.SetIndex(largestIndex);
largestRegion.SetSize(largestSize);
inputPtr->SetRegions(largestRegion);
ImageType::RegionType emptyRegion;
ImageType::SizeType emptySize = {{0,0}};
ImageType::IndexType emptyIndex = {{0,0}};
emptyRegion.SetSize(emptySize);
emptyRegion.SetIndex(emptyIndex);
inputPtr->SetRequestedRegion(emptyRegion);
inputPtr->SetBufferedRegion(emptyRegion);
DisplacementFieldType::Pointer dispPtr = DisplacementFieldType::New();
dispPtr->SetRegions(largestRegion);
dispPtr->Allocate();
DisplacementValueType v;
v[0]=-100;
v[1]=-100;
dispPtr->FillBuffer(v);
ImageWarperType::Pointer warper = ImageWarperType::New();
warper->SetDisplacementField(dispPtr);
warper->SetInput(inputPtr);
ImageType::PointType outputOrigin;
outputOrigin.Fill(0);
warper->SetOutputOrigin(outputOrigin);
// requested region for full output is completely outside largest
// possible region of input
warper->GetOutput()->UpdateOutputInformation();
// Before bugfix this would lead to famous ITK exception outside of
// largest possible region
warper->GetOutput()->PropagateRequestedRegion();
// After requested region has been propagated, we need to be sure
// that requested region can be cropped by largest region
auto requestedRegion = inputPtr->GetRequestedRegion();
std::cout<<requestedRegion<<std::endl;
std::cout<<inputPtr->GetLargestPossibleRegion()<<std::endl;
if (! requestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
{
std::cerr<<"Requested region can not be cropped by largest region"<<std::endl;
return EXIT_FAILURE;
}
// And we also need to check that requested region is not largest
// region
if( inputPtr->GetRequestedRegion().GetNumberOfPixels() != 0)
{
std::cerr<<"Requested region should have {{0, 0}} size"<<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -31,6 +31,7 @@ void RegisterTests()
REGISTER_TEST(otbCreateProjectionWithOTB);
REGISTER_TEST(otbGenericMapProjection);
REGISTER_TEST(otbStreamingWarpImageFilter);
REGISTER_TEST(otbStreamingWarpImageFilterEmptyRegion);
REGISTER_TEST(otbInverseLogPolarTransform);
REGISTER_TEST(otbInverseLogPolarTransformResample);
REGISTER_TEST(otbStreamingResampleImageFilterWithAffineTransform);
......
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