OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ModNormalFlippingT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2011 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: 460 $ *
38  * $Date: 2011-11-16 10:45:08 +0100 (Mi, 16 Nov 2011) $ *
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 DecimaterT>
78 class ModNormalFlippingT : public ModBaseT< DecimaterT >
79 {
80 public:
81 
83 
84 public:
85 
87  ModNormalFlippingT( DecimaterT &_dec) : Base(_dec, true)
88  {
89  set_max_normal_deviation( 90.0f );
90  }
91 
92 
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 
144 
145 
146 public:
147 
149  float max_normal_deviation() const { return max_deviation_ / M_PI * 180.0; }
150 
156  void set_max_normal_deviation(float _f) {
157  max_deviation_ = _f / 180.0 * M_PI;
158  min_cos_ = cos(max_deviation_);
159  }
160 
161 private:
162 
163  // hide this method
164  void set_binary(bool _b) {}
165 
166 private:
167 
168  // maximum normal deviation
169  double max_deviation_, min_cos_;
170 };
171 
172 
173 //=============================================================================
174 } // END_NS_DECIMATER
175 } // END_NS_OPENMESH
176 //=============================================================================
177 #endif // OPENACG_MODNORMALFLIPPING_HH defined
178 //=============================================================================
179 

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