msl 1.1.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
25 using Points = std::vector<Point>;
26
28 static bool lessX(Point const & p, Point const & q) { return p[0] < q[0]; }
29
31 static bool lessY(Point const & p, Point const & q) { return p[1] < q[1]; }
32
34 Mask(Shape const & shape={}, bool value=true);
35
37 std::size_t size() const;
38
40 Shape const & shape() const;
41
43 std::size_t count() const;
44
46 Mask & enable(Point const & p);
47
49 Mask & disable(Point const & p);
50
52 bool enabled(Point const & p) const;
53
56
58 Mask & operator|=(Mask const & right);
59
61 Mask & operator&=(Mask const & right);
62
65
66protected:
68 boost::dynamic_bitset<> _mask;
69
71 std::size_t _index(Point const & p) const;
72};
73
76
78Mask operator&(Mask left, Mask const & right);
79
81Mask operator|(Mask left, Mask const & right);
82
83}
84
85#endif // _a4690364_ec62_4b06_aebc_5b4dc3f92f29
A two dimensional mask.
Definition Mask.h:18
std::vector< Point > Points
Definition Mask.h:25
std::size_t size() const
Return the total number of points in the mask.
Shape _shape
Definition Mask.h:67
Mask & operator|=(Mask const &right)
In-place union of two masks.
Vector2l Point
2D point, as (column, row)
Definition Mask.h:21
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:28
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.
Vector2l Shape
Shape of the mask, as (column, row)
Definition Mask.h:23
boost::dynamic_bitset _mask
Definition Mask.h:68
std::size_t count() const
Return the number of enabled points.
std::size_t _index(Point const &p) const
Return the linear index corresponding to a point.
static bool lessY(Point const &p, Point const &q)
Compare points according to their y coordinate.
Definition Mask.h:31
bool enabled(Point const &p) const
Check whether the point is enabled.
Definition acceleration.h:17
Vector< 2, long > Vector2l
2D vector of longs
Definition Vector.h:104
Mask operator&(Mask left, Mask const &right)
Intersection of two masks.
Mask operator!(Mask mask)
Retrun a switched mask (enabled ↔ disabled)
Mask operator|(Mask left, Mask const &right)
Union of two masks.