Commit 885fafb6 authored by Philip Trettner's avatar Philip Trettner
Browse files

restructure algorithms folder, fixed some hole-related problems, added sqrt3-subdiv

parent 56153d0f
......@@ -114,10 +114,10 @@ private:
void reserve_edges(int capacity);
void reserve_halfedges(int capacity);
int size_faces() const { return (int)mFaces.size(); }
int size_vertices() const { return (int)mVertices.size(); }
int size_edges() const { return (int)mHalfedges.size() >> 1; }
int size_halfedges() const { return (int)mHalfedges.size(); }
int size_all_faces() const { return (int)mFaces.size(); }
int size_all_vertices() const { return (int)mVertices.size(); }
int size_all_edges() const { return (int)mHalfedges.size() >> 1; }
int size_all_halfedges() const { return (int)mHalfedges.size(); }
int size_valid_faces() const { return (int)mFaces.size() - mRemovedFaces; }
int size_valid_vertices() const { return (int)mVertices.size() - mRemovedVertices; }
......@@ -302,42 +302,42 @@ private:
struct face_info &face(face_index i)
{
assert(i.is_valid() && i.value < size_faces());
assert(i.is_valid() && i.value < size_all_faces());
return mFaces[i.value];
}
struct face_info const &face(face_index i) const
{
assert(i.is_valid() && i.value < size_faces());
assert(i.is_valid() && i.value < size_all_faces());
return mFaces[i.value];
}
struct vertex_info &vertex(vertex_index i)
{
assert(i.is_valid() && i.value < size_vertices());
assert(i.is_valid() && i.value < size_all_vertices());
return mVertices[i.value];
}
struct vertex_info const &vertex(vertex_index i) const
{
assert(i.is_valid() && i.value < size_vertices());
assert(i.is_valid() && i.value < size_all_vertices());
return mVertices[i.value];
}
struct halfedge_info &halfedge(halfedge_index i)
{
assert(i.is_valid() && i.value < size_halfedges());
assert(i.is_valid() && i.value < size_all_halfedges());
return mHalfedges[i.value];
}
struct halfedge_info const &halfedge(halfedge_index i) const
{
assert(i.is_valid() && i.value < size_halfedges());
assert(i.is_valid() && i.value < size_all_halfedges());
return mHalfedges[i.value];
}
struct halfedge_info &halfedge(edge_index i, int h)
{
assert(i.is_valid() && i.value < size_edges());
assert(i.is_valid() && i.value < size_all_edges());
return mHalfedges[(i.value << 1) + h];
}
struct halfedge_info const &halfedge(edge_index i, int h) const
{
assert(i.is_valid() && i.value < size_edges());
assert(i.is_valid() && i.value < size_all_edges());
return mHalfedges[(i.value << 1) + h];
}
......
......@@ -8,7 +8,7 @@ namespace polymesh
{
vertex_attribute<float> geodesic_fast_marching_linear(Mesh const& m, vertex_attribute<glm::vec3> const& position)
{
auto dis = m.vertices().make_attribute<float>(-1);
auto dis = m.vertices().make_attribute_with_default<float>(std::numeric_limits<float>::max());
// TODO
......
#pragma once
#include "../Mesh.hh"
#include "../fields.hh"
#include <polymesh/Mesh.hh>
#include <polymesh/fields.hh>
namespace polymesh
{
......@@ -28,4 +28,4 @@ GeodesicNNF<Vec3, Scalar> make_geodesic_nnf(Mesh const& m, vertex_attribute<Vec3
}
// Implementation
#include "geodesic_nnf.impl.hh"
#include "gsf.impl.hh"
#pragma once
#include "geodesic_nnf.hh"
#include "gsf.hh"
namespace polymesh
{
......
#pragma once
#include <polymesh/Mesh.hh>
namespace polymesh {
/// Performs a loop subdivision step (topology only)
void subdivide_loop(Mesh& m);
}
#pragma once
#include <polymesh/Mesh.hh>
namespace polymesh
{
/// Performs a uniform sqrt-3 subdivision step (topology only)
/// A provided function is called for each new vertex with handles (v_new, v0, v1, v2)
template <class VertexF>
void subdivide_sqrt3(Mesh& m, VertexF&& vf);
/// ======== IMPLEMENTATION ========
template <class VertexF>
void subdivide_sqrt3(Mesh& m, VertexF&& vf)
{
auto e_end = m.edges().end();
for (auto f : m.faces())
{
auto h = f.any_halfedge();
auto v0 = h.vertex_from();
auto v1 = h.vertex_to();
auto v2 = h.next().vertex_to();
// split face
auto v = m.faces().split(f);
// call vf
vf(v, v0, v1, v2);
}
// rotate old edges
for (auto it = m.edges().begin(); it != e_end; ++it)
{
auto e = *it;
if (e.is_boundary())
continue;
m.edges().rotate_next(e);
}
}
}
......@@ -97,7 +97,7 @@ inline void Mesh::register_attr(primitive_attribute_base<vertex_tag> *attr) cons
nextAttrs->mPrevAttribute = attr;
// resize attr
attr->resize(vertices().size(), false);
attr->resize(all_vertices().size(), false);
}
inline void Mesh::deregister_attr(primitive_attribute_base<vertex_tag> *attr) const
......@@ -125,7 +125,7 @@ inline void Mesh::register_attr(primitive_attribute_base<face_tag> *attr) const
nextAttrs->mPrevAttribute = attr;
// resize attr
attr->resize(faces().size(), false);
attr->resize(all_faces().size(), false);
}
inline void Mesh::deregister_attr(primitive_attribute_base<face_tag> *attr) const
......@@ -153,7 +153,7 @@ inline void Mesh::register_attr(primitive_attribute_base<edge_tag> *attr) const
nextAttrs->mPrevAttribute = attr;
// resize attr
attr->resize(edges().size(), false);
attr->resize(all_edges().size(), false);
}
inline void Mesh::deregister_attr(primitive_attribute_base<edge_tag> *attr) const
......@@ -181,7 +181,7 @@ inline void Mesh::register_attr(primitive_attribute_base<halfedge_tag> *attr) co
nextAttrs->mPrevAttribute = attr;
// resize attr
attr->resize(halfedges().size(), false);
attr->resize(all_halfedges().size(), false);
}
inline void Mesh::deregister_attr(primitive_attribute_base<halfedge_tag> *attr) const
......
......@@ -491,7 +491,7 @@ inline vertex_index Mesh::next_valid_idx_from(vertex_index idx) const
for (auto i = idx.value; i < (int)mVertices.size(); ++i)
if (mVertices[i].is_valid())
return vertex_index(i);
return vertex_index(size_vertices()); // end index
return vertex_index(size_all_vertices()); // end index
}
inline vertex_index Mesh::prev_valid_idx_from(vertex_index idx) const
......@@ -507,7 +507,7 @@ inline edge_index Mesh::next_valid_idx_from(edge_index idx) const
for (auto i = idx.value << 1; i < (int)mHalfedges.size(); i += 2)
if (mHalfedges[i].is_valid())
return edge_index(i >> 1);
return edge_index(size_edges()); // end index
return edge_index(size_all_edges()); // end index
}
inline edge_index Mesh::prev_valid_idx_from(edge_index idx) const
......@@ -523,7 +523,7 @@ inline face_index Mesh::next_valid_idx_from(face_index idx) const
for (auto i = idx.value; i < (int)mFaces.size(); ++i)
if (mFaces[i].is_valid())
return face_index(i);
return face_index(size_faces()); // end index
return face_index(size_all_faces()); // end index
}
inline face_index Mesh::prev_valid_idx_from(face_index idx) const
......@@ -539,7 +539,7 @@ inline halfedge_index Mesh::next_valid_idx_from(halfedge_index idx) const
for (auto i = idx.value; i < (int)mHalfedges.size(); ++i)
if (mHalfedges[i].is_valid())
return halfedge_index(i);
return halfedge_index(size_halfedges()); // end index
return halfedge_index(size_all_halfedges()); // end index
}
inline halfedge_index Mesh::prev_valid_idx_from(halfedge_index idx) const
......@@ -581,7 +581,8 @@ inline vertex_index Mesh::face_split(face_index f)
add_face(vs, 3);
h = halfedge(h).next_halfedge;
// NOTE: add_face inserted a new halfedge
h = halfedge(opposite(halfedge(h).next_halfedge)).next_halfedge;
} while (h != h_begin);
return vs[0];
......@@ -1121,10 +1122,10 @@ inline void Mesh::compactify()
return;
// calculate remappings
int v_cnt = size_vertices();
int f_cnt = size_faces();
int e_cnt = size_edges();
int h_cnt = size_halfedges();
int v_cnt = size_all_vertices();
int f_cnt = size_all_faces();
int e_cnt = size_all_edges();
int h_cnt = size_all_halfedges();
std::vector<int> v_new_to_old;
std::vector<int> f_new_to_old;
std::vector<int> e_new_to_old;
......@@ -1214,13 +1215,13 @@ inline void Mesh::compactify()
mHalfedges.shrink_to_fit();
for (auto a = mVertexAttrs; a; a = a->mNextAttribute)
a->resize(size_vertices(), true);
a->resize(size_all_vertices(), true);
for (auto a = mFaceAttrs; a; a = a->mNextAttribute)
a->resize(size_faces(), true);
a->resize(size_all_faces(), true);
for (auto a = mEdgeAttrs; a; a = a->mNextAttribute)
a->resize(size_edges(), true);
a->resize(size_all_edges(), true);
for (auto a = mHalfedgeAttrs; a; a = a->mNextAttribute)
a->resize(size_halfedges(), true);
a->resize(size_all_halfedges(), true);
mRemovedFaces = 0;
mRemovedHalfedges = 0;
......
......@@ -5,10 +5,10 @@
namespace polymesh
{
// primitive::all_size
inline int primitive<vertex_tag>::all_size(Mesh const &m) { return m.size_vertices(); }
inline int primitive<face_tag>::all_size(Mesh const &m) { return m.size_faces(); }
inline int primitive<edge_tag>::all_size(Mesh const &m) { return m.size_edges(); }
inline int primitive<halfedge_tag>::all_size(Mesh const &m) { return m.size_halfedges(); }
inline int primitive<vertex_tag>::all_size(Mesh const &m) { return m.size_all_vertices(); }
inline int primitive<face_tag>::all_size(Mesh const &m) { return m.size_all_faces(); }
inline int primitive<edge_tag>::all_size(Mesh const &m) { return m.size_all_edges(); }
inline int primitive<halfedge_tag>::all_size(Mesh const &m) { return m.size_all_halfedges(); }
// primitive::valid_size
inline int primitive<vertex_tag>::valid_size(Mesh const &m) { return m.size_valid_vertices(); }
......
Markdown is supported
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