Skip to content
Snippets Groups Projects
Commit de37c871 authored by Bastien JARILLON's avatar Bastien JARILLON
Browse files

ajout de la segmentation par périmètre. WIP

parents a44f4587 0e76f190
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,6 @@ void add_colors(const Facet_int_map& faces_classes, const std::string filename,
nb_classes = std::max(nb_classes, p.second);
}
nb_classes;
// std::cout << "number of classes: " << nb_classes << std::endl;
// create a map which matches a class with a color
......
#include "measures.hpp"
#include "libraries.hpp"
/**********************************************************************
* Compute perimeters of each face
****************************************************************************/
void computePerimeters(Polyhedron & mesh)
{
std::cout << std::endl;
std::vector<float> perimeters;
for (Facet_iterator i = mesh.facets_begin(); i != mesh.facets_end(); ++i) {
Halfedge_facet_circulator j = i->facet_begin();
float perimeter = 0.0, distance = 0.0;
do {
auto p1 = j->vertex()->point();
j++;
auto p2 = j->vertex()->point();
distance = CGAL::squared_distance(p1, p2);
if (distance > 0) perimeter += sqrt(distance);
} while (j != i->facet_begin());
perimeters.push_back(perimeter);
}
// display the content of perimeters
std::cout << "liste des périmètres de chaque face:" << std::endl;
for (float p: perimeters)
{
std::cout << p << " ";
}
std::cout << std::endl;
}
/**********************************************************************
* Compute the perimeterof a face
****************************************************************************/
float getPerimeter(Polyhedron::Facet_handle & face){
Halfedge_facet_circulator j = face->facet_begin();
float perimeter = 0.0, distance = 0.0;
do {
auto p1 = j->vertex()->point();
j++;
auto p2 = j->vertex()->point();
distance = CGAL::squared_distance(p1, p2);
if (distance > 0) perimeter += sqrt(distance);
} while (j != face->facet_begin());
return perimeter;
}
/**********************************************************************
* Compute the angle between the normal of a face and the x-y-z axis,
* for each face
****************************************************************************/
void computeAngles(Polyhedron & mesh)
{
std::cout << std::endl;
const Vector3 X_axis(1.0, 0.0, 0.0);
const Vector3 Y_axis(0.0, 1.0, 0.0);
const Vector3 Z_axis(0.0, 0.0, 1.0);
std::vector<CGAL::Angle> angles_x;
std::vector<CGAL::Angle> angles_y;
std::vector<CGAL::Angle> angles_z;
for (Facet_iterator i = mesh.facets_begin(); i != mesh.facets_end(); ++i) {
Halfedge_facet_circulator j = i->facet_begin();
auto p1 = j->vertex()->point();
++j;
auto p2 = j->vertex()->point();
++j;
auto p3 = j->vertex()->point();
auto normal = CGAL::normal(p1, p2, p3);
auto angle = CGAL::angle(X_axis, normal);
angles_x.push_back(angle);
angle = CGAL::angle(Y_axis, normal);
angles_y.push_back(angle);
angle = CGAL::angle(Z_axis, normal);
angles_z.push_back(angle);
}
// display all the angles
std::cout << "angles with x axis values: " << std::endl;
for (auto angle: angles_x) std::cout << angle << " ";
std::cout << std::endl;
std::cout << "angles with y axis values: " << std::endl;
for (auto angle: angles_y) std::cout << angle << " ";
std::cout << std::endl;
std::cout << "angles with z axis values: " << std::endl;
for (auto angle: angles_z) std::cout << angle << " ";
std::cout << std::endl;
}
/**********************************************************************
* Compute the area of all faces
****************************************************************************/
void computeArea(Polyhedron & mesh)
{
std::cout << std::endl;
std::vector<double> areas;
for (Facet_iterator i = mesh.facets_begin(); i != mesh.facets_end(); ++i) {
Halfedge_facet_circulator j = i->facet_begin();
double areaface = 0.0, area = 0.0;
j++;
auto p1 = j->vertex()->point();
do {
++j;
auto p2 = j->vertex()->point();
area = CGAL::squared_area(i->facet_begin()->vertex()->point(), p1, p2);
if (area > 0) areaface += sqrt(area);
p1 = p2;
} while (j != i->facet_begin());
areas.push_back(areaface);
}
// affichage des aires de chaque face
std::cout << "liste des aires de chaque face:" << std::endl;
for (float p: areas)
{
std::cout << p << " ";
}
std::cout << std::endl;
}
#ifndef __MEASURES_HPP__
#define __MEASURES_HPP__
#include "libraries.hpp"
void computePerimeters(Polyhedron&);
float getPerimeter(Polyhedron::Facet_handle &);
void computeAngles(Polyhedron&);
void computeArea(Polyhedron&);
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment