-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMesh.cpp
217 lines (193 loc) · 6.19 KB
/
TestMesh.cpp
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/**
* @file TestMesh.cpp
* @brief Unit test of Mesh class
* @author cromod
* @date july 2015
*/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE TestMesh
#include <boost/test/unit_test.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System/Clock.hpp>
#include <iostream>
#include "Mesh.hpp"
#include "Exception.hpp"
using namespace Cromod::GeomAPI ;
using namespace Cromod::Tools ;
using namespace std ;
BOOST_AUTO_TEST_CASE( BasicTests )
{
cout << "- Default constructor test" << endl;
try {
Mesh mesh;
}
catch(...) {
BOOST_FAIL("Default constructor failure");
}
cout << "- Copy constructor test" << endl;
Mesh mesh;
try {
Mesh new_mesh(mesh);
}
catch(...) {
BOOST_FAIL("Copy constructor failure");
}
cout << "- Mesh::addNode test" << endl;
double val1[] = {0.,1.};
Point point1(val1,2);
Node node1(point1);
try {
mesh.addNode(node1);
}
catch(...) {
BOOST_FAIL("Mesh::addNode failure");
}
cout << "- Mesh::size test" << endl;
double val2[] = {2.,1.};
Point point2(val2,2);
Node node2(point2);
mesh.addNode(node2);
BOOST_REQUIRE_MESSAGE(mesh.size()==2,"Mesh::size failure");
cout << "- [] operator test" << endl;
BOOST_REQUIRE_MESSAGE(mesh[0]==node1,"[] operator failure");
cout << "- Mesh::deleteNode test" << endl;
double val3[] = {0.,1.};
Point point3(val3,2);
Node node3(point3);
mesh.addNode(node3);
try {
mesh.deleteNode();
}
catch(...) {
BOOST_FAIL("Mesh::deleteNode failure");
}
BOOST_REQUIRE_MESSAGE(mesh.size()==2,"Mesh::deleteNode failure");
cout << "- Mesh::deleteAll test" << endl;
try {
mesh.deleteAll();
}
catch(...) {
BOOST_FAIL("Mesh::deleteAll failure");
}
BOOST_REQUIRE_MESSAGE(mesh.size()==0,"Mesh::deleteAll failure");
}
BOOST_AUTO_TEST_CASE( MethodTests )
{
double listVal[13][2]= {{200.,-100.},{200.,50.},{150.,100.},{100.,100.},{100.,200.},{-100.,200.},{-100.,100.},
{-200.,100.},{-200.,-100.},{-100.,-100.},{-100.,-200.},{100.,-200.},{100.,-100.}};
vector<Point> listPoints;
for(int i=0; i<13; i++) {
Point point(listVal[i],2);
listPoints.push_back(point);
}
Polygon polygon(listPoints);
Mesh mesh;
cout << "- Mesh::setPolygon test" << endl;
try {
mesh.setPolygon(polygon);
}
catch(...) {
BOOST_FAIL("Mesh::setPolygon failure");
}
cout << "- Mesh::getPolygon test" << endl;
try {
Polygon pol(mesh.getPolygon());
}
catch(...) {
BOOST_FAIL("Mesh::getPolygon failure");
}
cout << "- Mesh::setStep test" << endl;
try {
mesh.setStep(10.);
}
catch(...) {
BOOST_FAIL("Mesh::setStep failure");
}
cout << "- Mesh::getStep test" << endl;
BOOST_REQUIRE_MESSAGE(mesh.getStep()==10.,"Mesh::getStep failure");
cout << "- Mesh::setInitGrid test" << endl;
try {
mesh.setInitGrid();
}
catch(...) {
BOOST_FAIL("Mesh::setInitGrid failure");
}
cout << " Nb of node = " << mesh.size() << endl;
BOOST_REQUIRE_MESSAGE(mesh.size()==1849,"Mesh::setInitGrid failure");
cout << "- Mesh::isInit test" << endl;
BOOST_REQUIRE_MESSAGE(mesh.isInit(),"Mesh::isInit failure");
cout << "- Mesh::setInit test" << endl;
try {
mesh.setInit(false);
}
catch(...) {
BOOST_FAIL("Mesh::setInit failure");
}
BOOST_REQUIRE_MESSAGE(!mesh.isInit(),"Mesh::setInit failure");
cout << "- Mesh::detectNode test" << endl;
try {
mesh.detectNode();
}
catch(...) {
BOOST_FAIL("Mesh::detectNode failure");
}
cout << " Nb of node = " << mesh.size() << endl;
BOOST_REQUIRE_MESSAGE(mesh.size()==1849,"Mesh::detectNode failure");
cout << "- Mesh::isDetect test" << endl;
BOOST_REQUIRE_MESSAGE(mesh.isDetect(),"Mesh::isDetect failure");
cout << "- Mesh::setDetect test" << endl;
try {
mesh.setDetect(false);
}
catch(...) {
BOOST_FAIL("Mesh::setDetect failure");
}
BOOST_REQUIRE_MESSAGE(!mesh.isDetect(),"Mesh::setInit failure");
cout << "- Mesh::getDim test" << endl;
mesh.setInit(true);
BOOST_REQUIRE_MESSAGE(mesh.getDim()[0]==43,"Mesh::getDim failure");
BOOST_REQUIRE_MESSAGE(mesh.getDim()[1]==43,"Mesh::getDim failure");
cout << "- Mesh::setDim test" << endl;
vector<int> dim;
dim.push_back(43);
dim.push_back(43);
mesh.setDim(dim);
BOOST_REQUIRE_MESSAGE(mesh.getDim()[0]==43,"Mesh::getDim failure");
BOOST_REQUIRE_MESSAGE(mesh.getDim()[1]==43,"Mesh::getDim failure");
cout << "- Graphic test of Mesh" << endl;
sf::RenderWindow window(sf::VideoMode(500, 500), "Test of Mesh class");
// on fait tourner le programme jusqu'à ce que la fenêtre soit fermée
sf::Clock clock;
sf::Time time;
while (window.isOpen() && time.asSeconds()<2.0) {
// on inspecte tous les evenements de la fenetre qui ont ete emis depuis la precedente itération
sf::Event event;
while (window.pollEvent(event)) {
// evenement "fermeture demandee" : on ferme la fenetre
if (event.type == sf::Event::Closed)
window.close();
}
// fenetre en blanc
window.clear(sf::Color::White);
// trace du maillage
for(unsigned int i=0; i<mesh.size(); i++) {
Point point(mesh[i].getPosition());
sf::CircleShape c_in(4);
c_in.setOrigin(4.,4.);
c_in.setFillColor(sf::Color::Green);
c_in.setPosition(point[0]+250.,point[1]+250.);
window.draw(c_in);
if (mesh[i].isNearEdge()) {
sf::CircleShape c_near(2);
c_near.setOrigin(2.,2.);
c_near.setFillColor(sf::Color::Red);
c_near.setPosition(point[0]+250.,point[1]+250.);
window.draw(c_near);
}
}
// fin de la frame courante, affichage de tout ce qu'on a dessine
window.display();
time = clock.getElapsedTime();
}
}