Skip to content

Commit 185c905

Browse files
authored
Merge pull request #176 from ndem0/pyocc_74
porting to python-occ==7.4
2 parents 0fedaa2 + 6ee89b7 commit 185c905

File tree

8 files changed

+110
-119
lines changed

8 files changed

+110
-119
lines changed

.travis.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sudo: true
2-
dist: trusty
2+
dist: xenial
33

44
language: python
55

@@ -8,17 +8,11 @@ service: docker
88
matrix:
99
include:
1010
- os: linux
11-
python: 2.7
12-
env: TOXENV=py27
13-
- os: linux
14-
python: 3.5
15-
env: TOXENV=py35
16-
- os: osx
17-
language: generic
18-
env: TOXENV=py27
11+
python: 3.7
12+
env: TOXENV=py37
1913
- os: osx
2014
language: generic
21-
env: TOXENV=py35
15+
env: TOXENV=py37
2216

2317
before_script:
2418
- "export DISPLAY=:99.0"
@@ -51,22 +45,13 @@ install:
5145
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
5246
conda create --yes -n test python=$TRAVIS_PYTHON_VERSION;
5347
else
54-
if [[ "$TOXENV" == "py27" ]]; then
55-
conda create --yes -n test python="2.7";
56-
else
57-
conda create --yes -n test python="3.5";
58-
fi
48+
conda create --yes -n test python="3.7";
5949
fi
6050
- source activate test
6151
- echo $LD_LIBRARY_PATH
6252
- echo $DYLD_LIBRARY_PATH
6353
- echo $PATH
64-
- conda install "numpy>=1.12" scipy matplotlib vtk nose setuptools coveralls
65-
- if [[ "$TOXENV" == "py27" ]]; then
66-
conda install --yes -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core=0.17 python=2.7;
67-
else
68-
conda install --yes -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core=0.17 python=3.5;
69-
fi
54+
- conda install --yes -c conda-forge pythonocc-core=7.4.0 numpy scipy matplotlib vtk nose setuptools coveralls python=3.7
7055
- python setup.py install
7156

7257
script:

pygem/igeshandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
Derived module from filehandler.py to handle iges and igs files.
33
"""
4-
from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer,
4+
from OCC.Core.IGESControl import (IGESControl_Reader, IGESControl_Writer,
55
IGESControl_Controller_Init)
6-
from OCC.IFSelect import IFSelect_RetDone
6+
from OCC.Core.IFSelect import IFSelect_RetDone
77
from pygem.nurbshandler import NurbsHandler
88

99

pygem/nurbshandler.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
"""
77
import os
88
import numpy as np
9-
from OCC.BRep import BRep_Tool, BRep_Builder, BRep_Tool_Curve
10-
from OCC.BRepAlgo import brepalgo_IsValid
11-
from OCC.BRepBuilderAPI import (
9+
from OCC.Core.BRep import BRep_Tool, BRep_Builder, BRep_Tool_Curve
10+
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
11+
from OCC.Core.BRepAlgo import brepalgo_IsValid
12+
from OCC.Core.BRepBuilderAPI import (
1213
BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace,
1314
BRepBuilderAPI_NurbsConvert, BRepBuilderAPI_MakeWire, BRepBuilderAPI_Sewing)
14-
from OCC.BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
15+
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
1516
from OCC.Display.SimpleGui import init_display
16-
from OCC.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
17+
from OCC.Core.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
1718
geomconvert_CurveToBSplineCurve)
18-
from OCC.gp import gp_Pnt, gp_XYZ
19-
from OCC.Precision import precision_Confusion
20-
from OCC.ShapeAnalysis import ShapeAnalysis_WireOrder
21-
from OCC.ShapeFix import ShapeFix_ShapeTolerance, ShapeFix_Shell
22-
from OCC.StlAPI import StlAPI_Writer
23-
from OCC.TColgp import TColgp_Array1OfPnt, TColgp_Array2OfPnt
24-
from OCC.TopAbs import (TopAbs_FACE, TopAbs_EDGE, TopAbs_WIRE, TopAbs_FORWARD,
19+
from OCC.Core.gp import gp_Pnt, gp_XYZ
20+
from OCC.Core.Precision import precision_Confusion
21+
from OCC.Core.ShapeAnalysis import ShapeAnalysis_WireOrder
22+
from OCC.Core.ShapeFix import ShapeFix_ShapeTolerance, ShapeFix_Shell
23+
from OCC.Core.StlAPI import StlAPI_Writer
24+
from OCC.Core.TColgp import TColgp_Array1OfPnt, TColgp_Array2OfPnt
25+
from OCC.Core.TopAbs import (TopAbs_FACE, TopAbs_EDGE, TopAbs_WIRE, TopAbs_FORWARD,
2526
TopAbs_SHELL)
26-
from OCC.TopExp import TopExp_Explorer, topexp
27-
from OCC.TopoDS import (topods_Face, TopoDS_Compound, topods_Shell, topods_Edge,
27+
from OCC.Core.TopExp import TopExp_Explorer, topexp
28+
from OCC.Core.TopoDS import (topods_Face, TopoDS_Compound, topods_Shell, topods_Edge,
2829
topods_Wire, topods, TopoDS_Shape)
2930
from matplotlib import pyplot
3031
from mpl_toolkits import mplot3d
@@ -112,7 +113,7 @@ def parse(self, filename):
112113
bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)
113114

114115
# openCascade object
115-
occ_face = bspline_face.GetObject()
116+
occ_face = bspline_face
116117

117118
# extract the Control Points of each face
118119
n_poles_u = occ_face.NbUPoles()
@@ -185,7 +186,7 @@ def write(self, mesh_points, filename, tolerance=None):
185186
face_aux = topods_Face(nurbs_face)
186187
brep_face = BRep_Tool.Surface(topods_Face(nurbs_face))
187188
bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)
188-
occ_face = bspline_face.GetObject()
189+
occ_face = bspline_face
189190

190191
n_poles_u = occ_face.NbUPoles()
191192
n_poles_v = occ_face.NbVPoles()
@@ -205,7 +206,7 @@ def write(self, mesh_points, filename, tolerance=None):
205206
# construct the deformed wire for the trimmed surfaces
206207
wire_maker = BRepBuilderAPI_MakeWire()
207208
tol = ShapeFix_ShapeTolerance()
208-
brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
209+
brep = BRepBuilderAPI_MakeFace(occ_face,
209210
self.tolerance).Face()
210211
brep_face = BRep_Tool.Surface(brep)
211212

@@ -228,7 +229,7 @@ def write(self, mesh_points, filename, tolerance=None):
228229
wire = wire_maker.Wire()
229230

230231
# trimming the surfaces
231-
brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
232+
brep_surf = BRepBuilderAPI_MakeFace(occ_face,
232233
wire).Shape()
233234
compound_builder.Add(compound, brep_surf)
234235
n_faces += 1
@@ -303,7 +304,7 @@ def parse_face(topo_face):
303304
h_geom_edge = BRep_Tool_Curve(
304305
topods_Edge(bspline_tshape_edge))[0]
305306
h_bspline_edge = geomconvert_CurveToBSplineCurve(h_geom_edge)
306-
bspline_geom_edge = h_bspline_edge.GetObject()
307+
bspline_geom_edge = h_bspline_edge
307308

308309
nb_poles = bspline_geom_edge.NbPoles()
309310

@@ -334,7 +335,7 @@ def parse_face(topo_face):
334335
nurbs_face = nurbs_converter.Shape()
335336
h_geomsurface = BRep_Tool.Surface(topods.Face(nurbs_face))
336337
h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface)
337-
bsurface = h_bsurface.GetObject()
338+
bsurface = h_bsurface
338339

339340
# get access to control points (poles)
340341
nb_u = bsurface.NbUPoles()
@@ -435,7 +436,7 @@ def write_edge(points_edge, topo_edge):
435436
topo_curve = topods_Edge(nurbs_curve)
436437
h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
437438
h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
438-
bspline_edge_curve = h_bcurve.GetObject()
439+
bspline_edge_curve = h_bcurve
439440

440441
# Edge geometric properties
441442
nb_cpt = bspline_edge_curve.NbPoles()
@@ -734,7 +735,12 @@ def plot(self, plot_file=None, save_fig=False):
734735
stl_writer = StlAPI_Writer()
735736
# Do not switch SetASCIIMode() from False to True.
736737
stl_writer.SetASCIIMode(False)
737-
stl_writer.Write(shape, 'aux_figure.stl')
738+
739+
# Necessary to write to STL [to check]
740+
stl_mesh = BRepMesh_IncrementalMesh(shape, 0.01)
741+
stl_mesh.Perform()
742+
743+
f = stl_writer.Write(shape, 'aux_figure.stl')
738744

739745
# Create a new plot
740746
figure = pyplot.figure()

pygem/params/ffdparams.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import ConfigParser as configparser
99
import os
1010
import numpy as np
11-
from OCC.Bnd import Bnd_Box
12-
from OCC.BRepBndLib import brepbndlib_Add
13-
from OCC.BRepMesh import BRepMesh_IncrementalMesh
11+
#from OCC.Bnd import Bnd_Box
12+
#from OCC.BRepBndLib import brepbndlib_Add
13+
#from OCC.BRepMesh import BRepMesh_IncrementalMesh
1414
import vtk
1515
import pygem.affine as at
1616

@@ -482,41 +482,45 @@ def save_points(self, filename, write_deformed=True):
482482
writer.SetInputData(data)
483483
writer.Write()
484484

485-
def build_bounding_box(self,
486-
shape,
487-
tol=1e-6,
488-
triangulate=False,
489-
triangulate_tol=1e-1):
490-
"""
491-
Builds a bounding box around the given shape. All parameters are set to
492-
match the computed box, the deformed FFD points are reset.
493-
494-
:param shape: the shape to compute the bounding box.
495-
:type shape: TopoDS_Shape or its subclass
496-
:param float tol: tolerance of the computed bounding box.
497-
:param bool triangulate: if True, shape is triangulated before the
498-
bouning box creation.
499-
:param float triangulate_tol: tolerance of triangulation (size of
500-
created triangles).
501-
502-
.. note::
503-
504-
Every UV-Surface has to be rectangular. When a solid is created
505-
surfaces are trimmed. The trimmed part, however, is still saved
506-
inside a file. It is just *invisible* when drawn in a program.
507-
"""
508-
bbox = Bnd_Box()
509-
bbox.SetGap(tol)
510-
if triangulate:
511-
BRepMesh_IncrementalMesh(shape, triangulate_tol)
512-
brepbndlib_Add(shape, bbox, triangulate)
513-
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
514-
min_xyz = np.array([xmin, ymin, zmin])
515-
max_xyz = np.array([xmax, ymax, zmax])
516-
517-
self.box_origin = min_xyz
518-
self.box_length = max_xyz - min_xyz
519-
self.reset_deformation()
485+
486+
# TODO
487+
# to reimplement avoiding OCC
488+
#
489+
# def build_bounding_box(self,
490+
# shape,
491+
# tol=1e-6,
492+
# triangulate=False,
493+
# triangulate_tol=1e-1):
494+
# """
495+
# Builds a bounding box around the given shape. All parameters are set to
496+
# match the computed box, the deformed FFD points are reset.
497+
#
498+
# :param shape: the shape to compute the bounding box.
499+
# :type shape: TopoDS_Shape or its subclass
500+
# :param float tol: tolerance of the computed bounding box.
501+
# :param bool triangulate: if True, shape is triangulated before the
502+
# bouning box creation.
503+
# :param float triangulate_tol: tolerance of triangulation (size of
504+
# created triangles).
505+
#
506+
# .. note::
507+
#
508+
# Every UV-Surface has to be rectangular. When a solid is created
509+
# surfaces are trimmed. The trimmed part, however, is still saved
510+
# inside a file. It is just *invisible* when drawn in a program.
511+
# """
512+
# bbox = Bnd_Box()
513+
# bbox.SetGap(tol)
514+
# if triangulate:
515+
# BRepMesh_IncrementalMesh(shape, triangulate_tol)
516+
# brepbndlib_Add(shape, bbox, triangulate)
517+
# xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
518+
# min_xyz = np.array([xmin, ymin, zmin])
519+
# max_xyz = np.array([xmax, ymax, zmax])
520+
#
521+
# self.box_origin = min_xyz
522+
# self.box_length = max_xyz - min_xyz
523+
# self.reset_deformation()
520524

521525
def reset_deformation(self):
522526
"""

pygem/stephandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Derived module from nurbshandler.py to handle step and stp files.
33
"""
4-
from OCC.IFSelect import IFSelect_RetDone
5-
from OCC.Interface import Interface_Static_SetCVal
6-
from OCC.STEPControl import STEPControl_Writer, STEPControl_Reader
7-
from OCC.STEPControl import STEPControl_AsIs
4+
from OCC.Core.IFSelect import IFSelect_RetDone
5+
from OCC.Core.Interface import Interface_Static_SetCVal
6+
from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_Reader
7+
from OCC.Core.STEPControl import STEPControl_AsIs
88
from pygem.nurbshandler import NurbsHandler
99

1010

tests/test_ffdparams.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
from unittest import TestCase
44

55
import numpy as np
6-
from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut
7-
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
8-
from OCC.gp import gp_Pnt
9-
106
from pygem.params import FFDParameters
117

128

@@ -357,26 +353,26 @@ def test_print(self):
357353
params = FFDParameters(n_control_points=[3, 2, 2])
358354
print(params)
359355

360-
def test_build_bounding_box_1(self):
361-
origin = np.array([0., 0., 0.])
362-
tops = np.array([1., 1., 1.])
363-
cube = BRepPrimAPI_MakeBox(*tops).Shape()
364-
params = FFDParameters()
365-
params.build_bounding_box(cube)
366-
367-
np.testing.assert_array_almost_equal(params.box_length, tops, decimal=5)
368-
369-
def test_build_bounding_box_2(self):
370-
origin = np.array([0., 0., 0.])
371-
tops = np.array([1., 1., 1.])
372-
cube = BRepPrimAPI_MakeBox(*tops).Shape()
373-
params = FFDParameters()
374-
params.build_bounding_box(cube)
375-
376-
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
377-
[0., 0., 1.]])
378-
np.testing.assert_almost_equal(
379-
params.position_vertices, expected_matrix, decimal=5)
356+
# def test_build_bounding_box_1(self):
357+
# origin = np.array([0., 0., 0.])
358+
# tops = np.array([1., 1., 1.])
359+
# cube = BRepPrimAPI_MakeBox(*tops).Shape()
360+
# params = FFDParameters()
361+
# params.build_bounding_box(cube)
362+
#
363+
# np.testing.assert_array_almost_equal(params.box_length, tops, decimal=5)
364+
#
365+
# def test_build_bounding_box_2(self):
366+
# origin = np.array([0., 0., 0.])
367+
# tops = np.array([1., 1., 1.])
368+
# cube = BRepPrimAPI_MakeBox(*tops).Shape()
369+
# params = FFDParameters()
370+
# params.build_bounding_box(cube)
371+
#
372+
# expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
373+
# [0., 0., 1.]])
374+
# np.testing.assert_almost_equal(
375+
# params.position_vertices, expected_matrix, decimal=5)
380376

381377
def test_set_position_of_vertices(self):
382378
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],

tests/test_igeshandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from unittest import TestCase
33

44
import numpy as np
5-
from OCC.TopoDS import TopoDS_Shape
6-
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
5+
from OCC.Core.TopoDS import TopoDS_Shape, TopoDS_Compound
6+
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
77

88
import pygem.igeshandler as ih
99

@@ -195,13 +195,13 @@ def test_iges_load_shape_correct_iges(self):
195195
iges_handler = ih.IgesHandler()
196196
shape = iges_handler.load_shape_from_file(
197197
'tests/test_datasets/test_pipe.iges')
198-
self.assertEqual(type(shape), TopoDS_Shape)
198+
self.assertEqual(type(shape), TopoDS_Compound)
199199

200200
def test_iges_load_shape_correct_igs(self):
201201
iges_handler = ih.IgesHandler()
202202
shape = iges_handler.load_shape_from_file(
203203
'tests/test_datasets/test_pipe.igs')
204-
self.assertEqual(type(shape), TopoDS_Shape)
204+
self.assertEqual(type(shape), TopoDS_Compound)
205205

206206
def test_iges_write_shape_to_file_raises_wrong_type(self):
207207
iges_handler = ih.IgesHandler()

0 commit comments

Comments
 (0)