modifié : include/Appli/Option.hpp
modifié : src/Appli/Option.cpp modifié : src/apGenerator.cpp
This commit is contained in:
parent
2fbc95ffc0
commit
db7037f624
@ -27,6 +27,7 @@ namespace otb {
|
||||
vector<double> 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);
|
||||
|
||||
@ -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<unsigned int> (&coreCount), "thread used to build tree (default hardware value)")
|
||||
// ("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation attributs")
|
||||
// ("moment-of-inertia,I", po::value<string> (&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")
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "triskeleDebug.hpp"
|
||||
#include "triskeleBase.hpp"
|
||||
@ -30,6 +31,25 @@
|
||||
using namespace otb::triskele;
|
||||
using namespace otb::triskele::arrayTree;
|
||||
|
||||
template<typename PixelT>
|
||||
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<typename PixelT>
|
||||
inline
|
||||
void apGenerator (Option &option) {
|
||||
@ -52,13 +72,14 @@ void apGenerator (Option &option) {
|
||||
vector <vector <PixelT> > allBands (maxThresholds, vector<PixelT> (leafCount, 0));
|
||||
|
||||
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
||||
if (!option.oneBand)
|
||||
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
|
||||
|
||||
Raster<PixelT> 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<PixelT, PixelT> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user