59 #define OPENMESH_DECIMATER_MODHAUSDORFFT_C 74 template <
class MeshT>
75 typename ModHausdorffT<MeshT>::Scalar
82 const Point v0v1 = _v1 - _v0;
83 const Point v0v2 = _v2 - _v0;
84 const Point n = v0v1 % v0v2;
85 const double d = n.sqrnorm();
89 if (d < FLT_MIN && d > -FLT_MIN) {
92 const double invD = 1.0 / d;
96 const Point v1v2 = _v2 - _v1;
97 const double inv_v0v2_2 = 1.0 / v0v2.sqrnorm();
98 const double inv_v0v1_2 = 1.0 / v0v1.sqrnorm();
99 const double inv_v1v2_2 = 1.0 / v1v2.sqrnorm();
102 Point v0p = _p - _v0;
104 typename Point::value_type s01, s02, s12;
105 const double a = (t | v0v2) * -invD;
106 const double b = (t | v0v1) * invD;
111 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
114 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
117 }
else if (s01 >= 1.0) {
120 v0p = _v0 + v0v1 * s01;
122 }
else if (s02 > 1.0) {
123 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
126 }
else if (s12 <= 0.0) {
129 v0p = _v1 + v1v2 * s12;
132 v0p = _v0 + v0v2 * s02;
134 }
else if (b < 0.0) {
136 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
140 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
143 }
else if (s02 >= 1.0) {
146 v0p = _v0 + v0v2 * s02;
148 }
else if (s01 > 1.0) {
149 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
152 }
else if (s12 <= 0.0) {
155 v0p = _v1 + v1v2 * s12;
158 v0p = _v0 + v0v1 * s01;
160 }
else if (a+b > 1.0) {
162 s12 = ( v1v2 | ( _p - _v1 )) * inv_v1v2_2;
164 s02 = ( v0v2 | v0p ) * inv_v0v2_2;
167 }
else if (s02 >= 1.0) {
170 v0p = _v0 + v0v2*s02;
172 }
else if (s12 <= 0.0) {
173 s01 = ( v0v1 | v0p ) * inv_v0v1_2;
176 }
else if (s01 >= 1.0) {
179 v0p = _v0 + v0v1 * s01;
182 v0p = _v1 + v1v2 * s12;
186 return ( (_p - n*((n|v0p) * invD)) - _p).sqrnorm();
189 return (v0p - _p).sqrnorm();
193 template <
class MeshT>
198 typename Mesh::FIter f_it(mesh_.faces_begin()), f_end(mesh_.faces_end());
200 for (; f_it!=f_end; ++f_it)
201 mesh_.property(points_, *f_it).clear();
208 template <
class MeshT>
213 std::vector<FaceHandle> faces; faces.reserve(20);
215 typename Mesh::FaceHandle fh;
216 const typename Mesh::Scalar sqr_tolerace = tolerance_*tolerance_;
217 typename Mesh::CFVIter fv_it;
225 for (vf_it=mesh_.vf_iter(_ci.
v0); vf_it.is_valid(); ++vf_it) {
228 if (fh != _ci.
fl && fh != _ci.
fr)
231 Points& pts = mesh_.property(points_, fh);
232 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
236 tmp_points_.push_back(_ci.
p0);
239 typename std::vector<FaceHandle>::iterator fh_it, fh_end(faces.end());
240 typename Points::const_iterator p_it, p_end(tmp_points_.end());
243 mesh_.set_point(_ci.
v0, _ci.
p1);
248 for (p_it=tmp_points_.begin(); ok && p_it!=p_end; ++p_it) {
251 for (fh_it=faces.begin(); !ok && fh_it!=fh_end; ++fh_it) {
252 fv_it=mesh_.cfv_iter(*fh_it);
253 const Point& p0 = mesh_.point(*fv_it);
254 const Point& p1 = mesh_.point(*(++fv_it));
255 const Point& p2 = mesh_.point(*(++fv_it));
257 if ( distPointTriangleSquared(*p_it, p0, p1, p2) <= sqr_tolerace)
263 mesh_.set_point(_ci.
v0, _ci.
p0);
265 return ( ok ? Base::LEGAL_COLLAPSE : Base::ILLEGAL_COLLAPSE );
270 template<
class MeshT>
272 if (_factor >= 0.0 && _factor <= 1.0) {
276 Scalar tolerance = tolerance_ * Scalar(_factor / this->error_tolerance_factor_);
277 set_tolerance(tolerance);
278 this->error_tolerance_factor_ = _factor;
284 template <
class MeshT>
291 std::vector<FaceHandle> faces;
300 for (vf_it=mesh_.vf_iter(_ci.
v1); vf_it.is_valid(); ++vf_it) {
304 Points& pts = mesh_.property(points_, fh);
305 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
308 if (faces.empty())
return;
312 if ((fh=_ci.
fl).is_valid()) {
313 Points& pts = mesh_.property(points_, fh);
314 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
317 if ((fh=_ci.
fr).is_valid()) {
318 Points& pts = mesh_.property(points_, fh);
319 std::copy(pts.begin(), pts.end(), std::back_inserter(tmp_points_));
324 tmp_points_.push_back(_ci.
p0);
328 typename std::vector<FaceHandle>::iterator fh_it, fh_end(faces.end());
329 typename Points::const_iterator p_it, p_end(tmp_points_.end());
333 typename Mesh::CFVIter fv_it;
335 for (p_it=tmp_points_.begin(); p_it!=p_end; ++p_it) {
338 for (fh_it=faces.begin(); fh_it!=fh_end; ++fh_it) {
339 fv_it=mesh_.cfv_iter(*fh_it);
340 const Point& p0 = mesh_.point(*fv_it);
341 const Point& p1 = mesh_.point(*(++fv_it));
342 const Point& p2 = mesh_.point(*(++fv_it));
344 e = distPointTriangleSquared(*p_it, p0, p1, p2);
352 mesh_.property(points_, fh).push_back(*p_it);
360 template <
class MeshT>
361 typename ModHausdorffT<MeshT>::Scalar
365 typename Mesh::CFVIter fv_it = mesh_.cfv_iter(_fh);
366 const Point& p0 = mesh_.point(fv_it);
367 const Point& p1 = mesh_.point(++fv_it);
368 const Point& p2 = mesh_.point(++fv_it);
370 const Points& points = mesh_.property(points_, _fh);
371 typename Points::const_iterator p_it = points.begin();
372 typename Points::const_iterator p_end = points.end();
376 Scalar emax = distPointTriangleSquared(_p, p0, p1, p2);
380 for (; p_it!=p_end; ++p_it) {
381 e = distPointTriangleSquared(*p_it, p0, p1, p2);
Mesh::VertexHandle v1
Remaining vertex.
Mesh::FaceHandle fl
Left face.
Mesh::FaceHandle fr
Right face.
Mesh::Point p1
Positions of remaining vertex.
Mesh::Point p0
Position of removed vertex.
virtual void postprocess_collapse(const CollapseInfo &_ci)
re-distribute points
Mesh::VertexHandle v0
Vertex to be removed.
virtual float collapse_priority(const CollapseInfo &_ci)
compute Hausdorff error for one-ring
Scalar compute_sqr_error(FaceHandle _fh, const Point &_p) const
compute max error for face _fh w.r.t. its point list and _p
void set_error_tolerance_factor(double _factor)
set the percentage of tolerance
Kernel::VertexFaceIter VertexFaceIter
Circulator.
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.
virtual void initialize()
reset per-face point lists