Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate occt #1315

Merged
merged 23 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ steps:
event: pull_request
commands:
- git fetch --tags
- apt-get update # Add this line to update package information
- apt-get install -y libgl1 # Add this line to install libgl1
- pip install .[doc,test]
- python setup.py build_ext --inplace
- cd tests
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## v0.17.0 [Unreleased]
### New Features

- occt integration: surface intersections.
- Commented some surface intersectios methods.

#### curves.py
- Ellipse3D: to_step
#### edges.py
Expand Down
2 changes: 1 addition & 1 deletion code_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'arguments-differ': 16,
'too-many-locals': 75,
'unused-argument': 6,
'too-many-arguments': 32,
'too-many-arguments': 33,
'line-too-long': 12,
'too-many-branches': 22,
'too-many-statements': 11,
Expand Down
2 changes: 2 additions & 0 deletions coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'models/__init__.py',
'models/contours.py',
'models/bspline_curves.py',
'volmdlr/from_occt.py',
'volmdlr/to_occt.py'
]

print('untracked modules:', untracked_modules)
Expand Down
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def version_from_git_describe(version):
split_versions[-1] = str(int(split_versions[-1]) + 1)
future_version = ".".join(split_versions)
return "{}.dev{}".format(future_version, number_commits_ahead)
else:
return ".".join(split_versions)
return ".".join(split_versions)

if number_commits_ahead > 0:
if len(split_versions) == 2:
Expand All @@ -64,11 +63,10 @@ def version_from_git_describe(version):
split_versions[-1] = str(int(split_versions[-1]) + 1)
split_versions = ".".join(split_versions)
return "{}.dev{}+{}".format(split_versions, number_commits_ahead, commit_hash)
else:
if suffix is not None:
split_versions.append(suffix)
if suffix is not None:
split_versions.append(suffix)

return ".".join(split_versions)
return ".".join(split_versions)


# Just testing if get_version works well
Expand Down Expand Up @@ -143,6 +141,7 @@ def get_version():
"gmsh",
"pyfqmr",
"CGAL",
"cadquery-ocp"
],
extras_require={"test": ["coverage"],
"doc": ["sphinx", "nbsphinx", "pydata_sphinx_theme", "nbformat", "nbconvert",
Expand Down
4 changes: 2 additions & 2 deletions tests/edges/test_fullarc2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_trim(self):
split_point1 = volmdlr.Point2D(-0.7071067811865475, 0.7071067811865475)
split_point2 = volmdlr.Point2D(-0.7071067811865475, -0.7071067811865475)
split = self.fullarc2d.trim(split_point1, split_point2)
self.assertEqual(split, edges.Arc2D(self.circle2d, volmdlr.Point2D(-0.7071067811865475, -0.7071067811865475),
volmdlr.Point2D(-0.7071067811865475, 0.7071067811865475)))
self.assertEqual(split, edges.Arc2D(self.circle2d, volmdlr.Point2D(-0.7071067811865475, 0.7071067811865475),
volmdlr.Point2D(-0.7071067811865475, -0.7071067811865475)))


if __name__ == '__main__':
Expand Down
22 changes: 7 additions & 15 deletions tests/faces/test_cylindricalface3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ def test_plane_intersections(self):
self.assertAlmostEqual(plane_intersections[0].length(), 0.10485331158773475)

def test_conicalface_intersections(self):
expected_results = [[[3.7095444178694787], [2.754671034122705, 0.7935213452250598],
[2.075126698839449, 0.49133092691300395, 1.0377142752022748, 0.5464208749923458],
[2.5699447071876236, 2.569944707187624],
[0.5440554686815117, 0.04555235973555357, 1.2782307913877522, 0.25616610636212483]],
[[0.904180630293272, 1.392773884071054], [2.754671034122705, 0.7935213452250598],
[0.9945099178084125, 0.011885799104577068, 0.49133092691300395, 1.0377142752022748,
0.5464208749923458], [0.2895638627891746, 0.9393502379009631, 2.569944707187624],
[0.2798809795825533, 0.04555235973555357, 0.7579656339795895]],
[[0.8560428761357552, 0.32222897609785606],
[0.6888878220595716, 0.6888878220595696, 0.1984154951054974, 0.19841549510549764],
[0.49133092691300395, 1.0377142752022748, 0.5464208749923458], [2.569944707187624],
[]]]
conical_surface = surfaces.ConicalSurface3D(volmdlr.OXYZ, math.pi / 6)
conical_face = faces.ConicalFace3D.from_surface_rectangular_cut(
conical_surface, 0, volmdlr.TWO_PI, 0, 2)
Expand Down Expand Up @@ -196,9 +184,13 @@ def test_conicalface_intersections(self):
cyl_face = faces.CylindricalFace3D.from_surface_rectangular_cut(
cylindrical_surface, 0, volmdlr.TWO_PI, z, 2)
list_curves = cyl_face.face_intersections(conical_face)
self.assertEqual(len(list_curves), len(expected_results[i][j]))
for curve_solution, expected_result in zip(list_curves, expected_results[i][j]):
self.assertAlmostEqual(curve_solution.length(), expected_result, 6)
for intersection in list_curves:
for point in intersection.discretization_points(number_points=50):
self.assertTrue(cyl_face.point_belongs(point, 1e-6))
self.assertTrue(conical_face.point_belongs(point, 1e-6))
# self.assertEqual(len(list_curves), len(expected_results[i][j]))
# for curve_solution, expected_result in zip(list_curves, expected_results[i][j]):
# self.assertAlmostEqual(curve_solution.length(), expected_result, 6)

def test_normal_at_point(self):
cylindricalsurface = surfaces.CylindricalSurface3D(volmdlr.OXYZ, 0.15)
Expand Down
20 changes: 7 additions & 13 deletions tests/faces/test_toroidalface3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,25 @@ def test_from_contours3d(self):
self.assertAlmostEqual(face.surface2d.area(), 36.56961010698211, 2)

def test_planeface_intersections(self):
expected_results = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2]

ts = surfaces.ToroidalSurface3D(volmdlr.OXYZ, 2, 1)
tf = faces.ToroidalFace3D.from_surface_rectangular_cut(ts, -1.4, 3.5, 0., 2.5)

# list_expected_lenghts1 = []
plane1 = surfaces.Plane3D(volmdlr.OXYZ)
plane1 = plane1.rotation(volmdlr.O3D, volmdlr.Z3D, math.pi / 4)
for i, n in enumerate(npy.linspace(0, math.pi / 4, 10)):
plane = plane1.rotation(plane1.frame.origin, volmdlr.X3D, n)
plane_face = faces.PlaneFace3D.from_surface_rectangular_cut(plane, 4, -4, 4, -4)
planeface_intersections = tf.face_intersections(plane_face)
# list_expected_lenghts1.append([i.length() for i in planeface_intersections])
self.assertEqual(len(planeface_intersections), expected_results[i])
self.assertTrue(all(tf.point_belongs(p, 1e-4) and plane_face.point_belongs(p, 1e-4)
self.assertTrue(all(tf.point_belongs(p, 1e-6) and plane_face.point_belongs(p, 1e-6)
for i in planeface_intersections for p in i.primitives[0].points))
# for result, expected_result in zip(planeface_intersections, expected_results[i]):
# self.assertAlmostEqual(result.length(), expected_result, 5)

planeface, toroidalface = DessiaObject.from_json(
os.path.join(folder, "test_planeface_toroidialface_intersections301123.json")).primitives

inters = planeface.face_intersections(toroidalface)
self.assertEqual(len(inters), 1)
self.assertAlmostEqual(inters[0].length(), 0.08139556829160953, 5)
self.assertEqual(len(inters), 2)
self.assertAlmostEqual(inters[0].length(), 0.05927981578248949, 5)
self.assertAlmostEqual(inters[1].length(), 0.02211845531216632, 5)

planeface, toroidalface = DessiaObject.from_json(
os.path.join(folder, 'test_planeface3d_toroidalface3d_121223.json')).primitives
Expand All @@ -86,9 +80,9 @@ def test_planeface_intersections(self):
self.assertAlmostEqual(inters[0].length(), 0.030296492908080553, 5)

def test_cylindricalface_intersections(self):
expected_results = [[2.5461209954222026], [2.454561591082158], [2.7679468571575105], [2.8109179729321183],
[1.3806998569480715, 3.0283316710422508], [2.1248782869459646], [1.7368478889595058],
[2.55833794579346], [2.8123613465408064, 1.3899450251554277], [2.447515630586587]]
expected_results = [[2.546120946430277], [2.4545584333145953], [2.7679468837029058], [2.810918022378337],
[1.380699832995302, 3.0283316366328172], [2.1248783055959217], [1.736847951355942],
[2.5583380427505085], [2.812361368015032, 1.3899450172350931], [2.447515690966958]]
toroidal_surface = surfaces.ToroidalSurface3D(volmdlr.OXYZ, 2, 1)
tf = faces.ToroidalFace3D.from_surface_rectangular_cut(toroidal_surface, 0, 3, 1, 3)
frame = volmdlr.OXYZ.translation(volmdlr.Vector3D(1, 1, 0))
Expand Down
82 changes: 54 additions & 28 deletions tests/surfaces/test_conical_surface3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ def test_perpendicular_plane_intersection(self):
self.assertAlmostEqual(circle.radius, 1.0)

plane = surfaces.Plane3D(self.frame.translation(self.frame.w * 0.5))
circle = self.conical_surface4.perpendicular_plane_intersection(plane)[0]
self.assertTrue(circle.center.is_close(volmdlr.Point3D(0.5, 0.853553390593, 0.853553390593)))
self.assertTrue(circle.normal.is_close(volmdlr.Vector3D(0.0, 0.7071067811865475, 0.7071067811865475)))
self.assertAlmostEqual(circle.radius, 0.75)
fullarc = self.conical_surface4.perpendicular_plane_intersection(plane)[0]
self.assertTrue(fullarc.center.is_close(volmdlr.Point3D(0.5, 0.853553390593, 0.853553390593)))
self.assertTrue(fullarc.circle.normal.is_close(volmdlr.Vector3D(0.0, 0.7071067811865475, 0.7071067811865475)))
self.assertAlmostEqual(fullarc.circle.radius, 0.75)

def test_parallel_plane_intersection(self):
frame = volmdlr.Frame3D(volmdlr.Point3D(0.0, 0.0, 0.5), volmdlr.Z3D,
Expand Down Expand Up @@ -301,42 +301,63 @@ def test_circle_intersections(self):
self.assertTrue(self.conical_surface3.point_belongs(intersections[0]))
self.assertTrue(self.conical_surface3.point_belongs(intersections[1]))


def test_plane_intersections(self):
conical_surface = surfaces.ConicalSurface3D(volmdlr.OXYZ, math.pi / 6)

#test1
plane1 = surfaces.Plane3D(volmdlr.Frame3D(volmdlr.Point3D(0, 0, 0.5),
volmdlr.X3D, volmdlr.Y3D, volmdlr.Z3D))
intersections = conical_surface.surface_intersections(plane1)
self.assertEqual(len(intersections), 1)
self.assertEqual(intersections[0].__class__.__name__, 'FullArc3D')
self.assertAlmostEqual(intersections[0].radius, 0.2886751345948128)

plane2 = surfaces.Plane3D(volmdlr.Frame3D(volmdlr.Point3D(0, 0.25, 0.5),
volmdlr.Z3D, volmdlr.X3D, volmdlr.Y3D))
#test2
intersections = conical_surface.surface_intersections(plane2)
self.assertEqual(len(intersections), 1)
for intersection in intersections:
self.assertEqual(intersection.__class__.__name__, 'Hyperbola3D')
self.assertAlmostEqual(intersection.semi_major_axis, 0.4330127018922194)

#test3
plane3 = surfaces.Plane3D(volmdlr.Frame3D(volmdlr.Point3D(0, 0.0, 0.5),
volmdlr.Z3D, volmdlr.X3D, volmdlr.Y3D))
intersections = conical_surface.surface_intersections(plane3)
self.assertEqual(len(intersections), 2)
for i, intersection in enumerate(intersections):
self.assertEqual(intersection.__class__.__name__, 'Line3D')
if i == 0:
self.assertTrue(intersection.unit_direction_vector().is_close(
volmdlr.Vector3D(-0.49999999999999994, 0.0, 0.8660254037844386)))
else:
self.assertTrue(intersection.unit_direction_vector().is_close(
volmdlr.Vector3D(0.49999999999999994, 0.0, 0.8660254037844386)))

#test4
vector1 = volmdlr.Vector3D(1, 1, 1)
vector1 = vector1.unit_vector()
vector2 = vector1.deterministic_unit_normal_vector()
vector3 = vector1.cross(vector2)
frame = volmdlr.Frame3D(volmdlr.Point3D(0, 0, 0.5), vector1, vector2, vector3)
plane4 = surfaces.Plane3D(frame)
intersections = conical_surface.surface_intersections(plane4)
self.assertEqual(len(intersections), 1)
self.assertEqual(intersections[0].__class__.__name__, 'FullArcEllipse3D')
self.assertAlmostEqual(intersections[0].ellipse.major_axis, 0.612372435695794)

#test5
point1 = conical_surface.frame.origin
point2 = conical_surface.frame.local_to_global_coordinates(
volmdlr.Point3D(10 * math.tan(conical_surface.semi_angle), 0, 10))
generatrix = edges.LineSegment3D(point1, point2)
normal = generatrix.unit_normal_vector()
plane5 = surfaces.Plane3D.from_normal(frame.origin - normal * .5, normal)
expected_results = [[('Circle3D', 0.2886751345948128)],
[('Hyperbola3D', 0.4330127018922194)],
[('Line3D', volmdlr.Vector3D(-0.49999999999999994, 0.0, 0.8660254037844386)),
('Line3D', volmdlr.Vector3D(0.49999999999999994, 0.0, 0.8660254037844386))],
[('Ellipse3D', 0.3535533905927743)],
[('Parabola3D', 0.21650635094600354)]]
for i, plane in enumerate([plane1, plane2, plane3, plane4, plane5]):
intersections = conical_surface.surface_intersections(plane)
for intersection, expected_result in zip(intersections, expected_results[i]):
self.assertEqual(intersection.__class__.__name__, expected_result[0])
if i == 2:
self.assertTrue(intersection.unit_direction_vector().is_close(expected_result[1]))
else:
self.assertAlmostEqual(intersection[1], expected_result[1])
intersections = conical_surface.surface_intersections(plane5)
self.assertEqual(len(intersections), 1)
for intersection in intersections:
self.assertEqual(intersection.__class__.__name__, 'Parabola3D')
self.assertAlmostEqual(intersection.focal_length, 0.21650635094610962)

conicalsurface, plane = DessiaObject.from_json(
os.path.join(folder, 'test_conicalsurface_plane_intersections081223.json')).primitives
Expand Down Expand Up @@ -388,15 +409,19 @@ def test_sphericalsurface_intersections(self):
# test 1
conical_surface = surfaces.ConicalSurface3D(volmdlr.OXYZ, math.pi / 6)
inters = spherical_surface.surface_intersections(conical_surface)
self.assertEqual(len(inters), 1)
self.assertAlmostEqual(inters[0].length(), 6.132194414411092)
self.assertEqual(len(inters), 4)
self.assertAlmostEqual(inters[0].length(), 0.518221647963969)
self.assertAlmostEqual(inters[1].length(), 5.614215638678307)
self.assertAlmostEqual(inters[2].length(), 3.3317945727202956)
self.assertAlmostEqual(inters[3].length(), 2.8011685582531882)
# test 2
conical_surface = surfaces.ConicalSurface3D(volmdlr.OXYZ, math.pi / 6)
conical_surface = conical_surface.translation(-volmdlr.Z3D * 2)
inters = spherical_surface.surface_intersections(conical_surface)
self.assertEqual(len(inters), 2)
self.assertAlmostEqual(inters[0].length(), 10.905677051611681)
self.assertAlmostEqual(inters[1].length(), 0.5120820085072879)
self.assertEqual(len(inters), 3)
self.assertAlmostEqual(inters[0].length(), 0.5116334630857555)
self.assertAlmostEqual(inters[1].length(), 10.39429415265973)
self.assertAlmostEqual(inters[2].length(), 0.5120820074801914)

def test_conicalsurface_intersections(self):
conical_surface = surfaces.ConicalSurface3D(volmdlr.OXYZ, math.pi / 3)
Expand Down Expand Up @@ -472,15 +497,16 @@ def test_conicalsurface_intersections(self):
conical_intersections10 = conical_surface.surface_intersections(conical_surface2_1)
self.assertEqual(len(conical_intersections10), 1)
self.assertTrue(conical_intersections10[0].is_close(curves.Hyperbola3D(
volmdlr.Frame3D(origin=volmdlr.Point3D(0.25, 0.0, 0.0), u=volmdlr.Vector3D(0.0, 0.0, 1.0),
v=volmdlr.Vector3D(0.0, -1.0, 0.0), w=volmdlr.Vector3D(1.0, 0.0, -0.0)),
0.1443375672974065, 0.24999999999978403)))
volmdlr.Frame3D(origin=volmdlr.Point3D(0.250000021243, 0.0, 6.798e-09), u=volmdlr.Vector3D(0.0, 0.0, 1.0),
v=volmdlr.Vector3D(0.0, 0.9999999999999997, 0.0), w=volmdlr.Vector3D(-0.9999999999999997, -0.0, -2.71919372574203e-08)),
0.1443375727640583, 0.25000001601011906)))

def test_is_singularity_point(self):
point_true = volmdlr.Point3D(0.0, 0.0, -0.5)
point_false = volmdlr.Point3D(0.0, 0.0, -0.49)
self.assertTrue(self.conical_surface3.is_singularity_point(point_true))
self.assertFalse(self.conical_surface3.is_singularity_point(point_false))


if __name__ == '__main__':
unittest.main()
Loading