23#ifndef VCL_SPACE_COMPLEX_MESH_INFO_H
24#define VCL_SPACE_COMPLEX_MESH_INFO_H
26#include <vclib/mesh/requirements.h>
27#include <vclib/types.h>
82 enum class MeshType { TRIANGLE_MESH, QUAD_MESH, POLYGON_MESH, UNKNOWN };
91 enum Element { VERTEX, FACE, EDGE, MESH, NUM_ELEMENTS };
129 std::bitset<NUM_ELEMENTS> mElements = {
false};
132 std::array<std::bitset<NUM_COMPONENTS>, NUM_ELEMENTS> mPerElemComponents = {
136 Eigen::Matrix<DataType, NUM_ELEMENTS, NUM_COMPONENTS>
137 mPerElemComponentsType;
140 std::array<std::vector<CustomComponent>, NUM_ELEMENTS>
141 mPerElemCustomComponents;
153 MeshInfo() { mPerElemComponentsType.fill(PrimitiveType::NONE); }
164 template<MeshConcept Mesh>
171 if (isPerVertexNormalAvailable(
m)) {
175 typename Mesh::VertexType::NormalType::ScalarType>());
179 if (isPerVertexColorAvailable(
m)) {
180 setVertexColors(
true, PrimitiveType::UCHAR);
184 if (isPerVertexQualityAvailable(
m)) {
190 if (isPerVertexTexCoordAvailable(
m)) {
194 typename Mesh::VertexType::TexCoordType::ScalarType>());
198 auto names =
m.perVertexCustomComponentNames();
199 for (
auto& name :
names) {
201 if (
dt != PrimitiveType::NONE) {
202 addVertexCustomComponent(name,
dt);
224 typename Mesh::FaceType::NormalType::ScalarType>());
229 setFaceColors(
true, PrimitiveType::UCHAR);
240 setFaceWedgeTexCoords(
242 getType<
typename Mesh::FaceType::WedgeTexCoordType::
247 auto names =
m.perFaceCustomComponentNames();
248 for (
auto& name :
names) {
250 if (
dt != PrimitiveType::NONE) {
251 addFaceCustomComponent(name,
dt);
266 if (
m.textureNumber() > 0) {
281 for (
auto& comp : mPerElemComponents)
283 mPerElemComponentsType.fill(PrimitiveType::NONE);
285 for (
auto& v : mPerElemCustomComponents)
288 mType = MeshType::UNKNOWN;
295 bool isEmpty()
const {
return !mElements.any(); }
297 bool isUnkownMesh()
const {
return mType == MeshType::UNKNOWN; }
311 bool isQuadMesh()
const {
return mType == MeshType::QUAD_MESH; }
326 bool hasElement(
Element el)
const {
return mElements[
el]; }
330 return mPerElemComponents[el][comp];
345 return hasPerElementComponent(VERTEX, COORD);
354 return hasPerElementComponent(VERTEX, NORMAL);
363 return hasPerElementComponent(VERTEX, COLOR);
372 return hasPerElementComponent(VERTEX, QUALITY);
381 return hasPerElementComponent(VERTEX, TEXCOORD);
390 return hasPerElementComponent(VERTEX, CUSTOM_COMPONENTS);
403 bool hasFaceVRefs()
const {
return hasPerElementComponent(FACE, VREFS); }
405 bool hasFaceNormals()
const {
return hasPerElementComponent(FACE, NORMAL); }
407 bool hasFaceColors()
const {
return hasPerElementComponent(FACE, COLOR); }
409 bool hasFaceQuality()
const
411 return hasPerElementComponent(FACE, QUALITY);
414 bool hasFaceWedgeTexCoords()
const
416 return hasPerElementComponent(FACE, WEDGE_TEXCOORDS);
419 bool hasFaceCustomComponents()
const
421 return hasPerElementComponent(FACE, CUSTOM_COMPONENTS);
430 bool hasEdgeVRefs()
const {
return hasPerElementComponent(EDGE, VREFS); }
432 bool hasEdgeColors()
const {
return hasPerElementComponent(EDGE, COLOR); }
434 bool hasEdgeNormals()
const {
return hasPerElementComponent(EDGE, NORMAL); }
436 bool hasEdgeQuality()
const
438 return hasPerElementComponent(EDGE, QUALITY);
441 bool hasEdgeCustomComponents()
const
443 return hasPerElementComponent(EDGE, CUSTOM_COMPONENTS);
446 bool hasTextures()
const {
return hasPerElementComponent(MESH, TEXTURES); }
455 void updateMeshType(uint faceSize)
457 if (mType == MeshType::UNKNOWN) {
460 else if (faceSize == 4)
465 else if (mType == MeshType::TRIANGLE_MESH && faceSize != 3) {
468 else if (mType == MeshType::QUAD_MESH && faceSize != 4) {
473 void setUnknownMesh() { mType = MeshType::UNKNOWN; }
475 void setTriangleMesh() { mType = MeshType::TRIANGLE_MESH; }
477 void setQuadMesh() { mType = MeshType::QUAD_MESH; }
479 void setPolygonMesh() { mType = MeshType::POLYGON_MESH; }
481 void setMeshType(
MeshType t) { mType = t; }
483 void setElement(
Element el,
bool b =
true) { mElements[el] = b; }
488 mPerElemComponents[el][c] = b;
490 mPerElemComponentsType(el, c) = t;
493 void setVertices(
bool b =
true) { setElement(VERTEX, b); }
495 void setVertexCoords(
bool b =
true,
DataType t = PrimitiveType::DOUBLE)
497 setElementComponents(VERTEX, COORD, b, t);
500 void setVertexNormals(
bool b =
true,
DataType t = PrimitiveType::FLOAT)
502 setElementComponents(VERTEX, NORMAL, b, t);
505 void setVertexColors(
bool b =
true,
DataType t = PrimitiveType::UCHAR)
507 setElementComponents(VERTEX, COLOR, b, t);
510 void setVertexQuality(
bool b =
true,
DataType t = PrimitiveType::DOUBLE)
512 setElementComponents(VERTEX, QUALITY, b, t);
515 void setVertexTexCoords(
bool b =
true,
DataType t = PrimitiveType::FLOAT)
517 setElementComponents(VERTEX, TEXCOORD, b, t);
520 void setVertexCustomComponents(
bool b =
true)
522 setElementComponents(VERTEX, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
525 void setFaces(
bool b =
true) { setElement(FACE, b); }
527 void setFaceVRefs(
bool b =
true)
529 setElementComponents(FACE, VREFS, b, PrimitiveType::NONE);
532 void setFaceNormals(
bool b =
true,
DataType t = PrimitiveType::FLOAT)
534 setElementComponents(FACE, NORMAL, b, t);
537 void setFaceColors(
bool b =
true,
DataType t = PrimitiveType::UCHAR)
539 setElementComponents(FACE, COLOR, b, t);
542 void setFaceQuality(
bool b =
true,
DataType t = PrimitiveType::DOUBLE)
544 setElementComponents(FACE, QUALITY, b, t);
547 void setFaceWedgeTexCoords(
bool b =
true,
DataType t = PrimitiveType::FLOAT)
549 setElementComponents(FACE, WEDGE_TEXCOORDS, b, t);
552 void setFaceCustomComponents(
bool b =
true)
554 setElementComponents(FACE, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
557 void setEdges(
bool b =
true) { setElement(EDGE, b); }
559 void setEdgeVRefs(
bool b =
true)
561 setElementComponents(EDGE, VREFS, b, PrimitiveType::NONE);
564 void setEdgeColors(
bool b =
true,
DataType t = PrimitiveType::UCHAR)
566 setElementComponents(EDGE, COLOR, b, t);
569 void setEdgeNormals(
bool b =
true,
DataType t = PrimitiveType::FLOAT)
571 setElementComponents(EDGE, NORMAL, b, t);
574 void setEdgeQuality(
bool b =
true,
DataType t = PrimitiveType::DOUBLE)
576 setElementComponents(EDGE, QUALITY, b, t);
579 void setEdgeCustomComponents(
bool b =
true)
581 setElementComponents(EDGE, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
584 void setTextures(
bool b =
true)
586 setElementComponents(MESH, TEXTURES, b, PrimitiveType::NONE);
589 void addElementCustomComponent(
591 const std::string& name,
594 setElementComponents(el, CUSTOM_COMPONENTS,
true, PrimitiveType::NONE);
595 mPerElemCustomComponents[el].emplace_back(name, t);
598 void clearElementCustomComponents(
Element el)
600 setElementComponents(el, CUSTOM_COMPONENTS,
false, PrimitiveType::NONE);
601 mPerElemCustomComponents[el].clear();
604 void addVertexCustomComponent(
const std::string& name,
DataType t)
606 addElementCustomComponent(VERTEX, name, t);
609 void clearVertexCustomComponents() { clearElementCustomComponents(VERTEX); }
611 void addFaceCustomComponent(
const std::string& name,
DataType t)
613 addElementCustomComponent(FACE, name, t);
616 void clearFaceCustomComponents() { clearElementCustomComponents(FACE); }
618 void addEdgeCustomComponent(
const std::string& name,
DataType t)
620 addElementCustomComponent(EDGE, name, t);
623 void clearEdgeCustomComponents() { clearElementCustomComponents(EDGE); }
632 return mPerElemComponentsType(el, comp);
637 return elementComponentType(VERTEX, COORD);
642 return elementComponentType(VERTEX, NORMAL);
647 return elementComponentType(VERTEX, COLOR);
652 return elementComponentType(VERTEX, QUALITY);
655 DataType vertexTexCoordsType()
const
657 return elementComponentType(VERTEX, TEXCOORD);
662 return elementComponentType(FACE, NORMAL);
667 return elementComponentType(FACE, COLOR);
672 return elementComponentType(FACE, QUALITY);
675 DataType faceWedgeTexCoordsType()
const
677 return elementComponentType(FACE, WEDGE_TEXCOORDS);
682 return elementComponentType(EDGE, COLOR);
687 return elementComponentType(EDGE, NORMAL);
692 return elementComponentType(EDGE, QUALITY);
695 const std::vector<CustomComponent>& vertexCustomComponents()
const
697 return mPerElemCustomComponents[VERTEX];
700 const std::vector<CustomComponent>& faceCustomComponents()
const
702 return mPerElemCustomComponents[FACE];
705 const std::vector<CustomComponent>& edgeCustomComponents()
const
707 return mPerElemCustomComponents[EDGE];
724 for (
uint i = 0;
i < NUM_ELEMENTS; ++
i) {
725 res.mElements[
i] = mElements[
i] && info.mElements[
i];
726 for (
uint j = 0;
j < NUM_COMPONENTS; ++
j) {
727 res.mPerElemComponents[
i][
j] =
728 mPerElemComponents[
i][
j] && info.mPerElemComponents[
i][
j];
730 if (
res.mPerElemComponents[
i][
j]) {
731 res.mPerElemComponentsType(
i,
j) =
732 mPerElemComponentsType(
i,
j);
737 if (mType == info.mType) {
740 res.mPerElemCustomComponents = mPerElemCustomComponents;
757 if constexpr (std::is_same_v<T, char>)
758 return PrimitiveType::CHAR;
759 if constexpr (std::is_same_v<T, unsigned char>)
760 return PrimitiveType::UCHAR;
761 if constexpr (std::is_same_v<T, short>)
762 return PrimitiveType::SHORT;
763 if constexpr (std::is_same_v<T, unsigned short>)
764 return PrimitiveType::USHORT;
765 if constexpr (std::is_same_v<T, int>)
766 return PrimitiveType::INT;
767 if constexpr (std::is_same_v<T, uint>)
768 return PrimitiveType::UINT;
769 if constexpr (std::is_integral_v<T>)
770 return PrimitiveType::INT;
771 if constexpr (std::is_same_v<T, float>)
772 return PrimitiveType::FLOAT;
773 if constexpr (std::is_same_v<T, double>)
774 return PrimitiveType::DOUBLE;
775 if constexpr (std::is_floating_point_v<T>)
776 return PrimitiveType::FLOAT;
777 return PrimitiveType::NONE;
782 if (
ti ==
typeid(
char))
783 return PrimitiveType::CHAR;
784 if (
ti ==
typeid(
unsigned char))
785 return PrimitiveType::UCHAR;
786 if (
ti ==
typeid(
short))
787 return PrimitiveType::SHORT;
788 if (
ti ==
typeid(
unsigned short))
789 return PrimitiveType::USHORT;
790 if (
ti ==
typeid(
int))
791 return PrimitiveType::INT;
792 if (
ti ==
typeid(uint))
793 return PrimitiveType::UINT;
794 if (
ti ==
typeid(
float))
795 return PrimitiveType::FLOAT;
796 if (
ti ==
typeid(
double))
797 return PrimitiveType::DOUBLE;
798 return PrimitiveType::NONE;
802template<u
int ELEM_ID, MeshConcept MeshType>
803void addPerElementCustomComponent(
805 const MeshInfo::CustomComponent& cc)
808 case PrimitiveType::CHAR:
809 m.template addPerElementCustomComponent<ELEM_ID, char>(cc.name);
811 case PrimitiveType::UCHAR:
812 m.template addPerElementCustomComponent<ELEM_ID, unsigned char>(
815 case PrimitiveType::SHORT:
816 m.template addPerElementCustomComponent<ELEM_ID, short>(cc.name);
818 case PrimitiveType::USHORT:
819 m.template addPerElementCustomComponent<ELEM_ID, unsigned short>(
822 case PrimitiveType::INT:
823 m.template addPerElementCustomComponent<ELEM_ID, int>(cc.name);
825 case PrimitiveType::UINT:
826 m.template addPerElementCustomComponent<ELEM_ID, uint>(cc.name);
828 case PrimitiveType::FLOAT:
829 m.template addPerElementCustomComponent<ELEM_ID, float>(cc.name);
831 case PrimitiveType::DOUBLE:
832 m.template addPerElementCustomComponent<ELEM_ID, double>(cc.name);
838template<MeshConcept MeshType>
839void addPerVertexCustomComponent(
841 const MeshInfo::CustomComponent& cc)
843 addPerElementCustomComponent<ElemId::VERTEX>(m, cc);
846template<FaceMeshConcept MeshType>
847void addPerFaceCustomComponent(MeshType& m,
const MeshInfo::CustomComponent& cc)
849 addPerElementCustomComponent<ElemId::FACE>(m, cc);
852template<EdgeMeshConcept MeshType>
853void addPerEdgeCustomComponent(MeshType& m,
const MeshInfo::CustomComponent& cc)
855 addPerElementCustomComponent<ElemId::EDGE>(m, cc);
871template<MeshConcept MeshType>
872void enableOptionalComponentsFromInfo(MeshInfo& info, MeshType& m)
874 if (info.hasVertices()) {
875 if (info.hasVertexColors()) {
876 if (!enableIfPerVertexColorOptional(m)) {
877 info.setVertexColors(
false);
880 if (info.hasVertexNormals()) {
881 if (!enableIfPerVertexNormalOptional(m)) {
882 info.setVertexNormals(
false);
885 if (info.hasVertexQuality()) {
886 if (!enableIfPerVertexQualityOptional(m)) {
887 info.setVertexQuality(
false);
890 if (info.hasVertexTexCoords()) {
891 if (!enableIfPerVertexTexCoordOptional(m)) {
892 info.setVertexTexCoords(
false);
895 if (info.hasVertexCustomComponents()) {
896 if constexpr (HasPerVertexCustomComponents<MeshType>) {
897 for (
const auto& cc : info.vertexCustomComponents()) {
898 addPerVertexCustomComponent(m, cc);
902 info.clearVertexCustomComponents();
907 info.setVertices(
false);
910 if constexpr (HasFaces<MeshType>) {
911 if (info.hasFaces()) {
912 if (info.hasFaceColors()) {
914 info.setFaceColors(
false);
917 if (info.hasFaceNormals()) {
919 info.setFaceNormals(
false);
922 if (info.hasFaceQuality()) {
924 info.setFaceQuality(
false);
927 if (info.hasFaceWedgeTexCoords()) {
929 info.setFaceWedgeTexCoords(
false);
932 if (info.hasFaceCustomComponents()) {
933 if constexpr (HasPerFaceCustomComponents<MeshType>) {
934 for (
const auto& cc : info.faceCustomComponents()) {
935 addPerFaceCustomComponent(m, cc);
939 info.clearFaceCustomComponents();
944 info.setFaces(
false);
948 info.setFaces(
false);
951 if constexpr (HasEdges<MeshType>) {
952 if (info.hasEdges()) {
953 if (info.hasEdgeColors()) {
955 info.setEdgeColors(
false);
958 if (info.hasEdgeNormals()) {
960 info.setEdgeNormals(
false);
963 if (info.hasEdgeQuality()) {
965 info.setEdgeQuality(
false);
968 if (info.hasEdgeCustomComponents()) {
969 if constexpr (HasPerEdgeCustomComponents<MeshType>) {
970 for (
const auto& cc : info.edgeCustomComponents()) {
971 addPerEdgeCustomComponent(m, cc);
975 info.clearEdgeCustomComponents();
980 info.setEdges(
false);
984 info.setEdges(
false);
The Element class.
Definition element.h:57
A simple class that allows to store which elements and their components have been imported/loaded or ...
Definition mesh_info.h:76
MeshInfo intersect(const MeshInfo &info) const
Returns a MeshInfo object that is the intersection between this and info.
Definition mesh_info.h:721
static DataType getType()
Given the template T, returns the corresponding enum DataType value of T.
Definition mesh_info.h:755
bool isEmpty() const
Returns whether the current MeshInfo object is empty, i.e., it has no Elements set.
Definition mesh_info.h:295
bool hasVertexColors() const
Returns true if the current object has Vertex Colors.
Definition mesh_info.h:361
Component
Enum used to describe the type of Components that each Element can have.
Definition mesh_info.h:97
bool isTriangleMesh() const
Returns true if the current object has Mesh type set to MeshType::TRIANGLE_MESH.
Definition mesh_info.h:304
void clear()
Clears the MeshInfo object.
Definition mesh_info.h:278
bool hasFaceVRefs() const
Returns true if the current object has per Face Vertex References.
Definition mesh_info.h:403
bool isQuadMesh() const
Returns true if the current object has Mesh type set to MeshType::QUAD_MESH.
Definition mesh_info.h:311
bool hasVertices() const
Returns true if the current object has Vertex Elements.
Definition mesh_info.h:337
bool hasVertexCustomComponents() const
Returns true if the current object has Vertex Custom Components.
Definition mesh_info.h:388
bool isPolygonMesh() const
Returns true if the current object has Mesh type set to MeshType::POLYGON_MESH.
Definition mesh_info.h:318
PrimitiveType DataType
Enum used to describe the type of Data stored in a component.
Definition mesh_info.h:113
bool hasFaces() const
Returns true if the current object has Face Elements.
Definition mesh_info.h:397
bool hasVertexQuality() const
Returns true if the current object has Vertex Quality.
Definition mesh_info.h:370
bool hasVertexCoords() const
Returns true if the current object has Vertex Coordinates.
Definition mesh_info.h:343
bool hasVertexTexCoords() const
Returns true if the current object has Vertex Texture Coordinates.
Definition mesh_info.h:379
bool hasEdges() const
Returns true if the current object has Edge Elements.
Definition mesh_info.h:428
Element
Enum used to describe the type of Elements that can be found in a file.
Definition mesh_info.h:91
bool hasVertexNormals() const
Returns true if the current object has Vertex Normals.
Definition mesh_info.h:352
MeshInfo()
Default constructor.
Definition mesh_info.h:153
MeshInfo(const Mesh &m)
Sets the current status of the MeshInfo object from the input mesh.
Definition mesh_info.h:165
MeshType
Enum used to describe the type of the Mesh - by default, the value is set to UNKNOWN.
Definition mesh_info.h:82
The Mesh class represents a generic 3D mesh. A mesh is composed of a generic number of containers of ...
Definition mesh.h:68
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:131
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:133
Concept that checks if a Mesh has the per Face Color component.
Definition per_face.h:111
Concept that checks if a Mesh has the per Face CustomComponents component.
Definition per_face.h:127
Concept that checks if a Mesh has the per Face Normal component.
Definition per_face.h:158
Concept that checks if a Mesh has the per Face Quality component.
Definition per_face.h:206
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition per_face.h:270
Concept that checks if a Mesh has the per Vertex Color component.
Definition per_vertex.h:98
Concept that checks if a Mesh has the per Vertex CustomComponents.
Definition per_vertex.h:188
Concept that checks if a Mesh has the per Vertex Normal component.
Definition per_vertex.h:128
Concept that checks if a Mesh has the per Vertex Quality component.
Definition per_vertex.h:159
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition per_vertex.h:174
Concept that checks if a Mesh has the TexturePaths component.
Definition per_mesh.h:112
bool enableIfPerEdgeColorOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Color Component,...
Definition edge_requirements.h:238
bool enableIfPerEdgeNormalOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Normal Component,...
Definition edge_requirements.h:354
bool enableIfPerEdgeQualityOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Quality Component,...
Definition edge_requirements.h:412
bool enableIfPerFaceQualityOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Quality Component,...
Definition face_requirements.h:475
bool enableIfPerFaceWedgeTexCoordsOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a WedgeTexCoords Component,...
Definition face_requirements.h:597
bool isPerFaceWedgeTexCoordsAvailable(const MeshType &m)
Returns true if the WedgeTexCoords component is available (enabled) in the Face element of the input ...
Definition face_requirements.h:571
bool isPerFaceNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:330
bool isPerFaceQualityAvailable(const MeshType &m)
Returns true if the Quality component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:451
bool isPerFaceColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:214
bool enableIfPerFaceNormalOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Normal Component,...
Definition face_requirements.h:354
bool enableIfPerFaceColorOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Color Component,...
Definition face_requirements.h:238
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:58
The CustomComponent struct is a simple structure that describes a custom component of an Element (or ...
Definition mesh_info.h:120