Q&A from StackOverflow and more

I’ve been messing around with StackOverflow topics related to OpenCascade and found quite some interesting questions there. There are not so many, and definitely SO is not the right place to search for OCC community help. But people keep asking questions, and I could not resist the impulse of trying to answer them. Although this blog is definitely not the right place to answer OCC questions either!

So here is my “golden list” as of June 2021:

Question 1: about collision detection

With OpenCascade, how to do collision detection of 2 shapes? There may be several ways. One is to calculate their intersection and check the intersection results. Another way is to calculate their minimum distance. Which way is faster? Or any faster ways? Thanks a lot. (go to the source)

Well, the answer was provided (click the link above) and it’s definitely a good answer. Just to add another reference for those having the capacity of implementing things from scratch: [Christer Ericson. 2004. Real-Time Collision Detection. CRC Press, Inc., USA.]. That’s a great reading containing tons of useful C/C++ code snippets with explanations and follow-up discussions. Personally, I’ve used a couple of functions from this book, and I’m looking forward to opportunities to dive deeper into that monograph and try more things out.

Question 2: CGAL versus OpenCascade

Which CAD/geometry library should I use [for CAD]: CGAL, Open CASCADE, Boost::Geometry, or something else? (go to the source)

OpenCascade got quite a low grade in the first answer, while some reasoning about the quality looks a little bit speculating to me. To be honest, I never used CGAL (https://www.cgal.org/) in any industrial project, but I tend to think that CGAL is just a little bit out of scale. The reason for that is simple: CGAL does not lend itself as a full-featured CAD kernel, although I’m pretty sure it could be employed ad-hoc.

The following downsides of OpenCascade were brought to the table on StackOverflow:

Well, let’s go over these claims one by one.

As a small wrap-up, let me share a bit of my modus operandi here. I use OpenCascade for more than 10 years already, and I’m not going to give up, because there’s no alternative. But whenever I happen to hit the limitations of the library, I never tend to take other products like CGAL for the rescue, and prefer implementing the missing stuff from scratch. The truth is that other libs can do very little for you once you found yourself hitting the ultimate OpenCascade’s wall. Unless you’re trying to solve a problem that is out of the traditional CAD modeling scope, of course.

Question 3: direct editing?

How can I change the underlying geometry of a TopoDS_Shape in OpenCASCADE ? (go to the source)

There’s no easy way of doing this. OpenCascade was designed for history-based editing that assumes rebuilding your geometries from scratch (or starting from a certain cached version of it) whenever any design parameter changes its value. This discussion takes us to the holy grail of contemporary geometric modeling, which is direct editing. In OpenCascade, there is currently no such API.

I can share with you a little bit of experience here. To start off, any direct editing technique requires something called “local operation,” which is basically a way to modify your shape without rebuilding it from scratch. Think of dragging a vertex for example. One simple technique that can be employed for developing local operations is using the so-called Euler Operators. Did I say “simple”?

In our paper [Slyadnev, S. E., & Turlapov, V. E. (2020). Simplification of CAD Models by Automatic Recognition and Suppression of Blend Chains. Programming and Computer Software, 46(3), 233–243. https://doi.org/10.1134/S0361768820030081], we came up with a couple of Euler Operators for CAD model simplification. Just two of them: kell-edge-vertex (KEV) and kill-edge-face (KEF). And guess what? It was insanely hard to develop these two things on the top of a B-rep modeler like OpenCascade. I mean, it literally takes weeks to develop the operators that are trivially implemented in a couple of hours when dealing with meshes (think of edge/face collapse tools). If you want to know more about our simplification algorithm, check it out in Analysis Situs.

Let’s finish for today. There are many more interesting questions to cover, but it starts to be too much for a single blog post. Stay tuned!

Open-source CAD platform: analysissitus.org