File | Date | Author | Commit |
---|---|---|---|
docs | 2015-05-08 |
![]() |
[ddc9a5] example pics |
printer | 2015-05-09 |
![]() |
[161abe] bug fixes |
.gitmodules | 2015-05-07 |
![]() |
[bd32f6] initial commit |
BUILD | 2015-05-07 |
![]() |
[f0d013] subdir |
LICENSE | 2015-05-07 |
![]() |
[d779a7] Initial commit |
Makefile | 2015-05-07 |
![]() |
[782545] . |
README.md | 2015-05-09 |
![]() |
[543c26] Update README.md |
When I got a 3D printer, I thought it would be fun to procedurally generate objects. While there are a few existing options for procedural generation, it sounded fullfilling to write my own. I worked on this as a side project for a while, and had a lot of fun printing everything from simple buckles to a CAT scan of my skull.
I wanted a library that started with "objects", where each object only had to specify whether given a point x,y,z was inside or outside of the object, and that's it. For example, you could write a sphere object as:
class SphereObject : public PrintObject {
public:
bool ContainsPoint(const Point& p) { return p.x()*p.x() + p.y()*p.y() + p.z()*p.z() < 100; }
};
... and magically we would get a sphere printed out with radius 10cm.
This library is written in C++, and available under BSD-3.
git clone https://github.com/chrisvana/printer.git
cd printer
# Builds binaries in printer/examples by default.
./make
# Example, generate a sphere:
./sphere --logtostderr --output_stl_file=/tmp/sphere.stl
The code works by:
1. Taking a specified set of PrintObjects
2. Filling a set of voxels based on the PrintObjects
3. Uses a Marching Cubes algorithm to triangulate the voxels into a mesh
4. Performs simplification (optional)
1. It first tries to reduce each face of the mesh to a minimal number of triangles.
2. It then computes a boundary that the mesh cannot cross using Marching Cubes again, but offset slightly.
3. Using the boundary mesh to test validity of each simplification, we performs decimation on the original mesh.
1. Finally, it writes the resulting mesh out to an STL file.
I should note that the final output is a .stl file (not the .x3g file used by most 3D printers), so you will need to slice the STL using something like ReplicatorG (or Makerware, in my case).
Simplification can be quite slow (though helps later with slicing faster), and diabled via:
- --driver_run_simplifier=false
- --driver_run_face_reduction=false
(more configuration options are described below)
The examples live in printer/examples:
- sphere: Produces a sphere.
- buckle: Produces a curved buckle.
- cylinder: Intersects two cylinders.
- merged: Produces a large ring from 200 offset spheres.
- rotated: Demonstrates some translation/rotation on the PrintObjects.
- mandel: My (mostly failed) attempt at a 3D fractal.
- print_dicom: Prints out a DICOM file (or files), used by medical imaging.
printer/dicom/dicom_set generates a PrintObject from a set of DICOM files.
It does so by taking all frames from all input DICOM files, mapping the pixels in them to points, and then interpolates values in our voxel map based on the pixel values.
The print_dicom example can be used to actually generate an STL file from a DICOM file, see print_dicom.cc for instructions.
(Not all are included)
--driver_min_triangles_to_simplify (If >= 0, the maximum number of triangles
to take before we run the simplification process.) type: int32
default: -1
--driver_boundary_is_single_voxel (Overrides inner/outer boundary to be the
voxel that contains our initial points, rather than an iso surface
defined by driver_*_boundary_iso_level.) type: bool default: true
The library's major components are split into subdirectories:
- Base geometry library: printer/base
- Contains classes for manipulating geometry.
- Points, triangles, meshes, octrees, etc.
- Procedural objects: printer/objects
- This contains our abstract PrintObject, along with some useful objects (cubes, spheres, intersection, etc).
- Voxel manipulation: printer/execute
- Drives procedural generation of voxel map.
- Takes voxel map and runs Marching Cube triangulation
- Calls simplifiers.
- Simplification: printer/simplify
- Does 2D (single face) and 3D (full mesh) simplification
- STL Output: printer/stl
- Writes STL files given a triangle mesh.
- DICOM: printer/dicom
- Loads a set of dicom files into a PrintObject to be used by the rest of the library.