Commit 5dc77e5d authored by Philip Trettner's avatar Philip Trettner
Browse files

added some consistency checks

parent e4c7c8b6
......@@ -23,6 +23,93 @@ void Mesh::assert_consistency() const
assert(mHalfedges.size() % 2 == 0); ///< even number of halfedges
// check correct counts
{
auto vertex_cnt = 0;
auto face_cnt = 0;
auto edge_cnt = 0;
auto halfedge_cnt = 0;
auto valid_vertex_cnt = 0;
auto valid_face_cnt = 0;
auto valid_edge_cnt = 0;
auto valid_halfedge_cnt = 0;
auto invalid_vertex_cnt = 0;
auto invalid_face_cnt = 0;
auto invalid_edge_cnt = 0;
auto invalid_halfedge_cnt = 0;
for (auto h : vertices())
{
++vertex_cnt;
if (h.is_deleted())
++invalid_vertex_cnt;
}
for (auto h : faces())
{
++face_cnt;
if (h.is_deleted())
++invalid_face_cnt;
}
for (auto h : edges())
{
++edge_cnt;
if (h.is_deleted())
++invalid_edge_cnt;
}
for (auto h : halfedges())
{
++halfedge_cnt;
if (h.is_deleted())
++invalid_halfedge_cnt;
}
for (auto h : valid_vertices())
{
assert(h.is_valid());
++valid_vertex_cnt;
}
for (auto h : valid_faces())
{
assert(h.is_valid());
++valid_face_cnt;
}
for (auto h : valid_edges())
{
assert(h.is_valid());
++valid_edge_cnt;
}
for (auto h : valid_halfedges())
{
assert(h.is_valid());
++valid_halfedge_cnt;
}
assert(vertex_cnt == vertices().size());
assert(face_cnt == faces().size());
assert(edge_cnt == edges().size());
assert(halfedge_cnt == halfedges().size());
assert(valid_vertex_cnt == valid_vertices().size());
assert(valid_face_cnt == valid_faces().size());
assert(valid_edge_cnt == valid_edges().size());
assert(valid_halfedge_cnt == valid_halfedges().size());
assert(vertex_cnt == valid_vertex_cnt + invalid_vertex_cnt);
assert(face_cnt == valid_face_cnt + invalid_face_cnt);
assert(edge_cnt == valid_edge_cnt + invalid_edge_cnt);
assert(halfedge_cnt == valid_halfedge_cnt + invalid_halfedge_cnt);
assert(mDeletedFaces == invalid_face_cnt);
assert(mDeletedVertices == invalid_vertex_cnt);
assert(mDeletedHalfedges == invalid_halfedge_cnt);
assert(invalid_edge_cnt * 2 == invalid_halfedge_cnt);
assert(valid_edge_cnt * 2 == valid_halfedge_cnt);
assert(edge_cnt * 2 == halfedge_cnt);
}
// check prev-next heh
......
......@@ -47,6 +47,11 @@ public:
face_collection faces() { return {this}; }
edge_collection edges() { return {this}; }
halfedge_collection halfedges() { return {this}; }
// const versions:
const_vertex_collection vertices() const { return {this}; }
const_face_collection faces() const { return {this}; }
const_edge_collection edges() const { return {this}; }
const_halfedge_collection halfedges() const { return {this}; }
/// smart collections for VALID primitives (EXCLUDING deleted ones)
///
......@@ -264,24 +269,28 @@ private:
friend struct vertex_iterator;
friend struct valid_vertex_iterator;
friend struct valid_vertex_collection;
friend struct const_vertex_collection;
friend struct face_handle;
friend struct face_collection;
friend struct face_iterator;
friend struct valid_face_iterator;
friend struct valid_face_collection;
friend struct const_face_collection;
friend struct edge_handle;
friend struct edge_collection;
friend struct edge_iterator;
friend struct valid_edge_iterator;
friend struct valid_edge_collection;
friend struct const_edge_collection;
friend struct halfedge_handle;
friend struct halfedge_collection;
friend struct halfedge_iterator;
friend struct valid_halfedge_iterator;
friend struct valid_halfedge_collection;
friend struct const_halfedge_collection;
};
/// ======== IMPLEMENTATION ========
......@@ -672,6 +681,21 @@ inline vertex_iterator vertex_collection::end() const
return mesh->vertices_end();
}
inline int const_vertex_collection::size() const
{
return mesh->size_vertices();
}
inline vertex_iterator const_vertex_collection::begin() const
{
return mesh->vertices_begin();
}
inline vertex_iterator const_vertex_collection::end() const
{
return mesh->vertices_end();
}
inline int valid_vertex_collection::size() const
{
return mesh->size_valid_vertices();
......@@ -780,6 +804,21 @@ inline face_iterator face_collection::end() const
return mesh->faces_end();
}
inline int const_face_collection::size() const
{
return mesh->size_faces();
}
inline face_iterator const_face_collection::begin() const
{
return mesh->faces_begin();
}
inline face_iterator const_face_collection::end() const
{
return mesh->faces_end();
}
inline int valid_face_collection::size() const
{
return mesh->size_valid_faces();
......@@ -822,6 +861,21 @@ inline edge_iterator edge_collection::end() const
return mesh->edges_end();
}
inline int const_edge_collection::size() const
{
return mesh->size_edges();
}
inline edge_iterator const_edge_collection::begin() const
{
return mesh->edges_begin();
}
inline edge_iterator const_edge_collection::end() const
{
return mesh->edges_end();
}
inline int valid_edge_collection::size() const
{
return mesh->size_valid_edges();
......@@ -864,6 +918,21 @@ inline halfedge_iterator halfedge_collection::end() const
return mesh->halfedges_end();
}
inline int const_halfedge_collection::size() const
{
return mesh->size_halfedges();
}
inline halfedge_iterator const_halfedge_collection::begin() const
{
return mesh->halfedges_begin();
}
inline halfedge_iterator const_halfedge_collection::end() const
{
return mesh->halfedges_end();
}
inline int valid_halfedge_collection::size() const
{
return mesh->size_valid_halfedges();
......@@ -878,4 +947,47 @@ inline valid_halfedge_iterator valid_halfedge_collection::end() const
{
return mesh->valid_halfedges_end();
}
/// ======== HANDLES IMPLEMENTATION ========
inline bool vertex_handle::is_valid() const
{
return idx.is_valid() && mesh->mVertices[idx.value].is_valid();
}
inline bool vertex_handle::is_deleted() const
{
return !idx.is_valid() || !mesh->mVertices[idx.value].is_valid();
}
inline bool face_handle::is_valid() const
{
return idx.is_valid() && mesh->mFaces[idx.value].is_valid();
}
inline bool face_handle::is_deleted() const
{
return !idx.is_valid() || !mesh->mFaces[idx.value].is_valid();
}
inline bool edge_handle::is_valid() const
{
return idx.is_valid() && mesh->mHalfedges[idx.value >> 1].is_valid();
}
inline bool edge_handle::is_deleted() const
{
return !idx.is_valid() || !mesh->mHalfedges[idx.value >> 1].is_valid();
}
inline bool halfedge_handle::is_valid() const
{
return idx.is_valid() && mesh->mHalfedges[idx.value].is_valid();
}
inline bool halfedge_handle::is_deleted() const
{
return !idx.is_valid() || !mesh->mHalfedges[idx.value].is_valid();
}
}
......@@ -75,6 +75,9 @@ struct face_handle
bool operator!=(face_index const& rhs) const { return idx != rhs; }
bool operator==(face_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(face_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
bool is_valid() const; ///< valid idx and not deleted
bool is_deleted() const; ///< marked for deletion (or invalid idx)
};
struct vertex_handle
......@@ -88,6 +91,9 @@ struct vertex_handle
bool operator!=(vertex_index const& rhs) const { return idx != rhs; }
bool operator==(vertex_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(vertex_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
bool is_valid() const; ///< valid idx and not deleted
bool is_deleted() const; ///< marked for deletion (or invalid idx)
};
struct edge_handle
......@@ -101,6 +107,9 @@ struct edge_handle
bool operator!=(edge_index const& rhs) const { return idx != rhs; }
bool operator==(edge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(edge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
bool is_valid() const; ///< valid idx and not deleted
bool is_deleted() const; ///< marked for deletion (or invalid idx)
};
struct halfedge_handle
......@@ -115,6 +124,9 @@ struct halfedge_handle
bool operator==(halfedge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(halfedge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
bool is_valid() const; ///< valid idx and not deleted
bool is_deleted() const; ///< marked for deletion (or invalid idx)
// TODO:
// vertex_to
// vertex_from
......@@ -122,4 +134,5 @@ struct halfedge_handle
// opposite_face
// opposite
};
}
......@@ -30,6 +30,20 @@ struct vertex_collection
vertex_iterator end() const;
};
/// same as vertex_collection but const
struct const_vertex_collection
{
Mesh const* mesh;
/// Number of vertices, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
vertex_iterator begin() const;
vertex_iterator end() const;
};
/// Same as vertex_collection but only including valid, non-deleted vertices
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to vertex_collection)
......@@ -81,6 +95,20 @@ struct face_collection
face_iterator end() const;
};
/// same as face_collection but const
struct const_face_collection
{
Mesh const* mesh;
/// Number of faces, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
face_iterator begin() const;
face_iterator end() const;
};
/// Same as face_collection but only including valid, non-deleted faces
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to face_collection)
......@@ -118,6 +146,20 @@ struct edge_collection
edge_iterator end() const;
};
/// same as edge_collection but const
struct const_edge_collection
{
Mesh const* mesh;
/// Number of edges, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
edge_iterator begin() const;
edge_iterator end() const;
};
/// Same as edge_collection but only including valid, non-deleted edges
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to edge_collection)
......@@ -156,6 +198,20 @@ struct halfedge_collection
halfedge_iterator end() const;
};
/// same as halfedge_collection but const
struct const_halfedge_collection
{
Mesh const* mesh;
/// Number of halfedges, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
halfedge_iterator begin() const;
halfedge_iterator end() const;
};
/// Same as halfedge_collection but only including valid, non-deleted halfedges
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to halfedge_collection)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment