modifié : include/Appli/Option.hpp

modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/AverageAttributes.hpp
	modifié :         include/Attributes/AverageAttributes.tpp
	modifié :         include/Attributes/MoIAttributes.hpp
	modifié :         include/Attributes/MoIAttributes.tpp
	modifié :         include/Attributes/SDAttributes.hpp
	modifié :         include/Attributes/SDAttributes.tpp
	modifié :         include/Attributes/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Attributes/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/triskeleDealThreads.tpp
	modifié :         src/Appli/Option.cpp
	modifié :         src/IImage.cpp
	modifié :         src/apGenerator.cpp
This commit is contained in:
Git Merciol 2018-04-20 09:49:46 +02:00
parent f687310939
commit aff93d5467
19 changed files with 137 additions and 115 deletions

View File

@ -25,7 +25,7 @@ namespace otb {
Selected selectedBand;
size_t countingSortCeil = 2;
vector<DimImg> areaThresholds;
vector<double> sdThresholds, moiThresholds;
vector<double> levelThresholds, sdThresholds, moiThresholds;
unsigned int coreCount = boost::thread::hardware_concurrency ();
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false;
bool oneBand = false;

View File

@ -9,7 +9,7 @@
namespace otb {
namespace triskele {
class AreaAttributes : public CompAttributeC<DimImg> {
class AreaAttributes : public CompAttribute<DimImg> {
public:
inline AreaAttributes (const Tree &tree);
inline ~AreaAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline
AreaAttributes::AreaAttributes (const Tree &tree)
: CompAttributeC<DimImg> (tree) {
: CompAttribute<DimImg> (tree) {
compute ();
}
@ -18,7 +18,7 @@ inline void
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const vector<DimImg> &thresholds) const {
auto start = high_resolution_clock::now ();
CompAttributeC<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
CompAttribute<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
}

View File

@ -11,7 +11,7 @@
namespace otb {
namespace triskele {
class AverageAttributes : public CompAttributeC<double> {
class AverageAttributes : public CompAttribute<double> {
public:
template<typename PixelT>
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);

View File

@ -6,7 +6,7 @@ using namespace boost::chrono;
template<typename PixelT>
inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) {
: CompAttribute<double> (tree) {
compute (raster, areaAttributes);
}

View File

@ -9,7 +9,7 @@
namespace otb {
namespace triskele {
class MoIAttributes : public CompAttributeC<double> {
class MoIAttributes : public CompAttribute<double> {
public:
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
inline ~MoIAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
: CompAttributeC<double> (tree) {
: CompAttribute<double> (tree) {
compute (areaAttributes, xyAttributes);
}
@ -23,8 +23,8 @@ MoIAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<P
auto start = high_resolution_clock::now ();
double maxValue = CompAttribute<double>::getMaxValue ();
cerr << "moi max value:" << maxValue << endl;
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
}

View File

@ -11,7 +11,7 @@
namespace otb {
namespace triskele {
class SDAttributes : public CompAttributeC<double> {
class SDAttributes : public CompAttribute<double> {
public:
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~SDAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) {
: CompAttribute<double> (tree) {
compute (areaAttributes);
}
@ -23,8 +23,8 @@ SDAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<Pi
auto start = high_resolution_clock::now ();
double maxValue = CompAttribute<double>::getMaxValue ();
cerr << "sd max value:" << maxValue << endl;
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
}

View File

@ -2,6 +2,8 @@
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
#include <boost/chrono.hpp>
#include "triskeleBase.hpp"
namespace otb {
@ -15,6 +17,9 @@ namespace otb {
inline ~WeightAttributes ();
inline void setWeightBounds (Tree &tree);
template<typename PixelT>
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const vector<WeightT> &thresholds) const;
virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); return out; }
};

View File

@ -1,6 +1,8 @@
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
using namespace boost::chrono;
template<typename WeightT>
inline
WeightAttributes<WeightT>::WeightAttributes (const Tree &tree)
@ -39,4 +41,16 @@ WeightAttributes<WeightT>::setWeightBounds (Tree &tree) {
weightBounds.push_back (rootId+1);
}
template<typename WeightT>
template<typename PixelT>
inline void
WeightAttributes<WeightT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const vector<WeightT> &thresholds) const {
auto start = high_resolution_clock::now ();
CompAttribute<WeightT>::cut (allBands, attributeProfiles, 0., thresholds);
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
}
#endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP

View File

@ -18,7 +18,7 @@ namespace otb {
operator DimImg () const { return (DimImg) (x*y); }
};
class XYAttributes : public CompAttributeC<AverageXY> {
class XYAttributes : public CompAttribute<AverageXY> {
public:
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~XYAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<AverageXY> (tree) {
: CompAttribute<AverageXY> (tree) {
compute (areaAttributes);
}

View File

@ -14,6 +14,9 @@ namespace otb {
template<typename AttrT>
class CompAttribute {
public:
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
static inline vector<AttrT> getConvertedThresholds (const vector<double> &thresholds);
inline CompAttribute (const Tree &tree);
inline ~CompAttribute ();
@ -22,6 +25,14 @@ namespace otb {
inline AttrT *getValues ();
inline AttrT getMaxValue () const;
template<typename PixelT>
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
template<typename PixelT>
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
virtual inline ostream &print (ostream &out) const { print (out, ""); return out; }
protected:
@ -32,39 +43,19 @@ namespace otb {
inline void free ();
inline void book (const DimImg &leafCount);
template<typename CumpFunctPSE>
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
ostream &print (ostream &out, const string &msg) const;
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); }
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); return out; }
};
} // triskele
} // otb
#include "Attributes/WeightAttributes.hpp"
namespace otb {
namespace triskele {
template<typename AttrT>
class CompAttributeC : public CompAttribute<AttrT> {
public:
inline CompAttributeC (const Tree &tree);
inline ~CompAttributeC ();
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
template<typename PixelT>
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
template<typename PixelT>
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
protected:
template<typename CumpFunctPSE>
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
};
#include "CompAttribute.tpp"
} // triskele
} // otb

View File

@ -1,6 +1,26 @@
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
// ========================================
template<typename AttrT>
inline vector<AttrT>
CompAttribute<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
vector<AttrT> result;
for (double percent : thresholds)
result.push_back (percent*maxValue);
return result;
}
template<typename AttrT>
inline vector<AttrT>
CompAttribute<AttrT>::getConvertedThresholds (const vector<double> &thresholds) {
vector<AttrT> result;
for (double value : thresholds)
result.push_back ((AttrT) value);
return result;
}
// ========================================
template<typename AttrT>
inline
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
@ -47,78 +67,13 @@ CompAttribute<AttrT>::getMaxValue () const {
return max;
}
template<typename AttrT>
inline ostream &
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
cout << "values: " << msg << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
return cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::free () {
values = vector<AttrT> ();
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::book (const DimImg &leafCount) {
this->leafCount = leafCount;
values.resize (leafCount);
}
// ========================================
template<typename AttrT>
inline
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
: CompAttribute<AttrT> (tree) {
}
template<typename AttrT>
inline
CompAttributeC<AttrT>::~CompAttributeC () {
}
template<typename AttrT>
inline vector<AttrT>
CompAttributeC<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
vector<AttrT> result;
for (AttrT percent : thresholds)
result.push_back (percent*maxValue);
return result;
}
template<typename AttrT>
template<typename CumpFunctPSE>
inline void
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
LOG ("CompAttributeC::computeSameCompLevel: no thread");
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
return;
}
DimImg first = weightBounds [0];
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
DimImg next = weightBounds [curBound];
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
const DimImg parentId = id+first;
cumpFunctPSE (parentId);
});
first = next;
}
}
template<typename AttrT>
template<typename PixelT>
inline void
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
CompAttribute<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
DEF_LOG ("CompAttribute::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
});
@ -127,7 +82,7 @@ CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributePr
template<typename AttrT>
template<typename PixelT>
inline void
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
CompAttribute<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
// no debug (to many pixels)
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
@ -152,7 +107,7 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
AttrT ceil = thresholds[chanel];
for ( ; curValue < ceil && curId < rootId; ) {
if (parentId == DimImg_MAX || curId >= parentId) {
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
// cerr << "CompAttribute::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
for (; chanel < thresholdsSize; ++chanel)
allBands[chanel][leafId] = curValue;
return;
@ -167,4 +122,53 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
}
}
// ========================================
template<typename AttrT>
inline ostream &
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
cout << "values: " << msg << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
return out;
}
// ========================================
template<typename AttrT>
inline void
CompAttribute<AttrT>::free () {
values = vector<AttrT> ();
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::book (const DimImg &leafCount) {
this->leafCount = leafCount;
values.resize (leafCount);
}
// ========================================
template<typename AttrT>
template<typename CumpFunctPSE>
inline void
CompAttribute<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
DEF_LOG ("CompAttribute::computeSameCompLevel", "coreCount:" << coreCount);
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
LOG ("CompAttribute::computeSameCompLevel: no thread");
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
return;
}
DimImg first = weightBounds [0];
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
DimImg next = weightBounds [curBound];
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
const DimImg parentId = id+first;
cumpFunctPSE (parentId);
});
first = next;
}
}
// ========================================
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP

View File

@ -71,7 +71,7 @@ dealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
});
#else /* BOOST thread */
boost::thread tasks [coreCount];
std::vector<boost::thread> tasks;
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);

View File

@ -97,7 +97,7 @@ Option::parse (int argc, char** argv) {
bool helpFlag = false, versionFlag = false, useTheForceLuke = false;
string inputFileName, outputFileName, bandsRange;
long left = -1, top = -1, width = -1, height = -1;
string areaThresholdsName, sdThresholdsName, moiThresholdsName;
string areaThresholdsName, levelThresholdsName, sdThresholdsName, moiThresholdsName;
try {
desc.add_options ()
("help", po::bool_switch (&helpFlag), "produce this help message")
@ -115,6 +115,7 @@ Option::parse (int argc, char** argv) {
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
("level,L", po::value<string> (&levelThresholdsName), "produce level attributs")
("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation attributs")
("moment-of-inertia,M", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
;
@ -186,6 +187,7 @@ Option::parse (int argc, char** argv) {
usage ("Bad options");
}
areaThresholds = readThresholds<DimImg> (areaThresholdsName);
levelThresholds = readThresholds<double> (levelThresholdsName);
sdThresholds = readThresholds<double> (sdThresholdsName);
moiThresholds = readThresholds<double> (moiThresholdsName);

View File

@ -24,7 +24,7 @@ IImage::~IImage () {
void
IImage::readImage () {
DEF_LOG ("IImage::readImage", "fileName: " << fileName);
DEF_LOG ("IImage::readImage", "fileName: " << fileName << " c_str:" << fileName.c_str ());
BOOST_ASSERT (gdalInputDataset == nullptr);
BOOST_ASSERT (gdalOutputDataset == nullptr);
close ();

View File

@ -69,10 +69,10 @@ void apGenerator (Option &option) {
Border border (option.size, false); // default = no border
GraphWalker graphWalker (border);
DimImg leafCount = graphWalker.vertexMaxCount ();
DimChanel maxThresholds = max (max (option.areaThresholds.size (), option.sdThresholds.size ()), option.moiThresholds.size ());
DimChanel maxThresholds = max (max (max (option.areaThresholds.size (), option.levelThresholds.size ()), option.sdThresholds.size ()), option.moiThresholds.size ());
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 ()));
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.levelThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
if (!option.oneBand)
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
@ -96,6 +96,12 @@ void apGenerator (Option &option) {
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
writeBand (option, &allBands[c][0], chanel);
}
if (option.levelThresholds.size ()) {
vector<PixelT> thresholds (weightAttributes.getConvertedThresholds (option.levelThresholds));
weightAttributes.cut (allBands, attributeProfiles, thresholds);
for (DimChanel c = 0; c < option.levelThresholds.size (); ++c, ++chanel)
writeBand (option, &allBands[c][0], chanel);
}
if (option.sdThresholds.size ()) {
SDAttributes sdAttributes (tree, areaAttributes);
sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds);