Visual Computing Library
Loading...
Searching...
No Matches
vertex_sampler.h
1#ifndef VCL_SPACE_COMPLEX_SAMPLER_VERTEX_SAMPLER_H
2#define VCL_SPACE_COMPLEX_SAMPLER_VERTEX_SAMPLER_H
3
4#include <vclib/concepts/mesh/elements/vertex.h>
5#include <vclib/concepts/space/sampler.h>
6#include <vclib/views/mesh.h>
7
8namespace vcl {
9
10namespace detail {
11
12// TODO: make this class the default outside the detail namespace
13// and then define only the const version with CNST = true
14template<VertexConcept VertexType, bool CNST = false>
15class VertexSampler
16{
17 using VP = std::conditional_t<CNST, const VertexType*, VertexType*>;
18 using VPar = std::conditional_t<CNST, const VertexType&, VertexType&>;
19
20 std::vector<VP> mSamples;
21
22public:
23 using PointType = VertexType::CoordType;
24
25 VertexSampler() {}
26
27 const std::vector<VP> samples() const { return mSamples; }
28
29 const typename VertexType::CoordType& sample(uint i) const
30 {
31 return mSamples[i]->coord();
32 }
33
34 std::size_t size() const { return mSamples.size(); }
35
36 void clear() { mSamples.clear(); }
37
38 void reserve(uint n) { mSamples.reserve(n); }
39
40 void resize(uint n) { mSamples.resize(n); }
41
42 void add(VPar v) { mSamples.push_back(&v); }
43
44 void set(uint i, VPar v) { mSamples[i] = &v; }
45
46 auto begin() const { return std::begin(mSamples | views::coords); }
47
48 auto end() const { return std::end(mSamples | views::coords); }
49};
50
51} // namespace detail
52
53template<VertexConcept VertexType>
54using VertexSampler = detail::VertexSampler<VertexType, false>;
55
56template<VertexConcept VertexType>
57using ConstVertexSampler = detail::VertexSampler<VertexType, true>;
58
59} // namespace vcl
60
61#endif // VCL_SPACE_COMPLEX_SAMPLER_VERTEX_SAMPLER_H