53#define OPENMESH_DECIMATER_MODHAUSDORFFT_C
69typename ModHausdorffT<MeshT>::Scalar
71distPointTriangleSquared(
const Point& _p,
76 const Point v0v1 = _v1 - _v0;
77 const Point v0v2 = _v2 - _v0;
78 const Point n = v0v1 % v0v2;
79 const Scalar d = sqrnorm(n);
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) / sqrnorm(v0v2);
92 const Scalar inv_v0v1_2 =
static_cast<Scalar
>(1.0) / sqrnorm(v0v1);
93 const Scalar inv_v1v2_2 =
static_cast<Scalar
>(1.0) / sqrnorm(v1v2);
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 sqrnorm( (_p - n*((n|v0p) * invD)) - _p);
183 return sqrnorm(v0p - _p);
187template <
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();
202template <
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) );
266 if (_factor >= 0.0 && _factor <= 1.0) {
270 Scalar new_tolerance = tolerance_ * Scalar(_factor / this->error_tolerance_factor_);
271 set_tolerance(new_tolerance);
272 this->error_tolerance_factor_ = _factor;
278template <
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);
354template <
class MeshT>
355typename 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);
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Handle for a face entity.
Definition: Handles.hh:142
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
Kernel::VertexFaceIter VertexFaceIter
Circulator.
Definition: PolyMeshT.hh:166
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
Mesh::FaceHandle fr
Right face.
Definition: CollapseInfoT.hh:87
Mesh::Point p0
Position of removed vertex.
Definition: CollapseInfoT.hh:84
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:83
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:85
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:82
Mesh::FaceHandle fl
Left face.
Definition: CollapseInfoT.hh:86
Use Hausdorff distance to control decimation.
Definition: ModHausdorffT.hh:79
virtual float collapse_priority(const CollapseInfo &_ci) override
compute Hausdorff error for one-ring
Definition: ModHausdorffT_impl.hh:205
virtual void postprocess_collapse(const CollapseInfo &_ci) override
re-distribute points
Definition: ModHausdorffT_impl.hh:281
virtual void initialize() override
reset per-face point lists
Definition: ModHausdorffT_impl.hh:190
void set_error_tolerance_factor(double _factor) override
set the percentage of tolerance
Definition: ModHausdorffT_impl.hh:265