53 #define OPENMESH_DECIMATER_MODHAUSDORFFT_C 68 template <
class MeshT>
69 typename ModHausdorffT<MeshT>::Scalar
76 const Point v0v1 = _v1 - _v0;
77 const Point v0v2 = _v2 - _v0;
78 const Point n = v0v1 % v0v2;
79 const Scalar d = n.sqrnorm();
83 if (d < FLT_MIN && d > -FLT_MIN) {
86 const Scalar invD =
static_cast<Scalar
>(1.0) / d;
90 const Point v1v2 = _v2 - _v1;
91 const Scalar inv_v0v2_2 =
static_cast<Scalar
>(1.0) / v0v2.sqrnorm();
92 const Scalar inv_v0v1_2 =
static_cast<Scalar
>(1.0) / v0v1.sqrnorm();
93 const Scalar inv_v1v2_2 =
static_cast<Scalar
>(1.0) / v1v2.sqrnorm();
98 typename Point::value_type s01, s02, s12;
99 const Scalar a = (t | v0v2) * -invD;
100 const Scalar b = (t | v0v1) * invD;
105 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
108 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
111 }
else if (s01 >= 1.0) {
114 v0p = _v0 + v0v1 * s01;
116 }
else if (s02 > 1.0) {
117 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
120 }
else if (s12 <= 0.0) {
123 v0p = _v1 + v1v2 * s12;
126 v0p = _v0 + v0v2 * s02;
128 }
else if (b < 0.0) {
130 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
134 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
137 }
else if (s02 >= 1.0) {
140 v0p = _v0 + v0v2 * s02;
142 }
else if (s01 > 1.0) {
143 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
146 }
else if (s12 <= 0.0) {
149 v0p = _v1 + v1v2 * s12;
152 v0p = _v0 + v0v1 * s01;
154 }
else if (a+b > 1.0) {
156 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
158 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
161 }
else if (s02 >= 1.0) {
164 v0p = _v0 + v0v2*s02;
166 }
else if (s12 <= 0.0) {
167 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
170 }
else if (s01 >= 1.0) {
173 v0p = _v0 + v0v1 * s01;
176 v0p = _v1 + v1v2 * s12;
180 return ( (_p - n*((n|v0p) * invD)) - _p).sqrnorm();
183 return (v0p - _p).sqrnorm();
187 template <
class MeshT>
192 typename Mesh::FIter f_it(mesh_.faces_begin()), f_end(mesh_.faces_end());
194 for (; f_it!=f_end; ++f_it)
195 mesh_.property(points_, *f_it).clear();
202 template <
class MeshT>
207 std::vector<FaceHandle> faces; faces.reserve(20);
209 typename Mesh::FaceHandle fh;
210 const typename Mesh::Scalar sqr_tolerace = tolerance_*tolerance_;
211 typename Mesh::CFVIter fv_it;
219 for (vf_it=mesh_.vf_iter(_ci.
v0); vf_it.is_valid(); ++vf_it) {
222 if (fh != _ci.
fl && fh != _ci.
fr)
225 Points& pts = mesh_.property(points_, fh);
226 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
230 tmp_points_.push_back(_ci.
p0);
233 typename std::vector<FaceHandle>::iterator fh_it, fh_end(faces.end());
234 typename Points::const_iterator p_it, p_end(tmp_points_.end());
237 mesh_.set_point(_ci.
v0, _ci.
p1);
242 for (p_it=tmp_points_.begin(); ok && p_it!=p_end; ++p_it) {
245 for (fh_it=faces.begin(); !ok && fh_it!=fh_end; ++fh_it) {
246 fv_it=mesh_.cfv_iter(*fh_it);
247 const Point& p0 = mesh_.point(*fv_it);
248 const Point& p1 = mesh_.point(*(++fv_it));
249 const Point& p2 = mesh_.point(*(++fv_it));
251 if ( distPointTriangleSquared(*p_it, p0, p1, p2) <= sqr_tolerace)
257 mesh_.set_point(_ci.
v0, _ci.
p0);
259 return ( ok ? static_cast<float>(Base::LEGAL_COLLAPSE) : static_cast<float>(Base::ILLEGAL_COLLAPSE) );
264 template<
class MeshT>
266 if (_factor >= 0.0 && _factor <= 1.0) {
270 Scalar tolerance = tolerance_ * Scalar(_factor / this->error_tolerance_factor_);
271 set_tolerance(tolerance);
272 this->error_tolerance_factor_ = _factor;
278 template <
class MeshT>
285 std::vector<FaceHandle> faces;
294 for (vf_it=mesh_.vf_iter(_ci.
v1); vf_it.is_valid(); ++vf_it) {
298 Points& pts = mesh_.property(points_, fh);
299 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
302 if (faces.empty())
return;
306 if ((fh=_ci.
fl).is_valid()) {
307 Points& pts = mesh_.property(points_, fh);
308 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
311 if ((fh=_ci.
fr).is_valid()) {
312 Points& pts = mesh_.property(points_, fh);
313 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
318 tmp_points_.push_back(_ci.
p0);
322 typename std::vector<FaceHandle>::iterator fh_it, fh_end(faces.end());
323 typename Points::const_iterator p_it, p_end(tmp_points_.end());
327 typename Mesh::CFVIter fv_it;
329 for (p_it=tmp_points_.begin(); p_it!=p_end; ++p_it) {
332 for (fh_it=faces.begin(); fh_it!=fh_end; ++fh_it) {
333 fv_it=mesh_.cfv_iter(*fh_it);
334 const Point& p0 = mesh_.point(*fv_it);
335 const Point& p1 = mesh_.point(*(++fv_it));
336 const Point& p2 = mesh_.point(*(++fv_it));
338 e = distPointTriangleSquared(*p_it, p0, p1, p2);
346 mesh_.property(points_, fh).push_back(*p_it);
354 template <
class MeshT>
355 typename ModHausdorffT<MeshT>::Scalar
359 typename Mesh::CFVIter fv_it = mesh_.cfv_iter(_fh);
360 const Point& p0 = mesh_.point(fv_it);
361 const Point& p1 = mesh_.point(++fv_it);
362 const Point& p2 = mesh_.point(++fv_it);
364 const Points& points = mesh_.property(points_, _fh);
365 typename Points::const_iterator p_it = points.begin();
366 typename Points::const_iterator p_end = points.end();
370 Scalar emax = distPointTriangleSquared(_p, p0, p1, p2);
374 for (; p_it!=p_end; ++p_it) {
375 e = distPointTriangleSquared(*p_it, p0, p1, p2);
Mesh::Point p1
Positions of remaining vertex.
Mesh::FaceHandle fl
Left face.
Mesh::FaceHandle fr
Right face.
Kernel::VertexFaceIter VertexFaceIter
Circulator.
virtual float collapse_priority(const CollapseInfo &_ci) override
compute Hausdorff error for one-ring
void set_error_tolerance_factor(double _factor) override
set the percentage of tolerance
Scalar compute_sqr_error(FaceHandle _fh, const Point &_p) const
compute max error for face _fh w.r.t. its point list and _p
virtual void initialize() override
reset per-face point lists
virtual void postprocess_collapse(const CollapseInfo &_ci) override
re-distribute points
Scalar distPointTriangleSquared(const Point &_p, const Point &_v0, const Point &_v1, const Point &_v2)
squared distance from point _p to triangle (_v0, _v1, _v2)
Kernel::Scalar Scalar
Scalar type.
Mesh::VertexHandle v0
Vertex to be removed.
Mesh::VertexHandle v1
Remaining vertex.
Mesh::Point p0
Position of removed vertex.