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-2014 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: 990 $ *
38 * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05. Feb 2014) $ *
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.is_valid(); ++vf_it)
124 {
125 fh = *vf_it;
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
ModBaseT.hh
Base class for all decimation modules.
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
OpenMesh::Decimater::ModNormalFlippingT::set_max_normal_deviation
void set_max_normal_deviation(double _d)
Set normal deviation.
Definition: ModNormalFlippingT.hh:167
OpenMesh::Decimater::ModNormalFlippingT
Decimating module to avoid flipping of faces.
Definition: ModNormalFlippingT.hh:78
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition: ModBaseT.hh:190
OpenMesh::Decimater::ModNormalFlippingT::max_normal_deviation
double max_normal_deviation() const
get normal deviation
Definition: ModNormalFlippingT.hh:160
OpenMesh::Decimater::CollapseInfoT::p0
Mesh::Point p0
Position of removed vertex.
Definition: CollapseInfoT.hh:92
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
OpenMesh::Decimater::ModNormalFlippingT::ModNormalFlippingT
ModNormalFlippingT(MeshT &_mesh)
Constructor.
Definition: ModNormalFlippingT.hh:87
OpenMesh::dot
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
OpenMesh::Decimater::CollapseInfoT::v0
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:90
OpenMesh::Decimater::CollapseInfoT::p1
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:93
OpenMesh::Decimater::ModNormalFlippingT::set_error_tolerance_factor
void set_error_tolerance_factor(double _factor)
set the percentage of maximum normal deviation
Definition: ModNormalFlippingT.hh:145
OpenMesh::Decimater::CollapseInfoT::fl
Mesh::FaceHandle fl
Left face.
Definition: CollapseInfoT.hh:94
OpenMesh::Decimater::ModNormalFlippingT::collapse_priority
float collapse_priority(const CollapseInfo &_ci)
Compute collapse priority due to angular deviation of face normals before and after a collapse...
Definition: ModNormalFlippingT.hh:113
OpenMesh::Decimater::CollapseInfoT::fr
Mesh::FaceHandle fr
Right face.
Definition: CollapseInfoT.hh:95
DECIMATING_MODULE
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:147