Skip to content

Commit 9f0aa87

Browse files
authored
Export of points and triangles from mesh (#131)
1 parent 9ba5689 commit 9f0aa87

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

doxygen/HowToExamples.dox

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ mesh.transform( rotationXf );
5252
\sa \ref MR::subdivideMesh
5353
\sa \ref MR::Mesh
5454

55+
Export example of points and triangles from mesh (e.g. for rendering)
56+
57+
\code
58+
// create some mesh
59+
Mesh mesh = makeCube();
60+
61+
// all vertices of valid triangles
62+
const std::vector<std::array<VertId, 3>> triangles = mesh.topology.getAllTriVerts();
63+
64+
// all point coordinates
65+
const std::vector<Vector3f> & points = mesh.points.vec_;
66+
// triangle vertices as tripples of ints (pointing to elements in points vector)
67+
const int * vertexTripples = reinterpret_cast<const int*>( triangles.data() );
68+
\endcode
69+
5570
\section PythonCodeExamples Python Basic Examples
5671

5772
In this section we provide the same examples but with python code\n

source/MRMesh/MRMesh.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "MRLineSegm.h"
1515
#include "MRConstants.h"
1616
#include "MRComputeBoundingBox.h"
17+
#include "MRGTest.h"
18+
#include "MRCube.h"
1719
#include "MRPch/MRTBB.h"
1820

1921
namespace
@@ -776,4 +778,17 @@ Vector3f Mesh::findCenterFromBBox() const
776778
return computeBoundingBox().center();
777779
}
778780

781+
TEST( MRMesh, BasicExport )
782+
{
783+
Mesh mesh = makeCube();
784+
785+
const std::vector<std::array<VertId, 3>> triangles = mesh.topology.getAllTriVerts();
786+
787+
const std::vector<Vector3f> & points = mesh.points.vec_;
788+
const int * vertexTripples = reinterpret_cast<const int*>( triangles.data() );
789+
790+
(void)points;
791+
(void)vertexTripples;
792+
}
793+
779794
} //namespace MR

source/MRMesh/MRMeshTopology.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ void MeshTopology::getLeftTriVerts( EdgeId a, VertId & v0, VertId & v1, VertId &
195195
assert( a == prev( c.sym() ) );
196196
}
197197

198+
std::vector<std::array<VertId, 3>> MeshTopology::getAllTriVerts() const
199+
{
200+
MR_TIMER
201+
std::vector<std::array<VertId, 3>> res;
202+
res.reserve( numValidFaces_ );
203+
for ( auto f : validFaces_ )
204+
{
205+
VertId vs[3];
206+
getTriVerts( f, vs );
207+
res.push_back( { vs[0], vs[1], vs[2] } );
208+
}
209+
210+
return res;
211+
}
212+
198213
bool MeshTopology::isLeftQuad( EdgeId a ) const
199214
{
200215
assert( a.valid() );

source/MRMesh/MRMeshTopology.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class MeshTopology
7272
// the vertices are returned in counter-clockwise order if look from mesh outside
7373
void getTriVerts( FaceId f, VertId & v0, VertId & v1, VertId & v2 ) const { getLeftTriVerts( edgeWithLeft( f ), v0, v1, v2 ); }
7474
void getTriVerts( FaceId f, VertId (&v)[3] ) const { getTriVerts( f, v[0], v[1], v[2] ); }
75+
// returns all valid triangle vertices
76+
[[nodiscard]] MRMESH_API std::vector<std::array<VertId, 3>> getAllTriVerts() const;
7577
// gets 3 vertices of the left face ( face-id may not exist, but the shape must be triangular)
7678
// the vertices are returned in counter-clockwise order if look from mesh outside
7779
MRMESH_API void getLeftTriVerts( EdgeId a, VertId & v0, VertId & v1, VertId & v2 ) const;

0 commit comments

Comments
 (0)