Developer Documentation
NormalAttribT_impl.hh
1#pragma once
2/*===========================================================================*\
3 * *
4 * OpenVolumeMesh *
5 * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
6 * www.openvolumemesh.org *
7 * *
8 *---------------------------------------------------------------------------*
9 * This file is part of OpenVolumeMesh. *
10 * *
11 * OpenVolumeMesh is free software: you can redistribute it and/or modify *
12 * it under the terms of the GNU Lesser General Public License as *
13 * published by the Free Software Foundation, either version 3 of *
14 * the License, or (at your option) any later version with the *
15 * following exceptions: *
16 * *
17 * If other files instantiate templates or use macros *
18 * or inline functions from this file, or you compile this file and *
19 * link it with other files to produce an executable, this file does *
20 * not by itself cause the resulting executable to be covered by the *
21 * GNU Lesser General Public License. This exception does not however *
22 * invalidate any other reasons why the executable file might be *
23 * covered by the GNU Lesser General Public License. *
24 * *
25 * OpenVolumeMesh is distributed in the hope that it will be useful, *
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
28 * GNU Lesser General Public License for more details. *
29 * *
30 * You should have received a copy of the GNU LesserGeneral Public *
31 * License along with OpenVolumeMesh. If not, *
32 * see <http://www.gnu.org/licenses/>. *
33 * *
34\*===========================================================================*/
35
36#include <set>
37
38#include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
39
40#include <OpenVolumeMesh/Core/GeometryKernel.hh>
41
42namespace OpenVolumeMesh {
43
44template <class GeomKernelT>
45NormalAttrib<GeomKernelT>::NormalAttrib(GeomKernelT& _kernel) :
46kernel_(&_kernel),
47v_normals_(_kernel.template request_vertex_property<typename GeomKernelT::PointT>("vertex_normals", typename GeomKernelT::PointT(0.0))),
48f_normals_(_kernel.template request_face_property<typename GeomKernelT::PointT>("face_normals", typename GeomKernelT::PointT(0.0)))
49{
50
51}
52
53template <class GeomKernelT>
54NormalAttrib<GeomKernelT>::~NormalAttrib() {
55
56}
57
58template <class GeomKernelT>
60
61 if(!kernel_->has_face_bottom_up_incidences()) {
62 std::cerr << "Error: update_vertex_normals() needs bottom-up incidences!" << std::endl;
63 return;
64 }
65
66 // Compute face normals
68
69 for(const auto &_vh: kernel_->vertices())
70 {
71 compute_vertex_normal(_vh);
72 }
73}
74
75template <class GeomKernelT>
77
78 if(!kernel_->has_face_bottom_up_incidences()) {
79 std::cerr << "Error: update_normals() needs bottom-up incidences!" << std::endl;
80 return;
81 }
82
83 for (const auto &_fh: kernel_->faces()) {
84 f_normals_[_fh] = kernel_->normal(_fh.halfface_handle(0));
85 }
86}
87
88template <class GeomKernelT>
90
91 std::set<HalfFaceHandle> halffaces;
92 for(VertexOHalfEdgeIter voh_it = kernel_->voh_iter(_vh);
93 voh_it.valid(); ++voh_it) {
94
95 for(HalfEdgeHalfFaceIter hehf_it = kernel_->hehf_iter(*voh_it);
96 hehf_it.valid(); ++hehf_it) {
97 if(kernel_->is_boundary(*hehf_it)) {
98 halffaces.insert(*hehf_it);
99 }
100 }
101 }
102 typename GeomKernelT::PointT normal = typename GeomKernelT::PointT(0.0);
103 for(std::set<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
104 hf_it != halffaces.end(); ++hf_it) {
105 normal += (*this)[*hf_it];
106 }
107
108 normal.normalize();
109 v_normals_[_vh] = normal;
110}
111
112} // Namespace OpenVolumeMesh
void update_face_normals()
Compute face normals.