Giter Site home page Giter Site logo

meshdiff's Introduction

MESHDIFF: get the difference between topographic scans and reference STL files

This is a small utility to solve the following problem:

  • You are 3D-printing / precision-machining a shape from a STL file.
  • You can get a topography from the object, stored as a text file containing the topography's 3D coordinates (in the original application, the topography was obtained with a line laser scanner mounted in a linear axis moving orhtogonally w.r.t. the line scanner).
  • You need to measure possible differences and errors between the STL file and the result, as measured from the topography.

While not perfect, a first approximation to this problem is easy enough: just convert the topography to a STL file, and compute the difference between it and the original file. This is a small Python application that uses third-party software to solve this problem, with both command-line and GUI front-ends.

To solve the problem of computing the difference between two meshes, there are several possible solutions. One that is relatively good is gilbo's cork. cork has some issues with degenerate faces and repeated application of boolean operations, but for our particular use case is just fine, and actually better than other alternatives using floating point arithmetic. There is still one problem: cork does not accept STL files. To work around this issue, we use FreeCAD to convert STL files to OFF files and vice versa.

Examples

See the wiki for an example. The images from that example are reproduced below:

original object:

original

topography:

topography

difference (result from using this utility):

difference

Files

  • meshdiff.py contains all the logic to call FreeCAD and cork, and generate meshes from topograpic scans.

  • app.py implements a command-line front-end

  • gui.py implements a GUI front-end

  • freecadscript.py contains the Python code to use FreeCAD (because in Windows, a separate Python executable is usually needed to use FreeCAD as a Python library).

Known issues

  • In Windows, the scripts are currently hard-coded to use FreeCAD from the default install directory for FreeCAD 0.14.

  • The topography file is currently hard-coded to be the following format: a text file, one coordinate per line, with coordinates separated by semicolons.

Deployment

The Python scripts have been tested in Debian jessie and Windows 7. They have the following dependencies:

  • Python 2.7.9 (or later in the 2.7.* series)

  • SciPy (at least the 0.14 version, since previous versions do not consistently orient faces in Delaunay triangulations).

  • WxPython 3.0 (if using gui.py)

  • If you are in windows and you decide to go for 64-bit, make sure to get a Python distribution that handles x64 properly, or download the python packages from www.lfd.uci.edu/~gohlke/pythonlibs

  • FreeCAD (the scripts were developed with the 0.14 version, but any later version should be fine).

  • You will also need to compile cork and place the binary in the same folder as the Python scripts (for ease of use, cork binaries for Windows are provided in a zip file i the release).

Compiling cork in Linux is no big deal, just follow the instructions from gilbo's repository (or any fork you trust). However, in Windows, the history is a bit different. cork can be readily compiled in Visual Studio 2012 and later releases. However, you will also need a version of GMP compiled with exactly the same parameters. Now, GMP is easily built in POSIX machines, but not so easily in Windows ones. There is a fork of GMP with Windows support, MPIR, but it does not work well for cork. The alternative is to use CygWin to compile both GMP and cork, or cross-compile in POSIX for Windows. CygWin is a pain to install and configure, so I went for cross-compiling. However, cross-compiling is also a pain, and it turns out that it is a bit difficult to configure it properly and do the correct incantations in Debian: GMP cannot be easily compiled with clang because of errors in assembler code, apparently configured for gcc (ASM instructions can be disabled, but significant performance is lost in the process), but if compiled with gcc, it cannot be linked with code compiled in clang (required by cork) because gcc and clang differ in their exception handling methods. However, it is far easier in ArchLinux, as all the aforementioned problems are already solved. So I went for installing ArchLinux in a chroot of my Debian machine and cross-compiling sogilis' fork, following instructions from this comment. If you want to reproduce the build, this is my bash history in the ArchLinux chroot (be careful, it may contain errors, please also note that I unpackaged cork, mingw-w64-clang and mingw-w64-gmp in a custom directory of the chroot, /home/build):

pacman-key --init
pacman-key --populate archlinux
pacman -Syu
pacman -S base-devel --noconfirm
pacman -S mingw-w64-gcc --noconfirm
cd /home/build/mingw-w64-clang/
makepkg --asroot -s
pacman -U /home/build/mingw-w64-clang/mingw-w64-clang-r60.46ac262-1-x86_64.pkg.tar.xz
cd /home/build/mingw-w64-gmp/
makepkg --asroot -s
pacman -U /home/build/mingw-w64-gmp/mingw-w64-gmp-6.0.0-2-any.pkg.tar.xz
cd /home/build/cork
make CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ GMP_INC_DIR=/usr/x86_64-w64-mingw32/include/ GMP_LIB_DIR=/usr/x86_64-w64-mingw32/lib/

Licensing

This software is licensed under the GPLv2.

meshdiff's People

Contributors

jdfr avatar

Watchers

 avatar

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.