| OpenMesh

ModQuadricT_impl.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
48 //=============================================================================
49 //
50 // CLASS ModQuadric - IMPLEMENTATION
51 //
52 //=============================================================================
53
54 #define OPENMESH_DECIMATER_MODQUADRIC_CC
55
56 //== INCLUDES =================================================================
57
58 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
59
60
61 //== NAMESPACE ===============================================================
62
63 namespace OpenMesh { // BEGIN_NS_OPENMESH
64 namespace Decimater { // BEGIN_NS_DECIMATER
65
66
67 //== IMPLEMENTATION ==========================================================
68
69
70 template<class DecimaterType>
71 void
72 ModQuadricT<DecimaterType>::
73 initialize()
74 {
75 using Geometry::Quadricd;
76 // alloc quadrics
77 if (!quadrics_.is_valid())
78 Base::mesh().add_property( quadrics_ );
79
80 // clear quadrics
81 typename Mesh::VertexIter v_it = Base::mesh().vertices_begin(),
82 v_end = Base::mesh().vertices_end();
83
84 for (; v_it != v_end; ++v_it)
85 Base::mesh().property(quadrics_, *v_it).clear();
86
87 // calc (normal weighted) quadric
88 typename Mesh::FaceIter f_it = Base::mesh().faces_begin(),
89 f_end = Base::mesh().faces_end();
90
91 typename Mesh::FaceVertexIter fv_it;
92 typename Mesh::VertexHandle vh0, vh1, vh2;
93 typedef Vec3d Vec3;
94
95 for (; f_it != f_end; ++f_it)
96 {
97 fv_it = Base::mesh().fv_iter(*f_it);
98 vh0 = *fv_it; ++fv_it;
99 vh1 = *fv_it; ++fv_it;
100 vh2 = *fv_it;
101
102 Vec3 v0, v1, v2;
103 {
104 using namespace OpenMesh;
105
106 v0 = vector_cast<Vec3>(Base::mesh().point(vh0));
107 v1 = vector_cast<Vec3>(Base::mesh().point(vh1));
108 v2 = vector_cast<Vec3>(Base::mesh().point(vh2));
109 }
110
111 Vec3 n = (v1-v0) % (v2-v0);
112 double area = n.norm();
113 if (area > FLT_MIN)
114 {
115 n /= area;
116 area *= 0.5;
117 }
118
119 const double a = n[0];
120 const double b = n[1];
121 const double c = n[2];
122 const double d = -(vector_cast<Vec3>(Base::mesh().point(vh0))|n);
123
124 Quadricd q(a, b, c, d);
125 q *= area;
126
127 Base::mesh().property(quadrics_, vh0) += q;
128 Base::mesh().property(quadrics_, vh1) += q;
129 Base::mesh().property(quadrics_, vh2) += q;
130 }
131 }
132
133 //-----------------------------------------------------------------------------
134
135 template<class MeshT>
136 void ModQuadricT<MeshT>::set_error_tolerance_factor(double _factor) {
137 if (this->is_binary()) {
138 if (_factor >= 0.0 && _factor <= 1.0) {
139 // the smaller the factor, the smaller max_err_ gets
140 // thus creating a stricter constraint
141 // division by error_tolerance_factor_ is for normalization
142 double max_err = max_err_ * _factor / this->error_tolerance_factor_;
143 set_max_err(max_err);
144 this->error_tolerance_factor_ = _factor;
145
146 initialize();
147 }
148 }
149 }
150
151 //=============================================================================
152 } // END_NS_DECIMATER
153 } // END_NS_OPENMESH
154 //=============================================================================
OpenMesh::VectorT
Definition: Vector11T.hh:83
ModQuadricT.hh
OpenMesh::Decimater::ModQuadricT::initialize
virtual void initialize(void)
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT_impl.hh:73
OpenMesh::Geometry::QuadricT::clear
void clear()
set all entries to zero
Definition: QuadricT.hh:166
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::Decimater::ModQuadricT::set_error_tolerance_factor
void set_error_tolerance_factor(double _factor)
set the percentage of maximum quadric error
Definition: ModQuadricT_impl.hh:136
OpenMesh::PolyMeshT::FaceVertexIter
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Definition: PolyMeshT.hh:167
OpenMesh::Geometry::QuadricT
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:82
OpenMesh::vector_cast
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
Definition: vector_cast.hh:81