Visual Computing Library
Loading...
Searching...
No Matches
export_matrix.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_ALGORITHMS_MESH_IMPORT_EXPORT_EXPORT_MATRIX_H
24#define VCL_ALGORITHMS_MESH_IMPORT_EXPORT_EXPORT_MATRIX_H
25
26#include "export_buffer.h"
27
28#include <vclib/algorithms/mesh/stat/topology.h>
29#include <vclib/concepts/space/matrix.h>
30#include <vclib/mesh/requirements.h>
31#include <vclib/space/core/matrix.h>
32
46namespace vcl {
47
74template<MatrixConcept Matrix, MeshConcept MeshType>
75Matrix vertexCoordsMatrix(const MeshType& mesh)
76{
77 Matrix vM(mesh.vertexNumber(), 3);
78
79 MatrixStorageType stg = matrixStorageType<Matrix>();
80
81 vertexCoordsToBuffer(mesh, vM.data(), stg);
82
83 return vM;
84}
85
118template<typename Vect, FaceMeshConcept MeshType>
119Vect faceSizesVector(const MeshType& mesh)
120{
121 requireVertexContainerCompactness(mesh);
122
123 Vect fM(mesh.faceNumber());
124
125 faceSizesToBuffer(mesh, fM.data());
126
127 return fM;
128}
129
161template<typename Vect, FaceMeshConcept MeshType>
162Vect faceIndicesVector(const MeshType& mesh)
163{
164 requireVertexContainerCompactness(mesh);
165
166 uint nIndices = countPerFaceVertexReferences(mesh);
167
169
170 faceIndicesToBuffer(mesh, fV.data());
171
172 return fV;
173}
174
208template<MatrixConcept Matrix, FaceMeshConcept MeshType>
209Matrix faceIndicesMatrix(const MeshType& mesh)
210{
211 requireVertexContainerCompactness(mesh);
212
213 uint fMaxSize = largestFaceSize(mesh);
214
215 Matrix fM(mesh.faceNumber(), fMaxSize);
216
217 MatrixStorageType stg = matrixStorageType<Matrix>();
218
219 faceIndicesToBuffer(mesh, fM.data(), fMaxSize, stg);
220
221 return fM;
222}
223
250template<MatrixConcept Matrix, FaceMeshConcept MeshType>
251Matrix triangulatedFaceIndicesMatrix(
252 const MeshType& mesh,
253 TriPolyIndexBiMap& indexMap = detail::indexMap)
254{
255 requireVertexContainerCompactness(mesh);
256
257 uint tNumber = vcl::countTriangulatedTriangles(mesh);
258
259 Matrix tM(tNumber, 3);
260
261 MatrixStorageType stg = matrixStorageType<Matrix>();
262
263 triangulatedFaceIndicesToBuffer(mesh, tM.data(), indexMap, stg, tNumber);
264
265 return tM;
266}
267
298template<MatrixConcept Matrix, EdgeMeshConcept MeshType>
299Matrix edgeIndicesMatrix(const MeshType& mesh)
300{
301 requireVertexContainerCompactness(mesh);
302
303 Matrix eM(mesh.edgeNumber(), 2);
304
306
307 edgeIndicesToBuffer(mesh, eM.data(), stg);
308
309 return eM;
310}
311
341template<uint ELEM_ID, typename Vect, MeshConcept MeshType>
342Vect elementSelectionVector(const MeshType& mesh)
343{
344 Vect sV(mesh.template number<ELEM_ID>());
345
347 return sV;
348}
349
377template<typename Vect, MeshConcept MeshType>
378Vect vertexSelectionVector(const MeshType& mesh)
379{
380 return elementSelectionVector<ElemId::VERTEX, Vect>(mesh);
381}
382
411template<typename Vect, FaceMeshConcept MeshType>
412Vect faceSelectionVector(const MeshType& mesh)
413{
414 return elementSelectionVector<ElemId::FACE, Vect>(mesh);
415}
416
446template<uint ELEM_ID, MatrixConcept Matrix, MeshConcept MeshType>
447Matrix elementNormalsMatrix(const MeshType& mesh)
448{
449 Matrix eNM(mesh.template number<ELEM_ID>(), 3);
450
452
454
455 return eNM;
456}
457
484template<MatrixConcept Matrix, MeshConcept MeshType>
485Matrix vertexNormalsMatrix(const MeshType& mesh)
486{
488}
489
516template<MatrixConcept Matrix, FaceMeshConcept MeshType>
517Matrix faceNormalsMatrix(const MeshType& mesh)
518{
520}
521
551template<uint ELEM_ID, MatrixConcept Matrix, MeshConcept MeshType>
552Matrix elementColorsMatrix(const MeshType& mesh)
553{
555
556 Matrix eCM(mesh.template number<ELEM_ID>(), 4);
557
559
561
562 return eCM;
563}
564
597template<uint ELEM_ID, typename Vect, MeshConcept MeshType>
599{
601
602 Vect eCV(mesh.template number<ELEM_ID>());
603
605
606 return eCV;
607}
608
635template<MatrixConcept Matrix, MeshConcept MeshType>
636Matrix vertexColorsMatrix(const MeshType& mesh)
637{
639}
640
671template<typename Vect, MeshConcept MeshType>
676
703template<MatrixConcept Matrix, FaceMeshConcept MeshType>
704Matrix faceColorsMatrix(const MeshType& mesh)
705{
707}
708
739template<typename Vect, MeshConcept MeshType>
744
775template<uint ELEM_ID, typename Vect, MeshConcept MeshType>
776Vect elementQualityVector(const MeshType& mesh)
777{
779
780 Vect eQV(mesh.template number<ELEM_ID>());
781
783
784 return eQV;
785}
786
814template<typename Vect, MeshConcept MeshType>
815Vect vertexQualityVector(const MeshType& mesh)
816{
818}
819
847template<typename Vect, FaceMeshConcept MeshType>
848Vect faceQualityVector(const MeshType& mesh)
849{
851}
852
853} // namespace vcl
854
855#endif // VCL_ALGORITHMS_MESH_IMPORT_EXPORT_EXPORT_MATRIX_H
Format
Color format enumeration.
Definition color.h:77
Definition matrix.h:36
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
void triangulatedFaceIndicesToBuffer(const MeshType &mesh, auto *buffer, TriPolyIndexBiMap &indexMap=detail::indexMap, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint numTriangles=UINT_NULL, bool getIndicesAsIfContainerCompact=true)
Export into a buffer the vertex indices for each triangle computed by triangulating the faces of a Me...
Definition export_buffer.h:357
void edgeIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint rowNumber=UINT_NULL)
Export into a buffer the vertex indices for each edge of a Mesh.
Definition export_buffer.h:451
void vertexCoordsToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint rowNumber=UINT_NULL)
Export the vertex coordinates of a mesh to a buffer.
Definition export_buffer.h:101
void faceIndicesToBuffer(const MeshType &mesh, auto *buffer, bool getIndicesAsIfContainerCompact=true)
Export into a buffer the vertex indices for each face of a Mesh. Faces can be polygons.
Definition export_buffer.h:211
uint faceSizesToBuffer(const MeshType &mesh, auto *buffer)
Export into a buffer the sizes of the faces of a Mesh, and return the sum of the sizes.
Definition export_buffer.h:149
Matrix vertexColorsMatrix(const MeshType &mesh)
Get a #V*4 Matrix of integers containing the colors of the vertices of a Mesh. The function is templa...
Definition export_matrix.h:636
Vect vertexQualityVector(const MeshType &mesh)
Get a #V Vector of scalars containing the quality of the vertices of a Mesh. The function is template...
Definition export_matrix.h:815
Matrix elementNormalsMatrix(const MeshType &mesh)
Get a #E Vector of booleans (or integers) containing the selection status of the elements identified ...
Definition export_matrix.h:447
Vect vertexColorsVector(const MeshType &mesh, Color::Format colorFormat)
Get a #V Vector of integers containing the colors of the vertices of a Mesh. The function is template...
Definition export_matrix.h:672
Vect faceIndicesVector(const MeshType &mesh)
Get a #V*3 Matrix of scalars containing the coordinates of the vertices of a Mesh....
Definition export_matrix.h:162
Matrix faceColorsMatrix(const MeshType &mesh)
Get a #F*4 Matrix of integers containing the colors of the faces of a Mesh. The function is templated...
Definition export_matrix.h:704
Matrix faceNormalsMatrix(const MeshType &mesh)
Get a #F*3 Matrix of scalars containing the normals of the faces of a Mesh. The function is templated...
Definition export_matrix.h:517
Vect faceQualityVector(const MeshType &mesh)
Get a #F Vector of scalars containing the quality of the faces of a Mesh. The function is templated o...
Definition export_matrix.h:848
Vect elementQualityVector(const MeshType &mesh)
Get a #E Vector of scalars containing the quality of the elements identified by ELEM_ID of a Mesh....
Definition export_matrix.h:776
Vect elementColorsVector(const MeshType &mesh, Color::Format colorFormat)
Get a #E Vector of integers containing the colors of the elements identified by ELEM_ID of a Mesh....
Definition export_matrix.h:598
Matrix edgeIndicesMatrix(const MeshType &mesh)
Get a #F*max(size(F)) Matrix of integers containing the vertex indices for each face of a Mesh.
Definition export_matrix.h:299
Matrix elementColorsMatrix(const MeshType &mesh)
Get a #E*4 Matrix of integers containing the colors of the elements identified by ELEM_ID of a Mesh....
Definition export_matrix.h:552
Matrix vertexNormalsMatrix(const MeshType &mesh)
Get a #V*3 Matrix of scalars containing the normals of the vertices of a Mesh. The function is templa...
Definition export_matrix.h:485
Vect faceColorsVector(const MeshType &mesh, Color::Format colorFormat)
Get a #F Vector of integers containing the colors of the faces of a Mesh. The function is templated o...
Definition export_matrix.h:740
MatrixStorageType
A simple type that enumerates the main storage types for matrices (row or column major).
Definition base.h:76