Add cg::edge_mesh(dcel) and cg::triangle_mesh(dcel)
This commit is contained in:
parent
b7e070a3a6
commit
0fe4477097
1 changed files with 54 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <psemek/util/empty.hpp>
|
#include <psemek/util/empty.hpp>
|
||||||
#include <psemek/util/ebo.hpp>
|
#include <psemek/util/ebo.hpp>
|
||||||
|
#include <psemek/geom/simplex.hpp>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -599,4 +600,57 @@ namespace psemek::cg
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Point, typename Edge, typename Face, typename Index, typename OutputIterator>
|
||||||
|
OutputIterator edge_mesh(dcel<Point, Edge, Face, Index> const & dcel, OutputIterator out)
|
||||||
|
{
|
||||||
|
std::vector<bool> visited(dcel.edges.size(), false);
|
||||||
|
for (Index e = 0; e < dcel.edges.size(); ++e)
|
||||||
|
{
|
||||||
|
if (visited[e]) continue;
|
||||||
|
|
||||||
|
auto twin = dcel.edges[e].twin;
|
||||||
|
|
||||||
|
visited[e] = true;
|
||||||
|
visited[twin] = true;
|
||||||
|
|
||||||
|
auto h = dcel.edge(e);
|
||||||
|
|
||||||
|
*out++ = geom::segment<Index>{h.origin().index(), h.twin().origin().index()};
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Point, typename Edge, typename Face, typename Index>
|
||||||
|
auto edge_mesh(dcel<Point, Edge, Face, Index> const & dcel)
|
||||||
|
{
|
||||||
|
std::vector<geom::segment<Index>> result;
|
||||||
|
edge_mesh(dcel, std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Point, typename Edge, typename Face, typename Index, typename OutputIterator>
|
||||||
|
OutputIterator triangle_mesh(dcel<Point, Edge, Face, Index> const & dcel, OutputIterator out)
|
||||||
|
{
|
||||||
|
for (Index f = 1; f < dcel.faces.size(); ++f)
|
||||||
|
{
|
||||||
|
auto h = dcel.face(f).edge();
|
||||||
|
|
||||||
|
geom::triangle<Index> t;
|
||||||
|
t[0] = h.origin().index(); h = h.next();
|
||||||
|
t[1] = h.origin().index(); h = h.next();
|
||||||
|
t[2] = h.origin().index();
|
||||||
|
|
||||||
|
*out++ = t;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Point, typename Edge, typename Face, typename Index>
|
||||||
|
auto triangle_mesh(dcel<Point, Edge, Face, Index> const & dcel)
|
||||||
|
{
|
||||||
|
std::vector<geom::triangle<Index>> result;
|
||||||
|
triangle_mesh(dcel, std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue