Commit 2122e15c authored by Guillaume Pasero's avatar Guillaume Pasero

TEST: start regression test implementation for OGRDataToClassStatisticsFilter

parent 290e3108
......@@ -13,3 +13,6 @@ otb_module_target_label(otbSamplingTestDriver)
otb_add_test(NAME leTuOGRDataToClassStatisticsFilterNew COMMAND otbSamplingTestDriver
otbOGRDataToClassStatisticsFilterNew )
otb_add_test(NAME leTvOGRDataToClassStatisticsFilter COMMAND otbSamplingTestDriver
otbOGRDataToClassStatisticsFilter )
......@@ -30,3 +30,67 @@ int otbOGRDataToClassStatisticsFilterNew(int itkNotUsed(argc), char* itkNotUsed(
std::cout << filter << std::endl;
return EXIT_SUCCESS;
}
int otbOGRDataToClassStatisticsFilter(int argc, char* argv[])
{
typedef otb::VectorImage<float> InputImageType;
typedef otb::Image<unsigned char> MaskImageType;
typedef otb::OGRDataToClassStatisticsFilter<InputImageType,MaskImageType> FilterType;
if (argc < 3)
{
std::cout << "Usage : "<<argv[0]<< " input_vector output_stats" << std::endl;
}
std::string vectorPath(argv[1]);
std::string outputPath(argv[2]);
otb::ogr::DataSource::Pointer vectors = otb::ogr::DataSource::New(vectorPath);
InputImageType::RegionType region;
region.SetSize(0,100);
region.SetSize(1,50);
InputImageType::PointType origin;
origin.Fill(0.5);
InputImageType::PixelType pixel(3);
pixel.Fill(1);
InputImageType::Pointer inputImage = InputImageType::New();
inputImage->SetNumberOfComponentsPerPixel(3);
inputImage->SetRegions(region);
inputImage->SetOrigin(origin);
inputImage->Allocate();
inputImage->FillBuffer(pixel);
MaskImageType::Pointer mask = MaskImageType::New();
mask->SetRegions(region);
mask->SetOrigin(origin);
mask->Allocate();
itk::ImageRegionIterator<MaskImageType> it(mask,region);
unsigned int count = 0;
for (it.GoToBegin(); !it.IsAtEnd() ; ++it, ++count)
{
it.Set(count % 2);
}
std::string fieldName("Label");
FilterType::Pointer filter = FilterType::New();
filter->SetInput(inputImage);
filter->SetMask(mask);
filter->SetOGRData(vectors);
filter->SetFieldName(fieldName);
filter->Update();
FilterType::ClassCountMapType &classCount = filter->GetClassCountOutput()->Get();
FilterType::PolygonSizeMapType &polySize = filter->GetPolygonSizeOutput()->Get();
FilterType::ClassCountMapType::const_iterator itClass = classCount.begin();
std::cout << filter << std::endl;
return EXIT_SUCCESS;
}
......@@ -2,4 +2,5 @@
void RegisterTests()
{
REGISTER_TEST(otbOGRDataToClassStatisticsFilterNew);
REGISTER_TEST(otbOGRDataToClassStatisticsFilter);
}
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