35 #define NORMALATTRIBT_CC 39 #include "NormalAttrib.hh" 41 #include "../Core/GeometryKernel.hh" 45 template <
class GeomKernelT>
46 NormalAttrib<GeomKernelT>::NormalAttrib(GeomKernelT& _kernel) :
48 v_normals_(_kernel.template request_vertex_property<typename GeomKernelT::PointT>(
"vertex_normals", typename GeomKernelT::PointT(0.0))),
49 f_normals_(_kernel.template request_face_property<typename GeomKernelT::PointT>(
"face_normals", typename GeomKernelT::PointT(0.0)))
54 template <
class GeomKernelT>
55 NormalAttrib<GeomKernelT>::~NormalAttrib() {
59 template <
class GeomKernelT>
62 if(!kernel_.has_face_bottom_up_incidences()) {
63 std::cerr <<
"Error: update_vertex_normals() needs bottom-up incidences!" << std::endl;
70 for(
VertexIter v_it = kernel_.v_iter(); v_it.valid(); ++v_it) {
71 compute_vertex_normal(*v_it);
75 template <
class GeomKernelT>
78 if(!kernel_.has_face_bottom_up_incidences()) {
79 std::cerr <<
"Error: update_normals() needs bottom-up incidences!" << std::endl;
83 for(
FaceIter f_it = kernel_.f_iter(); f_it.valid(); ++f_it) {
86 compute_face_normal(*f_it);
90 template <
class GeomKernelT>
93 std::set<HalfFaceHandle> halffaces;
95 voh_it.valid(); ++voh_it) {
98 hehf_it.valid(); ++hehf_it) {
99 if(kernel_.is_boundary(*hehf_it)) {
100 halffaces.insert(*hehf_it);
104 typename GeomKernelT::PointT normal =
typename GeomKernelT::PointT(0.0);
105 for(std::set<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
106 hf_it != halffaces.end(); ++hf_it) {
107 normal += (*this)[*hf_it];
112 v_normals_[_vh] = normal;
115 template <
class GeomKernelT>
118 if(kernel_.face(_fh).halfedges().size() < 3) {
119 std::cerr <<
"Warning: Degenerate face detected!" << std::endl;
123 const std::vector<HalfEdgeHandle>& halfedges = kernel_.face(_fh).halfedges();
124 std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
126 typename GeomKernelT::PointT p1 = kernel_.vertex(kernel_.halfedge(*he_it).from_vertex());
127 typename GeomKernelT::PointT p2 = kernel_.vertex(kernel_.halfedge(*he_it).to_vertex());
129 typename GeomKernelT::PointT p3 = kernel_.vertex(kernel_.halfedge(*he_it).to_vertex());
131 typename GeomKernelT::PointT n = (p2 - p1) % (p3 - p2);
void update_vertex_normals()
A simple heuristic to estimate the vertex normals.
void update_face_normals()
Compute face normals.