Skip to content

Instantly share code, notes, and snippets.

View ochafik's full-sized avatar

Olivier Chafik ochafik

View GitHub Profile
@ochafik
ochafik / test_pmp.cc
Created February 20, 2021 01:14
Check edge cases of CGAL::Polygon_mesh_processing::corefine_and_compute_union
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
/*
https://github.com/openscad/openscad/pull/3641
g++ \
-stdlib=libc++ -std=c++1y \
-I../CGAL-5.2/include \
-lgmp -lmpfr \
@ochafik
ochafik / repair.cc
Created February 19, 2021 19:52
CGAL::Polyhedron_3 repair code with CGAL::Polygon_mesh_processing::repair_polygon_soup
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
template <typename K>
std::shared_ptr<CGAL::Polyhedron_3<K>> repairPolyhedron(const CGAL::Polyhedron_3<K> &poly)
{
@ochafik
ochafik / README.md
Last active February 22, 2021 15:04
CGAL corefinement vs. potentially-invalid inputs vs. attempts to fall back to Nef: error cases

Here's now to build the branch from openscad/openscad#3641 (see full build instructions)

git clone --depth 1 http://github.com/ochafik/openscad  --single-branch --branch fast_csg ochafik-openscad
cd ochafik-openscad
rm -fR objects/
qmake openscad.pro \
  CONFIG+=debug \
  CONFIG+=experimental \
 CONFIG+=info \
@ochafik
ochafik / cgal-kernels.h
Last active July 26, 2023 12:18
CGAL: convert between CGAL::Cartesian<CGAL::Gmpq> and CGAL::Epeck
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
@ochafik
ochafik / benchmark results.txt
Last active January 30, 2021 18:38
Experiment w/ fast-union heuristic to break local overlapping barriers
# Context: https://github.com/openscad/openscad/pull/3636
Notice the N=3 vs. N=5 below. All test on a MacBook Pro w/ 2.6GHz Core i7.
# Baseline
time openscad spheres_single_for_loop.scad -o out.stl -DN=3 -Doverlap=true # 52s
time openscad spheres_nested_for_loops.scad -o out.stl -DN=3 -Doverlap=true # 45s
time openscad spheres_single_for_loop.scad -o out.stl -DN=5 -Doverlap=true # 3min32
time openscad spheres_nested_for_loops.scad -o out.stl -DN=5 -Doverlap=true # 2min41
@ochafik
ochafik / compare.sh
Created January 30, 2021 16:04
OpenSCAD benchmarking utility (compares various features and logs times neatly)
#!/bin/bash
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
#
# Author: Olivier Chafik (http://ochafik.com)
#
# Usage:
# - Checkout my optimization integration branch (doesn't include multithreaded changes):
# git clone https://github.com/ochafik/openscad openscad-ochafik
# cd openscad-ochafik
@ochafik
ochafik / chainmail.scad
Last active January 30, 2021 15:21
OpenSCAD Chainmail benchmark for fast-union evaluation
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
// Author: Olivier Chafik (http://ochafik.com)
//
// This is extracted from my little chain/scalemail project shared in
// https://gist.github.com/ochafik/6d19e3b131153305b44ea275d5d930e3
//
// It is simpler to render, this example is crafted to exercice the fast-union
// feature I'm proposing in https://github.com/openscad/openscad/pull/3636
@ochafik
ochafik / _scalemail_10x10_heart.png
Last active February 14, 2021 03:32
An OpenSCAD model of scalemail (source included below) that benefits from rendering optimizations under development.
_scalemail_10x10_heart.png
@ochafik
ochafik / uncacheable_pattern.scad
Last active January 29, 2021 13:56
OpenSCAD file with an irregular pattern
// Context: ochafik@'s attempts to speed up OpenSCAD
// fast-union feature: https://github.com/openscad/openscad/pull/3636
// lazier union features: https://github.com/openscad/openscad/pull/3637
//
// (and parallelization attempts, not sent as PRs yet)
//
// fast-union, lazy-union, push-transforms-down-unions, lazy-module and flatten-children all help here!
// openscad --enable=fast-union cube-with-half-spheres-dents.scad -o cube-with-half-spheres-dents.stl
top_transform = true;
@ochafik
ochafik / README.md
Last active December 10, 2024 07:01
OpenSCAD Examples sped up by fast-csg feature

Here are some micro benchmarks that demonstrate big gains of OpenSCAD rendering with --enable=fast-csg (a feature I developed in this pull request).

Note: some (but not all) models making heavy use of minkowski may be slower with the feature enabled, as CGALUtils::applyMinkowski is forcing conversions to the old nef format. I hope to address that + publish benchmarks involving minkowski operations soon!*

Note2: these figures need updating, lots of changes since last time I tested these files! Most notably, I'm now proactively falling back to Nef computations in many cases that could have been handled by fast PMP operations on surface meshes, just by fear of hitting corner cases that might corrupt the data. Makes things slower :-(

  • uncacheable-grid.scad (see below): 35sec -> 1.5sec (31x faster)
  • chainmail.scad (see below): 24min 15sec -> 4min 27sec (5x faster)
  • spheres_nested_for_loops.scad (see below): 44sec