43 #define NORMALATTRIBT_CC
47 #include "NormalAttrib.hh"
49 #include "../Core/GeometryKernel.hh"
53 template <
class GeomKernelT>
54 NormalAttrib<GeomKernelT>::NormalAttrib(GeomKernelT& _kernel) :
56 v_normals_(_kernel.template request_vertex_property<typename GeomKernelT::PointT>(
"vertex_normals")),
57 f_normals_(_kernel.template request_face_property<typename GeomKernelT::PointT>(
"face_normals"))
62 template <
class GeomKernelT>
63 NormalAttrib<GeomKernelT>::~NormalAttrib() {
67 template <
class GeomKernelT>
70 if(!kernel_.has_face_bottom_up_incidences()) {
71 std::cerr <<
"Error: update_vertex_normals() needs bottom-up incidences!" << std::endl;
76 update_face_normals();
78 for(
VertexIter v_it = kernel_.v_iter(); v_it.valid(); ++v_it) {
79 compute_vertex_normal(*v_it);
83 template <
class GeomKernelT>
86 if(!kernel_.has_face_bottom_up_incidences()) {
87 std::cerr <<
"Error: update_normals() needs bottom-up incidences!" << std::endl;
91 for(
FaceIter f_it = kernel_.f_iter(); f_it.valid(); ++f_it) {
94 compute_face_normal(*f_it);
98 template <
class GeomKernelT>
101 std::set<HalfFaceHandle> halffaces;
103 voh_it.valid(); ++voh_it) {
106 hehf_it.valid(); ++hehf_it) {
107 if(kernel_.is_boundary(*hehf_it)) {
108 halffaces.insert(*hehf_it);
112 typename GeomKernelT::PointT normal =
typename GeomKernelT::PointT(0.0);
113 for(std::set<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
114 hf_it != halffaces.end(); ++hf_it) {
115 normal += (*this)[*hf_it];
120 v_normals_[_vh.idx()] = normal;
123 template <
class GeomKernelT>
124 void NormalAttrib<GeomKernelT>::compute_face_normal(
const FaceHandle& _fh) {
126 if(kernel_.face(_fh).halfedges().size() < 3) {
127 std::cerr <<
"Warning: Degenerate face detected!" << std::endl;
131 const std::vector<HalfEdgeHandle>& halfedges = kernel_.face(_fh).halfedges();
132 std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
134 typename GeomKernelT::PointT p1 = kernel_.vertex(kernel_.halfedge(*he_it).from_vertex());
135 typename GeomKernelT::PointT p2 = kernel_.vertex(kernel_.halfedge(*he_it).to_vertex());
137 typename GeomKernelT::PointT p3 = kernel_.vertex(kernel_.halfedge(*he_it).to_vertex());
139 typename GeomKernelT::PointT n = (p2 - p1) % (p3 - p2);
142 f_normals_[_fh.idx()] = n;
void update_face_normals()
Compute face normals.
void update_vertex_normals()
A simple heuristic to estimate the vertex normals.