File: BRepExtrema_test.cpp

package info (click to toggle)
oce 0.18.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 301,548 kB
  • sloc: cpp: 1,190,609; ansic: 67,225; sh: 11,630; tcl: 7,954; cs: 5,221; python: 2,867; java: 1,522; makefile: 342; xml: 292; perl: 37
file content (170 lines) | stat: -rw-r--r-- 5,325 bytes parent folder | download | duplicates (6)
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
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <TopoDS_Shape.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.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.001f;
    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.001f;
    ASSERT_NEAR(expected_result,min_dist,abs_error);
}

TEST(BRepExtremaTestSuite, testDistVertexEdge)
{
    gp_Pnt point(0.0, 0.0, 0.0);
    TopoDS_Vertex V=BRepBuilderAPI_MakeVertex(point).Vertex();
    gp_Pnt point1(-1.0, 1.0, 0.0);
    TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(point1).Vertex();
    gp_Pnt point2( 1.0, 1.0, 0.0);
    TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(point2).Vertex();
    TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(V1, V2);

    BRepExtrema_DistShapeShape distSS(V, edge);

    // should only be one minimal value
    ASSERT_EQ(distSS.NbSolution(),1);
    // this value should be V
    gp_Pnt res1 = distSS.PointOnShape1(1);
    Standard_Real dist = res1.Distance(point);

    ASSERT_NEAR(0.0, dist, 0.001);
}

// This test fails with OCCT >= 6.5.1
TEST(BRepExtremaTestSuite, testDistEdgeVertex)
{
    gp_Pnt point(0.0, 0.0, 0.0);
    TopoDS_Vertex V=BRepBuilderAPI_MakeVertex(point).Vertex();
    gp_Pnt point1(-1.0, 1.0, 0.0);
    TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(point1).Vertex();
    gp_Pnt point2( 1.0, 1.0, 0.0);
    TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(point2).Vertex();
    TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(V1, V2);

    BRepExtrema_DistShapeShape distSS(edge, V);

    // should only be one minimal value
    ASSERT_EQ(distSS.NbSolution(),1);
    // this value should be V
    gp_Pnt res2 = distSS.PointOnShape2(1);
    Standard_Real dist = res2.Distance(point);

    ASSERT_NEAR(0.0, dist, 0.001);
}

TEST(BRepExtremaTestSuite, testDistVertexFace)
{
    gp_Pnt point(0.0, 0.0, 0.0);
    TopoDS_Vertex V=BRepBuilderAPI_MakeVertex(point).Vertex();

    gp_Pnt pointF(0.0, 0.0, 1.0);
    gp_Dir dirF(0.0, 0.0, 1.0);
    gp_Pln Plane(pointF, dirF);
    TopoDS_Face F = BRepBuilderAPI_MakeFace(Plane, -1.0, 1.0, -1.0, 1.0);

    BRepExtrema_DistShapeShape distSS(V, F);

    // should only be one minimal value
    ASSERT_EQ(distSS.NbSolution(),1);
    // this value should be V
    gp_Pnt res1 = distSS.PointOnShape1(1);
    Standard_Real dist = res1.Distance(point);

    ASSERT_NEAR(0.0, dist, 0.001);
}

// This test fails with OCCT >= 6.5.1
TEST(BRepExtremaTestSuite, testDistFaceVertex)
{
    gp_Pnt point(0.0, 0.0, 0.0);
    TopoDS_Vertex V=BRepBuilderAPI_MakeVertex(point).Vertex();

    gp_Pnt pointF(0.0, 0.0, 1.0);
    gp_Dir dirF(0.0, 0.0, 1.0);
    gp_Pln Plane(pointF, dirF);
    TopoDS_Face F = BRepBuilderAPI_MakeFace(Plane, -1.0, 1.0, -1.0, 1.0);

    BRepExtrema_DistShapeShape distSS(F, V);

    // should only be one minimal value
    ASSERT_EQ(distSS.NbSolution(),1);
    // this value should be V
    gp_Pnt res2 = distSS.PointOnShape2(1);
    Standard_Real dist = res2.Distance(point);

    ASSERT_NEAR(0.0, dist, 0.001);
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}