Skip to content
Snippets Groups Projects
Commit 388fd79e authored by Philip Trettner's avatar Philip Trettner
Browse files

refactoring, new interface paradigm

parent 84187a66
No related branches found
No related tags found
No related merge requests found
#pragma once
#include "EdgeIndex.hh"
namespace polymesh
{
struct Mesh;
struct EdgeHandle
{
Mesh const* mesh;
EdgeIndex idx;
EdgeHandle(Mesh const* mesh, EdgeIndex idx) : mesh(mesh), idx(idx) {}
};
}
#pragma once
namespace polymesh
{
struct EdgeIndex
{
int value = -1;
EdgeIndex() = default;
explicit EdgeIndex(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static EdgeIndex invalid() { return {}; }
bool operator==(EdgeIndex const& rhs) const { return value == rhs.value; }
bool operator!=(EdgeIndex const& rhs) const { return value != rhs.value; }
};
}
#pragma once
#include "FaceIndex.hh"
namespace polymesh
{
struct Mesh;
struct FaceHandle
{
Mesh const* mesh;
FaceIndex idx;
FaceHandle(Mesh const* mesh, FaceIndex idx) : mesh(mesh), idx(idx) {}
};
}
#pragma once
namespace polymesh
{
struct FaceIndex
{
int value = -1;
FaceIndex() = default;
explicit FaceIndex(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static FaceIndex invalid() { return {}; }
bool operator==(FaceIndex const& rhs) const { return value == rhs.value; }
bool operator!=(FaceIndex const& rhs) const { return value != rhs.value; }
};
}
#pragma once
#include "HalfedgeIndex.hh"
namespace polymesh
{
struct Mesh;
struct HalfedgeHandle
{
Mesh const* mesh;
HalfedgeIndex idx;
HalfedgeHandle(Mesh const* mesh, HalfedgeIndex idx) : mesh(mesh), idx(idx) {}
};
}
#pragma once
namespace polymesh
{
struct HalfedgeIndex
{
int value = -1;
HalfedgeIndex() = default;
explicit HalfedgeIndex(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static HalfedgeIndex invalid() { return {}; }
bool operator==(HalfedgeIndex const& rhs) const { return value == rhs.value; }
bool operator!=(HalfedgeIndex const& rhs) const { return value != rhs.value; }
};
}
#pragma once
#include <cassert>
#include "EdgeHandle.hh"
#include "FaceHandle.hh"
#include "HalfedgeHandle.hh"
#include "VertexHandle.hh"
// For iterator interfaces, see http://anderberg.me/2016/07/04/c-custom-iterators/
// Note: some iterator methods are implemented at the end of Mesh.hh to ensure inlining
namespace polymesh
{
struct skipping_vertex_iterator
{
skipping_vertex_iterator() = default;
skipping_vertex_iterator(VertexHandle handle) : handle(handle) {}
VertexHandle operator*() const { return handle; }
skipping_vertex_iterator& operator++();
skipping_vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(skipping_vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(skipping_vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
VertexHandle handle;
};
struct vertex_iterator
{
vertex_iterator() = default;
vertex_iterator(VertexHandle handle) : handle(handle) {}
VertexHandle operator*() const { return handle; }
vertex_iterator& operator++();
vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
VertexHandle handle;
};
}
This diff is collapsed.
#pragma once
#include "Iterators.hh"
namespace polymesh
{
template<typename IteratorT>
struct iterator_range
{
IteratorT _begin;
IteratorT _end;
IteratorT begin() const { return _begin; }
IteratorT end() const { return _end; }
};
using vertex_range = iterator_range<vertex_iterator>;
using skipping_vertex_range = iterator_range<skipping_vertex_iterator>;
}
#pragma once
#include "VertexIndex.hh"
namespace polymesh
{
struct Mesh;
struct VertexHandle
{
Mesh const* mesh;
VertexIndex idx;
VertexHandle(Mesh const* mesh, VertexIndex idx) : mesh(mesh), idx(idx) {}
};
}
#pragma once
namespace polymesh
{
struct VertexIndex
{
int value = -1;
VertexIndex() = default;
explicit VertexIndex(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static VertexIndex invalid() { return {}; }
bool operator==(VertexIndex const& rhs) const { return value == rhs.value; }
bool operator!=(VertexIndex const& rhs) const { return value != rhs.value; }
};
}
#pragma once
namespace polymesh
{
struct Mesh;
// ======================== INDICES ========================
struct face_index
{
int value = -1;
face_index() = default;
explicit face_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static face_index invalid() { return {}; }
bool operator==(face_index const& rhs) const { return value == rhs.value; }
bool operator!=(face_index const& rhs) const { return value != rhs.value; }
};
struct vertex_index
{
int value = -1;
vertex_index() = default;
explicit vertex_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static vertex_index invalid() { return {}; }
bool operator==(vertex_index const& rhs) const { return value == rhs.value; }
bool operator!=(vertex_index const& rhs) const { return value != rhs.value; }
};
struct edge_index
{
int value = -1;
edge_index() = default;
explicit edge_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static edge_index invalid() { return {}; }
bool operator==(edge_index const& rhs) const { return value == rhs.value; }
bool operator!=(edge_index const& rhs) const { return value != rhs.value; }
};
struct halfedge_index
{
int value = -1;
halfedge_index() = default;
explicit halfedge_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
static halfedge_index invalid() { return {}; }
bool operator==(halfedge_index const& rhs) const { return value == rhs.value; }
bool operator!=(halfedge_index const& rhs) const { return value != rhs.value; }
};
// ======================== HANDLES ========================
struct face_handle
{
Mesh const* mesh;
face_index idx;
face_handle(Mesh const* mesh, face_index idx) : mesh(mesh), idx(idx) {}
bool operator==(face_index const& rhs) const { return idx == rhs; }
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; }
};
struct vertex_handle
{
Mesh const* mesh;
vertex_index idx;
vertex_handle(Mesh const* mesh, vertex_index idx) : mesh(mesh), idx(idx) {}
bool operator==(vertex_index const& rhs) const { return idx == rhs; }
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; }
};
struct edge_handle
{
Mesh const* mesh;
edge_index idx;
edge_handle(Mesh const* mesh, edge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(edge_index const& rhs) const { return idx == rhs; }
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; }
};
struct halfedge_handle
{
Mesh const* mesh;
halfedge_index idx;
halfedge_handle(Mesh const* mesh, halfedge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(halfedge_index const& rhs) const { return idx == rhs; }
bool operator!=(halfedge_index const& rhs) const { return idx != rhs; }
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; }
};
}
#pragma once
#include <cassert>
#include "cursors.hh"
// For iterator interfaces, see http://anderberg.me/2016/07/04/c-custom-iterators/
// Note: some iterator methods are implemented at the end of Mesh.hh to ensure inlining
namespace polymesh
{
struct valid_vertex_iterator
{
valid_vertex_iterator() = default;
valid_vertex_iterator(vertex_handle handle) : handle(handle) {}
vertex_handle operator*() const { return handle; }
valid_vertex_iterator& operator++();
valid_vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
vertex_handle handle;
};
struct vertex_iterator
{
vertex_iterator() = default;
vertex_iterator(vertex_handle handle) : handle(handle) {}
vertex_handle operator*() const { return handle; }
vertex_iterator& operator++();
vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
vertex_handle handle;
};
struct valid_face_iterator
{
valid_face_iterator() = default;
valid_face_iterator(face_handle handle) : handle(handle) {}
face_handle operator*() const { return handle; }
valid_face_iterator& operator++();
valid_face_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
face_handle handle;
};
struct face_iterator
{
face_iterator() = default;
face_iterator(face_handle handle) : handle(handle) {}
face_handle operator*() const { return handle; }
face_iterator& operator++();
face_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
face_handle handle;
};
struct valid_edge_iterator
{
valid_edge_iterator() = default;
valid_edge_iterator(edge_handle handle) : handle(handle) {}
edge_handle operator*() const { return handle; }
valid_edge_iterator& operator++();
valid_edge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
edge_handle handle;
};
struct edge_iterator
{
edge_iterator() = default;
edge_iterator(edge_handle handle) : handle(handle) {}
edge_handle operator*() const { return handle; }
edge_iterator& operator++();
edge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
edge_handle handle;
};
struct valid_halfedge_iterator
{
valid_halfedge_iterator() = default;
valid_halfedge_iterator(halfedge_handle handle) : handle(handle) {}
halfedge_handle operator*() const { return handle; }
valid_halfedge_iterator& operator++();
valid_halfedge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
halfedge_handle handle;
};
struct halfedge_iterator
{
halfedge_iterator() = default;
halfedge_iterator(halfedge_handle handle) : handle(handle) {}
halfedge_handle operator*() const { return handle; }
halfedge_iterator& operator++();
halfedge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
halfedge_handle handle;
};
}
#pragma once
#include <cstddef>
#include <vector>
#include "iterators.hh"
namespace polymesh
{
/// Collection of all vertices of a mesh, including deleted ones
/// Basically a smart std::vector
struct vertex_collection
{
Mesh* mesh;
/// Number of vertices, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
/// Ensures that a given number of vertices can be stored without reallocation
void reserve(int capacity) const;
/// Adds a new vertex and returns its handle
/// Does NOT invalidate any iterator!
vertex_handle add() const;
// TODO: delete
// 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)
struct valid_vertex_collection
{
Mesh const* mesh;
/// Number of vertices, EXCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
valid_vertex_iterator begin() const;
valid_vertex_iterator end() const;
};
/// Collection of all faces of a mesh, including deleted ones
/// Basically a smart std::vector
struct face_collection
{
Mesh* mesh;
/// Number of vertices, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
/// Ensures that a given number of faces can be stored without reallocation
void reserve(int capacity) const;
/// Adds a face consisting of N vertices
/// The vertices must already be sorted in CCW order
/// (note: trying to add already existing halfedges triggers assertions)
template <size_t N>
face_handle add_face(const vertex_handle (&vhandles)[N]) const;
face_handle add_face(vertex_handle v0, vertex_handle v1, vertex_handle v2) const;
face_handle add_face(vertex_handle v0, vertex_handle v1, vertex_handle v2, vertex_handle v3) const;
face_handle add_face(std::vector<vertex_handle> const &vhandles) const;
face_handle add_face(vertex_handle const *vhandles, size_t vcnt) const;
// TODO: delete
// 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)
struct valid_face_collection
{
Mesh const* mesh;
/// Number of faces, EXCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
valid_face_iterator begin() const;
valid_face_iterator end() const;
};
/// Collection of all edges of a mesh, including deleted ones
/// Basically a smart std::vector
struct edge_collection
{
Mesh* mesh;
/// Number of vertices, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
/// Ensures that a given number of edges can be stored without reallocation
void reserve(int capacity) 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)
struct valid_edge_collection
{
Mesh const* mesh;
/// Number of edges, EXCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
valid_edge_iterator begin() const;
valid_edge_iterator end() const;
};
/// Collection of all half-edges of a mesh, including deleted ones
/// Basically a smart std::vector
struct halfedge_collection
{
Mesh* mesh;
/// Number of vertices, INCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
/// Ensures that a given number of half-edges can be stored without reallocation
void reserve(int capacity) 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)
struct valid_halfedge_collection
{
Mesh const* mesh;
/// Number of halfedges, EXCLUDING deleted/invalid ones
/// O(1) computation
int size() const;
// Iteration:
valid_halfedge_iterator begin() const;
valid_halfedge_iterator end() const;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment