23#ifndef VCL_MESH_COMPONENTS_BASES_COMPONENT_H
24#define VCL_MESH_COMPONENTS_BASES_COMPONENT_H
26#include "../detail/component_data.h"
28#include <vclib/concepts/mesh/components/component.h>
29#include <vclib/concepts/mesh/elements/element.h>
30#include <vclib/concepts/mesh/mesh_concept.h>
118 typename DerivedComponent,
121 typename ParentElemType,
124 typename... ReferencedTypes>
125class Component :
public ReferencesComponentTriggerer<ReferencedTypes>...
132 using DataValueType = DataType;
138 static const bool IS_VERTICAL =
139 !std::is_same_v<ParentElemType, void> && VERT;
144 static const uint COMPONENT_ID = COMP_ID;
150 static const bool IS_OPTIONAL = VERT && OPT;
153 detail::ComponentData<DataValueType, IS_VERTICAL> mData;
167 bool isAvailable()
const
169 return mData.template isComponentAvailable<ParentElemType>(
170 static_cast<const DerivedComponent*
>(
this));
174 DataValueType& data()
176 return mData.template get<ParentElemType>(
177 static_cast<DerivedComponent*
>(
this));
180 const DataValueType& data()
const
182 return mData.template get<ParentElemType>(
183 static_cast<const DerivedComponent*
>(
this));
186 ParentElemType* parentElement()
189 !std::is_same_v<ParentElemType, void>,
190 "The component should know its parent element type to get access "
191 "to its pointer. You should define the component by passing the "
192 "element type as template parameter. E.G., for a Face element:\n"
193 "vcl::face::TriangleVertexPtrs<Vertex<Scalar>, Face<Scalar>>\n"
196 return static_cast<ParentElemType*
>(
this);
199 const ParentElemType* parentElement()
const
202 !std::is_same_v<ParentElemType, void>,
203 "The component should know its parent element type to get access "
204 "to its pointer. You should define the component by passing the "
205 "element type as template parameter. E.G., for a Face element:\n"
206 "vcl::face::TriangleVertexPtrs<Vertex<Scalar>, Face<Scalar>>\n"
209 return static_cast<const ParentElemType*
>(
this);
226template<u
int COMPONENT_ID, ElementOrMeshConcept T>
227bool isComponentAvailableOn(
const T& obj)
229 if constexpr (HasOptionalComponentOfType<T, COMPONENT_ID>) {
230 using ComponentType =
231 ComponentOfType<COMPONENT_ID, typename T::Components>;
232 const ComponentType& c =
static_cast<const ComponentType&
>(obj);
233 return c.isAvailable();
236 return HasComponentOfType<T, COMPONENT_ID>;
246struct IsComponentPred
248 static const bool value = ComponentConcept<T>;
252struct IsVerticalComponentPred
254 static const bool value = IsVerticalComponent<T>;