-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
9,263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Set the default behavior, in case people don't have core.autocrlf set. | ||
* text=auto | ||
|
||
# Explicitly declare text files you want to always be normalized and converted | ||
# to native line endings on checkout. | ||
*.tex text | ||
*.bib text | ||
*.svg text | ||
*.py text | ||
*.vbs text | ||
*.cpp text | ||
*.hpp text | ||
Makefile text | ||
|
||
# Declare files that will always have CRLF line endings on checkout. | ||
*.sln text eol=crlf | ||
|
||
# Denote all files that are truly binary and should not be modified. | ||
*.png binary | ||
*.jpg binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,10 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
# Extra directories | ||
.idea/ | ||
.vscode/ | ||
/cmake-build-* | ||
/build* | ||
/external* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
dist: trusty | ||
sudo: false | ||
language: cpp | ||
cache: ccache | ||
matrix: | ||
include: | ||
- os: linux | ||
compiler: gcc-7 | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- gcc-7 | ||
- g++-7 | ||
- xorg-dev | ||
- libglu1-mesa-dev | ||
env: | ||
- MATRIX_EVAL="export CC=gcc-7 && CXX=g++-7 && CONFIG=Debug && NPROC=2" | ||
- os: osx | ||
compiler: clang | ||
env: | ||
- MATRIX_EVAL="export CONFIG=Debug && NPROC=2" | ||
|
||
install: | ||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi | ||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi | ||
- eval "${MATRIX_EVAL}" | ||
|
||
script: | ||
- mkdir build | ||
- cd build | ||
- cmake -DCMAKE_BUILD_TYPE=$CONFIG .. | ||
- make -j ${NPROC} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
################################################################################ | ||
# General Information | ||
################################################################################ | ||
|
||
cmake_minimum_required(VERSION 3.8) | ||
project(voroffset) | ||
|
||
################################################################################ | ||
|
||
set(VOROFFSET_EXTERNAL ${CMAKE_CURRENT_SOURCE_DIR}/external/) | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
message(STATUS "No build type selected, default to Release") | ||
set(CMAKE_BUILD_TYPE "Release") | ||
endif() | ||
|
||
################################################################################ | ||
|
||
# Use folder in Visual Studio | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
||
# Color output | ||
include(UseColors) | ||
|
||
# Export compile flags(used for autocompletion of the C++ code) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) | ||
|
||
# CMake plugin for vscode | ||
include(CMakeToolsHelpers OPTIONAL) | ||
|
||
# Generate position independent code | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# Build shared or static? | ||
# set(BUILD_SHARED_LIBRARIES OFF) | ||
|
||
################################################################################ | ||
|
||
# CMake options | ||
option(VOROFFSET_WITH_SANITIZERS "Enable sanitizers" OFF) | ||
option(VOROFFSET_WITH_TBB "Enable TBB" ON) | ||
|
||
option(SANITIZE_ADDRESS "Sanitize Address" OFF) | ||
option(SANITIZE_MEMORY "Sanitize Memory" OFF) | ||
option(SANITIZE_THREAD "Sanitize Thread" OFF) | ||
option(SANITIZE_UNDEFINED "Sanitize Undefined" OFF) | ||
|
||
# Override cached options | ||
# set(SANITIZE_ADDRESS OFF CACHE BOOL "" FORCE) | ||
# set(VOROFFSET_WITH_TBB ON CACHE BOOL "" FORCE) | ||
|
||
################################################################################ | ||
# Dependencies | ||
################################################################################ | ||
|
||
# Sanitizers | ||
if(VOROFFSET_WITH_SANITIZERS) | ||
list(APPEND CMAKE_MODULE_PATH ${VOROFFSET_EXTERNAL}/sanitizers-cmake/cmake) | ||
endif() | ||
|
||
include(VoroffsetDependencies) | ||
|
||
################################################################################ | ||
|
||
# 2D version prototype | ||
add_subdirectory(src/vor2d) | ||
|
||
# 3D version prototype | ||
add_subdirectory(src/vor3d) | ||
|
||
# Binary executables | ||
add_subdirectory(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Voroffset | ||
|
||
Discrete mesh offsetting based on half-space Voronoi diagrams and Power diagrams. | ||
|
||
### Compilation | ||
|
||
Dependencies are downloaded automatically by CMake at configuration time. To compile the code, just type: | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
cmake -j8 | ||
``` | ||
|
||
### Running the code | ||
|
||
See possible options with: | ||
|
||
```bash | ||
./offset3d -h | ||
``` | ||
|
||
Example usage: | ||
|
||
``` | ||
./offset3d filigree.ply -n 512 -p 10 -r 5 -x dilation | ||
``` | ||
|
||
##### offset2d | ||
|
||
Takes a .svg file as input, and saves the result of the dilation as a quad-mesh (.obj). | ||
|
||
##### offset3d | ||
|
||
Takes a triangle mesh as input (.stl, .obj, .off), and saves the dilated output as a mesh (quad-mesh with .obj, hex-mesh with .mesh, etc.) | ||
|
||
``` | ||
Offset3D | ||
Usage: ./offset3d [OPTIONS] input [output] | ||
Positionals: | ||
input TEXT Input model | ||
output TEXT=output.obj Output model | ||
Options: | ||
-h,--help Print this help message and exit | ||
-i,--input TEXT Input model | ||
-o,--output TEXT=output.obj Output model | ||
-j,--json TEXT Output json file | ||
-d,--dexels_size FLOAT=1 Size of a dexel (in mm) | ||
-n,--num_dexels INT=256 Number of dexels (-1 to use dexel size instead) | ||
-p,--padding INT Padding (in #dexels) | ||
-t,--num_thread UINT=6 Number of threads | ||
-r,--radius FLOAT=8 Dilation/erosion radius (in #dexels) | ||
-m,--method TEXT in {brute_force,ours} | ||
The method to use | ||
-x,--apply TEXT in {closing,dilation,erosion,noop,opening}=dilation | ||
Morphological operation to apply | ||
-f,--force Overwrite output file | ||
-u,--radius_in_mm Radius is given in mm instead | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_subdirectory(cli2d) | ||
add_subdirectory(cli3d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
################################################################################ | ||
|
||
cmake_minimum_required(VERSION 3.3) | ||
project(offset2d) | ||
|
||
################################################################################ | ||
|
||
# Add executable | ||
add_executable(${PROJECT_NAME} offset2d.cpp) | ||
|
||
# Let's get a little bit paranoid | ||
include(SetWarnings) | ||
target_compile_options(${PROJECT_NAME} PRIVATE ${ALL_WARNINGS}) | ||
|
||
# Sanitizers | ||
if(VOROFFSET_WITH_SANITIZERS) | ||
add_sanitizers(${PROJECT_NAME}) | ||
endif() | ||
|
||
# Dependencies | ||
target_link_libraries(${PROJECT_NAME} PRIVATE vor2d yimg::yimg CLI11::CLI11) | ||
|
||
# Output directory for binaries | ||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
#include <CLI/CLI.hpp> | ||
#include <YImage.hpp> | ||
#include <vector> | ||
#include <vor2d/CompressedImage.h> | ||
#include <vor2d/Dexelize.h> | ||
#include <vor2d/DoubleCompressedImage.h> | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#define WHITE YImage::YPixel({255, 255, 255, 255}) | ||
#define BLACK YImage::YPixel({0, 0, 0, 255}) | ||
|
||
bool pixel_is_white(YImage::YPixel p) { | ||
return p.r > 128 || p.g > 128 || p.b > 128 || p.a > 128; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
// Default arguments | ||
struct { | ||
std::string input; | ||
std::string output = "out.png"; | ||
double radius = 0; | ||
bool erode = false; | ||
bool force = false; | ||
bool transpose = false; | ||
bool negate = false; | ||
} args; | ||
|
||
// Parse arguments | ||
CLI::App app("Offset2D"); | ||
app.add_option("input,-i,--input", args.input, "Input image.") | ||
->required() | ||
->check(CLI::ExistingFile); | ||
app.add_option("output,-o,--output", args.output, "Output image."); | ||
app.add_option("-r,--radius", args.radius, "Dilation/erosion radius."); | ||
app.add_flag("-e,--erode", args.erode, "Erode instead of dilate."); | ||
app.add_flag("-f,--force", args.force, "Overwrite output file."); | ||
app.add_flag("-t,--transpose", args.transpose, "Transpose input image."); | ||
app.add_flag("-n,--negate", args.negate, "Negate input image."); | ||
try { | ||
app.parse(argc, argv); | ||
} catch (const CLI::ParseError &e) { | ||
return app.exit(e); | ||
} | ||
|
||
// Load SVG | ||
vor::DoubleCompressedImage dexels = vor::create_dexels(args.input.c_str()); | ||
|
||
// Pre-processing operations | ||
if (args.transpose) { | ||
dexels.transposeInPlace(); | ||
} | ||
if (args.negate) { | ||
dexels.negate(); | ||
} | ||
|
||
// Offset | ||
if (args.radius > 0) { | ||
std::cout << "-- Performing offset by radius r = " << args.radius | ||
<< std::endl; | ||
if (args.erode) { | ||
dexels.erode(args.radius); | ||
} else { | ||
dexels.dilate(args.radius); | ||
} | ||
} | ||
|
||
// Save output image | ||
if (std::ifstream(args.output)) { | ||
// Output file exists! | ||
if (args.force) { | ||
std::cout << "-- Overwriting output file: " << args.output << std::endl; | ||
vor::dexel_dump(args.output.c_str(), dexels); | ||
} else { | ||
std::cerr << "-- Output file already exists. Please use -f to force overwriting." | ||
<< std::endl; | ||
} | ||
} else { | ||
std::cout << "-- Saving" << std::endl; | ||
vor::dexel_dump(args.output.c_str(), dexels); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
################################################################################ | ||
|
||
cmake_minimum_required(VERSION 3.3) | ||
project(offset3d) | ||
|
||
################################################################################ | ||
|
||
# Add executable | ||
add_executable(${PROJECT_NAME} offset3d.cpp) | ||
|
||
# Let's get a little bit paranoid | ||
include(SetWarnings) | ||
target_compile_options(${PROJECT_NAME} PRIVATE ${ALL_WARNINGS}) | ||
|
||
# Sanitizers | ||
if(VOROFFSET_WITH_SANITIZERS) | ||
add_sanitizers(${PROJECT_NAME}) | ||
endif() | ||
|
||
# Dependencies | ||
target_link_libraries(${PROJECT_NAME} PRIVATE vor3d CLI11::CLI11 json::json) | ||
|
||
# Output directory for binaries | ||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" | ||
) |
Oops, something went wrong.