23#ifndef VCL_MESH_CONTAINERS_FACE_CONTAINER_H
24#define VCL_MESH_CONTAINERS_FACE_CONTAINER_H
26#include "base/element_container.h"
28#include <vclib/mesh/elem_algorithms.h>
29#include <vclib/mesh/elements/face.h>
30#include <vclib/mesh/elements/face_components.h>
32#include <vclib/algorithms/core.h>
53template<FaceConcept T>
56 template<FaceConcept U>
65 using FaceIterator = Base::ElementIterator;
66 using ConstFaceIterator = Base::ConstElementIterator;
83 const FaceType&
face(
uint i)
const {
return Base::element(
i); }
138 template<
typename... V>
144 constexpr uint n =
sizeof...(args);
146 if constexpr (T::VERTEX_NUMBER < 0) {
151 n == T::VERTEX_NUMBER,
152 "Wrong number of vertices in Mesh::addFace.");
155 addFaceHelper(f, args...);
160 uint
addFace(Rng&& r)
requires (
161 InputRange<Rng, typename Face::VertexType*> || InputRange<Rng, uint>)
163 auto begin = std::ranges::begin(r);
164 auto end = std::ranges::end(r);
168 uint n = std::distance(begin, end);
176 if constexpr (T::VERTEX_NUMBER < 0) {
178 face(fid).resizeVertices(n);
181 assert(n == T::VERTEX_NUMBER);
182 if (n == T::VERTEX_NUMBER)
190 for (
auto it = begin; it != end; ++it) {
317 void deleteFace(
const FaceType* f) { Base::deleteElement(f); }
334 return Base::elementIndexIfCompact(
i);
350 return Base::elementCompactIndices();
402 FaceIterator
faceEnd() {
return Base::elementEnd(); }
424 ConstFaceIterator
faceEnd()
const {
return Base::elementEnd(); }
476 return Base::elements(begin, end);
532 return Base::elements(begin, end);
541 Base::enableAllOptionalComponents();
550 Base::disableAllOptionalComponents();
564 requires face::HasOptionalAdjacentEdges<T>
567 typename T::AdjacentEdges>();
593 requires face::HasOptionalAdjacentEdges<T>
609 requires face::HasOptionalAdjacentFaces<T>
612 typename T::AdjacentFaces>();
638 requires face::HasOptionalAdjacentFaces<T>
766 requires face::HasOptionalPrincipalCurvature<T>
769 typename T::PrincipalCurvature>();
779 requires face::HasOptionalPrincipalCurvature<T>
782 typename T::PrincipalCurvature>();
792 requires face::HasOptionalPrincipalCurvature<T>
795 typename T::PrincipalCurvature>();
846 requires face::HasOptionalWedgeColors<T>
849 typename T::WedgeColors>();
890 requires face::HasOptionalWedgeTexCoords<T>
893 typename T::WedgeTexCoords>();
908 requires face::HasOptionalWedgeTexCoords<T>
920 requires face::HasOptionalWedgeTexCoords<T>
942 return Base::hasElemCustomComponent(name);
958 return Base::elemCustomComponentNames();
1011 return Base::elemComponentType(name);
1033 template<
typename K>
1050 template<
typename K>
1072 Base::deleteElemCustomComponent(name);
1116 template<
typename K>
1164 template<
typename K>
1181 template<
typename K>
1198 template<
typename K>
1212 template<
typename OthMesh>
1216 using VertexType = ParentMesh::VertexType;
1229 !(FaceType::VERTEX_NUMBER != 3 && FaceType::VERTEX_NUMBER > 0 &&
1230 FaceType::VERTEX_NUMBER != MFaceType::VERTEX_NUMBER),
1231 "Cannot import from that type of Mesh. Don't know how to "
1238 FaceType::VERTEX_NUMBER == 3 &&
1239 (MFaceType::VERTEX_NUMBER > 3 || MFaceType::VERTEX_NUMBER < 0)) {
1240 VertexType* base = &Base::mParentMesh->
vertex(0);
1249 if (
mf.vertexNumber() != FaceType::VERTEX_NUMBER) {
1253 std::vector<uint>
tris =
1254 earCut(
mf.vertices() | views::positions);
1255 FaceType& f =
face(
m.index(
mf));
1274 void addFaceHelper(T& f) { }
1276 template<
typename... V>
1277 void addFaceHelper(T& f,
typename T::VertexType* v, V...
args)
1280 const std::size_t
n = f.vertexNumber() -
sizeof...(args) - 1;
1283 addFaceHelper(f,
args...);
1286 template<
typename... V>
1287 void addFaceHelper(T& f, uint vid, V... args)
1290 const std::size_t n = f.vertexNumber() -
sizeof...(args) - 1;
1291 f.setVertex(n, vid);
1293 addFaceHelper(f, args...);
1296 template<
typename MFaceType,
typename VertexType,
typename MVertexType>
1297 static void importTriPointersHelper(
1299 const MFaceType& mf,
1301 const MVertexType* mvbase,
1302 const std::vector<uint>& tris,
1306 for (uint i = basetri, j = 0; i < basetri + 3; i++, j++) {
1307 f.setVertex(j, base + (mf.vertex(tris[i]) - mvbase));
1311 face::HasWedgeColors<FaceType> &&
1312 face::HasWedgeColors<MFaceType>) {
1313 if (comp::isWedgeColorsAvailableOn(f) &&
1314 comp::isWedgeColorsAvailableOn(mf)) {
1315 f.wedgeColor(j) = mf.wedgeColor(tris[i]);
1321 face::HasWedgeTexCoords<FaceType> &&
1322 face::HasWedgeTexCoords<MFaceType>) {
1323 if (comp::isWedgeTexCoordsAvailableOn(f) &&
1324 comp::isWedgeTexCoordsAvailableOn(mf)) {
1325 using ST =
typename FaceType::WedgeTexCoordType::ScalarType;
1326 f.wedgeTexCoord(j) =
1327 mf.wedgeTexCoord(tris[i]).template cast<ST>();
1350 std::remove_cvref_t<T>,
1351 FaceContainer<typename RemoveRef<T>::FaceType>>;
1388template<
typename... Args>
A class representing a box in N-dimensional space.
Definition box.h:46
PointT size() const
Computes the size of the box.
Definition box.h:267
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:48
void resizeVertices(uint n)
Resize the number of Vertex Pointers of the Face, taking care of updating also the other components o...
Definition face.h:132
The FaceContainer class represents a container of Face elements that can be used in a Mesh class.
Definition face_container.h:55
FaceType & face(uint i)
Returns a reference of the Face at the i-th position in the Face Container of the Mesh,...
Definition face_container.h:95
void disablePerFacePrincipalCurvature()
Disables the Optional PrincipalCurvature of the Face.
Definition face_container.h:791
ConstFaceIterator faceEnd() const
Returns a const iterator to the end of the container.
Definition face_container.h:424
void enablePerFaceQuality()
Enable the Optional Quality of the Face.
Definition face_container.h:819
FaceIterator faceBegin(bool jumpDeleted=true)
Returns an iterator to the beginning of the container.
Definition face_container.h:393
void disablePerFaceAdjacentEdges()
Disables the Optional AdjacentEdges of the Face.
Definition face_container.h:592
std::vector< std::string > perFaceCustomComponentNames() const
Returns a vector containing all the names of the custom components of any type associated to the Face...
Definition face_container.h:955
bool isPerFaceMarkEnabled() const
Checks if the Face Optional Mark is enabled.
Definition face_container.h:690
bool isPerFaceAdjacentFacesEnabled() const
Checks if the Face Optional AdjacentFaces is enabled.
Definition face_container.h:608
void disablePerFaceAdjacentFaces()
Disables the Optional AdjacentFaces of the Face.
Definition face_container.h:637
FaceIterator faceEnd()
Returns an iterator to the end of the container.
Definition face_container.h:402
bool isPerFaceWedgeColorsEnabled() const
Checks if the Face Optional WedgeColors is enabled.
Definition face_container.h:845
void disablePerFaceQuality()
Disables the Optional Quality of the Face.
Definition face_container.h:830
CustomComponentVectorHandle< K > perFaceCustomComponentVectorHandle(const std::string &name)
Returns a vector handle to the custom component having the type K and the given name.
Definition face_container.h:1117
void enablePerFacePrincipalCurvature()
Enable the Optional PrincipalCurvature of the Face.
Definition face_container.h:778
bool isPerFacePrincipalCurvatureEnabled() const
Checks if the Face Optional PrincipalCurvature is enabled.
Definition face_container.h:765
uint faceContainerSize() const
Returns the number of Faces (also deleted) contained in the Face container of the Mesh.
Definition face_container.h:117
std::vector< uint > faceCompactIndices() const
Returns a vector that tells, for each actual Face index, the new index that the Face would have in a ...
Definition face_container.h:348
auto faces(bool jumpDeleted=true) const
Returns a small view object that allows to iterate over the Faces of the containers,...
Definition face_container.h:501
bool hasPerFaceCustomComponent(const std::string &name) const
Checks if Faces have a custom component with the given name.
Definition face_container.h:939
void disablePerFaceWedgeTexCoords()
Disables the Optional WedgeTexCoords of the Face.
Definition face_container.h:919
void enablePerFaceColor()
Enable the Optional Color of the Face.
Definition face_container.h:664
void addPerFaceCustomComponent(const std::string &name)
Adds a custom component of type K to the Face, having the given name.
Definition face_container.h:1051
auto faces(bool jumpDeleted=true)
Returns a small view object that allows to iterate over the Faces of the containers,...
Definition face_container.h:448
FaceContainer()=default
Empty constructor that creates an empty container of Faces.
void clearFaces()
Clears the Face container of the Mesh, deleting all the Faces.
Definition face_container.h:230
void disableAllPerFaceOptionalComponents()
Disables all the optional components associated to the Face type contained in the FaceContainer.
Definition face_container.h:548
bool isPerFaceQualityEnabled() const
Checks if the Face Optional Quality is enabled.
Definition face_container.h:808
void disablePerFaceMark()
Disables the Optional Mark of the Face.
Definition face_container.h:712
bool isPerFaceNormalEnabled() const
Checks if the Face Optional Normal is enabled.
Definition face_container.h:727
void deserializePerFaceCustomComponentsOfType(std::istream &is)
Deserializes in the given input stream all the custom components of the Face Element of type K.
Definition face_container.h:1199
auto faces(uint begin, uint end=UINT_NULL) const
Returns a view object that allows to iterate over the Faces of the container in the given range:
Definition face_container.h:530
void reserveFaces(uint n)
Reserve a number of Faces in the container of Faces. This is useful when you know (or you have an ide...
Definition face_container.h:280
uint deletedFaceNumber() const
Returns the number of deleted Faces in the Face container, that is faceContainerSize() - faceNumber()...
Definition face_container.h:125
void deleteFace(const FaceType *f)
Marks as deleted the given Face, before asserting that the Face belongs to this container.
Definition face_container.h:317
std::vector< std::string > perFaceCustomComponentNamesOfType() const
Returns a vector containing all the names of the custom components associated to the Edge Element hav...
Definition face_container.h:1034
void deleteFace(uint i)
Marks as deleted the Face with the given id.
Definition face_container.h:302
void disablePerFaceColor()
Disables the Optional Color of the Face.
Definition face_container.h:675
auto faces(uint begin, uint end=UINT_NULL)
Returns a view object that allows to iterate over the Faces of the container in the given range:
Definition face_container.h:474
bool isPerFaceCustomComponentOfType(const std::string &name) const
Checks if the custom component of the Face Element having the given name has the same type of the giv...
Definition face_container.h:987
void enablePerFaceNormal()
Enable the Optional Normal of the Face.
Definition face_container.h:738
void disablePerFaceWedgeColors()
Disables the Optional WedgeColors of the Face.
Definition face_container.h:874
bool isPerFaceWedgeTexCoordsEnabled() const
Checks if the Face Optional WedgeTexCoords is enabled.
Definition face_container.h:889
void deletePerFaceCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Face Element.
Definition face_container.h:1069
void disablePerFaceNormal()
Disables the Optional Normal of the Face.
Definition face_container.h:749
ConstCustomComponentVectorHandle< K > perFaceCustomComponentVectorHandle(const std::string &name) const
Returns a const vector handle to the custom component having type K and the given name.
Definition face_container.h:1165
void compactFaces()
Compacts the FaceContainer, removing all the Faces marked as deleted. Faces indices will change accor...
Definition face_container.h:288
std::type_index perFaceCustomComponentType(const std::string &name) const
Returns the std::type_index of the custom component of the Face Element having the given input name.
Definition face_container.h:1008
ConstFaceIterator faceBegin(bool jumpDeleted=true) const
Returns a const iterator to the beginning of the container.
Definition face_container.h:415
void enablePerFaceWedgeTexCoords()
Enable the Optional WedgeTexCoords of the Face.
Definition face_container.h:907
void enablePerFaceAdjacentFaces()
Enable the Optional AdjacentFaces of the Face.
Definition face_container.h:626
uint faceNumber() const
Returns the number of non-deleted Faces contained in the Face container of the Mesh.
Definition face_container.h:106
void manageImportTriFromPoly(const OthMesh &m)
This function manages the case where we try to import into a TriMesh a PolyMesh Faces have been alrea...
Definition face_container.h:1213
void enablePerFaceWedgeColors()
Enable the Optional WedgeColors of the Face.
Definition face_container.h:863
uint addFaces(uint n)
Add an arbitrary number of n Faces, returning the id of the first added Face.
Definition face_container.h:212
uint faceIndexIfCompact(uint i) const
This is an utility member function that returns the index of an element if the container would be com...
Definition face_container.h:332
void enablePerFaceMark()
Enable the Optional Mark of the Face.
Definition face_container.h:701
uint addFace()
Add a Face to the container, returning its index.
Definition face_container.h:136
void updateFaceIndices(const std::vector< uint > &newIndices)
Updates all the indices and pointers of the Faces of this container that are stored in any container ...
Definition face_container.h:377
bool isPerFaceAdjacentEdgesEnabled() const
Checks if the Face Optional AdjacentEdges is enabled.
Definition face_container.h:563
void enablePerFaceAdjacentEdges()
Enable the Optional AdjacentEdges of the Face.
Definition face_container.h:581
void enableAllPerFaceOptionalComponents()
Enables all the optional components associated to the Face type contained in the FaceContainer.
Definition face_container.h:539
bool isPerFaceColorEnabled() const
Checks if the Face Optional Color is enabled.
Definition face_container.h:653
const FaceType & face(uint i) const
Returns a const reference of the Face at the i-th position in the Face Container of the Mesh,...
Definition face_container.h:83
void serializePerFaceCustomComponentsOfType(std::ostream &os) const
Serializes in the given output stream all the custom components of the Face Element of type K.
Definition face_container.h:1182
void resizeFaces(uint n)
Resizes the Face container to contain n Faces.
Definition face_container.h:260
The Vertex Container class, will be used when the template argument given to the Mesh is a Vertex.
Definition vertex_container.h:52
const VertexType & vertex(uint i) const
Returns a const reference of the vertex at the i-th position in the Vertex Container of the Mesh,...
Definition vertex_container.h:81
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:1389
Definition face_components.h:82
Definition mesh_components.h:52
A concept that checks whether a class has (inherits from) an FaceContainer class.
Definition face_container.h:1349
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48
std::vector< uint > earCut(Iterator begin, Iterator end)
Triangulates a simple polygon with no holes using the ear-cutting algorithm.
Definition ear_cut.h:90