2015-04-28 11:54:17 +00:00
|
|
|
/* ========================================================================= *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2023-03-01 13:03:33 +01:00
|
|
|
* Copyright (c) 2001-2023, RWTH-Aachen University *
|
2015-04-28 13:07:46 +00:00
|
|
|
* Department of Computer Graphics and Multimedia *
|
2015-04-28 11:33:32 +00:00
|
|
|
* All rights reserved. *
|
|
|
|
|
* www.openmesh.org *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
|
* This file is part of OpenMesh. *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without *
|
|
|
|
|
* modification, are permitted provided that the following conditions *
|
|
|
|
|
* are met: *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, *
|
|
|
|
|
* this list of conditions and the following disclaimer. *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright *
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the *
|
|
|
|
|
* documentation and/or other materials provided with the distribution. *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 3. Neither the name of the copyright holder nor the names of its *
|
|
|
|
|
* contributors may be used to endorse or promote products derived from *
|
|
|
|
|
* this software without specific prior written permission. *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
|
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
|
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
|
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
|
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
2015-04-28 11:54:17 +00:00
|
|
|
* *
|
|
|
|
|
* ========================================================================= */
|
2009-06-04 08:46:29 +00:00
|
|
|
|
2019-01-15 11:21:12 +01:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#define OPENMESH_MESHCHECKER_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== NAMESPACES ==============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
//== IMPLEMENTATION ==========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Mesh>
|
|
|
|
|
bool
|
|
|
|
|
MeshCheckerT<Mesh>::
|
|
|
|
|
check(unsigned int _targets, std::ostream& _os)
|
|
|
|
|
{
|
|
|
|
|
bool ok(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--- vertex checks ---
|
|
|
|
|
|
|
|
|
|
if (_targets & CHECK_VERTICES)
|
|
|
|
|
{
|
|
|
|
|
unsigned int count;
|
|
|
|
|
const unsigned int max_valence(10000);
|
|
|
|
|
|
|
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
for (const auto vh: mesh_.vertices())
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
2013-08-07 11:59:44 +00:00
|
|
|
/* The outgoing halfedge of a boundary vertex has to be a boundary halfedge */
|
2023-07-20 20:28:39 +02:00
|
|
|
auto heh = vh.halfedge();
|
2013-08-07 11:59:44 +00:00
|
|
|
if (heh.is_valid() && !mesh_.is_boundary(heh))
|
|
|
|
|
{
|
|
|
|
|
for (typename Mesh::ConstVertexOHalfedgeIter vh_it(mesh_, vh);
|
|
|
|
|
vh_it.is_valid(); ++vh_it)
|
|
|
|
|
{
|
|
|
|
|
if (mesh_.is_boundary(*vh_it))
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< ": outgoing halfedge not on boundary error\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-20 20:28:39 +02:00
|
|
|
if (heh.is_valid()) {
|
2023-08-22 15:20:27 +02:00
|
|
|
if (heh.idx() < -1 || heh.idx() >= (int)mesh_.n_halfedges()) {
|
2023-07-20 20:28:39 +02:00
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< " has out-of-bounds outgoing HE: " << heh;
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
if (is_deleted(heh.edge())) {
|
|
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< " has deleted outgoing HE: " << heh;
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-07 11:59:44 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
2013-08-07 11:59:44 +00:00
|
|
|
// outgoing halfedge has to refer back to vertex
|
|
|
|
|
if (mesh_.halfedge_handle(vh).is_valid() &&
|
|
|
|
|
mesh_.from_vertex_handle(mesh_.halfedge_handle(vh)) != vh)
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< ": outgoing halfedge does not reference vertex\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check whether circulators are still in order
|
2023-07-20 20:28:39 +02:00
|
|
|
auto vv_it = mesh_.cvv_cwiter(vh);
|
2013-08-07 11:59:44 +00:00
|
|
|
for (count=0; vv_it.is_valid() && (count < max_valence); ++vv_it, ++count) {};
|
|
|
|
|
if (count == max_valence)
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< ": ++circulator problem, one ring corrupt\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2015-03-04 13:03:44 +00:00
|
|
|
vv_it = mesh_.cvv_cwiter(vh);
|
2013-08-07 11:59:44 +00:00
|
|
|
for (count=0; vv_it.is_valid() && (count < max_valence); --vv_it, ++count) {};
|
|
|
|
|
if (count == max_valence)
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: vertex " << vh
|
|
|
|
|
<< ": --circulator problem, one ring corrupt\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--- halfedge checks ---
|
|
|
|
|
|
|
|
|
|
if (_targets & CHECK_EDGES)
|
|
|
|
|
{
|
|
|
|
|
typename Mesh::ConstHalfedgeIter h_it(mesh_.halfedges_begin()),
|
2013-08-07 11:32:50 +00:00
|
|
|
h_end(mesh_.halfedges_end());
|
2023-08-22 16:44:07 +02:00
|
|
|
typename Mesh::HalfedgeHandle hstart, hhh;
|
2023-08-22 15:23:43 +02:00
|
|
|
size_t n_halfedges = 2*mesh_.n_edges();
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
for (const auto hh: mesh_.halfedges())
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
2023-07-20 20:28:39 +02:00
|
|
|
if (!hh.to().halfedge().is_valid()) {
|
|
|
|
|
_os << "MeshChecker: vertex " << hh.from()
|
|
|
|
|
<< " has no outgoing halfedge, but it is not isolated.\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
// degenerated halfedge ?
|
|
|
|
|
if (mesh_.from_vertex_handle(hh) == mesh_.to_vertex_handle(hh))
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
2023-07-20 20:28:39 +02:00
|
|
|
_os << "MeshChecker: halfedge " << hh
|
|
|
|
|
<< ": to-vertex == from-vertex\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2013-08-07 11:32:50 +00:00
|
|
|
|
|
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
// next <-> prev check
|
|
|
|
|
if (mesh_.next_halfedge_handle(mesh_.prev_halfedge_handle(hh)) != hh)
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: halfedge " << hh
|
|
|
|
|
<< ": prev->next != this\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2013-08-07 11:32:50 +00:00
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
// heh.to == heh.next.from?
|
|
|
|
|
if (mesh_.to_vertex_handle(hh) != mesh_.from_vertex_handle(
|
|
|
|
|
mesh_.next_halfedge_handle(hh)))
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: halfedge " << hh
|
|
|
|
|
<< ".to != he.next.from\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
// heh.from == heh.prev.to?
|
|
|
|
|
if (mesh_.from_vertex_handle(hh) != mesh_.to_vertex_handle(
|
|
|
|
|
mesh_.prev_halfedge_handle(hh)))
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: halfedge " << hh
|
|
|
|
|
<< ".from != he.prev.to\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2013-08-07 11:32:50 +00:00
|
|
|
|
|
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
// halfedges should form a cycle
|
2023-08-22 15:23:43 +02:00
|
|
|
size_t count=0; hstart=hhh=hh;
|
2023-07-20 20:28:39 +02:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
hhh = mesh_.next_halfedge_handle(hhh);
|
|
|
|
|
++count;
|
|
|
|
|
} while (hhh != hstart && count < n_halfedges);
|
2013-08-07 11:32:50 +00:00
|
|
|
|
2023-07-20 20:28:39 +02:00
|
|
|
if (count == n_halfedges)
|
|
|
|
|
{
|
|
|
|
|
_os << "MeshChecker: halfedges starting from " << hh
|
|
|
|
|
<< " do not form a cycle\n";
|
|
|
|
|
ok = false;
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--- face checks ---
|
|
|
|
|
|
|
|
|
|
if (_targets & CHECK_FACES)
|
|
|
|
|
{
|
|
|
|
|
typename Mesh::ConstFaceIter f_it(mesh_.faces_begin()),
|
2013-08-07 11:32:50 +00:00
|
|
|
f_end(mesh_.faces_end());
|
2009-02-06 13:37:46 +00:00
|
|
|
typename Mesh::ConstFaceHalfedgeIter fh_it;
|
2013-08-07 11:32:50 +00:00
|
|
|
|
2023-07-21 17:25:42 +02:00
|
|
|
for(const auto fh: mesh_.faces()) {
|
|
|
|
|
for(const auto heh: fh.halfedges()) {
|
|
|
|
|
if (heh.face() != fh) {
|
|
|
|
|
_os << "MeshChecker: face " << fh
|
|
|
|
|
<< ": its halfedge " << heh << " references a different face: "
|
|
|
|
|
<< heh.face()
|
|
|
|
|
<< ".\n";
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
2013-08-07 11:32:50 +00:00
|
|
|
}
|
2009-02-06 13:37:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // naespace Utils
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|