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
|
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <TopoDS_Shape.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <gtest/gtest.h>
/* @TODO: in the following tests, minimal distances between two shapes.
It's not obvious anyway to figure out the relationship between the deflection passed to
BRepExtrema_DistSS (related to the mesh quality) and the precision of the output.
This has to be investigated further.
*/
TEST(BRepExtremaTestSuite, testDistSphereSphere)
{
// the distance d between sphere1, centered at origin and radius r1, and
// sphere 2, centered at (a,0,0) and radius r2
// should be d = a-(r1+r2)
Standard_Real r1 = 10.0;
BRepPrimAPI_MakeSphere sphere1(r1);
TopoDS_Shape sphere1_shp = sphere1.Shape();
Standard_Real a = 100.0;
Standard_Real r2 = 20.0;
gp_Pnt center2(a,0,0);
BRepPrimAPI_MakeSphere sphere2(center2,r2);
TopoDS_Shape sphere2_shp = sphere2.Shape();
BRepExtrema_DistShapeShape distSS;
distSS.LoadS1(sphere1_shp);
distSS.LoadS2(sphere2_shp);
distSS.Perform();
// should only be one minimal value
ASSERT_EQ(distSS.NbSolution(),1);
// this value should be
Standard_Real expected_result = a-(r1+r2);
Standard_Real min_dist = distSS.Value();
// @TODO: should compare with a precision
float abs_error = 0.001;
ASSERT_NEAR(expected_result,min_dist,abs_error);
}
TEST(BRepExtremaTestSuite, testDistSphereVertex)
{
// the distance d between sphere1, centered at origin and radius r1, and
// vertex, a point of coordinates (a,b,c)
// should be d = sqrt(a^2+b^2+c^2)-r1
Standard_Real r1 = 10.0;
BRepPrimAPI_MakeSphere sphere1(r1);
TopoDS_Shape sphere1_shp = sphere1.Shape();
Standard_Real a = 100.0;
Standard_Real b = 50.0;
Standard_Real c = 20.0;
gp_Pnt point(a,b,c);
TopoDS_Vertex V=BRepBuilderAPI_MakeVertex(point).Vertex();
BRepExtrema_DistShapeShape distSS;
distSS.LoadS1(sphere1_shp);
distSS.LoadS2(V);
distSS.SetDeflection(0.001);
distSS.Perform();
// should only be one minimal value
ASSERT_EQ(distSS.NbSolution(),1);
// this value should be
gp_Vec v(a,b,c);
Standard_Real expected_result = v.Magnitude()-r1;
Standard_Real min_dist = distSS.Value();
float abs_error = 0.001;
ASSERT_NEAR(expected_result,min_dist,abs_error);
}
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|