OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
NormalAttrib.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 203 $ *
38  * $Date: 2012-05-24 17:42:06 +0200 (Thu, 24 May 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef NORMALATTRIB_HH_
44 #define NORMALATTRIB_HH_
45 
46 #include <cassert>
47 
48 #include "../Core/OpenVolumeMeshHandle.hh"
49 #include "OpenVolumeMeshStatus.hh"
50 #include "../Core/PropertyDefines.hh"
51 
52 namespace OpenVolumeMesh {
53 
54 template <class GeomKernelT>
55 class NormalAttrib {
56 public:
57 
58  NormalAttrib(GeomKernelT& _kernel);
59  virtual ~NormalAttrib();
60 
67  void update_vertex_normals();
68 
76  void update_face_normals();
77 
78  const typename GeomKernelT::PointT& operator[](const VertexHandle& _h) const {
79  assert((unsigned int)_h.idx() < kernel_.n_vertices());
80  return v_normals_[_h.idx()];
81  }
82 
83  const typename GeomKernelT::PointT& operator[](const FaceHandle& _h) const {
84  assert((unsigned int)_h.idx() < kernel_.n_faces());
85  return f_normals_[_h.idx()];
86  }
87 
88  const typename GeomKernelT::PointT operator[](const HalfFaceHandle& _h) const {
89  assert((unsigned int)_h.idx() < kernel_.n_halffaces());
90  double mult = 1.0;
91  if(_h.idx() % 2 == 1) mult = -1.0;
92  return f_normals_[kernel_.face_handle(_h).idx()] * mult;
93  }
94 
95  typename GeomKernelT::PointT& operator[](const VertexHandle& _h) {
96  assert((unsigned int)_h.idx() < kernel_.n_vertices());
97  return v_normals_[_h.idx()];
98  }
99 
100  typename GeomKernelT::PointT& operator[](const FaceHandle& _h) {
101  assert((unsigned int)_h.idx() < kernel_.n_faces());
102  return f_normals_[_h.idx()];
103  }
104 
105  typename GeomKernelT::PointT operator[](const HalfFaceHandle& _h) {
106  assert((unsigned int)_h.idx() < kernel_.n_halffaces());
107  double mult = 1.0;
108  if(_h.idx() % 2 == 1) mult = -1.0;
109  return f_normals_[kernel_.face_handle(_h).idx()] * mult;
110  }
111 
112 private:
113 
114  void compute_vertex_normal(const VertexHandle& _vh);
115 
116  void compute_face_normal(const FaceHandle& _fh);
117 
118  GeomKernelT& kernel_;
119 
122 };
123 
124 } // Namespace OpenVolumeMesh
125 
126 #if defined(INCLUDE_TEMPLATES) && !defined(NORMALATTRIBT_CC)
127 #include "NormalAttribT.cc"
128 #endif
129 
130 #endif /* NORMALATTRIB_HH_ */