Skip to content

Commit a1b2543

Browse files
committed
move mesh tests in MRTest
1 parent 0970865 commit a1b2543

File tree

2 files changed

+112
-113
lines changed

2 files changed

+112
-113
lines changed

source/MRMesh/MRMesh.cpp

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "MRConstants.h"
1111
#include "MRCube.h"
1212
#include "MREdgeIterator.h"
13-
#include "MRGTest.h"
1413
#include "MRLine3.h"
1514
#include "MRLineSegm.h"
15+
#include "MRPlane3.h"
1616
#include "MRMeshBuilder.h"
1717
#include "MRMeshIntersect.h"
1818
#include "MRMeshTriPoint.h"
@@ -27,7 +27,6 @@
2727
#include "MRMeshFillHole.h"
2828
#include "MRTriMesh.h"
2929
#include "MRDipole.h"
30-
#include "MRPch/MRTBB.h"
3130

3231
namespace MR
3332
{
@@ -605,115 +604,4 @@ void Mesh::mirror( const Plane3f& plane )
605604
invalidateCaches();
606605
}
607606

608-
TEST( MRMesh, BasicExport )
609-
{
610-
Mesh mesh = makeCube();
611-
612-
const std::vector<ThreeVertIds> triangles = mesh.topology.getAllTriVerts();
613-
614-
const std::vector<Vector3f> & points = mesh.points.vec_;
615-
const int * vertexTripples = reinterpret_cast<const int*>( triangles.data() );
616-
617-
(void)points;
618-
(void)vertexTripples;
619-
}
620-
621-
TEST(MRMesh, SplitEdge)
622-
{
623-
Triangulation t{
624-
{ VertId{0}, VertId{1}, VertId{2} },
625-
{ VertId{0}, VertId{2}, VertId{3} }
626-
};
627-
Mesh mesh;
628-
mesh.topology = MeshBuilder::fromTriangles( t );
629-
mesh.points.emplace_back( 0.f, 0.f, 0.f );
630-
mesh.points.emplace_back( 1.f, 0.f, 0.f );
631-
mesh.points.emplace_back( 1.f, 1.f, 0.f );
632-
mesh.points.emplace_back( 0.f, 1.f, 0.f );
633-
634-
EXPECT_EQ( mesh.topology.numValidVerts(), 4 );
635-
EXPECT_EQ( mesh.points.size(), 4 );
636-
EXPECT_EQ( mesh.topology.numValidFaces(), 2 );
637-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(9) ); // 5*2 = 10 half-edges in total
638-
639-
FaceBitSet region( 2 );
640-
region.set( 0_f );
641-
642-
auto e02 = mesh.topology.findEdge( VertId{0}, VertId{2} );
643-
EXPECT_TRUE( e02.valid() );
644-
auto ex = mesh.splitEdge( e02, &region );
645-
VertId v02 = mesh.topology.org( e02 );
646-
EXPECT_EQ( mesh.topology.dest( ex ), v02 );
647-
EXPECT_EQ( mesh.topology.numValidVerts(), 5 );
648-
EXPECT_EQ( mesh.points.size(), 5 );
649-
EXPECT_EQ( mesh.topology.numValidFaces(), 4 );
650-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(15) ); // 8*2 = 16 half-edges in total
651-
EXPECT_EQ( mesh.points[v02], ( Vector3f(.5f, .5f, 0.f) ) );
652-
EXPECT_EQ( region.count(), 2 );
653-
654-
auto e01 = mesh.topology.findEdge( VertId{0}, VertId{1} );
655-
EXPECT_TRUE( e01.valid() );
656-
auto ey = mesh.splitEdge( e01, &region );
657-
VertId v01 = mesh.topology.org( e01 );
658-
EXPECT_EQ( mesh.topology.dest( ey ), v01 );
659-
EXPECT_EQ( mesh.topology.numValidVerts(), 6 );
660-
EXPECT_EQ( mesh.points.size(), 6 );
661-
EXPECT_EQ( mesh.topology.numValidFaces(), 5 );
662-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(19) ); // 10*2 = 20 half-edges in total
663-
EXPECT_EQ( mesh.points[v01], ( Vector3f(.5f, 0.f, 0.f) ) );
664-
EXPECT_EQ( region.count(), 3 );
665-
}
666-
667-
TEST(MRMesh, SplitEdge1)
668-
{
669-
Mesh mesh;
670-
const auto e01 = mesh.topology.makeEdge();
671-
mesh.topology.setOrg( e01, mesh.topology.addVertId() );
672-
mesh.topology.setOrg( e01.sym(), mesh.topology.addVertId() );
673-
mesh.points.emplace_back( 0.f, 0.f, 0.f );
674-
mesh.points.emplace_back( 1.f, 0.f, 0.f );
675-
676-
EXPECT_EQ( mesh.topology.numValidVerts(), 2 );
677-
EXPECT_EQ( mesh.points.size(), 2 );
678-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(1) ); // 1*2 = 2 half-edges in total
679-
680-
auto ey = mesh.splitEdge( e01 );
681-
VertId v01 = mesh.topology.org( e01 );
682-
EXPECT_EQ( mesh.topology.dest( ey ), v01 );
683-
EXPECT_EQ( mesh.topology.numValidVerts(), 3 );
684-
EXPECT_EQ( mesh.points.size(), 3 );
685-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(3) ); // 2*2 = 4 half-edges in total
686-
EXPECT_EQ( mesh.points[v01], ( Vector3f( .5f, 0.f, 0.f ) ) );
687-
}
688-
689-
TEST(MRMesh, SplitFace)
690-
{
691-
Triangulation t{
692-
{ VertId{0}, VertId{1}, VertId{2} }
693-
};
694-
Mesh mesh;
695-
mesh.topology = MeshBuilder::fromTriangles( t );
696-
mesh.points.emplace_back( 0.f, 0.f, 0.f );
697-
mesh.points.emplace_back( 0.f, 0.f, 1.f );
698-
mesh.points.emplace_back( 0.f, 1.f, 0.f );
699-
700-
EXPECT_EQ( mesh.topology.numValidVerts(), 3 );
701-
EXPECT_EQ( mesh.points.size(), 3 );
702-
EXPECT_EQ( mesh.topology.numValidFaces(), 1 );
703-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(5) ); // 3*2 = 6 half-edges in total
704-
705-
mesh.splitFace( 0_f );
706-
EXPECT_EQ( mesh.topology.numValidVerts(), 4 );
707-
EXPECT_EQ( mesh.points.size(), 4 );
708-
EXPECT_EQ( mesh.topology.numValidFaces(), 3 );
709-
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(11) ); // 6*2 = 12 half-edges in total
710-
}
711-
712-
TEST( MRMesh, isOutside )
713-
{
714-
Mesh mesh = makeCube();
715-
EXPECT_TRUE( mesh.isOutside( Vector3f( 2, 0, 0 ) ) );
716-
EXPECT_FALSE( mesh.isOutside( Vector3f( 0, 0, 0 ) ) );
717-
}
718-
719607
} //namespace MR

source/MRTest/MRMeshTests.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,115 @@ TEST(MRMesh, AddMeshPart)
320320
EXPECT_EQ( edgeHashMap.getHashMap()->size(), ne );
321321
}
322322

323+
TEST( MRMesh, BasicExport )
324+
{
325+
Mesh mesh = makeCube();
326+
327+
const std::vector<ThreeVertIds> triangles = mesh.topology.getAllTriVerts();
328+
329+
const std::vector<Vector3f> & points = mesh.points.vec_;
330+
const int * vertexTripples = reinterpret_cast<const int*>( triangles.data() );
331+
332+
(void)points;
333+
(void)vertexTripples;
334+
}
335+
336+
TEST(MRMesh, SplitEdge)
337+
{
338+
Triangulation t{
339+
{ VertId{0}, VertId{1}, VertId{2} },
340+
{ VertId{0}, VertId{2}, VertId{3} }
341+
};
342+
Mesh mesh;
343+
mesh.topology = MeshBuilder::fromTriangles( t );
344+
mesh.points.emplace_back( 0.f, 0.f, 0.f );
345+
mesh.points.emplace_back( 1.f, 0.f, 0.f );
346+
mesh.points.emplace_back( 1.f, 1.f, 0.f );
347+
mesh.points.emplace_back( 0.f, 1.f, 0.f );
348+
349+
EXPECT_EQ( mesh.topology.numValidVerts(), 4 );
350+
EXPECT_EQ( mesh.points.size(), 4 );
351+
EXPECT_EQ( mesh.topology.numValidFaces(), 2 );
352+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(9) ); // 5*2 = 10 half-edges in total
353+
354+
FaceBitSet region( 2 );
355+
region.set( 0_f );
356+
357+
auto e02 = mesh.topology.findEdge( VertId{0}, VertId{2} );
358+
EXPECT_TRUE( e02.valid() );
359+
auto ex = mesh.splitEdge( e02, &region );
360+
VertId v02 = mesh.topology.org( e02 );
361+
EXPECT_EQ( mesh.topology.dest( ex ), v02 );
362+
EXPECT_EQ( mesh.topology.numValidVerts(), 5 );
363+
EXPECT_EQ( mesh.points.size(), 5 );
364+
EXPECT_EQ( mesh.topology.numValidFaces(), 4 );
365+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(15) ); // 8*2 = 16 half-edges in total
366+
EXPECT_EQ( mesh.points[v02], ( Vector3f(.5f, .5f, 0.f) ) );
367+
EXPECT_EQ( region.count(), 2 );
368+
369+
auto e01 = mesh.topology.findEdge( VertId{0}, VertId{1} );
370+
EXPECT_TRUE( e01.valid() );
371+
auto ey = mesh.splitEdge( e01, &region );
372+
VertId v01 = mesh.topology.org( e01 );
373+
EXPECT_EQ( mesh.topology.dest( ey ), v01 );
374+
EXPECT_EQ( mesh.topology.numValidVerts(), 6 );
375+
EXPECT_EQ( mesh.points.size(), 6 );
376+
EXPECT_EQ( mesh.topology.numValidFaces(), 5 );
377+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(19) ); // 10*2 = 20 half-edges in total
378+
EXPECT_EQ( mesh.points[v01], ( Vector3f(.5f, 0.f, 0.f) ) );
379+
EXPECT_EQ( region.count(), 3 );
380+
}
381+
382+
TEST(MRMesh, SplitEdge1)
383+
{
384+
Mesh mesh;
385+
const auto e01 = mesh.topology.makeEdge();
386+
mesh.topology.setOrg( e01, mesh.topology.addVertId() );
387+
mesh.topology.setOrg( e01.sym(), mesh.topology.addVertId() );
388+
mesh.points.emplace_back( 0.f, 0.f, 0.f );
389+
mesh.points.emplace_back( 1.f, 0.f, 0.f );
390+
391+
EXPECT_EQ( mesh.topology.numValidVerts(), 2 );
392+
EXPECT_EQ( mesh.points.size(), 2 );
393+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(1) ); // 1*2 = 2 half-edges in total
394+
395+
auto ey = mesh.splitEdge( e01 );
396+
VertId v01 = mesh.topology.org( e01 );
397+
EXPECT_EQ( mesh.topology.dest( ey ), v01 );
398+
EXPECT_EQ( mesh.topology.numValidVerts(), 3 );
399+
EXPECT_EQ( mesh.points.size(), 3 );
400+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(3) ); // 2*2 = 4 half-edges in total
401+
EXPECT_EQ( mesh.points[v01], ( Vector3f( .5f, 0.f, 0.f ) ) );
402+
}
403+
404+
TEST(MRMesh, SplitFace)
405+
{
406+
Triangulation t{
407+
{ VertId{0}, VertId{1}, VertId{2} }
408+
};
409+
Mesh mesh;
410+
mesh.topology = MeshBuilder::fromTriangles( t );
411+
mesh.points.emplace_back( 0.f, 0.f, 0.f );
412+
mesh.points.emplace_back( 0.f, 0.f, 1.f );
413+
mesh.points.emplace_back( 0.f, 1.f, 0.f );
414+
415+
EXPECT_EQ( mesh.topology.numValidVerts(), 3 );
416+
EXPECT_EQ( mesh.points.size(), 3 );
417+
EXPECT_EQ( mesh.topology.numValidFaces(), 1 );
418+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(5) ); // 3*2 = 6 half-edges in total
419+
420+
mesh.splitFace( 0_f );
421+
EXPECT_EQ( mesh.topology.numValidVerts(), 4 );
422+
EXPECT_EQ( mesh.points.size(), 4 );
423+
EXPECT_EQ( mesh.topology.numValidFaces(), 3 );
424+
EXPECT_EQ( mesh.topology.lastNotLoneEdge(), EdgeId(11) ); // 6*2 = 12 half-edges in total
425+
}
426+
427+
TEST( MRMesh, isOutside )
428+
{
429+
Mesh mesh = makeCube();
430+
EXPECT_TRUE( mesh.isOutside( Vector3f( 2, 0, 0 ) ) );
431+
EXPECT_FALSE( mesh.isOutside( Vector3f( 0, 0, 0 ) ) );
432+
}
433+
323434
} //namespace MR

0 commit comments

Comments
 (0)