Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Re: Merge coplanar neighboring facets

Subject: CGAL users discussion list

List archive

[cgal-discuss] Re: Merge coplanar neighboring facets


Chronological Thread 
  • From: tang <>
  • To:
  • Subject: [cgal-discuss] Re: Merge coplanar neighboring facets
  • Date: Sun, 11 Aug 2013 15:44:31 -0700 (PDT)

Dear all,

I am trying to write a program to merge coplanar facets. However, it crashed
there when running 'coplanar' after op=53. Could anyone help me to take a
look at the code to tell me what problem in the code?
aa0.off <http://cgal-discuss.949826.n4.nabble.com/file/n4657929/aa0.off>

Thanks,
Zhanghong Tang

The code:

#include <vector>
#include <iostream>
#include <istream>
#include <fstream>

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
#include <CGAL/Polyhedron_3.h>

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;

typedef Kernel::Point_3 Point;
typedef Kernel::Plane_3 Plane;

typedef CGAL::Polyhedron_3<Kernel>
Polyhedron;
typedef CGAL::Nef_polyhedron_3<Kernel>
Nef_polyhedron;
typedef Polyhedron::Halfedge_handle
Halfedge_handle;
typedef Polyhedron::Halfedge_iterator
Halfedge_iterator;
typedef Nef_polyhedron::Vector_3
Vector_3;

bool coplanar(Halfedge_handle &h1, Halfedge_handle &h2,double eps)
{
Vector_3 n1 = CGAL::cross_product(
h1->next()->vertex()->point() - h1->vertex()->point(),
h1->next()->next()->vertex()->point()- h1->next()->vertex()->point());
n1=n1/Kernel::FT(CGAL::sqrt(CGAL::to_double(n1.squared_length())));
Vector_3 n2 = CGAL::cross_product(
h2->next()->vertex()->point() - h2->vertex()->point(),
h2->next()->next()->vertex()->point()- h2->next()->vertex()->point());
n2=n2/Kernel::FT(CGAL::sqrt(CGAL::to_double(n2.squared_length())));
double len1 = CGAL::to_double((n1 - n2).squared_length());
double len2 = CGAL::to_double((n1 + n2).squared_length());
if(len1>=eps && len2>=eps)
return false;
else
return true;
}


void MergeCoplanarFacet(Polyhedron &p,double normalmin)
{
/// this function is used to merge coplanar facets
/// Zhanghong Tang @ 08/10/2013
double eps=normalmin*normalmin;
int op=0, debugnum=0;
while (true)
{
bool merged = false;
for (Halfedge_iterator he = p.halfedges_begin();he != p.halfedges_end();
he++)
{
Polyhedron::Halfedge_handle ohe = he->opposite();
if (coplanar(he, ohe,eps))
{
p.join_facet(he);
op++;
if(op>=debugnum)
{
printf("op = %d\n",op);
}
merged = true;
break;
}
}
if (!merged)
break;
}
}

int main(int argc, char * argv[])
{
Polyhedron *p = new Polyhedron;
std::ifstream stream("aa0.off");
stream >> *p;
MergeCoplanarFacet(*p,1.0e-5);

return 0;
}




--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Merge-coplanar-neighboring-facets-tp4657924p4657929.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page