-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTearingEngine_test.cpp
More file actions
169 lines (134 loc) · 5.44 KB
/
TearingEngine_test.cpp
File metadata and controls
169 lines (134 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*****************************************************************************
* - Copyright (C) 2020-Present InfinyTech3D - *
* *
* This file is part of the Tearing plugin for the SOFA framework. *
* *
* This file is dual-licensed: *
* *
* 1) Commercial License: *
* This file may be used under the terms of a valid commercial license *
* agreement provided wih the software by InfinyTech3D. *
* *
* 2) GNU General Public License (GPLv3) Usage *
* Alternatively, this file may be used under the terms of the *
* GNU General Public License version 3 as published by the *
* Free Software Foundation: https://www.gnu.org/licenses/gpl-3.0.html *
* *
* Contact: contact@infinytech3d.com *
* Further information: https://infinytech3d.com *
****************************************************************************/
//#include "TopologySceneLoader.h"
#include <sofa/testing/BaseSimulationTest.h>
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
#include <sofa/helper/system/FileRepository.h>
using namespace sofa::testing;
using namespace sofa::component::topology::container::dynamic;
class TearingEngine_test : public BaseSimulationTest
{
public:
//typedef TetrahedronSetGeometryAlgorithms<sofa::defaulttype::Vec3Types> TetraAlgo3;
//using TetrahedronCuttingManager3d = sofa::meshrefinement::TetrahedronCuttingManager<sofa::defaulttype::Vec3Types>;
//using TetrahedronSubdividersManager3d = sofa::meshrefinement::TetrahedronSubdividersManager<sofa::defaulttype::Vec3Types>;
/// Store SceneInstance
BaseSimulationTest::SceneInstance m_instance;
/// Name of the file to load
std::string m_fileName = "";
virtual bool testInit() = 0;
virtual bool testTearing() = 0;
void doSetUp() override
{
// Load the scene from the xml file
std::string filePath = std::string(SOFA_TEARING_TEST_SCENES_DIR) + "/" + m_fileName;
m_instance = BaseSimulationTest::SceneInstance();
// Load scene
m_instance.loadSceneFile(filePath);
// Init scene
m_instance.initScene();
// Test if root is not null
if (!m_instance.root)
{
ADD_FAILURE() << "Error while loading the scene: " << m_fileName << std::endl;
return;
}
}
/// Unload the scene
void doTearDown() override
{
if (m_instance.root != nullptr)
sofa::simulation::node::unload(m_instance.root);
}
protected:
TriangleSetTopologyContainer* getTopology()
{
Node::SPtr root = m_instance.root;
if (!root)
{
ADD_FAILURE() << "Error while loading the scene: " << m_fileName << std::endl;
return nullptr;
}
Node::SPtr nodeTopo = root.get()->getChild("SquareGravity");
if (!nodeTopo)
{
ADD_FAILURE() << "Error 'SquareGravity' Node not found in scene: " << m_fileName << std::endl;
return nullptr;
}
TriangleSetTopologyContainer* topoCon = dynamic_cast<TriangleSetTopologyContainer*>(nodeTopo->getMeshTopology());
if (topoCon == nullptr)
{
ADD_FAILURE() << "Error: TriangleSetTopologyContainer not found in 'SquareGravity' Node, in scene: " << m_fileName << std::endl;
return nullptr;
}
return topoCon;
}
private:
/// pointer to the topology scene
//TopologySceneLoader* m_scene;
//sofa::simulation::Simulation::SPtr m_simulation;
/// pointer to the topology container
//TetrahedronSetTopologyContainer* m_topoCon = nullptr;
};
struct TearingEngine_Case1 : public TearingEngine_test
{
TearingEngine_Case1() : TearingEngine_test()
{
m_fileName = "Benchmarks/Scenario-01_squareTissue_horizontal-cut.scn";
}
bool testInit() override
{
TriangleSetTopologyContainer* topoCon = this->getTopology();
if (topoCon == nullptr)
{
return false;
}
// check topology at start
EXPECT_EQ(topoCon->getNbTriangles(), 1450);
EXPECT_EQ(topoCon->getNbEdges(), 2223);
EXPECT_EQ(topoCon->getNbPoints(), 774);
return true;
}
bool testTearing() override
{
TriangleSetTopologyContainer* topoCon = this->getTopology();
if (topoCon == nullptr)
{
return false;
}
// to test incise animates the scene at least 1.2s
for (int i = 0; i < 100; i++)
{
m_instance.simulate(0.05);
}
EXPECT_EQ(topoCon->getNbTriangles(), 1505);
EXPECT_EQ(topoCon->getNbEdges(), 2334);
EXPECT_EQ(topoCon->getNbPoints(), 830);
return true;
}
};
TEST_F(TearingEngine_Case1, testInit)
{
ASSERT_TRUE(this->testInit());
}
TEST_F(TearingEngine_Case1, testTearing)
{
ASSERT_TRUE(this->testTearing());
}