OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ModNormalFlippingT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2015 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh 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  * OpenMesh 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 OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 1188 $ *
38  * $Date: 2015-01-05 16:34:10 +0100 (Mo, 05 Jan 2015) $ *
39  * *
40 \*===========================================================================*/
41 
46 //=============================================================================
47 //
48 // CLASS ModNormalFlipping
49 //
50 //=============================================================================
51 
52 
53 #ifndef OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
54 #define OPENMESH_DECIMATER_MODNORMALFLIPPING_HH
55 
56 
57 //== INCLUDES =================================================================
58 
60 
61 //== NAMESPACES ===============================================================
62 
63 namespace OpenMesh { // BEGIN_NS_OPENMESH
64 namespace Decimater { // BEGIN_NS_DECIMATER
65 
66 
67 //== CLASS DEFINITION =========================================================
68 
77 template <typename MeshT>
78 class ModNormalFlippingT : public ModBaseT< MeshT >
79 {
80 public:
81 
82  DECIMATING_MODULE( ModNormalFlippingT, MeshT, NormalFlipping );
83 
84 public:
85 
87  ModNormalFlippingT( MeshT &_mesh) : Base(_mesh, true)
88  {
89  set_max_normal_deviation( 90.0f );
90  const bool mesh_has_normals = _mesh.has_face_normals();
91  _mesh.request_face_normals();
92 
93  if (!mesh_has_normals)
94  {
95  std::cerr << "Mesh has no face normals. Compute them automatically." << std::endl;
96  _mesh.update_face_normals();
97  }
98  }
99 
100 
102  {
103  Base::mesh().release_face_normals();
104  }
105 
106 
107 public:
108 
123  float collapse_priority(const CollapseInfo& _ci)
124  {
125  // simulate collapse
126  Base::mesh().set_point(_ci.v0, _ci.p1);
127 
128  // check for flipping normals
129  typename Mesh::ConstVertexFaceIter vf_it(Base::mesh(), _ci.v0);
130  typename Mesh::FaceHandle fh;
131  typename Mesh::Scalar c(1.0);
132 
133  for (; vf_it.is_valid(); ++vf_it)
134  {
135  fh = *vf_it;
136  if (fh != _ci.fl && fh != _ci.fr)
137  {
138  typename Mesh::Normal n1 = Base::mesh().normal(fh);
139  typename Mesh::Normal n2 = Base::mesh().calc_face_normal(fh);
140 
141  c = dot(n1, n2);
142 
143  if (c < min_cos_)
144  break;
145  }
146  }
147 
148  // undo simulation changes
149  Base::mesh().set_point(_ci.v0, _ci.p0);
150 
151  return float( (c < min_cos_) ? Base::ILLEGAL_COLLAPSE : Base::LEGAL_COLLAPSE );
152  }
153 
155  void set_error_tolerance_factor(double _factor) {
156  if (_factor >= 0.0 && _factor <= 1.0) {
157  // the smaller the factor, the smaller max_deviation_ gets
158  // thus creating a stricter constraint
159  // division by error_tolerance_factor_ is for normalization
160  double max_normal_deviation = (max_deviation_ * 180.0/M_PI) * _factor / this->error_tolerance_factor_;
161  set_max_normal_deviation(max_normal_deviation);
162  this->error_tolerance_factor_ = _factor;
163  }
164  }
165 
166 
167 public:
168 
170  double max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
171 
177  void set_max_normal_deviation(double _d) {
178  max_deviation_ = _d / 180.0 * M_PI;
179  min_cos_ = cos(max_deviation_);
180  }
181 
182 private:
183 
184  // hide this method
185  void set_binary(bool _b) {}
186 
187 private:
188 
189  // maximum normal deviation
190  double max_deviation_, min_cos_;
191 };
192 
193 
194 //=============================================================================
195 } // END_NS_DECIMATER
196 } // END_NS_OPENMESH
197 //=============================================================================
198 #endif // OPENACG_MODNORMALFLIPPING_HH defined
199 //=============================================================================
200 
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
Decimating module to avoid flipping of faces.
Definition: ModNormalFlippingT.hh:78
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:93
Mesh::FaceHandle fl
Left face.
Definition: CollapseInfoT.hh:94
double max_normal_deviation() const
get normal deviation
Definition: ModNormalFlippingT.hh:170
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:147
void set_error_tolerance_factor(double _factor)
set the percentage of maximum normal deviation
Definition: ModNormalFlippingT.hh:155
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:174
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:90
void set_max_normal_deviation(double _d)
Set normal deviation.
Definition: ModNormalFlippingT.hh:177
Base class for all decimation modules.
float collapse_priority(const CollapseInfo &_ci)
Compute collapse priority due to angular deviation of face normals before and after a collapse...
Definition: ModNormalFlippingT.hh:123
Base class for all decimation modules.
Definition: ModBaseT.hh:190
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
Mesh::Point p0
Position of removed vertex.
Definition: CollapseInfoT.hh:92
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
Mesh::FaceHandle fr
Right face.
Definition: CollapseInfoT.hh:95
ModNormalFlippingT(MeshT &_mesh)
Constructor.
Definition: ModNormalFlippingT.hh:87

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .