Skip to content

Commit cc2f97b

Browse files
author
fsalmoir
committed
Merge pull request #61 from fsalmoir/iges_knot_insertion
added tolerance control to deal with complex geometries
2 parents 2d692d7 + 0abab67 commit cc2f97b

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

pygem/igeshandler.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ class IgesHandler(fh.FileHandler):
3131
It is equal to ['.iges', '.igs'].
3232
:cvar list control_point_position: index of the first NURBS control point (or pole)
3333
of each face of the iges file.
34+
:cvar float tolerance: tolerance for the construction of the faces and wires
35+
in the write function. Default value is 1e-6.
36+
37+
.. warning::
38+
39+
- For non trivial geometries it could be necessary to increase the tolerance.
40+
Linking edges into a single wire and then trimming the surface with the wire
41+
can be hard for the software, especially when the starting CAD has not been
42+
made for analysis but for design purposes.
3443
"""
3544
def __init__(self):
3645
super(IgesHandler, self).__init__()
3746
self.extension = ['.iges', '.igs']
3847
self._control_point_position = None
48+
self.tolerance = 1e-6
3949

4050

4151
def parse(self, filename):
@@ -46,9 +56,6 @@ def parse(self, filename):
4656
the points of the mesh
4757
:rtype: numpy.ndarray
4858
49-
.. todo::
50-
51-
- specify when it works
5259
"""
5360
self._check_filename_type(filename)
5461
self._check_extension(filename)
@@ -106,7 +113,7 @@ def parse(self, filename):
106113
return mesh_points
107114

108115

109-
def write(self, mesh_points, filename):
116+
def write(self, mesh_points, filename, tolerance=None):
110117
"""
111118
Writes a iges file, called filename, copying all the structures from self.filename but
112119
the coordinates. mesh_points is a matrix that contains the new coordinates to
@@ -121,6 +128,9 @@ def write(self, mesh_points, filename):
121128
self._check_infile_instantiation(self.infile)
122129

123130
self.outfile = filename
131+
132+
if tolerance is not None:
133+
self.tolerance = tolerance
124134

125135
# init the ouput file writer
126136
writer = IGESControl_Writer()
@@ -168,7 +178,7 @@ def write(self, mesh_points, filename):
168178
# construct the deformed wire for the trimmed surfaces
169179
wire_maker = BRepBuilderAPI_MakeWire()
170180
tol = ShapeFix_ShapeTolerance()
171-
brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), 1e-4).Face()
181+
brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), self.tolerance).Face()
172182
brep_face = BRep_Tool.Surface(brep)
173183

174184
# cycle on the edges
@@ -180,7 +190,7 @@ def write(self, mesh_points, filename):
180190
# evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones
181191
edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge(edge_uv_coordinates[0], brep_face)
182192
edge_phis_coordinates = edge_phis_coordinates_aux.Edge()
183-
tol.SetTolerance(edge_phis_coordinates, 1e-4)
193+
tol.SetTolerance(edge_phis_coordinates, self.tolerance)
184194
wire_maker.Add(edge_phis_coordinates)
185195
edge_explorer.Next()
186196

tests/test_igeshandler.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def test_iges_default_control_point_position_member(self):
2727
def test_iges_default_outfile_member(self):
2828
iges_handler = ih.IgesHandler()
2929
assert iges_handler.outfile == None
30+
31+
32+
def test_iges_default_tolerance(self):
33+
iges_handler = ih.IgesHandler()
34+
assert iges_handler.tolerance == 1e-6
3035

3136

3237
def test_iges_default_extension_member(self):
@@ -134,6 +139,24 @@ def test_iges_write_outfile(self):
134139
iges_handler.write(mesh_points, outfilename)
135140
assert iges_handler.outfile == outfilename
136141
os.remove(outfilename)
142+
143+
144+
def test_iges_write_outfile_tolerance(self):
145+
iges_handler = ih.IgesHandler()
146+
mesh_points = iges_handler.parse('tests/test_datasets/test_pipe.iges')
147+
outfilename = 'tests/test_datasets/test_pipe_out.iges'
148+
iges_handler.write(mesh_points, outfilename, 1e-3)
149+
assert iges_handler.tolerance == 1e-3
150+
os.remove(outfilename)
151+
152+
153+
def test_iges_write_modified_tolerance(self):
154+
iges_handler = ih.IgesHandler()
155+
mesh_points = iges_handler.parse('tests/test_datasets/test_pipe.iges')
156+
outfilename = 'tests/test_datasets/test_pipe_out.iges'
157+
iges_handler.write(mesh_points, outfilename, 1e-3)
158+
assert iges_handler.outfile == outfilename
159+
os.remove(outfilename)
137160

138161

139162
def test_iges_write_comparison_iges(self):

0 commit comments

Comments
 (0)