Volume Cartographer 2.27.0
VolumetricMask.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <memory>
6#include <unordered_set>
7
10
11namespace volcart
12{
13
21{
22public:
24 using Voxel = cv::Vec3i;
25
26private:
28 using MaskSet = std::unordered_set<Voxel, Vec3iHash>;
29
30public:
32 using iterator = MaskSet::iterator;
34 using const_iterator = MaskSet::const_iterator;
35
37 using Pointer = std::shared_ptr<VolumetricMask>;
38
40 template <typename... Args>
41 static auto New(Args... args) -> Pointer
42 {
43 return std::make_shared<VolumetricMask>(std::forward<Args>(args)...);
44 }
45
47 VolumetricMask() = default;
48
50 template <class Container>
51 explicit VolumetricMask(const Container& ps)
52 {
53 mask_.reserve(ps.size());
54 mask_.insert(std::begin(ps), std::end(ps));
55 }
56
58 void setIn(const Voxel& v);
60 void setOut(const Voxel& v);
61
63 template <class Container>
64 void setIn(const Container& ps)
65 {
66 mask_.reserve(mask_.size() + ps.size());
67 mask_.insert(std::begin(ps), std::end(ps));
68 }
69
71 template <class Container>
72 void setOut(const Container& ps)
73 {
74 for (const auto& p : ps) {
75 setOut(p);
76 }
77 }
78
80 [[nodiscard]] auto isIn(const Voxel& v) const -> bool;
82 [[nodiscard]] auto isOut(const Voxel& v) const -> bool;
83
85 [[nodiscard]] auto isIn(const cv::Vec3d& v) const -> bool;
87 [[nodiscard]] auto isOut(const cv::Vec3d& v) const -> bool;
88
90 auto begin() noexcept -> iterator;
92 [[nodiscard]] auto begin() const noexcept -> const_iterator;
94 [[nodiscard]] auto cbegin() const noexcept -> const_iterator;
95
97 auto end() noexcept -> iterator;
99 [[nodiscard]] auto end() const noexcept -> const_iterator;
101 [[nodiscard]] auto cend() const noexcept -> const_iterator;
102
104 void clear();
105
107 [[nodiscard]] auto empty() const -> bool;
108
110 [[nodiscard]] auto as_vector() const -> std::vector<Voxel>;
111
112private:
115};
116
117} // namespace volcart
Stores per-voxel mask information for a volume.
auto as_vector() const -> std::vector< Voxel >
Get the list of masked points as a vector.
void setIn(const Container &ps)
Add Voxels to mask.
void setOut(const Voxel &v)
Remove Voxel from mask.
auto isIn(const Voxel &v) const -> bool
Check whether a Voxel is in the mask.
std::shared_ptr< VolumetricMask > Pointer
auto isOut(const Voxel &v) const -> bool
Check whether a Voxel is not in the mask.
auto cend() const noexcept -> const_iterator
Get a const-iterator to one past the last element in the mask.
auto isOut(const cv::Vec3d &v) const -> bool
Check whether a sub-voxel is not in the mask.
void setOut(const Container &ps)
Remove Voxels from the mask.
void clear()
Clear the mask of all voxels.
void setIn(const Voxel &v)
Add Voxel to mask.
VolumetricMask()=default
Default constructor.
VolumetricMask(const Container &ps)
Constructor with existing Voxel container.
auto end() noexcept -> iterator
Get a const-iterator to one past the last element in the mask.
auto cbegin() const noexcept -> const_iterator
Get a const-iterator to the first element in the mask.
static auto New(Args... args) -> Pointer
auto empty() const -> bool
Check if mask is empty.
std::unordered_set< Voxel, Vec3iHash > MaskSet
auto begin() noexcept -> iterator
Get a const-iterator to the first element in the mask.
MaskSet::iterator iterator
auto isIn(const cv::Vec3d &v) const -> bool
Check whether a sub-voxel is in the mask.
MaskSet::const_iterator const_iterator
Volume Cartographer library