OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModNormalFlippingT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 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: 850 $ *
38 * $Date: 2013-07-23 18:01:46 +0200 (Di, 23. Jul 2013) $ *
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
59 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
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 }
91
92
93 ~ModNormalFlippingT()
94 { }
95
96
97 public:
98
113 float collapse_priority(const CollapseInfo& _ci)
114 {
115 // simulate collapse
116 Base::mesh().set_point(_ci.v0, _ci.p1);
117
118 // check for flipping normals
119 typename Mesh::ConstVertexFaceIter vf_it(Base::mesh(), _ci.v0);
120 typename Mesh::FaceHandle fh;
121 typename Mesh::Scalar c(1.0);
122
123 for (; vf_it; ++vf_it)
124 {
125 fh = vf_it.handle();
126 if (fh != _ci.fl && fh != _ci.fr)
127 {
128 typename Mesh::Normal n1 = Base::mesh().normal(fh);
129 typename Mesh::Normal n2 = Base::mesh().calc_face_normal(fh);
130
131 c = dot(n1, n2);
132
133 if (c < min_cos_)
134 break;
135 }
136 }
137
138 // undo simulation changes
139 Base::mesh().set_point(_ci.v0, _ci.p0);
140
141 return float( (c < min_cos_) ? Base::ILLEGAL_COLLAPSE : Base::LEGAL_COLLAPSE );
142 }
143
145 void set_error_tolerance_factor(double _factor) {
146 if (_factor >= 0.0 && _factor <= 1.0) {
147 // the smaller the factor, the smaller max_deviation_ gets
148 // thus creating a stricter constraint
149 // division by error_tolerance_factor_ is for normalization
150 double max_normal_deviation = (max_deviation_ * 180.0/M_PI) * _factor / this->error_tolerance_factor_;
151 set_max_normal_deviation(max_normal_deviation);
152 this->error_tolerance_factor_ = _factor;
153 }
154 }
155
156
157 public:
158
160 double max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
161
167 void set_max_normal_deviation(double _d) {
168 max_deviation_ = _d / 180.0 * M_PI;
169 min_cos_ = cos(max_deviation_);
170 }
171
172 private:
173
174 // hide this method
175 void set_binary(bool _b) {}
176
177 private:
178
179 // maximum normal deviation
180 double max_deviation_, min_cos_;
181 };
182
183
184 //=============================================================================
185 } // END_NS_DECIMATER
186 } // END_NS_OPENMESH
187 //=============================================================================
188 #endif // OPENACG_MODNORMALFLIPPING_HH defined
189 //=============================================================================
190