Giter VIP home page Giter VIP logo

occ-csg's Introduction

OCC-CSG

Build Status Build status

Simple but powerful CSG tool based on the OpenCascade CAD Kernel

This tool provides a simple command-line interface for applying boolean operations and transformations to 3D objects specified in either BREP/STEP or STL format. It contains a convenient STL importer for converting mesh based geometries to an eqivalent BREP representation (might cause performance issues for large STL files). Geometries can be exported as STL files as well.

There is a Java library VCSG and the corresponding VRL-Studio plugin for using OCC-CSG from Java and VRL-Studio.

Installation

To get started quickly, download a binary release (available for Linux, macOS and Windows on x64). On macOS occ-csg can be installed via Homebrew:

brew install miho/tap/occ-csg

Sample

These three lines

occ-csg --create box -5,-5,-5,5,5,5 box.stp
occ-csg --create sphere 0,0,0,6.5 sphere.stp
occ-csg --csg difference box.stp sphere.stp cut.stp

produce this hollow cube:

To convert this resolution independent geometry to a triangulated STL file use:

occ-csg --convert cut.stp cut.stl 0.1

The number at the end specifies the tolerance for the STL triangulation. Smaller values lead to better approximations. If the value is ommitted a default value (currently 0.5) will be used. This is how the resulting STL might look like:

CLI

To get an overview over the CLI type ./occ-csg --help:

-------------------------------------------------------------
----        CSG Tool based on the OCCT CAD Kernel        ----
----                    Version 0.9.9                    ----
---- 2018-2019 by Michael Hoffer ([email protected]) ----
----                   www.mihosoft.eu                   ----
-------------------------------------------------------------

USAGE: 

Help & Info:

 occ-csg --help
 occ-csg --version

Creating Primitives:

 occ-csg --create box x1,y1,z1,x2,y2,z2                            box.stp
 occ-csg --create sphere x1,y1,z1,r                                sphere.stp
 occ-csg --create cyl x1,y1,z1,r,h                                 cyl.stp
 occ-csg --create cone x1,y1,z1,r1,r2,h                            cone.stp
 occ-csg --create helix r,profile_r,pitch,num_revolutions          helix.stp
 occ-csg --create helix r,profile_face.stp,pitch,num_revolutions   helix.stp
 occ-csg --create polygons x1,y1,z1,x2,y2,z2,... p1v1,p1v2,p1v3,...:p2v1,p2v2,p2v3,... polygons.stp
 occ-csg --create 2d:circle x,y,r                                  2dcircle.stp
 occ-csg --create 2d:polygon x1,y1,x2,y2,...                       2dpolygon.stp
 occ-csg --create 2d:rect x1,y1,x2,y2                              2drectangle.stp
 occ-csg --create 2d:round-rect x,y,width,height,corner_r          2drectangle.stp
 occ-csg --create extrusion:polygon ex,ey,ez,x1,y1,z1,x2,y2,z2,... extrude.stp
 occ-csg --create extrusion:file ex,ey,ez                          2dpath.stp extrude.stp

Format Conversion:

 occ-csg --convert file1.stl file1.stp
 occ-csg --convert file1.stp file1.stl 0.1

Geometric Transformation:

 occ-csg --transform translate x,y,z                               file1.stp file1-translated.stp
 occ-csg --transform scale     sx,sy,sz                            file1.stp file1-scaled.stp
 occ-csg --transform rot       dir_x,dir_y,dir_z,angle file1.stp   file1-rotated.stp
 occ-csg --transform matrix    t1,t2,t3,...,t12 file1.stp          file1-transformed.stp

Boolean Operators, Constructive Solid Geometry (CSG):

 occ-csg --csg union file1.stp file2.stp file-out.stp
 occ-csg --csg difference file1.stp file2.stp file-out.stp
 occ-csg --csg intersection file1.stp file2.stp file-out.stp

Shape Editing:

 occ-csg --edit split-shape shape.stp stp
 occ-csg --edit round-edges radius shape.stp shape-rounded.stp
 occ-csg --edit chamfer-edges radius shape.stp shape-chamfered.stp


Shape Info:

 occ-csg --info bounds file.stp      
 occ-csg --info bounds file.stp      bounds.stp
 occ-csg --info volume file.stp tol

How to build OCC-CSG

Requirements

  • C++ Compiler with C++11 support (tested with Clang, GCC, MSVC++ 2017 on x64)
  • CMake >= 3.1
  • OCC >= 7.3.0.x (official version is currently built with 7.4.0)

Hints for building OCC:

For using occ-csg as independent command-line tool it is recommended to compile OCC as static library. This will increase the occ-csg file size but ensures the tool can be used without carrying too many additional libraries around. occ-csg comes with the freetype headers to simplify the build process on Windows. The recommended settings are:

Dependencies required by OCC:
  • FreeType: if freetype cannot be found on Ubuntu then install libfreetype6-dev, we use freetype-2.7 on Windows and macOS, to build static freetype on macOS, make sure to build without zlib, libpng, bzip2 and harfbuzz (otherwise it will have dynamic dependencies to these libraries)
  • OpenGL: ย  if GL/GLU cannot be found on Unbuntu then install libglu1-mesa-dev and libgl1-mesa-dev
  • XQuartz: only necessary on macOS. Whether XQuartz is necessary depends on the version of macOS and OCC, see OCC documentation. It might be necessary to adjust the X11 include path via ln -s /opt/X11/include/X11 /usr/local/include/X11

Bash (Linux/macOS/Cygwin/other Unix-like Shell)

cd /path/to/project
mkdir build && cd build
cmake .. -DOpenCASCADE_DIR=/path/to/occ
make -j4

On Linux, it might be necessary to install fontconfig-devel to successfully link the executable. On Ubuntu the precise package name is libfontconfig-dev.

Windows (CMD)

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd" -arch=x64
cd \path\to\project
mkdir build
cd build
cmake .. -DOpenCASCADE_DIR=\path\to\occ
MSBuild .\occ-csg-prj.sln  /property:Configuration=Release /property:Platform=x64

For building large projects on Windows it might be preferable to use the x64 host compiler instead of the x86 compiler. Note that both compilers are able to produce x64 binaries. But the x64 compiler can use more memory during compilation. To really prevent that CMake picks the 64bit x86 host compiler just force cmake to use the x64 host compiler via

-DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=X64 -G "Visual Studio 15 2017 Win64"

occ-csg's People

Contributors

miho avatar piaoger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

occ-csg's Issues

why no iges support?

I wonder if you have known there are something wrong or just skip iges support.

I am trying to add iges support for occ-csg. However, I always get "Segmentation fault" while exporting iges to stl.

My environment: MacOSX & "brew install opencascade"

> loading geometry
 -> reading file '/Users/badman/models/iges/in/T26.IGS'
Total number of loaded entities 90416.
 -> done.
> saving geometry
 -> writing file '/Users/badman/models/output/k.stl'
 -> STL TOL: 0.5
Segmentation fault: 11

OpenMP Linker problem

It seems that on Linux we need to tell CMake to look for OpenMP. Otherwise we get ugly linker errors.

Version 0.9.1 - terminate called after throwing an instance of 'StdFail_NotDone'

Getting this error on a stock Ubuntu 18.04 machine for any STL I give it (random models from around the internet and generated objects from occ-csg).

Full output:

$ occ-csg --create box 0,0,0,10,10,10 box.stl
------------------------------------------------------------
------      CSG Tool based on the OCE CAD Kernel      ------
------                 Version 0.9.1                  ------
------ 2018 by Michael Hoffer ([email protected]) ------
------                www.mihosoft.eu                 ------
------------------------------------------------------------
> saving geometry
 -> writing file 'box.stl'
 -> STL TOL: 0.5
 -> done.
$ occ-csg --edit round-edges 20 box.stl box-rounded.stl
------------------------------------------------------------
------      CSG Tool based on the OCE CAD Kernel      ------
------                 Version 0.9.1                  ------
------ 2018 by Michael Hoffer ([email protected]) ------
------                www.mihosoft.eu                 ------
------------------------------------------------------------
> loading geometry
 -> reading file 'box.stl'
> importing STL file
 -> reading 'box.stl'
 -> converting to faces
 -> sewing faces
 -> extracting shells
   -> shells found: 1
 -> converting to solid
 -> done.
 -> done.
terminate called after throwing an instance of 'StdFail_NotDone'
Aborted (core dumped)

OCC-CSG examples of use in Java

Hello,
I'd like to try out OCC-CSG and see if I can incorporate this nice piece of software in my Java libraries.
Could you please provide one or more simple examples in Java?
Thanks,
Agostino

OCC Dependencies on Debian 10

Hello,

Thanks for an awesome program! very useful.
On Debian 10 (Buster), it seems installing the following packages takes care of the OCC 7.3 requirements, and there's no need to build it from source:

apt-get install libocct-data-exchange-dev libocct-draw-dev libocct-foundation-dev \
               libocct-modeling-algorithms-dev libocct-modeling-data-dev \
               libocct-ocaf-dev libocct-visualization-dev \
               libtbb-dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.