41 class Point final :
private std::vector<TYPECOORD> {
43 using std::vector<TYPECOORD>::begin;
44 using std::vector<TYPECOORD>::end;
45 using std::vector<TYPECOORD>::push_back;
46 using std::vector<TYPECOORD>::size;
47 using std::vector<TYPECOORD>::clear;
48 using std::vector<TYPECOORD>::operator[];
64 Point(
const std::vector<TYPECOORD>&);
109 friend std::ostream& operator<<(std::ostream& os, const Point<N>& p) {
111 os <<
"Empty point (" << p.value() <<
")";
114 for(
unsigned int i = 0; i < N; i++) {
116 if(i != p.size()-1) os <<
", ";
119 if(p.value() != 0) os <<
" [" << p.value() <<
"]";
126 for(
int ii=0; ii<N; ii++) {
141 for(
int ii=0; ii<N; ii++) {
142 res.push_back(x[ii]+y[ii]);
150 for(
int ii=0; ii<N; ii++) {
151 res.push_back(x[ii]-y[ii]);
169 long double getDeterminant_rec(
const std::vector<std::vector<TYPECOORD>>&)
const;
183 std::cerr <<
"\033[31mERROR\033[0m : Copying Point : Point size (" << p.size() <<
") does not correspond to template parameter Point<" << N <<
">" << std::endl;
187 this->push_back(elm);
189 this->val = p.value();
209 std::cerr <<
"\033[31mERROR\033[0m : Making Point : Vector size (" << v.size() <<
") does not correspond to template parameter Point<" << N <<
">" << std::endl;
212 for(
unsigned int ii=0; ii < v.size(); ii++) {
213 this->push_back(v[ii]);
221 std::cout <<
"Construit Point vector dim " << N << std::endl;
223 std::cerr <<
"\033[31mERROR\033[0m : Making Point : Vector size (" << v.size() <<
") does not correspond to template parameter Point<" << N <<
">" << std::endl;
241 if(a.size() != b.size())
243 for(
unsigned int ii=0; ii<a.size(); ii++) {
244 res+=(a[ii]-b[ii])*(a[ii]-b[ii]);
253 if(a.size() != b.size())
255 for(
unsigned int ii=0; ii<a.size(); ii++) {
256 res.push_back((a[ii]+b[ii])/2);
264 std::vector<std::vector<TYPECOORD>> v_pts;
268 return pts[0].getDeterminant_rec(v_pts);
274 if(pts.size() == 2) {
275 return pts[0][0]*pts[1][1]-pts[1][0]*pts[0][1];
279 for(
unsigned int ii=0; ii<pts.size(); ii++) {
281 std::vector<std::vector<TYPECOORD>> matrix_minor(pts);
282 matrix_minor.erase(matrix_minor.begin());
283 for(
unsigned int jj=0; jj<pts.size()-1; jj++) {
284 matrix_minor[jj].erase(matrix_minor[jj].begin()+ii);
308 class Simplex final :
private std::vector<Point<N>> {
311 using std::vector<Point<N>>::begin;
312 using std::vector<Point<N>>::end;
313 using std::vector<Point<N>>::push_back;
314 using std::vector<Point<N>>::size;
315 using std::vector<Point<N>>::clear;
316 using std::vector<Point<N>>::operator[];
353 double getVolume()
const;
360 bool contain(
const Point<N>&)
const;
370 friend std::ostream& operator<<(std::ostream& os, const Simplex<N>& s) {
372 os <<
"Empty simplex";
374 os << s.getIndice() <<
" {" << std::endl;
376 os << pt << std::endl;
418 auto pointSimplexe = this->at(0);
419 std::vector<Point<N>> matrix;
420 for(
unsigned int ind=1; ind<=N; ind++) {
421 auto pointFace = this->at(ind);
422 matrix.push_back(pointFace-pointSimplexe);
428 for(
int ii=1; ii<=N; ii++)
433 return res>0 ? res : -res;
440 for(
auto pointSimplexe: *
this) {
441 std::vector<Point<N>> matrixFace, matrixSommet;
443 for(
auto pointFace: *
this) {
444 if(pointSimplexe == pointFace)
continue;
445 matrixFace.push_back(p-pointFace);
446 matrixSommet.push_back(pointSimplexe-pointFace);
451 if(detFace*detSommet < 0) {
465 std::cerr <<
"\033[31m\033[31mERROR\033[0m\033[0m: GET : simplex " << *
this <<
" does not contain point " << p << std::endl;
471 for(
auto pointSommet: *
this) {
472 for(
auto pointFace: *
this) {
473 if(pointSommet == pointFace)
continue;
474 simplexQ.push_back(pointFace);
476 simplexQ.push_back(p);
480 auto lambda = volumeQ/volumeD;
482 res += lambda * pointSommet.value();
519 Paving(
const int &,
const int &,
const int &);
554 return this->treated_points;
558 return this->simplices;
583 std::vector<Simplex<N>> sliceHypercube(
const std::vector<
Point<N>>&hypercube,
const Point<N>&mid);
615 std::vector<Point<N>> getPointsFromSimplex(
const std::vector<int>&)
const;
619 void showPoints()
const;
621 void showTreatedPoints()
const;
623 void showSimplices()
const;
633 std::vector<Point<N>> points;
634 std::vector<Point<N>> treated_points;
635 std::vector<std::vector<int>> simplices;
641 std::vector<Point<N>> user_points;
670 std::cout <<
"Generating " << n <<
" random points of dimension " << N << std::endl;
671 for(
int ii = 0; ii < N; ii++) {
672 p_min.push_back(9999999);
673 p_max.push_back(-9999999);
677 for(
int ii = 0; ii < n; ii++) {
679 for(
int jj=0; jj < N; jj++) {
680 TYPEVAL val = (rand()%(maxv-minv))+minv;
682 p_min[jj] = val < p_min[jj] ? val : p_min[jj];
683 p_max[jj] = val > p_max[jj] ? val : p_max[jj];
685 this->points.push_back(pt);
693 std::cout <<
"Current data dimension " << N << std::endl << std::endl;
694 std::cout <<
"Building Paving from file '" << f <<
"', " ;
695 std::ifstream inputFile(f);
697 for(
int ii = 0; ii < N; ii++) {
698 p_min.push_back(9999999);
699 p_max.push_back(-9999999);
702 if(inputFile.is_open()) {
703 inputFile >> nbPoints;
705 std::cout <<
"data dimension " << dim << std::endl;
707 std::cerr <<
"\033[31mERROR\033[0m : Reading file : Data dimension (" << dim <<
") does not correspond to template parameter Paving<" << N <<
">" << std::endl;
710 for(
int ii=1; ii<=nbPoints; ii++) {
714 for(
int jj=0; jj<N; jj++) {
716 point.push_back(coord);
717 p_min[jj] = val < p_min[jj] ? val : p_min[jj];
718 p_max[jj] = val > p_max[jj] ? val : p_max[jj];
722 this->points.push_back(point);
726 std::cerr <<
"\033[31mERROR\033[0m: failed open file" << std::endl;
738 std::cout << std::endl <<
"Paving initialisation" << std::endl << std::endl;
741 auto extrem_coord = std::max(abs(*std::max_element(p_max.begin(),p_max.end())), abs(*std::min_element(p_min.begin(),p_min.end())));
742 auto coeff = extrem_coord/100;
743 if(coeff < 1) coeff = 1;
746 std::cout <<
"Creating englobing simplex..." << std::endl << std::endl;
747 std::vector<Point<N>> tmp_points(points);
748 points = std::vector<Point<N>>();
751 for(
int ii = 0; ii < N+2; ii++) {
752 for(
int jj = 0; jj < N+1; jj++) {
754 p.push_back(-extrem_coord);
756 if(ii==jj) p.push_back(extrem_coord);
760 eng_simplex.push_back(p);
764 std::cout <<
"Start englobing simplex : " << std::endl;
765 std::cout << eng_simplex << std::endl << std::endl;
767 while(!tmp_points.empty()) {
769 for(
int ii = 0; ii < N+1; ii++) {
770 eng_simplex[ii][ii]+=coeff;
772 for(
int ii = 0; ii < N+1; ii++) {
773 eng_simplex[N+1][ii]-=coeff;
777 for(
unsigned int ii = 0; ii < tmp_points.size(); ii++) {
781 for(
auto c: pt) point.push_back(c);
783 if(eng_simplex.contain(point)) {
785 points.push_back(tmp_points[ii]);
786 tmp_points.erase(tmp_points.begin()+ii);
792 for(
unsigned int ii = 0; ii < eng_simplex.size(); ii++) {
793 if(ii == eng_simplex.size()-2)
continue;
796 for(
int jj = 0; jj < N; jj++) {
797 pt.push_back(point[jj]);
799 main_simplex.push_back(pt);
803 std::cout <<
"Pre-refine englobing simplex : " << std::endl;
804 std::cout << main_simplex << std::endl << std::endl;
807 std::cout <<
"Refining englobing simplex..." << std::endl << std::endl;
813 for(
int ii = 0; ii < N; ii++)
814 main_simplex[ii][ii]-=coeff;
821 for(
int ii = 0; ii < N; ii++)
822 main_simplex[ii][ii]+=coeff;
824 p_max.push_back(main_simplex[0][0]);
825 p_max.push_back(main_simplex[0][0]);
830 for(
int ii = 0; ii < N; ii++)
831 main_simplex[N][ii]+=coeff;
836 for(
int ii = 0; ii < N; ii++)
837 main_simplex[N][ii]-=coeff;
839 auto v = main_simplex[N][0] > 0 ? 0 : main_simplex[N][0];
843 std::cout <<
"Englobing simplex : " << std::endl;
844 std::cout << main_simplex << std::endl << std::endl;
849 std::vector<int> sim;
850 for(
unsigned int ii = 0; ii < main_simplex.size(); ii++) {
851 treated_points.push_back(main_simplex[ii]);
854 simplices.push_back(sim);
858 Point<N> pt(main_simplex[main_simplex.size()-1]);
860 while(!this->points.empty()) {
861 int id = getNearestPoint(pt, this->points);
862 pt = this->points[id];
863 this->points.erase(this->points.begin()+id);
864 if(!this->
add(pt)) res =
false;
867 user_points = std::vector<Point<N>>();
868 std::cout << std::endl << std::endl << std::endl;
995 std::cout <<
"Adding point " << p <<
": ";
999 if(simplex.size()!=0) {
1001 auto newInd = this->treated_points.size();
1002 this->treated_points.push_back(p);
1003 for(
auto indSimplex: this->simplices[simplex.
getIndice()]) {
1004 std::vector<int> sim;
1005 sim.push_back(newInd);
1006 for(
auto indFace: this->simplices[simplex.
getIndice()]) {
1007 if(indSimplex == indFace)
continue;
1008 sim.push_back(indFace);
1010 this->simplices.push_back(sim);
1012 this->simplices.erase(this->simplices.begin()+simplex.
getIndice());
1013 std::cout <<
"\033[32madded\033[0m" << std::endl;
1016 std::cout <<
"\033[31mnot in any simplex\033[0m" << std::endl;
1026 std::cout <<
"Getting " << p << std::endl << std::endl;
1029 std::cout <<
"Containing simplex: " << simplexD << std::endl;
1031 if(simplexD.size()!=0) {
1032 res = simplexD.
get(p);
1033 user_points.push_back(p);
1035 std::cout <<
"\033[31mPoint " << p <<
" not in any simplex\033[0m" << std::endl;
1044 double d = 9999999, tmpD;
1047 if(tmpD < d && p!=elm) {
1060 for(
auto vec: this->simplices) {
1075 std::vector<Point<N>> res;
1077 Point<N> pt = this->treated_points[ind];
1086 std::cout <<
"Points (" << this->points.size() <<
") :" << std::endl;
1087 for(
auto p : this->points) {
1088 std::cout <<
" " << p << std::endl;
1090 std::cout << std::endl;
1096 std::cout <<
"Treated points (" << this->treated_points.size() <<
") :" << std::endl;
1097 for(
auto p : this->treated_points) {
1098 std::cout <<
" " << p << std::endl;
1100 std::cout << std::endl;
1106 std::cout <<
"Simplices (" << this->simplices.size() <<
") :" << std::endl;
1108 for(
auto v: this->simplices) {
1110 std::cout << sim << std::endl;
1112 std::cout << std::endl;
1121 grapic::color(242,224,26);
1122 for(
auto pt: this->points) {
1123 grapic::point((pt[0]-p_min[0])*coeff, (pt[1]-p_min[1])*coeff);
1126 grapic::color(74, 239, 231);
1127 if(simplices.empty())
return;
1128 for(
auto vec: this->simplices) {
1129 Point<N> a(this->treated_points[vec[0]]), b(this->treated_points[vec[1]]), c(this->treated_points[vec[2]]);
1130 grapic::line((a[0]-p_min[0])*coeff, (a[1]-p_min[1])*coeff, (b[0]-p_min[0])*coeff, (b[1]-p_min[1])*coeff);
1131 grapic::line((a[0]-p_min[0])*coeff, (a[1]-p_min[1])*coeff, (c[0]-p_min[0])*coeff, (c[1]-p_min[1])*coeff);
1132 grapic::line((c[0]-p_min[0])*coeff, (c[1]-p_min[1])*coeff, (b[0]-p_min[0])*coeff, (b[1]-p_min[1])*coeff);
1135 grapic::color(239, 74, 1);
1136 if(user_points.empty())
return;
1137 Point<N> pt(user_points[user_points.size()-1]);
1139 for(
auto pt_sim: sim) {
1140 grapic::line((pt[0]-p_min[0])*coeff, (pt[1]-p_min[1])*coeff, (pt_sim[0]-p_min[0])*coeff, (pt_sim[1]-p_min[1])*coeff);
1148 grapic::backgroundColor(0,0,0);
1151 grapic::winDisplay();
1152 std::cout <<
"Press ENTER to continue" << std::endl;
friend bool operator==(const Point< N > &x, const Point< N > &y)
Test d'égalité entre deux points.
Definition: Paving.hpp:125
Classe Simplex.
Definition: Paving.hpp:308
bool contain(const Point< N > &) const
Vérifie si un point se trouve dans le simplexe.
Definition: Paving.hpp:438
const int WINDIM_X
Longueur des fenêtres d'affichage.
Definition: Paving_config.hpp:26
friend bool operator!=(const Point< N > &x, const Point< N > &y)
Test de la différence entre deux points.
Definition: Paving.hpp:134
TYPEVAL get(const Point< N > &p)
Méthode centrale: calcule en fonction d'un point donné
Definition: Paving.hpp:1024
friend Point< N > operator+(const Point< N > &x, const Point< N > &y)
Permet l'addition des points membres à membres.
Definition: Paving.hpp:139
const int WINDIM_Y
Hauteur des fenêtres d'affichage.
Definition: Paving_config.hpp:29
~Point()
Destructeur.
Definition: Paving.hpp:234
std::vector< Point< N > > getPointsFromSimplex(const std::vector< int > &) const
Renvoie les points d'un simplexe donné
Definition: Paving.hpp:1074
void draw() const
Dessine le Pavage pour la fenêtre graphique.
Definition: Paving.hpp:1117
double TYPECOORD
Type des coordonnées des échantillons.
Definition: Paving_config.hpp:20
std::vector< Point< N > > getTreatedPoints()
Retourne tous les points traités sous forme d'un vector.
Definition: Paving.hpp:553
double getVolume() const
Renvoie le volume du simplexe.
Definition: Paving.hpp:416
Classe Point.
Definition: Paving.hpp:41
void showTreatedPoints() const
Afiche les points traités sur la sortie standard.
Definition: Paving.hpp:1095
void showPoints() const
Afiche les points sur la sortie standard.
Definition: Paving.hpp:1085
bool init()
Initialise le Pavage.
Definition: Paving.hpp:737
~Paving()
Destructeur.
Definition: Paving.hpp:732
bool add(Point< N > &p)
Ajoute un point incrémentalement au pavage.
Definition: Paving.hpp:994
Simplex< N > getSimplex(const Point< N > &p) const
Renvoie le simplexe contenant le point.
Definition: Paving.hpp:1058
std::vector< std::vector< int > > getSimplices()
Retourne tous les simplexes.
Definition: Paving.hpp:557
Point< N > getMiddle(const Point< N > &, const Point< N > &) const
Calcule le milieu de deux points de même dimension.
Definition: Paving.hpp:251
Configuration des paramètres utilisateurs.
TYPEVAL value() const
Retourne la valeur du point.
Definition: Paving.hpp:73
int getIndice() const
Retourne l'indice du simplexe dans le tableau de simplexes de la classe Pavage.
Definition: Paving.hpp:345
~Simplex()
Destructeur.
Definition: Paving.hpp:411
static double getDistance(const Point< N > &, const Point< N > &)
Calcule la distance entre deux points de même dimension.
Definition: Paving.hpp:239
double TYPEVAL
Type des valeurs des échantillons.
Definition: Paving_config.hpp:23
static long double getDeterminant(const std::vector< Point< N >> &)
Calcule le déterminant entre deux points de même dimension.
Definition: Paving.hpp:263
Simplex()
Construit un simplex vide.
Definition: Paving.hpp:391
Classe Paving.
Definition: Paving.hpp:504
void showSimplices() const
Afiche les simplices sur la sortie standard.
Definition: Paving.hpp:1105
std::vector< Point< N > > getPoints()
Retourne tous les points sous forme d'un vector.
Definition: Paving.hpp:549
TYPEVAL get(const Point< N > &) const
Renvoie la valeur du point du simplexe.
Definition: Paving.hpp:462
Point()
Construit un point de valeur 0.
Definition: Paving.hpp:176
Paving()
Constructeur par défaut.
Definition: Paving.hpp:659
void show() const
Affichge le Pavage dans une fenêtre graphique.
Definition: Paving.hpp:1146
void setValue(const TYPEVAL &v)
Change la valeur du point.
Definition: Paving.hpp:78
friend Point< N > operator-(const Point< N > &x, const Point< N > &y)
Permet la soustraction des points membres à membres.
Definition: Paving.hpp:148