diff --git a/app/otbLSGRM.cxx b/app/otbLSGRM.cxx index b5dd444238db0afd5ef90225fc164f9688a86894..c662c750b26e8b40c6eaebef648969e3bbaaf8ab 100644 --- a/app/otbLSGRM.cxx +++ b/app/otbLSGRM.cxx @@ -17,6 +17,9 @@ #include "lsgrmFullLambdaScheduleSegmenter.h" #include "lsgrmController.h" +// Vectorization +#include "otbLabelImageToVectorDataFilter.h" + // system tools #include <itksys/SystemTools.hxx> @@ -45,6 +48,9 @@ public: typedef lsgrm::SpringSegmenter<ImageType> SpringSegmenterType; typedef lsgrm::FullLambdaScheduleSegmenter<ImageType> FLSSegmenterType; + /** Vectorization typedefs */ + typedef otb::LabelImageToVectorDataFilter<UInt32ImageType> VectorizeLabelFilterType; + private: /* Tiling mode choice */ @@ -63,6 +69,13 @@ private: CRITERION_FLS }; + /* Output mode */ + enum OutMode + { + OUTPUT_MODE_RASTER, + OUTPUT_MODE_VECTOR + }; + void DoInit() { SetName("GenericRegionMerging"); @@ -70,10 +83,16 @@ private: "(LSGRM) and provides currently 3 homogeneity criteria: Euclidean Distance, " "Full Lambda Schedule and Baatz & Schape criterion."); - // Input and Output images + // Input image AddParameter(ParameterType_InputImage, "in", "Input Image"); - AddParameter(ParameterType_OutputImage, "out", "Ouput Label Image"); - SetDefaultOutputPixelType("out", ImagePixelType_uint32); + + // Outputs + AddParameter(ParameterType_Choice, "mode", "output mode"); + AddChoice("mode.raster", "Output is a label image"); + AddChoice("mode.vector", "Output is a vector layer"); + AddParameter(ParameterType_OutputImage, "mode.raster.out", "Ouput Label Image"); + SetDefaultOutputPixelType("mode.raster.out", ImagePixelType_uint32); + AddParameter(ParameterType_OutputVectorData, "mode.vector.out", "Output vector layer"); // Criterion choice AddParameter(ParameterType_Choice, "criterion", "Homogeneity criterion to use"); @@ -121,7 +140,19 @@ private: { // Get output filename (without extension) - std::string outfname = GetParameterString("out"); + std::string outfname; + if (GetParameterInt("mode") == OUTPUT_MODE_RASTER) + { + outfname = GetParameterAsString("mode.raster.out"); + } + else if (GetParameterInt("mode") == OUTPUT_MODE_VECTOR) + { + outfname = GetParameterAsString("mode.vector.out"); + } + else + { + otbAppLogFATAL("Unknown output mode"); + } std::string outbfname = itksys::SystemTools::GetFilenameWithoutExtension(outfname.c_str()); // Get specified temporary directory @@ -133,6 +164,10 @@ private: else { tmpdir = itksys::SystemTools::GetFilenamePath(outfname); + if (tmpdir.empty()) + { + tmpdir = itksys::SystemTools::GetCurrentWorkingDirectory(true); + } } if (!tmpdir.empty()) @@ -266,7 +301,21 @@ private: labelImage->SetProjectionRef(inputImage->GetProjectionRef()); labelImage->SetOrigin(inputImage->GetOrigin()); labelImage->SetSpacing(inputImage->GetSpacing()); - SetParameterOutputImage<UInt32ImageType>("out", labelImage); + + if (GetParameterInt("mode") == OUTPUT_MODE_RASTER) + { + SetParameterOutputImage<UInt32ImageType>("mode.raster.out", labelImage); + } + else if (GetParameterInt("mode") == OUTPUT_MODE_VECTOR) + { + VectorizeLabelFilterType::Pointer vectorizeFilter = + VectorizeLabelFilterType::New(); + vectorizeFilter->SetInput(labelImage); + vectorizeFilter->SetInputMask(labelImage); + vectorizeFilter->Update(); + SetParameterOutputVectorData("mode.vector.out", vectorizeFilter->GetOutput()); + } + }