nouveau fichier : MakefileNoOTB

nouveau fichier : include/Attributes/AverageAttributes.hpp
	nouveau fichier : include/Attributes/AverageAttributes.tpp
	nouveau fichier : include/Attributes/SDAttributes.hpp
	nouveau fichier : include/Attributes/SDAttributes.tpp
	nouveau fichier : include/Attributes/XYAttributes.hpp
	nouveau fichier : include/Attributes/XYAttributes.tpp
	nouveau fichier : include/CompAttribute.hpp
	nouveau fichier : include/CompAttribute.tpp
This commit is contained in:
Git Merciol 2018-02-19 16:58:11 +01:00
parent 869eda6449
commit e09d2793e2
9 changed files with 381 additions and 0 deletions

60
MakefileNoOTB Normal file
View File

@ -0,0 +1,60 @@
## DIR #################################
SRC_DIR = .
CPP_DIR = $(SRC_DIR)/src
HPP_DIR = $(SRC_DIR)/include
BLD_DIR = build
OUT_DIR = $(BLD_DIR)/out
LIB_DIR = $(BLD_DIR)/lib
OBJ_DIR = $(BLD_DIR)/obj
## PRG #################################
TST_PRG = testMain
TST_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(TST_PRG))
TST_OUT = $(patsubst %, $(OUT_DIR)/%, $(TST_PRG))
## FLAGS ###############################
#DFLAGS = -O2
DFLAGS = -g -DENABLE_LOG -DNO_OTB # -DSMART_LOG # -DTHREAD_DISABLE
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR)
LFLAGS = -L$(LIB_DIR) -ltriskele -lstdc++ -lpthread -lboost_system -lboost_chrono -lboost_thread -lboost_program_options -lboost_date_time -lboost_serialization -lboost_filesystem -lboost_unit_test_framework -lgdal
CC = g++
## RULES ###############################
$(OBJ_DIR)/%.o: $(CPP_DIR)/%.cpp
$(CC) $< $(IFLAGS) -cpp -c -o $@
$(OBJ_DIR)/%.o: $(CPP_DIR)/*/%.cpp
$(CC) $< $(IFLAGS) -cpp -c -o $@
$(OUT_DIR)/%: $(CPP_DIR)/%.cpp
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
$(OUT_DIR)/%: $(CPP_DIR)/*/%.cpp
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
## ENTRIES #############################
all: init libtriskele testMain
init:
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
clean:
find . -type f '(' -name '#*' -o -name '*~' ')' -print -exec rm -f '{}' \;
wipe: clean
rm -rf $(OBJ_DIR)
rm -f $(TST_OUT) $(LIB_DIR)/libtriskele.a
libtriskele: $(LIB_DIR)/libtriskele.a
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
testMain: $(TST_OUT)
$(TST_OUT) data/nairobi-byte.tif data/result.tif -b 0 -w 5 -h 5 # --debug
## DEPENDS #############################
ALL_OUT = $(TST_OUT)
ALL_OBJ = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/XMLTreeBuilder.o $(OBJ_DIR)/Option.o
DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d}
-include ${DEPENDS}
$(LIB_DIR)/libtriskele.a: $(ALL_OBJ)
ar rcs $@ $^
########################################

View File

@ -0,0 +1,24 @@
#ifndef _OTB_TRISKELE_AVERAGE_ATTRIBUTES_HPP
#define _OTB_TRISKELE_AVERAGE_ATTRIBUTES_HPP
#include "triskeleBase.hpp"
#include "CompAttribute.hpp"
namespace otb {
namespace triskele {
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 ();
protected:
template<typename PixelT>
inline void compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
};
#include "AverageAttributes.tpp"
} // triskele
} // otb
#endif // _OTB_TRISKELE_AVERAGE_ATTRIBUTES_HPP

View File

@ -0,0 +1,29 @@
#ifndef _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
#define _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
template<typename PixelT>
inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
compute (raster, areaAttributes);
}
inline
AverageAttributes::~AverageAttributes () {
}
template<typename PixelT>
inline void
AverageAttributes::compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes) {
const PixelT *pixels = raster.getPixels ();
const DimImg *areas = areaAttributes.getValues ();
computeSameCompLevel ([this, &pixels, &areas] (const DimImg &parentId) {
double tmpAverage = 0.;
tree.forEachChildTI (parentId, [this, &tmpAverage, &pixels, &areas] (const bool &isLeaf, const DimImg &childId) {
tmpAverage += isLeaf ? pixels[childId] : (CompAttribute<double>::values [childId] * areas[childId]);
});
CompAttribute<double>::values [parentId] = tmpAverage/areas[parentId];
});
}
#endif // _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP

View File

@ -0,0 +1,22 @@
#ifndef _OTB_TRISKELE_SD_ATTRIBUTES_HPP
#define _OTB_TRISKELE_SD_ATTRIBUTES_HPP
#include "triskeleBase.hpp"
#include "CompAttribute.hpp"
namespace otb {
namespace triskele {
class SDAttributes : public CompAttributeC<double> {
public:
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount);
inline ~SDAttributes ();
protected:
inline void compute (const AreaAttributes &areaAttributes);
};
#include "SDAttributes.tpp"
} // triskele
} // otb
#endif // _OTB_TRISKELE_SD_ATTRIBUTES_HPP

View File

@ -0,0 +1,32 @@
#ifndef _OTB_TRISKELE_SD_ATTRIBUTES_TPP
#define _OTB_TRISKELE_SD_ATTRIBUTES_TPP
inline
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
compute (areaAttributes);
}
inline
SDAttributes::~SDAttributes () {
}
inline void
SDAttributes::compute (const AreaAttributes &areaAttributes) {
const DimImg *areas = areaAttributes.getValues ();
computeSameCompLevel ([this, &areas] (const DimImg &parentId) {
double tmpSD = 0.;
tree.forEachChildTI (parentId, [this, &tmpSD, &areas, &parentId] (const bool &isLeaf, const DimImg &childId) {
if (isLeaf)
return;
double diff = areas [childId]-areas [parentId];
tmpSD += (diff * diff)*areas[childId];
});
CompAttribute<double>::values[parentId] = tmpSD / areas[parentId];
// XXX on peut virer pour gagner du temps et calculer SD*SD
CompAttribute<double>::values[parentId] = sqrt (CompAttribute<double>::values[parentId]);
});
}
#endif // _OTB_TRISKELE_SD_ATTRIBUTES_TPP

View File

@ -0,0 +1,26 @@
#ifndef _OTB_TRISKELE_XY_ATTRIBUTES_HPP
#define _OTB_TRISKELE_XY_ATTRIBUTES_HPP
#include "triskeleBase.hpp"
#include "CompAttribute.hpp"
namespace otb {
namespace triskele {
struct AverageXY {
double x, y;
inline AverageXY () : x(0), y(0) {}
};
class XYAttributes : public CompAttributeC<AverageXY> {
public:
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount);
inline ~XYAttributes ();
protected:
inline void compute (const AreaAttributes &areaAttributes);
};
#include "XYAttributes.tpp"
} // triskele
} // otb
#endif // _OTB_TRISKELE_XY_ATTRIBUTES_HPP

View File

@ -0,0 +1,34 @@
#ifndef _OTB_TRISKELE_XY_ATTRIBUTES_TPP
#define _OTB_TRISKELE_XY_ATTRIBUTES_TPP
inline
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<AverageXY> (tree, treeCoreCount) {
compute (areaAttributes);
}
inline
XYAttributes::~XYAttributes () {
}
inline void
XYAttributes::compute (const AreaAttributes &areaAttributes) {
DimImg const width = CompAttribute<AverageXY>::tree.getSize ().width;
const DimImg *areas = areaAttributes.getValues ();
computeSameCompLevel ([this, &width, &areas] (const DimImg &parentId) {
AverageXY tmpXY;
tree.forEachChildTI (parentId, [this, &tmpXY, &width, &areas, &parentId] (const bool &isLeaf, const DimImg &childId) {
if (isLeaf) {
tmpXY.x += childId % width;
tmpXY.y += childId / width;
return;
}
tmpXY.x += CompAttribute<AverageXY>::values[childId].x*areas[childId];
tmpXY.y += CompAttribute<AverageXY>::values[childId].y*areas[childId];
});
CompAttribute<AverageXY>::values[parentId].x = tmpXY.x/areas[parentId];
CompAttribute<AverageXY>::values[parentId].y = tmpXY.y/areas[parentId];
});
}
#endif // _OTB_TRISKELE_XY_ATTRIBUTES_TPP

55
include/CompAttribute.hpp Normal file
View File

@ -0,0 +1,55 @@
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_HPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_HPP
#include "triskeleBase.hpp"
#include "Tree.hpp"
namespace otb {
namespace triskele {
template<typename AttrT>
class CompAttribute {
public:
inline CompAttribute (const Tree &tree);
inline ~CompAttribute ();
inline void updateTranscient ();
inline const AttrT *getValues () const;
inline AttrT *getValues ();
inline void printValues (const string &msg) const;
protected:
const Tree &tree;
DimNodeId leafCount;
AttrT *values;
inline void free ();
inline void book (const DimImg &leafCount);
};
} // triskele
} // otb
#include "Attributes/WeightAttributes.hpp"
namespace otb {
namespace triskele {
template<typename AttrT>
class CompAttributeC : public CompAttribute<AttrT> {
public:
inline CompAttributeC (const Tree &tree, const unsigned int &treeCoreCount);
inline ~CompAttributeC ();
protected:
const unsigned int treeCoreCount;
template<typename CumpFunctPSE>
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/);
};
#include "CompAttribute.tpp"
} // triskele
} // otb
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_HPP

99
include/CompAttribute.tpp Normal file
View File

@ -0,0 +1,99 @@
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
template<typename AttrT>
inline
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
: tree (tree),
leafCount (0),
values (nullptr) {
updateTranscient ();
}
template<typename AttrT>
inline
CompAttribute<AttrT>::~CompAttribute () {
free ();
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::updateTranscient () {
book (tree.getLeafCount ());
}
template<typename AttrT>
inline const AttrT *
CompAttribute<AttrT>::getValues () const {
return values;
}
template<typename AttrT>
inline AttrT *
CompAttribute<AttrT>::getValues () {
return values;
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::printValues (const string &msg) const {
cout << "values: " << msg << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
printMap (cout, values, doubleSize, tree.getCompCount ()) << endl << endl;
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::free () {
if (values)
delete[] values;
values = nullptr;
}
template<typename AttrT>
inline void
CompAttribute<AttrT>::book (const DimImg &leafCount) {
if (this->leafCount == leafCount)
return;
free ();
if (!leafCount)
return;
this->leafCount = leafCount;
values = new AttrT[leafCount];
}
// ========================================
template<typename AttrT>
inline
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree, const unsigned int &treeCoreCount)
: CompAttribute<AttrT> (tree),
treeCoreCount (treeCoreCount) {
}
template<typename AttrT>
inline
CompAttributeC<AttrT>::~CompAttributeC () {
}
template<typename AttrT>
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) {
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) {
const DimImg parentId = id+first;
cumpFunctPSE (parentId);
});
first = next;
}
}
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP