msl 1.3.0
Loading...
Searching...
No Matches
Mask.h
Go to the documentation of this file.
1// Copyright 2024-2025 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _a4690364_ec62_4b06_aebc_5b4dc3f92f29
5#define _a4690364_ec62_4b06_aebc_5b4dc3f92f29
6
7#include <vector>
8
9#include <boost/dynamic_bitset.hpp>
10
11#include "Vector.h"
12
13namespace msl
14{
15
17class Mask
18{
19public:
21 using Point = Vector2l;
23 using Shape = Vector2l;
24
26 using Points = std::vector<Point>;
27
29 static bool lessX(Point const & p, Point const & q) { return p[0] < q[0]; }
30
32 static bool lessKy(Point const & p, Point const & q) { return lessX(p, q); }
33
35 static bool lessY(Point const & p, Point const & q) { return p[1] < q[1]; }
36
38 static bool lessKz(Point const & p, Point const & q) { return lessY(p, q); }
39
41 Mask(Shape const & shape={}, bool value=true);
42
44 std::size_t size() const;
45
47 Shape const & shape() const;
48
50 std::size_t count() const;
51
53 Mask & enable(Point const & p);
54
56 Mask & disable(Point const & p);
57
59 bool enabled(Point const & p) const;
60
63
65 Mask & operator|=(Mask const & right);
66
68 Mask & operator&=(Mask const & right);
69
72
73protected:
74 Shape _shape;
75 boost::dynamic_bitset<> _mask;
76
78 std::size_t _index(Point const & p) const;
79};
80
82std::ostream & operator<<(std::ostream & stream, Mask const & mask);
83
86
88Mask operator&(Mask left, Mask const & right);
89
91Mask operator|(Mask left, Mask const & right);
92
93}
94
95#endif // _a4690364_ec62_4b06_aebc_5b4dc3f92f29
A two dimensional mask.
Definition Mask.h:18
std::vector< Point > Points
Container of Point.
Definition Mask.h:26
std::size_t size() const
Return the total number of points in the mask.
Mask & operator|=(Mask const &right)
In-place union of two masks.
Shape const & shape() const
Return the shape of the mask.
static bool lessX(Point const &p, Point const &q)
Compare points according to their x coordinate.
Definition Mask.h:29
Mask & enable(Point const &p)
Enable a point.
Mask(Shape const &shape={}, bool value=true)
Create a constant mask.
Mask & disable(Point const &p)
Disable a point.
Mask & operator&=(Mask const &right)
In-place intersection of two masks.
Mask & flip()
Switch the status of all points (enabled ↔ disabled)
Points enabledPoints() const
Return a vector of enabled points.
std::size_t count() const
Return the number of enabled points.
static bool lessKz(Point const &p, Point const &q)
Compare points according to their kz coordinate.
Definition Mask.h:38
static bool lessKy(Point const &p, Point const &q)
Compare points according to their ky coordinate.
Definition Mask.h:32
static bool lessY(Point const &p, Point const &q)
Compare points according to their y coordinate.
Definition Mask.h:35
bool enabled(Point const &p) const
Check whether the point is enabled.
Top-level namespace of the msl library.
Definition acceleration.h:17
Mask operator&(Mask left, Mask const &right)
Intersection of two masks.
Mask operator!(Mask mask)
Retrun a switched mask (enabled ↔ disabled)
Vector< 2, long > Vector2l
2D vector of longs
Definition Vector.h:117
std::ostream & operator<<(std::ostream &stream, Mask const &mask)
Visual representation of the mask.
Mask operator|(Mask left, Mask const &right)
Union of two masks.