Skip to content

Commit

Permalink
Add a cmake option for CrossSection (#888)
Browse files Browse the repository at this point in the history
* Add a cmake option for CrossSection

* Add MANIFOLD_CROSS_SECTION to manifoldConfig.cmake

* Document MANIFOLD_CROSS_SECTION in README

* Fix default MANIFOLD_JSBIND value

* Enable tests that run without CrossSection

* Remove cross_section.h from tests that don't use it

* Add ifdef to tests using CrossSection

* CI: Build without CrossSection

* CI: Separate Python bindings test
  • Loading branch information
cjmayo authored Aug 13, 2024
1 parent 8443343 commit e26e01a
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 45 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ on:

jobs:
build:
name: CrossSection:${{matrix.cross_section}} ${{matrix.parallel_backend == 'TBB' && 'TBB' || ''}} GCC ${{matrix.gcc}}
timeout-minutes: 45
strategy:
matrix:
cross_section: [ON]
parallel_backend: [NONE, TBB]
gcc: [13, 14]
include:
- cross_section: OFF
parallel_backend: TBB
gcc: 14
runs-on: ubuntu-24.04
env:
CC: gcc-${{ matrix.gcc }}
Expand All @@ -40,14 +46,16 @@ jobs:
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_PYBIND=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_EXPORT=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} .. && make
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_PYBIND=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_CROSS_SECTION=${{matrix.cross_section}} -DMANIFOLD_EXPORT=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} .. && make
- name: Test ${{matrix.parallel_backend}}
if: matrix.parallel_backend != 'NONE'
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)/build/bindings/python
cd build/test
./manifold_test
cd ../../
- name: Test Python bindings ${{matrix.parallel_backend}}
if: matrix.parallel_backend != 'NONE' && matrix.cross_section == 'ON'
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)/build/bindings/python
python3 bindings/python/examples/run_all.py -e
python3 -m pytest
- name: Coverage Report
Expand Down
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ project(manifold LANGUAGES CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)

if(EMSCRIPTEN)
set(JSBIND_DEFAULT ON)
else()
set(JSBIND_DEFAULT OFF)
endif()

set(MANIFOLD_PAR "NONE" CACHE STRING "Parallel backend, either \"TBB\" or \"NONE\"")
set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags")
option(MANIFOLD_CROSS_SECTION "Build CrossSection for 2D support" ON)
option(MANIFOLD_EXPORT "Build mesh export (via assimp) utility library" OFF)
option(MANIFOLD_TEST "Enable testing suite" ON)
# fuzztest is a rather large dependency
option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF)
option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF)
option(MANIFOLD_PYBIND "Build python bindings" OFF)
option(MANIFOLD_CBIND "Build C (FFI) bindings" ON)
option(MANIFOLD_JSBIND "Build js binding" ${EMSCRIPTEN})
option(MANIFOLD_EXCEPTIONS "Build manifold with exception enabled" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON)
include(CMakeDependentOption)
cmake_dependent_option(MANIFOLD_CBIND "Build C (FFI) bindings" ON "MANIFOLD_CROSS_SECTION" OFF)
cmake_dependent_option(MANIFOLD_JSBIND "Build js binding" ${JSBIND_DEFAULT} "MANIFOLD_CROSS_SECTION" OFF)
cmake_dependent_option(MANIFOLD_PYBIND "Build python bindings" OFF "MANIFOLD_CROSS_SECTION" OFF)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(MANIFOLD_FUZZ)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ CMake flags (usage e.g. `-DMANIFOLD_DEBUG=ON`):
- `MANIFOLD_CBIND=[<OFF>, ON]`: Build C FFI binding.
- `MANIFOLD_PYBIND=[OFF, <ON>]`: Build python binding.
- `MANIFOLD_PAR=[<NONE>, TBB]`: Provides multi-thread parallelization, requires `libtbb-dev` if `TBB` backend is selected.
- `MANIFOLD_CROSS_SECTION=[OFF, <ON>]`: Build CrossSection for 2D support (needed by language bindings).
- `MANIFOLD_EXPORT=[<OFF>, ON]`: Enables GLB export of 3D models from the tests, requires `libassimp-dev`.
- `MANIFOLD_DEBUG=[<OFF>, ON]`: Enables internal assertions and exceptions.
- `MANIFOLD_TEST=[OFF, <ON>]`: Build unittests.
Expand Down
1 change: 1 addition & 0 deletions manifoldConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(MANIFOLD_PAR "@MANIFOLD_PAR@")
set(MANIFOLD_CROSS_SECTION "@MANIFOLD_CROSS_SECTION@")
set(MANIFOLD_EXPORT "@MANIFOLD_EXPORT@")
include("${CMAKE_CURRENT_LIST_DIR}/manifoldDeps.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/manifoldTargets.cmake")
62 changes: 32 additions & 30 deletions manifoldDeps.cmake
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
include(FetchContent)
include(GNUInstallDirs)
find_package(PkgConfig QUIET)
find_package(Clipper2 QUIET)

if(MANIFOLD_PAR STREQUAL "TBB")
find_package(TBB QUIET)
if(APPLE)
find_package(oneDPL QUIET)
endif()
endif()
if (PKG_CONFIG_FOUND)
if (NOT Clipper2_FOUND)
pkg_check_modules(Clipper2 Clipper2)
endif()
if(MANIFOLD_PAR STREQUAL "TBB" AND NOT TBB_FOUND)
if(NOT TBB_FOUND AND PKG_CONFIG_FOUND)
pkg_check_modules(TBB tbb)
endif()
endif()
if(Clipper2_FOUND)
add_library(Clipper2 SHARED IMPORTED)
set_property(TARGET Clipper2 PROPERTY
IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES})
if(WIN32)
set_property(TARGET Clipper2 PROPERTY
IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES})

if(MANIFOLD_CROSS_SECTION)
find_package(Clipper2 QUIET)
if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND)
pkg_check_modules(Clipper2 Clipper2)
endif()
target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS})
else()
message(STATUS "clipper2 not found, downloading from source")
set(CLIPPER2_UTILS OFF)
set(CLIPPER2_EXAMPLES OFF)
set(CLIPPER2_TESTS OFF)
set(CLIPPER2_USINGZ "OFF" CACHE STRING "Preempt cache default of USINGZ (we only use 2d)")
FetchContent_Declare(Clipper2
GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git
GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba
GIT_PROGRESS TRUE
SOURCE_SUBDIR CPP
)
FetchContent_MakeAvailable(Clipper2)
if(NOT EMSCRIPTEN)
install(TARGETS Clipper2)
if(Clipper2_FOUND)
add_library(Clipper2 SHARED IMPORTED)
set_property(TARGET Clipper2 PROPERTY
IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES})
if(WIN32)
set_property(TARGET Clipper2 PROPERTY
IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES})
endif()
target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS})
else()
message(STATUS "clipper2 not found, downloading from source")
set(CLIPPER2_UTILS OFF)
set(CLIPPER2_EXAMPLES OFF)
set(CLIPPER2_TESTS OFF)
set(CLIPPER2_USINGZ "OFF" CACHE STRING "Preempt cache default of USINGZ (we only use 2d)")
FetchContent_Declare(Clipper2
GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git
GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba
GIT_PROGRESS TRUE
SOURCE_SUBDIR CPP
)
FetchContent_MakeAvailable(Clipper2)
if(NOT EMSCRIPTEN)
install(TARGETS Clipper2)
endif()
endif()
endif()

Expand Down
12 changes: 8 additions & 4 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@

project(samples)

add_library(samples src/bracelet.cpp src/knot.cpp src/menger_sponge.cpp
add_library(samples src/menger_sponge.cpp
src/rounded_frame.cpp src/scallop.cpp src/tet_puzzle.cpp
src/gyroid_module.cpp src/condensed_matter.cpp)
if(MANIFOLD_CROSS_SECTION)
target_sources(samples PUBLIC src/bracelet.cpp src/knot.cpp)
endif()

target_include_directories(samples
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

target_link_libraries(samples
PUBLIC manifold cross_section
)
target_link_libraries(samples PUBLIC manifold)
if(MANIFOLD_CROSS_SECTION)
target_link_libraries(${PROJECT_NAME} PUBLIC cross_section)
endif()

target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(samples PUBLIC cxx_std_17)
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

add_subdirectory(utilities)
add_subdirectory(collider)
add_subdirectory(cross_section)
if(MANIFOLD_CROSS_SECTION)
add_subdirectory(cross_section)
endif()
add_subdirectory(polygon)
add_subdirectory(manifold)
12 changes: 10 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ project(manifold_test)
set(CMAKE_CXX_STANDARD 17)
enable_testing()

set(SOURCE_FILES test_main.cpp polygon_test.cpp cross_section_test.cpp properties_test.cpp manifold_test.cpp hull_test.cpp smooth_test.cpp sdf_test.cpp boolean_test.cpp boolean_complex_test.cpp samples_test.cpp)
set(SOURCE_FILES test_main.cpp polygon_test.cpp properties_test.cpp manifold_test.cpp hull_test.cpp smooth_test.cpp sdf_test.cpp boolean_test.cpp boolean_complex_test.cpp samples_test.cpp)

if(MANIFOLD_CROSS_SECTION)
list(APPEND SOURCE_FILES cross_section_test.cpp)
endif()

if(MANIFOLD_CBIND AND NOT EMSCRIPTEN)
list(APPEND SOURCE_FILES manifoldc_test.cpp)
Expand All @@ -43,7 +47,7 @@ if(NOT TARGET GTest::gtest_main)
endif()

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} polygon GTest::gtest_main manifold samples cross_section)
target_link_libraries(${PROJECT_NAME} polygon GTest::gtest_main manifold samples)

if(MANIFOLD_FUZZ)
FetchContent_Declare(fuzztest
Expand All @@ -64,6 +68,10 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN)
target_link_libraries(${PROJECT_NAME} manifoldc)
endif()

if(MANIFOLD_CROSS_SECTION)
target_link_libraries(${PROJECT_NAME} cross_section)
endif()

if(MANIFOLD_EXPORT)
target_link_libraries(${PROJECT_NAME} meshIO)
target_compile_options(${PROJECT_NAME} PUBLIC -DMANIFOLD_EXPORT)
Expand Down
4 changes: 4 additions & 0 deletions test/boolean_complex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef MANIFOLD_CROSS_SECTION
#include "cross_section.h"
#endif
#include "manifold.h"
#include "polygon.h"
#include "test.h"
Expand Down Expand Up @@ -261,6 +263,7 @@ TEST(BooleanComplex, Spiral) {
EXPECT_EQ(result.Genus(), -120);
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(BooleanComplex, Sweep) {
PolygonParams().processOverlaps = true;

Expand Down Expand Up @@ -504,6 +507,7 @@ TEST(BooleanComplex, Sweep) {

PolygonParams().processOverlaps = false;
}
#endif

TEST(BooleanComplex, InterpolatedNormals) {
MeshGL a;
Expand Down
1 change: 0 additions & 1 deletion test/hull_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <algorithm>

#include "cross_section.h"
#include "manifold.h"
#include "samples.h"
#include "test.h"
Expand Down
12 changes: 12 additions & 0 deletions test/manifold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include <algorithm>

#ifdef MANIFOLD_CROSS_SECTION
#include "cross_section.h"
#endif
#include "samples.h"
#include "test.h"
#include "tri_dist.h"
Expand Down Expand Up @@ -259,13 +261,15 @@ TEST(Manifold, Revolve2) {
EXPECT_NEAR(prop.surfaceArea, 96.0f * glm::pi<float>(), 1.0f);
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Manifold, Revolve3) {
CrossSection circle = CrossSection::Circle(1, 32);
Manifold sphere = Manifold::Revolve(circle.ToPolygons(), 32);
auto prop = sphere.GetProperties();
EXPECT_NEAR(prop.volume, 4.0f / 3.0f * glm::pi<float>(), 0.1);
EXPECT_NEAR(prop.surfaceArea, 4 * glm::pi<float>(), 0.15);
}
#endif

TEST(Manifold, PartialRevolveOnYAxis) {
Polygons polys = SquareHole(2.0f);
Expand Down Expand Up @@ -299,6 +303,7 @@ TEST(Manifold, PartialRevolveOffset) {
}
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Manifold, Warp) {
CrossSection square = CrossSection::Square({1, 1});
Manifold shape =
Expand Down Expand Up @@ -339,6 +344,7 @@ TEST(Manifold, Warp2) {
EXPECT_NEAR(propBefore.surfaceArea, propAfter.surfaceArea, 0.0001);
EXPECT_NEAR(propBefore.volume, 321, 1);
}
#endif

TEST(Manifold, WarpBatch) {
Manifold shape1 =
Expand All @@ -357,6 +363,7 @@ TEST(Manifold, WarpBatch) {
EXPECT_EQ(prop1.surfaceArea, prop2.surfaceArea);
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Manifold, Project) {
Mesh input;
input.vertPos = {{0, 0, 0},
Expand Down Expand Up @@ -403,6 +410,7 @@ TEST(Manifold, Project) {
CrossSection projected = in.Project();
EXPECT_NEAR(projected.Area(), 0.72, 0.01);
}
#endif

/**
* Testing more advanced Manifold operations.
Expand Down Expand Up @@ -433,13 +441,15 @@ TEST(Manifold, Transform) {
Identical(cube.GetMesh(), cube2.GetMesh());
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Manifold, Slice) {
Manifold cube = Manifold::Cube();
CrossSection bottom = cube.Slice();
CrossSection top = cube.Slice(1);
EXPECT_EQ(bottom.Area(), 1);
EXPECT_EQ(top.Area(), 0);
}
#endif

TEST(Manifold, MeshRelation) {
MeshGL gyroidMeshGL = WithIndexColors(Gyroid());
Expand Down Expand Up @@ -591,6 +601,7 @@ TEST(Manifold, MirrorUnion2) {
EXPECT_TRUE(result.MatchesTriNormals());
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Manifold, Invalid) {
auto invalid = Manifold::Error::InvalidConstruction;
auto circ = CrossSection::Circle(10.);
Expand All @@ -606,6 +617,7 @@ TEST(Manifold, Invalid) {
EXPECT_EQ(Manifold::Extrude(empty_circ.ToPolygons(), 10.).Status(), invalid);
EXPECT_EQ(Manifold::Revolve(empty_sq.ToPolygons()).Status(), invalid);
}
#endif

TEST(Manifold, MultiCompose) {
auto part = Manifold::Compose({Manifold::Cube({10, 10, 10})});
Expand Down
3 changes: 2 additions & 1 deletion test/properties_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <algorithm>

#include "cross_section.h"
#include "manifold.h"
#include "samples.h"
#include "test.h"
Expand Down Expand Up @@ -177,6 +176,7 @@ TEST(Properties, MingapAfterTransformations) {
ASSERT_NEAR(distance, 1, 0.001f);
}

#ifdef MANIFOLD_CROSS_SECTION
TEST(Properties, MingapStretchyBracelet) {
auto a = StretchyBracelet();
auto b = StretchyBracelet().Translate({0, 0, 20});
Expand All @@ -185,6 +185,7 @@ TEST(Properties, MingapStretchyBracelet) {

ASSERT_NEAR(distance, 5, 0.001f);
}
#endif

TEST(Properties, MinGapAfterTransformationsOutOfBounds) {
auto a = Manifold::Sphere(1, 512).Rotate(30, 30, 30);
Expand Down
Loading

0 comments on commit e26e01a

Please sign in to comment.