Error in GeomConvert_ApproxCurve
chenkasirer opened this issue · 3 comments
I am attempting to serialize the brep created in this example using compas.data.json_dump
but getting the following error:
Traceback (most recent call last):
...
json_dump(C, PATH, pretty=True)
File "C:\Users\ckasirer\.conda\envs\occ\lib\site-packages\compas\data\json.py", line 41, in json_dump
return json.dump(data, f, cls=DataEncoder, **kwargs)
File "C:\Users\ckasirer\.conda\envs\occ\lib\json\__init__.py", line 179, in dump
for chunk in iterable:
File "C:\Users\ckasirer\.conda\envs\occ\lib\json\encoder.py", line 438, in _iterencode
o = _default(o)
File "C:\Users\ckasirer\.conda\envs\occ\lib\site-packages\compas\data\encoders.py", line 102, in default
value = o.to_data()
File "C:\Users\ckasirer\.conda\envs\occ\lib\site-packages\compas\data\data.py", line 248, in to_data
return self.data
File "c:\users\ckasirer\repos\compas_occ\src\compas_occ\brep\brep.py", line 163, in data
faces.append(face.data)
File "c:\users\ckasirer\repos\compas_occ\src\compas_occ\brep\brepface.py", line 101, in data
boundary = self.loops[0].data
File "c:\users\ckasirer\repos\compas_occ\src\compas_occ\brep\breploop.py", line 56, in data
edges.append(edge.data)
File "c:\users\ckasirer\repos\compas_occ\src\compas_occ\brep\brepedge.py", line 120, in data
convert = GeomConvert_ApproxCurve(
File "C:\Users\ckasirer\.conda\envs\occ\lib\site-packages\OCC\Core\GeomConvert.py", line 717, in __init__
_GeomConvert.GeomConvert_ApproxCurve_swiginit(self, _GeomConvert.new_GeomConvert_ApproxCurve(*args))
TypeError: Wrong number or type of arguments for overloaded function 'new_GeomConvert_ApproxCurve'.
Possible C/C++ prototypes are:
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(opencascade::handle< Geom_Curve > const &,Standard_Real const,GeomAbs_Shape const,Standard_Integer const,Standard_Integer const)
GeomConvert_ApproxCurve::GeomConvert_ApproxCurve(opencascade::handle< Adaptor3d_HCurve > const &,Standard_Real const,GeomAbs_Shape const,Standard_Integer const,Standard_Integer const)
To Reproduce
Run the following code
from compas.geometry import Point, Vector, Plane
from compas.geometry import Box, Cylinder
from compas_occ.brep import BRep
R = 1.4
P = Point(0, 0, 0)
X = Vector(1, 0, 0)
Y = Vector(0, 1, 0)
Z = Vector(0, 0, 1)
YZ = Plane(P, X)
ZX = Plane(P, Y)
XY = Plane(P, Z)
box = Box.from_width_height_depth(2 * R, 2 * R, 2 * R)
cx = Cylinder((YZ, 0.7 * R), 4 * R)
cy = Cylinder((ZX, 0.7 * R), 4 * R)
cz = Cylinder((XY, 0.7 * R), 4 * R)
A = BRep.from_box(box)
B1 = BRep.from_cylinder(cx)
B2 = BRep.from_cylinder(cy)
B3 = BRep.from_cylinder(cz)
C = A - (B1 + B2 + B3)
json_dump(C, PATH, pretty=True)
Expected behavior
The Brep should be serialized.
Desktop (please complete the following information):
- OS: Windows 10
- CPython 3.9
Some more info:
This is due to this call to GeomConvert_ApproxCurve()
in BRepEdge.data
convert = GeomConvert_ApproxCurve(self.curve, 1e-3, GeomAbs_Shape.GeomAbs_C1, 1, 5)
Seems there's some issue with the types of the arguments being sent. I initially thought this is due to sending self.curve
which is of type compas_occ.geometry.OCCCurve
whereas Geom_Curve
is expected, but sending the underlying self.curve.occ_curve
doesn't work either.
Generally, I wasn't able to successfully call GeomConvert_ApproxCurve()
which in turn calls _GeomConvert.new_GeomConvert_ApproxCurve(*args)
. Hard to debug further because it's passed to the C binding from there on.
PyCharm seems to thing the issue is the GeomAbs_Shape.GeomAbs_C1
as it indicates that I'm sending an int
rather than the Enum type, but not sure if that's really the issue, and in any case not sure how to do it differently.
the use of GeomConvert_ApproxCurve
was an attempt to always convert to NURBS without any further checks. it seems that this doesn't really work. so we will have to go back to the more elaborate setup of checking curve types and doing specific conversions.
will update...
going to close this, even though not entirely solved yet, since the code has changed quite a bit in the meantime...