23#ifndef VCL_MESH_COMPONENTS_POLYGON_BIT_FLAGS_H
24#define VCL_MESH_COMPONENTS_POLYGON_BIT_FLAGS_H
26#include "bases/container_component.h"
28#include <vclib/concepts/mesh/components/bit_flags.h>
29#include <vclib/space/core/bit_set.h>
97template<
int N,
typename ParentElemType =
void,
bool OPT = false>
100 PolygonBitFlags<N, ParentElemType, OPT>,
106 !std::is_same_v<ParentElemType, void>,
119 !std::is_same_v<ParentElemType, void>,
123 static const uint FIRST_USER_BIT = 6;
124 static const uint FIRST_EDGE_USER_BIT = 3;
136 enum { EDGEBORD = 0, EDGESEL = 1, EDGEVIS = 2 };
149 sizeof(
FT) * 8 - FIRST_EDGE_USER_BIT;
161 if constexpr (!Base::IS_VERTICAL) {
176 void init() { flags().reset(); }
184 bool deleted()
const {
return flags()[DELETED]; }
197 bool selected()
const {
return flags()[SELECTED]; }
210 bool visited()
const {
return flags()[VISITED]; }
220 for (uint
i = 0;
i < 12; ++
i)
235 assert(
i < edgeFlags().size());
236 return edgeFlags()[
i][EDGEBORD];
248 assert(
i < edgeFlags().size());
249 return edgeFlags()[
i][EDGEBORD];
261 assert(
i < edgeFlags().size());
262 return edgeFlags()[
i][EDGESEL];
274 assert(
i < edgeFlags().size());
275 return edgeFlags()[
i][EDGESEL];
286 assert(
i < edgeFlags().size());
287 return edgeFlags()[
i][EDGEVIS];
299 assert(
i < edgeFlags().size());
300 return edgeFlags()[
i][EDGEVIS];
318 return flags()[FAUX0 +
i];
336 return flags()[FAUX0 +
i];
351 return flags()[
bit + FIRST_USER_BIT];
365 return flags()[
bit + FIRST_USER_BIT];
380 return edgeFlags()[
i][
bit + FIRST_EDGE_USER_BIT];
395 return edgeFlags()[
i][
bit + FIRST_EDGE_USER_BIT];
406 for (uint
i = 0;
i < edgeFlags().size(); ++
i)
407 edgeFlags()[
i].reset();
479 void __polygonBitFlags()
const {}
485 template<
typename Element>
486 void importFrom(
const Element& e,
bool =
true)
488 if constexpr (HasBitFlags<Element>) {
490 if constexpr (HasPolygonBitFlags<Element>) {
492 edgeFlags() = e.edgeFlags();
496 deletedBit() = e.deleted();
500 for (uint i = 0; i < UM; ++i)
502 if constexpr (HasTriangleBitFlags<Element>) {
504 for (uint i = 0; i < 3; ++i) {
515 void serialize(std::ostream& os)
const
517 flags().serialize(os);
518 edgeFlags().serialize(os);
521 void deserialize(std::istream& is)
523 flags().deserialize(is);
524 edgeFlags().deserialize(is);
528 void resize(uint n)
requires (N < 0) { edgeFlags().resize(n); }
530 void pushBack(BitSet<FT> f = BitSet<FT>())
requires (N < 0)
532 edgeFlags().pushBack(f);
535 void insert(uint i, BitSet<FT> f = BitSet<FT>())
requires (N < 0)
537 edgeFlags().insert(i, f);
540 void erase(uint i)
requires (N < 0) { edgeFlags().erase(i); }
542 void clear()
requires (N < 0) { edgeFlags().clear(); }
548 BitSet<FT>& flags() {
return Base::additionalData(); }
550 const BitSet<FT>& flags()
const {
return Base::additionalData(); }
552 Vector<BitSet<FT>, -1>& edgeFlags() {
return Base::container(); }
554 const Vector<BitSet<FT>, -1>& edgeFlags()
const
556 return Base::container();
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The ContainerComponent class is the base class for all the components of VCLib that store a container...
Definition container_component.h:130
The PolygonBitFlags class represents a collection of 8 bits plus 8 bits for each edge that will be pa...
Definition polygon_bit_flags.h:109
bool onBorder() const
Returns whether the current Polygon is on border or not, by checking whether at least one of its edge...
Definition polygon_bit_flags.h:218
BitProxy< FT > edgeUserBit(uint i, uint bit)
Returns a reference to the value of the user bit of the i-th edge of this Polygon given in input....
Definition polygon_bit_flags.h:392
BitProxy< FT > edgeFaux(uint i)
Accesses the 'faux' bit of the i-th edge of the polygon, returning a reference to it.
Definition polygon_bit_flags.h:315
void importFlagsFromVCGFormat(int f)
Sets all the flags of this element to the values contained in the integer input parameter,...
Definition polygon_bit_flags.h:417
PolygonBitFlags()
Initializes all the bits to false.
Definition polygon_bit_flags.h:159
void init()
Initializes the bits to false.
Definition polygon_bit_flags.h:176
bool edgeOnBorder(uint i) const
Returns whether the i-th edge of the current Polygon is on border or not.
Definition polygon_bit_flags.h:246
bool edgeSelected(uint i) const
Returns whether the i-th edge of the current Polygon is selected or not.
Definition polygon_bit_flags.h:272
void resetBitFlags()
Unsets all the flags of this Polygon and sets them to false, except the deleted flag,...
Definition polygon_bit_flags.h:402
bool edgeVisited(uint i) const
Returns whether the i-th edge of the current Polygon has been visited or not.
Definition polygon_bit_flags.h:297
BitProxy< FT > visited()
Accesses the 'visited' bit of this Polygon, returning a reference to it.
Definition polygon_bit_flags.h:204
bool visited() const
Returns whether the current Polygon has been visited or not.
Definition polygon_bit_flags.h:210
bool edgeFaux(uint i) const
Returns whether the i-th edge of the current Polygon is faux or not.
Definition polygon_bit_flags.h:333
bool deleted() const
Returns whether the current Polygon is deleted or not.
Definition polygon_bit_flags.h:184
BitProxy< FT > edgeOnBorder(uint i)
Accesses the 'onBorder' bit of the i-th edge of the polygon, returning a reference to it.
Definition polygon_bit_flags.h:233
static const uint USER_BITS_NUMBER
Static number of bits that can have custom meanings to the user.
Definition polygon_bit_flags.h:142
BitProxy< FT > edgeVisited(uint i)
Accesses the 'visited' bit of the i-th edge of the polygon, returning a reference to it.
Definition polygon_bit_flags.h:284
static const uint EDGE_USER_BITS_NUMBER
Static number of bits for each edge that can have custom meanings to the user.
Definition polygon_bit_flags.h:148
int exportFlagsToVCGFormat() const
Returns the bit flags of this element in the format of the VCG library.
Definition polygon_bit_flags.h:450
BitProxy< FT > selected()
Accesses the 'selected' bit of this Polygon, returning a reference to it.
Definition polygon_bit_flags.h:191
bool edgeUserBit(uint i, uint bit) const
Returns the boolean value of the user bit of the i-th edge of this Polygon given in input....
Definition polygon_bit_flags.h:377
BitProxy< FT > edgeSelected(uint i)
Accesses the 'selected' bit of the i-th edge of the polygon, returning a reference to it.
Definition polygon_bit_flags.h:259
BitProxy< FT > userBit(uint bit)
Returns a reference to the value of the user bit of this Polygon given in input. The bit is checked t...
Definition polygon_bit_flags.h:362
bool userBit(uint bit) const
Returns the boolean value of the user bit of this Polygon given in input. The bit is checked to be le...
Definition polygon_bit_flags.h:348
bool selected() const
Returns whether the current Polygon is selected or not.
Definition polygon_bit_flags.h:197