OpenMesh
Loading...
Searching...
No Matches
ModAspectRatioT_impl.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, 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
46//=============================================================================
47//
48// CLASS ModAspectRatioT - IMPLEMENTATION
49//
50//=============================================================================
51#define OPENMESH_DECIMATER_MODASPECTRATIOT_C
52
53//== INCLUDES =================================================================
54
55#include "ModAspectRatioT.hh"
56
57//== NAMESPACES ===============================================================
58
59namespace OpenMesh {
60namespace Decimater {
61
62//== IMPLEMENTATION ==========================================================
63
64template<class MeshT>
65typename ModAspectRatioT<MeshT>::Scalar ModAspectRatioT<MeshT>::aspectRatio(
66 const Point& _v0, const Point& _v1, const Point& _v2) {
67
68 // Egde vectors
69 const Point d0 = _v0 - _v1;
70 const Point d1 = _v1 - _v2;
71 const Point d2 = _v2 - _v0;
72
73 // squared edge lengths
74 const Scalar l0 = sqrnorm(d0);
75 const Scalar l1 = sqrnorm(d1);
76 const Scalar l2 = sqrnorm(d2);
77
78 // find the maximal squared edge length
79 const Scalar maxl2 = std::max(l0, std::max(l1, l2));
80
81 // squared area of the parallelogram spanned by d0 and d2
82 // (twice the triangle's area, magnitude independent of which two edges are chosen)
83 Scalar a2 = sqrnorm(d0 % d2);
84
85 // the area of the triangle would be
86 // sqrt(a2)/2 or length * height / 2
87 // aspect ratio = length / height
88 // = length * length / (2*area)
89 // = length * length / sqrt(a2)
90
91 // returns the length of the longest edge
92 // divided by its corresponding height
93 // As maxl2 is positive, we can reduce that from sqrt((maxl2 * maxl2) / a2) to the following:
94 return maxl2 / sqrt(a2);
95}
96
97//-----------------------------------------------------------------------------
98
99template<class MeshT>
101
102 for (const auto& fh : mesh_.faces())
103 {
104 auto fv_it = mesh_.cfv_iter(fh);
105
106 const typename Mesh::Point& p0 = mesh_.point(*fv_it);
107 const typename Mesh::Point& p1 = mesh_.point(*(++fv_it));
108 const typename Mesh::Point& p2 = mesh_.point(*(++fv_it));
109
110 mesh_.property(aspect_, fh) = static_cast<typename Mesh::Scalar>(1.0) / aspectRatio(p0, p1, p2);
111 }
112
113}
114
115//-----------------------------------------------------------------------------
116
117template<class MeshT>
118void ModAspectRatioT<MeshT>::preprocess_collapse(const CollapseInfo& _ci) {
119 typename Mesh::FaceHandle fh;
120 typename Mesh::FVIter fv_it;
121
122 for (typename Mesh::VFIter vf_it = mesh_.vf_iter(_ci.v0); vf_it.is_valid(); ++vf_it) {
123 fh = *vf_it;
124 if (fh != _ci.fl && fh != _ci.fr) {
125 fv_it = mesh_.fv_iter(fh);
126 typename Mesh::Point& p0 = mesh_.point(*fv_it);
127 typename Mesh::Point& p1 = mesh_.point(*(++fv_it));
128 typename Mesh::Point& p2 = mesh_.point(*(++fv_it));
129
130 mesh_.property(aspect_, fh) = static_cast<typename Mesh::Scalar>(1.0) / aspectRatio(p0, p1, p2);
131 }
132 }
133}
134
135//-----------------------------------------------------------------------------
136
137template<class MeshT>
138float ModAspectRatioT<MeshT>::collapse_priority(const CollapseInfo& _ci) {
139 typename Mesh::VertexHandle v2, v3;
140 typename Mesh::FaceHandle fh;
141 const typename Mesh::Point* p1(&_ci.p1);
142 typename Mesh::Scalar r0, r1, r0_min(1.0), r1_min(1.0);
143 typename Mesh::ConstVertexOHalfedgeIter voh_it(mesh_, _ci.v0);
144
145 v3 = mesh_.to_vertex_handle(*voh_it);
146 auto p3 = &mesh_.point(v3);
147
148 while (voh_it.is_valid()) {
149 v2 = v3;
150 auto p2 = p3;
151
152 ++voh_it;
153 v3 = mesh_.to_vertex_handle(*voh_it);
154 p3 = &mesh_.point(v3);
155
156 fh = mesh_.face_handle(*voh_it);
157
158 // if not boundary
159 if (fh.is_valid()) {
160 // aspect before
161 if ((r0 = mesh_.property(aspect_, fh)) < r0_min)
162 r0_min = r0;
163
164 // aspect after
165 if (!(v2 == _ci.v1 || v3 == _ci.v1))
166 if ((r1 = static_cast<typename Mesh::Scalar>(1.0) / aspectRatio(*p1, *p2, *p3)) < r1_min)
167 r1_min = r1;
168 }
169 }
170
171 if (Base::is_binary()) {
172 return
173 ((r1_min > r0_min) || (r1_min > min_aspect_)) ? float(Base::LEGAL_COLLAPSE) :
174 float(Base::ILLEGAL_COLLAPSE);
175
176 } else {
177 if (r1_min > r0_min)
178 return 1.f - float(r1_min);
179 else
180 return
181 (r1_min > min_aspect_) ? 2.f - float(r1_min) : float(Base::ILLEGAL_COLLAPSE);
182 }
183}
184
185//-----------------------------------------------------------------------------
186
187template<class MeshT>
189 if (_factor >= 0.0 && _factor <= 1.0) {
190 // the smaller the factor, the larger min_aspect_ gets
191 // thus creating a stricter constraint
192 // division by (2.0 - error_tolerance_factor_) is for normalization
193 float min_aspect = min_aspect_ * (2.f - float(_factor)) / (2.f - float(this->error_tolerance_factor_));
194 set_aspect_ratio(1.f/min_aspect);
195 this->error_tolerance_factor_ = _factor;
196 }
197}
198
199//=============================================================================
200}
201}
202//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition PolyMeshT.hh:136
Kernel::Scalar Scalar
Scalar type.
Definition PolyMeshT.hh:110
Kernel::FaceHandle FaceHandle
Scalar type.
Definition PolyMeshT.hh:139
Kernel::ConstVertexOHalfedgeIter ConstVertexOHalfedgeIter
Circulator.
Definition PolyMeshT.hh:173
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:112
void preprocess_collapse(const CollapseInfo &_ci) override
update aspect ratio of one-ring
Definition ModAspectRatioT_impl.hh:118
float collapse_priority(const CollapseInfo &_ci) override
Returns the collapse priority.
Definition ModAspectRatioT_impl.hh:138
void set_error_tolerance_factor(double _factor) override
set percentage of aspect ratio
Definition ModAspectRatioT_impl.hh:188
void initialize() override
precompute face aspect ratio
Definition ModAspectRatioT_impl.hh:100

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .