diff --git a/Testing/Fa/CMakeLists.txt b/Testing/Fa/CMakeLists.txt index 354bdd8d0a510135f4f82931e9a406d4d2869831..045c5d124fd10a127f7dddaea6f1c12456aa619c 100644 --- a/Testing/Fa/CMakeLists.txt +++ b/Testing/Fa/CMakeLists.txt @@ -54,6 +54,9 @@ TARGET_LINK_LIBRARIES(0000428-CastImageFilterStreaming OTBIO OTBCommon OTBBasicF ADD_EXECUTABLE(0000433-LineSegmentDetector_8b_16b_compare 0000433-LineSegmentDetector_8b_16b_compare.cxx) TARGET_LINK_LIBRARIES(0000433-LineSegmentDetector_8b_16b_compare OTBIO OTBFeatureExtraction) +ADD_EXECUTABLE(otbVectorDataToLabelImageFilterWithoutReader otbVectorDataToLabelImageFilterWithoutReader.cxx) +TARGET_LINK_LIBRARIES(otbVectorDataToLabelImageFilterWithoutReader OTBBasicFilters OTBIO OTBCommon) + IF(BUILD_APPLICATIONS) ADD_EXECUTABLE(0000436-WrapperInputImage_GetImage 0000436-WrapperInputImage_GetImage.cxx) TARGET_LINK_LIBRARIES(0000436-WrapperInputImage_GetImage OTBApplicationEngine) diff --git a/Testing/Fa/Failing/CMakeLists.txt b/Testing/Fa/Failing/CMakeLists.txt index 5ca733305d3dbb6d9414fa8ddb9d1b1926a5840b..cd356e1b0d809e3078ab4c90914262b514c94cf7 100644 --- a/Testing/Fa/Failing/CMakeLists.txt +++ b/Testing/Fa/Failing/CMakeLists.txt @@ -27,6 +27,12 @@ ADD_TEST(NAME FA-0000495-StreamingImageFileWriterProgressReporting ${TEMP}/FA-0000495-output1.tif ${TEMP}/FA-0000495-output2.tif) + +ADD_TEST(NAME otbVectorDataToLabelImageFilterWithoutReader + COMMAND ${CXX_TEST_PATH}/otbVectorDataToLabelImageFilterWithoutReader + ${TEMP}/rasterizedVectorData.tif) + + # ------- Vectorization issue ----------------------------------- # http://bugs.orfeo-toolbox.org/view.php?id=94 ADD_TEST(FA-0000094-fe-PolygonsVectorization ${CXX_TEST_PATH}/0000094-PolygonsVectorization diff --git a/Testing/Fa/otbVectorDataToLabelImageFilterWithoutReader.cxx b/Testing/Fa/otbVectorDataToLabelImageFilterWithoutReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4434f7cd3ba151880451a8958f3bed7ab40de20f --- /dev/null +++ b/Testing/Fa/otbVectorDataToLabelImageFilterWithoutReader.cxx @@ -0,0 +1,161 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Copyright (c) Institut Telecom; Telecom Bretagne. All rights reserved. + See ITCopyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +#include "otbVectorData.h" + +#include "otbVectorDataToLabelImageFilter.h" +#include "otbStandardOneLineFilterWatcher.h" + +typedef otb::Image<unsigned int, 2> ImageType; +typedef otb::VectorData<> VectorDataType; +typedef otb::ImageFileReader<ImageType> ReaderType; +typedef otb::StreamingImageFileWriter<ImageType> WriterType; +typedef otb::VectorDataToLabelImageFilter<VectorDataType, + ImageType> RasterizationFilterType; + +typedef VectorDataType::DataNodeType DataNodeType; + +typedef DataNodeType::PointType PointType; +typedef DataNodeType::LineType LineType; +typedef DataNodeType::PolygonType PolygonType; +typedef LineType::VertexType VertexType; + +int main(int argc, char* argv[]) +{ + + //OGRRegisterAll(); + + // Create vector Data + + VectorDataType::Pointer data = VectorDataType::New(); + + DataNodeType::Pointer document = DataNodeType::New(); + DataNodeType::Pointer folder = DataNodeType::New(); + + DataNodeType::Pointer polygon1 = DataNodeType::New(); + DataNodeType::Pointer polygon2 = DataNodeType::New(); + DataNodeType::Pointer polygon3 = DataNodeType::New(); + DataNodeType::Pointer polygon4 = DataNodeType::New(); + DataNodeType::Pointer polygon5 = DataNodeType::New(); + + document->SetNodeType(otb::DOCUMENT); + folder->SetNodeType(otb::FOLDER); + polygon1->SetNodeType(otb::FEATURE_POLYGON); + + document->SetNodeId("DOCUMENT"); + folder->SetNodeId("THE_FOLDER"); + polygon1->SetNodeId("FEATURE_POLYGON"); + + VertexType p1; + p1.Fill(1); + + VertexType p3; + p3.Fill(11); + + VertexType p2; + p2[0] = 1; + p2[1] = 11; + + VertexType p4; + p4[0] = 11; + p4[1] = 1; + + PolygonType::Pointer poly1 = PolygonType::New(); + poly1->AddVertex(p1); + poly1->AddVertex(p2); + poly1->AddVertex(p3); + poly1->AddVertex(p4); + poly1->AddVertex(p1); + polygon1->SetPolygonExteriorRing(poly1); + polygon1->SetFieldAsInt("DN",32); + + + p1.Fill(51); + + p3.Fill(61); + + p2[0] = 51; + p2[1] = 61; + + p4[0] = 61; + p4[1] = 51; + + + PolygonType::Pointer poly2 = PolygonType::New(); + poly2->AddVertex(p1); + poly2->AddVertex(p2); + poly2->AddVertex(p3); + poly2->AddVertex(p4); + poly2->AddVertex(p1); + polygon2->SetLine(poly2); + polygon2->SetFieldAsInt("DN",64); + + + + + DataNodeType::Pointer root = data->GetDataTree()->GetRoot()->Get(); + + data->GetDataTree()->Add(document, root); + data->GetDataTree()->Add(folder, document); + data->GetDataTree()->Add(polygon1, folder); + data->GetDataTree()->Add(polygon2, folder); + + data->Update(); + + // rasterize + RasterizationFilterType::Pointer rasterization = RasterizationFilterType::New(); + rasterization->AddVectorData(data); + + + + rasterization->SetBurnAttribute("DN"); + + + // image infos + ImageType::SizeType size; + size[0] = 100; + size[1] = 100; + + ImageType::PointType origin; + origin[0]=0; + origin[1]=0; + + ImageType::SpacingType spacing; + spacing[0]=1; + spacing[1]=1; + + + rasterization->SetOutputSize(size); + rasterization->SetOutputOrigin(origin); + rasterization->SetOutputSpacing(spacing); + + otb::StandardOneLineFilterWatcher * watch = new otb::StandardOneLineFilterWatcher(rasterization.GetPointer(), + "rasterization"); + + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(argv[1]); + writer->SetInput(rasterization->GetOutput()); + writer->Update(); + +return EXIT_SUCCESS; +}