Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinknowles/f281d9dcfe73cfd2a360dff9e128cd19 to your computer and use it in GitHub Desktop.
Save robinknowles/f281d9dcfe73cfd2a360dff9e128cd19 to your computer and use it in GitHub Desktop.
Building triangle_alpha_wrap from the CGAL examples

Shrink-wrapping triangle meshes using CGAL

Accompanies OnCFD Newsletter #147: "It's a(n open-source) wrap"

Here are my "high-level" notes on building a command-line, mesh shrinkwrapper using Alpha Wrap 3 from CGAL.

I did this in an Ubuntu container on a Mac, but you could do similar in Windows Subsystem for Linux or native Ubuntu (or anywhere else that you can grab all of the dependecies).

See the accompanying article for more background 👋

Prep

# Refresh repository lists 
sudo apt-get update

# Install pre-requisites (you may already have many of them)
sudo apt-get install cmake wget build-essential libgmp-dev libmpfr-dev libboost-all-dev

# Download & extract latest CGAL source code
wget https://github.com/CGAL/cgal/releases/download/v5.5.2/CGAL-5.5.2.tar.xz
tar xf CGAL-5.5.2.tar.xz

# Install CGAL into /usr/local/lib/...
cd CGAL-5.5.2
cmake .
make install

Code

Copy the following code example & save it locally as mesh_wrap.cpp

Build

In the directory containing your new source code file, run the following:

# Prepare the inputs for cmake
cgal_create_CMakeLists -s mesh_wrap

# Use cmake to create the build files
cmake -DCGAL_DIR=/usr/local/lib/cmake/CGAL -DCMAKE_BUILD_TYPE=Release .

# Build the executable
make

To Run

The command-line options aren't documented as such, but you can run your new tool using the following:

./mesh_wrap INPUT_FILE ALPHA_VALUE OFFSET_VALUE

See here for an illustration of appropriate alpha & offset values & what they do.

For example:

./mesh_wrap wrapThisTri.stl 100 800

Possible Changes

The code currently writes Object File Format .off files if you'd prefer .obj output you could change this line in the source code from .off at the end to .obj (or .stl etc).

Recompile the code & you'll have .obj output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment