OpenCASCADE utility library - algorithms and convenience functions.
OCCUtils aims to be
- Simple to use: Most tasks should be accomplishable in one line of code.
- Aid rapid development: No need to write tons of utility functions ; no need to wait for long compile-times
- Modular: Pull in only what you need, or just copy the underlying sourcecode.
- Clear: What you write should be what you mean:
Edge::FromPoints()
instead ofBRepBuilderAPI_MakeEdge
three-liners. - High-Level: Common tasks in 3D engineering should be accomplishable without diving into low level OpenCASCADE code
- Modern: Uses features from C++17, because those make your code more readable.
- Liberally licensed: OCCUtils is licensed under Apache License v2.0, allowing you to copy & modify the sourcecode for use in your commercial projects for free. Keep in mind that OpenCASCADE is still LGPL licensed.
Note that OCCUtils is very young and although it is used in multiple production projects, it might not have all the functionality you want or need, and might have some bugs.
If you are missing functionality, feel free to submit an issue or pull request.
First install OpenCASCADE 7.x. My preferred method on Ubuntu is to use the FreeCAD daily PPA:
sudo add-apt-repository ppa:freecad-maintainers/freecad-daily
sudo apt-get update
sudo apt install libocct\*
Also you need to install a recent version of CMake & GCC. Since we use C++17 features, a recent version of both G++ and CMake is required:
sudo apt install cmake build-essential
On Ubuntu 18.04+ you don't need to do anything special to compile.
There are two preferred methods of building and installing OCCUtils
git clone https://github.com/ulikoehler/OCCUtils.git
cmake .
make
sudo make install
Then you can use e.g.
#include <occutils/SurfaceUtils.hxx>
using namespace OCCUtils;
// ...
auto surfOpt = SurfaceUtils::SurfaceFromFace(face);
// ...
and link with -loccutils
.
This method involves adding the repository and building it as a subproject of your CMake-based main project. I recommend doing this especially for more complex projects. However you need some knowledge of CMake to get it working and debug related issues.
In your project root directory:
git submodule init
git submodule add https://github.com/ulikoehler/OCCUtils.git OCCUtils
Then add this CMake code to your CMakeLists.txt
:
add_subdirectory(OCCUtils)
and
add_dependencies( my_target occutils )
target_link_libraries( my_target occutils )
replacing my_target
with the name of your build target (i.e. the first argument you give to add_executable()
). The occutils
CMake script will take care of the rest.
On my blog I provide examples of specific usecases for OpenCASCADE, including the following full examples:
... and examples of how to use the specific OCCUtils functions:
- How to compute surface area of TopoDS_Face in OpenCASCADE
- How to create a Cylinder TopoDS_Solid in OpenCASCADE
- How to create a Box TopoDS_Solid in OpenCASCADE
- How to create a Cube TopoDS_Solid in OpenCASCADE
- How to create TopTools_ListOfShape of two or more shapes in OpenCASCADE
- How to iterate all edges in TopoDS_Face using OpenCASCADE
- How to export STEP file in OpenCASCADE
- How to fuse TopoDS_Shapes in OpenCASCADE (boolean AND)
- How to cut shapes using OCCUtils for OpenCascade (boolean difference)
- How to export colored STEP files in OpenCASCADE
- Overview of all standard colors available in OpenCASCADE
- How to check if two gp_Pnt coincide in OpenCASCADE
- How to create TopoDS_Edge from to gp_Pnt in OpenCASCADE
- How to create TopoDS_Wire from TopoDS_Edge(s) in OpenCASCADE
- How to convert Geom_TrimmedCurve to GeomAdaptor_Curve in OpenCASCADE
- How to compute surface normal in OpenCASCADE
- How to compute volume of TopoDS_Shape / TopoDS_Solid in OpenCASCADE
- How to get midpoint/center between points in OpenCASCADE
- How to get gp_Dir orthogonal to two gp_Dirs in OpenCASCADE
- How to check if gp_Ax1 contains gp_Pnt in OpenCASCADE
- Computing distance between gp_Pnt and gp_Ax1 in OpenCASCADE
- Converting vector of TopoDS_Face to vector of TopoDS_Shape in OpenCASCADE
- Converting vector of TopoDS_Solid to vector of TopoDS_Shape in OpenCASCADE
- How to make TopoDS_Face from gp_Pnts