From db7037f6242063d3909a6c62252f561b8fbaecfe Mon Sep 17 00:00:00 2001 From: Git Merciol Date: Sun, 25 Feb 2018 19:57:12 +0100 Subject: [PATCH] =?UTF-8?q?=09modifi=C3=A9=C2=A0:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20include/Appli/Option.hpp=20=09modifi=C3=A9=C2=A0:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20src/Appli/Option.cpp=20=09modifi=C3=A9=C2=A0:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20src/apGenerator.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Appli/Option.hpp | 1 + src/Appli/Option.cpp | 3 +-- src/apGenerator.cpp | 31 ++++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/Appli/Option.hpp b/include/Appli/Option.hpp index d8f40f9..435c9ad 100644 --- a/include/Appli/Option.hpp +++ b/include/Appli/Option.hpp @@ -27,6 +27,7 @@ namespace otb { vector sdThresholds, moiThresholds; unsigned int coreCount = boost::thread::hardware_concurrency (); bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false; + bool oneBand = false; Option (); Option (int argc, char** argv); diff --git a/src/Appli/Option.cpp b/src/Appli/Option.cpp index 0e60ac9..764c1f5 100644 --- a/src/Appli/Option.cpp +++ b/src/Appli/Option.cpp @@ -120,8 +120,7 @@ Option::parse (int argc, char** argv) { hide.add_options () ("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options") ("tree-core-count", po::value (&coreCount), "thread used to build tree (default hardware value)") - // ("standard-deviation,S", po::value (&sdThresholdsName), "produce standard deviation attributs") - // ("moment-of-inertia,I", po::value (&moiThresholdsName), "produce moment of inertia attributs") + ("one-band", po::bool_switch (&oneBand), "split all bands, one band per image") // ("no-border", po::bool_switch (&options.noBorder), "build tree with all pixels (included no-data)") // ("dap", po::bool_switch (&options.dapFlag), "produce DAP rather than AP") // ("use-all-orig", po::bool_switch (&options.useAllOrigFlag), "force use all original band") diff --git a/src/apGenerator.cpp b/src/apGenerator.cpp index 285053e..0834221 100644 --- a/src/apGenerator.cpp +++ b/src/apGenerator.cpp @@ -1,4 +1,5 @@ #include +#include #include "triskeleDebug.hpp" #include "triskeleBase.hpp" @@ -30,6 +31,25 @@ using namespace otb::triskele; using namespace otb::triskele::arrayTree; +template +inline void +writeOneBand (Option &option, PixelT *pixels, DimChanel band) { + if (!option.oneBand) { + option.outputImage.writeBand (pixels, band); + return; + } + string outputBaseName = boost::filesystem::path (option.outputImage.getFileName ()).replace_extension ("").string (); + //boost::filesystem::basename (option.outputImage.getFileName ()); + string outputExtension = boost::filesystem::extension (option.outputImage.getFileName ()); + + ostringstream fileNameStream; + fileNameStream << outputBaseName << "-" << std::setfill ('0') << std::setw (3) << (band) << outputExtension; + IImage outputImage (fileNameStream.str ()); + outputImage.createImage (option.size, option.inputImage.getDataType (), 1); + outputImage.writeBand (pixels, 0); +} + + template inline void apGenerator (Option &option) { @@ -52,13 +72,14 @@ void apGenerator (Option &option) { vector > allBands (maxThresholds, vector (leafCount, 0)); DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ())); - option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard); + if (!option.oneBand) + option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard); Raster raster; DimChanel chanel = 0; for (DimChanel band : option.selectedBand.getSet ()) { option.inputImage.readBand (raster, band, option.topLeft, option.size); - option.outputImage.writeBand (raster.getPixels (), chanel++); + writeOneBand (option, raster.getPixels (), chanel++); for (TreeType treeType : treeTypes) { ArrayTreeBuilder atb (raster, graphWalker, treeType); @@ -72,20 +93,20 @@ void apGenerator (Option &option) { if (option.areaThresholds.size ()) { areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds); for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel) - option.outputImage.writeBand (&allBands[c][0], chanel); + writeOneBand (option, &allBands[c][0], chanel); } if (option.sdThresholds.size ()) { SDAttributes sdAttributes (tree, areaAttributes); sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds); for (DimChanel c = 0; c < option.sdThresholds.size (); ++c, ++chanel) - option.outputImage.writeBand (&allBands[c][0], chanel); + writeOneBand (option, &allBands[c][0], chanel); } if (option.moiThresholds.size ()) { XYAttributes xyAttributes (tree, areaAttributes); MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes); moiAttributes.cut (allBands, attributeProfiles, option.moiThresholds); for (DimChanel c = 0; c < option.moiThresholds.size (); ++c, ++chanel) - option.outputImage.writeBand (&allBands[c][0], chanel); + writeOneBand (option, &allBands[c][0], chanel); } } }