Visual Computing Library
All Classes Functions Variables Typedefs Enumerations Friends Modules Pages Concepts
mark.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_MESH_COMPONENTS_MARK_H
24#define VCL_MESH_COMPONENTS_MARK_H
25
26#include "bases/component.h"
27
28#include <vclib/concepts/mesh/components/mark.h>
29#include <vclib/io/serialization.h>
30
31namespace vcl::comp {
32
81template<typename ParentElemType = void, bool OPT = false>
82class Mark :
83 public Component<
84 Mark<ParentElemType, OPT>,
85 CompId::MARK,
86 int,
87 ParentElemType,
88 !std::is_same_v<ParentElemType, void>,
89 OPT>
90{
91 using Base = Component<
93 CompId::MARK,
94 int,
96 !std::is_same_v<ParentElemType, void>,
97 OPT>;
98
99public:
100 /* Constructors */
101
106 {
107 if constexpr (!Base::IS_VERTICAL) {
108 init();
109 }
110 }
111
122 void init() { markRef() = 0; }
123
124 /* Member functions */
125
130 int mark() const { return Base::data(); }
131
135 void resetMark() { markRef() = 0; }
136
144 template<typename E>
145 bool hasSameMark(const E& e) const
146 {
147 if constexpr (std::is_pointer<E>::value) {
148 return e->mark() == mark();
149 }
150 else {
151 return e.mark() == mark();
152 }
153 }
154
158 void incrementMark() { markRef()++; }
159
163 void decrementMark() { markRef()--; }
164
165protected:
166 // Component interface function
167 template<typename Element>
168 void importFrom(const Element& e, bool = true)
169 {
170 if constexpr (HasMark<Element>) {
171 if (isMarkAvailableOn(e)) {
172 markRef() = e.mark();
173 }
174 }
175 }
176
177 void serialize(std::ostream& os) const { vcl::serialize(os, mark()); }
178
179 void deserialize(std::istream& is) { vcl::deserialize(is, markRef()); }
180
181private:
182 int& markRef() { return Base::data(); }
183};
184
185/* Detector function to check if a class has Mark available */
186
199bool isMarkAvailableOn(const ElementOrMeshConcept auto& element)
200{
201 return isComponentAvailableOn<CompId::MARK>(element);
202}
203
204} // namespace vcl::comp
205
206#endif // VCL_MESH_COMPONENTS_MARK_H
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The Mark class is an utility class useful to un-mark components in constant time.
Definition mark.h:90
void incrementMark()
Increments the mark of the current element/mesh by 1.
Definition mark.h:158
bool hasSameMark(const E &e) const
Checks if the current element/mesh has the same mark of the given input element/mesh e.
Definition mark.h:145
void decrementMark()
Decrements the mark of the current element/mesh by 1.
Definition mark.h:163
void init()
Initializes the mark to 0.
Definition mark.h:122
void resetMark()
Resets the mark to 0.
Definition mark.h:135
int mark() const
Returns the value of the mark.
Definition mark.h:130
Mark()
Constructor that initializes the mark to 0.
Definition mark.h:105
HasMark concept is satisfied only if a Element/Mesh class provides the types and member functions spe...
Definition mark.h:47