Reputation: 892
I am new to CGAL and am trying to find the length of each each edge in a mesh. I don't see any or length member functions or any way of easily getting the points on either side of the edge.
Here is where I have gotten so far. How do I get either the points on either end of the edge or the size of the edge itself?
#include <iostream>
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
typedef double Real;
typedef CGAL::Cartesian<Real> Kernel0;
// Use a filtered kernel so that all predicates are exact.
typedef CGAL::Filtered_kernel<Kernel0> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Kernel::Point_3 Point;
void Edge_Analysis(Polyhedron mesh){
float mean = 0, min, max, length;
int count = 0; bool init = true;
for (Polyhedron::Edge_const_iterator edgeIter = mesh.edges_begin(); edgeIter != mesh.edges_end(); ++edgeIter){
Point a = edgeIter.prev()->vertex()->point();
Point b = edgeIter.vertex()->point();
length = CGAL::sqrt(CGAL::squared_distance(a, b));
++count;
if (init){
mean = min = max = length;
init = false;
}
else{
if (length < min) min = length;
if (length > max) max = length;
}
mean += length;
}
mean /= count;
std::cout << min << " " << max << " " << mean << "\n";
}
int main(int argc, char **argv){
Polyhedron mesh;
// Read the input mesh from standard input in OFF format.
if (!(std::cin >> mesh)) {
std::cerr << "Cannot read input mesh\n";
return 1;
}
Edge_Analysis(mesh);
return 0;
}
Upvotes: 1
Views: 733
Reputation: 6263
The only mistake that should be fixed in order to compile is:
const Point& a = edgeIter->prev()->vertex()->point();
const Point& b = edgeIter->vertex()->point();
You should use CGAL::Exact_predicates_inexact_constructions_kernel
instead of Kernel
. You should take a const ref on mesh
if you want to avoid an unneeded copy.
Upvotes: 2