tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.36k stars 378 forks source link

Is there a way to approximate Spline surfaces with basic OCC objects? #1039

Open tnakaicode opened 3 years ago

tnakaicode commented 3 years ago

I'm trying to figure out if there is a way to approximate the part of a shape that is loaded in a STEP file where Spline is used. Is there any way to approximate the surface generated by Spline using gp_Circe, gp_Cone, gp_Torus, gp_Plane, etc.?

As for the conversions, they are equivalent to the inverse conversion of Class in the following URL. https://dev.opencascade.org/doc/occt-7.5.0/refman/html/class_convert___circle_to_b_spline_curve.html

I would like to hear your opinions.

cafhach commented 3 years ago

You want to fit a primitive surface like a cone to a BSplineSurface?

tnakaicode commented 3 years ago

Yes, correct. I want to fit primitive surface (gp_Plane, gp_Sphere, gp_Torus, gp_Cone, etc) to BSplineSurface.

rainman110 commented 3 years ago

Yes, but not directly. A cone for example consists of two surface (bottom and mantle). You have to extract the surface you are interested in with BrepTool_surface and then convert the surface into a Geom_BSplineSurface with GeomConvert_SurfaceToBSplineSurface.

tpaviot commented 2 years ago

As far as I understand you want to approximate a BSpline surface using primitive surfaces like cones, planes, spheres, etc. Usually we work the other way (using for example the GeomConvert_SurfaceToBSplineSurface class). What kind of industrial workflow requires a spline surf to be approximated using these basic surfaces ??? maybe I misunderstand?

cafhach commented 2 years ago

You could try to employ a general optimization algorithm (e.g. from SciPy) to find the parameters of your primitive surface. All you'd require would hopefully be a distance quantity. Perhaps pythonocc could help here by measuring the distance between the surfaces on a grid of points on the BSplineSurface. This quantity would have to be minimized by the optimizer then.

tnakaicode commented 2 years ago

"to approximate a BSpline surface using primitive surfaces like cones, planes, spheres, etc" is correct. This is exactly what I want to do. And it is certainly out of the normal workflow.

Specifically, I use it to read geometry data in an analysis code called MCNP. The MCNP Manual https://mcnp.lanl.gov/pdf_files/la-ur-17-29981.pdf p.59 Table3-4 lists the configurations that MCNP can read geometry data. Many models created by CAD software or OpenCASCADE contain splines, but there are several other analysis codes such as MCNP that do not contain splines in their readable geometry. I am wondering if there is a way to pass the data to such analysis codes that have difficulties in reading.

tpaviot commented 2 years ago

And what about using a 2d tri or planar quad mesh?