Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile.
Chronological Thread
- From: Andreas Fabri <>
- To:
- Subject: Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile.
- Date: Thu, 12 Nov 2015 17:51:15 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=None ; spf=None
- Ironport-phdr: 9a23:XzfctRbWsdlsqqOazykVSMj/LSx+4OfEezUN459isYplN5qZpcm+bnLW6fgltlLVR4KTs6sC0LqL9fyxEjxRqb+681k8M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLsh730p8yYM1QArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIYTGZn9Kq83RLgdADU9OH0u/+XqswPCRE2B/CgySGITxzNODxLI5QqycJ77qCqy4uN71DOXNNawQ7k+QzWK4KpsTRL0kjYJPjUl93vGzMd3ifQI81qauxVjztuMM8muP/1kc/aFcA==
- Organization: GeometryFactory
Hello,
The facet has to provide storage for a plane.
Note that I also converted to double before doing sqrt.
best,
andreas
On 12/11/2015 15:28, Gilles wrote:
I did not receive any clue by now.
I desesperate...
Gilles
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Polyhedron-with-item-class-Nef-Polyhedron-does-not-compile-tp4661327p4661328.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
--
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project
phone: +33.492.954.912 skype: andreas.fabri
//#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_traits_with_normals_3.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <iostream>
#include <algorithm>
// Two functors to compute the normals: We assume the
// Simple_cartesian<double> Kernel here and use its global functions.
struct Facet_normal {
template <class Facet>
void operator()( Facet& f) {
typename Facet::Halfedge_handle h = f.halfedge();
typename Facet::Normal_3 normal = CGAL::cross_product(
h->next()->vertex()->point() - h->vertex()->point(),
h->next()->next()->vertex()->point() -
h->next()->vertex()->point());
f.normal() = normal / std::sqrt( CGAL::to_double(normal * normal));
}
};
struct Vertex_normal {
template <class Vertex>
void operator()( Vertex& v) {
typename Vertex::Normal_3 normal = CGAL::NULL_VECTOR;
typedef typename Vertex::Halfedge_around_vertex_const_circulator
Circ;
Circ c = v.vertex_begin();
Circ d = c;
CGAL_For_all( c, d) {
if ( ! c->is_border())
normal = normal + c->facet()->normal();
}
v.normal() = normal / std::sqrt( CGAL::to_double(normal * normal));
}
};
template <class Refs, class T, class P, class Norm>
class My_vertex : public CGAL::HalfedgeDS_vertex_base<Refs, T, P> {
Norm norm;
public:
My_vertex() {} // repeat mandatory constructors
My_vertex( const P& pt) : CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
{}
typedef Norm Normal_3;
Normal_3& normal() { return norm; }
const Normal_3& normal() const { return norm; }
};
template <class Refs, class T, class Plane, class Norm>
class My_facet : public CGAL::HalfedgeDS_face_base<Refs, T, Plane> {
Norm norm;
public:
// no constructors to repeat, since only default constructor mandatory
typedef Norm Normal_3;
typedef Norm Plane_3;
Normal_3& normal() { return norm; }
const Normal_3& normal() const { return norm; }
};
struct My_items : public CGAL::Polyhedron_items_3 {
template <class Refs, class Traits>
struct Vertex_wrapper {
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3 Normal;
typedef My_vertex<Refs, CGAL::Tag_true, Point, Normal> Vertex;
};
template <class Refs, class Traits>
struct Face_wrapper {
typedef typename Traits::Vector_3 Normal;
typedef typename Traits::Plane_3 Plane;
typedef My_facet<Refs, CGAL::Tag_true, Plane, Normal> Face;
};
};
// Tie all types together and a small main function using it.
//typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Polyhedron_3<Kernel,My_items> Polyhedron;
typedef Polyhedron::Vertex_iterator Vertex_iterator;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
int main() {
Point_3 p( 1, 0, 0);
Point_3 q( 0, 1, 0);
Point_3 r( 0, 0, 1);
Point_3 s( 0, 0, 0);
Polyhedron P;
P.make_tetrahedron( p, q, r, s);
Nef_polyhedron N1(P);
std::for_each( P.facets_begin(), P.facets_end(), Facet_normal());
std::for_each( P.vertices_begin(), P.vertices_end(), Vertex_normal());
CGAL::set_pretty_mode( std::cout);
for ( Vertex_iterator i = P.vertices_begin(); i != P.vertices_end();
++i)
std::cout << i->normal() << std::endl;
return 0;
}
- [cgal-discuss] Using Polyhedron & Nef Polyhedron with item class does not compile., Gilles, 11/11/2015
- Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile., Gilles, 11/12/2015
- Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile., Andreas Fabri, 11/12/2015
- Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile., Gilles, 11/13/2015
- Re: [cgal-discuss] Polyhedron (with item class) & Nef Polyhedron does not compile., Gilles, 11/12/2015
Archive powered by MHonArc 2.6.18.