Developer Documentation
NormalAttrib.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
37#include <cassert>
38
39#include <OpenVolumeMesh/Core/Handles.hh>
40#include <OpenVolumeMesh/Attribs/OpenVolumeMeshStatus.hh>
41#include <OpenVolumeMesh/Core/Properties/PropertyPtr.hh>
42
43namespace OpenVolumeMesh {
44
45template <class GeomKernelT>
47public:
48
49 explicit NormalAttrib(GeomKernelT& _kernel);
50 virtual ~NormalAttrib();
51
59
68
69 const typename GeomKernelT::PointT& operator[](const VertexHandle& _h) const {
70 assert((unsigned int)_h.idx() < kernel_->n_vertices());
71 return v_normals_[_h];
72 }
73
74 const typename GeomKernelT::PointT& operator[](const FaceHandle& _h) const {
75 assert((unsigned int)_h.idx() < kernel_->n_faces());
76 return f_normals_[_h];
77 }
78
79 const typename GeomKernelT::PointT operator[](const HalfFaceHandle& _h) const {
80 assert((unsigned int)_h.idx() < kernel_->n_halffaces());
81 double mult = 1.0;
82 if(_h.idx() % 2 == 1) mult = -1.0;
83 return f_normals_[kernel_->face_handle(_h)] * mult;
84 }
85
86 typename GeomKernelT::PointT& operator[](const VertexHandle& _h) {
87 assert((unsigned int)_h.idx() < kernel_->n_vertices());
88 return v_normals_[_h];
89 }
90
91 typename GeomKernelT::PointT& operator[](const FaceHandle& _h) {
92 assert((unsigned int)_h.idx() < kernel_->n_faces());
93 return f_normals_[_h];
94 }
95
96 typename GeomKernelT::PointT operator[](const HalfFaceHandle& _h) {
97 assert((unsigned int)_h.idx() < kernel_->n_halffaces());
98 double mult = 1.0;
99 if(_h.idx() % 2 == 1) mult = -1.0;
100 return f_normals_[kernel_->face_handle(_h)] * mult;
101 }
102
103private:
104
105 void compute_vertex_normal(const VertexHandle& _vh);
106
107 const GeomKernelT* kernel_;
108
111
112};
113
114} // Namespace OpenVolumeMesh
115
116
117#include <OpenVolumeMesh/Attribs/NormalAttribT_impl.hh>
118
void update_face_normals()
Compute face normals.
void update_vertex_normals()
A simple heuristic to estimate the vertex normals.