modifié : include/ArrayTree/ArrayTreeBuilder.hpp

modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	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/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         src/Tree.cpp
	modifié :         src/testMain.cpp
This commit is contained in:
Git Merciol 2018-02-19 19:28:52 +01:00
parent 675b87e17e
commit 3d46f792d6
20 changed files with 68 additions and 53 deletions

View File

@ -23,7 +23,7 @@ namespace otb {
template <typename WeightT, typename PixelT>
class ArrayTreeBuilder : public TreeBuilder {
protected:
const unsigned int coreCount;
unsigned int coreCount;
const Raster<PixelT> &raster;
const GraphWalker &graphWalker;
TreeType type;
@ -35,8 +35,7 @@ namespace otb {
DimImg *newCompId;
WeightT *compWeights;
public:
inline ArrayTreeBuilder (const unsigned int &coreCount,
Raster<PixelT> &raster, const GraphWalker &graphWalker,
inline ArrayTreeBuilder (Raster<PixelT> &raster, const GraphWalker &graphWalker,
const TreeType &treeType, const bool &countingSort = true);
inline ~ArrayTreeBuilder ();

View File

@ -4,10 +4,9 @@
// ========================================
template<typename WeightT, typename PixelT>
inline
ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (const unsigned int &coreCount,
Raster<PixelT> &raster, const GraphWalker &graphWalker,
ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (Raster<PixelT> &raster, const GraphWalker &graphWalker,
const TreeType &treeType, const bool &countingSort) :
coreCount (coreCount),
coreCount (boost::thread::hardware_concurrency ()),
raster (raster),
graphWalker (graphWalker),
type (treeType),
@ -83,8 +82,7 @@ template<typename WeightFunct>
inline void
ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &weightFunct) {
DEF_LOG ("ArrayTreeBuilder::buildTree", "");
//XXX initWeights (graphWalker, weightFunct);
coreCount = tree.getCoreCount ();
// buildParents
vector<Edge<WeightT> > allEdges (graphWalker.edgeMaxCount ());

View File

@ -9,7 +9,7 @@ namespace otb {
class AreaAttributes : public CompAttributeC<DimImg> {
public:
inline AreaAttributes (const Tree &tree, const unsigned int &treeCoreCount);
inline AreaAttributes (const Tree &tree);
inline ~AreaAttributes ();
protected:
inline void compute ();

View File

@ -2,8 +2,8 @@
#define _OTB_TRISKELE_AREA_ATTRIBUTES_TPP
inline
AreaAttributes::AreaAttributes (const Tree &tree, const unsigned int &treeCoreCount)
: CompAttributeC<DimImg> (tree, treeCoreCount) {
AreaAttributes::AreaAttributes (const Tree &tree)
: CompAttributeC<DimImg> (tree) {
compute ();
}

View File

@ -12,7 +12,7 @@ namespace otb {
class AverageAttributes : public CompAttributeC<double> {
public:
template<typename PixelT>
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount);
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
inline ~AverageAttributes ();
protected:
template<typename PixelT>

View File

@ -3,8 +3,8 @@
template<typename PixelT>
inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) {
compute (raster, areaAttributes);
}

View File

@ -9,7 +9,7 @@ namespace otb {
class MoIAttributes : public CompAttributeC<double> {
public:
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes, const unsigned int &treeCoreCount);
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
inline ~MoIAttributes ();
protected:
inline void compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);

View File

@ -2,8 +2,8 @@
#define _OTB_TRISKELE_MOI_ATTRIBUTES_TPP
inline
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
: CompAttributeC<double> (tree) {
compute (areaAttributes, xyAttributes);
}

View File

@ -10,7 +10,7 @@ namespace otb {
class SDAttributes : public CompAttributeC<double> {
public:
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount);
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~SDAttributes ();
protected:
inline void compute (const AreaAttributes &areaAttributes);

View File

@ -2,8 +2,8 @@
#define _OTB_TRISKELE_SD_ATTRIBUTES_TPP
inline
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) {
compute (areaAttributes);
}

View File

@ -14,7 +14,7 @@ namespace otb {
};
class XYAttributes : public CompAttributeC<AverageXY> {
public:
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount);
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~XYAttributes ();
protected:
inline void compute (const AreaAttributes &areaAttributes);

View File

@ -2,8 +2,8 @@
#define _OTB_TRISKELE_XY_ATTRIBUTES_TPP
inline
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<AverageXY> (tree, treeCoreCount) {
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<AverageXY> (tree) {
compute (areaAttributes);
}

View File

@ -48,7 +48,7 @@ namespace otb {
template<typename AttrT>
class CompAttributeC : public CompAttribute<AttrT> {
public:
inline CompAttributeC (const Tree &tree, const unsigned int &treeCoreCount);
inline CompAttributeC (const Tree &tree);
inline ~CompAttributeC ();
template<typename PixelT>
@ -60,8 +60,6 @@ namespace otb {
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection);
protected:
const unsigned int treeCoreCount;
template<typename CumpFunctPSE>
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/);
};

View File

@ -66,9 +66,8 @@ CompAttribute<AttrT>::book (const DimImg &leafCount) {
// ========================================
template<typename AttrT>
inline
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree, const unsigned int &treeCoreCount)
: CompAttribute<AttrT> (tree),
treeCoreCount (treeCoreCount) {
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
: CompAttribute<AttrT> (tree) {
}
template<typename AttrT>
@ -81,14 +80,15 @@ template<typename CumpFunctPSE>
inline void
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < treeCoreCount) {
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
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, treeCoreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
const DimImg parentId = id+first;
cumpFunctPSE (parentId);
});
@ -101,7 +101,7 @@ template<typename PixelT>
inline void
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection) {
dealThreadRange (CompAttribute<AttrT>::leafCount, treeCoreCount, [this, &allBands, &attributeProfiles, &pixelAttrValue, &selection] (const DimImg &leafId) {
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::coreCount, [this, &allBands, &attributeProfiles, &pixelAttrValue, &selection] (const DimImg &leafId) {
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, selection);
});
}

View File

@ -56,7 +56,7 @@ namespace triskele {
template<typename PixelT>
inline void readBand (Raster<PixelT> &raster, DimChanel band, const Point &cropOrig, const Size &cropSize) const;
template<typename PixelT>
inline void writeBand (Raster<PixelT> &raster, DimChanel band) const;
inline void writeBand (PixelT *pixels, DimChanel band) const;
private:
IImage (const IImage &o) = delete;

View File

@ -131,12 +131,12 @@ IImage::readBand (Raster<PixelT> &raster, DimChanel band, const Point &cropOrig,
template<typename PixelT>
inline void
IImage::writeBand (Raster<PixelT> &raster, DimChanel band) const {
IImage::writeBand (PixelT *pixels, DimChanel band) const {
DEF_LOG ("IImage::writeBand", "band: " << band);
BOOST_ASSERT (gdalOutputDataset);
band++; // !!! GDAL layers starts at 1 (not 0 :-( )
GDALRasterBand &poBand = *gdalOutputDataset->GetRasterBand (band);
CPLErr err = poBand.RasterIO (GF_Write, 0, 0, size.width, size.height, raster.getPixels (), size.width, size.height, dataType, 0, 0);
CPLErr err = poBand.RasterIO (GF_Write, 0, 0, size.width, size.height, pixels, size.width, size.height, dataType, 0, 0);
if (err != CE_None)
cerr << "IImage::writeBand: can't acces " << fileName << endl;
}

View File

@ -5,6 +5,7 @@
#include <map>
#include <string>
#include <numeric>
#include <boost/thread.hpp>
#include "triskeleBase.hpp"
#include "triskeleDebug.hpp"
@ -26,6 +27,9 @@ namespace otb {
inline DimNodeId *getChildCount ();
protected:
/*! nb core for build and compute attributes */
const unsigned int coreCount;
/*! Info about the picture */
Size size;
@ -56,8 +60,9 @@ namespace otb {
public:
// Constructors, destructor and resize method (does the same as the constructors)
Tree (const DimSideImg &width, const DimSideImg &height);
Tree ();
// XXX test sans defaut treeCoreCount
Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount = boost::thread::hardware_concurrency ());
Tree (unsigned int coreCount = boost::thread::hardware_concurrency ());
~Tree ();
/*! clear values according to the size defined */
@ -69,6 +74,8 @@ namespace otb {
inline void setNodeCount (const DimImg &newNodeCount);
inline void setSize (const Size &newSize);
inline unsigned int getCoreCount () const;
// Get the tree state and the size
inline State getState () const;
inline Size getSize () const;

View File

@ -2,6 +2,11 @@
#define _OTB_TRISKELE_TREE_TPP
// ========================================
inline unsigned int
Tree::getCoreCount () const {
return coreCount;
}
inline DimNodeId *
Tree::getChildCount () {
return childCount;

View File

@ -3,14 +3,15 @@
using namespace otb::triskele;
using namespace std;
Tree::Tree (const DimSideImg &width, const DimSideImg &height)
: Tree ()
Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount)
: Tree (coreCount)
{
resize (width, height);
}
Tree::Tree ()
Tree::Tree (unsigned int coreCount)
: size (),
coreCount (coreCount),
leafCount (0),
nodeCount (0),
leafParents (nullptr),

View File

@ -32,39 +32,46 @@ using namespace otb::triskele::arrayTree;
template<typename PixelT>
inline
void prog (const Option &option) {
void prog (Option &option) {
Raster<PixelT> raster;
option.inputImage.readBand (raster, option.chanel, option.topLeft, option.size);
Border border; // default = no border
GraphWalker graphWalker (raster.getSize (), border);
ArrayTreeBuilder<PixelT, PixelT> atb (option.treeCoreCount, raster, graphWalker, TreeType::MAX);
Tree tree;
ArrayTreeBuilder<PixelT, PixelT> atb (raster, graphWalker, TreeType::MAX);
Tree tree (option.treeCoreCount);
WeightAttributes<PixelT> weightAttributes (tree);
atb.buildTree (tree, weightAttributes);
weightAttributes.printValues ("weight");
tree.printTree ();
AttributeProfiles<PixelT> attributeProfiles (tree);
atb.setAttributProfiles (attributeProfiles, raster);
attributeProfiles.printValues ();
AreaAttributes areaAttributes (tree, option.treeCoreCount);
AreaAttributes areaAttributes (tree);
areaAttributes.printValues ("area");
AverageAttributes averageAttributes (tree, raster, areaAttributes, option.treeCoreCount);
AverageAttributes averageAttributes (tree, raster, areaAttributes);
averageAttributes.printValues ("average");
SDAttributes sdAttributes (tree, areaAttributes, option.treeCoreCount);
SDAttributes sdAttributes (tree, areaAttributes);
sdAttributes.printValues ("sd");
XYAttributes xyAttributes (tree, areaAttributes, option.treeCoreCount);
XYAttributes xyAttributes (tree, areaAttributes);
//xyAttributes.printValues ("XY"); // pb print de complexe
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes, option.treeCoreCount);
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
moiAttributes.printValues ("moi");
// XXX cut
// XXX cut allProfiles.clear ();
DimChanel nbBands = 1;
vector <vector <PixelT> > allBands (tree.getLeafCount (), vector<PixelT> (nbBands, 0));
// attribute.cut (out, attributProfiles, threshold)
// XXX write
tree.printTree ();
option.outputImage.createImage (tree.getSize (), option.inputImage.getDataType (), nbBands);
for (DimChanel c = 0; c < nbBands; ++c)
option.outputImage.writeBand (&allBands[c][0], c);
cerr << endl << "*** prog ok!" << endl;
}