modifié : include/ArrayTree/ArrayTreeBuilder.tpp

modifié :         include/AttributeProfiles.hpp
	modifié :         include/AttributeProfiles.tpp
	modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/triskeleBase.tpp
	modifié :         src/Tree.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/testMain.cpp
This commit is contained in:
Git Merciol 2018-02-19 16:56:30 +01:00
parent 9e41428cc7
commit 869eda6449
13 changed files with 168 additions and 74 deletions

View File

@ -50,6 +50,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
break;
// XXX msg
}
weightAttributes.setWeightBounds (tree);
leaders.free ();
newCompId = nullptr;
buildChildren ();

View File

@ -14,6 +14,7 @@ namespace otb {
inline void updateTranscient ();
inline PixelT *getValues ();
inline void printValues () const;
protected:
const Tree &tree;

View File

@ -28,6 +28,14 @@ AttributeProfiles<PixelT>::getValues () {
return values;
}
template<typename PixelT>
inline void
AttributeProfiles<PixelT>::printValues () const {
cout << "AP" << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
printMap (cout, values, doubleSize, tree.getNodeCount ()) << endl << endl;
}
template<typename PixelT>
inline void
AttributeProfiles<PixelT>::free () {

View File

@ -7,13 +7,12 @@
namespace otb {
namespace triskele {
template<typename WeightT>
class AreaAttributes : public CompAttributeC<double> {
class AreaAttributes : public CompAttributeC<DimImg> {
public:
inline AreaAttributes (const Tree &tree, const WeightAttributes<WeightT> &weightAttributes, const unsigned int &treeCoreCount);
inline AreaAttributes (const Tree &tree, const unsigned int &treeCoreCount);
inline ~AreaAttributes ();
protected:
inline void compute (const WeightAttributes<WeightT> &weightAttributes);
inline void compute ();
};
#include "AreaAttributes.tpp"

View File

@ -1,22 +1,25 @@
#ifndef _OTB_TRISKELE_AREA_ATTRIBUTES_TPP
#define _OTB_TRISKELE_AREA_ATTRIBUTES_TPP
template<typename WeightT>
inline
AreaAttributes<WeightT>::AreaAttributes (const Tree &tree, const WeightAttributes<WeightT> &weightAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
compute (weightAttributes);
AreaAttributes::AreaAttributes (const Tree &tree, const unsigned int &treeCoreCount)
: CompAttributeC<DimImg> (tree, treeCoreCount) {
compute ();
}
template<typename WeightT>
inline
AreaAttributes<WeightT>::~AreaAttributes () {
AreaAttributes::~AreaAttributes () {
}
template<typename WeightT>
inline void
AreaAttributes<WeightT>::compute (const WeightAttributes<WeightT> &weightAttributes) {
// XXX
AreaAttributes::compute () {
computeSameCompLevel ([this] (const DimImg &parentId) {
DimImg area = 0;
tree.forEachChildTI (parentId, [this, &area] (const bool &isLeaf, const DimImg &childId) {
area += isLeaf ? 1 : CompAttribute<DimImg>::values [childId];
});
CompAttribute<DimImg>::values [parentId] = area;
});
}
#endif // _OTB_TRISKELE_AREA_ATTRIBUTES_TPP

View File

@ -13,6 +13,8 @@ namespace otb {
public:
inline WeightAttributes (const Tree &tree);
inline ~WeightAttributes ();
inline void setWeightBounds (Tree &tree);
};
#include "WeightAttributes.tpp"

View File

@ -12,4 +12,31 @@ inline
WeightAttributes<WeightT>::~WeightAttributes () {
}
template<typename WeightT>
inline void
WeightAttributes<WeightT>::setWeightBounds (Tree &tree) {
vector<DimImg> &weightBounds (tree.getWeightBounds ());
DimImg rootId = tree.getCompRoot ();
DimImg stepsCard = 0;
WeightT curLevel = CompAttribute<WeightT>::values [0];
for (DimImg compId = 1; compId <= rootId; ++compId) {
if (CompAttribute<WeightT>::values [compId] == curLevel)
continue;
++stepsCard;
curLevel = CompAttribute<WeightT>::values [compId];
}
weightBounds.clear ();
weightBounds.reserve (stepsCard+1);
weightBounds.push_back (0);
curLevel = CompAttribute<WeightT>::values [0];
for (DimImg compId = 1; compId <= rootId; ++compId) {
if (CompAttribute<WeightT>::values [compId] == curLevel)
continue;
weightBounds.push_back (compId);
curLevel = CompAttribute<WeightT>::values [compId];
}
weightBounds.push_back (rootId+1);
}
#endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP

View File

@ -30,13 +30,19 @@ namespace otb {
Size size;
/*! Number of pixels / leaf */
DimNodeId leafCount, nodeCount;
DimImg leafCount;
/*! number of node */
DimNodeId nodeCount; /* nodeCount = leafCount+compCount */
/*! Pointers on the parents of each leafs / nodes */
DimNodeId *leafParents, *compParents;
DimImg *leafParents, *compParents;
/*! Pointers on the children and count how many children a parents have */
DimNodeId *children, *childCount;
DimImg *childCount;
DimNodeId *children;
/*! Pointers of same weight in parents (+1 : last is root)*/
vector<DimImg> weightBounds;
/*! State of the tree */
State state;
@ -68,26 +74,34 @@ namespace otb {
inline Size getSize () const;
// Getters for tree structure
inline DimNodeId getRoot () const;
inline DimNodeId getAbsRoot () const;
inline DimNodeId getCompCount () const;
inline const DimImg &getLeafCount () const;
inline const DimNodeId &getNodeCount () const;
inline DimImg getCompCount () const;
inline DimNodeId getNodeRoot () const;
inline DimImg getCompRoot () const;
inline const DimNodeId &getParent (const DimNodeId &idx) const;
inline const DimNodeId &getLeafParent (const DimNodeId &idx) const;
inline const DimNodeId &getCompParent (const DimNodeId &idx) const;
inline const DimNodeId &getChildrenCount (const DimImg &idx) const;
inline const DimSideImg &getLeafCount () const;
inline const DimSideImg &getNodeCount () const;
inline const DimImg &getParent (const DimNodeId &nodeId) const;
inline const DimImg &getLeafParent (const DimImg &leafId) const;
inline const DimImg &getCompParent (const DimImg &compId) const;
inline const DimImg &getChildrenCount (const DimImg &CompId) const;
inline const DimNodeId &getChildren (const DimImg &childId) const;
inline const DimNodeId *getChildren () const; // XXX a virer ?
inline const vector<DimImg> &getWeightBounds () const;
inline vector<DimImg> &getWeightBounds ();
// Functions to apply to specific entities
template<typename FuncToApply>
void forEachLeaf (const FuncToApply &f /* f (DimNodeId leafId) */) const;
void forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const;
template<typename FuncToApply>
inline void forEachComp (const FuncToApply &f /* f (DimNodeId compId) */) const;
inline void forEachComp (const FuncToApply &f /* f (DimImg compId) */) const;
template<typename FuncToApply>
inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const;
template<typename FuncToApply>
inline void forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const;
#ifdef ENABLE_LOG
// Print info about the tree

View File

@ -1,6 +1,7 @@
#ifndef _OTB_TRISKELE_TREE_TPP
#define _OTB_TRISKELE_TREE_TPP
// ========================================
inline DimNodeId *
Tree::getChildCount () {
return childCount;
@ -25,56 +26,74 @@ Tree::getSize () const {
return size;
}
inline DimNodeId
Tree::getRoot () const {
return nodeCount-1;
}
inline DimNodeId
Tree::getAbsRoot () const {
return nodeCount-1+leafCount;
}
inline DimNodeId
Tree::getCompCount () const {
return nodeCount-leafCount;
}
inline const DimNodeId &
Tree::getParent (const DimNodeId &idx) const {
return leafParents[idx];
}
inline const DimNodeId &
Tree::getLeafParent (const DimNodeId &idx) const {
return leafParents[idx];
}
inline const DimNodeId &
Tree::getCompParent (const DimNodeId &idx) const {
return compParents[idx];
}
inline const DimNodeId &
Tree::getChildrenCount (const DimImg &idx) const {
return childCount[idx];
}
inline const DimSideImg &
Tree::getLeafCount () const {
return leafCount;
}
inline const DimSideImg &
inline const DimNodeId &
Tree::getNodeCount () const {
return nodeCount;
}
inline DimImg
Tree::getCompCount () const {
return (DimImg) (nodeCount-leafCount);
}
inline DimNodeId
Tree::getNodeRoot () const {
return nodeCount-1;
}
inline DimImg
Tree::getCompRoot () const {
return (DimImg) (nodeCount-1-leafCount);
}
inline const DimImg &
Tree::getParent (const DimNodeId &nodeId) const {
return leafParents[nodeId];
}
inline const DimImg &
Tree::getLeafParent (const DimImg &leafId) const {
return leafParents[leafId];
}
inline const DimImg &
Tree::getCompParent (const DimImg &compId) const {
return compParents[compId];
}
inline const DimImg &
Tree::getChildrenCount (const DimImg &compId) const {
return childCount[compId];
}
inline const DimNodeId &
Tree::getChildren (const DimImg &childId) const {
return children[childId];
}
inline const DimNodeId *
Tree::getChildren () const {
return children;
}
inline const vector<DimImg> &
Tree::getWeightBounds () const {
return weightBounds;
}
inline vector<DimImg> &
Tree::getWeightBounds () {
return weightBounds;
}
// ========================================
template<typename FuncToApply>
inline void
Tree::forEachLeaf (const FuncToApply &f /* f (DimNodeId leafId) */) const {
for (DimNodeId leafId = 0; leafId < leafCount; ++leafId)
Tree::forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const {
for (DimImg leafId = 0; leafId < leafCount; ++leafId)
f (leafId);
}
template<typename FuncToApply>
inline void
Tree::forEachComp (const FuncToApply &f /* f (DimNodeId compId) */) const {
DimNodeId compCount = nodeCount - leafCount;
Tree::forEachComp (const FuncToApply &f /* f (DimImg compId) */) const {
const DimNodeId compCount = getCompCount ();
for (DimNodeId compId = 0; compId < compCount; ++compId)
f (compId);
}
@ -86,5 +105,15 @@ Tree::forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNod
for (DimNodeId childId = minChild; childId < maxChild; ++childId)
f (children[childId]);
}
template<typename FuncToApply>
inline void
Tree::forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const {
DimNodeId minChild = childCount[parentId], maxChild = childCount[parentId+1];
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
const DimNodeId &child (getChildren (childId));
const bool isLeaf = child < leafCount;
f (isLeaf, isLeaf ? (DimImg) child : (DimImg) (child-leafCount));
}
}
#endif // _OTB_TRISKELE_TREE_TPP

View File

@ -108,9 +108,9 @@ idx2point (const Size &size, const DimImg &idx) {
}
template <typename DimImg>
template <typename T>
inline std::ostream &
printMap (std::ostream &out, const DimImg *map, const Size &size, DimNodeId maxValues) {
printMap (std::ostream &out, const T *map, const Size &size, DimNodeId maxValues) {
if (size.width > printMapMaxSide || size.height > printMapMaxSide) {
return out << "map too big to print!" << std::endl;
}
@ -121,9 +121,9 @@ printMap (std::ostream &out, const DimImg *map, const Size &size, DimNodeId maxV
if (!maxValues)
return out;
if (*map == DimImg_MAX)
out << " M";
out << " M ";
else
out << std::setw(3) << *map;
out << std::setw(3) << ((double) *map) << " ";
}
out << std::endl;
}

View File

@ -38,6 +38,7 @@ Tree::clear () {
fill_n (children, (leafCount-1)*2, 0);
fill_n (childCount, leafCount+1, 0);
#endif
weightBounds.resize (0);
}
void
@ -57,6 +58,7 @@ Tree::free () {
if (childCount)
delete[] childCount;
children = childCount = nullptr;
weightBounds.resize (0);
}
void

View File

@ -81,7 +81,7 @@ XMLTreeBuilder::exportToFile (const Tree &tree, const std::string &fileName) {
treeNode->SetAttribute ("height", tree.getSize ().height);
// Construct the tree
writeNodeChildren (tree, tree.getAbsRoot (), treeNode);
writeNodeChildren (tree, tree.getNodeRoot (), treeNode);
doc.SaveFile (fileName.c_str ());
}

View File

@ -21,6 +21,9 @@
#include "Attributes/WeightAttributes.hpp"
#include "AttributeProfiles.hpp"
#include "Attributes/AreaAttributes.hpp"
#include "Attributes/AverageAttributes.hpp"
#include "Attributes/SDAttributes.hpp"
#include "Attributes/XYAttributes.hpp"
//using namespace triskele;
using namespace otb::triskele;
@ -32,25 +35,30 @@ void prog (const Option &option) {
Raster<PixelT> raster;
option.inputImage.readBand (raster, option.chanel, option.topLeft, option.size);
Border border;
Border border; // default = no border
GraphWalker graphWalker (raster.getSize (), border);
ArrayTreeBuilder<PixelT, PixelT> atb (option.treeCoreCount, raster, graphWalker, TreeType::MAX);
Tree tree;
WeightAttributes<PixelT> weightAttributes (tree);
atb.buildTree (tree, weightAttributes);
weightAttributes.printValues ("weight");
// XXX buildAttr
AttributeProfiles<PixelT> attributeProfiles (tree);
atb.setAttributProfiles (attributeProfiles, raster);
attributeProfiles.printValues ();
AreaAttributes<PixelT> areaAttributes (tree, weightAttributes, option.treeCoreCount);
// AverageAttributs<PixelT> averageAttributs (tree, raster);
// SDAttributs sdAttributs (tree, areaAttributs); // XXX<double>
// XYAttributs xyAttributs (tree, areaAttributs); // XXX<double>
// MoIAttributs moiAttributs (tree, xyAttributs); // XXX<double>
AreaAttributes areaAttributes (tree, option.treeCoreCount);
areaAttributes.printValues ("area");
AverageAttributes averageAttributes (tree, raster, areaAttributes, option.treeCoreCount);
averageAttributes.printValues ("average");
SDAttributes sdAttributes (tree, areaAttributes, option.treeCoreCount);
sdAttributes.printValues ("sd");
XYAttributes xyAttributes (tree, areaAttributes, option.treeCoreCount);
//xyAttributes.printValues ("XY"); // pb print de complexe
// MoIAttributes moiAttributes (tree, xyAttributes); // XXX<double>
// XXX cut
// attribut.cut (out, attributProfiles, threshold)
// attribute.cut (out, attributProfiles, threshold)
// XXX write