Skip to content
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
27 changes: 6 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: true
dist: trusty
dist: xenial

language: python

Expand All @@ -8,17 +8,11 @@ service: docker
matrix:
include:
- os: linux
python: 2.7
env: TOXENV=py27
- os: linux
python: 3.5
env: TOXENV=py35
- os: osx
language: generic
env: TOXENV=py27
python: 3.7
env: TOXENV=py37
- os: osx
language: generic
env: TOXENV=py35
env: TOXENV=py37

before_script:
- "export DISPLAY=:99.0"
Expand Down Expand Up @@ -51,22 +45,13 @@ install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
conda create --yes -n test python=$TRAVIS_PYTHON_VERSION;
else
if [[ "$TOXENV" == "py27" ]]; then
conda create --yes -n test python="2.7";
else
conda create --yes -n test python="3.5";
fi
conda create --yes -n test python="3.7";
fi
- source activate test
- echo $LD_LIBRARY_PATH
- echo $DYLD_LIBRARY_PATH
- echo $PATH
- conda install "numpy>=1.12" scipy matplotlib vtk nose setuptools coveralls
- if [[ "$TOXENV" == "py27" ]]; then
conda install --yes -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core=0.17 python=2.7;
else
conda install --yes -c conda-forge -c dlr-sc -c pythonocc -c oce pythonocc-core=0.17 python=3.5;
fi
- conda install --yes -c conda-forge pythonocc-core=7.4.0 numpy scipy matplotlib vtk nose setuptools coveralls python=3.7
- python setup.py install

script:
Expand Down
4 changes: 2 additions & 2 deletions pygem/igeshandler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Derived module from filehandler.py to handle iges and igs files.
"""
from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer,
from OCC.Core.IGESControl import (IGESControl_Reader, IGESControl_Writer,
IGESControl_Controller_Init)
from OCC.IFSelect import IFSelect_RetDone
from OCC.Core.IFSelect import IFSelect_RetDone
from pygem.nurbshandler import NurbsHandler


Expand Down
50 changes: 28 additions & 22 deletions pygem/nurbshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
"""
import os
import numpy as np
from OCC.BRep import BRep_Tool, BRep_Builder, BRep_Tool_Curve
from OCC.BRepAlgo import brepalgo_IsValid
from OCC.BRepBuilderAPI import (
from OCC.Core.BRep import BRep_Tool, BRep_Builder, BRep_Tool_Curve
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.BRepAlgo import brepalgo_IsValid
from OCC.Core.BRepBuilderAPI import (
BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace,
BRepBuilderAPI_NurbsConvert, BRepBuilderAPI_MakeWire, BRepBuilderAPI_Sewing)
from OCC.BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
from OCC.Display.SimpleGui import init_display
from OCC.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
from OCC.Core.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
geomconvert_CurveToBSplineCurve)
from OCC.gp import gp_Pnt, gp_XYZ
from OCC.Precision import precision_Confusion
from OCC.ShapeAnalysis import ShapeAnalysis_WireOrder
from OCC.ShapeFix import ShapeFix_ShapeTolerance, ShapeFix_Shell
from OCC.StlAPI import StlAPI_Writer
from OCC.TColgp import TColgp_Array1OfPnt, TColgp_Array2OfPnt
from OCC.TopAbs import (TopAbs_FACE, TopAbs_EDGE, TopAbs_WIRE, TopAbs_FORWARD,
from OCC.Core.gp import gp_Pnt, gp_XYZ
from OCC.Core.Precision import precision_Confusion
from OCC.Core.ShapeAnalysis import ShapeAnalysis_WireOrder
from OCC.Core.ShapeFix import ShapeFix_ShapeTolerance, ShapeFix_Shell
from OCC.Core.StlAPI import StlAPI_Writer
from OCC.Core.TColgp import TColgp_Array1OfPnt, TColgp_Array2OfPnt
from OCC.Core.TopAbs import (TopAbs_FACE, TopAbs_EDGE, TopAbs_WIRE, TopAbs_FORWARD,
TopAbs_SHELL)
from OCC.TopExp import TopExp_Explorer, topexp
from OCC.TopoDS import (topods_Face, TopoDS_Compound, topods_Shell, topods_Edge,
from OCC.Core.TopExp import TopExp_Explorer, topexp
from OCC.Core.TopoDS import (topods_Face, TopoDS_Compound, topods_Shell, topods_Edge,
topods_Wire, topods, TopoDS_Shape)
from matplotlib import pyplot
from mpl_toolkits import mplot3d
Expand Down Expand Up @@ -112,7 +113,7 @@ def parse(self, filename):
bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)

# openCascade object
occ_face = bspline_face.GetObject()
occ_face = bspline_face

# extract the Control Points of each face
n_poles_u = occ_face.NbUPoles()
Expand Down Expand Up @@ -185,7 +186,7 @@ def write(self, mesh_points, filename, tolerance=None):
face_aux = topods_Face(nurbs_face)
brep_face = BRep_Tool.Surface(topods_Face(nurbs_face))
bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)
occ_face = bspline_face.GetObject()
occ_face = bspline_face

n_poles_u = occ_face.NbUPoles()
n_poles_v = occ_face.NbVPoles()
Expand All @@ -205,7 +206,7 @@ def write(self, mesh_points, filename, tolerance=None):
# construct the deformed wire for the trimmed surfaces
wire_maker = BRepBuilderAPI_MakeWire()
tol = ShapeFix_ShapeTolerance()
brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
brep = BRepBuilderAPI_MakeFace(occ_face,
self.tolerance).Face()
brep_face = BRep_Tool.Surface(brep)

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

# trimming the surfaces
brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
brep_surf = BRepBuilderAPI_MakeFace(occ_face,
wire).Shape()
compound_builder.Add(compound, brep_surf)
n_faces += 1
Expand Down Expand Up @@ -303,7 +304,7 @@ def parse_face(topo_face):
h_geom_edge = BRep_Tool_Curve(
topods_Edge(bspline_tshape_edge))[0]
h_bspline_edge = geomconvert_CurveToBSplineCurve(h_geom_edge)
bspline_geom_edge = h_bspline_edge.GetObject()
bspline_geom_edge = h_bspline_edge

nb_poles = bspline_geom_edge.NbPoles()

Expand Down Expand Up @@ -334,7 +335,7 @@ def parse_face(topo_face):
nurbs_face = nurbs_converter.Shape()
h_geomsurface = BRep_Tool.Surface(topods.Face(nurbs_face))
h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface)
bsurface = h_bsurface.GetObject()
bsurface = h_bsurface

# get access to control points (poles)
nb_u = bsurface.NbUPoles()
Expand Down Expand Up @@ -435,7 +436,7 @@ def write_edge(points_edge, topo_edge):
topo_curve = topods_Edge(nurbs_curve)
h_geomcurve = BRep_Tool.Curve(topo_curve)[0]
h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
bspline_edge_curve = h_bcurve.GetObject()
bspline_edge_curve = h_bcurve

# Edge geometric properties
nb_cpt = bspline_edge_curve.NbPoles()
Expand Down Expand Up @@ -734,7 +735,12 @@ def plot(self, plot_file=None, save_fig=False):
stl_writer = StlAPI_Writer()
# Do not switch SetASCIIMode() from False to True.
stl_writer.SetASCIIMode(False)
stl_writer.Write(shape, 'aux_figure.stl')

# Necessary to write to STL [to check]
stl_mesh = BRepMesh_IncrementalMesh(shape, 0.01)
stl_mesh.Perform()

f = stl_writer.Write(shape, 'aux_figure.stl')

# Create a new plot
figure = pyplot.figure()
Expand Down
80 changes: 42 additions & 38 deletions pygem/params/ffdparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import ConfigParser as configparser
import os
import numpy as np
from OCC.Bnd import Bnd_Box
from OCC.BRepBndLib import brepbndlib_Add
from OCC.BRepMesh import BRepMesh_IncrementalMesh
#from OCC.Bnd import Bnd_Box
#from OCC.BRepBndLib import brepbndlib_Add
#from OCC.BRepMesh import BRepMesh_IncrementalMesh
import vtk
import pygem.affine as at

Expand Down Expand Up @@ -482,41 +482,45 @@ def save_points(self, filename, write_deformed=True):
writer.SetInputData(data)
writer.Write()

def build_bounding_box(self,
shape,
tol=1e-6,
triangulate=False,
triangulate_tol=1e-1):
"""
Builds a bounding box around the given shape. All parameters are set to
match the computed box, the deformed FFD points are reset.

:param shape: the shape to compute the bounding box.
:type shape: TopoDS_Shape or its subclass
:param float tol: tolerance of the computed bounding box.
:param bool triangulate: if True, shape is triangulated before the
bouning box creation.
:param float triangulate_tol: tolerance of triangulation (size of
created triangles).

.. note::

Every UV-Surface has to be rectangular. When a solid is created
surfaces are trimmed. The trimmed part, however, is still saved
inside a file. It is just *invisible* when drawn in a program.
"""
bbox = Bnd_Box()
bbox.SetGap(tol)
if triangulate:
BRepMesh_IncrementalMesh(shape, triangulate_tol)
brepbndlib_Add(shape, bbox, triangulate)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
min_xyz = np.array([xmin, ymin, zmin])
max_xyz = np.array([xmax, ymax, zmax])

self.box_origin = min_xyz
self.box_length = max_xyz - min_xyz
self.reset_deformation()

# TODO
# to reimplement avoiding OCC
#
# def build_bounding_box(self,
# shape,
# tol=1e-6,
# triangulate=False,
# triangulate_tol=1e-1):
# """
# Builds a bounding box around the given shape. All parameters are set to
# match the computed box, the deformed FFD points are reset.
#
# :param shape: the shape to compute the bounding box.
# :type shape: TopoDS_Shape or its subclass
# :param float tol: tolerance of the computed bounding box.
# :param bool triangulate: if True, shape is triangulated before the
# bouning box creation.
# :param float triangulate_tol: tolerance of triangulation (size of
# created triangles).
#
# .. note::
#
# Every UV-Surface has to be rectangular. When a solid is created
# surfaces are trimmed. The trimmed part, however, is still saved
# inside a file. It is just *invisible* when drawn in a program.
# """
# bbox = Bnd_Box()
# bbox.SetGap(tol)
# if triangulate:
# BRepMesh_IncrementalMesh(shape, triangulate_tol)
# brepbndlib_Add(shape, bbox, triangulate)
# xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
# min_xyz = np.array([xmin, ymin, zmin])
# max_xyz = np.array([xmax, ymax, zmax])
#
# self.box_origin = min_xyz
# self.box_length = max_xyz - min_xyz
# self.reset_deformation()

def reset_deformation(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions pygem/stephandler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Derived module from nurbshandler.py to handle step and stp files.
"""
from OCC.IFSelect import IFSelect_RetDone
from OCC.Interface import Interface_Static_SetCVal
from OCC.STEPControl import STEPControl_Writer, STEPControl_Reader
from OCC.STEPControl import STEPControl_AsIs
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.Interface import Interface_Static_SetCVal
from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_Reader
from OCC.Core.STEPControl import STEPControl_AsIs
from pygem.nurbshandler import NurbsHandler


Expand Down
44 changes: 20 additions & 24 deletions tests/test_ffdparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
from unittest import TestCase

import numpy as np
from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
from OCC.gp import gp_Pnt

from pygem.params import FFDParameters


Expand Down Expand Up @@ -357,26 +353,26 @@ def test_print(self):
params = FFDParameters(n_control_points=[3, 2, 2])
print(params)

def test_build_bounding_box_1(self):
origin = np.array([0., 0., 0.])
tops = np.array([1., 1., 1.])
cube = BRepPrimAPI_MakeBox(*tops).Shape()
params = FFDParameters()
params.build_bounding_box(cube)

np.testing.assert_array_almost_equal(params.box_length, tops, decimal=5)

def test_build_bounding_box_2(self):
origin = np.array([0., 0., 0.])
tops = np.array([1., 1., 1.])
cube = BRepPrimAPI_MakeBox(*tops).Shape()
params = FFDParameters()
params.build_bounding_box(cube)

expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
[0., 0., 1.]])
np.testing.assert_almost_equal(
params.position_vertices, expected_matrix, decimal=5)
# def test_build_bounding_box_1(self):
# origin = np.array([0., 0., 0.])
# tops = np.array([1., 1., 1.])
# cube = BRepPrimAPI_MakeBox(*tops).Shape()
# params = FFDParameters()
# params.build_bounding_box(cube)
#
# np.testing.assert_array_almost_equal(params.box_length, tops, decimal=5)
#
# def test_build_bounding_box_2(self):
# origin = np.array([0., 0., 0.])
# tops = np.array([1., 1., 1.])
# cube = BRepPrimAPI_MakeBox(*tops).Shape()
# params = FFDParameters()
# params.build_bounding_box(cube)
#
# expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
# [0., 0., 1.]])
# np.testing.assert_almost_equal(
# params.position_vertices, expected_matrix, decimal=5)

def test_set_position_of_vertices(self):
expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.],
Expand Down
8 changes: 4 additions & 4 deletions tests/test_igeshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from unittest import TestCase

import numpy as np
from OCC.TopoDS import TopoDS_Shape
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.TopoDS import TopoDS_Shape, TopoDS_Compound
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox

import pygem.igeshandler as ih

Expand Down Expand Up @@ -195,13 +195,13 @@ def test_iges_load_shape_correct_iges(self):
iges_handler = ih.IgesHandler()
shape = iges_handler.load_shape_from_file(
'tests/test_datasets/test_pipe.iges')
self.assertEqual(type(shape), TopoDS_Shape)
self.assertEqual(type(shape), TopoDS_Compound)

def test_iges_load_shape_correct_igs(self):
iges_handler = ih.IgesHandler()
shape = iges_handler.load_shape_from_file(
'tests/test_datasets/test_pipe.igs')
self.assertEqual(type(shape), TopoDS_Shape)
self.assertEqual(type(shape), TopoDS_Compound)

def test_iges_write_shape_to_file_raises_wrong_type(self):
iges_handler = ih.IgesHandler()
Expand Down
Loading