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
18 changes: 9 additions & 9 deletions pygem/cad/cad_deformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
BRepBuilderAPI_MakeWire,
BRepBuilderAPI_MakeEdge,
BRepBuilderAPI_NurbsConvert)
from OCC.Core.BRep import BRep_Tool, BRep_Tool_Curve
from OCC.Core.BRep import BRep_Tool
from OCC.Core.Geom import Geom_BSplineCurve, Geom_BSplineSurface
from OCC.Core.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
geomconvert_CurveToBSplineCurve,
geomconvert,
GeomConvert_CompCurveToBSplineCurve)
from OCC.Core.gp import gp_Pnt
from OCC.Core.BRepTools import breptools_OuterWire
from OCC.Core.BRepTools import breptools
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.Interface import Interface_Static_SetCVal
from OCC.Core.STEPControl import (STEPControl_Writer, STEPControl_Reader,
STEPControl_AsIs)
from OCC.Core.IGESControl import (IGESControl_Writer, IGESControl_Reader,
IGESControl_Controller_Init)
IGESControl_Controller)


class CADDeformation():
Expand Down Expand Up @@ -138,7 +138,7 @@ def write_shape(filename, shape):
"""
def write_iges(filename, shape):
""" IGES writer """
IGESControl_Controller_Init()
IGESControl_Controller.Init()
writer = IGESControl_Writer()
writer.AddShape(shape)
writer.Write(filename)
Expand Down Expand Up @@ -181,7 +181,7 @@ def _bspline_surface_from_face(self, face):
# GeomSurface obtained from Nurbs face
surface = BRep_Tool.Surface(nurbs_face)
# surface is now further converted to a bspline surface
bspline_surface = geomconvert_SurfaceToBSplineSurface(surface)
bspline_surface = geomconvert.SurfaceToBSplineSurface(surface)
return bspline_surface

def _bspline_curve_from_wire(self, wire):
Expand Down Expand Up @@ -216,10 +216,10 @@ def _bspline_curve_from_wire(self, wire):
nurbs_edge = nurbs_converter.Shape()

# here we extract the underlying curve from the Nurbs edge
nurbs_curve = BRep_Tool_Curve(nurbs_edge)[0]
nurbs_curve = BRep_Tool.Curve(nurbs_edge)[0]

# we convert the Nurbs curve to Bspline curve
bspline_curve = geomconvert_CurveToBSplineCurve(nurbs_curve)
bspline_curve = geomconvert.CurveToBSplineCurve(nurbs_curve)

# we can now add the Bspline curve to the composite wire curve
composite_curve_builder.Add(bspline_curve, self.tolerance)
Expand Down Expand Up @@ -448,7 +448,7 @@ def __call__(self, obj, dst=None):
# using the outer wire, and then we can trim it
# with the wires corresponding to all the holes.
# the wire order is important, in the trimming process
if wire == breptools_OuterWire(face):
if wire == breptools.OuterWire(face):
outer_wires.append(modified_wire)
else:
inner_wires.append(modified_wire)
Expand Down
48 changes: 31 additions & 17 deletions tests/test_ffdcad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,42 @@
from pygem.cad import CADDeformation



class TestFFDCAD(TestCase):

def extract_floats(self, lines):
"""
Extract all numeric values from IGES file content.

This helper function parses a list of IGES file lines and returns
a flattened numpy array of all floating-point numbers, ignoring
line breaks, empty lines, and non-numeric text.

IGES files often wrap data lines differently on different platforms.
By flattening all numeric values into a single array, this function enables reliable numerical comparison of IGES files regardless of
line wrapping or minor formatting differences.
"""
all_values = []
for line in lines:
if not line.strip():
continue
parts = line.strip().split(',')[:-1]
for p in parts:
try:
all_values.append(float(p))
except ValueError:
pass
return np.asarray(all_values)

def test_ffd_iges_pipe_mod_through_files(self):
ffd = FFD(None,30,30,30,1e-4)
ffd.read_parameters(
filename='tests/test_datasets/parameters_test_ffd_iges.prm')
ffd('tests/test_datasets/test_pipe.iges', 'test_pipe_result.iges')
with open('test_pipe_result.iges', "r") as created, \
open('tests/test_datasets/test_pipe_out_true.iges', "r") as reference:
ref = reference.readlines()[5:]
cre = created.readlines()[5:]
self.assertEqual(len(ref),len(cre))
for i in range(len(cre)):
ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float)
cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float)
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
ref_data = self.extract_floats(reference.readlines()[5:])
cre_data = self.extract_floats(created.readlines()[5:])
np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6)
self.addCleanup(os.remove, 'test_pipe_result.iges')

def test_ffd_iges_pipe_mod_through_topods_shape(self):
Expand All @@ -39,13 +58,9 @@ def test_ffd_iges_pipe_mod_through_topods_shape(self):
CADDeformation.write_shape('test_pipe_hollow_result.iges', mod_shape)
with open('test_pipe_hollow_result.iges', "r") as created, \
open('tests/test_datasets/test_pipe_hollow_out_true.iges', "r") as reference:
ref = reference.readlines()[5:]
cre = created.readlines()[5:]
self.assertEqual(len(ref),len(cre))
for i in range(len(cre)):
ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float)
cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float)
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
ref_data = self.extract_floats(reference.readlines()[5:])
cre_data = self.extract_floats(created.readlines()[5:])
np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6)
self.addCleanup(os.remove, 'test_pipe_hollow_result.iges')

"""
Expand All @@ -64,5 +79,4 @@ def test_ffd_step_pipe_mod_through_files(self):
cre_ = np.asarray(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", cre[i]),dtype=float)
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
self.addCleanup(os.remove, 'test_pipe_result.step')
"""

"""
Loading