Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_info.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_SPACE_COMPLEX_MESH_INFO_H
24#define VCL_SPACE_COMPLEX_MESH_INFO_H
25
26#include <vclib/base.h>
27#include <vclib/mesh.h>
28
29#include <array>
30#include <bitset>
31#include <string>
32#include <typeindex>
33#include <vector>
34
35namespace vcl {
36
76{
77public:
82 enum class MeshType { TRIANGLE_MESH, QUAD_MESH, POLYGON_MESH, UNKNOWN };
83
91 enum Element { VERTEX, FACE, EDGE, MESH, NUM_ELEMENTS };
92
97 enum Component {
98 POSITION,
99 VREFS,
100 NORMAL,
101 COLOR,
102 QUALITY,
103 TEXCOORD,
104 MATERIAL_INDEX,
105 WEDGE_TEXCOORDS,
106 CUSTOM_COMPONENTS,
107 MATERIALS,
108 NUM_COMPONENTS
109 };
110
115
121 {
122 std::string name;
123 DataType type;
124
125 CustomComponent(std::string n, DataType t) : name(n), type(t) {}
126 };
127
128private:
129 // Tell if elements are present in the file
130 std::bitset<NUM_ELEMENTS> mElements = {false};
131
132 // Tell if per element components are present in the file
133 std::array<std::bitset<NUM_COMPONENTS>, NUM_ELEMENTS> mPerElemComponents = {
134 false};
135
136 // Tell the data type for each component of each element
137 Eigen::Matrix<DataType, NUM_ELEMENTS, NUM_COMPONENTS>
138 mPerElemComponentsType;
139
140 // Store name and type of per element custom components
141 std::array<std::vector<CustomComponent>, NUM_ELEMENTS>
142 mPerElemCustomComponents;
143
144 // Mesh Type
145 MeshType mType = MeshType::UNKNOWN;
146
147public:
154 MeshInfo() { mPerElemComponentsType.fill(PrimitiveType::NONE); }
155
165 template<MeshConcept Mesh>
167 {
168 setVertices();
169 setPerVertexPosition(
170 true,
172 if constexpr (HasPerVertexNormal<Mesh>) {
173 if (isPerVertexNormalAvailable(m)) {
174 setPerVertexNormal(
175 true,
176 getType<
177 typename Mesh::VertexType::NormalType::ScalarType>());
178 }
179 }
180 if constexpr (HasPerVertexColor<Mesh>) {
181 if (isPerVertexColorAvailable(m)) {
182 setPerVertexColor(true, PrimitiveType::UCHAR);
183 }
184 }
185 if constexpr (HasPerVertexQuality<Mesh>) {
186 if (isPerVertexQualityAvailable(m)) {
187 setPerVertexQuality(
189 }
190 }
191 if constexpr (HasPerVertexTexCoord<Mesh>) {
192 if (isPerVertexTexCoordAvailable(m)) {
193 setPerVertexTexCoord(
194 true,
195 getType<
196 typename Mesh::VertexType::TexCoordType::ScalarType>());
197 }
198 }
199 if constexpr (HasPerVertexMaterialIndex<Mesh>) {
200 if (isPerVertexMaterialIndexAvailable(m)) {
201 setPerVertexMaterialIndex(true, PrimitiveType::UINT);
202 }
203 }
205 auto names = m.perVertexCustomComponentNames();
206 for (auto& name : names) {
207 DataType dt = getType(m.perVertexCustomComponentType(name));
208 if (dt != PrimitiveType::NONE) {
209 addPerVertexCustomComponent(name, dt);
210 }
211 }
212 }
213
214 if constexpr (HasFaces<Mesh>) {
215 setFaces();
216 setPerFaceVertexReferences();
217 if (HasTriangles<Mesh>) {
218 setTriangleMesh();
219 }
220 else if (HasQuads<Mesh>) {
221 setQuadMesh();
222 }
223 else {
224 setPolygonMesh();
225 }
226 if constexpr (HasPerFaceNormal<Mesh>) {
228 setPerFaceNormal(
229 true,
230 getType<
231 typename Mesh::FaceType::NormalType::ScalarType>());
232 }
233 }
234 if constexpr (HasPerFaceColor<Mesh>) {
236 setPerFaceColor(true, PrimitiveType::UCHAR);
237 }
238 }
239 if constexpr (HasPerFaceQuality<Mesh>) {
241 setPerFaceQuality(
243 }
244 }
245 if constexpr (HasPerFaceWedgeTexCoords<Mesh>) {
247 setPerFaceWedgeTexCoords(
248 true,
249 getType<typename Mesh::FaceType::WedgeTexCoordType::
250 ScalarType>());
251 }
252 }
253 if constexpr (HasPerFaceMaterialIndex<Mesh>) {
255 setPerFaceMaterialIndex(true, PrimitiveType::UINT);
256 }
257 }
258 if constexpr (HasPerFaceCustomComponents<Mesh>) {
259 auto names = m.perFaceCustomComponentNames();
260 for (auto& name : names) {
261 DataType dt = getType(m.perFaceCustomComponentType(name));
262 if (dt != PrimitiveType::NONE) {
263 addPerFaceCustomComponent(name, dt);
264 }
265 }
266 }
267 }
268
269 if constexpr (HasEdges<Mesh>) {
270 setEdges();
271 setPerEdgeVertexReferences();
272 // if constexpr (HasPerEdgeColor<Mesh>)
273 // if (isPerEdgeColorAvailable(m))
274 // setEdgeColors(true, UCHAR);
275 }
276
277 if constexpr (HasMaterials<Mesh>) {
278 if (m.materialsNumber() > 0) {
279 setMaterials(true);
280 }
281 }
282 }
283
290 void clear()
291 {
292 mElements.reset();
293 for (auto& comp : mPerElemComponents)
294 comp.reset();
295 mPerElemComponentsType.fill(PrimitiveType::NONE);
296
297 for (auto& v : mPerElemCustomComponents)
298 v.clear();
299
300 mType = MeshType::UNKNOWN;
301 }
302
307 bool isEmpty() const { return !mElements.any(); }
308
309 MeshType meshType() const { return mType; }
310
311 bool isUnkownMesh() const { return mType == MeshType::UNKNOWN; }
312
318 bool isTriangleMesh() const { return mType == MeshType::TRIANGLE_MESH; }
319
325 bool isQuadMesh() const { return mType == MeshType::QUAD_MESH; }
326
332 bool isPolygonMesh() const { return mType == MeshType::POLYGON_MESH; }
333
334 /*
335 * Getter Elements/Components functions: they are used mostly after the
336 * loading of a Mesh from a file, to know if Elements/Components have been
337 * loaded.
338 */
339
340 bool hasElement(Element el) const { return mElements[el]; }
341
342 bool hasPerElementComponent(Element el, Component comp) const
343 {
344 return mPerElemComponents[el][comp];
345 }
346
351 bool hasVertices() const { return hasElement(VERTEX); }
352
358 {
359 return hasPerElementComponent(VERTEX, POSITION);
360 }
361
367 {
368 return hasPerElementComponent(VERTEX, NORMAL);
369 }
370
375 bool hasPerVertexColor() const
376 {
377 return hasPerElementComponent(VERTEX, COLOR);
378 }
379
385 {
386 return hasPerElementComponent(VERTEX, QUALITY);
387 }
388
394 {
395 return hasPerElementComponent(VERTEX, TEXCOORD);
396 }
397
403 {
404 return hasPerElementComponent(VERTEX, MATERIAL_INDEX);
405 }
406
412 {
413 return hasPerElementComponent(VERTEX, CUSTOM_COMPONENTS);
414 }
415
420 bool hasFaces() const { return hasElement(FACE); }
421
427 {
428 return hasPerElementComponent(FACE, VREFS);
429 }
430
431 bool hasPerFaceNormal() const
432 {
433 return hasPerElementComponent(FACE, NORMAL);
434 }
435
436 bool hasPerFaceColor() const { return hasPerElementComponent(FACE, COLOR); }
437
438 bool hasPerFaceQuality() const
439 {
440 return hasPerElementComponent(FACE, QUALITY);
441 }
442
443 bool hasPerFaceWedgeTexCoords() const
444 {
445 return hasPerElementComponent(FACE, WEDGE_TEXCOORDS);
446 }
447
453 {
454 return hasPerElementComponent(FACE, MATERIAL_INDEX);
455 }
456
457 bool hasPerFaceCustomComponents() const
458 {
459 return hasPerElementComponent(FACE, CUSTOM_COMPONENTS);
460 }
461
466 bool hasEdges() const { return hasElement(EDGE); }
467
468 bool hasPerEdgeVertexReferences() const
469 {
470 return hasPerElementComponent(EDGE, VREFS);
471 }
472
473 bool hasPerEdgeColor() const { return hasPerElementComponent(EDGE, COLOR); }
474
475 bool hasPerEdgeNormal() const
476 {
477 return hasPerElementComponent(EDGE, NORMAL);
478 }
479
480 bool hasPerEdgeQuality() const
481 {
482 return hasPerElementComponent(EDGE, QUALITY);
483 }
484
485 bool hasPerEdgeCustomComponents() const
486 {
487 return hasPerElementComponent(EDGE, CUSTOM_COMPONENTS);
488 }
489
490 bool hasMaterials() const
491 {
492 return hasPerElementComponent(MESH, MATERIALS);
493 }
494
495 /*
496 * Setter functions: they are used by the load functions to tell which
497 * Elements/Components are loaded from a file, and they can be used by the
498 * user that wants to save in a file only a specific set of
499 * Elements/Components of a Mesh.
500 */
501
502 void updateMeshType(uint faceSize)
503 {
504 if (mType == MeshType::UNKNOWN) {
505 if (faceSize == 3)
506 setTriangleMesh();
507 else if (faceSize == 4)
508 setQuadMesh();
509 else
510 setPolygonMesh();
511 }
512 else if (mType == MeshType::TRIANGLE_MESH && faceSize != 3) {
513 setPolygonMesh();
514 }
515 else if (mType == MeshType::QUAD_MESH && faceSize != 4) {
516 setPolygonMesh();
517 }
518 }
519
520 void setUnknownMesh() { mType = MeshType::UNKNOWN; }
521
522 void setTriangleMesh() { mType = MeshType::TRIANGLE_MESH; }
523
524 void setQuadMesh() { mType = MeshType::QUAD_MESH; }
525
526 void setPolygonMesh() { mType = MeshType::POLYGON_MESH; }
527
528 void setMeshType(MeshType t) { mType = t; }
529
530 void setElement(Element el, bool b = true) { mElements[el] = b; }
531
532 void setPerElementComponent(Element el, Component c, bool b, DataType t)
533 {
534 mElements[el] = b;
535 mPerElemComponents[el][c] = b;
536 if (b)
537 mPerElemComponentsType(el, c) = t;
538 }
539
540 void setVertices(bool b = true) { setElement(VERTEX, b); }
541
542 void setPerVertexPosition(bool b = true, DataType t = PrimitiveType::DOUBLE)
543 {
544 setPerElementComponent(VERTEX, POSITION, b, t);
545 }
546
547 void setPerVertexNormal(bool b = true, DataType t = PrimitiveType::FLOAT)
548 {
549 setPerElementComponent(VERTEX, NORMAL, b, t);
550 }
551
552 void setPerVertexColor(bool b = true, DataType t = PrimitiveType::UCHAR)
553 {
554 setPerElementComponent(VERTEX, COLOR, b, t);
555 }
556
557 void setPerVertexQuality(bool b = true, DataType t = PrimitiveType::DOUBLE)
558 {
559 setPerElementComponent(VERTEX, QUALITY, b, t);
560 }
561
562 void setPerVertexTexCoord(bool b = true, DataType t = PrimitiveType::FLOAT)
563 {
564 setPerElementComponent(VERTEX, TEXCOORD, b, t);
565 }
566
567 void setPerVertexMaterialIndex(
568 bool b = true,
569 DataType t = PrimitiveType::USHORT)
570 {
571 setPerElementComponent(VERTEX, MATERIAL_INDEX, b, t);
572 }
573
574 void setPerVertexCustomComponents(bool b = true)
575 {
576 setPerElementComponent(
577 VERTEX, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
578 }
579
580 void setFaces(bool b = true) { setElement(FACE, b); }
581
582 void setPerFaceVertexReferences(bool b = true)
583 {
584 setPerElementComponent(FACE, VREFS, b, PrimitiveType::NONE);
585 }
586
587 void setPerFaceNormal(bool b = true, DataType t = PrimitiveType::FLOAT)
588 {
589 setPerElementComponent(FACE, NORMAL, b, t);
590 }
591
592 void setPerFaceColor(bool b = true, DataType t = PrimitiveType::UCHAR)
593 {
594 setPerElementComponent(FACE, COLOR, b, t);
595 }
596
597 void setPerFaceQuality(bool b = true, DataType t = PrimitiveType::DOUBLE)
598 {
599 setPerElementComponent(FACE, QUALITY, b, t);
600 }
601
602 void setPerFaceWedgeTexCoords(
603 bool b = true,
604 DataType t = PrimitiveType::FLOAT)
605 {
606 setPerElementComponent(FACE, WEDGE_TEXCOORDS, b, t);
607 }
608
609 void setPerFaceMaterialIndex(
610 bool b = true,
611 DataType t = PrimitiveType::USHORT)
612 {
613 setPerElementComponent(FACE, MATERIAL_INDEX, b, t);
614 }
615
616 void setPerFaceCustomComponents(bool b = true)
617 {
618 setPerElementComponent(FACE, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
619 }
620
621 void setEdges(bool b = true) { setElement(EDGE, b); }
622
623 void setPerEdgeVertexReferences(bool b = true)
624 {
625 setPerElementComponent(EDGE, VREFS, b, PrimitiveType::NONE);
626 }
627
628 void setPerEdgeColor(bool b = true, DataType t = PrimitiveType::UCHAR)
629 {
630 setPerElementComponent(EDGE, COLOR, b, t);
631 }
632
633 void setPerEdgeNormal(bool b = true, DataType t = PrimitiveType::FLOAT)
634 {
635 setPerElementComponent(EDGE, NORMAL, b, t);
636 }
637
638 void setPerEdgeQuality(bool b = true, DataType t = PrimitiveType::DOUBLE)
639 {
640 setPerElementComponent(EDGE, QUALITY, b, t);
641 }
642
643 void setPerEdgeCustomComponents(bool b = true)
644 {
645 setPerElementComponent(EDGE, CUSTOM_COMPONENTS, b, PrimitiveType::NONE);
646 }
647
648 void setMaterials(bool b = true)
649 {
650 setPerElementComponent(MESH, MATERIALS, b, PrimitiveType::NONE);
651 }
652
653 void addPerElementCustomComponent(
654 Element el,
655 const std::string& name,
656 DataType t)
657 {
658 setPerElementComponent(
659 el, CUSTOM_COMPONENTS, true, PrimitiveType::NONE);
660 mPerElemCustomComponents[el].emplace_back(name, t);
661 }
662
663 void clearPerElementCustomComponents(Element el)
664 {
665 setPerElementComponent(
666 el, CUSTOM_COMPONENTS, false, PrimitiveType::NONE);
667 mPerElemCustomComponents[el].clear();
668 }
669
670 void addPerVertexCustomComponent(const std::string& name, DataType t)
671 {
672 addPerElementCustomComponent(VERTEX, name, t);
673 }
674
675 void clearPerVertexCustomComponents()
676 {
677 clearPerElementCustomComponents(VERTEX);
678 }
679
680 void addPerFaceCustomComponent(const std::string& name, DataType t)
681 {
682 addPerElementCustomComponent(FACE, name, t);
683 }
684
685 void clearPerFaceCustomComponents()
686 {
687 clearPerElementCustomComponents(FACE);
688 }
689
690 void addPerEdgeCustomComponent(const std::string& name, DataType t)
691 {
692 addPerElementCustomComponent(EDGE, name, t);
693 }
694
695 void clearPerEdgeCustomComponents()
696 {
697 clearPerElementCustomComponents(EDGE);
698 }
699
700 /*
701 * Getter Component type functions : they are used mostly by save functions
702 * to know the type that needs to use to save a given Component
703 */
704
705 DataType perElementComponentType(Element el, Component comp) const
706 {
707 return mPerElemComponentsType(el, comp);
708 }
709
710 DataType perVertexPositionType() const
711 {
712 return perElementComponentType(VERTEX, POSITION);
713 }
714
715 DataType perVertexNormalType() const
716 {
717 return perElementComponentType(VERTEX, NORMAL);
718 }
719
720 DataType perVertexColorType() const
721 {
722 return perElementComponentType(VERTEX, COLOR);
723 }
724
725 DataType perVertexQualityType() const
726 {
727 return perElementComponentType(VERTEX, QUALITY);
728 }
729
730 DataType perVertexTexCoordType() const
731 {
732 return perElementComponentType(VERTEX, TEXCOORD);
733 }
734
735 DataType perVertexMaterialIndexType() const
736 {
737 return perElementComponentType(VERTEX, MATERIAL_INDEX);
738 }
739
740 DataType perFaceNormalType() const
741 {
742 return perElementComponentType(FACE, NORMAL);
743 }
744
745 DataType perFaceColorType() const
746 {
747 return perElementComponentType(FACE, COLOR);
748 }
749
750 DataType perFaceQualityType() const
751 {
752 return perElementComponentType(FACE, QUALITY);
753 }
754
755 DataType perFaceWedgeTexCoordsType() const
756 {
757 return perElementComponentType(FACE, WEDGE_TEXCOORDS);
758 }
759
760 DataType perFaceMaterialIndexType() const
761 {
762 return perElementComponentType(FACE, MATERIAL_INDEX);
763 }
764
765 DataType perEdgeNormalType() const
766 {
767 return perElementComponentType(EDGE, NORMAL);
768 }
769
770 DataType perEdgeColorType() const
771 {
772 return perElementComponentType(EDGE, COLOR);
773 }
774
775 DataType perEdgeQualityType() const
776 {
777 return perElementComponentType(EDGE, QUALITY);
778 }
779
780 const std::vector<CustomComponent>& perElementCustomComponents(
781 Element el) const
782 {
783 return mPerElemCustomComponents[el];
784 }
785
786 const std::vector<CustomComponent>& perVertexCustomComponents() const
787 {
788 return mPerElemCustomComponents[VERTEX];
789 }
790
791 const std::vector<CustomComponent>& perFaceCustomComponents() const
792 {
793 return mPerElemCustomComponents[FACE];
794 }
795
796 const std::vector<CustomComponent>& perEdgeCustomComponents() const
797 {
798 return mPerElemCustomComponents[EDGE];
799 }
800
812 [[nodiscard]] MeshInfo intersect(const MeshInfo& info) const
813 {
815 for (uint i = 0; i < NUM_ELEMENTS; ++i) {
816 res.mElements[i] = mElements[i] && info.mElements[i];
817 for (uint j = 0; j < NUM_COMPONENTS; ++j) {
818 res.mPerElemComponents[i][j] =
819 mPerElemComponents[i][j] && info.mPerElemComponents[i][j];
820
821 if (res.mPerElemComponents[i][j]) {
822 res.mPerElemComponentsType(i, j) =
823 mPerElemComponentsType(i, j);
824 }
825 }
826 }
827
828 if (mType == info.mType) {
829 res.mType = mType;
830 }
831 res.mPerElemCustomComponents = mPerElemCustomComponents;
832
833 return res;
834 }
835
836private:
845 template<typename T>
847 {
848 if constexpr (std::is_same_v<T, char>)
849 return PrimitiveType::CHAR;
850 if constexpr (std::is_same_v<T, unsigned char>)
851 return PrimitiveType::UCHAR;
852 if constexpr (std::is_same_v<T, short>)
853 return PrimitiveType::SHORT;
854 if constexpr (std::is_same_v<T, unsigned short>)
855 return PrimitiveType::USHORT;
856 if constexpr (std::is_same_v<T, int>)
857 return PrimitiveType::INT;
858 if constexpr (std::is_same_v<T, uint>)
859 return PrimitiveType::UINT;
860 if constexpr (std::is_integral_v<T>)
861 return PrimitiveType::INT; // fallback to int
862 if constexpr (std::is_same_v<T, float>)
863 return PrimitiveType::FLOAT;
864 if constexpr (std::is_same_v<T, double>)
865 return PrimitiveType::DOUBLE;
866 if constexpr (std::is_floating_point_v<T>)
867 return PrimitiveType::FLOAT; // fallback to float
868 return PrimitiveType::NONE;
869 }
870
871 static DataType getType(std::type_index ti)
872 {
873 if (ti == typeid(char))
874 return PrimitiveType::CHAR;
875 if (ti == typeid(unsigned char))
876 return PrimitiveType::UCHAR;
877 if (ti == typeid(short))
878 return PrimitiveType::SHORT;
879 if (ti == typeid(unsigned short))
880 return PrimitiveType::USHORT;
881 if (ti == typeid(int))
882 return PrimitiveType::INT;
883 if (ti == typeid(uint))
884 return PrimitiveType::UINT;
885 if (ti == typeid(float))
886 return PrimitiveType::FLOAT;
887 if (ti == typeid(double))
888 return PrimitiveType::DOUBLE;
889 return PrimitiveType::NONE;
890 }
891};
892
893template<uint ELEM_ID, MeshConcept MeshType>
894void addPerElementCustomComponent(
895 MeshType& m,
896 const MeshInfo::CustomComponent& cc)
897{
898 switch (cc.type) {
899 case PrimitiveType::CHAR:
900 m.template addPerElementCustomComponent<ELEM_ID, char>(cc.name);
901 break;
902 case PrimitiveType::UCHAR:
903 m.template addPerElementCustomComponent<ELEM_ID, unsigned char>(
904 cc.name);
905 break;
906 case PrimitiveType::SHORT:
907 m.template addPerElementCustomComponent<ELEM_ID, short>(cc.name);
908 break;
909 case PrimitiveType::USHORT:
910 m.template addPerElementCustomComponent<ELEM_ID, unsigned short>(
911 cc.name);
912 break;
913 case PrimitiveType::INT:
914 m.template addPerElementCustomComponent<ELEM_ID, int>(cc.name);
915 break;
916 case PrimitiveType::UINT:
917 m.template addPerElementCustomComponent<ELEM_ID, uint>(cc.name);
918 break;
919 case PrimitiveType::FLOAT:
920 m.template addPerElementCustomComponent<ELEM_ID, float>(cc.name);
921 break;
922 case PrimitiveType::DOUBLE:
923 m.template addPerElementCustomComponent<ELEM_ID, double>(cc.name);
924 break;
925 default: assert(0);
926 }
927}
928
929template<MeshConcept MeshType>
930void addPerVertexCustomComponent(
931 MeshType& m,
932 const MeshInfo::CustomComponent& cc)
933{
934 addPerElementCustomComponent<ElemId::VERTEX>(m, cc);
935}
936
937template<FaceMeshConcept MeshType>
938void addPerFaceCustomComponent(MeshType& m, const MeshInfo::CustomComponent& cc)
939{
940 addPerElementCustomComponent<ElemId::FACE>(m, cc);
941}
942
943template<EdgeMeshConcept MeshType>
944void addPerEdgeCustomComponent(MeshType& m, const MeshInfo::CustomComponent& cc)
945{
946 addPerElementCustomComponent<ElemId::EDGE>(m, cc);
947}
948
962template<MeshConcept MeshType>
963void enableOptionalComponentsFromInfo(MeshInfo& info, MeshType& m)
964{
965 if (info.hasVertices()) {
966 if (info.hasPerVertexColor()) {
967 if (!enableIfPerVertexColorOptional(m)) {
968 info.setPerVertexColor(false);
969 }
970 }
971 if (info.hasPerVertexNormal()) {
972 if (!enableIfPerVertexNormalOptional(m)) {
973 info.setPerVertexNormal(false);
974 }
975 }
976 if (info.hasPerVertexQuality()) {
977 if (!enableIfPerVertexQualityOptional(m)) {
978 info.setPerVertexQuality(false);
979 }
980 }
981 if (info.hasPerVertexTexCoord()) {
982 if (!enableIfPerVertexTexCoordOptional(m)) {
983 info.setPerVertexTexCoord(false);
984 }
985 }
986 if (info.hasPerVertexMaterialIndex()) {
987 if (!enableIfPerVertexMaterialIndexOptional(m)) {
988 info.setPerVertexMaterialIndex(false);
989 }
990 }
991 if (info.hasPerVertexCustomComponents()) {
992 if constexpr (HasPerVertexCustomComponents<MeshType>) {
993 for (const auto& cc : info.perVertexCustomComponents()) {
994 addPerVertexCustomComponent(m, cc);
995 }
996 }
997 else {
998 info.clearPerVertexCustomComponents();
999 }
1000 }
1001 }
1002 else {
1003 info.setVertices(false);
1004 }
1005
1006 if constexpr (HasFaces<MeshType>) {
1007 if (info.hasFaces()) {
1008 if (info.hasPerFaceColor()) {
1010 info.setPerFaceColor(false);
1011 }
1012 }
1013 if (info.hasPerFaceNormal()) {
1015 info.setPerFaceNormal(false);
1016 }
1017 }
1018 if (info.hasPerFaceQuality()) {
1020 info.setPerFaceQuality(false);
1021 }
1022 }
1023 if (info.hasPerFaceWedgeTexCoords()) {
1025 info.setPerFaceWedgeTexCoords(false);
1026 }
1027 }
1028 if (info.hasPerFaceMaterialIndex()) {
1030 info.setPerFaceMaterialIndex(false);
1031 }
1032 }
1033 if (info.hasPerFaceCustomComponents()) {
1034 if constexpr (HasPerFaceCustomComponents<MeshType>) {
1035 for (const auto& cc : info.perFaceCustomComponents()) {
1036 addPerFaceCustomComponent(m, cc);
1037 }
1038 }
1039 else {
1040 info.clearPerFaceCustomComponents();
1041 }
1042 }
1043 }
1044 else {
1045 info.setFaces(false);
1046 }
1047 }
1048 else {
1049 info.setFaces(false);
1050 }
1051
1052 if constexpr (HasEdges<MeshType>) {
1053 if (info.hasEdges()) {
1054 if (info.hasPerEdgeColor()) {
1056 info.setPerEdgeColor(false);
1057 }
1058 }
1059 if (info.hasPerEdgeNormal()) {
1061 info.setPerEdgeNormal(false);
1062 }
1063 }
1064 if (info.hasPerEdgeQuality()) {
1066 info.setPerEdgeQuality(false);
1067 }
1068 }
1069 if (info.hasPerEdgeCustomComponents()) {
1070 if constexpr (HasPerEdgeCustomComponents<MeshType>) {
1071 for (const auto& cc : info.perEdgeCustomComponents()) {
1072 addPerEdgeCustomComponent(m, cc);
1073 }
1074 }
1075 else {
1076 info.clearPerEdgeCustomComponents();
1077 }
1078 }
1079 }
1080 else {
1081 info.setEdges(false);
1082 }
1083 }
1084 else {
1085 info.setEdges(false);
1086 }
1087}
1088
1089} // namespace vcl
1090
1091#endif // VCL_SPACE_COMPLEX_MESH_INFO_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
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:812
bool hasPerVertexMaterialIndex() const
Returns true if the current object has Vertex Material Index.
Definition mesh_info.h:402
bool hasPerVertexColor() const
Returns true if the current object has Vertex Colors.
Definition mesh_info.h:375
static DataType getType()
Given the template T, returns the corresponding enum DataType value of T.
Definition mesh_info.h:846
bool isEmpty() const
Returns whether the current MeshInfo object is empty, i.e., it has no Elements set.
Definition mesh_info.h:307
bool hasPerVertexNormal() const
Returns true if the current object has Vertex Normals.
Definition mesh_info.h:366
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:318
void clear()
Clears the MeshInfo object.
Definition mesh_info.h:290
bool hasPerVertexTexCoord() const
Returns true if the current object has Vertex Texture Coordinates.
Definition mesh_info.h:393
bool isQuadMesh() const
Returns true if the current object has Mesh type set to MeshType::QUAD_MESH.
Definition mesh_info.h:325
bool hasVertices() const
Returns true if the current object has Vertex Elements.
Definition mesh_info.h:351
bool hasPerVertexCustomComponents() const
Returns true if the current object has Vertex Custom Components.
Definition mesh_info.h:411
bool isPolygonMesh() const
Returns true if the current object has Mesh type set to MeshType::POLYGON_MESH.
Definition mesh_info.h:332
PrimitiveType DataType
Enum used to describe the type of Data stored in a component.
Definition mesh_info.h:114
bool hasFaces() const
Returns true if the current object has Face Elements.
Definition mesh_info.h:420
bool hasEdges() const
Returns true if the current object has Edge Elements.
Definition mesh_info.h:466
Element
Enum used to describe the type of Elements that can be found in a file.
Definition mesh_info.h:91
bool hasPerFaceVertexReferences() const
Returns true if the current object has per Face Vertex References.
Definition mesh_info.h:426
MeshInfo()
Default constructor.
Definition mesh_info.h:154
MeshInfo(const Mesh &m)
Sets the current status of the MeshInfo object from the input mesh.
Definition mesh_info.h:166
bool hasPerFaceMaterialIndex() const
Returns true if the current object has Face Material Index.
Definition mesh_info.h:452
MeshType
Enum used to describe the type of the Mesh - by default, the value is set to UNKNOWN.
Definition mesh_info.h:82
bool hasPerVertexPosition() const
Returns true if the current object has Vertex Positions.
Definition mesh_info.h:357
bool hasPerVertexQuality() const
Returns true if the current object has Vertex Quality.
Definition mesh_info.h:384
The Mesh class represents a generic 3D mesh. A mesh is composed of a generic number of containers of ...
Definition mesh.h:68
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:1064
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:1429
Concept that is evaluated true if a Mesh has the Materials component.
Definition mesh_requirements.h:88
Concept that checks if a Mesh has the per Face Color component.
Definition face_requirements.h:141
Concept that checks if a Mesh has the per Face CustomComponents component.
Definition face_requirements.h:157
Concept that checks if a Mesh has the per Face MaterialIndex component.
Definition face_requirements.h:188
Concept that checks if a Mesh has the per Face Normal component.
Definition face_requirements.h:204
Concept that checks if a Mesh has the per Face Quality component.
Definition face_requirements.h:252
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition face_requirements.h:316
Concept that checks if a Mesh has the per Vertex Color component.
Definition vertex_requirements.h:110
Concept that checks if a Mesh has the per Vertex CustomComponents.
Definition vertex_requirements.h:231
Concept that checks if a Mesh has the per Vertex MaterialIndex component.
Definition vertex_requirements.h:141
Concept that checks if a Mesh has the per Vertex Normal component.
Definition vertex_requirements.h:156
Concept that checks if a Mesh has the per Vertex Quality component.
Definition vertex_requirements.h:187
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition vertex_requirements.h:217
Definition face_requirements.h:56
Definition face_requirements.h:52
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:70
bool enableIfPerEdgeColorOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Color Component,...
Definition edge_requirements.h:394
bool enableIfPerEdgeNormalOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Normal Component,...
Definition edge_requirements.h:510
bool enableIfPerEdgeQualityOptional(MeshType &m)
If the input mesh has a EdgeContainer, and the Edge Element has a Quality Component,...
Definition edge_requirements.h:568
bool enableIfPerFaceQualityOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Quality Component,...
Definition face_requirements.h:814
bool enableIfPerFaceWedgeTexCoordsOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a WedgeTexCoords Component,...
Definition face_requirements.h:936
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:910
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:669
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:790
bool isPerFaceMaterialIndexAvailable(const MeshType &m)
Returns true if the MaterialIndex component is available (enabled) in the Face element of the input m...
Definition face_requirements.h:608
bool enableIfPerFaceMaterialIndexOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a MaterialIndex Component,...
Definition face_requirements.h:633
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:492
bool enableIfPerFaceNormalOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Normal Component,...
Definition face_requirements.h:693
bool enableIfPerFaceColorOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a Color Component,...
Definition face_requirements.h:516
The CustomComponent struct is a simple structure that describes a custom component of an Element (or ...
Definition mesh_info.h:121