Skip to content

Commit bcf5217

Browse files
committed
Initial release.
1 parent 07015c6 commit bcf5217

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+9263
-0
lines changed

.gitattributes

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Explicitly declare text files you want to always be normalized and converted
5+
# to native line endings on checkout.
6+
*.tex text
7+
*.bib text
8+
*.svg text
9+
*.py text
10+
*.vbs text
11+
*.cpp text
12+
*.hpp text
13+
Makefile text
14+
15+
# Declare files that will always have CRLF line endings on checkout.
16+
*.sln text eol=crlf
17+
18+
# Denote all files that are truly binary and should not be modified.
19+
*.png binary
20+
*.jpg binary

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
# Extra directories
35+
.idea/
36+
.vscode/
37+
/cmake-build-*
38+
/build*
39+
/external*

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
dist: trusty
2+
sudo: false
3+
language: cpp
4+
cache: ccache
5+
matrix:
6+
include:
7+
- os: linux
8+
compiler: gcc-7
9+
addons:
10+
apt:
11+
sources:
12+
- ubuntu-toolchain-r-test
13+
packages:
14+
- gcc-7
15+
- g++-7
16+
- xorg-dev
17+
- libglu1-mesa-dev
18+
env:
19+
- MATRIX_EVAL="export CC=gcc-7 && CXX=g++-7 && CONFIG=Debug && NPROC=2"
20+
- os: osx
21+
compiler: clang
22+
env:
23+
- MATRIX_EVAL="export CONFIG=Debug && NPROC=2"
24+
25+
install:
26+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi
27+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
28+
- eval "${MATRIX_EVAL}"
29+
30+
script:
31+
- mkdir build
32+
- cd build
33+
- cmake -DCMAKE_BUILD_TYPE=$CONFIG ..
34+
- make -j ${NPROC}

CMakeLists.txt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
################################################################################
2+
# General Information
3+
################################################################################
4+
5+
cmake_minimum_required(VERSION 3.8)
6+
project(voroffset)
7+
8+
################################################################################
9+
10+
set(VOROFFSET_EXTERNAL ${CMAKE_CURRENT_SOURCE_DIR}/external/)
11+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
12+
13+
if(NOT CMAKE_BUILD_TYPE)
14+
message(STATUS "No build type selected, default to Release")
15+
set(CMAKE_BUILD_TYPE "Release")
16+
endif()
17+
18+
################################################################################
19+
20+
# Use folder in Visual Studio
21+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
22+
23+
# Color output
24+
include(UseColors)
25+
26+
# Export compile flags(used for autocompletion of the C++ code)
27+
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
28+
29+
# CMake plugin for vscode
30+
include(CMakeToolsHelpers OPTIONAL)
31+
32+
# Generate position independent code
33+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
34+
35+
# Build shared or static?
36+
# set(BUILD_SHARED_LIBRARIES OFF)
37+
38+
################################################################################
39+
40+
# CMake options
41+
option(VOROFFSET_WITH_SANITIZERS "Enable sanitizers" OFF)
42+
option(VOROFFSET_WITH_TBB "Enable TBB" ON)
43+
44+
option(SANITIZE_ADDRESS "Sanitize Address" OFF)
45+
option(SANITIZE_MEMORY "Sanitize Memory" OFF)
46+
option(SANITIZE_THREAD "Sanitize Thread" OFF)
47+
option(SANITIZE_UNDEFINED "Sanitize Undefined" OFF)
48+
49+
# Override cached options
50+
# set(SANITIZE_ADDRESS OFF CACHE BOOL "" FORCE)
51+
# set(VOROFFSET_WITH_TBB ON CACHE BOOL "" FORCE)
52+
53+
################################################################################
54+
# Dependencies
55+
################################################################################
56+
57+
# Sanitizers
58+
if(VOROFFSET_WITH_SANITIZERS)
59+
list(APPEND CMAKE_MODULE_PATH ${VOROFFSET_EXTERNAL}/sanitizers-cmake/cmake)
60+
endif()
61+
62+
include(VoroffsetDependencies)
63+
64+
################################################################################
65+
66+
# 2D version prototype
67+
add_subdirectory(src/vor2d)
68+
69+
# 3D version prototype
70+
add_subdirectory(src/vor3d)
71+
72+
# Binary executables
73+
add_subdirectory(app)

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Voroffset
2+
3+
Discrete mesh offsetting based on half-space Voronoi diagrams and Power diagrams.
4+
5+
### Compilation
6+
7+
Dependencies are downloaded automatically by CMake at configuration time. To compile the code, just type:
8+
9+
```bash
10+
mkdir build
11+
cd build
12+
cmake -j8
13+
```
14+
15+
### Running the code
16+
17+
See possible options with:
18+
19+
```bash
20+
./offset3d -h
21+
```
22+
23+
Example usage:
24+
25+
```
26+
./offset3d filigree.ply -n 512 -p 10 -r 5 -x dilation
27+
```
28+
29+
##### offset2d
30+
31+
Takes a .svg file as input, and saves the result of the dilation as a quad-mesh (.obj).
32+
33+
##### offset3d
34+
35+
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.)
36+
37+
```
38+
Offset3D
39+
Usage: ./offset3d [OPTIONS] input [output]
40+
41+
Positionals:
42+
input TEXT Input model
43+
output TEXT=output.obj Output model
44+
45+
Options:
46+
-h,--help Print this help message and exit
47+
-i,--input TEXT Input model
48+
-o,--output TEXT=output.obj Output model
49+
-j,--json TEXT Output json file
50+
-d,--dexels_size FLOAT=1 Size of a dexel (in mm)
51+
-n,--num_dexels INT=256 Number of dexels (-1 to use dexel size instead)
52+
-p,--padding INT Padding (in #dexels)
53+
-t,--num_thread UINT=6 Number of threads
54+
-r,--radius FLOAT=8 Dilation/erosion radius (in #dexels)
55+
-m,--method TEXT in {brute_force,ours}
56+
The method to use
57+
-x,--apply TEXT in {closing,dilation,erosion,noop,opening}=dilation
58+
Morphological operation to apply
59+
-f,--force Overwrite output file
60+
-u,--radius_in_mm Radius is given in mm instead
61+
```

app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(cli2d)
2+
add_subdirectory(cli3d)

app/cli2d/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
################################################################################
2+
3+
cmake_minimum_required(VERSION 3.3)
4+
project(offset2d)
5+
6+
################################################################################
7+
8+
# Add executable
9+
add_executable(${PROJECT_NAME} offset2d.cpp)
10+
11+
# Let's get a little bit paranoid
12+
include(SetWarnings)
13+
target_compile_options(${PROJECT_NAME} PRIVATE ${ALL_WARNINGS})
14+
15+
# Sanitizers
16+
if(VOROFFSET_WITH_SANITIZERS)
17+
add_sanitizers(${PROJECT_NAME})
18+
endif()
19+
20+
# Dependencies
21+
target_link_libraries(${PROJECT_NAME} PRIVATE vor2d yimg::yimg CLI11::CLI11)
22+
23+
# Output directory for binaries
24+
set_target_properties(${PROJECT_NAME}
25+
PROPERTIES
26+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
27+
)

app/cli2d/offset2d.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
#include <CLI/CLI.hpp>
3+
#include <YImage.hpp>
4+
#include <vector>
5+
#include <vor2d/CompressedImage.h>
6+
#include <vor2d/Dexelize.h>
7+
#include <vor2d/DoubleCompressedImage.h>
8+
////////////////////////////////////////////////////////////////////////////////
9+
10+
#define WHITE YImage::YPixel({255, 255, 255, 255})
11+
#define BLACK YImage::YPixel({0, 0, 0, 255})
12+
13+
bool pixel_is_white(YImage::YPixel p) {
14+
return p.r > 128 || p.g > 128 || p.b > 128 || p.a > 128;
15+
}
16+
17+
int main(int argc, char *argv[]) {
18+
// Default arguments
19+
struct {
20+
std::string input;
21+
std::string output = "out.png";
22+
double radius = 0;
23+
bool erode = false;
24+
bool force = false;
25+
bool transpose = false;
26+
bool negate = false;
27+
} args;
28+
29+
// Parse arguments
30+
CLI::App app("Offset2D");
31+
app.add_option("input,-i,--input", args.input, "Input image.")
32+
->required()
33+
->check(CLI::ExistingFile);
34+
app.add_option("output,-o,--output", args.output, "Output image.");
35+
app.add_option("-r,--radius", args.radius, "Dilation/erosion radius.");
36+
app.add_flag("-e,--erode", args.erode, "Erode instead of dilate.");
37+
app.add_flag("-f,--force", args.force, "Overwrite output file.");
38+
app.add_flag("-t,--transpose", args.transpose, "Transpose input image.");
39+
app.add_flag("-n,--negate", args.negate, "Negate input image.");
40+
try {
41+
app.parse(argc, argv);
42+
} catch (const CLI::ParseError &e) {
43+
return app.exit(e);
44+
}
45+
46+
// Load SVG
47+
vor::DoubleCompressedImage dexels = vor::create_dexels(args.input.c_str());
48+
49+
// Pre-processing operations
50+
if (args.transpose) {
51+
dexels.transposeInPlace();
52+
}
53+
if (args.negate) {
54+
dexels.negate();
55+
}
56+
57+
// Offset
58+
if (args.radius > 0) {
59+
std::cout << "-- Performing offset by radius r = " << args.radius
60+
<< std::endl;
61+
if (args.erode) {
62+
dexels.erode(args.radius);
63+
} else {
64+
dexels.dilate(args.radius);
65+
}
66+
}
67+
68+
// Save output image
69+
if (std::ifstream(args.output)) {
70+
// Output file exists!
71+
if (args.force) {
72+
std::cout << "-- Overwriting output file: " << args.output << std::endl;
73+
vor::dexel_dump(args.output.c_str(), dexels);
74+
} else {
75+
std::cerr << "-- Output file already exists. Please use -f to force overwriting."
76+
<< std::endl;
77+
}
78+
} else {
79+
std::cout << "-- Saving" << std::endl;
80+
vor::dexel_dump(args.output.c_str(), dexels);
81+
}
82+
return 0;
83+
}

app/cli3d/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
################################################################################
2+
3+
cmake_minimum_required(VERSION 3.3)
4+
project(offset3d)
5+
6+
################################################################################
7+
8+
# Add executable
9+
add_executable(${PROJECT_NAME} offset3d.cpp)
10+
11+
# Let's get a little bit paranoid
12+
include(SetWarnings)
13+
target_compile_options(${PROJECT_NAME} PRIVATE ${ALL_WARNINGS})
14+
15+
# Sanitizers
16+
if(VOROFFSET_WITH_SANITIZERS)
17+
add_sanitizers(${PROJECT_NAME})
18+
endif()
19+
20+
# Dependencies
21+
target_link_libraries(${PROJECT_NAME} PRIVATE vor3d CLI11::CLI11 json::json)
22+
23+
# Output directory for binaries
24+
set_target_properties(${PROJECT_NAME}
25+
PROPERTIES
26+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
27+
)

0 commit comments

Comments
 (0)