Add a file for general geometric mesh utilities
This commit is contained in:
parent
ebcd2906a8
commit
fb9134993c
1 changed files with 54 additions and 0 deletions
54
libs/geom/include/psemek/geom/mesh.hpp
Normal file
54
libs/geom/include/psemek/geom/mesh.hpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/geom/box.hpp>
|
||||
#include <psemek/geom/simplex.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace psemek::geom
|
||||
{
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
std::vector<point<T, N>> vertices(box<T, N> const & b)
|
||||
{
|
||||
std::vector<point<T, N>> result;
|
||||
|
||||
for (std::size_t mask = 0; mask < (1 << N); ++mask)
|
||||
{
|
||||
point<T, N> p;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
{
|
||||
p[i] = (mask & (1 << i)) ? b[i].max : b[i].min;
|
||||
}
|
||||
result.push_back(p);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Index = std::uint32_t, typename T, std::size_t N>
|
||||
std::vector<simplex<Index, 1>> edges(box<T, N> const &)
|
||||
{
|
||||
static_assert(N > 0); // who knows?..
|
||||
|
||||
std::vector<simplex<Index, 1>> result;
|
||||
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
{
|
||||
for (std::size_t mask = 0; mask < (1 << (N - 1)); ++mask)
|
||||
{
|
||||
auto const lo = mask & ((1 << i) - 1);
|
||||
auto const hi = mask ^ lo;
|
||||
|
||||
auto const idx0 = lo | (hi << 1);
|
||||
auto const idx1 = idx0 | (1 << i);
|
||||
|
||||
result.push_back({static_cast<Index>(idx0), static_cast<Index>(idx1)});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue