3 #include "TestUtils.hxx"
4 #include "BrepGeometryTest.hxx"
5 #include "../XAO_XaoUtils.hxx"
6 #include "../XAO_Xao.hxx"
7 #include "../XAO_BrepGeometry.hxx"
11 void BrepGeometryTest::setUp()
15 void BrepGeometryTest::tearDown()
19 void BrepGeometryTest::cleanUp()
23 void readBrep(Geometry* geom, const std::string& fileName)
25 char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
26 geom->setShapeString(txt);
29 void BrepGeometryTest::testGetIDs()
31 BrepGeometry* geom = new BrepGeometry("box");
32 readBrep(geom, "Box_1.brep");
34 CPPUNIT_ASSERT_EQUAL(8, geom->countElements(XAO::VERTEX));
35 CPPUNIT_ASSERT_EQUAL(8, geom->countVertices());
36 int vertices[8] = { 6,7,9,11,16,17,19,21 };
37 for (int i = 0; i < 8; ++i)
38 CPPUNIT_ASSERT_EQUAL(vertices[i], geom->getVertexID(i));
40 CPPUNIT_ASSERT_EQUAL(12, geom->countElements(XAO::EDGE));
41 CPPUNIT_ASSERT_EQUAL(12, geom->countEdges());
42 int edges[12] = { 5,8,10,12,15,18,20,22,25,26,29,30 };
43 for (int i = 0; i < 12; ++i)
44 CPPUNIT_ASSERT_EQUAL(edges[i], geom->getEdgeID(i));
46 CPPUNIT_ASSERT_EQUAL(6, geom->countElements(XAO::FACE));
47 CPPUNIT_ASSERT_EQUAL(6, geom->countFaces());
48 int faces[6] = { 3,13,23,27,31,33 };
49 for (int i = 0; i < 6; ++i)
50 CPPUNIT_ASSERT_EQUAL(faces[i], geom->getFaceID(i));
52 CPPUNIT_ASSERT_EQUAL(1, geom->countElements(XAO::SOLID));
53 CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
54 CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
59 void BrepGeometryTest::testGetReferences()
61 BrepGeometry* geom = new BrepGeometry("box");
62 readBrep(geom, "Box_1.brep");
64 // vertex of index 1 has id = 7
65 CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getElementReference(XAO::VERTEX, 1));
66 CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getVertexReference(1));
67 CPPUNIT_ASSERT_EQUAL(7, geom->getVertexID(1));
68 CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::VERTEX, "7"));
69 CPPUNIT_ASSERT_EQUAL(1, geom->findVertex(7));
71 // edge of index 1 has id = 8
72 CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getElementReference(XAO::EDGE, 1));
73 CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getEdgeReference(1));
74 CPPUNIT_ASSERT_EQUAL(8, geom->getEdgeID(1));
75 CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::EDGE, "8"));
76 CPPUNIT_ASSERT_EQUAL(1, geom->findEdge(8));
78 // face of index 1 has id = 13
79 CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getElementReference(XAO::FACE, 1));
80 CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getFaceReference(1));
81 CPPUNIT_ASSERT_EQUAL(13, geom->getFaceID(1));
82 CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::FACE, "13"));
83 CPPUNIT_ASSERT_EQUAL(1, geom->findFace(13));
85 // solid of index 0 has id = 1
86 CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getElementReference(XAO::SOLID, 0));
87 CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getSolidReference(0));
88 CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
89 CPPUNIT_ASSERT_EQUAL(0, geom->getElementIndexByReference(XAO::SOLID, "1"));
90 CPPUNIT_ASSERT_EQUAL(0, geom->findSolid(1));
95 void BrepGeometryTest::testGetNames()
97 BrepGeometry* geom = new BrepGeometry("box");
98 readBrep(geom, "Box_1.brep");
102 // vertex of index 1 has id = 7
104 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findVertexName(id));
105 geom->changeVertexName(id, std::string("va"));
106 CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->findVertexName(id));
107 CPPUNIT_ASSERT_THROW(geom->changeVertexName(100, "a"), XAO_Exception);
108 CPPUNIT_ASSERT_THROW(geom->findVertexName(100), XAO_Exception);
110 // edge of index 1 has id = 8
112 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findEdgeName(id));
113 geom->changeEdgeName(id, std::string("ea"));
114 CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->findEdgeName(id));
115 CPPUNIT_ASSERT_THROW(geom->changeEdgeName(100, "a"), XAO_Exception);
116 CPPUNIT_ASSERT_THROW(geom->findEdgeName(100), XAO_Exception);
118 // face of index 1 has id = 13
120 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findFaceName(id));
121 geom->changeFaceName(id, std::string("fa"));
122 CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->findFaceName(id));
123 CPPUNIT_ASSERT_THROW(geom->changeFaceName(100, "a"), XAO_Exception);
124 CPPUNIT_ASSERT_THROW(geom->findFaceName(100), XAO_Exception);
126 // solid of index 0 has id = 1
128 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findSolidName(id));
129 geom->changeSolidName(id, std::string("sa"));
130 CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->findSolidName(id));
131 CPPUNIT_ASSERT_THROW(geom->changeSolidName(100, "a"), XAO_Exception);
132 CPPUNIT_ASSERT_THROW(geom->findSolidName(100), XAO_Exception);
137 void BrepGeometryTest::testGetEdgeVertices()
139 BrepGeometry* geom = new BrepGeometry("box");
140 readBrep(geom, "Box_2.brep");
142 // edge of index 23, id = #63
143 // vertex are 47 (#12), 59 (#15)
145 geom->getEdgeVertices(23, v1, v2);
146 CPPUNIT_ASSERT_EQUAL(12, v1);
147 CPPUNIT_ASSERT_EQUAL(15, v2);
152 void printVector(std::vector<int>& v)
155 for (int i = 0; i < v.size(); i++)
156 std::cout << v[i] << ", ";
157 std::cout << std::endl;
160 void BrepGeometryTest::testGetFaceEdges()
162 BrepGeometry* geom = new BrepGeometry("box");
163 readBrep(geom, "Box_2.brep");
165 CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(1)); // face 13
166 CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(2)); // face 29
168 // wire 0 of face 1 (#13) => edge 4 (#15), 5 (#17), 0 (#5), 6 (#19)
169 std::vector<int> edges = geom->getFaceEdges(1, 0);
170 CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
171 int ids1[4] = { 4,5,0,6 };
172 for (int i = 0; i < 4; ++i)
173 CPPUNIT_ASSERT_EQUAL(ids1[i], edges[i]);
175 // wire 1 of face 13 => edge 7 (#21) ,8 (#24), 9 (#26), 10 (#28)
176 edges = geom->getFaceEdges(1, 1);
177 CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
178 int ids2[4] = { 7,8,9,10 };
179 for (int i = 0; i < 4; ++i)
180 CPPUNIT_ASSERT_EQUAL(ids2[i], edges[i]);
185 void BrepGeometryTest::testSolidFaces()
187 BrepGeometry* geom = new BrepGeometry("box");
188 readBrep(geom, "Cut_2.brep");
190 CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(0));
192 std::vector<int> faces = geom->getSolidFaces(0, 0);
193 CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
194 int ids[6] = { 0, 1, 2, 3, 4, 5 };
195 for (int i = 0; i < 6; ++i)
196 CPPUNIT_ASSERT_EQUAL(ids[i], faces[i]);
198 faces = geom->getSolidFaces(0, 1);
199 CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
200 int ids2[6] = { 6, 7, 8, 9, 10, 11 };
201 for (int i = 0; i < 6; ++i)
202 CPPUNIT_ASSERT_EQUAL(ids2[i], faces[i]);
207 void BrepGeometryTest::testGetVertex()
209 BrepGeometry* geom = new BrepGeometry("box");
210 readBrep(geom, "Box_2.brep");
213 geom->getVertexXYZ(15, x, y, z);
214 CPPUNIT_ASSERT_DOUBLES_EQUAL(60., x, 1e-6);
215 CPPUNIT_ASSERT_DOUBLES_EQUAL(80., y, 1e-6);
216 CPPUNIT_ASSERT_DOUBLES_EQUAL(60., z, 1e-6);
221 void BrepGeometryTest::testGetEdgeLength()
223 BrepGeometry* geom = new BrepGeometry("box");
224 readBrep(geom, "Box_2.brep");
226 // edges 0 (#5), 7 (#21)
227 CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(0), 0);
228 CPPUNIT_ASSERT_DOUBLES_EQUAL(80., geom->getEdgeLength(7), 0);
233 void BrepGeometryTest::testGetFaceArea()
235 BrepGeometry* geom = new BrepGeometry("box");
236 readBrep(geom, "Box_2.brep");
238 // faces 0 (#3), 1 (#13)
239 CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(0), 1e-9);
240 CPPUNIT_ASSERT_DOUBLES_EQUAL(33600., geom->getFaceArea(1), 1e-9);
245 void BrepGeometryTest::testGetSolidVolume()
247 BrepGeometry* geom = new BrepGeometry("box");
248 readBrep(geom, "Box_2.brep");
250 CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(0), 1e-9);
255 void BrepGeometryTest::testParse()
257 BrepGeometry* geom = new BrepGeometry("box");
258 readBrep(geom, "Box_2.brep");
259 std::cout << std::endl;
261 for (int solidIndex = 0; solidIndex < geom->countSolids(); ++solidIndex)
263 std::cout << "Solid #" << solidIndex << " : " << geom->getSolidReference(solidIndex) << std::endl;
264 int nbShells = geom->countSolidShells(solidIndex);
265 for (int shellIndex = 0; shellIndex < nbShells; ++shellIndex)
267 std::cout << " Shell #" << shellIndex << std::endl;
268 std::vector<int> faces = geom->getSolidFaces(solidIndex, shellIndex);
269 for (int indf = 0; indf < faces.size(); ++indf)
271 int faceIndex = faces[indf];
272 std::cout << " Face #" << geom->getFaceReference(faceIndex) << std::endl;
274 int nbWires = geom->countFaceWires(faceIndex);
275 for (int wireIndex = 0; wireIndex < nbWires; ++wireIndex)
277 std::cout << " Wire #" << wireIndex << std::endl;
278 std::vector<int> edges = geom->getFaceEdges(faceIndex, wireIndex);
279 for (int inde = 0; inde < edges.size(); ++inde)
281 int edgeIndex = edges[inde];
282 std::cout << " Edge #" << geom->getEdgeReference(edgeIndex) << " : ";
285 geom->getEdgeVertices(edgeIndex, va, vb);
286 int vaRef = geom->getVertexID(va);
287 int vbRef = geom->getVertexID(vb);
288 double ax, ay, az, bx, by, bz;
289 geom->getVertexXYZ(va, ax, ay, az);
290 geom->getVertexXYZ(vb, bx, by, bz);
292 std::cout << vaRef << " (" << ax << ", " << ay << ", " << az << ")";
294 std::cout << vbRef << " (" << bx << ", " << by << ", " << bz << ")";
295 std::cout << std::endl;