23#ifndef VCL_MESH_CONTAINERS_FACE_CONTAINER_H
24#define VCL_MESH_CONTAINERS_FACE_CONTAINER_H
26#include "element_container.h"
28#include <vclib/algorithms/core/polygon/ear_cut.h>
29#include <vclib/mesh/containers/custom_component_vector_handle.h>
30#include <vclib/mesh/elements/face.h>
31#include <vclib/mesh/elements/face_components.h>
32#include <vclib/views/mesh.h>
52template<FaceConcept T>
55 template<FaceConcept U>
64 using FaceIterator = Base::ElementIterator;
65 using ConstFaceIterator = Base::ConstElementIterator;
82 const FaceType&
face(
uint i)
const {
return Base::element(
i); }
137 template<
typename... V>
143 constexpr uint n =
sizeof...(args);
145 if constexpr (T::VERTEX_NUMBER < 0) {
150 n == T::VERTEX_NUMBER,
151 "Wrong number of vertices in Mesh::addFace.");
154 addFaceHelper(f, args...);
159 uint
addFace(Rng&& r)
requires (
160 InputRange<Rng, typename Face::VertexType*> || InputRange<Rng, uint>)
162 auto begin = std::ranges::begin(r);
163 auto end = std::ranges::end(r);
167 uint n = std::distance(begin, end);
175 if constexpr (T::VERTEX_NUMBER < 0) {
177 face(fid).resizeVertices(n);
180 assert(n == T::VERTEX_NUMBER);
181 if (n == T::VERTEX_NUMBER)
189 for (
auto it = begin; it != end; ++it) {
316 void deleteFace(
const FaceType* f) { Base::deleteElement(f); }
333 return Base::elementIndexIfCompact(
i);
349 return Base::elementCompactIndices();
401 FaceIterator
faceEnd() {
return Base::elementEnd(); }
423 ConstFaceIterator
faceEnd()
const {
return Base::elementEnd(); }
482 Base::enableAllOptionalComponents();
491 Base::disableAllOptionalComponents();
505 requires face::HasOptionalAdjacentEdges<T>
508 typename T::AdjacentEdges>();
534 requires face::HasOptionalAdjacentEdges<T>
550 requires face::HasOptionalAdjacentFaces<T>
553 typename T::AdjacentFaces>();
579 requires face::HasOptionalAdjacentFaces<T>
707 requires face::HasOptionalPrincipalCurvature<T>
710 typename T::PrincipalCurvature>();
720 requires face::HasOptionalPrincipalCurvature<T>
723 typename T::PrincipalCurvature>();
733 requires face::HasOptionalPrincipalCurvature<T>
736 typename T::PrincipalCurvature>();
787 requires face::HasOptionalWedgeColors<T>
790 typename T::WedgeColors>();
831 requires face::HasOptionalWedgeTexCoords<T>
834 typename T::WedgeTexCoords>();
849 requires face::HasOptionalWedgeTexCoords<T>
861 requires face::HasOptionalWedgeTexCoords<T>
883 return Base::hasElemCustomComponent(name);
899 return Base::elemCustomComponentNames();
952 return Base::elemComponentType(name);
1013 Base::deleteElemCustomComponent(name);
1057 template<
typename K>
1105 template<
typename K>
1119 template<
typename OthMesh>
1124 using VertexType = ParentMesh::VertexType;
1138 !(FaceType::VERTEX_NUMBER != 3 && FaceType::VERTEX_NUMBER > 0 &&
1139 FaceType::VERTEX_NUMBER != MFaceType::VERTEX_NUMBER),
1140 "Cannot import from that type of Mesh. Don't know how to "
1147 FaceType::VERTEX_NUMBER == 3 &&
1148 (MFaceType::VERTEX_NUMBER > 3 ||
1149 MFaceType::VERTEX_NUMBER < 0)) {
1150 VertexType*
base = &Base::mParentMesh->vertex(0);
1159 if (
mf.vertexNumber() != FaceType::VERTEX_NUMBER) {
1164 std::vector<uint>
tris =
1165 earCut(
mf.vertices() | views::coords);
1166 FaceType& f =
face(
m.index(
mf));
1176 importTriPointersHelper(
1187 void addFaceHelper(T& f) { }
1189 template<
typename... V>
1190 void addFaceHelper(T& f,
typename T::VertexType* v, V...
args)
1193 const std::size_t
n = f.vertexNumber() -
sizeof...(args) - 1;
1196 addFaceHelper(f,
args...);
1199 template<
typename... V>
1200 void addFaceHelper(T& f, uint vid, V... args)
1203 const std::size_t n = f.vertexNumber() -
sizeof...(args) - 1;
1204 f.setVertex(n, vid);
1206 addFaceHelper(f, args...);
1209 template<
typename MFaceType,
typename VertexType,
typename MVertexType>
1210 static void importTriPointersHelper(
1212 const MFaceType& mf,
1214 const MVertexType* mvbase,
1215 const std::vector<uint>& tris,
1219 for (uint i = basetri, j = 0; i < basetri + 3; i++, j++) {
1220 f.setVertex(j, base + (mf.vertex(tris[i]) - mvbase));
1224 face::HasWedgeColors<FaceType> &&
1225 face::HasWedgeColors<MFaceType>) {
1226 if (comp::isWedgeColorsAvailableOn(f) &&
1227 comp::isWedgeColorsAvailableOn(mf)) {
1228 f.wedgeColor(j) = mf.wedgeColor(tris[i]);
1234 face::HasWedgeTexCoords<FaceType> &&
1235 face::HasWedgeTexCoords<MFaceType>) {
1236 if (comp::isWedgeTexCoordsAvailableOn(f) &&
1237 comp::isWedgeTexCoordsAvailableOn(mf)) {
1238 using ST =
typename FaceType::WedgeTexCoordType::ScalarType;
1239 f.wedgeTexCoord(j) =
1240 mf.wedgeTexCoord(tris[i]).template cast<ST>();
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:49
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:135
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The FaceContainer class represents a container of Face elements that can be used in a Mesh class.
Definition face_container.h:54
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:94
void disablePerFacePrincipalCurvature()
Disables the Optional PrincipalCurvature of the Face.
Definition face_container.h:732
ConstFaceIterator faceEnd() const
Returns a const iterator to the end of the container.
Definition face_container.h:423
void enablePerFaceQuality()
Enable the Optional Quality of the Face.
Definition face_container.h:760
FaceIterator faceBegin(bool jumpDeleted=true)
Returns an iterator to the beginning of the container.
Definition face_container.h:392
void disablePerFaceAdjacentEdges()
Disables the Optional AdjacentEdges of the Face.
Definition face_container.h:533
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:896
bool isPerFaceMarkEnabled() const
Checks if the Face Optional Mark is enabled.
Definition face_container.h:631
bool isPerFaceAdjacentFacesEnabled() const
Checks if the Face Optional AdjacentFaces is enabled.
Definition face_container.h:549
void disablePerFaceAdjacentFaces()
Disables the Optional AdjacentFaces of the Face.
Definition face_container.h:578
FaceIterator faceEnd()
Returns an iterator to the end of the container.
Definition face_container.h:401
bool isPerFaceWedgeColorsEnabled() const
Checks if the Face Optional WedgeColors is enabled.
Definition face_container.h:786
void disablePerFaceQuality()
Disables the Optional Quality of the Face.
Definition face_container.h:771
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:1058
void enablePerFacePrincipalCurvature()
Enable the Optional PrincipalCurvature of the Face.
Definition face_container.h:719
bool isPerFacePrincipalCurvatureEnabled() const
Checks if the Face Optional PrincipalCurvature is enabled.
Definition face_container.h:706
uint faceContainerSize() const
Returns the number of Faces (also deleted) contained in the Face container of the Mesh.
Definition face_container.h:116
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:347
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:471
bool hasPerFaceCustomComponent(const std::string &name) const
Checks if Faces have a custom component with the given name.
Definition face_container.h:880
void disablePerFaceWedgeTexCoords()
Disables the Optional WedgeTexCoords of the Face.
Definition face_container.h:860
void enablePerFaceColor()
Enable the Optional Color of the Face.
Definition face_container.h:605
void addPerFaceCustomComponent(const std::string &name)
Adds a custom component of type K to the Face, having the given name.
Definition face_container.h:992
auto faces(bool jumpDeleted=true)
Returns a small view object that allows to iterate over the Faces of the containers,...
Definition face_container.h:447
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:229
void disableAllPerFaceOptionalComponents()
Disables all the optional components associated to the Face type contained in the FaceContainer.
Definition face_container.h:489
bool isPerFaceQualityEnabled() const
Checks if the Face Optional Quality is enabled.
Definition face_container.h:749
void disablePerFaceMark()
Disables the Optional Mark of the Face.
Definition face_container.h:653
bool isPerFaceNormalEnabled() const
Checks if the Face Optional Normal is enabled.
Definition face_container.h:668
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:279
uint deletedFaceNumber() const
Returns the number of deleted Faces in the Face container, that is faceContainerSize() - faceNumber()...
Definition face_container.h:124
void deleteFace(const FaceType *f)
Marks as deleted the given Face, before asserting that the Face belongs to this container.
Definition face_container.h:316
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:975
void deleteFace(uint i)
Marks as deleted the Face with the given id.
Definition face_container.h:301
void disablePerFaceColor()
Disables the Optional Color of the Face.
Definition face_container.h:616
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:928
void enablePerFaceNormal()
Enable the Optional Normal of the Face.
Definition face_container.h:679
void disablePerFaceWedgeColors()
Disables the Optional WedgeColors of the Face.
Definition face_container.h:815
bool isPerFaceWedgeTexCoordsEnabled() const
Checks if the Face Optional WedgeTexCoords is enabled.
Definition face_container.h:830
void deletePerFaceCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Face Element.
Definition face_container.h:1010
void disablePerFaceNormal()
Disables the Optional Normal of the Face.
Definition face_container.h:690
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:1106
void compactFaces()
Compacts the FaceContainer, removing all the Faces marked as deleted. Faces indices will change accor...
Definition face_container.h:287
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:949
ConstFaceIterator faceBegin(bool jumpDeleted=true) const
Returns a const iterator to the beginning of the container.
Definition face_container.h:414
void enablePerFaceWedgeTexCoords()
Enable the Optional WedgeTexCoords of the Face.
Definition face_container.h:848
void enablePerFaceAdjacentFaces()
Enable the Optional AdjacentFaces of the Face.
Definition face_container.h:567
uint faceNumber() const
Returns the number of non-deleted Faces contained in the Face container of the Mesh.
Definition face_container.h:105
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:1120
void enablePerFaceWedgeColors()
Enable the Optional WedgeColors of the Face.
Definition face_container.h:804
uint addFaces(uint n)
Add an arbitrary number of n Faces, returning the id of the first added Face.
Definition face_container.h:211
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:331
void enablePerFaceMark()
Enable the Optional Mark of the Face.
Definition face_container.h:642
uint addFace()
Add a Face to the container, returning its index.
Definition face_container.h:135
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:376
bool isPerFaceAdjacentEdgesEnabled() const
Checks if the Face Optional AdjacentEdges is enabled.
Definition face_container.h:504
void enablePerFaceAdjacentEdges()
Enable the Optional AdjacentEdges of the Face.
Definition face_container.h:522
void enableAllPerFaceOptionalComponents()
Enables all the optional components associated to the Face type contained in the FaceContainer.
Definition face_container.h:480
bool isPerFaceColorEnabled() const
Checks if the Face Optional Color is enabled.
Definition face_container.h:594
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:82
void resizeFaces(uint n)
Resizes the Face container to contain n Faces.
Definition face_container.h:259
The Vertex Container class, will be used when the template argument given to the Mesh is a Vertex.
Definition vertex_container.h:51
The HasFaceContainer concept is satisfied only if a container class provides the types and member fun...
Definition face_container.h:44
std::vector< uint > earCut(Iterator begin, Iterator end)
Triangulates a simple polygon with no holes using the ear-cutting algorithm.
Definition ear_cut.h:92
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