Commit 9c1d0adc authored by Philip Trettner's avatar Philip Trettner
Browse files

working on optimization

parent ccd228a2
......@@ -4,6 +4,7 @@
#include "../detail/permutation.hh"
#include "../detail/random.hh"
#include "../detail/union_find.hh"
namespace polymesh
{
......@@ -62,6 +63,17 @@ inline void optimize_for_rendering(Mesh& m)
inline std::vector<int> cache_coherent_face_layout(Mesh const& m)
{
// build binary tree
// - approx min cut
// - refine approx
// - split
std::vector<std::pair<int, int>> edges;
for (auto e : m.edges())
edges.emplace_back((int)e.faceA(), (int)e.faceB());
// TODO
std::vector<int> id;
for (auto i = 0u; i < m.faces().size(); ++i)
id.push_back(i);
......
#pragma once
#include <vector>
#include "../Mesh.hh"
namespace polymesh {
/// Given a face handle, returns the topologically farthest (but finite) face
/// (i.e. the last face that would be visited in a BFS)
face_handle farthest_face(face_handle f);
/// ======== IMPLEMENTATION ========
/*inline face_handle farthest_face(face_handle f)
{
std::vector<face_index> q_curr;
std::vector<face_index> q_next;
q_curr.push_back(f.idx);
face_handle last_f = f;
while (!q_curr.empty())
{
for (auto f : q_curr)
{
// TODO
}
std::swap(q_curr, q_next);
}
return last_f;
}*/
}
......@@ -31,6 +31,8 @@ struct primitive_index
bool operator==(handle_t const& rhs) const { return value == rhs.idx.value; }
bool operator!=(handle_t const& rhs) const { return value != rhs.idx.value; }
explicit operator int() const { return value; }
/// indexes this primitive by a functor
/// also works for attributes
/// - e.g. v[position] or f[area]
......@@ -57,6 +59,8 @@ struct primitive_handle
bool operator==(handle_t const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(handle_t const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
explicit operator int() const { return (int)idx; }
/// indexes this primitive by a functor
/// also works for attributes
/// - e.g. v[position] or f[area]
......
#pragma once
#include <vector>
namespace polymesh
{
namespace detail
{
struct disjoint_set
{
public:
disjoint_set(int size) : entries(size)
{
for (auto i = 0; i < size; ++i)
{
auto& e = entries[i];
e.parent = i;
e.size = 1;
}
}
int find(int idx)
{
auto& e = entries[idx];
if (e.parent != idx)
e.parent = find(e.parent);
return e.parent;
}
bool do_union(int x, int y)
{
// union by size
auto x_root = find(x);
auto y_root = find(y);
if (x_root == y_root)
return false;
if (entries[x_root].size < entries[y_root].size)
std::swap(x_root, y_root);
// |X| > |Y|
entries[y_root].parent = x_root;
entries[x_root].size += entries[y_root].size;
return true;
}
private:
struct entry
{
int parent;
int size;
};
private:
std::vector<entry> entries;
};
}
}
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