Update LCC operations to work with CMap and GMap

This commit is contained in:
Guillaume Damiand 2016-10-20 14:56:27 -04:00
parent 8d22d7e7dc
commit a0fb8e0a26
3 changed files with 52 additions and 20 deletions

View File

@ -324,7 +324,6 @@ void Viewer::compute_face(Dart_handle dh, LCC::size_type markface)
he_circ_end = lcc.darts_of_orbit<1>(dh).end(); he_circ_end = lcc.darts_of_orbit<1>(dh).end();
he_circ!=he_circ_end; ++he_circ) he_circ!=he_circ_end; ++he_circ)
{ {
std::cout<<lcc.point(he_circ)<<std::endl;
CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ)); CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ));
if(first == NULL) if(first == NULL)
{ first = vh; } { first = vh; }

View File

@ -192,7 +192,8 @@ typedef CGAL::Triangulation_face_base_with_info_2<Face_info,P_traits> Fb1;
typedef CGAL::Constrained_triangulation_face_base_2<P_traits, Fb1> Fb; typedef CGAL::Constrained_triangulation_face_base_2<P_traits, Fb1> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS; typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
typedef CGAL::No_intersection_tag Itag; // typedef CGAL::No_intersection_tag Itag;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<P_traits, TDS, typedef CGAL::Constrained_Delaunay_triangulation_2<P_traits, TDS,
Itag> CDT; Itag> CDT;

View File

@ -36,9 +36,18 @@ namespace CGAL {
template <class Point, class Vector> template <class Point, class Vector>
void newell_single_step_3_for_lcc(const Point& p, const Point& q, Vector& n) void newell_single_step_3_for_lcc(const Point& p, const Point& q, Vector& n)
{ {
// Compute normal of the face by using Newell's method: for each edge PQ
// Nx += (Py - Qy) * (Pz + Qz);
// Ny += (Pz - Qz) * (Px + Qx);
// Nz += (Px - Qx) * (Py + Qy);
n = Vector(n.x()+((p.y()-q.y())*(p.z()+q.z())), n = Vector(n.x()+((p.y()-q.y())*(p.z()+q.z())),
n.y()+((p.z()-q.z())*(p.x()+q.x())), n.y()+((p.z()-q.z())*(p.x()+q.x())),
n.z()+((p.x()-q.x())*(p.y()+q.y()))); n.z()+((p.x()-q.x())*(p.y()+q.y())));
// Dot product formula
/*n=Vector(n.x()+((p.y()*q.z())-(p.z()*q.y())),
n.y()+((p.x()*q.z())-(p.z()*q.x())),
n.z()+((p.x()*q.y())-(p.y()*q.x())));*/
} }
} // End namespace internal } // End namespace internal
@ -51,11 +60,6 @@ namespace CGAL {
typename LCC::Vector compute_normal_of_cell_2 typename LCC::Vector compute_normal_of_cell_2
(const LCC& amap, typename LCC::Dart_const_handle adart) (const LCC& amap, typename LCC::Dart_const_handle adart)
{ {
// Compute normal of the face by using Newell's method: for each edge PQ
// Nx += (Py - Qy) * (Pz + Qz);
// Ny += (Pz - Qz) * (Px + Qx);
// Nz += (Px - Qx) * (Py + Qy);
typedef typename LCC::Point Point; typedef typename LCC::Point Point;
typedef typename LCC::Vector Vector; typedef typename LCC::Vector Vector;
@ -68,17 +72,28 @@ namespace CGAL {
// Now we advance to process each edge // Now we advance to process each edge
unsigned int nb = 0; unsigned int nb = 0;
const Point* curr = &amap.point(adart); const Point* curr = &amap.point(start);
for ( adart=start; adart!=start && amap.is_next_exist(adart); adart=start;
adart=next(adart) ) do
{
if (amap.other_extremity(adart)==LCC::null_handle)
adart=start; // To leave the loop, because we know that adart has no next dart
else
{ {
const Point* next = &amap.point(amap.other_extremity(adart)); const Point* next = &amap.point(amap.other_extremity(adart));
internal::newell_single_step_3_for_lcc(*curr, *next, normal); internal::newell_single_step_3_for_lcc(*curr, *next, normal);
++nb; ++nb;
curr = next; curr = next;
if (amap.is_next_exist(adart) && amap.next(adart)!=start)
adart=amap.next(adart);
else
adart=start;
} }
}
while(adart!=start);
assert(nb>0);
return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb)); return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb));
// return normal / std::sqrt(normal * normal); // return normal / std::sqrt(normal * normal);
} }
@ -166,21 +181,38 @@ namespace CGAL {
CGAL_static_assertion(2<=LCC::dimension); CGAL_static_assertion(2<=LCC::dimension);
CGAL_assertion(adart != LCC::null_handle); CGAL_assertion(adart != LCC::null_handle);
// We go to the beginning of the face (first dart, case of open face)
typename LCC::Dart_const_handle start=adart;
while ( amap.is_previous_exist(start) && amap.previous(start)!=adart )
start = amap.previous(start);
typename LCC::Vector vec typename LCC::Vector vec
(typename LCC::Traits::Construct_vector()(CGAL::ORIGIN, (typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
amap.point(adart))); amap.point(start)));
if ((!amap.is_previous_exist(adart) && !amap.is_next_exist(adart)) ||
amap.next(adart)==adart)
return typename LCC::Traits::Construct_translated_point()
(CGAL::ORIGIN, vec); // case of face with only one edge
unsigned int nb = 1; unsigned int nb = 1;
typename LCC::template Dart_of_cell_range<2,2>::const_iterator // Now we advance to process each edge
vhit = amap.template darts_of_cell<2,2>(adart).begin(), adart=amap.next(start); // Because the first vertex was already sum up
vhend = amap.template darts_of_cell<2,2>(adart).end(); do
for( ++vhit; vhit!=vhend; ++vhit )
{ {
vec = typename LCC::Traits::Construct_sum_of_vectors() vec = typename LCC::Traits::Construct_sum_of_vectors()
(vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN, (vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
amap.point(vhit) )); amap.point(adart)));
++nb; ++nb;
if (amap.is_next_exist(adart) && amap.next(adart)!=start)
adart=amap.next(adart);
else
adart=start;
} }
while(adart!=start);
assert(nb>1);
return typename LCC::Traits::Construct_translated_point() return typename LCC::Traits::Construct_translated_point()
(CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector() (CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector()
(vec, 1.0/nb)); (vec, 1.0/nb));