Merge commit '5e3e5492487690fb48cd7c4bb0b7e0e019e30a5c' (wip)

This commit is contained in:
supermerill 2019-12-05 20:53:02 +01:00
commit dda438c74b
376 changed files with 122718 additions and 12461 deletions

View File

@ -1,5 +1,5 @@
project(Slic3r)
cmake_minimum_required(VERSION 3.2)
project(Slic3r)
include("version.inc")
include(GNUInstallDirs)
@ -37,7 +37,7 @@ set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux")
# Proposal for C++ unit tests and sandboxes
option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF)
option(SLIC3R_BUILD_TESTS "Build unit tests" OFF)
option(SLIC3R_BUILD_TESTS "Build unit tests" ON)
# Print out the SLIC3R_* cache options
get_cmake_property(_cache_vars CACHE_VARIABLES)
@ -173,10 +173,11 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP
# On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error.
add_compile_options(-Werror=return-type)
#removes LOTS of extraneous Eigen warnings (GCC only supports it since 6.1)
#if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.1)
# add_compile_options(-Wno-ignored-attributes) # Tamas: Eigen include dirs are marked as SYSTEM
#endif()
# removes LOTS of extraneous Eigen warnings (GCC only supports it since 6.1)
# https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1221
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
add_compile_options(-Wno-ignored-attributes) # Tamas: Eigen include dirs are marked as SYSTEM
endif()
#GCC generates loads of -Wunknown-pragmas when compiling igl. The fix is not easy due to a bug in gcc, see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or
@ -190,6 +191,7 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
@ -254,7 +256,8 @@ if(NOT WIN32)
# boost::process was introduced first in version 1.64.0
set(MINIMUM_BOOST_VERSION "1.64.0")
endif()
find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS system filesystem thread log locale regex)
set(_boost_components "system;filesystem;thread;log;locale;regex;chrono;atomic;date_time")
find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS ${_boost_components})
# boost compile only in release & debug. We have to force the release version for RELWITHDEBINFO compilation
if (MSVC)
set_target_properties(${Boost_LIBRARIES} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
@ -272,37 +275,55 @@ if(NOT SLIC3R_STATIC)
target_compile_definitions(boost_headeronly INTERFACE BOOST_LOG_DYN_LINK)
endif()
function(slic3r_remap_configs targets from_Cfg to_Cfg)
if(MSVC)
string(TOUPPER ${from_Cfg} from_CFG)
foreach(tgt ${targets})
if(TARGET ${tgt})
set_target_properties(${tgt} PROPERTIES MAP_IMPORTED_CONFIG_${from_CFG} ${to_Cfg})
endif()
endforeach()
endif()
endfunction()
if(TARGET Boost::system)
message(STATUS "Boost::boost exists")
target_link_libraries(boost_headeronly INTERFACE Boost::boost)
# Only from cmake 3.12
# list(TRANSFORM _boost_components PREPEND Boost:: OUTPUT_VARIABLE _boost_targets)
set(_boost_targets "")
foreach(comp ${_boost_components})
list(APPEND _boost_targets "Boost::${comp}")
endforeach()
target_link_libraries(boost_libs INTERFACE
boost_headeronly # includes the custom compile definitions as well
Boost::system
Boost::filesystem
Boost::thread
Boost::log
Boost::locale
Boost::regex
${_boost_targets}
)
slic3r_remap_configs("${_boost_targets}" RelWithDebInfo Release)
else()
target_include_directories(boost_headeronly INTERFACE ${Boost_INCLUDE_DIRS})
target_link_libraries(boost_libs INTERFACE boost_headeronly ${Boost_LIBRARIES})
endif()
# Find and configure intel-tbb
if(SLIC3R_STATIC)
set(TBB_STATIC 1)
endif()
set(TBB_DEBUG 1)
find_package(TBB REQUIRED)
include_directories(${TBB_INCLUDE_DIRS})
add_definitions(${TBB_DEFINITIONS})
if(MSVC)
# Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
endif()
# include_directories(${TBB_INCLUDE_DIRS})
# add_definitions(${TBB_DEFINITIONS})
# if(MSVC)
# # Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
# add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
# endif()
# The Intel TBB library will use the std::exception_ptr feature of C++11.
add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
# add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
@ -379,6 +400,16 @@ add_custom_target(pot
COMMENT "Generate pot file from strings in the source tree"
)
find_package(NLopt 1.4 REQUIRED)
if(SLIC3R_STATIC)
set(OPENVDB_USE_STATIC_LIBS ON)
set(USE_BLOSC TRUE)
endif()
#find_package(OpenVDB 5.0 COMPONENTS openvdb)
#slic3r_remap_configs(IlmBase::Half RelWithDebInfo Release)
# libslic3r, Slic3r GUI and the slic3r executable.
add_subdirectory(src)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT slic3r_app_console)

View File

@ -0,0 +1,175 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
Catch
-----
This module defines a function to help use the Catch test framework.
The :command:`catch_discover_tests` discovers tests by asking the compiled test
executable to enumerate its tests. This does not require CMake to be re-run
when tests change. However, it may not work in a cross-compiling environment,
and setting test properties is less convenient.
This command is intended to replace use of :command:`add_test` to register
tests, and will create a separate CTest test for each Catch test case. Note
that this is in some cases less efficient, as common set-up and tear-down logic
cannot be shared by multiple test cases executing in the same instance.
However, it provides more fine-grained pass/fail information to CTest, which is
usually considered as more beneficial. By default, the CTest test name is the
same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
.. command:: catch_discover_tests
Automatically add tests with CTest by querying the compiled test executable
for available tests::
catch_discover_tests(target
[TEST_SPEC arg1...]
[EXTRA_ARGS arg1...]
[WORKING_DIRECTORY dir]
[TEST_PREFIX prefix]
[TEST_SUFFIX suffix]
[PROPERTIES name1 value1...]
[TEST_LIST var]
)
``catch_discover_tests`` sets up a post-build command on the test executable
that generates the list of tests by parsing the output from running the test
with the ``--list-test-names-only`` argument. This ensures that the full
list of tests is obtained. Since test discovery occurs at build time, it is
not necessary to re-run CMake when the list of tests changes.
However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
in order to function in a cross-compiling environment.
Additionally, setting properties on tests is somewhat less convenient, since
the tests are not available at CMake time. Additional test properties may be
assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
more fine-grained test control is needed, custom content may be provided
through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
directory property. The set of discovered tests is made accessible to such a
script via the ``<target>_TESTS`` variable.
The options are:
``target``
Specifies the Catch executable, which must be a known CMake executable
target. CMake will substitute the location of the built executable when
running the test.
``TEST_SPEC arg1...``
Specifies test cases, wildcarded test cases, tags and tag expressions to
pass to the Catch executable with the ``--list-test-names-only`` argument.
``EXTRA_ARGS arg1...``
Any extra arguments to pass on the command line to each test case.
``WORKING_DIRECTORY dir``
Specifies the directory in which to run the discovered test cases. If this
option is not provided, the current binary directory is used.
``TEST_PREFIX prefix``
Specifies a ``prefix`` to be prepended to the name of each discovered test
case. This can be useful when the same test executable is being used in
multiple calls to ``catch_discover_tests()`` but with different
``TEST_SPEC`` or ``EXTRA_ARGS``.
``TEST_SUFFIX suffix``
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
be specified.
``PROPERTIES name1 value1...``
Specifies additional properties to be set on all tests discovered by this
invocation of ``catch_discover_tests``.
``TEST_LIST var``
Make the list of tests available in the variable ``var``, rather than the
default ``<target>_TESTS``. This can be useful when the same test
executable is being used in multiple calls to ``catch_discover_tests()``.
Note that this variable is only available in CTest.
#]=======================================================================]
#------------------------------------------------------------------------------
function(catch_discover_tests TARGET)
cmake_parse_arguments(
""
""
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
${ARGN}
)
if(NOT _WORKING_DIRECTORY)
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(NOT _TEST_LIST)
set(_TEST_LIST ${TARGET}_TESTS)
endif()
## Generate a unique name based on the extra arguments
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}")
string(SUBSTRING ${args_hash} 0 7 args_hash)
# Define rule to generate test list for aforementioned test executable
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
get_property(crosscompiling_emulator
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR
)
add_custom_command(
TARGET ${TARGET} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${TARGET}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
-D "TEST_SPEC=${_TEST_SPEC}"
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
-D "TEST_PROPERTIES=${_PROPERTIES}"
-D "TEST_PREFIX='${_TEST_PREFIX}'"
-D "TEST_SUFFIX='${_TEST_SUFFIX}'"
-D "TEST_LIST=${_TEST_LIST}"
-D "CTEST_FILE=${ctest_tests_file}"
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
VERBATIM
)
file(WRITE "${ctest_include_file}"
"if(EXISTS \"${ctest_tests_file}\")\n"
" include(\"${ctest_tests_file}\")\n"
"else()\n"
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
"endif()\n"
)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
# Add discovered tests to directory TEST_INCLUDE_FILES
set_property(DIRECTORY
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
)
else()
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
if (NOT ${test_include_file_set})
set_property(DIRECTORY
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
)
else()
message(FATAL_ERROR
"Cannot set more than one TEST_INCLUDE_FILE"
)
endif()
endif()
endfunction()
###############################################################################
set(_CATCH_DISCOVER_TESTS_SCRIPT
${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake
)

View File

@ -0,0 +1,106 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
set(prefix "${TEST_PREFIX}")
set(suffix "${TEST_SUFFIX}")
set(spec ${TEST_SPEC})
set(extra_args ${TEST_EXTRA_ARGS})
set(properties ${TEST_PROPERTIES})
set(script)
set(suite)
set(tests)
function(add_command NAME)
set(_args "")
foreach(_arg ${ARGN})
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
else()
set(_args "${_args} ${_arg}")
endif()
endforeach()
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction()
macro(_add_catch_test_labels LINE)
# convert to list of tags
string(REPLACE "][" "]\\;[" tags ${line})
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
LABELS "${tags}"
)
endmacro()
macro(_add_catch_test LINE)
set(test ${line})
# use escape commas to handle properly test cases with commans inside the name
string(REPLACE "," "\\," test_name ${test})
# ...and add to script
add_command(
add_test "${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"${test_name}"
${extra_args}
)
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endmacro()
# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
)
endif()
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests
OUTPUT_VARIABLE output
RESULT_VARIABLE result
)
# Catch --list-test-names-only reports the number of tests, so 0 is... surprising
if(${result} EQUAL 0)
message(WARNING
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
)
elseif(${result} LESS 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${result}\n"
" Output: ${output}\n"
)
endif()
string(REPLACE "\n" ";" output "${output}")
set(test)
set(tags_regex "(\\[([^\\[]*)\\])+$")
# Parse output
foreach(line ${output})
# lines without leading whitespaces are catch output not tests
if(${line} MATCHES "^[ \t]+")
# strip leading spaces and tabs
string(REGEX REPLACE "^[ \t]+" "" line ${line})
if(${line} MATCHES "${tags_regex}")
_add_catch_test_labels(${line})
else()
_add_catch_test(${line})
endif()
endif()
endforeach()
# Create a list of all discovered tests, which users may use to e.g. set
# properties on the tests
add_command(set ${TEST_LIST} ${tests})
# Write CTest script
file(WRITE "${CTEST_FILE}" "${script}")

View File

@ -0,0 +1,225 @@
#==================================================================================================#
# supported macros #
# - TEST_CASE, #
# - SCENARIO, #
# - TEST_CASE_METHOD, #
# - CATCH_TEST_CASE, #
# - CATCH_SCENARIO, #
# - CATCH_TEST_CASE_METHOD. #
# #
# Usage #
# 1. make sure this module is in the path or add this otherwise: #
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake.modules/") #
# 2. make sure that you've enabled testing option for the project by the call: #
# enable_testing() #
# 3. add the lines to the script for testing target (sample CMakeLists.txt): #
# project(testing_target) #
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake.modules/") #
# enable_testing() #
# #
# find_path(CATCH_INCLUDE_DIR "catch.hpp") #
# include_directories(${INCLUDE_DIRECTORIES} ${CATCH_INCLUDE_DIR}) #
# #
# file(GLOB SOURCE_FILES "*.cpp") #
# add_executable(${PROJECT_NAME} ${SOURCE_FILES}) #
# #
# include(ParseAndAddCatchTests) #
# ParseAndAddCatchTests(${PROJECT_NAME}) #
# #
# The following variables affect the behavior of the script: #
# #
# PARSE_CATCH_TESTS_VERBOSE (Default OFF) #
# -- enables debug messages #
# PARSE_CATCH_TESTS_NO_HIDDEN_TESTS (Default OFF) #
# -- excludes tests marked with [!hide], [.] or [.foo] tags #
# PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME (Default ON) #
# -- adds fixture class name to the test name #
# PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME (Default ON) #
# -- adds cmake target name to the test name #
# PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS (Default OFF) #
# -- causes CMake to rerun when file with tests changes so that new tests will be discovered #
# #
# One can also set (locally) the optional variable OptionalCatchTestLauncher to precise the way #
# a test should be run. For instance to use test MPI, one can write #
# set(OptionalCatchTestLauncher ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${NUMPROC}) #
# just before calling this ParseAndAddCatchTests function #
# #
# The AdditionalCatchParameters optional variable can be used to pass extra argument to the test #
# command. For example, to include successful tests in the output, one can write #
# set(AdditionalCatchParameters --success) #
# #
# After the script, the ParseAndAddCatchTests_TESTS property for the target, and for each source #
# file in the target is set, and contains the list of the tests extracted from that target, or #
# from that file. This is useful, for example to add further labels or properties to the tests. #
# #
#==================================================================================================#
if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer")
endif()
option(PARSE_CATCH_TESTS_VERBOSE "Print Catch to CTest parser debug messages" OFF)
option(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS "Exclude tests with [!hide], [.] or [.foo] tags" OFF)
option(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME "Add fixture class name to the test name" ON)
option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test name" ON)
option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF)
function(ParseAndAddCatchTests_PrintDebugMessage)
if(PARSE_CATCH_TESTS_VERBOSE)
message(STATUS "ParseAndAddCatchTests: ${ARGV}")
endif()
endfunction()
# This removes the contents between
# - block comments (i.e. /* ... */)
# - full line comments (i.e. // ... )
# contents have been read into '${CppCode}'.
# !keep partial line comments
function(ParseAndAddCatchTests_RemoveComments CppCode)
string(ASCII 2 CMakeBeginBlockComment)
string(ASCII 3 CMakeEndBlockComment)
string(REGEX REPLACE "/\\*" "${CMakeBeginBlockComment}" ${CppCode} "${${CppCode}}")
string(REGEX REPLACE "\\*/" "${CMakeEndBlockComment}" ${CppCode} "${${CppCode}}")
string(REGEX REPLACE "${CMakeBeginBlockComment}[^${CMakeEndBlockComment}]*${CMakeEndBlockComment}" "" ${CppCode} "${${CppCode}}")
string(REGEX REPLACE "\n[ \t]*//+[^\n]+" "\n" ${CppCode} "${${CppCode}}")
set(${CppCode} "${${CppCode}}" PARENT_SCOPE)
endfunction()
# Worker function
function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
# If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
return()
endif()
# According to CMake docs EXISTS behavior is well-defined only for full paths.
get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
if(NOT EXISTS ${SourceFile})
message(WARNING "Cannot find source file: ${SourceFile}")
return()
endif()
ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
# Remove block and fullline comments
ParseAndAddCatchTests_RemoveComments(Contents)
# Find definition of test names
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^\)]+\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
)
endif()
foreach(TestName ${Tests})
# Strip newlines
string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
# Get test type and fixture if applicable
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
# Get string parts of test definition
string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
# Strip wrapping quotation marks
string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
# Validate that a test name and tags have been provided
list(LENGTH TestStrings TestStringsLength)
if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
endif()
# Assign name and tags
list(GET TestStrings 0 Name)
if("${TestType}" STREQUAL "SCENARIO")
set(Name "Scenario: ${Name}")
endif()
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND TestFixture)
set(CTestName "${TestFixture}:${Name}")
else()
set(CTestName "${Name}")
endif()
if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
set(CTestName "${TestTarget}:${CTestName}")
endif()
# add target to labels to enable running all tests added from this target
set(Labels ${TestTarget})
if(TestStringsLength EQUAL 2)
list(GET TestStrings 1 Tags)
string(TOLOWER "${Tags}" Tags)
# remove target from labels if the test is hidden
if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
list(REMOVE_ITEM Labels ${TestTarget})
endif()
string(REPLACE "]" ";" Tags "${Tags}")
string(REPLACE "[" "" Tags "${Tags}")
else()
# unset tags variable from previous loop
unset(Tags)
endif()
list(APPEND Labels ${Tags})
set(HiddenTagFound OFF)
foreach(label ${Labels})
string(REGEX MATCH "^!hide|^\\." result ${label})
if(result)
set(HiddenTagFound ON)
break()
endif(result)
endforeach(label)
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
else()
ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
if(Labels)
ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
endif()
# Escape commas in the test spec
string(REPLACE "," "\\," Name ${Name})
# Add the test and set its properties
add_test(NAME "\"${CTestName}\"" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
# Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
set_tests_properties("\"${CTestName}\"" PROPERTIES DISABLED ON)
else()
set_tests_properties("\"${CTestName}\"" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
LABELS "${Labels}")
endif()
set_property(
TARGET ${TestTarget}
APPEND
PROPERTY ParseAndAddCatchTests_TESTS "\"${CTestName}\"")
set_property(
SOURCE ${SourceFile}
APPEND
PROPERTY ParseAndAddCatchTests_TESTS "\"${CTestName}\"")
endif()
endforeach()
endfunction()
# entry point
function(ParseAndAddCatchTests TestTarget)
ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
get_target_property(SourceFiles ${TestTarget} SOURCES)
ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
foreach(SourceFile ${SourceFiles})
ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
endforeach()
ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
endfunction()

View File

@ -21,8 +21,7 @@
set(NLopt_FOUND FALSE)
set(NLopt_ERROR_REASON "")
set(NLopt_DEFINITIONS "")
set(NLopt_LIBS)
unset(NLopt_LIBS CACHE)
set(NLopt_DIR $ENV{NLOPT})
if(NOT NLopt_DIR)
@ -48,7 +47,6 @@ if(NOT NLopt_DIR)
set(NLopt_ERROR_REASON "${NLopt_ERROR_REASON} Cannot find NLopt header file '${_NLopt_HEADER_FILE_NAME}'.")
endif()
unset(_NLopt_HEADER_FILE_NAME)
unset(_NLopt_HEADER_FILE)
if(NOT NLopt_FOUND)
set(NLopt_ERROR_REASON "${NLopt_ERROR_REASON} NLopt not found in system directories (and environment variable NLOPT is not set).")
@ -56,7 +54,7 @@ if(NOT NLopt_DIR)
get_filename_component(NLopt_INCLUDE_DIR ${_NLopt_HEADER_FILE} DIRECTORY )
endif()
unset(_NLopt_HEADER_FILE CACHE)
else()
@ -95,7 +93,7 @@ else()
set(NLopt_ERROR_REASON "${NLopt_ERROR_REASON} Cannot find NLopt header file '${_NLopt_HEADER_FILE_NAME}' in '${NLopt_INCLUDE_DIR}'.")
endif()
unset(_NLopt_HEADER_FILE_NAME)
unset(_NLopt_HEADER_FILE)
unset(_NLopt_HEADER_FILE CACHE)
endif()
@ -114,10 +112,10 @@ if(NLopt_FOUND)
message(STATUS "Found NLopt in '${NLopt_DIR}'.")
message(STATUS "Using NLopt include directory '${NLopt_INCLUDE_DIR}'.")
message(STATUS "Using NLopt library '${NLopt_LIBS}'.")
add_library(Nlopt::Nlopt INTERFACE IMPORTED)
set_target_properties(Nlopt::Nlopt PROPERTIES INTERFACE_LINK_LIBRARIES ${NLopt_LIBS})
set_target_properties(Nlopt::Nlopt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${NLopt_INCLUDE_DIR})
set_target_properties(Nlopt::Nlopt PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${NLopt_DEFINITIONS}")
add_library(NLopt::nlopt INTERFACE IMPORTED)
set_target_properties(NLopt::nlopt PROPERTIES INTERFACE_LINK_LIBRARIES ${NLopt_LIBS})
set_target_properties(NLopt::nlopt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${NLopt_INCLUDE_DIR})
set_target_properties(NLopt::nlopt PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${NLopt_DEFINITIONS}")
# target_link_libraries(Nlopt::Nlopt INTERFACE ${NLopt_LIBS})
# target_include_directories(Nlopt::Nlopt INTERFACE ${NLopt_INCLUDE_DIR})
# target_compile_definitions(Nlopt::Nlopt INTERFACE ${NLopt_DEFINITIONS})

View File

@ -0,0 +1,490 @@
# Copyright (c) DreamWorks Animation LLC
#
# All rights reserved. This software is distributed under the
# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
#
# Redistributions of source code must retain the above copyright
# and license notice and the following restrictions and disclaimer.
#
# * Neither the name of DreamWorks Animation nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
#
#[=======================================================================[.rst:
FindOpenVDB
-----------
Find OpenVDB include dirs, libraries and settings
Use this module by invoking find_package with the form::
find_package(OpenVDB
[version] [EXACT] # Minimum or EXACT version
[REQUIRED] # Fail with error if OpenVDB is not found
[COMPONENTS <libs>...] # OpenVDB libraries by their canonical name
# e.g. "openvdb" for "libopenvdb"
)
IMPORTED Targets
^^^^^^^^^^^^^^^^
``OpenVDB::openvdb``
The core openvdb library target.
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``OpenVDB_FOUND``
True if the system has the OpenVDB library.
``OpenVDB_VERSION``
The version of the OpenVDB library which was found.
``OpenVDB_INCLUDE_DIRS``
Include directories needed to use OpenVDB.
``OpenVDB_LIBRARIES``
Libraries needed to link to OpenVDB.
``OpenVDB_LIBRARY_DIRS``
OpenVDB library directories.
``OpenVDB_DEFINITIONS``
Definitions to use when compiling code that uses OpenVDB.
``OpenVDB_{COMPONENT}_FOUND``
True if the system has the named OpenVDB component.
``OpenVDB_USES_BLOSC``
True if the OpenVDB Library has been built with blosc support
``OpenVDB_USES_LOG4CPLUS``
True if the OpenVDB Library has been built with log4cplus support
``OpenVDB_USES_EXR``
True if the OpenVDB Library has been built with openexr support
``OpenVDB_ABI``
Set if this module was able to determine the ABI number the located
OpenVDB Library was built against. Unset otherwise.
Cache Variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``OpenVDB_INCLUDE_DIR``
The directory containing ``openvdb/version.h``.
``OpenVDB_{COMPONENT}_LIBRARY``
Individual component libraries for OpenVDB
Hints
^^^^^
Instead of explicitly setting the cache variables, the following variables
may be provided to tell this module where to look.
``OPENVDB_ROOT``
Preferred installation prefix.
``OPENVDB_INCLUDEDIR``
Preferred include directory e.g. <prefix>/include
``OPENVDB_LIBRARYDIR``
Preferred library directory e.g. <prefix>/lib
``SYSTEM_LIBRARY_PATHS``
Paths appended to all include and lib searches.
#]=======================================================================]
cmake_minimum_required(VERSION 3.3)
# Monitoring <PackageName>_ROOT variables
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# Include utility functions for version information
include(${CMAKE_CURRENT_LIST_DIR}/OpenVDBUtils.cmake)
mark_as_advanced(
OpenVDB_INCLUDE_DIR
OpenVDB_LIBRARY
)
set(_OPENVDB_COMPONENT_LIST
openvdb
)
if(OpenVDB_FIND_COMPONENTS)
set(OPENVDB_COMPONENTS_PROVIDED TRUE)
set(_IGNORED_COMPONENTS "")
foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
if(NOT ${COMPONENT} IN_LIST _OPENVDB_COMPONENT_LIST)
list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
endif()
endforeach()
if(_IGNORED_COMPONENTS)
message(STATUS "Ignoring unknown components of OpenVDB:")
foreach(COMPONENT ${_IGNORED_COMPONENTS})
message(STATUS " ${COMPONENT}")
endforeach()
list(REMOVE_ITEM OpenVDB_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
endif()
else()
set(OPENVDB_COMPONENTS_PROVIDED FALSE)
set(OpenVDB_FIND_COMPONENTS ${_OPENVDB_COMPONENT_LIST})
endif()
# Append OPENVDB_ROOT or $ENV{OPENVDB_ROOT} if set (prioritize the direct cmake var)
set(_OPENVDB_ROOT_SEARCH_DIR "")
# Additionally try and use pkconfig to find OpenVDB
find_package(PkgConfig)
pkg_check_modules(PC_OpenVDB QUIET OpenVDB)
# ------------------------------------------------------------------------
# Search for OpenVDB include DIR
# ------------------------------------------------------------------------
set(_OPENVDB_INCLUDE_SEARCH_DIRS "")
list(APPEND _OPENVDB_INCLUDE_SEARCH_DIRS
${OPENVDB_INCLUDEDIR}
${_OPENVDB_ROOT_SEARCH_DIR}
${PC_OpenVDB_INCLUDE_DIRS}
${SYSTEM_LIBRARY_PATHS}
)
# Look for a standard OpenVDB header file.
find_path(OpenVDB_INCLUDE_DIR openvdb/version.h
PATHS ${_OPENVDB_INCLUDE_SEARCH_DIRS}
PATH_SUFFIXES include
)
OPENVDB_VERSION_FROM_HEADER("${OpenVDB_INCLUDE_DIR}/openvdb/version.h"
VERSION OpenVDB_VERSION
MAJOR OpenVDB_MAJOR_VERSION
MINOR OpenVDB_MINOR_VERSION
PATCH OpenVDB_PATCH_VERSION
)
# ------------------------------------------------------------------------
# Search for OPENVDB lib DIR
# ------------------------------------------------------------------------
set(_OPENVDB_LIBRARYDIR_SEARCH_DIRS "")
# Append to _OPENVDB_LIBRARYDIR_SEARCH_DIRS in priority order
list(APPEND _OPENVDB_LIBRARYDIR_SEARCH_DIRS
${OPENVDB_LIBRARYDIR}
${_OPENVDB_ROOT_SEARCH_DIR}
${PC_OpenVDB_LIBRARY_DIRS}
${SYSTEM_LIBRARY_PATHS}
)
# Build suffix directories
set(OPENVDB_PATH_SUFFIXES
lib64
lib
)
# Static library setup
if(UNIX AND OPENVDB_USE_STATIC_LIBS)
set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
set(OpenVDB_LIB_COMPONENTS "")
foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
set(LIB_NAME ${COMPONENT})
find_library(OpenVDB_${COMPONENT}_LIBRARY ${LIB_NAME} lib${LIB_NAME}
PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
)
list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY})
if(OpenVDB_${COMPONENT}_LIBRARY)
set(OpenVDB_${COMPONENT}_FOUND TRUE)
else()
set(OpenVDB_${COMPONENT}_FOUND FALSE)
endif()
endforeach()
if(UNIX AND OPENVDB_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
# ------------------------------------------------------------------------
# Cache and set OPENVDB_FOUND
# ------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenVDB
FOUND_VAR OpenVDB_FOUND
REQUIRED_VARS
OpenVDB_INCLUDE_DIR
OpenVDB_LIB_COMPONENTS
VERSION_VAR OpenVDB_VERSION
HANDLE_COMPONENTS
)
# ------------------------------------------------------------------------
# Determine ABI number
# ------------------------------------------------------------------------
# Set the ABI number the library was built against. Uses vdb_print
find_program(OPENVDB_PRINT vdb_print PATHS ${OpenVDB_INCLUDE_DIR} )
OPENVDB_ABI_VERSION_FROM_PRINT(
"${OPENVDB_PRINT}"
ABI OpenVDB_ABI
)
if(NOT OpenVDB_FIND_QUIET)
if(NOT OpenVDB_ABI)
message(WARNING "Unable to determine OpenVDB ABI version from OpenVDB "
"installation. The library major version \"${OpenVDB_MAJOR_VERSION}\" "
"will be inferred. If this is not correct, use "
"add_definitions(-DOPENVDB_ABI_VERSION_NUMBER=N)"
)
else()
message(STATUS "OpenVDB ABI Version: ${OpenVDB_ABI}")
endif()
endif()
# ------------------------------------------------------------------------
# Handle OpenVDB dependencies
# ------------------------------------------------------------------------
# Add standard dependencies
find_package(IlmBase COMPONENTS Half)
if(NOT IlmBase_FOUND)
pkg_check_modules(IlmBase QUIET IlmBase)
endif()
if (IlmBase_FOUND AND NOT TARGET IlmBase::Half)
message(STATUS "Falling back to IlmBase found by pkg-config...")
find_library(IlmHalf_LIBRARY NAMES Half)
if(IlmHalf_LIBRARY-NOTFOUND)
message(FATAL_ERROR "IlmBase::Half can not be found!")
endif()
add_library(IlmBase::Half UNKNOWN IMPORTED)
set_target_properties(IlmBase::Half PROPERTIES
IMPORTED_LOCATION "${IlmHalf_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES ${IlmBase_INCLUDE_DIRS})
elseif(NOT IlmBase_FOUND)
message(FATAL_ERROR "IlmBase::Half can not be found!")
endif()
find_package(TBB REQUIRED COMPONENTS tbb)
find_package(ZLIB REQUIRED)
find_package(Boost REQUIRED COMPONENTS iostreams system)
# Use GetPrerequisites to see which libraries this OpenVDB lib has linked to
# which we can query for optional deps. This basically runs ldd/otoll/objdump
# etc to track deps. We could use a vdb_config binary tools here to improve
# this process
include(GetPrerequisites)
set(_EXCLUDE_SYSTEM_PREREQUISITES 1)
set(_RECURSE_PREREQUISITES 0)
set(_OPENVDB_PREREQUISITE_LIST)
if(NOT OPENVDB_USE_STATIC_LIBS)
get_prerequisites(${OpenVDB_openvdb_LIBRARY}
_OPENVDB_PREREQUISITE_LIST
${_EXCLUDE_SYSTEM_PREREQUISITES}
${_RECURSE_PREREQUISITES}
""
"${SYSTEM_LIBRARY_PATHS}"
)
endif()
unset(_EXCLUDE_SYSTEM_PREREQUISITES)
unset(_RECURSE_PREREQUISITES)
# As the way we resolve optional libraries relies on library file names, use
# the configuration options from the main CMakeLists.txt to allow users
# to manually identify the requirements of OpenVDB builds if they know them.
set(OpenVDB_USES_BLOSC ${USE_BLOSC})
set(OpenVDB_USES_LOG4CPLUS ${USE_LOG4CPLUS})
set(OpenVDB_USES_ILM ${USE_EXR})
set(OpenVDB_USES_EXR ${USE_EXR})
# Search for optional dependencies
foreach(PREREQUISITE ${_OPENVDB_PREREQUISITE_LIST})
set(_HAS_DEP)
get_filename_component(PREREQUISITE ${PREREQUISITE} NAME)
string(FIND ${PREREQUISITE} "blosc" _HAS_DEP)
if(NOT ${_HAS_DEP} EQUAL -1)
set(OpenVDB_USES_BLOSC ON)
endif()
string(FIND ${PREREQUISITE} "log4cplus" _HAS_DEP)
if(NOT ${_HAS_DEP} EQUAL -1)
set(OpenVDB_USES_LOG4CPLUS ON)
endif()
string(FIND ${PREREQUISITE} "IlmImf" _HAS_DEP)
if(NOT ${_HAS_DEP} EQUAL -1)
set(OpenVDB_USES_ILM ON)
endif()
endforeach()
unset(_OPENVDB_PREREQUISITE_LIST)
unset(_HAS_DEP)
if(OpenVDB_USES_BLOSC)
find_package(Blosc )
if(NOT Blosc_FOUND OR NOT TARGET Blosc::blosc)
message(STATUS "find_package could not find Blosc. Using fallback blosc search...")
find_path(Blosc_INCLUDE_DIR blosc.h)
find_library(Blosc_LIBRARY NAMES blosc)
if (Blosc_INCLUDE_DIR AND Blosc_LIBRARY)
set(Blosc_FOUND TRUE)
add_library(Blosc::blosc UNKNOWN IMPORTED)
set_target_properties(Blosc::blosc PROPERTIES
IMPORTED_LOCATION "${Blosc_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES ${Blosc_INCLUDE_DIR})
elseif()
message(FATAL_ERROR "Blosc library can not be found!")
endif()
endif()
endif()
if(OpenVDB_USES_LOG4CPLUS)
find_package(Log4cplus REQUIRED)
endif()
if(OpenVDB_USES_ILM)
find_package(IlmBase REQUIRED)
endif()
if(OpenVDB_USES_EXR)
find_package(OpenEXR REQUIRED)
endif()
if(UNIX)
find_package(Threads REQUIRED)
endif()
# Set deps. Note that the order here is important. If we're building against
# Houdini 17.5 we must include OpenEXR and IlmBase deps first to ensure the
# users chosen namespaced headers are correctly prioritized. Otherwise other
# include paths from shared installs (including houdini) may pull in the wrong
# headers
set(_OPENVDB_VISIBLE_DEPENDENCIES
Boost::iostreams
Boost::system
IlmBase::Half
)
set(_OPENVDB_DEFINITIONS)
if(OpenVDB_ABI)
list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_ABI_VERSION_NUMBER=${OpenVDB_ABI}")
endif()
if(OpenVDB_USES_EXR)
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
IlmBase::IlmThread
IlmBase::Iex
IlmBase::Imath
OpenEXR::IlmImf
)
list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_TOOLS_RAYTRACER_USE_EXR")
endif()
if(OpenVDB_USES_LOG4CPLUS)
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Log4cplus::log4cplus)
list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_USE_LOG4CPLUS")
endif()
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
TBB::tbb
)
if(UNIX)
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
Threads::Threads
)
endif()
set(_OPENVDB_HIDDEN_DEPENDENCIES)
if(OpenVDB_USES_BLOSC)
if(OPENVDB_USE_STATIC_LIBS)
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:Blosc::blosc>)
else()
list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES Blosc::blosc)
endif()
endif()
if(OPENVDB_USE_STATIC_LIBS)
list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:ZLIB::ZLIB>)
else()
list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES ZLIB::ZLIB)
endif()
# ------------------------------------------------------------------------
# Configure imported target
# ------------------------------------------------------------------------
set(OpenVDB_LIBRARIES
${OpenVDB_LIB_COMPONENTS}
)
set(OpenVDB_INCLUDE_DIRS ${OpenVDB_INCLUDE_DIR})
set(OpenVDB_DEFINITIONS)
list(APPEND OpenVDB_DEFINITIONS "${PC_OpenVDB_CFLAGS_OTHER}")
list(APPEND OpenVDB_DEFINITIONS "${_OPENVDB_DEFINITIONS}")
list(REMOVE_DUPLICATES OpenVDB_DEFINITIONS)
set(OpenVDB_LIBRARY_DIRS "")
foreach(LIB ${OpenVDB_LIB_COMPONENTS})
get_filename_component(_OPENVDB_LIBDIR ${LIB} DIRECTORY)
list(APPEND OpenVDB_LIBRARY_DIRS ${_OPENVDB_LIBDIR})
endforeach()
list(REMOVE_DUPLICATES OpenVDB_LIBRARY_DIRS)
foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
if(NOT TARGET OpenVDB::${COMPONENT})
add_library(OpenVDB::${COMPONENT} UNKNOWN IMPORTED)
set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
IMPORTED_LOCATION "${OpenVDB_${COMPONENT}_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${OpenVDB_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_INCLUDE_DIR}"
IMPORTED_LINK_DEPENDENT_LIBRARIES "${_OPENVDB_HIDDEN_DEPENDENCIES}" # non visible deps
INTERFACE_LINK_LIBRARIES "${_OPENVDB_VISIBLE_DEPENDENCIES}" # visible deps (headers)
INTERFACE_COMPILE_FEATURES cxx_std_11
)
if (OPENVDB_USE_STATIC_LIBS)
set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "OPENVDB_STATICLIB;OPENVDB_OPENEXR_STATICLIB"
)
endif()
endif()
endforeach()
if(OpenVDB_FOUND AND NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message(STATUS "OpenVDB libraries: ${OpenVDB_LIBRARIES}")
endif()
unset(_OPENVDB_DEFINITIONS)
unset(_OPENVDB_VISIBLE_DEPENDENCIES)
unset(_OPENVDB_HIDDEN_DEPENDENCIES)

View File

@ -93,8 +93,16 @@
# This module will also create the "tbb" target that may be used when building
# executables and libraries.
unset(TBB_FOUND CACHE)
unset(TBB_INCLUDE_DIRS CACHE)
unset(TBB_LIBRARIES)
unset(TBB_LIBRARIES_DEBUG)
unset(TBB_LIBRARIES_RELEASE)
include(FindPackageHandleStandardArgs)
find_package(Threads QUIET REQUIRED)
if(NOT TBB_FOUND)
##################################
@ -215,6 +223,9 @@ if(NOT TBB_FOUND)
foreach(_comp ${TBB_SEARCH_COMPOMPONENTS})
if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};")
unset(TBB_${_comp}_LIBRARY_DEBUG CACHE)
unset(TBB_${_comp}_LIBRARY_RELEASE CACHE)
# Search for the libraries
find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}${TBB_STATIC_SUFFIX}
HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
@ -250,28 +261,31 @@ if(NOT TBB_FOUND)
endif()
endforeach()
unset(TBB_STATIC_SUFFIX)
##################################
# Set compile flags and libraries
##################################
set(TBB_DEFINITIONS_RELEASE "")
set(TBB_DEFINITIONS_DEBUG "-DTBB_USE_DEBUG=1")
set(TBB_DEFINITIONS_DEBUG "TBB_USE_DEBUG=1")
if(TBB_LIBRARIES_${TBB_BUILD_TYPE})
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_${TBB_BUILD_TYPE}}")
set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}")
elseif(TBB_LIBRARIES_RELEASE)
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_RELEASE}")
set(TBB_LIBRARIES "${TBB_LIBRARIES_RELEASE}")
elseif(TBB_LIBRARIES_DEBUG)
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}")
set(TBB_LIBRARIES "${TBB_LIBRARIES_DEBUG}")
endif()
if(NOT MSVC AND NOT TBB_LIBRARIES)
set(TBB_LIBRARIES ${TBB_LIBRARIES_RELEASE})
endif()
set(TBB_DEFINITIONS "")
if (MSVC AND TBB_STATIC)
set(TBB_DEFINITIONS __TBB_NO_IMPLICIT_LINKAGE)
endif ()
unset (TBB_STATIC_SUFFIX)
find_package_handle_standard_args(TBB
REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
FAIL_MESSAGE "TBB library cannot be found. Consider set TBBROOT environment variable."
HANDLE_COMPONENTS
VERSION_VAR TBB_VERSION)
@ -280,25 +294,20 @@ if(NOT TBB_FOUND)
##################################
if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
add_library(tbb UNKNOWN IMPORTED)
set_target_properties(tbb PROPERTIES
add_library(TBB::tbb UNKNOWN IMPORTED)
set_target_properties(TBB::tbb PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS}"
INTERFACE_LINK_LIBRARIES "Threads::Threads;${CMAKE_DL_LIBS}"
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
IMPORTED_LOCATION ${TBB_LIBRARIES})
if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG)
set_target_properties(tbb PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>"
set_target_properties(TBB::tbb PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS};$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:${TBB_DEFINITIONS_DEBUG}>;$<$<CONFIG:Release>:${TBB_DEFINITIONS_RELEASE}>"
IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG}
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_RELEASE}
IMPORTED_LOCATION_RELEASE ${TBB_LIBRARIES_RELEASE}
IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE}
)
elseif(TBB_LIBRARIES_RELEASE)
set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE})
else()
set_target_properties(tbb PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}"
IMPORTED_LOCATION ${TBB_LIBRARIES_DEBUG}
)
endif()
endif()

View File

@ -0,0 +1,166 @@
# Copyright (c) DreamWorks Animation LLC
#
# All rights reserved. This software is distributed under the
# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
#
# Redistributions of source code must retain the above copyright
# and license notice and the following restrictions and disclaimer.
#
# * Neither the name of DreamWorks Animation nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
#
#[=======================================================================[.rst:
OpenVDBUtils.cmake
------------------
A utility CMake file which provides helper functions for configuring an
OpenVDB installation.
Use this module by invoking include with the form::
include ( OpenVDBUtils )
The following functions are provided:
``OPENVDB_VERSION_FROM_HEADER``
OPENVDB_VERSION_FROM_HEADER ( <header_path>
VERSION [<version>]
MAJOR [<version>]
MINOR [<version>]
PATCH [<version>] )
Parse the provided version file to retrieve the current OpenVDB
version information. The file is expected to be a version.h file
as found in the following path of an OpenVDB repository:
openvdb/version.h
If the file does not exist, variables are unmodified.
``OPENVDB_ABI_VERSION_FROM_PRINT``
OPENVDB_ABI_VERSION_FROM_PRINT ( <vdb_print>
[QUIET]
ABI [<version>] )
Retrieve the ABI version that an installation of OpenVDB was compiled
for using the provided vdb_print binary. Parses the result of:
vdb_print --version
If the binary does not exist or fails to launch, variables are
unmodified.
#]=======================================================================]
function(OPENVDB_VERSION_FROM_HEADER OPENVDB_VERSION_FILE)
cmake_parse_arguments(_VDB "" "VERSION;MAJOR;MINOR;PATCH" "" ${ARGN})
if(NOT EXISTS ${OPENVDB_VERSION_FILE})
return()
endif()
file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
REGEX "^#define[\t ]+OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+.*"
)
string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
_OpenVDB_MAJOR_VERSION "${openvdb_version_str}"
)
file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
REGEX "^#define[\t ]+OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+.*"
)
string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
_OpenVDB_MINOR_VERSION "${openvdb_version_str}"
)
file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str
REGEX "^#define[\t ]+OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+.*"
)
string(REGEX REPLACE "^.*OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1"
_OpenVDB_PATCH_VERSION "${openvdb_version_str}"
)
unset(openvdb_version_str)
if(_VDB_VERSION)
set(${_VDB_VERSION}
${_OpenVDB_MAJOR_VERSION}.${_OpenVDB_MINOR_VERSION}.${_OpenVDB_PATCH_VERSION}
PARENT_SCOPE
)
endif()
if(_VDB_MAJOR)
set(${_VDB_MAJOR} ${_OpenVDB_MAJOR_VERSION} PARENT_SCOPE)
endif()
if(_VDB_MINOR)
set(${_VDB_MINOR} ${_OpenVDB_MINOR_VERSION} PARENT_SCOPE)
endif()
if(_VDB_PATCH)
set(${_VDB_PATCH} ${_OpenVDB_PATCH_VERSION} PARENT_SCOPE)
endif()
endfunction()
########################################################################
########################################################################
function(OPENVDB_ABI_VERSION_FROM_PRINT OPENVDB_PRINT)
cmake_parse_arguments(_VDB "QUIET" "ABI" "" ${ARGN})
if(NOT EXISTS ${OPENVDB_PRINT})
message(WARNING "vdb_print not found! ${OPENVDB_PRINT}")
return()
endif()
set(_VDB_PRINT_VERSION_STRING "")
set(_VDB_PRINT_RETURN_STATUS "")
if(${_VDB_QUIET})
execute_process(COMMAND ${OPENVDB_PRINT} "--version"
RESULT_VARIABLE _VDB_PRINT_RETURN_STATUS
OUTPUT_VARIABLE _VDB_PRINT_VERSION_STRING
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
execute_process(COMMAND ${OPENVDB_PRINT} "--version"
RESULT_VARIABLE _VDB_PRINT_RETURN_STATUS
OUTPUT_VARIABLE _VDB_PRINT_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(${_VDB_PRINT_RETURN_STATUS})
message(WARNING "vdb_print returned with status ${_VDB_PRINT_RETURN_STATUS}")
return()
endif()
set(_OpenVDB_ABI)
string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING})
if(${_OpenVDB_ABI} STREQUAL ${_VDB_PRINT_VERSION_STRING})
set(_OpenVDB_ABI "")
endif()
unset(_VDB_PRINT_RETURN_STATUS)
unset(_VDB_PRINT_VERSION_STRING)
if(_VDB_ABI)
set(${_VDB_ABI} ${_OpenVDB_ABI} PARENT_SCOPE)
endif()
endfunction()

4
deps/CMakeLists.txt vendored
View File

@ -71,7 +71,7 @@ elseif (APPLE)
message(FATAL_ERROR "Could not determine OS X SDK version. Please use -DCMAKE_OSX_DEPLOYMENT_TARGET=<version>")
endif ()
message("OS X Deployment Target (inferred from default): ${DEP_OSX_TARGET}")
message("OS X Deployment Target (inferred from SDK): ${DEP_OSX_TARGET}")
endif ()
include("deps-macos.cmake")
@ -95,6 +95,7 @@ if (MSVC)
dep_nlopt
# dep_qhull # Experimental
dep_zlib # on Windows we still need zlib
dep_openvdb
)
else()
@ -109,6 +110,7 @@ else()
dep_cereal
dep_nlopt
dep_qhull
dep_openvdb
# dep_libigl # Not working, static build has different Eigen
)

469
deps/blosc-mods.patch vendored Normal file
View File

@ -0,0 +1,469 @@
From 7cf6c014a36f1712efbdbe9bc52d2d4922b54673 Mon Sep 17 00:00:00 2001
From: tamasmeszaros <meszaros.q@gmail.com>
Date: Wed, 30 Oct 2019 12:54:52 +0100
Subject: [PATCH] Blosc 1.17 fixes and cmake config script
Signed-off-by: tamasmeszaros <meszaros.q@gmail.com>
---
CMakeLists.txt | 105 +++++++++++++++++-----------------
blosc/CMakeLists.txt | 118 +++++++++------------------------------
cmake/FindLZ4.cmake | 6 +-
cmake/FindSnappy.cmake | 8 ++-
cmake/FindZstd.cmake | 8 ++-
cmake_config.cmake.in | 24 ++++++++
internal-complibs/CMakeLists.txt | 35 ++++++++++++
7 files changed, 157 insertions(+), 147 deletions(-)
create mode 100644 cmake_config.cmake.in
create mode 100644 internal-complibs/CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59d9fab..e9134c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,7 +71,7 @@
# DEV: static includes blosc.a and blosc.h
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.1) # Threads::Threads target available from 3.1
if (NOT CMAKE_VERSION VERSION_LESS 3.3)
cmake_policy(SET CMP0063 NEW)
endif()
@@ -124,55 +124,30 @@ option(PREFER_EXTERNAL_ZSTD
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
-
-if(NOT DEACTIVATE_LZ4)
- if(PREFER_EXTERNAL_LZ4)
- find_package(LZ4)
- else()
- message(STATUS "Using LZ4 internal sources.")
- endif(PREFER_EXTERNAL_LZ4)
- # HAVE_LZ4 will be set to true because even if the library is
- # not found, we will use the included sources for it
- set(HAVE_LZ4 TRUE)
-endif(NOT DEACTIVATE_LZ4)
-
-if(NOT DEACTIVATE_SNAPPY)
- if(PREFER_EXTERNAL_SNAPPY)
- find_package(Snappy)
- else()
- message(STATUS "Using Snappy internal sources.")
- endif(PREFER_EXTERNAL_SNAPPY)
- # HAVE_SNAPPY will be set to true because even if the library is not found,
- # we will use the included sources for it
- set(HAVE_SNAPPY TRUE)
-endif(NOT DEACTIVATE_SNAPPY)
-
-if(NOT DEACTIVATE_ZLIB)
- # import the ZLIB_ROOT environment variable to help finding the zlib library
- if(PREFER_EXTERNAL_ZLIB)
- set(ZLIB_ROOT $ENV{ZLIB_ROOT})
- find_package(ZLIB)
- if (NOT ZLIB_FOUND )
- message(STATUS "No zlib found. Using internal sources.")
- endif (NOT ZLIB_FOUND )
- else()
- message(STATUS "Using zlib internal sources.")
- endif(PREFER_EXTERNAL_ZLIB)
- # HAVE_ZLIB will be set to true because even if the library is not found,
- # we will use the included sources for it
- set(HAVE_ZLIB TRUE)
-endif(NOT DEACTIVATE_ZLIB)
-
-if (NOT DEACTIVATE_ZSTD)
- if (PREFER_EXTERNAL_ZSTD)
- find_package(Zstd)
- else ()
- message(STATUS "Using ZSTD internal sources.")
- endif (PREFER_EXTERNAL_ZSTD)
- # HAVE_ZSTD will be set to true because even if the library is
- # not found, we will use the included sources for it
- set(HAVE_ZSTD TRUE)
-endif (NOT DEACTIVATE_ZSTD)
+set(LIBS "")
+macro(use_package _pkg _tgt)
+ string(TOUPPER ${_pkg} _PKG)
+ if(NOT DEACTIVATE_${_PKG})
+ if(PREFER_EXTERNAL_${_PKG})
+ find_package(${_pkg})
+ if (NOT ${_pkg}_FOUND )
+ message(STATUS "No ${_pkg} found. Using internal sources.")
+ endif()
+ else()
+ message(STATUS "Using ${_pkg} internal sources.")
+ endif(PREFER_EXTERNAL_${_PKG})
+ # HAVE_${_pkg} will be set to true because even if the library is
+ # not found, we will use the included sources for it
+ set(HAVE_${_PKG} TRUE)
+ list(APPEND LIBS ${_pkg}::${_tgt})
+ endif(NOT DEACTIVATE_${_PKG})
+endmacro()
+
+set(ZLIB_ROOT $ENV{ZLIB_ROOT})
+use_package(ZLIB ZLIB)
+use_package(LZ4 LZ4)
+use_package(Snappy snappy)
+use_package(Zstd Zstd)
# create the config.h file
configure_file ("blosc/config.h.in" "blosc/config.h" )
@@ -316,6 +291,7 @@ endif()
# subdirectories
+add_subdirectory(internal-complibs)
add_subdirectory(blosc)
if(BUILD_TESTS)
@@ -328,7 +304,6 @@ if(BUILD_BENCHMARKS)
add_subdirectory(bench)
endif(BUILD_BENCHMARKS)
-
# uninstall target
if (BLOSC_INSTALL)
configure_file(
@@ -338,10 +313,38 @@ if (BLOSC_INSTALL)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/blosc.pc"
DESTINATION lib/pkgconfig COMPONENT DEV)
+ configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/BloscConfig.cmake"
+ @ONLY)
+
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
+
+ include(CMakePackageConfigHelpers)
+ write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/BloscConfigVersion.cmake"
+ VERSION ${BLOSC_VERSION_MAJOR}.${BLOSC_VERSION_MINOR}.${BLOSC_VERSION_PATCH}
+ COMPATIBILITY AnyNewerVersion
+ )
+
+ export(EXPORT BloscTargets
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/BloscTargets.cmake"
+ NAMESPACE Blosc::)
+
+ install(EXPORT BloscTargets
+ FILE BloscTargets.cmake
+ NAMESPACE Blosc::
+ DESTINATION lib/cmake/Blosc
+ EXPORT_LINK_INTERFACE_LIBRARIES)
+
+ install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/BloscConfig.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/cmakeexports/BloscConfigVersion.cmake"
+ DESTINATION lib/cmake/Blosc COMPONENT DEV)
+
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
diff --git a/blosc/CMakeLists.txt b/blosc/CMakeLists.txt
index 1d1bebe..f554abe 100644
--- a/blosc/CMakeLists.txt
+++ b/blosc/CMakeLists.txt
@@ -1,52 +1,11 @@
# a simple way to detect that we are using CMAKE
add_definitions(-DUSING_CMAKE)
-set(INTERNAL_LIBS ${PROJECT_SOURCE_DIR}/internal-complibs)
-
# Hide symbols by default unless they're specifically exported.
# This makes it easier to keep the set of exported symbols the
# same across all compilers/platforms.
set(CMAKE_C_VISIBILITY_PRESET hidden)
-# includes
-set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
-if(NOT DEACTIVATE_LZ4)
- if (LZ4_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_INCLUDE_DIR})
- else(LZ4_FOUND)
- set(LZ4_LOCAL_DIR ${INTERNAL_LIBS}/lz4-1.9.1)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_LOCAL_DIR})
- endif(LZ4_FOUND)
-endif(NOT DEACTIVATE_LZ4)
-
-if(NOT DEACTIVATE_SNAPPY)
- if (SNAPPY_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_INCLUDE_DIR})
- else(SNAPPY_FOUND)
- set(SNAPPY_LOCAL_DIR ${INTERNAL_LIBS}/snappy-1.1.1)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_LOCAL_DIR})
- endif(SNAPPY_FOUND)
-endif(NOT DEACTIVATE_SNAPPY)
-
-if(NOT DEACTIVATE_ZLIB)
- if (ZLIB_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
- else(ZLIB_FOUND)
- set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/zlib-1.2.8)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_LOCAL_DIR})
- endif(ZLIB_FOUND)
-endif(NOT DEACTIVATE_ZLIB)
-
-if (NOT DEACTIVATE_ZSTD)
- if (ZSTD_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIR})
- else (ZSTD_FOUND)
- set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.4.1)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
- endif (ZSTD_FOUND)
-endif (NOT DEACTIVATE_ZSTD)
-
-include_directories(${BLOSC_INCLUDE_DIRS})
# library sources
set(SOURCES blosc.c blosclz.c fastcopy.c shuffle-generic.c bitshuffle-generic.c
@@ -73,53 +32,13 @@ if(WIN32)
message(STATUS "using the internal pthread library for win32 systems.")
set(SOURCES ${SOURCES} win32/pthread.c)
else(NOT Threads_FOUND)
- set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
+ list(APPEND LIBS Threads::Threads)
endif(NOT Threads_FOUND)
else(WIN32)
find_package(Threads REQUIRED)
- set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
+ list(APPEND LIBS Threads::Threads)
endif(WIN32)
-if(NOT DEACTIVATE_LZ4)
- if(LZ4_FOUND)
- set(LIBS ${LIBS} ${LZ4_LIBRARY})
- else(LZ4_FOUND)
- file(GLOB LZ4_FILES ${LZ4_LOCAL_DIR}/*.c)
- set(SOURCES ${SOURCES} ${LZ4_FILES})
- endif(LZ4_FOUND)
-endif(NOT DEACTIVATE_LZ4)
-
-if(NOT DEACTIVATE_SNAPPY)
- if(SNAPPY_FOUND)
- set(LIBS ${LIBS} ${SNAPPY_LIBRARY})
- else(SNAPPY_FOUND)
- file(GLOB SNAPPY_FILES ${SNAPPY_LOCAL_DIR}/*.cc)
- set(SOURCES ${SOURCES} ${SNAPPY_FILES})
- endif(SNAPPY_FOUND)
-endif(NOT DEACTIVATE_SNAPPY)
-
-if(NOT DEACTIVATE_ZLIB)
- if(ZLIB_FOUND)
- set(LIBS ${LIBS} ${ZLIB_LIBRARY})
- else(ZLIB_FOUND)
- file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c)
- set(SOURCES ${SOURCES} ${ZLIB_FILES})
- endif(ZLIB_FOUND)
-endif(NOT DEACTIVATE_ZLIB)
-
-if (NOT DEACTIVATE_ZSTD)
- if (ZSTD_FOUND)
- set(LIBS ${LIBS} ${ZSTD_LIBRARY})
- else (ZSTD_FOUND)
- file(GLOB ZSTD_FILES
- ${ZSTD_LOCAL_DIR}/common/*.c
- ${ZSTD_LOCAL_DIR}/compress/*.c
- ${ZSTD_LOCAL_DIR}/decompress/*.c)
- set(SOURCES ${SOURCES} ${ZSTD_FILES})
- endif (ZSTD_FOUND)
-endif (NOT DEACTIVATE_ZSTD)
-
-
# targets
if (BUILD_SHARED)
add_library(blosc_shared SHARED ${SOURCES})
@@ -191,14 +110,17 @@ if (BUILD_TESTS)
endif()
endif()
+add_library(blosc INTERFACE)
+
if (BUILD_SHARED)
- target_link_libraries(blosc_shared ${LIBS})
- target_include_directories(blosc_shared PUBLIC ${BLOSC_INCLUDE_DIRS})
+ target_link_libraries(blosc_shared PRIVATE ${LIBS})
+ target_include_directories(blosc_shared PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
+ target_link_libraries(blosc INTERFACE blosc_shared)
endif()
if (BUILD_TESTS)
- target_link_libraries(blosc_shared_testing ${LIBS})
- target_include_directories(blosc_shared_testing PUBLIC ${BLOSC_INCLUDE_DIRS})
+ target_link_libraries(blosc_shared_testing PRIVATE ${LIBS})
+ target_include_directories(blosc_shared_testing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(BUILD_STATIC)
@@ -207,17 +129,31 @@ if(BUILD_STATIC)
if (MSVC)
set_target_properties(blosc_static PROPERTIES PREFIX lib)
endif()
- target_link_libraries(blosc_static ${LIBS})
- target_include_directories(blosc_static PUBLIC ${BLOSC_INCLUDE_DIRS})
+ # With the static library, cmake has to deal with transitive dependencies
+ target_link_libraries(blosc_static PRIVATE ${LIBS})
+ target_include_directories(blosc_static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
+ if (NOT BUILD_SHARED)
+ target_link_libraries(blosc INTERFACE blosc_static)
+ endif()
endif(BUILD_STATIC)
+
# install
if(BLOSC_INSTALL)
install(FILES blosc.h blosc-export.h DESTINATION include COMPONENT DEV)
+ set(_inst_libs "blosc")
if(BUILD_SHARED)
- install(TARGETS blosc_shared DESTINATION ${lib_dir} COMPONENT LIB)
+ list(APPEND _inst_libs blosc_shared)
endif(BUILD_SHARED)
if(BUILD_STATIC)
- install(TARGETS blosc_static DESTINATION ${lib_dir} COMPONENT DEV)
+ list(APPEND _inst_libs blosc_static)
endif(BUILD_STATIC)
+
+ install(TARGETS ${_inst_libs}
+ EXPORT BloscTargets
+ LIBRARY DESTINATION ${lib_dir}
+ ARCHIVE DESTINATION ${lib_dir}
+ RUNTIME DESTINATION bin
+ COMPONENT DEV
+ INCLUDES DESTINATION include)
endif(BLOSC_INSTALL)
diff --git a/cmake/FindLZ4.cmake b/cmake/FindLZ4.cmake
index e581a80..05de6ef 100644
--- a/cmake/FindLZ4.cmake
+++ b/cmake/FindLZ4.cmake
@@ -5,6 +5,10 @@ find_library(LZ4_LIBRARY NAMES lz4)
if (LZ4_INCLUDE_DIR AND LZ4_LIBRARY)
set(LZ4_FOUND TRUE)
message(STATUS "Found LZ4 library: ${LZ4_LIBRARY}")
+ add_library(LZ4::LZ4 UNKNOWN IMPORTED)
+ set_target_properties(LZ4::LZ4 PROPERTIES
+ IMPORTED_LOCATION ${LZ4_LIBRARY}
+ INTERFACE_INCLUDE_DIRECTORIES ${LZ4_INCLUDE_DIR})
else ()
message(STATUS "No LZ4 library found. Using internal sources.")
-endif ()
+endif ()
\ No newline at end of file
diff --git a/cmake/FindSnappy.cmake b/cmake/FindSnappy.cmake
index 688d4d5..21dbee1 100644
--- a/cmake/FindSnappy.cmake
+++ b/cmake/FindSnappy.cmake
@@ -3,8 +3,12 @@ find_path(SNAPPY_INCLUDE_DIR snappy-c.h)
find_library(SNAPPY_LIBRARY NAMES snappy)
if (SNAPPY_INCLUDE_DIR AND SNAPPY_LIBRARY)
- set(SNAPPY_FOUND TRUE)
+ set(Snappy_FOUND TRUE)
+ add_library(Snappy::snappy UNKNOWN IMPORTED)
+ set_target_properties(Snappy::snappy PROPERTIES
+ IMPORTED_LOCATION ${SNAPPY_LIBRARY}
+ INTERFACE_INCLUDE_DIRECTORIES ${SNAPPY_INCLUDE_DIR})
message(STATUS "Found SNAPPY library: ${SNAPPY_LIBRARY}")
else ()
message(STATUS "No snappy found. Using internal sources.")
-endif ()
+endif ()
\ No newline at end of file
diff --git a/cmake/FindZstd.cmake b/cmake/FindZstd.cmake
index 7db4bb9..cabc2f8 100644
--- a/cmake/FindZstd.cmake
+++ b/cmake/FindZstd.cmake
@@ -3,8 +3,12 @@ find_path(ZSTD_INCLUDE_DIR zstd.h)
find_library(ZSTD_LIBRARY NAMES zstd)
if (ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY)
- set(ZSTD_FOUND TRUE)
+ set(Zstd_FOUND TRUE)
+ add_library(Zstd::Zstd UNKNOWN IMPORTED)
+ set_target_properties(Zstd::Zstd PROPERTIES
+ IMPORTED_LOCATION ${ZSTD_LIBRARY}
+ INTERFACE_INCLUDE_DIRECTORIES ${ZSTD_INCLUDE_DIR})
message(STATUS "Found Zstd library: ${ZSTD_LIBRARY}")
else ()
message(STATUS "No Zstd library found. Using internal sources.")
-endif ()
+endif ()
\ No newline at end of file
diff --git a/cmake_config.cmake.in b/cmake_config.cmake.in
new file mode 100644
index 0000000..0f6af24
--- /dev/null
+++ b/cmake_config.cmake.in
@@ -0,0 +1,24 @@
+include(CMakeFindDependencyMacro)
+
+include("${CMAKE_CURRENT_LIST_DIR}/BloscTargets.cmake")
+
+function(_blosc_remap_configs from_Cfg to_Cfg)
+ string(TOUPPER ${from_Cfg} from_CFG)
+ string(TOLOWER ${from_Cfg} from_cfg)
+
+ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/BloscTargets-${from_cfg}.cmake)
+ foreach(tgt IN ITEMS blosc_static blosc_shared blosc)
+ if(TARGET Blosc::${tgt})
+ set_target_properties(Blosc::${tgt} PROPERTIES
+ MAP_IMPORTED_CONFIG_${from_CFG} ${to_Cfg})
+ endif()
+ endforeach()
+ endif()
+endfunction()
+
+# MSVC will try to link RelWithDebInfo or MinSizeRel target with debug config
+# if no matching installation is present which would result in link errors.
+if(MSVC)
+ _blosc_remap_configs(RelWithDebInfo Release)
+ _blosc_remap_configs(MinSizeRel Release)
+endif()
diff --git a/internal-complibs/CMakeLists.txt b/internal-complibs/CMakeLists.txt
new file mode 100644
index 0000000..4586efa
--- /dev/null
+++ b/internal-complibs/CMakeLists.txt
@@ -0,0 +1,35 @@
+macro(add_lib_target pkg tgt incdir files)
+ string(TOUPPER ${pkg} TGT)
+ if(NOT DEACTIVATE_${TGT} AND NOT ${pkg}_FOUND)
+ add_library(${tgt}_objs OBJECT ${files})
+ add_library(${tgt} INTERFACE)
+ target_include_directories(${tgt}_objs PRIVATE $<BUILD_INTERFACE:${incdir}>)
+ target_include_directories(${tgt} INTERFACE $<BUILD_INTERFACE:${incdir}>)
+ #set_target_properties(${tgt} PROPERTIES INTERFACE_SOURCES "$<TARGET_OBJECTS:${tgt}_objs>")
+ set_target_properties(${tgt}_objs PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ target_sources(${tgt} INTERFACE "$<BUILD_INTERFACE:$<TARGET_OBJECTS:${tgt}_objs>>")
+ add_library(${pkg}::${tgt} ALIAS ${tgt})
+
+ # This creates dummy (empty) interface targets in the exported config.
+ install(TARGETS ${tgt} EXPORT BloscTargets INCLUDES DESTINATION include)
+ endif()
+ unset(TGT)
+endmacro()
+
+set(ZLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zlib-1.2.8)
+file(GLOB ZLIB_FILES ${ZLIB_DIR}/*.c)
+add_lib_target(ZLIB ZLIB ${ZLIB_DIR} "${ZLIB_FILES}")
+
+set(SNAPPY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/snappy-1.1.1)
+file(GLOB SNAPPY_FILES ${SNAPPY_DIR}/*.cc)
+add_lib_target(Snappy snappy ${SNAPPY_DIR} "${SNAPPY_FILES}")
+
+set(LZ4_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lz4-1.9.1)
+file(GLOB LZ4_FILES ${LZ4_DIR}/*.c)
+add_lib_target(LZ4 LZ4 ${LZ4_DIR} "${LZ4_FILES}")
+
+set(ZSTD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zstd-1.4.1)
+file(GLOB ZSTD_FILES ${ZSTD_DIR}/common/*.c ${ZSTD_DIR}/compress/*.c ${ZSTD_DIR}/decompress/*.c)
+add_lib_target(Zstd Zstd ${ZSTD_DIR} "${ZSTD_FILES}")
+target_include_directories(Zstd INTERFACE $<BUILD_INTERFACE:${ZSTD_DIR}/common>)
+target_include_directories(Zstd_objs PRIVATE $<BUILD_INTERFACE:${ZSTD_DIR}/common>)
\ No newline at end of file
--
2.16.2.windows.1

24
deps/deps-linux.cmake vendored
View File

@ -5,11 +5,11 @@ include("deps-unix-common.cmake")
ExternalProject_Add(dep_boost
EXCLUDE_FROM_ALL 1
URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz"
URL_HASH SHA256=bd0df411efd9a585e5a2212275f8762079fed8842264954675a4fddc46cfcf60
URL "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz"
URL_HASH SHA256=882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./bootstrap.sh
--with-libraries=system,filesystem,thread,log,locale,regex
--with-libraries=system,iostreams,filesystem,thread,log,locale,regex
"--prefix=${DESTDIR}/usr/local"
BUILD_COMMAND ./b2
-j ${NPROC}
@ -26,8 +26,8 @@ ExternalProject_Add(dep_boost
ExternalProject_Add(dep_libopenssl
EXCLUDE_FROM_ALL 1
URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0g.tar.gz"
URL_HASH SHA256=8e9516b8635bb9113c51a7b5b27f9027692a56b104e75b709e588c3ffd6a0422
URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0l.tar.gz"
URL_HASH SHA256=e2acf0cf58d9bff2b42f2dc0aee79340c8ffe2c5e45d3ca4533dd5d4f5775b1d
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./config
"--prefix=${DESTDIR}/usr/local"
@ -88,19 +88,17 @@ ExternalProject_Add(dep_libcurl
)
if (DEP_WX_STABLE)
set(DEP_WX_URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.4/wxWidgets-3.0.4.tar.bz2")
set(DEP_WX_HASH "SHA256=96157f988d261b7368e5340afa1a0cad943768f35929c22841f62c25b17bf7f0")
set(DEP_WX_TAG "v3.0.4")
else ()
set(DEP_WX_URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2")
set(DEP_WX_HASH "SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e")
set(DEP_WX_TAG "v3.1.1-patched")
endif()
ExternalProject_Add(dep_wxwidgets
EXCLUDE_FROM_ALL 1
URL "${DEP_WX_URL}"
URL_HASH "${DEP_WX_HASH}"
GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets"
GIT_TAG "${DEP_WX_TAG}"
BUILD_IN_SOURCE 1
PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/wxwidgets-pngprefix.h" src/png/pngprefix.h
# PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/wxwidgets-pngprefix.h" src/png/pngprefix.h
CONFIGURE_COMMAND ./configure
"--prefix=${DESTDIR}/usr/local"
--disable-shared
@ -123,3 +121,5 @@ ExternalProject_Add(dep_wxwidgets
BUILD_COMMAND make "-j${NPROC}" && make -C locale allmo
INSTALL_COMMAND make install
)
add_dependencies(dep_openvdb dep_boost)

25
deps/deps-macos.cmake vendored
View File

@ -6,7 +6,7 @@ set(DEP_WERRORS_SDK "-Werror=partial-availability -Werror=unguarded-availability
set(DEP_CMAKE_OPTS
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
"-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}"
"-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}"
"-DCMAKE_OSX_DEPLOYMENT_TARGET=${DEP_OSX_TARGET}"
"-DCMAKE_CXX_FLAGS=${DEP_WERRORS_SDK}"
"-DCMAKE_C_FLAGS=${DEP_WERRORS_SDK}"
)
@ -14,28 +14,27 @@ set(DEP_CMAKE_OPTS
include("deps-unix-common.cmake")
set(DEP_BOOST_OSX_TARGET "")
if (CMAKE_OSX_DEPLOYMENT_TARGET)
set(DEP_BOOST_OSX_TARGET "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif ()
ExternalProject_Add(dep_boost
EXCLUDE_FROM_ALL 1
URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz"
URL_HASH SHA256=bd0df411efd9a585e5a2212275f8762079fed8842264954675a4fddc46cfcf60
URL "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz"
URL_HASH SHA256=882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./bootstrap.sh
--with-libraries=system,filesystem,thread,log,locale,regex
--with-toolset=clang
--with-libraries=system,iostreams,filesystem,thread,log,locale,regex
"--prefix=${DESTDIR}/usr/local"
BUILD_COMMAND ./b2
-j ${NPROC}
--reconfigure
toolset=clang
link=static
variant=release
threading=multi
boost.locale.icu=off
"cflags=-fPIC ${DEP_BOOST_OSX_TARGET}"
"cxxflags=-fPIC ${DEP_BOOST_OSX_TARGET}"
"cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}"
"cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}"
"mflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}"
"mmflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET}"
install
INSTALL_COMMAND "" # b2 does that already
)
@ -91,8 +90,6 @@ ExternalProject_Add(dep_wxwidgets
EXCLUDE_FROM_ALL 1
GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets"
GIT_TAG v3.1.1-patched
# URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.2/wxWidgets-3.1.2.tar.bz2"
# URL_HASH SHA256=4cb8d23d70f9261debf7d6cfeca667fc0a7d2b6565adb8f1c484f9b674f1f27a
BUILD_IN_SOURCE 1
# PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/wxwidgets-pngprefix.h" src/png/pngprefix.h
CONFIGURE_COMMAND env "CXXFLAGS=${DEP_WERRORS_SDK}" "CFLAGS=${DEP_WERRORS_SDK}" ./configure
@ -114,3 +111,5 @@ ExternalProject_Add(dep_wxwidgets
BUILD_COMMAND make "-j${NPROC}" && PATH=/usr/local/opt/gettext/bin/:$ENV{PATH} make -C locale allmo
INSTALL_COMMAND make install
)
add_dependencies(dep_openvdb dep_boost)

View File

@ -7,6 +7,8 @@ else ()
set(TBB_MINGW_WORKAROUND "")
endif ()
find_package(ZLIB REQUIRED)
ExternalProject_Add(dep_tbb
EXCLUDE_FROM_ALL 1
URL "https://github.com/wjakob/tbb/archive/a0dc9bf76d0120f917b641ed095360448cabc85b.tar.gz"
@ -53,40 +55,67 @@ find_package(Git REQUIRED)
ExternalProject_Add(dep_qhull
EXCLUDE_FROM_ALL 1
URL "https://github.com/qhull/qhull/archive/v7.2.1.tar.gz"
URL_HASH SHA256=6fc251e0b75467e00943bfb7191e986fce0e1f8f6f0251f9c6ce5a843821ea78
#URL "https://github.com/qhull/qhull/archive/v7.3.2.tar.gz"
#URL_HASH SHA256=619c8a954880d545194bc03359404ef36a1abd2dde03678089459757fd790cb0
GIT_REPOSITORY https://github.com/qhull/qhull.git
GIT_TAG 7afedcc73666e46a9f1d74632412ebecf53b1b30 # v7.3.2 plus the mac build patch
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
${DEP_CMAKE_OPTS}
PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/qhull-mods.patch
)
ExternalProject_Add(dep_libigl
ExternalProject_Add(dep_blosc
EXCLUDE_FROM_ALL 1
URL "https://github.com/libigl/libigl/archive/v2.0.0.tar.gz"
URL_HASH SHA256=42518e6b106c7209c73435fd260ed5d34edeb254852495b4c95dce2d95401328
GIT_REPOSITORY https://github.com/Blosc/c-blosc.git
GIT_TAG e63775855294b50820ef44d1b157f4de1cc38d3e #v1.17.0
DEPENDS
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DLIBIGL_BUILD_PYTHON=OFF
-DLIBIGL_BUILD_TESTS=OFF
-DLIBIGL_BUILD_TUTORIALS=OFF
-DLIBIGL_USE_STATIC_LIBRARY=OFF #${DEP_BUILD_IGL_STATIC}
-DLIBIGL_WITHOUT_COPYLEFT=OFF
-DLIBIGL_WITH_CGAL=OFF
-DLIBIGL_WITH_COMISO=OFF
-DLIBIGL_WITH_CORK=OFF
-DLIBIGL_WITH_EMBREE=OFF
-DLIBIGL_WITH_MATLAB=OFF
-DLIBIGL_WITH_MOSEK=OFF
-DLIBIGL_WITH_OPENGL=OFF
-DLIBIGL_WITH_OPENGL_GLFW=OFF
-DLIBIGL_WITH_OPENGL_GLFW_IMGUI=OFF
-DLIBIGL_WITH_PNG=OFF
-DLIBIGL_WITH_PYTHON=OFF
-DLIBIGL_WITH_TETGEN=OFF
-DLIBIGL_WITH_TRIANGLE=OFF
-DLIBIGL_WITH_XML=OFF
PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/igl-fixes.patch
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_DEBUG_POSTFIX=d
-DBUILD_SHARED=OFF
-DBUILD_STATIC=ON
-DBUILD_TESTS=OFF
-DBUILD_BENCHMARKS=OFF
-DPREFER_EXTERNAL_ZLIB=ON
PATCH_COMMAND ${GIT_EXECUTABLE} reset --hard && git clean -df &&
${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_SOURCE_DIR}/blosc-mods.patch
)
ExternalProject_Add(dep_openexr
EXCLUDE_FROM_ALL 1
GIT_REPOSITORY https://github.com/openexr/openexr.git
GIT_TAG eae0e337c9f5117e78114fd05f7a415819df413a #v2.4.0
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DBUILD_TESTING=OFF
-DPYILMBASE_ENABLE:BOOL=OFF
-DOPENEXR_VIEWERS_ENABLE:BOOL=OFF
-DOPENEXR_BUILD_UTILS:BOOL=OFF
)
ExternalProject_Add(dep_openvdb
EXCLUDE_FROM_ALL 1
GIT_REPOSITORY https://github.com/AcademySoftwareFoundation/openvdb.git
GIT_TAG aebaf8d95be5e57fd33949281ec357db4a576c2e #v6.2.1
DEPENDS dep_blosc dep_openexr dep_tbb
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_PREFIX_PATH=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DOPENVDB_BUILD_PYTHON_MODULE=OFF
-DUSE_BLOSC=ON
-DOPENVDB_CORE_SHARED=OFF
-DOPENVDB_CORE_STATIC=ON
-DTBB_STATIC=ON
-DOPENVDB_BUILD_VDB_PRINT=ON
-DDISABLE_DEPENDENCY_VERSION_CHECKS=ON
PATCH_COMMAND PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_SOURCE_DIR}/openvdb-mods.patch
)

View File

@ -44,6 +44,18 @@ else ()
set(DEP_BOOST_DEBUG "")
endif ()
macro(add_debug_dep _dep)
if (${DEP_DEBUG})
ExternalProject_Get_Property(${_dep} BINARY_DIR)
ExternalProject_Add_Step(${_dep} build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
endmacro()
ExternalProject_Add(dep_boost
EXCLUDE_FROM_ALL 1
URL "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz"
@ -53,6 +65,7 @@ ExternalProject_Add(dep_boost
BUILD_COMMAND b2.exe
-j "${NPROC}"
--with-system
--with-iostreams
--with-filesystem
--with-thread
--with-log
@ -69,7 +82,6 @@ ExternalProject_Add(dep_boost
INSTALL_COMMAND "" # b2 does that already
)
ExternalProject_Add(dep_tbb
EXCLUDE_FROM_ALL 1
URL "https://github.com/wjakob/tbb/archive/a0dc9bf76d0120f917b641ed095360448cabc85b.tar.gz"
@ -86,43 +98,25 @@ ExternalProject_Add(dep_tbb
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_tbb BINARY_DIR)
ExternalProject_Add_Step(dep_tbb build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
add_debug_dep(dep_tbb)
ExternalProject_Add(dep_gtest
EXCLUDE_FROM_ALL 1
URL "https://github.com/google/googletest/archive/release-1.8.1.tar.gz"
URL_HASH SHA256=9bf1fe5182a604b4135edc1a425ae356c9ad15e9b23f9f12a02e80184c3a249c
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
# if (DEP_VS_VER MORE 15)
# ExternalProject_Add(dep_gtest
# EXCLUDE_FROM_ALL 1
# URL "https://github.com/google/googletest/archive/release-1.8.1.tar.gz"
# URL_HASH SHA256=9bf1fe5182a604b4135edc1a425ae356c9ad15e9b23f9f12a02e80184c3a249c
# CMAKE_GENERATOR "${DEP_MSVC_GEN}"
# CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}"
# endif()
CMAKE_ARGS
-DBUILD_GMOCK=OFF
-Dgtest_force_shared_crt=ON
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
"-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local"
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_gtest BINARY_DIR)
ExternalProject_Add_Step(dep_gtest build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
# CMAKE_ARGS
# -DBUILD_GMOCK=OFF
# -Dgtest_force_shared_crt=ON
# -DCMAKE_POSITION_INDEPENDENT_CODE=ON
# "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local"
# BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
# INSTALL_COMMAND ""
# )
# add_debug_dep(dep_gtest)
ExternalProject_Add(dep_cereal
EXCLUDE_FROM_ALL 1
@ -137,7 +131,6 @@ ExternalProject_Add(dep_cereal
INSTALL_COMMAND ""
)
ExternalProject_Add(dep_nlopt
EXCLUDE_FROM_ALL 1
URL "https://github.com/stevengj/nlopt/archive/v2.5.0.tar.gz"
@ -158,16 +151,8 @@ ExternalProject_Add(dep_nlopt
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_nlopt BINARY_DIR)
ExternalProject_Add_Step(dep_nlopt build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
add_debug_dep(dep_nlopt)
ExternalProject_Add(dep_zlib
EXCLUDE_FROM_ALL 1
@ -185,15 +170,9 @@ ExternalProject_Add(dep_zlib
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_zlib BINARY_DIR)
ExternalProject_Add_Step(dep_zlib build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
add_debug_dep(dep_zlib)
# The following steps are unfortunately needed to remove the _static suffix on libraries
ExternalProject_Add_Step(dep_zlib fix_static
DEPENDEES install
@ -208,7 +187,6 @@ if (${DEP_DEBUG})
)
endif ()
if (${DEPS_BITS} EQUAL 32)
set(DEP_LIBCURL_TARGET "x86")
else ()
@ -247,29 +225,21 @@ find_package(Git REQUIRED)
ExternalProject_Add(dep_qhull
EXCLUDE_FROM_ALL 1
URL "https://github.com/qhull/qhull/archive/v7.2.1.tar.gz"
URL_HASH SHA256=6fc251e0b75467e00943bfb7191e986fce0e1f8f6f0251f9c6ce5a843821ea78
#URL "https://github.com/qhull/qhull/archive/v7.3.2.tar.gz"
#URL_HASH SHA256=619c8a954880d545194bc03359404ef36a1abd2dde03678089459757fd790cb0
GIT_REPOSITORY https://github.com/qhull/qhull.git
GIT_TAG 7afedcc73666e46a9f1d74632412ebecf53b1b30 # v7.3.2 plus the mac build patch
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_DEBUG_POSTFIX=d
PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/qhull-mods.patch
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_qhull BINARY_DIR)
ExternalProject_Add_Step(dep_qhull build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
add_debug_dep(dep_qhull)
if (${DEPS_BITS} EQUAL 32)
set(DEP_WXWIDGETS_TARGET "")
@ -281,49 +251,6 @@ endif ()
find_package(Git REQUIRED)
ExternalProject_Add(dep_libigl
EXCLUDE_FROM_ALL 1
URL "https://github.com/libigl/libigl/archive/v2.0.0.tar.gz"
URL_HASH SHA256=42518e6b106c7209c73435fd260ed5d34edeb254852495b4c95dce2d95401328
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DLIBIGL_BUILD_PYTHON=OFF
-DLIBIGL_BUILD_TESTS=OFF
-DLIBIGL_BUILD_TUTORIALS=OFF
-DLIBIGL_USE_STATIC_LIBRARY=OFF #${DEP_BUILD_IGL_STATIC}
-DLIBIGL_WITHOUT_COPYLEFT=OFF
-DLIBIGL_WITH_CGAL=OFF
-DLIBIGL_WITH_COMISO=OFF
-DLIBIGL_WITH_CORK=OFF
-DLIBIGL_WITH_EMBREE=OFF
-DLIBIGL_WITH_MATLAB=OFF
-DLIBIGL_WITH_MOSEK=OFF
-DLIBIGL_WITH_OPENGL=OFF
-DLIBIGL_WITH_OPENGL_GLFW=OFF
-DLIBIGL_WITH_OPENGL_GLFW_IMGUI=OFF
-DLIBIGL_WITH_PNG=OFF
-DLIBIGL_WITH_PYTHON=OFF
-DLIBIGL_WITH_TETGEN=OFF
-DLIBIGL_WITH_TRIANGLE=OFF
-DLIBIGL_WITH_XML=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_DEBUG_POSTFIX=d
PATCH_COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/igl-fixes.patch
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_libigl BINARY_DIR)
ExternalProject_Add_Step(dep_libigl build_debug
DEPENDEES build
DEPENDERS install
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()
ExternalProject_Add(dep_wxwidgets
EXCLUDE_FROM_ALL 1
GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets"
@ -346,3 +273,91 @@ if (${DEP_DEBUG})
WORKING_DIRECTORY "${SOURCE_DIR}"
)
endif ()
ExternalProject_Add(dep_blosc
EXCLUDE_FROM_ALL 1
#URL https://github.com/Blosc/c-blosc/archive/v1.17.0.zip
#URL_HASH SHA256=7463a1df566704f212263312717ab2c36b45d45cba6cd0dccebf91b2cc4b4da9
GIT_REPOSITORY https://github.com/Blosc/c-blosc.git
GIT_TAG e63775855294b50820ef44d1b157f4de1cc38d3e #v1.17.0
DEPENDS dep_zlib
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_DEBUG_POSTFIX=d
-DBUILD_SHARED=OFF
-DBUILD_STATIC=ON
-DBUILD_TESTS=OFF
-DBUILD_BENCHMARKS=OFF
-DPREFER_EXTERNAL_ZLIB=ON
-DBLOSC_IS_SUBPROJECT:BOOL=ON
-DBLOSC_INSTALL:BOOL=ON
PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_SOURCE_DIR}/blosc-mods.patch
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
add_debug_dep(dep_blosc)
ExternalProject_Add(dep_openexr
EXCLUDE_FROM_ALL 1
GIT_REPOSITORY https://github.com/openexr/openexr.git
GIT_TAG eae0e337c9f5117e78114fd05f7a415819df413a #v2.4.0
DEPENDS dep_zlib
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DBUILD_TESTING=OFF
-DPYILMBASE_ENABLE:BOOL=OFF
-DOPENEXR_VIEWERS_ENABLE:BOOL=OFF
-DOPENEXR_BUILD_UTILS:BOOL=OFF
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
INSTALL_COMMAND ""
)
add_debug_dep(dep_openexr)
ExternalProject_Add(dep_openvdb
EXCLUDE_FROM_ALL 1
#URL https://github.com/AcademySoftwareFoundation/openvdb/archive/v6.2.1.zip
#URL_HASH SHA256=dc337399dce8e1c9f21f20e97b1ce7e4933cb0a63bb3b8b734d8fcc464aa0c48
GIT_REPOSITORY https://github.com/AcademySoftwareFoundation/openvdb.git
GIT_TAG aebaf8d95be5e57fd33949281ec357db4a576c2e #v6.2.1
DEPENDS dep_blosc dep_openexr dep_tbb dep_boost
CMAKE_GENERATOR "${DEP_MSVC_GEN}"
CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_PREFIX_PATH=${DESTDIR}/usr/local
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DOPENVDB_BUILD_PYTHON_MODULE=OFF
-DUSE_BLOSC=ON
-DOPENVDB_CORE_SHARED=OFF
-DOPENVDB_CORE_STATIC=ON
-DTBB_STATIC=ON
-DOPENVDB_BUILD_VDB_PRINT=ON
BUILD_COMMAND msbuild /m /P:Configuration=Release INSTALL.vcxproj
PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_SOURCE_DIR}/openvdb-mods.patch
INSTALL_COMMAND ""
)
if (${DEP_DEBUG})
ExternalProject_Get_Property(dep_openvdb BINARY_DIR)
ExternalProject_Add_Step(dep_openvdb build_debug
DEPENDEES build
DEPENDERS install
COMMAND ${CMAKE_COMMAND} ../dep_openvdb -DOPENVDB_BUILD_VDB_PRINT=OFF
COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj
WORKING_DIRECTORY "${BINARY_DIR}"
)
endif ()

128
deps/igl-fixes.patch vendored
View File

@ -1,128 +0,0 @@
diff --git a/cmake/libigl-config.cmake.in b/cmake/libigl-config.cmake.in
index 317c745c..f9808e1e 100644
--- a/cmake/libigl-config.cmake.in
+++ b/cmake/libigl-config.cmake.in
@@ -2,28 +2,28 @@
include(${CMAKE_CURRENT_LIST_DIR}/libigl-export.cmake)
-if (TARGET igl::core)
- if (NOT TARGET Eigen3::Eigen)
- find_package(Eigen3 QUIET)
- if (NOT Eigen3_FOUND)
- # try with PkgCOnfig
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(Eigen3 QUIET IMPORTED_TARGET eigen3)
- endif()
-
- if (NOT Eigen3_FOUND)
- message(FATAL_ERROR "Could not find required dependency Eigen3")
- set(libigl_core_FOUND FALSE)
- else()
- target_link_libraries(igl::core INTERFACE PkgConfig::Eigen3)
- set(libigl_core_FOUND TRUE)
- endif()
- else()
- target_link_libraries(igl::core INTERFACE Eigen3::Eigen)
- set(libigl_core_FOUND TRUE)
- endif()
-
-endif()
+# if (TARGET igl::core)
+# if (NOT TARGET Eigen3::Eigen)
+# find_package(Eigen3 QUIET)
+# if (NOT Eigen3_FOUND)
+# # try with PkgCOnfig
+# find_package(PkgConfig REQUIRED)
+# pkg_check_modules(Eigen3 QUIET IMPORTED_TARGET eigen3)
+# endif()
+#
+# if (NOT Eigen3_FOUND)
+# message(FATAL_ERROR "Could not find required dependency Eigen3")
+# set(libigl_core_FOUND FALSE)
+# else()
+# target_link_libraries(igl::core INTERFACE PkgConfig::Eigen3)
+# set(libigl_core_FOUND TRUE)
+# endif()
+# else()
+# target_link_libraries(igl::core INTERFACE Eigen3::Eigen)
+# set(libigl_core_FOUND TRUE)
+# endif()
+#
+# endif()
check_required_components(libigl)
diff --git a/cmake/libigl.cmake b/cmake/libigl.cmake
index 4b11007a..47e6c395 100644
--- a/cmake/libigl.cmake
+++ b/cmake/libigl.cmake
@@ -445,6 +445,7 @@ function(install_dir_files dir_name)
if(NOT LIBIGL_USE_STATIC_LIBRARY)
file(GLOB public_sources
${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.c
)
endif()
list(APPEND files_to_install ${public_sources})
diff --git a/include/igl/AABB.cpp b/include/igl/AABB.cpp
index 09537335..92e90cb7 100644
--- a/include/igl/AABB.cpp
+++ b/include/igl/AABB.cpp
@@ -1071,5 +1071,11 @@ template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::init<Eigen
// generated by autoexplicit.sh
template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::init<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
template double igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::squared_distance<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, double, int&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&) const;
+template float igl::AABB<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, 3>::squared_distance<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > >(Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::Matrix<float, 1, 3, 1, 1, 3> const&, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> >&) const;
template bool igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::intersect_ray<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, igl::Hit&) const;
+template bool igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::intersect_ray<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, std::vector<igl::Hit>&) const;
+
+template void igl::AABB<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, 3>::init<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > >(Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&);
+
+template bool igl::AABB<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, 3>::intersect_ray<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > >(Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::Matrix<float, 1, 3, 1, 1, 3> const&, Eigen::Matrix<float, 1, 3, 1, 1, 3> const&, std::vector<igl::Hit, std::allocator<igl::Hit> >&) const;
#endif
diff --git a/include/igl/barycenter.cpp b/include/igl/barycenter.cpp
index 065f82aa..ec2d96cd 100644
--- a/include/igl/barycenter.cpp
+++ b/include/igl/barycenter.cpp
@@ -54,4 +54,6 @@ template void igl::barycenter<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::M
template void igl::barycenter<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&);
template void igl::barycenter<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
template void igl::barycenter<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&);
+
+template void igl::barycenter<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, Eigen::Matrix<float, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> >&);
#endif
diff --git a/include/igl/point_simplex_squared_distance.cpp b/include/igl/point_simplex_squared_distance.cpp
index 2b98bd28..c66d9ae1 100644
--- a/include/igl/point_simplex_squared_distance.cpp
+++ b/include/igl/point_simplex_squared_distance.cpp
@@ -178,4 +178,6 @@ template void igl::point_simplex_squared_distance<3, Eigen::Matrix<double, 1, 3,
template void igl::point_simplex_squared_distance<3, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>::Index, double&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 1, 1, 3> >&);
template void igl::point_simplex_squared_distance<2, Eigen::Matrix<double, 1, 2, 1, 1, 2>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>::Index, double&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> >&);
template void igl::point_simplex_squared_distance<2, Eigen::Matrix<double, 1, 2, 1, 1, 2>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>::Index, double&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 1, 1, 2> >&);
+
+template void igl::point_simplex_squared_distance<3, Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, float, Eigen::Matrix<float, 1, 3, 1, 1, 3> >(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >::Index, float&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> >&);
#endif
diff --git a/include/igl/ray_box_intersect.cpp b/include/igl/ray_box_intersect.cpp
index 4a88b89e..b547f8f8 100644
--- a/include/igl/ray_box_intersect.cpp
+++ b/include/igl/ray_box_intersect.cpp
@@ -147,4 +147,6 @@ IGL_INLINE bool igl::ray_box_intersect(
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
template bool igl::ray_box_intersect<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, double>(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::AlignedBox<double, 3> const&, double const&, double const&, double&, double&);
+
+template bool igl::ray_box_intersect<Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3>, float>(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::AlignedBox<float, 3> const&, float const&, float const&, float&, float&);
#endif
diff --git a/include/igl/ray_mesh_intersect.cpp b/include/igl/ray_mesh_intersect.cpp
index 9a70a22b..4233e722 100644
--- a/include/igl/ray_mesh_intersect.cpp
+++ b/include/igl/ray_mesh_intersect.cpp
@@ -83,4 +83,7 @@ IGL_INLINE bool igl::ray_mesh_intersect(
template bool igl::ray_mesh_intersect<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<igl::Hit, std::allocator<igl::Hit> >&);
template bool igl::ray_mesh_intersect<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::Hit&);
template bool igl::ray_mesh_intersect<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Block<Eigen::Matrix<int, -1, -1, 0, -1, -1> const, 1, -1, false> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<int, -1, -1, 0, -1, -1> const, 1, -1, false> > const&, igl::Hit&);
+template bool igl::ray_mesh_intersect<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Block<Eigen::Matrix<int, -1, -1, 0, -1, -1> const, 1, -1, false> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<int, -1, -1, 0, -1, -1> const, 1, -1, false> > const&, std::vector<igl::Hit, std::allocator<igl::Hit> >&);
+
+template bool igl::ray_mesh_intersect<Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> >, Eigen::Block<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > const, 1, -1, true> >(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<float, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > > const&, Eigen::MatrixBase<Eigen::Block<Eigen::Map<Eigen::Matrix<int, -1, -1, 3, -1, -1> const, 0, Eigen::Stride<0, 0> > const, 1, -1, true> > const&, std::vector<igl::Hit, std::allocator<igl::Hit> >&);
#endif

1783
deps/openvdb-mods.patch vendored Normal file

File diff suppressed because it is too large Load Diff

144
deps/qhull-mods.patch vendored
View File

@ -1,121 +1,49 @@
From a31ae4781a4afa60e21c70e5b4ae784bcd447c8a Mon Sep 17 00:00:00 2001
From 7f55a56b3d112f4dffbf21b1722f400c64bf03b1 Mon Sep 17 00:00:00 2001
From: tamasmeszaros <meszaros.q@gmail.com>
Date: Thu, 6 Jun 2019 15:41:43 +0200
Subject: [PATCH] prusa-slicer changes
Date: Mon, 21 Oct 2019 16:52:04 +0200
Subject: [PATCH] Fix the build on macOS
---
CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++---
Config.cmake.in | 2 ++
src/libqhull_r/qhull_r-exports.def | 2 ++
src/libqhull_r/user_r.h | 2 +-
4 files changed, 46 insertions(+), 4 deletions(-)
create mode 100644 Config.cmake.in
CMakeLists.txt | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59dff41..20c2ec5 100644
index 07d3da2..14df8e9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,7 +61,7 @@
# $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
@@ -626,18 +626,18 @@ install(TARGETS ${qhull_TARGETS_INSTALL} EXPORT QhullTargets
include(CMakePackageConfigHelpers)
project(qhull)
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.0)
write_basic_package_version_file(
- "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/QhullExport/QhullConfigVersion.cmake"
VERSION ${qhull_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Define qhull_VERSION in CMakeLists.txt, Makefile, qhull-exports.def, qhull_p-exports.def, qhull_r-exports.def, qhull-warn.pri
set(qhull_VERSION2 "2015.2 2016/01/18") # not used, See global.c, global_r.c, rbox.c, rbox_r.c
@@ -610,10 +610,48 @@ add_test(NAME user_eg3
# Define install
# ---------------------------------------
export(EXPORT QhullTargets
- FILE "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullTargets.cmake"
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/QhullExport/QhullTargets.cmake"
NAMESPACE Qhull::
)
-install(TARGETS ${qhull_TARGETS_INSTALL}
+install(TARGETS ${qhull_TARGETS_INSTALL} EXPORT QhullTargets
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
- ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+ ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+ INCLUDES DESTINATION include)
+
+include(CMakePackageConfigHelpers)
+
+write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake"
+ VERSION ${qhull_VERSION}
+ COMPATIBILITY AnyNewerVersion
+)
+
+export(EXPORT QhullTargets
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullTargets.cmake"
+ NAMESPACE Qhull::
+)
+
+configure_file(Config.cmake.in
+ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake"
+ @ONLY
+)
+
+set(ConfigPackageLocation lib/cmake/Qhull)
+install(EXPORT QhullTargets
+ FILE
+ QhullTargets.cmake
+ NAMESPACE
+ Qhull::
+ DESTINATION
+ ${ConfigPackageLocation}
+)
+install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake"
+ DESTINATION
+ ${ConfigPackageLocation}
+ COMPONENT
+ Devel
+)
configure_file(${PROJECT_SOURCE_DIR}/build/config.cmake.in
- "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/QhullExport/QhullConfig.cmake"
@ONLY
)
install(FILES ${libqhull_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/libqhull)
install(FILES ${libqhull_DOC} DESTINATION ${INCLUDE_INSTALL_DIR}/libqhull)
diff --git a/Config.cmake.in b/Config.cmake.in
new file mode 100644
index 0000000..bc92bfe
--- /dev/null
+++ b/Config.cmake.in
@@ -0,0 +1,2 @@
+include("${CMAKE_CURRENT_LIST_DIR}/QhullTargets.cmake")
+
diff --git a/src/libqhull_r/qhull_r-exports.def b/src/libqhull_r/qhull_r-exports.def
index 325d57c..72f6ad0 100644
--- a/src/libqhull_r/qhull_r-exports.def
+++ b/src/libqhull_r/qhull_r-exports.def
@@ -185,6 +185,7 @@ qh_memsetup
qh_memsize
qh_memstatistics
qh_memtotal
+qh_memcheck
qh_merge_degenredundant
qh_merge_nonconvex
qh_mergecycle
@@ -372,6 +373,7 @@ qh_settruncate
qh_setunique
qh_setvoronoi_all
qh_setzero
+qh_setendpointer
qh_sharpnewfacets
qh_skipfacet
qh_skipfilename
diff --git a/src/libqhull_r/user_r.h b/src/libqhull_r/user_r.h
index fc105b9..7cca65a 100644
--- a/src/libqhull_r/user_r.h
+++ b/src/libqhull_r/user_r.h
@@ -139,7 +139,7 @@ Code flags --
REALfloat = 1 all numbers are 'float' type
= 0 all numbers are 'double' type
*/
-#define REALfloat 0
+#define REALfloat 1
#if (REALfloat == 1)
#define realT float
@@ -652,8 +652,8 @@ install(EXPORT QhullTargets
)
install(
FILES
- "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfig.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/Qhull/QhullConfigVersion.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/QhullExport/QhullConfig.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/QhullExport/QhullConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
--
2.16.2.windows.1
2.17.1

View File

@ -1,6 +1,6 @@
# Dependency report for PrusaSlicer
## Possible dynamic linking on Linux
* zlib: This should not be even mentioned in our cmake scripts but due to a bug in the system libraries of gtk it has to be linked to PrusaSlicer.
* zlib: Strict dependency required from the system, linked dynamically. Many other libs depend on zlib.
* wxWidgets: searches for wx-3.1 by default, but with cmake option `SLIC3R_WX_STABLE=ON` it will use wx-3.0 bundled with most distros.
* libcurl
* tbb
@ -10,13 +10,13 @@
* expat
* openssl
* nlopt
* gtest
* openvdb: This library depends on other libs, namely boost, zlib, openexr, blosc (not strictly), etc...
## External libraries in source tree
* ad-mesh: Lots of customization, have to be bundled in the source tree.
* avrdude: Like ad-mesh, many customization, need to be in the source tree.
* clipper: An important library we have to have full control over it. We also have some slicer specific modifications.
* glu-libtess: This is an extract of the mesa/glu library not oficially available as a package.
* glu-libtess: This is an extract of the mesa/glu library not officially available as a package.
* imgui: no packages for debian, author suggests using in the source tree
* miniz: No packages, author suggests using in the source tree
* qhull: libqhull-dev does not contain libqhullcpp => link errors. Until it is fixed, we will use the builtin version. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=925540
@ -29,5 +29,6 @@
* igl
* nanosvg
* agg
* catch2: Only Arch has packages for catch2, other distros at most catch (v1.x). Being strictly header only, we bundle this in the source tree. Used for the unit-test suites.

View File

@ -2,7 +2,7 @@
# Building Slic3r++ on UNIX/Linux
Slic3r++ uses the CMake build system and requires several dependencies.
The dependencies can be listed in `deps/deps-linux.cmake`, although they don't necessarily need to be as recent
The dependencies can be listed in `deps/deps-linux.cmake` and `deps/deps-unix-common.cmake`, although they don't necessarily need to be as recent
as the versions listed - generally versions available on conservative Linux distros such as Debian stable or CentOS should suffice.
Perl is not required any more.

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="export_x5F_gcode">
<g>
<path fill="#808080" d="M5.02,7.17H9v3.08c0,2.6-1.23,3.72-4.05,3.72S1,12.85,1,10.29V5.54C1,3.12,2.09,2,4.95,2S9,3,9,5.54H6.88
c0-1.11-0.28-1.66-1.92-1.66c-1.54,0-1.83,0.69-1.83,1.77v4.65c0,1.12,0.29,1.77,1.83,1.77c1.54,0,2.08-0.65,2.08-1.82V9.09H5.02
V7.17z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 656 B

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,70 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" width="180.5mm" height="180.6mm" viewBox="0 0 511.7 512">
<title>MINI_bed_texture</title>
<path d="M510.6,510.9" transform="translate(0.4 0.4)" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<path d="M.4,510.9" transform="translate(0.4 0.4)" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="511" y1="511.3" x2="511" y2="0.8" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<path d="M.4.4" transform="translate(0.4 0.4)" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<path d="M510.6.4" transform="translate(0.4 0.4)" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="0.8" y1="0.8" x2="0.8" y2="511.3" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="0.8" y1="511.3" x2="0.8" y2="0.8" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="511" y1="0.8" x2="511" y2="511.3" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="0.8" y1="511.3" x2="511" y2="511.3" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<line x1="0.8" y1="0.8" x2="511" y2="0.8" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-width: 1.5px"/>
<g>
<g>
<line x1="0.8" y1="383.6" x2="2.9" y2="383.6" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="5" y1="383.6" x2="6.6" y2="383.6" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.5694814920425415,2.1355555057525635"/>
<line x1="7.7" y1="383.6" x2="507.8" y2="383.6" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.271111011505127,2.1355555057525635,0.5694814920425415,2.1355555057525635"/>
<line x1="508.9" y1="383.6" x2="511" y2="383.6" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
<g>
<line x1="0.8" y1="256" x2="2.9" y2="256" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="5" y1="256" x2="6.6" y2="256" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.5694814920425415,2.1355555057525635"/>
<line x1="7.7" y1="256" x2="507.8" y2="256" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.271111011505127,2.1355555057525635,0.5694814920425415,2.1355555057525635"/>
<line x1="508.9" y1="256" x2="511" y2="256" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
<g>
<line x1="511" y1="128.4" x2="508.9" y2="128.4" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="506.7" y1="128.4" x2="505.1" y2="128.4" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.5694814920425415,2.1355555057525635"/>
<line x1="504" y1="128.4" x2="3.9" y2="128.4" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.271111011505127,2.1355555057525635,0.5694814920425415,2.1355555057525635"/>
<line x1="2.9" y1="128.4" x2="0.8" y2="128.4" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
<g>
<line x1="128.3" y1="511.3" x2="128.3" y2="509.1" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="128.3" y1="507" x2="128.3" y2="505.4" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.569789707660675,2.1367111206054688"/>
<line x1="128.3" y1="504.3" x2="128.3" y2="3.9" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.2734222412109375,2.1367111206054688,0.569789707660675,2.1367111206054688"/>
<line x1="128.3" y1="2.9" x2="128.3" y2="0.8" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
<g>
<line x1="255.9" y1="0.8" x2="255.9" y2="2.9" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="255.9" y1="5" x2="255.9" y2="6.7" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.569789707660675,2.1367111206054688"/>
<line x1="255.9" y1="7.7" x2="255.9" y2="508.1" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.2734222412109375,2.1367111206054688,0.569789707660675,2.1367111206054688"/>
<line x1="255.9" y1="509.1" x2="255.9" y2="511.3" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
<g>
<line x1="383.4" y1="484.8" x2="383.4" y2="482.6" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
<line x1="383.4" y1="480.5" x2="383.4" y2="478.9" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 0.5708136558532715,2.1405510902404785"/>
<line x1="383.4" y1="477.8" x2="383.4" y2="3.9" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round;stroke-dasharray: 4.281102180480957,2.1405510902404785,0.5708136558532715,2.1405510902404785"/>
<line x1="383.4" y1="2.9" x2="383.4" y2="0.8" style="fill: none;stroke: #fff;stroke-linecap: round;stroke-linejoin: round"/>
</g>
</g>
<g>
<path d="M277.3,489.1c4.6,0,7.4,2.8,7.4,8.1s-2.9,8.1-7.4,8.1-7.4-2.9-7.4-8.1S272.9,489.1,277.3,489.1Zm3.7,8.1c0-3.8-1.5-5.7-3.7-5.7s-3.8,1.9-3.8,5.7,1.3,5.6,3.8,5.6S281,500.9,281,497.2Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M293.1,499h-2.5v6h-3.3V489.3h6.1a7.3,7.3,0,0,1,3.2.6,4.1,4.1,0,0,1,2.6,4,4.4,4.4,0,0,1-3.1,4.3h0l3.5,6.8H296Zm-.1-2.4c1.5,0,2.7-.7,2.7-2.5a2.4,2.4,0,0,0-2.7-2.5h-2.4v5Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M302,489.3h3.4V505H302Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M311.6,497.2c0,4,1.4,5.6,3.8,5.6s3.4-1.3,3.6-3.5V499h-3.7v-2.4h6.8V505h-2.6v-2.2h-.1a5,5,0,0,1-4.6,2.5c-4.4,0-6.8-3.1-6.8-7.9s3-8.3,7.4-8.3,6.1,1.7,6.4,4.9h-3.4a2.8,2.8,0,0,0-3-2.5C313,491.5,311.6,493.5,311.6,497.2Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M325.1,489.3h3.4V505h-3.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M331.7,489.3h3.7l5,8.5a16.8,16.8,0,0,1,1.2,2.3h0V489.3h3.1V505h-3.5l-5.3-8.7a12.8,12.8,0,0,1-1.1-2.4h-.1V505h-3Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M356.8,501.5H351l-1.1,3.5h-3.2l5.4-15.7h3.8l5.6,15.7h-3.6Zm-3.5-7.1-1.5,4.6H356l-1.5-4.5c-.4-1.4-.6-2.3-.6-2.3h0A15.3,15.3,0,0,1,353.3,494.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M363.4,489.3h3.4v13h6.8V505H363.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M384,499.6V505h-3.4V489.3h5.5c3.4,0,6,1.4,6,5s-2.8,5.3-6.3,5.3Zm2-2.5a2.5,2.5,0,0,0,2.8-2.7c0-1.9-1.1-2.7-2.8-2.7h-2v5.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M400.1,499h-2.4v6h-3.4V489.3h6.1a7.3,7.3,0,0,1,3.2.6,3.9,3.9,0,0,1,2.6,4,4.5,4.5,0,0,1-3,4.3h0l3.5,6.8H403Zm-.1-2.4c1.5,0,2.8-.7,2.8-2.5a2.4,2.4,0,0,0-2.7-2.5h-2.4v5Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M408.7,489.3H412v9.1a5.6,5.6,0,0,0,.6,3.2,3.6,3.6,0,0,0,5,0c.6-.8.5-2.1.5-3.2v-9.1h3.3v10.2c0,3.9-2.5,5.8-6.4,5.8s-6.3-1.8-6.3-5.8Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M432.4,493.5a2,2,0,0,0-2.3-2c-1.5,0-2.4.8-2.4,1.9s.6,1.7,2.1,1.9l2.4.5c2.8.5,4.1,2,4.1,4.3s-2.3,5.2-6.3,5.2-6.1-1.9-6.2-4.8h3.5a2.5,2.5,0,0,0,2.8,2.3c1.9,0,2.7-.9,2.7-2.1s-.5-1.7-2.2-2l-2.3-.4c-2.4-.5-4.1-1.9-4.1-4.4s2.2-4.8,5.9-4.8,5.7,2,5.8,4.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M447.4,501.5h-5.7l-1.2,3.5h-3.2l5.5-15.7h3.7l5.6,15.7h-3.5Zm-3.5-7.1-1.4,4.6h4.1l-1.4-4.5a11.3,11.3,0,0,1-.6-2.3h-.1A15.3,15.3,0,0,1,443.9,494.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M458.7,489.3h4.9l2.8,8.4a15.7,15.7,0,0,1,.7,2.3h0l.7-2.3,2.8-8.4h4.9V505h-3.3V492.7h-.1a26.9,26.9,0,0,1-1,3.3l-2.9,9h-2.5l-2.9-9a26.9,26.9,0,0,1-1-3.3h0V505h-3.1Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M478.6,489.3H482V505h-3.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M485.2,489.3h3.7l5,8.5a16.8,16.8,0,0,1,1.2,2.3h0V489.3h3.1V505h-3.5l-5.3-8.7a12.8,12.8,0,0,1-1.1-2.4h-.1V505h-3Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
<path d="M501.3,489.3h3.4V505h-3.4Z" transform="translate(0.4 0.4)" style="fill: #fff"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="change_x5F_extruder_2_">
<path fill="#ED6B21" d="M14.65,11.92c0.19-0.19,0.19-0.51,0-0.71L11.92,8.5c-0.19-0.19-0.35-0.13-0.35,0.15v1.29
c0,0.27-0.22,0.5-0.5,0.5H7.5c-0.28,0-0.5,0.22-0.5,0.5v1.29c0,0.27,0.22,0.5,0.5,0.5h3.57c0.28,0,0.5,0.22,0.5,0.5v1.29
c0,0.27,0.16,0.34,0.35,0.15L14.65,11.92z"/>
<path fill="#ED6B21" d="M1.35,11.92c-0.19-0.19-0.19-0.51,0-0.71L4.08,8.5C4.27,8.3,4.43,8.37,4.43,8.64v1.29
c0,0.27,0.23,0.5,0.5,0.5H8.5c0.27,0,0.5,0.22,0.5,0.5v1.29c0,0.27-0.23,0.5-0.5,0.5H4.93c-0.27,0-0.5,0.22-0.5,0.5v1.29
c0,0.27-0.16,0.34-0.35,0.15L1.35,11.92z"/>
<path fill="#808080" d="M14,2l0,4h-3c-0.55,0-1,0.45-1,1v0.47L8,8.8L6,7.46V7c0-0.55-0.45-1-1-1L2,6l0-4H14 M14,1H2
C1.45,1,1,1.45,1,2v4c0,0.55,0.45,1,1,1h3v1l2.45,1.63C7.61,9.74,7.81,9.8,8,9.8c0.19,0,0.39-0.06,0.55-0.17L11,8V7h3
c0.55,0,1-0.45,1-1V2C15,1.45,14.55,1,14,1L14,1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_plus">
<g>
<polygon fill="#ED6B21" points="8,1 2,5 2,7 2,11 8,15 14,11 14,7 14,5 "/>
</g>
<g id="plus_1_">
<line fill="none" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-miterlimit="10" x1="8" y1="5" x2="8" y2="11"/>
<line fill="none" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-miterlimit="10" x1="11" y1="8" x2="5" y2="8"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 759 B

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_plus">
<g>
<polygon fill="#ED6B21" points="8,1 2,5 2,7 2,11 8,15 14,11 14,7 14,5 "/>
</g>
<g id="plus_1_">
<line fill="none" stroke="#FFFFFF" stroke-width="2.126" stroke-linecap="round" stroke-miterlimit="10" x1="8" y1="5" x2="8" y2="11"/>
<line fill="none" stroke="#FFFFFF" stroke-width="2.126" stroke-linecap="round" stroke-miterlimit="10" x1="11" y1="8" x2="5" y2="8"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 763 B

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_plus">
<g>
<path fill="#808080" d="M8,1.85l5.29,3.53V7v3.62L8,14.15l-5.29-3.53V7V5.38L8,1.85 M8,1L2,5v2v4l6,4l6-4V7V5L8,1L8,1z"/>
</g>
<g id="plus_1_">
<g>
<path fill="#ED6B21" d="M8,11.71c-0.39,0-0.71-0.32-0.71-0.71V5c0-0.39,0.32-0.71,0.71-0.71S8.71,4.61,8.71,5v6
C8.71,11.39,8.39,11.71,8,11.71z"/>
</g>
<g>
<path fill="#ED6B21" d="M11,8.71H5C4.61,8.71,4.29,8.39,4.29,8S4.61,7.29,5,7.29h6c0.39,0,0.71,0.32,0.71,0.71
S11.39,8.71,11,8.71z"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 844 B

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_X">
<g>
<polygon fill="#808080" points="8,1 2,5 2,7 2,11 8,15 14,11 14,7 14,5 "/>
</g>
<g id="plus_2_">
<line fill="none" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-miterlimit="10" x1="10.12" y1="5.88" x2="5.88" y2="10.12"/>
<line fill="none" stroke="#FFFFFF" stroke-width="1.5" stroke-linecap="round" stroke-miterlimit="10" x1="10.12" y1="10.12" x2="5.88" y2="5.88"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 782 B

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_X">
<g>
<polygon fill="#808080" points="8,1 2,5 2,7 2,11 8,15 14,11 14,7 14,5 "/>
</g>
<g id="plus_2_">
<line fill="none" stroke="#FFFFFF" stroke-width="2.126" stroke-linecap="round" stroke-miterlimit="10" x1="10.12" y1="5.88" x2="5.88" y2="10.12"/>
<line fill="none" stroke="#FFFFFF" stroke-width="2.126" stroke-linecap="round" stroke-miterlimit="10" x1="10.12" y1="10.12" x2="5.88" y2="5.88"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 786 B

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="edit_x5F_Gcode">
<g>
<path fill="#808080" d="M8,1.85l5.29,3.53V7v3.62L8,14.15l-5.29-3.53V7V5.38L8,1.85 M8,1L2,5v2v4l6,4l6-4V7V5L8,1L8,1z"/>
</g>
<g>
<path fill="#ED6B21" d="M7.97,7.47h2.65v2.05c0,1.73-0.82,2.48-2.69,2.48S5.3,11.25,5.3,9.55V6.39c0-1.61,0.73-2.36,2.63-2.36
s2.69,0.67,2.69,2.36H9.21c0-0.74-0.18-1.11-1.28-1.11c-1.02,0-1.22,0.46-1.22,1.18v3.09c0,0.75,0.19,1.18,1.22,1.18
c1.02,0,1.38-0.43,1.38-1.21V8.75H7.97V7.47z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 808 B

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="edit_x5F_uni">
<path fill="#808080" d="M8,1.85l5.29,3.53V7v3.62L8,14.15l-5.29-3.53V7V5.38L8,1.85 M8,1L2,5v2v4l6,4l6-4V7V5L8,1L8,1z"/>
<path fill="#ED6B21" d="M11.87,7.36l-0.43-0.22c-0.07-0.04-0.16-0.13-0.18-0.21l-0.2-0.48c-0.04-0.07-0.04-0.2-0.02-0.28l0.15-0.46
c0.03-0.08,0-0.19-0.06-0.25l-0.6-0.6c-0.06-0.06-0.17-0.08-0.25-0.06L9.83,4.97c-0.08,0.03-0.2,0.02-0.28-0.02l-0.48-0.2
C8.99,4.72,8.89,4.64,8.85,4.57L8.64,4.13C8.6,4.06,8.5,4,8.42,4H7.58C7.5,4,7.4,4.06,7.36,4.13L7.15,4.57
C7.11,4.64,7.01,4.72,6.94,4.75l-0.48,0.2c-0.07,0.04-0.2,0.04-0.28,0.02L5.72,4.81c-0.08-0.03-0.19,0-0.25,0.06l-0.6,0.6
C4.82,5.53,4.79,5.64,4.81,5.72l0.15,0.46c0.03,0.08,0.02,0.2-0.02,0.28l-0.2,0.48C4.72,7.01,4.64,7.11,4.57,7.15L4.13,7.36
C4.06,7.4,4,7.5,4,7.58v0.84C4,8.5,4.06,8.6,4.13,8.64l0.43,0.22c0.07,0.04,0.16,0.13,0.18,0.21l0.2,0.48
c0.04,0.07,0.04,0.2,0.02,0.28l-0.15,0.46c-0.03,0.08,0,0.19,0.06,0.25l0.6,0.6c0.06,0.06,0.17,0.08,0.25,0.06l0.46-0.15
c0.08-0.03,0.2-0.02,0.28,0.02l0.48,0.2c0.08,0.03,0.17,0.11,0.21,0.18l0.22,0.43C7.4,11.94,7.5,12,7.58,12h0.84
c0.08,0,0.18-0.06,0.22-0.13l0.22-0.43c0.04-0.07,0.13-0.16,0.21-0.18l0.48-0.2c0.07-0.04,0.2-0.04,0.28-0.02l0.46,0.15
c0.08,0.03,0.19,0,0.25-0.06l0.6-0.6c0.06-0.06,0.08-0.17,0.06-0.25l-0.15-0.46c-0.03-0.08-0.02-0.2,0.02-0.28l0.2-0.48
c0.03-0.08,0.11-0.17,0.18-0.21l0.43-0.22C11.94,8.6,12,8.5,12,8.42V7.58C12,7.5,11.94,7.4,11.87,7.36z M8,10.29
c-1.26,0-2.29-1.03-2.29-2.29c0-1.26,1.03-2.29,2.29-2.29S10.29,6.74,10.29,8C10.29,9.26,9.26,10.29,8,10.29z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="pause_x5F_print">
<g>
<path fill="#808080" d="M8,1.85l5.29,3.53V7v3.62L8,14.15l-5.29-3.53V7V5.38L8,1.85 M8,1L2,5v2v4l6,4l6-4V7V5L8,1L8,1z"/>
</g>
<g>
<path fill="#ED6B21" d="M6,11.71c-0.39,0-0.71-0.32-0.71-0.71V5c0-0.39,0.32-0.71,0.71-0.71S6.71,4.61,6.71,5v6
C6.71,11.39,6.39,11.71,6,11.71z"/>
</g>
<g>
<path fill="#ED6B21" d="M10,11.71c-0.39,0-0.71-0.32-0.71-0.71V5c0-0.39,0.32-0.71,0.71-0.71S10.71,4.61,10.71,5v6
C10.71,11.39,10.39,11.71,10,11.71z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_plus">
<g>
<polygon fill="#ED6B21" points="2,8 2,11 8,15 14,11 14,8 "/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 446 B

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="hex_x5F_plus">
<g>
<polygon fill="#ED6B21" points="8,1 2,5 2,7 2,8 14,8 14,7 14,5 "/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 454 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,11 @@
src/slic3r/GUI/AboutDialog.cpp
src/slic3r/GUI/AppConfig.cpp
src/slic3r/GUI/BackgroundSlicingProcess.cpp
src/slic3r/GUI/BedShapeDialog.cpp
src/slic3r/GUI/BedShapeDialog.hpp
src/slic3r/GUI/BonjourDialog.cpp
src/slic3r/GUI/ButtonsDescription.cpp
src/slic3r/GUI/ConfigManipulation.cpp
src/slic3r/GUI/ConfigSnapshotDialog.cpp
src/slic3r/GUI/ConfigWizard.cpp
src/slic3r/GUI/Field.cpp
@ -26,6 +28,7 @@ src/slic3r/GUI/GUI_ObjectSettings.cpp
src/slic3r/GUI/GUI_Preview.cpp
src/slic3r/GUI/KBShortcutsDialog.cpp
src/slic3r/GUI/MainFrame.cpp
src/slic3r/GUI/Mouse3DController.cpp
src/slic3r/GUI/MsgDialog.cpp
src/slic3r/GUI/OptionsGroup.cpp
src/slic3r/GUI/Plater.cpp
@ -43,12 +46,18 @@ src/slic3r/GUI/Tab.hpp
src/slic3r/GUI/UpdateDialogs.cpp
src/slic3r/GUI/WipeTowerDialog.cpp
src/slic3r/GUI/wxExtensions.cpp
src/slic3r/GUI/ExtruderSequenceDialog.cpp
src/slic3r/Utils/Duet.cpp
src/slic3r/Utils/OctoPrint.cpp
src/slic3r/Utils/FlashAir.cpp
src/slic3r/Utils/PresetUpdater.cpp
src/slic3r/Utils/FixModelByWin10.cpp
src/libslic3r/SLA/SLAPad.cpp
src/libslic3r/Zipper.cpp
src/libslic3r/SLA/SLASupportTree.cpp
src/libslic3r/GCode.cpp
src/libslic3r/ExtrusionEntity.cpp
src/libslic3r/Format/3mf.cpp
src/libslic3r/Format/AMF.cpp
src/libslic3r/Print.cpp
src/libslic3r/SLAPrint.cpp
src/libslic3r/PrintBase.cpp

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,12 @@
min_slic3r_version = 2.2.0-alpha0
1.1.0 Filament aliases, Creality profiles and other goodies for PrusaSlicer 2.2.0-alpha0
min_slic3r_version = 2.1.1-beta0
1.0.6 Added Prusa MINI profiles
min_slic3r_version = 2.1.0-alpha0
1.0.5 Added SLA materials
1.0.4 Updated firmware version and 0.25mm nozzle profiles
1.0.3 Added filament profiles
1.0.2 Added SLA materials
1.0.1 Updated MK3 firmware version check to 3.8.0, new soluble support profiles for 0.6mm nozzle diameter MMU2S printers.
1.0.0 Updated end G-code for the MMU2 profiles to lift the extruder at the end of print. Wipe tower bridging distance was made smaller for soluble supports.
1.0.0-beta1 Updated color for the ASA filaments to differ from the other filaments. Single extruder printers now have no extruder color assigned, obects and toolpaths will be colored with the color of the active filament.
@ -7,6 +15,8 @@ min_slic3r_version = 2.1.0-alpha0
1.0.0-alpha1 Added Prusament ASA profile
1.0.0-alpha0 Filament specific retract for PET and similar copolymers, and for FLEX
min_slic3r_version = 1.42.0-alpha6
0.8.7 Updated firmware version
0.8.6 Updated firmware version for MK2.5/S and MK3/S
0.8.5 Updated SL1 printer and material settings
0.8.4 Added Prusament ASA profile
0.8.3 FW version and SL1 materials update
@ -31,6 +41,8 @@ min_slic3r_version = 1.42.0-alpha
0.4.0-alpha3 Update of SLA profiles
0.4.0-alpha2 First SLA profiles
min_slic3r_version = 1.41.3-alpha
0.4.10 Updated firmware version
0.4.9 Updated firmware version for MK2.5/S and MK3/S
0.4.8 MK2.5/3/S FW update
0.4.7 MK2/S/MMU FW update
0.4.6 Updated firmware versions for MK2.5/S and MK3/S
@ -41,6 +53,8 @@ min_slic3r_version = 1.41.3-alpha
0.4.1 New MK2.5S and MK3S FW versions
0.4.0 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt
min_slic3r_version = 1.41.1
0.3.10 Updated firmware version
0.3.9 Updated firmware version for MK2.5/S and MK3/S
0.3.8 MK2.5/3/S FW update
0.3.7 MK2/S/MMU FW update
0.3.6 Updated firmware versions for MK2.5 and MK3
@ -77,6 +91,8 @@ min_slic3r_version = 1.41.0-alpha
0.2.0-alpha1 added initial profiles for the i3 MK3 Multi Material Upgrade 2.0
0.2.0-alpha moved machine limits from the start G-code to the new print profile parameters
min_slic3r_version = 1.40.0
0.1.18 Updated firmware version
0.1.17 Updated firmware version for MK2.5/S and MK3/S
0.1.16 MK2.5/3/S FW update
0.1.15 MK2/S/MMU FW update
0.1.14 Updated firmware versions for MK2.5 and MK3

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
# See src/slic3r/GUI/Mouse3DController.cpp for the list of devices
# Logitech vendor devices
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c603", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c605", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c606", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c621", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c623", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c625", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c626", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c627", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c628", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c629", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62b", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62e", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c62f", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c631", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c632", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c633", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c635", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c636", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c640", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c652", MODE="0666"
# 3D Connexion vendor devices
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c603", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c605", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c606", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c621", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c623", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c625", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c626", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c627", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c628", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c629", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62b", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62e", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c62f", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c631", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c632", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c633", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c635", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c636", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c640", MODE="0666"
KERNEL=="hidraw*", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c652", MODE="0666"

View File

@ -1,2 +1,2 @@
add_subdirectory(slabasebed)
add_subdirectory(slasupporttree)
add_subdirectory(openvdb)

View File

@ -0,0 +1,2 @@
add_executable(openvdb_example openvdb_example.cpp)
target_link_libraries(openvdb_example libslic3r)

View File

@ -0,0 +1,37 @@
#include <openvdb/openvdb.h>
#include <iostream>
int main()
{
// Initialize the OpenVDB library. This must be called at least
// once per program and may safely be called multiple times.
openvdb::initialize();
// Create an empty floating-point grid with background value 0.
openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
std::cout << "Testing random access:" << std::endl;
// Get an accessor for coordinate-based access to voxels.
openvdb::FloatGrid::Accessor accessor = grid->getAccessor();
// Define a coordinate with large signed indices.
openvdb::Coord xyz(1000, -200000000, 30000000);
// Set the voxel value at (1000, -200000000, 30000000) to 1.
accessor.setValue(xyz, 1.0);
// Verify that the voxel value at (1000, -200000000, 30000000) is 1.
std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl;
// Reset the coordinates to those of a different voxel.
xyz.reset(1000, 200000000, -30000000);
// Verify that the voxel value at (1000, 200000000, -30000000) is
// the background value, 0.
std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl;
// Set the voxel value at (1000, 200000000, -30000000) to 2.
accessor.setValue(xyz, 2.0);
// Set the voxels at the two extremes of the available coordinate space.
// For 32-bit signed coordinates these are (-2147483648, -2147483648, -2147483648)
// and (2147483647, 2147483647, 2147483647).
accessor.setValue(openvdb::Coord::min(), 3.0f);
accessor.setValue(openvdb::Coord::max(), 4.0f);
std::cout << "Testing sequential access:" << std::endl;
// Print all active ("on") voxels by means of an iterator.
for (openvdb::FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) {
std::cout << "Grid" << iter.getCoord() << " = " << *iter << std::endl;
}
}

View File

@ -1,2 +0,0 @@
add_executable(slabasebed EXCLUDE_FROM_ALL slabasebed.cpp)
target_link_libraries(slabasebed libslic3r ${Boost_LIBRARIES} ${TBB_LIBRARIES} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS})

View File

@ -1,85 +0,0 @@
#include <iostream>
#include <fstream>
#include <string>
#include <libslic3r/libslic3r.h>
#include <libslic3r/TriangleMesh.hpp>
#include <libslic3r/Tesselate.hpp>
#include <libslic3r/ClipperUtils.hpp>
#include <libslic3r/SLA/SLABasePool.hpp>
#include <libslic3r/SLA/SLABoilerPlate.hpp>
#include <libnest2d/tools/benchmark.h>
const std::string USAGE_STR = {
"Usage: slabasebed stlfilename.stl"
};
namespace Slic3r { namespace sla {
Contour3D create_base_pool(const Polygons &ground_layer,
const ExPolygons &holes = {},
const PoolConfig& cfg = PoolConfig());
Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling,
double floor_z_mm, double ceiling_z_mm,
double offset_difference_mm, ThrowOnCancel thr);
void offset(ExPolygon& sh, coord_t distance);
}
}
int main(const int argc, const char *argv[]) {
using namespace Slic3r;
using std::cout; using std::endl;
if(argc < 2) {
cout << USAGE_STR << endl;
return EXIT_SUCCESS;
}
TriangleMesh model;
Benchmark bench;
model.ReadSTLFile(argv[1]);
model.align_to_origin();
ExPolygons ground_slice;
sla::base_plate(model, ground_slice, 0.1f);
if(ground_slice.empty()) return EXIT_FAILURE;
ground_slice = offset_ex(ground_slice, 0.5);
ExPolygon gndfirst; gndfirst = ground_slice.front();
sla::breakstick_holes(gndfirst, 0.5, 10, 0.3);
sla::Contour3D mesh;
bench.start();
sla::PoolConfig cfg;
cfg.min_wall_height_mm = 0;
cfg.edge_radius_mm = 0;
mesh = sla::create_base_pool(to_polygons(ground_slice), {}, cfg);
bench.stop();
cout << "Base pool creation time: " << std::setprecision(10)
<< bench.getElapsedSec() << " seconds." << endl;
for(auto& trind : mesh.indices) {
Vec3d p0 = mesh.points[size_t(trind[0])];
Vec3d p1 = mesh.points[size_t(trind[1])];
Vec3d p2 = mesh.points[size_t(trind[2])];
Vec3d p01 = p1 - p0;
Vec3d p02 = p2 - p0;
auto a = p01.cross(p02).norm() / 2.0;
if(std::abs(a) < 1e-6) std::cout << "degenerate triangle" << std::endl;
}
// basepool.write_ascii("out.stl");
std::fstream outstream("out.obj", std::fstream::out);
mesh.to_obj(outstream);
return EXIT_SUCCESS;
}

View File

@ -17,13 +17,14 @@ add_subdirectory(libigl)
add_subdirectory(test)
# Adding libnest2d project for bin packing...
set(LIBNEST2D_UNITTESTS ON CACHE BOOL "Force generating unittests for libnest2d")
add_subdirectory(libnest2d)
add_subdirectory(libslic3r)
if (SLIC3R_GUI)
add_subdirectory(imgui)
add_subdirectory(hidapi)
include_directories(hidapi/include)
if(WIN32)
message(STATUS "WXWIN environment set to: $ENV{WXWIN}")

View File

@ -162,6 +162,7 @@ int CLI::run(int argc, char **argv)
// sla_print_config.apply(m_print_config, true);
// Loop through transform options.
bool user_center_specified = false;
for (auto const &opt_key : m_transforms) {
if (opt_key == "merge") {
Model m;
@ -204,6 +205,7 @@ int CLI::run(int argc, char **argv)
for (auto &model : m_models)
model.duplicate_objects_grid(x, y, (distance > 0) ? distance : 6); // TODO: this is not the right place for setting a default
} else if (opt_key == "center") {
user_center_specified = true;
for (auto &model : m_models) {
model.add_default_instances();
// this affects instances:
@ -398,7 +400,9 @@ int CLI::run(int argc, char **argv)
if (! m_config.opt_bool("dont_arrange")) {
//FIXME make the min_object_distance configurable.
model.arrange_objects(fff_print.config().min_object_distance());
model.center_instances_around_point(m_config.option<ConfigOptionPoint>("center")->value);
model.center_instances_around_point((! user_center_specified && m_print_config.has("bed_shape")) ?
BoundingBoxf(m_print_config.opt<ConfigOptionPoints>("bed_shape")->values).center() :
m_config.option<ConfigOptionPoint>("center")->value);
}
if (printer_technology == ptFFF) {
for (auto* mo : model.objects)
@ -599,7 +603,7 @@ void CLI::print_help(bool include_print_options, PrinterTechnology printer_techn
<< " (without GUI support)"
#endif /* SLIC3R_GUI */
<< std::endl
<< "https://github.com/supermerill/slic3r" << std::endl << std::endl
<< "https://github.com/prusa3d/PrusaSlicer" << std::endl << std::endl
<< "Usage: prusa-slicer [ ACTIONS ] [ TRANSFORM ] [ OPTIONS ] [ file.stl ... ]" << std::endl
<< std::endl
<< "Actions:" << std::endl;
@ -618,7 +622,7 @@ void CLI::print_help(bool include_print_options, PrinterTechnology printer_techn
if (include_print_options) {
boost::nowide::cout << std::endl;
print_config_def.print_cli_help(boost::nowide::cout, true, [printer_technology](const ConfigOptionDef &def)
{ return (printer_technology & def.printer_technology) != 0; });
{ return printer_technology == ptAny || def.printer_technology == ptAny || printer_technology == def.printer_technology; });
} else {
boost::nowide::cout
<< std::endl

View File

@ -89,33 +89,34 @@ struct stl_neighbors {
};
struct stl_stats {
stl_stats() { this->reset(); }
void reset() { memset(this, 0, sizeof(stl_stats)); this->volume = -1.0; }
stl_stats() { memset(&header, 0, 81); }
char header[81];
stl_type type;
uint32_t number_of_facets;
stl_vertex max;
stl_vertex min;
stl_vertex size;
float bounding_diameter;
float shortest_edge;
float volume;
int connected_edges;
int connected_facets_1_edge;
int connected_facets_2_edge;
int connected_facets_3_edge;
int facets_w_1_bad_edge;
int facets_w_2_bad_edge;
int facets_w_3_bad_edge;
int original_num_facets;
int edges_fixed;
int degenerate_facets;
int facets_removed;
int facets_added;
int facets_reversed;
int backwards_edges;
int normals_fixed;
int number_of_parts;
stl_type type = (stl_type)0;
uint32_t number_of_facets = 0;
stl_vertex max = stl_vertex::Zero();
stl_vertex min = stl_vertex::Zero();
stl_vertex size = stl_vertex::Zero();
float bounding_diameter = 0.f;
float shortest_edge = 0.f;
float volume = -1.f;
int connected_edges = 0;
int connected_facets_1_edge = 0;
int connected_facets_2_edge = 0;
int connected_facets_3_edge = 0;
int facets_w_1_bad_edge = 0;
int facets_w_2_bad_edge = 0;
int facets_w_3_bad_edge = 0;
int original_num_facets = 0;
int edges_fixed = 0;
int degenerate_facets = 0;
int facets_removed = 0;
int facets_added = 0;
int facets_reversed = 0;
int backwards_edges = 0;
int normals_fixed = 0;
int number_of_parts = 0;
void clear() { *this = stl_stats(); }
};
struct stl_file {
@ -124,7 +125,7 @@ struct stl_file {
void clear() {
this->facet_start.clear();
this->neighbors_start.clear();
this->stats.reset();
this->stats.clear();
}
size_t memsize() const {
@ -183,9 +184,20 @@ extern void stl_mirror_xz(stl_file *stl);
extern void stl_get_size(stl_file *stl);
// the following function is not used
/*
template<typename T>
extern void stl_transform(stl_file *stl, T *trafo3x4)
{
Eigen::Matrix<T, 3, 3, Eigen::DontAlign> trafo3x3;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
trafo3x3(i, j) = (i * 4) + j;
}
}
Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = trafo3x3.inverse().transpose();
for (uint32_t i_face = 0; i_face < stl->stats.number_of_facets; ++ i_face) {
stl_facet &face = stl->facet_start[i_face];
for (int i_vertex = 0; i_vertex < 3; ++ i_vertex) {
@ -195,20 +207,17 @@ extern void stl_transform(stl_file *stl, T *trafo3x4)
v_dst(1) = T(trafo3x4[4] * v_src(0) + trafo3x4[5] * v_src(1) + trafo3x4[6] * v_src(2) + trafo3x4[7]);
v_dst(2) = T(trafo3x4[8] * v_src(0) + trafo3x4[9] * v_src(1) + trafo3x4[10] * v_src(2) + trafo3x4[11]);
}
stl_vertex &v_dst = face.normal;
stl_vertex v_src = v_dst;
v_dst(0) = T(trafo3x4[0] * v_src(0) + trafo3x4[1] * v_src(1) + trafo3x4[2] * v_src(2));
v_dst(1) = T(trafo3x4[4] * v_src(0) + trafo3x4[5] * v_src(1) + trafo3x4[6] * v_src(2));
v_dst(2) = T(trafo3x4[8] * v_src(0) + trafo3x4[9] * v_src(1) + trafo3x4[10] * v_src(2));
face.normal = (r * face.normal.template cast<T>()).template cast<float>().eval();
}
stl_get_size(stl);
}
*/
template<typename T>
inline void stl_transform(stl_file *stl, const Eigen::Transform<T, 3, Eigen::Affine, Eigen::DontAlign>& t)
{
const Eigen::Matrix<double, 3, 3, Eigen::DontAlign> r = t.matrix().template block<3, 3>(0, 0);
const Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = t.matrix().template block<3, 3>(0, 0).inverse().transpose();
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
stl_facet &f = stl->facet_start[i];
for (size_t j = 0; j < 3; ++j)
@ -222,11 +231,12 @@ inline void stl_transform(stl_file *stl, const Eigen::Transform<T, 3, Eigen::Aff
template<typename T>
inline void stl_transform(stl_file *stl, const Eigen::Matrix<T, 3, 3, Eigen::DontAlign>& m)
{
const Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = m.inverse().transpose();
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
stl_facet &f = stl->facet_start[i];
for (size_t j = 0; j < 3; ++j)
f.vertex[j] = (m * f.vertex[j].template cast<T>()).template cast<float>().eval();
f.normal = (m * f.normal.template cast<T>()).template cast<float>().eval();
f.normal = (r * f.normal.template cast<T>()).template cast<float>().eval();
}
stl_get_size(stl);

View File

@ -36,6 +36,10 @@
#error "SEEK_SET not defined"
#endif
#ifndef BOOST_LITTLE_ENDIAN
extern void stl_internal_reverse_quads(char *buf, size_t cnt);
#endif /* BOOST_LITTLE_ENDIAN */
static FILE* stl_open_count_facets(stl_file *stl, const char *file)
{
// Open the file in binary mode first.
@ -238,10 +242,6 @@ bool stl_open(stl_file *stl, const char *file)
return result;
}
#ifndef BOOST_LITTLE_ENDIAN
extern void stl_internal_reverse_quads(char *buf, size_t cnt);
#endif /* BOOST_LITTLE_ENDIAN */
void stl_allocate(stl_file *stl)
{
// Allocate memory for the entire .STL file.

View File

@ -156,7 +156,7 @@ namespace agg
//-------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
void add_path(VertexSource &&vs, unsigned path_id=0)
{
double x;
double y;

View File

@ -15,4 +15,4 @@
#undef clipper_hpp
#undef use_xyz
#endif clipper_z_hpp
#endif // clipper_z_hpp

19
src/hidapi/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
if (WIN32)
set(HIDAPI_IMPL win/hid.c)
elseif (APPLE)
set(HIDAPI_IMPL mac/hid.c)
else ()
# Assume Linux or Unix other than Mac OS
set(HIDAPI_IMPL linux/hid.c)
endif()
include_directories(include)
add_library(hidapi STATIC ${HIDAPI_IMPL})
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Don't link the udev library, as there are two versions out there (libudev.so.0, libudev.so.1), so they are linked explicitely.
# target_link_libraries(hidapi udev)
target_link_libraries(hidapi)
endif()

395
src/hidapi/include/hidapi.h Normal file
View File

@ -0,0 +1,395 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/** @file
* @defgroup API hidapi API
*/
#ifndef HIDAPI_H__
#define HIDAPI_H__
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
#define HID_API_CALL /**< API call macro */
#endif
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
#ifdef __cplusplus
extern "C" {
#endif
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface.
* Valid on the Mac implementation if and only if the device
is a USB HID device. */
int interface_number;
/** Pointer to the next device */
struct hid_device_info *next;
};
/** @brief Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not
strictly necessary, as it will be called automatically by
hid_enumerate() and any of the hid_open_*() functions if it is
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_init(void);
/** @brief Finalize the HIDAPI library.
This function frees all of the static data associated with
HIDAPI. It should be called at the end of execution to avoid
memory leaks.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_exit(void);
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
attached to the system which match vendor_id and product_id.
If @p vendor_id is set to 0 then any vendor matches.
If @p product_id is set to 0 then any product matches.
If @p vendor_id and @p product_id are both set to 0, then
all HID devices will be returned.
@ingroup API
@param vendor_id The Vendor ID (VID) of the types of device
to open.
@param product_id The Product ID (PID) of the types of
device to open.
@returns
This function returns a pointer to a linked list of type
struct #hid_device_info, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
/** @brief Free an enumeration Linked List
This function frees a linked list created by hid_enumerate().
@ingroup API
@param devs Pointer to a list of struct_device returned from
hid_enumerate().
*/
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
/** @brief Open a HID device using a Vendor ID (VID), Product ID
(PID) and optionally a serial number.
If @p serial_number is NULL, the first device with the
specified VID and PID is opened.
@ingroup API
@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
(Optionally NULL).
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
The path name be determined by calling hid_enumerate(), or a
platform-specific path name can be used (eg: /dev/hidraw0 on
Linux).
@ingroup API
@param path The path name of the device to open
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
/** @brief Write an Output report to a HID device.
The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.
hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read within
the timeout period, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
/** @brief Read an Input report from a HID device.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
In non-blocking mode calls to hid_read() will return
immediately with a value of 0 if there is no data to be
read. In blocking mode, hid_read() will wait (block) until
there is data to read before returning.
Nonblocking can be turned on and off at any time.
@ingroup API
@param dev A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock);
/** @brief Send a Feature report to the device.
Feature reports are sent over the Control endpoint as a
Set_Report transfer. The first byte of @p data[] must
contain the Report ID. For devices which only support a
single report, this must be set to 0x0. The remaining bytes
contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one
more byte than the report contains. For example, if a hid
report is 16 bytes long, 17 bytes must be passed to
hid_send_feature_report(): the Report ID (or 0x0, for
devices which do not use numbered reports), followed by the
report data (16 bytes). In this example, the length passed
in would be 17.
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
the report number.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
Set the first byte of @p data[] to the Report ID of the
report to be read. Make sure to allow space for this
extra byte in @p data[]. Upon return, the first byte will
still contain the Report ID, and the report data will
start in data[1].
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read, or set it to zero
if your device does not use numbered reports.
@param length The number of bytes to read, including an
extra byte for the report ID. The buffer can be longer
than the actual report.
@returns
This function returns the number of bytes read plus
one for the report ID (which is still in the first
byte), or -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param dev A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param dev A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
#ifdef __cplusplus
}
#endif
#endif

918
src/hidapi/linux/hid.c Normal file
View File

@ -0,0 +1,918 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Linux Version - 6/2/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/* C */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <errno.h>
/* Unix */
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include <poll.h>
/* Linux */
#include <linux/hidraw.h>
#include <linux/version.h>
#include <linux/input.h>
#include <libudev.h>
#include "hidapi.h"
typedef const char* (*hid_wrapper_udev_device_get_devnode_type)(struct udev_device *udev_device);
typedef struct udev_device* (*hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type)(struct udev_device *udev_device, const char *subsystem, const char *devtype);
typedef const char* (*hid_wrapper_udev_device_get_sysattr_value_type)(struct udev_device *udev_device, const char *sysattr);
typedef struct udev_device* (*hid_wrapper_udev_device_new_from_devnum_type)(struct udev *udev, char type, dev_t devnum);
typedef struct udev_device* (*hid_wrapper_udev_device_new_from_syspath_type)(struct udev *udev, const char *syspath);
typedef struct udev_device* (*hid_wrapper_udev_device_unref_type)(struct udev_device *udev_device);
typedef int (*hid_wrapper_udev_enumerate_add_match_subsystem_type)(struct udev_enumerate *udev_enumerate, const char *subsystem);
typedef struct udev_list_entry* (*hid_wrapper_udev_enumerate_get_list_entry_type)(struct udev_enumerate *udev_enumerate);
typedef struct udev_enumerate* (*hid_wrapper_udev_enumerate_new_type)(struct udev *udev);
typedef int (*hid_wrapper_udev_enumerate_scan_devices_type)(struct udev_enumerate *udev_enumerate);
typedef struct udev_enumerate* (*hid_wrapper_udev_enumerate_unref_type)(struct udev_enumerate *udev_enumerate);
typedef const char* (*hid_wrapper_udev_list_entry_get_name_type)(struct udev_list_entry *list_entry);
typedef struct udev_list_entry* (*hid_wrapper_udev_list_entry_get_next_type)(struct udev_list_entry *list_entry);
typedef struct udev* (*hid_wrapper_udev_new_type)(void);
typedef struct udev* (*hid_wrapper_udev_unref_type)(struct udev *udev);
void *hid_wrapper_handle = NULL;
static hid_wrapper_udev_device_get_devnode_type hid_wrapper_udev_device_get_devnode = NULL;
static hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type hid_wrapper_udev_device_get_parent_with_subsystem_devtype = NULL;
static hid_wrapper_udev_device_get_sysattr_value_type hid_wrapper_udev_device_get_sysattr_value = NULL;
static hid_wrapper_udev_device_new_from_devnum_type hid_wrapper_udev_device_new_from_devnum = NULL;
static hid_wrapper_udev_device_new_from_syspath_type hid_wrapper_udev_device_new_from_syspath = NULL;
static hid_wrapper_udev_device_unref_type hid_wrapper_udev_device_unref = NULL;
static hid_wrapper_udev_enumerate_add_match_subsystem_type hid_wrapper_udev_enumerate_add_match_subsystem = NULL;
static hid_wrapper_udev_enumerate_get_list_entry_type hid_wrapper_udev_enumerate_get_list_entry = NULL;
static hid_wrapper_udev_enumerate_new_type hid_wrapper_udev_enumerate_new = NULL;
static hid_wrapper_udev_enumerate_scan_devices_type hid_wrapper_udev_enumerate_scan_devices = NULL;
static hid_wrapper_udev_enumerate_unref_type hid_wrapper_udev_enumerate_unref = NULL;
static hid_wrapper_udev_list_entry_get_name_type hid_wrapper_udev_list_entry_get_name = NULL;
static hid_wrapper_udev_list_entry_get_next_type hid_wrapper_udev_list_entry_get_next = NULL;
static hid_wrapper_udev_new_type hid_wrapper_udev_new = NULL;
static hid_wrapper_udev_unref_type hid_wrapper_udev_unref = NULL;
static void hid_wrapper_udev_close()
{
if (hid_wrapper_handle)
dlclose(hid_wrapper_handle);
hid_wrapper_handle = NULL;
hid_wrapper_udev_device_get_devnode = NULL;
hid_wrapper_udev_device_get_parent_with_subsystem_devtype = NULL;
hid_wrapper_udev_device_get_sysattr_value = NULL;
hid_wrapper_udev_device_new_from_devnum = NULL;
hid_wrapper_udev_device_new_from_syspath = NULL;
hid_wrapper_udev_device_unref = NULL;
hid_wrapper_udev_enumerate_add_match_subsystem = NULL;
hid_wrapper_udev_enumerate_get_list_entry = NULL;
hid_wrapper_udev_enumerate_new = NULL;
hid_wrapper_udev_enumerate_scan_devices = NULL;
hid_wrapper_udev_enumerate_unref = NULL;
hid_wrapper_udev_list_entry_get_name = NULL;
hid_wrapper_udev_list_entry_get_next = NULL;
hid_wrapper_udev_new = NULL;
hid_wrapper_udev_unref = NULL;
}
static const char *hid_wrapper_libudev_paths[] = {
"libudev.so.1", "libudev.so.0"
};
static int hid_wrapper_udev_init()
{
int i;
hid_wrapper_udev_close();
// Search for the libudev0 or libudev1 library.
for (i = 0; i < sizeof(hid_wrapper_libudev_paths) / sizeof(hid_wrapper_libudev_paths[0]); ++ i)
if ((hid_wrapper_handle = dlopen(hid_wrapper_libudev_paths[i], RTLD_NOW | RTLD_GLOBAL)) != NULL)
break;
if (hid_wrapper_handle == NULL) {
// Error, close the shared library handle and finish.
hid_wrapper_udev_close();
return -1;
}
// Resolve the functions.
hid_wrapper_udev_device_get_devnode = (hid_wrapper_udev_device_get_devnode_type) dlsym(hid_wrapper_handle, "udev_device_get_devnode");
hid_wrapper_udev_device_get_parent_with_subsystem_devtype = (hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type) dlsym(hid_wrapper_handle, "udev_device_get_parent_with_subsystem_devtype");
hid_wrapper_udev_device_get_sysattr_value = (hid_wrapper_udev_device_get_sysattr_value_type) dlsym(hid_wrapper_handle, "udev_device_get_sysattr_value");
hid_wrapper_udev_device_new_from_devnum = (hid_wrapper_udev_device_new_from_devnum_type) dlsym(hid_wrapper_handle, "udev_device_new_from_devnum");
hid_wrapper_udev_device_new_from_syspath = (hid_wrapper_udev_device_new_from_syspath_type) dlsym(hid_wrapper_handle, "udev_device_new_from_syspath");
hid_wrapper_udev_device_unref = (hid_wrapper_udev_device_unref_type) dlsym(hid_wrapper_handle, "udev_device_unref");
hid_wrapper_udev_enumerate_add_match_subsystem = (hid_wrapper_udev_enumerate_add_match_subsystem_type) dlsym(hid_wrapper_handle, "udev_enumerate_add_match_subsystem");
hid_wrapper_udev_enumerate_get_list_entry = (hid_wrapper_udev_enumerate_get_list_entry_type) dlsym(hid_wrapper_handle, "udev_enumerate_get_list_entry");
hid_wrapper_udev_enumerate_new = (hid_wrapper_udev_enumerate_new_type) dlsym(hid_wrapper_handle, "udev_enumerate_new");
hid_wrapper_udev_enumerate_scan_devices = (hid_wrapper_udev_enumerate_scan_devices_type) dlsym(hid_wrapper_handle, "udev_enumerate_scan_devices");
hid_wrapper_udev_enumerate_unref = (hid_wrapper_udev_enumerate_unref_type) dlsym(hid_wrapper_handle, "udev_enumerate_unref");
hid_wrapper_udev_list_entry_get_name = (hid_wrapper_udev_list_entry_get_name_type) dlsym(hid_wrapper_handle, "udev_list_entry_get_name");
hid_wrapper_udev_list_entry_get_next = (hid_wrapper_udev_list_entry_get_next_type) dlsym(hid_wrapper_handle, "udev_list_entry_get_next");
hid_wrapper_udev_new = (hid_wrapper_udev_new_type) dlsym(hid_wrapper_handle, "udev_new");
hid_wrapper_udev_unref = (hid_wrapper_udev_unref_type) dlsym(hid_wrapper_handle, "udev_unref");
// Were all the funcions resolved?
if (hid_wrapper_handle == NULL ||
hid_wrapper_udev_device_get_devnode == NULL ||
hid_wrapper_udev_device_get_parent_with_subsystem_devtype == NULL ||
hid_wrapper_udev_device_get_sysattr_value == NULL ||
hid_wrapper_udev_device_new_from_devnum == NULL ||
hid_wrapper_udev_device_new_from_syspath == NULL ||
hid_wrapper_udev_device_unref == NULL ||
hid_wrapper_udev_enumerate_add_match_subsystem == NULL ||
hid_wrapper_udev_enumerate_get_list_entry == NULL ||
hid_wrapper_udev_enumerate_new == NULL ||
hid_wrapper_udev_enumerate_scan_devices == NULL ||
hid_wrapper_udev_enumerate_unref == NULL ||
hid_wrapper_udev_list_entry_get_name == NULL ||
hid_wrapper_udev_list_entry_get_next == NULL ||
hid_wrapper_udev_new == NULL ||
hid_wrapper_udev_unref == NULL)
{
// Error, close the shared library handle and finish.
hid_wrapper_udev_close();
return -1;
}
// Success.
return 0;
}
/* Definitions from linux/hidraw.h. Since these are new, some distros
may not have header files which contain them. */
#ifndef HIDIOCSFEATURE
#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)
#endif
#ifndef HIDIOCGFEATURE
#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
#endif
/* USB HID device property names */
const char *device_string_names[] = {
"manufacturer",
"product",
"serial",
};
/* Symbolic names for the properties above */
enum device_string_id {
DEVICE_STRING_MANUFACTURER,
DEVICE_STRING_PRODUCT,
DEVICE_STRING_SERIAL,
DEVICE_STRING_COUNT,
};
struct hid_device_ {
int device_handle;
int blocking;
int uses_numbered_reports;
};
static __u32 kernel_version = 0;
static __u32 detect_kernel_version(void)
{
struct utsname name;
int major, minor, release;
int ret;
uname(&name);
ret = sscanf(name.release, "%d.%d.%d", &major, &minor, &release);
if (ret == 3) {
return KERNEL_VERSION(major, minor, release);
}
ret = sscanf(name.release, "%d.%d", &major, &minor);
if (ret == 2) {
return KERNEL_VERSION(major, minor, 0);
}
printf("Couldn't determine kernel version from version string \"%s\"\n", name.release);
return 0;
}
static hid_device *new_hid_device(void)
{
hid_device *dev = calloc(1, sizeof(hid_device));
dev->device_handle = -1;
dev->blocking = 1;
dev->uses_numbered_reports = 0;
return dev;
}
/* The caller must free the returned string with free(). */
static wchar_t *utf8_to_wchar_t(const char *utf8)
{
wchar_t *ret = NULL;
if (utf8) {
size_t wlen = mbstowcs(NULL, utf8, 0);
if ((size_t) -1 == wlen) {
return wcsdup(L"");
}
ret = calloc(wlen+1, sizeof(wchar_t));
mbstowcs(ret, utf8, wlen+1);
ret[wlen] = 0x0000;
}
return ret;
}
/* Get an attribute value from a udev_device and return it as a whar_t
string. The returned string must be freed with free() when done.*/
static wchar_t *copy_udev_string(struct udev_device *dev, const char *udev_name)
{
return utf8_to_wchar_t(hid_wrapper_udev_device_get_sysattr_value(dev, udev_name));
}
/* uses_numbered_reports() returns 1 if report_descriptor describes a device
which contains numbered reports. */
static int uses_numbered_reports(__u8 *report_descriptor, __u32 size) {
unsigned int i = 0;
int size_code;
int data_len, key_size;
while (i < size) {
int key = report_descriptor[i];
/* Check for the Report ID key */
if (key == 0x85/*Report ID*/) {
/* This device has a Report ID, which means it uses
numbered reports. */
return 1;
}
//printf("key: %02hhx\n", key);
if ((key & 0xf0) == 0xf0) {
/* This is a Long Item. The next byte contains the
length of the data section (value) for this key.
See the HID specification, version 1.11, section
6.2.2.3, titled "Long Items." */
if (i+1 < size)
data_len = report_descriptor[i+1];
else
data_len = 0; /* malformed report */
key_size = 3;
}
else {
/* This is a Short Item. The bottom two bits of the
key contain the size code for the data section
(value) for this key. Refer to the HID
specification, version 1.11, section 6.2.2.2,
titled "Short Items." */
size_code = key & 0x3;
switch (size_code) {
case 0:
case 1:
case 2:
data_len = size_code;
break;
case 3:
data_len = 4;
break;
default:
/* Can't ever happen since size_code is & 0x3 */
data_len = 0;
break;
};
key_size = 1;
}
/* Skip over this key and it's associated data */
i += data_len + key_size;
}
/* Didn't find a Report ID key. Device doesn't use numbered reports. */
return 0;
}
/*
* The caller is responsible for free()ing the (newly-allocated) character
* strings pointed to by serial_number_utf8 and product_name_utf8 after use.
*/
static int
parse_uevent_info(const char *uevent, int *bus_type,
unsigned short *vendor_id, unsigned short *product_id,
char **serial_number_utf8, char **product_name_utf8)
{
char *tmp = strdup(uevent);
char *saveptr = NULL;
char *line;
char *key;
char *value;
int found_id = 0;
int found_serial = 0;
int found_name = 0;
line = strtok_r(tmp, "\n", &saveptr);
while (line != NULL) {
/* line: "KEY=value" */
key = line;
value = strchr(line, '=');
if (!value) {
goto next_line;
}
*value = '\0';
value++;
if (strcmp(key, "HID_ID") == 0) {
/**
* type vendor product
* HID_ID=0003:000005AC:00008242
**/
int ret = sscanf(value, "%x:%hx:%hx", bus_type, vendor_id, product_id);
if (ret == 3) {
found_id = 1;
}
} else if (strcmp(key, "HID_NAME") == 0) {
/* The caller has to free the product name */
*product_name_utf8 = strdup(value);
found_name = 1;
} else if (strcmp(key, "HID_UNIQ") == 0) {
/* The caller has to free the serial number */
*serial_number_utf8 = strdup(value);
found_serial = 1;
}
next_line:
line = strtok_r(NULL, "\n", &saveptr);
}
free(tmp);
return (found_id && found_name && found_serial);
}
static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t *string, size_t maxlen)
{
struct udev *udev;
struct udev_device *udev_dev, *parent, *hid_dev;
struct stat s;
int ret = -1;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
/* Create the udev object */
udev = hid_wrapper_udev_new();
if (!udev) {
printf("Can't create udev\n");
return -1;
}
/* Get the dev_t (major/minor numbers) from the file handle. */
ret = fstat(dev->device_handle, &s);
if (-1 == ret)
return ret;
/* Open a udev device from the dev_t. 'c' means character device. */
udev_dev = hid_wrapper_udev_device_new_from_devnum(udev, 'c', s.st_rdev);
if (udev_dev) {
hid_dev = hid_wrapper_udev_device_get_parent_with_subsystem_devtype(
udev_dev,
"hid",
NULL);
if (hid_dev) {
unsigned short dev_vid;
unsigned short dev_pid;
int bus_type;
size_t retm;
ret = parse_uevent_info(
hid_wrapper_udev_device_get_sysattr_value(hid_dev, "uevent"),
&bus_type,
&dev_vid,
&dev_pid,
&serial_number_utf8,
&product_name_utf8);
if (bus_type == BUS_BLUETOOTH) {
switch (key) {
case DEVICE_STRING_MANUFACTURER:
wcsncpy(string, L"", maxlen);
ret = 0;
break;
case DEVICE_STRING_PRODUCT:
retm = mbstowcs(string, product_name_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_SERIAL:
retm = mbstowcs(string, serial_number_utf8, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
break;
case DEVICE_STRING_COUNT:
default:
ret = -1;
break;
}
}
else {
/* This is a USB device. Find its parent USB Device node. */
parent = hid_wrapper_udev_device_get_parent_with_subsystem_devtype(
udev_dev,
"usb",
"usb_device");
if (parent) {
const char *str;
const char *key_str = NULL;
if (key >= 0 && key < DEVICE_STRING_COUNT) {
key_str = device_string_names[key];
} else {
ret = -1;
goto end;
}
str = hid_wrapper_udev_device_get_sysattr_value(parent, key_str);
if (str) {
/* Convert the string from UTF-8 to wchar_t */
retm = mbstowcs(string, str, maxlen);
ret = (retm == (size_t)-1)? -1: 0;
goto end;
}
}
}
}
}
end:
free(serial_number_utf8);
free(product_name_utf8);
hid_wrapper_udev_device_unref(udev_dev);
/* parent and hid_dev don't need to be (and can't be) unref'd.
I'm not sure why, but they'll throw double-free() errors. */
hid_wrapper_udev_unref(udev);
return ret;
}
int HID_API_EXPORT hid_init(void)
{
const char *locale;
/* Set the locale if it's not set. */
locale = setlocale(LC_CTYPE, NULL);
if (!locale)
setlocale(LC_CTYPE, "");
kernel_version = detect_kernel_version();
return hid_wrapper_udev_init();
}
int HID_API_EXPORT hid_exit(void)
{
/* Nothing to do for this in the Linux/hidraw implementation. */
hid_wrapper_udev_close();
return 0;
}
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
struct udev *udev;
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct hid_device_info *root = NULL; /* return object */
struct hid_device_info *cur_dev = NULL;
struct hid_device_info *prev_dev = NULL; /* previous device */
hid_init();
/* Create the udev object */
udev = hid_wrapper_udev_new();
if (!udev) {
printf("Can't create udev\n");
return NULL;
}
/* Create a list of the devices in the 'hidraw' subsystem. */
enumerate = hid_wrapper_udev_enumerate_new(udev);
hid_wrapper_udev_enumerate_add_match_subsystem(enumerate, "hidraw");
hid_wrapper_udev_enumerate_scan_devices(enumerate);
devices = hid_wrapper_udev_enumerate_get_list_entry(enumerate);
/* For each item, see if it matches the vid/pid, and if so
create a udev_device record for it */
for (dev_list_entry = devices; dev_list_entry; dev_list_entry = hid_wrapper_udev_list_entry_get_next(dev_list_entry)) {
const char *sysfs_path;
const char *dev_path;
const char *str;
struct udev_device *raw_dev; /* The device's hidraw udev node. */
struct udev_device *hid_dev; /* The device's HID udev node. */
struct udev_device *usb_dev; /* The device's USB udev node. */
struct udev_device *intf_dev; /* The device's interface (in the USB sense). */
unsigned short dev_vid;
unsigned short dev_pid;
char *serial_number_utf8 = NULL;
char *product_name_utf8 = NULL;
int bus_type;
int result;
/* Get the filename of the /sys entry for the device
and create a udev_device object (dev) representing it */
sysfs_path = hid_wrapper_udev_list_entry_get_name(dev_list_entry);
raw_dev = hid_wrapper_udev_device_new_from_syspath(udev, sysfs_path);
dev_path = hid_wrapper_udev_device_get_devnode(raw_dev);
hid_dev = hid_wrapper_udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"hid",
NULL);
if (!hid_dev) {
/* Unable to find parent hid device. */
goto next;
}
result = parse_uevent_info(
hid_wrapper_udev_device_get_sysattr_value(hid_dev, "uevent"),
&bus_type,
&dev_vid,
&dev_pid,
&serial_number_utf8,
&product_name_utf8);
if (!result) {
/* parse_uevent_info() failed for at least one field. */
goto next;
}
if (bus_type != BUS_USB && bus_type != BUS_BLUETOOTH) {
/* We only know how to handle USB and BT devices. */
goto next;
}
/* Check the VID/PID against the arguments */
if ((vendor_id == 0x0 || vendor_id == dev_vid) &&
(product_id == 0x0 || product_id == dev_pid)) {
struct hid_device_info *tmp;
/* VID/PID match. Create the record. */
tmp = malloc(sizeof(struct hid_device_info));
if (cur_dev) {
cur_dev->next = tmp;
}
else {
root = tmp;
}
prev_dev = cur_dev;
cur_dev = tmp;
/* Fill out the record */
cur_dev->next = NULL;
cur_dev->path = dev_path? strdup(dev_path): NULL;
/* VID/PID */
cur_dev->vendor_id = dev_vid;
cur_dev->product_id = dev_pid;
/* Serial Number */
cur_dev->serial_number = utf8_to_wchar_t(serial_number_utf8);
/* Release Number */
cur_dev->release_number = 0x0;
/* Interface Number */
cur_dev->interface_number = -1;
switch (bus_type) {
case BUS_USB:
/* The device pointed to by raw_dev contains information about
the hidraw device. In order to get information about the
USB device, get the parent device with the
subsystem/devtype pair of "usb"/"usb_device". This will
be several levels up the tree, but the function will find
it. */
usb_dev = hid_wrapper_udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"usb",
"usb_device");
if (!usb_dev) {
/* Free this device */
free(cur_dev->serial_number);
free(cur_dev->path);
free(cur_dev);
/* Take it off the device list. */
if (prev_dev) {
prev_dev->next = NULL;
cur_dev = prev_dev;
}
else {
cur_dev = root = NULL;
}
goto next;
}
/* Manufacturer and Product strings */
cur_dev->manufacturer_string = copy_udev_string(usb_dev, device_string_names[DEVICE_STRING_MANUFACTURER]);
cur_dev->product_string = copy_udev_string(usb_dev, device_string_names[DEVICE_STRING_PRODUCT]);
/* Release Number */
str = hid_wrapper_udev_device_get_sysattr_value(usb_dev, "bcdDevice");
cur_dev->release_number = (str)? strtol(str, NULL, 16): 0x0;
/* Get a handle to the interface's udev node. */
intf_dev = hid_wrapper_udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"usb",
"usb_interface");
if (intf_dev) {
str = hid_wrapper_udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
cur_dev->interface_number = (str)? strtol(str, NULL, 16): -1;
}
break;
case BUS_BLUETOOTH:
/* Manufacturer and Product strings */
cur_dev->manufacturer_string = wcsdup(L"");
cur_dev->product_string = utf8_to_wchar_t(product_name_utf8);
break;
default:
/* Unknown device type - this should never happen, as we
* check for USB and Bluetooth devices above */
break;
}
}
next:
free(serial_number_utf8);
free(product_name_utf8);
hid_wrapper_udev_device_unref(raw_dev);
/* hid_dev, usb_dev and intf_dev don't need to be (and can't be)
unref()d. It will cause a double-free() error. I'm not
sure why. */
}
/* Free the enumerator and udev objects. */
hid_wrapper_udev_enumerate_unref(enumerate);
hid_wrapper_udev_unref(udev);
return root;
}
void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)
{
struct hid_device_info *d = devs;
while (d) {
struct hid_device_info *next = d->next;
free(d->path);
free(d->serial_number);
free(d->manufacturer_string);
free(d->product_string);
free(d);
d = next;
}
}
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
struct hid_device_info *devs, *cur_dev;
const char *path_to_open = NULL;
hid_device *handle = NULL;
devs = hid_enumerate(vendor_id, product_id);
cur_dev = devs;
while (cur_dev) {
if (cur_dev->vendor_id == vendor_id &&
cur_dev->product_id == product_id) {
if (serial_number) {
if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
path_to_open = cur_dev->path;
break;
}
}
else {
path_to_open = cur_dev->path;
break;
}
}
cur_dev = cur_dev->next;
}
if (path_to_open) {
/* Open the device */
handle = hid_open_path(path_to_open);
}
hid_free_enumeration(devs);
return handle;
}
hid_device * HID_API_EXPORT hid_open_path(const char *path)
{
hid_device *dev = NULL;
hid_init();
dev = new_hid_device();
/* OPEN HERE */
dev->device_handle = open(path, O_RDWR);
/* If we have a good handle, return it. */
if (dev->device_handle > 0) {
/* Get the report descriptor */
int res, desc_size = 0;
struct hidraw_report_descriptor rpt_desc;
memset(&rpt_desc, 0x0, sizeof(rpt_desc));
/* Get Report Descriptor Size */
res = ioctl(dev->device_handle, HIDIOCGRDESCSIZE, &desc_size);
if (res < 0)
perror("HIDIOCGRDESCSIZE");
/* Get Report Descriptor */
rpt_desc.size = desc_size;
res = ioctl(dev->device_handle, HIDIOCGRDESC, &rpt_desc);
if (res < 0) {
perror("HIDIOCGRDESC");
} else {
/* Determine if this device uses numbered reports. */
dev->uses_numbered_reports =
uses_numbered_reports(rpt_desc.value,
rpt_desc.size);
}
return dev;
}
else {
/* Unable to open any devices. */
free(dev);
return NULL;
}
}
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
int bytes_written;
bytes_written = write(dev->device_handle, data, length);
return bytes_written;
}
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
{
int bytes_read;
if (milliseconds >= 0) {
/* Milliseconds is either 0 (non-blocking) or > 0 (contains
a valid timeout). In both cases we want to call poll()
and wait for data to arrive. Don't rely on non-blocking
operation (O_NONBLOCK) since some kernels don't seem to
properly report device disconnection through read() when
in non-blocking mode. */
int ret;
struct pollfd fds;
fds.fd = dev->device_handle;
fds.events = POLLIN;
fds.revents = 0;
ret = poll(&fds, 1, milliseconds);
if (ret == -1 || ret == 0) {
/* Error or timeout */
return ret;
}
else {
/* Check for errors on the file descriptor. This will
indicate a device disconnection. */
if (fds.revents & (POLLERR | POLLHUP | POLLNVAL))
return -1;
}
}
bytes_read = read(dev->device_handle, data, length);
if (bytes_read < 0 && (errno == EAGAIN || errno == EINPROGRESS))
bytes_read = 0;
if (bytes_read >= 0 &&
kernel_version != 0 &&
kernel_version < KERNEL_VERSION(2,6,34) &&
dev->uses_numbered_reports) {
/* Work around a kernel bug. Chop off the first byte. */
memmove(data, data+1, bytes_read);
bytes_read--;
}
return bytes_read;
}
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
{
return hid_read_timeout(dev, data, length, (dev->blocking)? -1: 0);
}
int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
{
/* Do all non-blocking in userspace using poll(), since it looks
like there's a bug in the kernel in some versions where
read() will not return -1 on disconnection of the USB device */
dev->blocking = !nonblock;
return 0; /* Success */
}
int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
int res;
res = ioctl(dev->device_handle, HIDIOCSFEATURE(length), data);
if (res < 0)
perror("ioctl (SFEATURE)");
return res;
}
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
int res;
res = ioctl(dev->device_handle, HIDIOCGFEATURE(length), data);
if (res < 0)
perror("ioctl (GFEATURE)");
return res;
}
void HID_API_EXPORT hid_close(hid_device *dev)
{
if (!dev)
return;
close(dev->device_handle);
free(dev);
}
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
return get_device_string(dev, DEVICE_STRING_MANUFACTURER, string, maxlen);
}
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
return get_device_string(dev, DEVICE_STRING_PRODUCT, string, maxlen);
}
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
return get_device_string(dev, DEVICE_STRING_SERIAL, string, maxlen);
}
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
{
return -1;
}
HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
{
return NULL;
}

1121
src/hidapi/mac/hid.c Normal file

File diff suppressed because it is too large Load Diff

956
src/hidapi/win/hid.c Normal file
View File

@ -0,0 +1,956 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
#include <windows.h>
#ifndef _NTDEF_
typedef LONG NTSTATUS;
#endif
#ifdef __MINGW32__
#include <ntdef.h>
#include <winbase.h>
#endif
#ifdef __CYGWIN__
#include <ntdef.h>
#define _wcsdup wcsdup
#endif
/* The maximum number of characters that can be passed into the
HidD_Get*String() functions without it failing.*/
#define MAX_STRING_WCHARS 0xFFF
/*#define HIDAPI_USE_DDK*/
#ifdef __cplusplus
extern "C" {
#endif
#include <setupapi.h>
#include <winioctl.h>
#ifdef HIDAPI_USE_DDK
#include <hidsdi.h>
#endif
/* Copied from inc/ddk/hidclass.h, part of the Windows DDK. */
#define HID_OUT_CTL_CODE(id) \
CTL_CODE(FILE_DEVICE_KEYBOARD, (id), METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_HID_GET_FEATURE HID_OUT_CTL_CODE(100)
#ifdef __cplusplus
} /* extern "C" */
#endif
#include <stdio.h>
#include <stdlib.h>
#include "hidapi.h"
#undef MIN
#define MIN(x,y) ((x) < (y)? (x): (y))
#ifdef _MSC_VER
/* Thanks Microsoft, but I know how to use strncpy(). */
#pragma warning(disable:4996)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef HIDAPI_USE_DDK
/* Since we're not building with the DDK, and the HID header
files aren't part of the SDK, we have to define all this
stuff here. In lookup_functions(), the function pointers
defined below are set. */
typedef struct _HIDD_ATTRIBUTES{
ULONG Size;
USHORT VendorID;
USHORT ProductID;
USHORT VersionNumber;
} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
typedef USHORT USAGE;
typedef struct _HIDP_CAPS {
USAGE Usage;
USAGE UsagePage;
USHORT InputReportByteLength;
USHORT OutputReportByteLength;
USHORT FeatureReportByteLength;
USHORT Reserved[17];
USHORT fields_not_used_by_hidapi[10];
} HIDP_CAPS, *PHIDP_CAPS;
typedef void* PHIDP_PREPARSED_DATA;
#define HIDP_STATUS_SUCCESS 0x110000
typedef BOOLEAN (__stdcall *HidD_GetAttributes_)(HANDLE device, PHIDD_ATTRIBUTES attrib);
typedef BOOLEAN (__stdcall *HidD_GetSerialNumberString_)(HANDLE device, PVOID buffer, ULONG buffer_len);
typedef BOOLEAN (__stdcall *HidD_GetManufacturerString_)(HANDLE handle, PVOID buffer, ULONG buffer_len);
typedef BOOLEAN (__stdcall *HidD_GetProductString_)(HANDLE handle, PVOID buffer, ULONG buffer_len);
typedef BOOLEAN (__stdcall *HidD_SetFeature_)(HANDLE handle, PVOID data, ULONG length);
typedef BOOLEAN (__stdcall *HidD_GetFeature_)(HANDLE handle, PVOID data, ULONG length);
typedef BOOLEAN (__stdcall *HidD_GetIndexedString_)(HANDLE handle, ULONG string_index, PVOID buffer, ULONG buffer_len);
typedef BOOLEAN (__stdcall *HidD_GetPreparsedData_)(HANDLE handle, PHIDP_PREPARSED_DATA *preparsed_data);
typedef BOOLEAN (__stdcall *HidD_FreePreparsedData_)(PHIDP_PREPARSED_DATA preparsed_data);
typedef NTSTATUS (__stdcall *HidP_GetCaps_)(PHIDP_PREPARSED_DATA preparsed_data, HIDP_CAPS *caps);
typedef BOOLEAN (__stdcall *HidD_SetNumInputBuffers_)(HANDLE handle, ULONG number_buffers);
static HidD_GetAttributes_ HidD_GetAttributes;
static HidD_GetSerialNumberString_ HidD_GetSerialNumberString;
static HidD_GetManufacturerString_ HidD_GetManufacturerString;
static HidD_GetProductString_ HidD_GetProductString;
static HidD_SetFeature_ HidD_SetFeature;
static HidD_GetFeature_ HidD_GetFeature;
static HidD_GetIndexedString_ HidD_GetIndexedString;
static HidD_GetPreparsedData_ HidD_GetPreparsedData;
static HidD_FreePreparsedData_ HidD_FreePreparsedData;
static HidP_GetCaps_ HidP_GetCaps;
static HidD_SetNumInputBuffers_ HidD_SetNumInputBuffers;
static HMODULE lib_handle = NULL;
static BOOLEAN initialized = FALSE;
#endif /* HIDAPI_USE_DDK */
struct hid_device_ {
HANDLE device_handle;
BOOL blocking;
USHORT output_report_length;
size_t input_report_length;
void *last_error_str;
DWORD last_error_num;
BOOL read_pending;
char *read_buf;
OVERLAPPED ol;
};
static hid_device *new_hid_device()
{
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
dev->device_handle = INVALID_HANDLE_VALUE;
dev->blocking = TRUE;
dev->output_report_length = 0;
dev->input_report_length = 0;
dev->last_error_str = NULL;
dev->last_error_num = 0;
dev->read_pending = FALSE;
dev->read_buf = NULL;
memset(&dev->ol, 0, sizeof(dev->ol));
dev->ol.hEvent = CreateEvent(NULL, FALSE, FALSE /*initial state f=nonsignaled*/, NULL);
return dev;
}
static void free_hid_device(hid_device *dev)
{
CloseHandle(dev->ol.hEvent);
CloseHandle(dev->device_handle);
LocalFree(dev->last_error_str);
free(dev->read_buf);
free(dev);
}
static void register_error(hid_device *dev, const char *op)
{
WCHAR *ptr, *msg;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPVOID)&msg, 0/*sz*/,
NULL);
/* Get rid of the CR and LF that FormatMessage() sticks at the
end of the message. Thanks Microsoft! */
ptr = msg;
while (*ptr) {
if (*ptr == '\r') {
*ptr = 0x0000;
break;
}
ptr++;
}
/* Store the message off in the Device entry so that
the hid_error() function can pick it up. */
LocalFree(dev->last_error_str);
dev->last_error_str = msg;
}
#ifndef HIDAPI_USE_DDK
static int lookup_functions()
{
lib_handle = LoadLibraryA("hid.dll");
if (lib_handle) {
#define RESOLVE(x) x = (x##_)GetProcAddress(lib_handle, #x); if (!x) return -1;
RESOLVE(HidD_GetAttributes);
RESOLVE(HidD_GetSerialNumberString);
RESOLVE(HidD_GetManufacturerString);
RESOLVE(HidD_GetProductString);
RESOLVE(HidD_SetFeature);
RESOLVE(HidD_GetFeature);
RESOLVE(HidD_GetIndexedString);
RESOLVE(HidD_GetPreparsedData);
RESOLVE(HidD_FreePreparsedData);
RESOLVE(HidP_GetCaps);
RESOLVE(HidD_SetNumInputBuffers);
#undef RESOLVE
}
else
return -1;
return 0;
}
#endif
static HANDLE open_device(const char *path, BOOL open_rw)
{
HANDLE handle;
DWORD desired_access = (open_rw)? (GENERIC_WRITE | GENERIC_READ): 0;
DWORD share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
handle = CreateFileA(path,
desired_access,
share_mode,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/
0);
return handle;
}
int HID_API_EXPORT hid_init(void)
{
#ifndef HIDAPI_USE_DDK
if (!initialized) {
if (lookup_functions() < 0) {
hid_exit();
return -1;
}
initialized = TRUE;
}
#endif
return 0;
}
int HID_API_EXPORT hid_exit(void)
{
#ifndef HIDAPI_USE_DDK
if (lib_handle)
FreeLibrary(lib_handle);
lib_handle = NULL;
initialized = FALSE;
#endif
return 0;
}
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
BOOL res;
struct hid_device_info *root = NULL; /* return object */
struct hid_device_info *cur_dev = NULL;
/* Windows objects for interacting with the driver. */
GUID InterfaceClassGuid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30} };
SP_DEVINFO_DATA devinfo_data;
SP_DEVICE_INTERFACE_DATA device_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A *device_interface_detail_data = NULL;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
int device_index = 0;
int i;
if (hid_init() < 0)
return NULL;
/* Initialize the Windows objects. */
memset(&devinfo_data, 0x0, sizeof(devinfo_data));
devinfo_data.cbSize = sizeof(SP_DEVINFO_DATA);
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
/* Get information for all the devices belonging to the HID class. */
device_info_set = SetupDiGetClassDevsA(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
/* Iterate over each device in the HID class, looking for the right one. */
for (;;) {
HANDLE write_handle = INVALID_HANDLE_VALUE;
DWORD required_size = 0;
HIDD_ATTRIBUTES attrib;
res = SetupDiEnumDeviceInterfaces(device_info_set,
NULL,
&InterfaceClassGuid,
device_index,
&device_interface_data);
if (!res) {
/* A return of FALSE from this function means that
there are no more devices. */
break;
}
/* Call with 0-sized detail size, and let the function
tell us how long the detail struct needs to be. The
size is put in &required_size. */
res = SetupDiGetDeviceInterfaceDetailA(device_info_set,
&device_interface_data,
NULL,
0,
&required_size,
NULL);
/* Allocate a long enough structure for device_interface_detail_data. */
device_interface_detail_data = (SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc(required_size);
device_interface_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
/* Get the detailed data for this device. The detail data gives us
the device path for this device, which is then passed into
CreateFile() to get a handle to the device. */
res = SetupDiGetDeviceInterfaceDetailA(device_info_set,
&device_interface_data,
device_interface_detail_data,
required_size,
NULL,
NULL);
if (!res) {
/* register_error(dev, "Unable to call SetupDiGetDeviceInterfaceDetail");
Continue to the next device. */
goto cont;
}
/* Make sure this device is of Setup Class "HIDClass" and has a
driver bound to it. */
for (i = 0; ; i++) {
char driver_name[256];
/* Populate devinfo_data. This function will return failure
when there are no more interfaces left. */
res = SetupDiEnumDeviceInfo(device_info_set, i, &devinfo_data);
if (!res)
goto cont;
res = SetupDiGetDeviceRegistryPropertyA(device_info_set, &devinfo_data,
SPDRP_CLASS, NULL, (PBYTE)driver_name, sizeof(driver_name), NULL);
if (!res)
goto cont;
if ((strcmp(driver_name, "HIDClass") == 0) ||
(strcmp(driver_name, "Mouse") == 0) ||
(strcmp(driver_name, "Keyboard") == 0)) {
/* See if there's a driver bound. */
res = SetupDiGetDeviceRegistryPropertyA(device_info_set, &devinfo_data,
SPDRP_DRIVER, NULL, (PBYTE)driver_name, sizeof(driver_name), NULL);
if (res)
break;
}
}
//wprintf(L"HandleName: %s\n", device_interface_detail_data->DevicePath);
/* Open a handle to the device */
write_handle = open_device(device_interface_detail_data->DevicePath, FALSE);
/* Check validity of write_handle. */
if (write_handle == INVALID_HANDLE_VALUE) {
/* Unable to open the device. */
//register_error(dev, "CreateFile");
goto cont_close;
}
/* Get the Vendor ID and Product ID for this device. */
attrib.Size = sizeof(HIDD_ATTRIBUTES);
HidD_GetAttributes(write_handle, &attrib);
//wprintf(L"Product/Vendor: %x %x\n", attrib.ProductID, attrib.VendorID);
/* Check the VID/PID to see if we should add this
device to the enumeration list. */
if ((vendor_id == 0x0 || attrib.VendorID == vendor_id) &&
(product_id == 0x0 || attrib.ProductID == product_id)) {
#define WSTR_LEN 512
const char *str;
struct hid_device_info *tmp;
PHIDP_PREPARSED_DATA pp_data = NULL;
HIDP_CAPS caps;
BOOLEAN res;
NTSTATUS nt_res;
wchar_t wstr[WSTR_LEN]; /* TODO: Determine Size */
size_t len;
/* VID/PID match. Create the record. */
tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
if (cur_dev) {
cur_dev->next = tmp;
}
else {
root = tmp;
}
cur_dev = tmp;
/* Get the Usage Page and Usage for this device. */
res = HidD_GetPreparsedData(write_handle, &pp_data);
if (res) {
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res == HIDP_STATUS_SUCCESS) {
cur_dev->usage_page = caps.UsagePage;
cur_dev->usage = caps.Usage;
}
HidD_FreePreparsedData(pp_data);
}
/* Fill out the record */
cur_dev->next = NULL;
str = device_interface_detail_data->DevicePath;
if (str) {
len = strlen(str);
cur_dev->path = (char*) calloc(len+1, sizeof(char));
strncpy(cur_dev->path, str, len+1);
cur_dev->path[len] = '\0';
}
else
cur_dev->path = NULL;
/* Serial Number */
res = HidD_GetSerialNumberString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->serial_number = _wcsdup(wstr);
}
/* Manufacturer String */
res = HidD_GetManufacturerString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->manufacturer_string = _wcsdup(wstr);
}
/* Product String */
res = HidD_GetProductString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->product_string = _wcsdup(wstr);
}
/* VID/PID */
cur_dev->vendor_id = attrib.VendorID;
cur_dev->product_id = attrib.ProductID;
/* Release Number */
cur_dev->release_number = attrib.VersionNumber;
/* Interface Number. It can sometimes be parsed out of the path
on Windows if a device has multiple interfaces. See
http://msdn.microsoft.com/en-us/windows/hardware/gg487473 or
search for "Hardware IDs for HID Devices" at MSDN. If it's not
in the path, it's set to -1. */
cur_dev->interface_number = -1;
if (cur_dev->path) {
char *interface_component = strstr(cur_dev->path, "&mi_");
if (interface_component) {
char *hex_str = interface_component + 4;
char *endptr = NULL;
cur_dev->interface_number = strtol(hex_str, &endptr, 16);
if (endptr == hex_str) {
/* The parsing failed. Set interface_number to -1. */
cur_dev->interface_number = -1;
}
}
}
}
cont_close:
CloseHandle(write_handle);
cont:
/* We no longer need the detail data. It can be freed */
free(device_interface_detail_data);
device_index++;
}
/* Close the device information handle. */
SetupDiDestroyDeviceInfoList(device_info_set);
return root;
}
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
{
/* TODO: Merge this with the Linux version. This function is platform-independent. */
struct hid_device_info *d = devs;
while (d) {
struct hid_device_info *next = d->next;
free(d->path);
free(d->serial_number);
free(d->manufacturer_string);
free(d->product_string);
free(d);
d = next;
}
}
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
/* TODO: Merge this functions with the Linux version. This function should be platform independent. */
struct hid_device_info *devs, *cur_dev;
const char *path_to_open = NULL;
hid_device *handle = NULL;
devs = hid_enumerate(vendor_id, product_id);
cur_dev = devs;
while (cur_dev) {
if (cur_dev->vendor_id == vendor_id &&
cur_dev->product_id == product_id) {
if (serial_number) {
if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
path_to_open = cur_dev->path;
break;
}
}
else {
path_to_open = cur_dev->path;
break;
}
}
cur_dev = cur_dev->next;
}
if (path_to_open) {
/* Open the device */
handle = hid_open_path(path_to_open);
}
hid_free_enumeration(devs);
return handle;
}
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
{
hid_device *dev;
HIDP_CAPS caps;
PHIDP_PREPARSED_DATA pp_data = NULL;
BOOLEAN res;
NTSTATUS nt_res;
if (hid_init() < 0) {
return NULL;
}
dev = new_hid_device();
/* Open a handle to the device */
dev->device_handle = open_device(path, TRUE);
/* Check validity of write_handle. */
if (dev->device_handle == INVALID_HANDLE_VALUE) {
/* System devices, such as keyboards and mice, cannot be opened in
read-write mode, because the system takes exclusive control over
them. This is to prevent keyloggers. However, feature reports
can still be sent and received. Retry opening the device, but
without read/write access. */
dev->device_handle = open_device(path, FALSE);
/* Check the validity of the limited device_handle. */
if (dev->device_handle == INVALID_HANDLE_VALUE) {
/* Unable to open the device, even without read-write mode. */
register_error(dev, "CreateFile");
goto err;
}
}
/* Set the Input Report buffer size to 64 reports. */
res = HidD_SetNumInputBuffers(dev->device_handle, 64);
if (!res) {
register_error(dev, "HidD_SetNumInputBuffers");
goto err;
}
/* Get the Input Report length for the device. */
res = HidD_GetPreparsedData(dev->device_handle, &pp_data);
if (!res) {
register_error(dev, "HidD_GetPreparsedData");
goto err;
}
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res != HIDP_STATUS_SUCCESS) {
register_error(dev, "HidP_GetCaps");
goto err_pp_data;
}
dev->output_report_length = caps.OutputReportByteLength;
dev->input_report_length = caps.InputReportByteLength;
HidD_FreePreparsedData(pp_data);
dev->read_buf = (char*) malloc(dev->input_report_length);
return dev;
err_pp_data:
HidD_FreePreparsedData(pp_data);
err:
free_hid_device(dev);
return NULL;
}
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length)
{
DWORD bytes_written;
BOOL res;
OVERLAPPED ol;
unsigned char *buf;
memset(&ol, 0, sizeof(ol));
/* Make sure the right number of bytes are passed to WriteFile. Windows
expects the number of bytes which are in the _longest_ report (plus
one for the report number) bytes even if the data is a report
which is shorter than that. Windows gives us this value in
caps.OutputReportByteLength. If a user passes in fewer bytes than this,
create a temporary buffer which is the proper size. */
if (length >= dev->output_report_length) {
/* The user passed the right number of bytes. Use the buffer as-is. */
buf = (unsigned char *) data;
} else {
/* Create a temporary buffer and copy the user's data
into it, padding the rest with zeros. */
buf = (unsigned char *) malloc(dev->output_report_length);
memcpy(buf, data, length);
memset(buf + length, 0, dev->output_report_length - length);
length = dev->output_report_length;
}
res = WriteFile(dev->device_handle, buf, length, NULL, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* WriteFile() failed. Return error. */
register_error(dev, "WriteFile");
bytes_written = -1;
goto end_of_function;
}
}
/* Wait here until the write is done. This makes
hid_write() synchronous. */
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_written, TRUE/*wait*/);
if (!res) {
/* The Write operation failed. */
register_error(dev, "WriteFile");
bytes_written = -1;
goto end_of_function;
}
end_of_function:
if (buf != data)
free(buf);
return bytes_written;
}
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
{
DWORD bytes_read = 0;
size_t copy_len = 0;
BOOL res;
/* Copy the handle for convenience. */
HANDLE ev = dev->ol.hEvent;
if (!dev->read_pending) {
/* Start an Overlapped I/O read. */
dev->read_pending = TRUE;
memset(dev->read_buf, 0, dev->input_report_length);
ResetEvent(ev);
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* ReadFile() has failed.
Clean up and return error. */
CancelIo(dev->device_handle);
dev->read_pending = FALSE;
goto end_of_function;
}
}
}
if (milliseconds >= 0) {
/* See if there is any data yet. */
res = WaitForSingleObject(ev, milliseconds);
if (res != WAIT_OBJECT_0) {
/* There was no data this time. Return zero bytes available,
but leave the Overlapped I/O running. */
return 0;
}
}
/* Either WaitForSingleObject() told us that ReadFile has completed, or
we are in non-blocking mode. Get the number of bytes read. The actual
data has been copied to the data[] array which was passed to ReadFile(). */
res = GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/);
/* Set pending back to false, even if GetOverlappedResult() returned error. */
dev->read_pending = FALSE;
if (res && bytes_read > 0) {
if (dev->read_buf[0] == 0x0) {
/* If report numbers aren't being used, but Windows sticks a report
number (0x0) on the beginning of the report anyway. To make this
work like the other platforms, and to make it work more like the
HID spec, we'll skip over this byte. */
bytes_read--;
copy_len = length > bytes_read ? bytes_read : length;
memcpy(data, dev->read_buf+1, copy_len);
}
else {
/* Copy the whole buffer, report number and all. */
copy_len = length > bytes_read ? bytes_read : length;
memcpy(data, dev->read_buf, copy_len);
}
}
end_of_function:
if (!res) {
register_error(dev, "GetOverlappedResult");
return -1;
}
return copy_len;
}
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length)
{
return hid_read_timeout(dev, data, length, (dev->blocking)? -1: 0);
}
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock)
{
dev->blocking = !nonblock;
return 0; /* Success */
}
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, length);
if (!res) {
register_error(dev, "HidD_SetFeature");
return -1;
}
return length;
}
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
BOOL res;
#if 0
res = HidD_GetFeature(dev->device_handle, data, length);
if (!res) {
register_error(dev, "HidD_GetFeature");
return -1;
}
return 0; /* HidD_GetFeature() doesn't give us an actual length, unfortunately */
#else
DWORD bytes_returned;
OVERLAPPED ol;
memset(&ol, 0, sizeof(ol));
res = DeviceIoControl(dev->device_handle,
IOCTL_HID_GET_FEATURE,
data, length,
data, length,
&bytes_returned, &ol);
if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
/* DeviceIoControl() failed. Return error. */
register_error(dev, "Send Feature Report DeviceIoControl");
return -1;
}
}
/* Wait here until the write is done. This makes
hid_get_feature_report() synchronous. */
res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/);
if (!res) {
/* The operation failed. */
register_error(dev, "Send Feature Report GetOverLappedResult");
return -1;
}
/* bytes_returned does not include the first byte which contains the
report ID. The data buffer actually contains one more byte than
bytes_returned. */
bytes_returned++;
return bytes_returned;
#endif
}
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev)
{
if (!dev)
return;
CancelIo(dev->device_handle);
free_hid_device(dev);
}
int HID_API_EXPORT_CALL HID_API_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetManufacturerString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetManufacturerString");
return -1;
}
return 0;
}
int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetProductString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetProductString");
return -1;
}
return 0;
}
int HID_API_EXPORT_CALL HID_API_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetSerialNumberString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetSerialNumberString");
return -1;
}
return 0;
}
int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
{
BOOL res;
res = HidD_GetIndexedString(dev->device_handle, string_index, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetIndexedString");
return -1;
}
return 0;
}
HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
{
return (wchar_t*)dev->last_error_str;
}
/*#define PICPGM*/
/*#define S11*/
#define P32
#ifdef S11
unsigned short VendorID = 0xa0a0;
unsigned short ProductID = 0x0001;
#endif
#ifdef P32
unsigned short VendorID = 0x04d8;
unsigned short ProductID = 0x3f;
#endif
#ifdef PICPGM
unsigned short VendorID = 0x04d8;
unsigned short ProductID = 0x0033;
#endif
#if 0
int __cdecl main(int argc, char* argv[])
{
int res;
unsigned char buf[65];
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
/* Set up the command buffer. */
memset(buf,0x00,sizeof(buf));
buf[0] = 0;
buf[1] = 0x81;
/* Open the device. */
int handle = open(VendorID, ProductID, L"12345");
if (handle < 0)
printf("unable to open device\n");
/* Toggle LED (cmd 0x80) */
buf[1] = 0x80;
res = write(handle, buf, 65);
if (res < 0)
printf("Unable to write()\n");
/* Request state (cmd 0x81) */
buf[1] = 0x81;
write(handle, buf, 65);
if (res < 0)
printf("Unable to write() (2)\n");
/* Read requested state */
read(handle, buf, 65);
if (res < 0)
printf("Unable to read()\n");
/* Print out the returned buffer. */
for (int i = 0; i < 4; i++)
printf("buf[%d]: %d\n", i, buf[i]);
return 0;
}
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@ -1,134 +1,31 @@
cmake_minimum_required(VERSION 3.0)
project(Libnest2D)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long ")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED)
# Add our own cmake module path.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
option(LIBNEST2D_UNITTESTS "If enabled, googletest framework will be downloaded
and the provided unit tests will be included in the build." OFF)
option(LIBNEST2D_BUILD_EXAMPLES "If enabled, examples will be built." OFF)
option(LIBNEST2D_HEADER_ONLY "If enabled static library will not be built." ON)
set(GEOMETRY_BACKENDS clipper boost eigen)
set(LIBNEST2D_GEOMETRIES clipper CACHE STRING "Geometry backend")
set_property(CACHE LIBNEST2D_GEOMETRIES PROPERTY STRINGS ${GEOMETRY_BACKENDS})
list(FIND GEOMETRY_BACKENDS ${LIBNEST2D_GEOMETRIES} GEOMETRY_TYPE)
if(${GEOMETRY_TYPE} EQUAL -1)
message(FATAL_ERROR "Option ${LIBNEST2D_GEOMETRIES} not supported, valid entries are ${GEOMETRY_BACKENDS}")
endif()
set(OPTIMIZERS nlopt optimlib)
set(LIBNEST2D_OPTIMIZER nlopt CACHE STRING "Optimization backend")
set_property(CACHE LIBNEST2D_OPTIMIZER PROPERTY STRINGS ${OPTIMIZERS})
list(FIND OPTIMIZERS ${LIBNEST2D_OPTIMIZER} OPTIMIZER_TYPE)
if(${OPTIMIZER_TYPE} EQUAL -1)
message(FATAL_ERROR "Option ${LIBNEST2D_OPTIMIZER} not supported, valid entries are ${OPTIMIZERS}")
endif()
add_library(libnest2d INTERFACE)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/include)
set(LIBNEST2D_SRCFILES
${SRC_DIR}/libnest2d/libnest2d.hpp # Templates only
${SRC_DIR}/libnest2d/geometry_traits.hpp
${SRC_DIR}/libnest2d/geometry_traits_nfp.hpp
${SRC_DIR}/libnest2d/common.hpp
${SRC_DIR}/libnest2d/optimizer.hpp
${SRC_DIR}/libnest2d/utils/metaloop.hpp
${SRC_DIR}/libnest2d/utils/rotfinder.hpp
${SRC_DIR}/libnest2d/utils/rotcalipers.hpp
${SRC_DIR}/libnest2d/utils/bigint.hpp
${SRC_DIR}/libnest2d/utils/rational.hpp
${SRC_DIR}/libnest2d/placers/placer_boilerplate.hpp
${SRC_DIR}/libnest2d/placers/bottomleftplacer.hpp
${SRC_DIR}/libnest2d/placers/nfpplacer.hpp
${SRC_DIR}/libnest2d/selections/selection_boilerplate.hpp
${SRC_DIR}/libnest2d/selections/filler.hpp
${SRC_DIR}/libnest2d/selections/firstfit.hpp
${SRC_DIR}/libnest2d/selections/djd_heuristic.hpp
include/libnest2d/libnest2d.hpp
include/libnest2d/nester.hpp
include/libnest2d/geometry_traits.hpp
include/libnest2d/geometry_traits_nfp.hpp
include/libnest2d/common.hpp
include/libnest2d/optimizer.hpp
include/libnest2d/utils/metaloop.hpp
include/libnest2d/utils/rotfinder.hpp
include/libnest2d/utils/rotcalipers.hpp
include/libnest2d/placers/placer_boilerplate.hpp
include/libnest2d/placers/bottomleftplacer.hpp
include/libnest2d/placers/nfpplacer.hpp
include/libnest2d/selections/selection_boilerplate.hpp
#include/libnest2d/selections/filler.hpp
include/libnest2d/selections/firstfit.hpp
#include/libnest2d/selections/djd_heuristic.hpp
include/libnest2d/backends/clipper/geometries.hpp
include/libnest2d/backends/clipper/clipper_polygon.hpp
include/libnest2d/optimizers/nlopt/nlopt_boilerplate.hpp
include/libnest2d/optimizers/nlopt/simplex.hpp
include/libnest2d/optimizers/nlopt/subplex.hpp
include/libnest2d/optimizers/nlopt/genetic.hpp
src/libnest2d.cpp
)
set(TBB_STATIC ON)
find_package(TBB QUIET)
if(TBB_FOUND)
message(STATUS "Parallelization with Intel TBB")
target_include_directories(libnest2d INTERFACE ${TBB_INCLUDE_DIRS})
target_compile_definitions(libnest2d INTERFACE ${TBB_DEFINITIONS} -DUSE_TBB)
if(MSVC)
# Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
target_compile_definitions(libnest2d INTERFACE -D__TBB_NO_IMPLICIT_LINKAGE)
endif()
# The Intel TBB library will use the std::exception_ptr feature of C++11.
target_compile_definitions(libnest2d INTERFACE -DTBB_USE_CAPTURED_EXCEPTION=0)
add_library(libnest2d ${LIBNEST2D_SRCFILES})
find_package(Threads REQUIRED)
target_link_libraries(libnest2d INTERFACE
tbb # VS debug mode needs linking this way:
# ${TBB_LIBRARIES}
${CMAKE_DL_LIBS}
Threads::Threads
)
else()
find_package(OpenMP QUIET)
if(OpenMP_CXX_FOUND)
message(STATUS "Parallelization with OpenMP")
target_include_directories(libnest2d INTERFACE OpenMP::OpenMP_CXX)
target_link_libraries(libnest2d INTERFACE OpenMP::OpenMP_CXX)
else()
message("Parallelization with C++11 threads")
find_package(Threads REQUIRED)
target_link_libraries(libnest2d INTERFACE Threads::Threads)
endif()
endif()
add_subdirectory(${SRC_DIR}/libnest2d/backends/${LIBNEST2D_GEOMETRIES})
target_link_libraries(libnest2d INTERFACE ${LIBNEST2D_GEOMETRIES}Backend)
add_subdirectory(${SRC_DIR}/libnest2d/optimizers/${LIBNEST2D_OPTIMIZER})
target_link_libraries(libnest2d INTERFACE ${LIBNEST2D_OPTIMIZER}Optimizer)
# target_sources(libnest2d INTERFACE ${LIBNEST2D_SRCFILES})
target_include_directories(libnest2d INTERFACE ${SRC_DIR})
if(NOT LIBNEST2D_HEADER_ONLY)
set(LIBNAME libnest2d_${LIBNEST2D_GEOMETRIES}_${LIBNEST2D_OPTIMIZER})
add_library(${LIBNAME} ${PROJECT_SOURCE_DIR}/src/libnest2d.cpp)
target_link_libraries(${LIBNAME} PUBLIC libnest2d)
target_compile_definitions(${LIBNAME} PUBLIC LIBNEST2D_STATIC)
endif()
if(LIBNEST2D_BUILD_EXAMPLES)
add_executable(example examples/main.cpp
# tools/libnfpglue.hpp
# tools/libnfpglue.cpp
tools/nfp_svgnest.hpp
tools/nfp_svgnest_glue.hpp
tools/svgtools.hpp
tests/printer_parts.cpp
tests/printer_parts.h
)
if(NOT LIBNEST2D_HEADER_ONLY)
target_link_libraries(example ${LIBNAME})
else()
target_link_libraries(example libnest2d)
endif()
endif()
if(LIBNEST2D_UNITTESTS)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
endif()
target_include_directories(libnest2d PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(libnest2d PUBLIC clipper NLopt::nlopt TBB::tbb Boost::boost)
target_compile_definitions(libnest2d PUBLIC USE_TBB LIBNEST2D_STATIC LIBNEST2D_OPTIMIZER_nlopt LIBNEST2D_GEOMETRIES_clipper)

View File

@ -1,35 +0,0 @@
include(DownloadProject)
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
set(URL_NLOPT "https://github.com/stevengj/nlopt.git"
CACHE STRING "Location of the nlopt git repository")
# set(NLopt_DIR ${CMAKE_BINARY_DIR}/nlopt)
include(DownloadProject)
download_project( PROJ nlopt
GIT_REPOSITORY ${URL_NLOPT}
GIT_TAG v2.5.0
# CMAKE_CACHE_ARGS -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${NLopt_DIR}
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
set(SHARED_LIBS_STATE BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(NLOPT_PYTHON OFF CACHE BOOL "" FORCE)
set(NLOPT_OCTAVE OFF CACHE BOOL "" FORCE)
set(NLOPT_MATLAB OFF CACHE BOOL "" FORCE)
set(NLOPT_GUILE OFF CACHE BOOL "" FORCE)
set(NLOPT_SWIG OFF CACHE BOOL "" FORCE)
set(NLOPT_LINK_PYTHON OFF CACHE BOOL "" FORCE)
add_subdirectory(${nlopt_SOURCE_DIR} ${nlopt_BINARY_DIR})
set(NLopt_LIBS nlopt)
set(NLopt_INCLUDE_DIR ${nlopt_BINARY_DIR}
${nlopt_BINARY_DIR}/src/api)
set(SHARED_LIBS_STATE ${SHARED_STATE})

View File

@ -1,17 +0,0 @@
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
cmake_minimum_required(VERSION 2.8.2)
project(${DL_ARGS_PROJ}-download NONE)
include(ExternalProject)
ExternalProject_Add(${DL_ARGS_PROJ}-download
${DL_ARGS_UNPARSED_ARGUMENTS}
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -1,182 +0,0 @@
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
#
# MODULE: DownloadProject
#
# PROVIDES:
# download_project( PROJ projectName
# [PREFIX prefixDir]
# [DOWNLOAD_DIR downloadDir]
# [SOURCE_DIR srcDir]
# [BINARY_DIR binDir]
# [QUIET]
# ...
# )
#
# Provides the ability to download and unpack a tarball, zip file, git repository,
# etc. at configure time (i.e. when the cmake command is run). How the downloaded
# and unpacked contents are used is up to the caller, but the motivating case is
# to download source code which can then be included directly in the build with
# add_subdirectory() after the call to download_project(). Source and build
# directories are set up with this in mind.
#
# The PROJ argument is required. The projectName value will be used to construct
# the following variables upon exit (obviously replace projectName with its actual
# value):
#
# projectName_SOURCE_DIR
# projectName_BINARY_DIR
#
# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically
# need to be provided. They can be specified if you want the downloaded source
# and build directories to be located in a specific place. The contents of
# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the
# locations used whether you provide SOURCE_DIR/BINARY_DIR or not.
#
# The DOWNLOAD_DIR argument does not normally need to be set. It controls the
# location of the temporary CMake build used to perform the download.
#
# The PREFIX argument can be provided to change the base location of the default
# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments
# are provided, then PREFIX will have no effect. The default value for PREFIX is
# CMAKE_BINARY_DIR.
#
# The QUIET option can be given if you do not want to show the output associated
# with downloading the specified project.
#
# In addition to the above, any other options are passed through unmodified to
# ExternalProject_Add() to perform the actual download, patch and update steps.
# The following ExternalProject_Add() options are explicitly prohibited (they
# are reserved for use by the download_project() command):
#
# CONFIGURE_COMMAND
# BUILD_COMMAND
# INSTALL_COMMAND
# TEST_COMMAND
#
# Only those ExternalProject_Add() arguments which relate to downloading, patching
# and updating of the project sources are intended to be used. Also note that at
# least one set of download-related arguments are required.
#
# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to
# prevent a check at the remote end for changes every time CMake is run
# after the first successful download. See the documentation of the ExternalProject
# module for more information. It is likely you will want to use this option if it
# is available to you. Note, however, that the ExternalProject implementation contains
# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when
# using the URL download method or when specifying a SOURCE_DIR with no download
# method. Fixes for these have been created, the last of which is scheduled for
# inclusion in CMake 3.8.0. Details can be found here:
#
# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c
# https://gitlab.kitware.com/cmake/cmake/issues/16428
#
# If you experience build errors related to the update step, consider avoiding
# the use of UPDATE_DISCONNECTED.
#
# EXAMPLE USAGE:
#
# include(DownloadProject)
# download_project(PROJ googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG master
# UPDATE_DISCONNECTED 1
# QUIET
# )
#
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
#
#========================================================================================
set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}")
include(CMakeParseArguments)
function(download_project)
set(options QUIET)
set(oneValueArgs
PROJ
PREFIX
DOWNLOAD_DIR
SOURCE_DIR
BINARY_DIR
# Prevent the following from being passed through
CONFIGURE_COMMAND
BUILD_COMMAND
INSTALL_COMMAND
TEST_COMMAND
)
set(multiValueArgs "")
cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Hide output if requested
if (DL_ARGS_QUIET)
set(OUTPUT_QUIET "OUTPUT_QUIET")
else()
unset(OUTPUT_QUIET)
message(STATUS "Downloading/updating ${DL_ARGS_PROJ}")
endif()
# Set up where we will put our temporary CMakeLists.txt file and also
# the base point below which the default source and binary dirs will be.
# The prefix must always be an absolute path.
if (NOT DL_ARGS_PREFIX)
set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}")
else()
get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if (NOT DL_ARGS_DOWNLOAD_DIR)
set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download")
endif()
# Ensure the caller can know where to find the source and build directories
if (NOT DL_ARGS_SOURCE_DIR)
set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src")
endif()
if (NOT DL_ARGS_BINARY_DIR)
set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build")
endif()
set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE)
set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE)
# The way that CLion manages multiple configurations, it causes a copy of
# the CMakeCache.txt to be copied across due to it not expecting there to
# be a project within a project. This causes the hard-coded paths in the
# cache to be copied and builds to fail. To mitigate this, we simply
# remove the cache if it exists before we configure the new project. It
# is safe to do so because it will be re-generated. Since this is only
# executed at the configure step, it should not cause additional builds or
# downloads.
file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt")
# Create and build a separate CMake project to carry out the download.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
# has this set to something not findable on the PATH.
configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in"
"${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt")
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}"
.
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}")
endif()
endfunction()

View File

@ -1,58 +0,0 @@
# Find Clipper library (http://www.angusj.com/delphi/clipper.php).
# The following variables are set
#
# CLIPPER_FOUND
# CLIPPER_INCLUDE_DIRS
# CLIPPER_LIBRARIES
#
# It searches the environment variable $CLIPPER_PATH automatically.
FIND_PATH(CLIPPER_INCLUDE_DIRS clipper.hpp
$ENV{CLIPPER_PATH}
$ENV{CLIPPER_PATH}/cpp/
$ENV{CLIPPER_PATH}/include/
$ENV{CLIPPER_PATH}/include/polyclipping/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/polyclipping/
${CMAKE_PREFIX_PATH}/include/polyclipping
${CMAKE_PREFIX_PATH}/include/
/opt/local/include/
/opt/local/include/polyclipping/
/usr/local/include/
/usr/local/include/polyclipping/
/usr/include
/usr/include/polyclipping/)
FIND_LIBRARY(CLIPPER_LIBRARIES polyclipping
$ENV{CLIPPER_PATH}
$ENV{CLIPPER_PATH}/cpp/
$ENV{CLIPPER_PATH}/cpp/build/
$ENV{CLIPPER_PATH}/lib/
$ENV{CLIPPER_PATH}/lib/polyclipping/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/polyclipping/
${CMAKE_PREFIX_PATH}/lib/
${CMAKE_PREFIX_PATH}/lib/polyclipping/
/opt/local/lib/
/opt/local/lib/polyclipping/
/usr/local/lib/
/usr/local/lib/polyclipping/
/usr/lib/polyclipping)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Clipper
"Clipper library cannot be found. Consider set CLIPPER_PATH environment variable"
CLIPPER_INCLUDE_DIRS
CLIPPER_LIBRARIES)
MARK_AS_ADVANCED(
CLIPPER_INCLUDE_DIRS
CLIPPER_LIBRARIES)
if(CLIPPER_FOUND)
add_library(Clipper::Clipper INTERFACE IMPORTED)
set_target_properties(Clipper::Clipper PROPERTIES INTERFACE_LINK_LIBRARIES ${CLIPPER_LIBRARIES})
set_target_properties(Clipper::Clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS})
#target_link_libraries(Clipper::Clipper INTERFACE ${CLIPPER_LIBRARIES})
#target_include_directories(Clipper::Clipper INTERFACE ${CLIPPER_INCLUDE_DIRS})
endif()

View File

@ -1,141 +0,0 @@
#ifndef LIBNEST2D_H
#define LIBNEST2D_H
// The type of backend should be set conditionally by the cmake configuriation
// for now we set it statically to clipper backend
#ifdef LIBNEST2D_BACKEND_CLIPPER
#include <libnest2d/backends/clipper/geometries.hpp>
#endif
#ifdef LIBNEST2D_OPTIMIZER_NLOPT
// We include the stock optimizers for local and global optimization
#include <libnest2d/optimizers/nlopt/subplex.hpp> // Local subplex for NfpPlacer
#include <libnest2d/optimizers/nlopt/genetic.hpp> // Genetic for min. bounding box
#endif
#include <libnest2d/libnest2d.hpp>
#include <libnest2d/placers/bottomleftplacer.hpp>
#include <libnest2d/placers/nfpplacer.hpp>
#include <libnest2d/selections/firstfit.hpp>
#include <libnest2d/selections/filler.hpp>
#include <libnest2d/selections/djd_heuristic.hpp>
namespace libnest2d {
using Point = PointImpl;
using Coord = TCoord<PointImpl>;
using Box = _Box<PointImpl>;
using Segment = _Segment<PointImpl>;
using Circle = _Circle<PointImpl>;
using Item = _Item<PolygonImpl>;
using Rectangle = _Rectangle<PolygonImpl>;
using PackGroup = _PackGroup<PolygonImpl>;
using FillerSelection = selections::_FillerSelection<PolygonImpl>;
using FirstFitSelection = selections::_FirstFitSelection<PolygonImpl>;
using DJDHeuristic = selections::_DJDHeuristic<PolygonImpl>;
template<class Bin> // Generic placer for arbitrary bin types
using _NfpPlacer = placers::_NofitPolyPlacer<PolygonImpl, Bin>;
// NfpPlacer is with Box bin
using NfpPlacer = _NfpPlacer<Box>;
// This supports only box shaped bins
using BottomLeftPlacer = placers::_BottomLeftPlacer<PolygonImpl>;
#ifdef LIBNEST2D_STATIC
extern template class Nester<NfpPlacer, FirstFitSelection>;
extern template class Nester<BottomLeftPlacer, FirstFitSelection>;
extern template PackGroup Nester<NfpPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
extern template PackGroup Nester<BottomLeftPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
#endif
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Iterator = std::vector<Item>::iterator>
void nest(Iterator from, Iterator to,
const typename Placer::BinType& bin,
Coord dist = 0,
const typename Placer::Config& pconf = {},
const typename Selector::Config& sconf = {})
{
_Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
nester.execute(from, to);
}
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Iterator = std::vector<Item>::iterator>
void nest(Iterator from, Iterator to,
const typename Placer::BinType& bin,
ProgressFunction prg,
StopCondition scond = []() { return false; },
Coord dist = 0,
const typename Placer::Config& pconf = {},
const typename Selector::Config& sconf = {})
{
_Nester<Placer, Selector> nester(bin, dist, pconf, sconf);
if(prg) nester.progressIndicator(prg);
if(scond) nester.stopCondition(scond);
nester.execute(from, to);
}
#ifdef LIBNEST2D_STATIC
extern template class Nester<NfpPlacer, FirstFitSelection>;
extern template class Nester<BottomLeftPlacer, FirstFitSelection>;
extern template void nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box& bin,
Coord dist = 0,
const NfpPlacer::Config& pconf,
const FirstFitSelection::Config& sconf);
extern template void nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box& bin,
ProgressFunction prg,
StopCondition scond,
Coord dist = 0,
const NfpPlacer::Config& pconf,
const FirstFitSelection::Config& sconf);
#endif
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Container = std::vector<Item>>
void nest(Container&& cont,
const typename Placer::BinType& bin,
Coord dist = 0,
const typename Placer::Config& pconf = {},
const typename Selector::Config& sconf = {})
{
nest<Placer, Selector>(cont.begin(), cont.end(), bin, dist, pconf, sconf);
}
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Container = std::vector<Item>>
void nest(Container&& cont,
const typename Placer::BinType& bin,
ProgressFunction prg,
StopCondition scond = []() { return false; },
Coord dist = 0,
const typename Placer::Config& pconf = {},
const typename Selector::Config& sconf = {})
{
nest<Placer, Selector>(cont.begin(), cont.end(), bin, prg, scond, dist,
pconf, sconf);
}
}
#endif // LIBNEST2D_H

View File

@ -1,73 +0,0 @@
if(NOT TARGET clipper) # If there is a clipper target in the parent project we are good to go.
find_package(Clipper 6.1)
if(NOT CLIPPER_FOUND)
find_package(Subversion QUIET)
if(Subversion_FOUND)
set(URL_CLIPPER "https://svn.code.sf.net/p/polyclipping/code/trunk/cpp"
CACHE STRING "Clipper source code repository location.")
message(STATUS "Clipper not found so it will be downloaded.")
# Silently download and build the library in the build dir
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
include(DownloadProject)
download_project( PROJ clipper_library
SVN_REPOSITORY ${URL_CLIPPER}
SVN_REVISION -r540
#SOURCE_SUBDIR cpp
INSTALL_COMMAND ""
CONFIGURE_COMMAND "" # Not working, I will just add the source files
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
# This is not working and I dont have time to fix it
# add_subdirectory(${clipper_library_SOURCE_DIR}/cpp
# ${clipper_library_BINARY_DIR}
# )
add_library(clipperBackend STATIC
${clipper_library_SOURCE_DIR}/clipper.cpp
${clipper_library_SOURCE_DIR}/clipper.hpp)
target_include_directories(clipperBackend INTERFACE ${clipper_library_SOURCE_DIR})
else()
message(FATAL_ERROR "Can't find clipper library and no SVN client found to download.
You can download the clipper sources and define a clipper target in your project, that will work for libnest2d.")
endif()
else()
add_library(clipperBackend INTERFACE)
target_link_libraries(clipperBackend INTERFACE Clipper::Clipper)
endif()
else()
# set(CLIPPER_INCLUDE_DIRS "" PARENT_SCOPE)
# set(CLIPPER_LIBRARIES clipper PARENT_SCOPE)
add_library(clipperBackend INTERFACE)
target_link_libraries(clipperBackend INTERFACE clipper)
endif()
# Clipper backend is not enough on its own, it still needs some functions
# from Boost geometry
if(NOT Boost_FOUND)
find_package(Boost 1.58 REQUIRED)
# TODO automatic download of boost geometry headers
endif()
target_link_libraries(clipperBackend INTERFACE Boost::boost )
#target_sources(ClipperBackend INTERFACE
# ${CMAKE_CURRENT_SOURCE_DIR}/geometries.hpp
# ${CMAKE_CURRENT_SOURCE_DIR}/clipper_polygon.hpp
# ${SRC_DIR}/libnest2d/utils/boost_alg.hpp )
target_compile_definitions(clipperBackend INTERFACE LIBNEST2D_BACKEND_CLIPPER)
# And finally plug the clipperBackend into libnest2d
# target_link_libraries(libnest2d INTERFACE clipperBackend)

View File

@ -81,17 +81,16 @@ inline void offset(PolygonImpl& sh, TCoord<PointImpl> distance, const PolygonTag
using ClipperLib::etClosedPolygon;
using ClipperLib::Paths;
// If the input is not at least a triangle, we can not do this algorithm
if(sh.Contour.size() <= 3 ||
std::any_of(sh.Holes.begin(), sh.Holes.end(),
[](const PathImpl& p) { return p.size() <= 3; })
) throw GeometryException(GeomErr::OFFSET);
ClipperOffset offs;
Paths result;
try {
ClipperOffset offs;
offs.AddPath(sh.Contour, jtMiter, etClosedPolygon);
offs.AddPaths(sh.Holes, jtMiter, etClosedPolygon);
offs.Execute(result, static_cast<double>(distance));
} catch (ClipperLib::clipperException &) {
throw GeometryException(GeomErr::OFFSET);
}
// Offsetting reverts the orientation and also removes the last vertex
// so boost will not have a closed polygon.

View File

@ -1144,7 +1144,7 @@ inline bool isInside(const TBGuest& ibb, const TBHost& box,
auto minY = getY(box.minCorner());
auto maxY = getY(box.maxCorner());
return iminX > minX && imaxX < maxX && iminY > minY && imaxY < maxY;
return iminX >= minX && imaxX <= maxX && iminY >= minY && imaxY <= maxY;
}
template<class S, class TB>

View File

@ -301,7 +301,454 @@ template<class RawShape>
NfpResult<RawShape> nfpSimpleSimple(const RawShape& cstationary,
const RawShape& cother)
{
return {};
// Algorithms are from the original algorithm proposed in paper:
// https://eprints.soton.ac.uk/36850/1/CORMSIS-05-05.pdf
// /////////////////////////////////////////////////////////////////////////
// Algorithm 1: Obtaining the minkowski sum
// /////////////////////////////////////////////////////////////////////////
// I guess this is not a full minkowski sum of the two input polygons by
// definition. This yields a subset that is compatible with the next 2
// algorithms.
using Result = NfpResult<RawShape>;
using Vertex = TPoint<RawShape>;
using Coord = TCoord<Vertex>;
using Edge = _Segment<Vertex>;
namespace sl = shapelike;
using std::signbit;
using std::sort;
using std::vector;
using std::ref;
using std::reference_wrapper;
// TODO The original algorithms expects the stationary polygon in
// counter clockwise and the orbiter in clockwise order.
// So for preventing any further complication, I will make the input
// the way it should be, than make my way around the orientations.
// Reverse the stationary contour to counter clockwise
auto stcont = sl::contour(cstationary);
{
std::reverse(sl::begin(stcont), sl::end(stcont));
stcont.pop_back();
auto it = std::min_element(sl::begin(stcont), sl::end(stcont),
[](const Vertex& v1, const Vertex& v2) {
return getY(v1) < getY(v2);
});
std::rotate(sl::begin(stcont), it, sl::end(stcont));
sl::addVertex(stcont, sl::front(stcont));
}
RawShape stationary;
sl::contour(stationary) = stcont;
// Reverse the orbiter contour to counter clockwise
auto orbcont = sl::contour(cother);
{
std::reverse(orbcont.begin(), orbcont.end());
// Step 1: Make the orbiter reverse oriented
orbcont.pop_back();
auto it = std::min_element(orbcont.begin(), orbcont.end(),
[](const Vertex& v1, const Vertex& v2) {
return getY(v1) < getY(v2);
});
std::rotate(orbcont.begin(), it, orbcont.end());
orbcont.emplace_back(orbcont.front());
for(auto &v : orbcont) v = -v;
}
// Copy the orbiter (contour only), we will have to work on it
RawShape orbiter;
sl::contour(orbiter) = orbcont;
// An edge with additional data for marking it
struct MarkedEdge {
Edge e; Radians turn_angle = 0; bool is_turning_point = false;
MarkedEdge() = default;
MarkedEdge(const Edge& ed, Radians ta, bool tp):
e(ed), turn_angle(ta), is_turning_point(tp) {}
// debug
std::string label;
};
// Container for marked edges
using EdgeList = vector<MarkedEdge>;
EdgeList A, B;
// This is how an edge list is created from the polygons
auto fillEdgeList = [](EdgeList& L, const RawShape& ppoly, int dir) {
auto& poly = sl::contour(ppoly);
L.reserve(sl::contourVertexCount(poly));
if(dir > 0) {
auto it = poly.begin();
auto nextit = std::next(it);
double turn_angle = 0;
bool is_turn_point = false;
while(nextit != poly.end()) {
L.emplace_back(Edge(*it, *nextit), turn_angle, is_turn_point);
it++; nextit++;
}
} else {
auto it = sl::rbegin(poly);
auto nextit = std::next(it);
double turn_angle = 0;
bool is_turn_point = false;
while(nextit != sl::rend(poly)) {
L.emplace_back(Edge(*it, *nextit), turn_angle, is_turn_point);
it++; nextit++;
}
}
auto getTurnAngle = [](const Edge& e1, const Edge& e2) {
auto phi = e1.angleToXaxis();
auto phi_prev = e2.angleToXaxis();
auto turn_angle = phi-phi_prev;
if(turn_angle > Pi) turn_angle -= TwoPi;
if(turn_angle < -Pi) turn_angle += TwoPi;
return turn_angle;
};
auto eit = L.begin();
auto enext = std::next(eit);
eit->turn_angle = getTurnAngle(L.front().e, L.back().e);
while(enext != L.end()) {
enext->turn_angle = getTurnAngle( enext->e, eit->e);
eit->is_turning_point =
signbit(enext->turn_angle) != signbit(eit->turn_angle);
++eit; ++enext;
}
L.back().is_turning_point = signbit(L.back().turn_angle) !=
signbit(L.front().turn_angle);
};
// Step 2: Fill the edgelists
fillEdgeList(A, stationary, 1);
fillEdgeList(B, orbiter, 1);
int i = 1;
for(MarkedEdge& me : A) {
std::cout << "a" << i << ":\n\t"
<< getX(me.e.first()) << " " << getY(me.e.first()) << "\n\t"
<< getX(me.e.second()) << " " << getY(me.e.second()) << "\n\t"
<< "Turning point: " << (me.is_turning_point ? "yes" : "no")
<< std::endl;
me.label = "a"; me.label += std::to_string(i);
i++;
}
i = 1;
for(MarkedEdge& me : B) {
std::cout << "b" << i << ":\n\t"
<< getX(me.e.first()) << " " << getY(me.e.first()) << "\n\t"
<< getX(me.e.second()) << " " << getY(me.e.second()) << "\n\t"
<< "Turning point: " << (me.is_turning_point ? "yes" : "no")
<< std::endl;
me.label = "b"; me.label += std::to_string(i);
i++;
}
// A reference to a marked edge that also knows its container
struct MarkedEdgeRef {
reference_wrapper<MarkedEdge> eref;
reference_wrapper<vector<MarkedEdgeRef>> container;
Coord dir = 1; // Direction modifier
inline Radians angleX() const { return eref.get().e.angleToXaxis(); }
inline const Edge& edge() const { return eref.get().e; }
inline Edge& edge() { return eref.get().e; }
inline bool isTurningPoint() const {
return eref.get().is_turning_point;
}
inline bool isFrom(const vector<MarkedEdgeRef>& cont ) {
return &(container.get()) == &cont;
}
inline bool eq(const MarkedEdgeRef& mr) {
return &(eref.get()) == &(mr.eref.get());
}
MarkedEdgeRef(reference_wrapper<MarkedEdge> er,
reference_wrapper<vector<MarkedEdgeRef>> ec):
eref(er), container(ec), dir(1) {}
MarkedEdgeRef(reference_wrapper<MarkedEdge> er,
reference_wrapper<vector<MarkedEdgeRef>> ec,
Coord d):
eref(er), container(ec), dir(d) {}
};
using EdgeRefList = vector<MarkedEdgeRef>;
// Comparing two marked edges
auto sortfn = [](const MarkedEdgeRef& e1, const MarkedEdgeRef& e2) {
return e1.angleX() < e2.angleX();
};
EdgeRefList Aref, Bref; // We create containers for the references
Aref.reserve(A.size()); Bref.reserve(B.size());
// Fill reference container for the stationary polygon
std::for_each(A.begin(), A.end(), [&Aref](MarkedEdge& me) {
Aref.emplace_back( ref(me), ref(Aref) );
});
// Fill reference container for the orbiting polygon
std::for_each(B.begin(), B.end(), [&Bref](MarkedEdge& me) {
Bref.emplace_back( ref(me), ref(Bref) );
});
auto mink = [sortfn] // the Mink(Q, R, direction) sub-procedure
(const EdgeRefList& Q, const EdgeRefList& R, bool positive)
{
// Step 1 "merge sort_list(Q) and sort_list(R) to form merge_list(Q,R)"
// Sort the containers of edge references and merge them.
// Q could be sorted only once and be reused here but we would still
// need to merge it with sorted(R).
EdgeRefList merged;
EdgeRefList S, seq;
merged.reserve(Q.size() + R.size());
merged.insert(merged.end(), R.begin(), R.end());
std::stable_sort(merged.begin(), merged.end(), sortfn);
merged.insert(merged.end(), Q.begin(), Q.end());
std::stable_sort(merged.begin(), merged.end(), sortfn);
// Step 2 "set i = 1, k = 1, direction = 1, s1 = q1"
// we don't use i, instead, q is an iterator into Q. k would be an index
// into the merged sequence but we use "it" as an iterator for that
// here we obtain references for the containers for later comparisons
const auto& Rcont = R.begin()->container.get();
const auto& Qcont = Q.begin()->container.get();
// Set the initial direction
Coord dir = 1;
// roughly i = 1 (so q = Q.begin()) and s1 = q1 so S[0] = q;
if(positive) {
auto q = Q.begin();
S.emplace_back(*q);
// Roughly step 3
std::cout << "merged size: " << merged.size() << std::endl;
auto mit = merged.begin();
for(bool finish = false; !finish && q != Q.end();) {
++q; // "Set i = i + 1"
while(!finish && mit != merged.end()) {
if(mit->isFrom(Rcont)) {
auto s = *mit;
s.dir = dir;
S.emplace_back(s);
}
if(mit->eq(*q)) {
S.emplace_back(*q);
if(mit->isTurningPoint()) dir = -dir;
if(q == Q.begin()) finish = true;
break;
}
mit += dir;
// __nfp::advance(mit, merged, dir > 0);
}
}
} else {
auto q = Q.rbegin();
S.emplace_back(*q);
// Roughly step 3
std::cout << "merged size: " << merged.size() << std::endl;
auto mit = merged.begin();
for(bool finish = false; !finish && q != Q.rend();) {
++q; // "Set i = i + 1"
while(!finish && mit != merged.end()) {
if(mit->isFrom(Rcont)) {
auto s = *mit;
s.dir = dir;
S.emplace_back(s);
}
if(mit->eq(*q)) {
S.emplace_back(*q);
S.back().dir = -1;
if(mit->isTurningPoint()) dir = -dir;
if(q == Q.rbegin()) finish = true;
break;
}
mit += dir;
// __nfp::advance(mit, merged, dir > 0);
}
}
}
// Step 4:
// "Let starting edge r1 be in position si in sequence"
// whaaat? I guess this means the following:
auto it = S.begin();
while(!it->eq(*R.begin())) ++it;
// "Set j = 1, next = 2, direction = 1, seq1 = si"
// we don't use j, seq is expanded dynamically.
dir = 1;
auto next = std::next(R.begin()); seq.emplace_back(*it);
// Step 5:
// "If all si edges have been allocated to seqj" should mean that
// we loop until seq has equal size with S
auto send = it; //it == S.begin() ? it : std::prev(it);
while(it != S.end()) {
++it; if(it == S.end()) it = S.begin();
if(it == send) break;
if(it->isFrom(Qcont)) {
seq.emplace_back(*it); // "If si is from Q, j = j + 1, seqj = si"
// "If si is a turning point in Q,
// direction = - direction, next = next + direction"
if(it->isTurningPoint()) {
dir = -dir;
next += dir;
// __nfp::advance(next, R, dir > 0);
}
}
if(it->eq(*next) /*&& dir == next->dir*/) { // "If si = direction.rnext"
// "j = j + 1, seqj = si, next = next + direction"
seq.emplace_back(*it);
next += dir;
// __nfp::advance(next, R, dir > 0);
}
}
return seq;
};
std::vector<EdgeRefList> seqlist;
seqlist.reserve(Bref.size());
EdgeRefList Bslope = Bref; // copy Bref, we will make a slope diagram
// make the slope diagram of B
std::sort(Bslope.begin(), Bslope.end(), sortfn);
auto slopeit = Bslope.begin(); // search for the first turning point
while(!slopeit->isTurningPoint() && slopeit != Bslope.end()) slopeit++;
if(slopeit == Bslope.end()) {
// no turning point means convex polygon.
seqlist.emplace_back(mink(Aref, Bref, true));
} else {
int dir = 1;
auto firstturn = Bref.begin();
while(!firstturn->eq(*slopeit)) ++firstturn;
assert(firstturn != Bref.end());
EdgeRefList bgroup; bgroup.reserve(Bref.size());
bgroup.emplace_back(*slopeit);
auto b_it = std::next(firstturn);
while(b_it != firstturn) {
if(b_it == Bref.end()) b_it = Bref.begin();
while(!slopeit->eq(*b_it)) {
__nfp::advance(slopeit, Bslope, dir > 0);
}
if(!slopeit->isTurningPoint()) {
bgroup.emplace_back(*slopeit);
} else {
if(!bgroup.empty()) {
if(dir > 0) bgroup.emplace_back(*slopeit);
for(auto& me : bgroup) {
std::cout << me.eref.get().label << ", ";
}
std::cout << std::endl;
seqlist.emplace_back(mink(Aref, bgroup, dir == 1 ? true : false));
bgroup.clear();
if(dir < 0) bgroup.emplace_back(*slopeit);
} else {
bgroup.emplace_back(*slopeit);
}
dir *= -1;
}
++b_it;
}
}
// while(it != Bref.end()) // This is step 3 and step 4 in one loop
// if(it->isTurningPoint()) {
// R = {R.last, it++};
// auto seq = mink(Q, R, orientation);
// // TODO step 6 (should be 5 shouldn't it?): linking edges from A
// // I don't get this step
// seqlist.insert(seqlist.end(), seq.begin(), seq.end());
// orientation = !orientation;
// } else ++it;
// if(seqlist.empty()) seqlist = mink(Q, {Bref.begin(), Bref.end()}, true);
// /////////////////////////////////////////////////////////////////////////
// Algorithm 2: breaking Minkowski sums into track line trips
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// Algorithm 3: finding the boundary of the NFP from track line trips
// /////////////////////////////////////////////////////////////////////////
for(auto& seq : seqlist) {
std::cout << "seqlist size: " << seq.size() << std::endl;
for(auto& s : seq) {
std::cout << (s.dir > 0 ? "" : "-") << s.eref.get().label << ", ";
}
std::cout << std::endl;
}
auto& seq = seqlist.front();
RawShape rsh;
Vertex top_nfp;
std::vector<Edge> edgelist; edgelist.reserve(seq.size());
for(auto& s : seq) {
edgelist.emplace_back(s.eref.get().e);
}
__nfp::buildPolygon(edgelist, rsh, top_nfp);
return Result(rsh, top_nfp);
}
// Specializable NFP implementation class. Specialize it if you have a faster

View File

@ -1,862 +1,134 @@
#ifndef LIBNEST2D_HPP
#define LIBNEST2D_HPP
#include <memory>
#include <vector>
#include <map>
#include <array>
#include <algorithm>
#include <functional>
// The type of backend should be set conditionally by the cmake configuriation
// for now we set it statically to clipper backend
#ifdef LIBNEST2D_GEOMETRIES_clipper
#include <libnest2d/backends/clipper/geometries.hpp>
#endif
#include <libnest2d/geometry_traits.hpp>
#ifdef LIBNEST2D_OPTIMIZER_nlopt
// We include the stock optimizers for local and global optimization
#include <libnest2d/optimizers/nlopt/subplex.hpp> // Local subplex for NfpPlacer
#include <libnest2d/optimizers/nlopt/genetic.hpp> // Genetic for min. bounding box
#endif
#include <libnest2d/nester.hpp>
#include <libnest2d/placers/bottomleftplacer.hpp>
#include <libnest2d/placers/nfpplacer.hpp>
#include <libnest2d/selections/firstfit.hpp>
#include <libnest2d/selections/filler.hpp>
#include <libnest2d/selections/djd_heuristic.hpp>
namespace libnest2d {
static const constexpr int BIN_ID_UNSET = -1;
/**
* \brief An item to be placed on a bin.
*
* It holds a copy of the original shape object but supports move construction
* from the shape objects if its an rvalue reference. This way we can construct
* the items without the cost of copying a potentially large amount of input.
*
* The results of some calculations are cached for maintaining fast run times.
* For this reason, memory demands are much higher but this should pay off.
*/
template<class RawShape>
class _Item {
using Coord = TCoord<TPoint<RawShape>>;
using Vertex = TPoint<RawShape>;
using Box = _Box<Vertex>;
using VertexConstIterator = typename TContour<RawShape>::const_iterator;
// The original shape that gets encapsulated.
RawShape sh_;
// Transformation data
Vertex translation_{0, 0};
Radians rotation_{0.0};
Coord inflation_{0};
// Info about whether the transformations will have to take place
// This is needed because if floating point is used, it is hard to say
// that a zero angle is not a rotation because of testing for equality.
bool has_rotation_ = false, has_translation_ = false, has_inflation_ = false;
// For caching the calculations as they can get pretty expensive.
mutable RawShape tr_cache_;
mutable bool tr_cache_valid_ = false;
mutable double area_cache_ = 0;
mutable bool area_cache_valid_ = false;
mutable RawShape inflate_cache_;
mutable bool inflate_cache_valid_ = false;
enum class Convexity: char {
UNCHECKED,
C_TRUE,
C_FALSE
};
mutable Convexity convexity_ = Convexity::UNCHECKED;
mutable VertexConstIterator rmt_; // rightmost top vertex
mutable VertexConstIterator lmb_; // leftmost bottom vertex
mutable bool rmt_valid_ = false, lmb_valid_ = false;
mutable struct BBCache {
Box bb; bool valid;
BBCache(): valid(false) {}
} bb_cache_;
int binid_{BIN_ID_UNSET}, priority_{0};
bool fixed_{false};
public:
/// The type of the shape which was handed over as the template argument.
using ShapeType = RawShape;
/**
* \brief Iterator type for the outer vertices.
*
* Only const iterators can be used. The _Item type is not intended to
* modify the carried shapes from the outside. The main purpose of this type
* is to cache the calculation results from the various operators it
* supports. Giving out a non const iterator would make it impossible to
* perform correct cache invalidation.
*/
using Iterator = VertexConstIterator;
/**
* @brief Get the orientation of the polygon.
*
* The orientation have to be specified as a specialization of the
* OrientationType struct which has a Value constant.
*
* @return The orientation type identifier for the _Item type.
*/
static BP2D_CONSTEXPR Orientation orientation() {
return OrientationType<RawShape>::Value;
}
/**
* @brief Constructing an _Item form an existing raw shape. The shape will
* be copied into the _Item object.
* @param sh The original shape object.
*/
explicit inline _Item(const RawShape& sh): sh_(sh) {}
/**
* @brief Construction of an item by moving the content of the raw shape,
* assuming that it supports move semantics.
* @param sh The original shape object.
*/
explicit inline _Item(RawShape&& sh): sh_(std::move(sh)) {}
/**
* @brief Create an item from an initializer list.
* @param il The initializer list of vertices.
*/
inline _Item(const std::initializer_list< Vertex >& il):
sh_(sl::create<RawShape>(il)) {}
inline _Item(const TContour<RawShape>& contour,
const THolesContainer<RawShape>& holes = {}):
sh_(sl::create<RawShape>(contour, holes)) {}
inline _Item(TContour<RawShape>&& contour,
THolesContainer<RawShape>&& holes):
sh_(sl::create<RawShape>(std::move(contour), std::move(holes))) {}
inline bool isFixed() const noexcept { return fixed_; }
inline void markAsFixed(bool fixed = true) { fixed_ = fixed; }
inline void binId(int idx) { binid_ = idx; }
inline int binId() const noexcept { return binid_; }
inline void priority(int p) { priority_ = p; }
inline int priority() const noexcept { return priority_; }
/**
* @brief Convert the polygon to string representation. The format depends
* on the implementation of the polygon.
* @return
*/
inline std::string toString() const
{
return sl::toString(sh_);
}
/// Iterator tho the first contour vertex in the polygon.
inline Iterator begin() const
{
return sl::cbegin(sh_);
}
/// Alias to begin()
inline Iterator cbegin() const
{
return sl::cbegin(sh_);
}
/// Iterator to the last contour vertex.
inline Iterator end() const
{
return sl::cend(sh_);
}
/// Alias to end()
inline Iterator cend() const
{
return sl::cend(sh_);
}
/**
* @brief Get a copy of an outer vertex within the carried shape.
*
* Note that the vertex considered here is taken from the original shape
* that this item is constructed from. This means that no transformation is
* applied to the shape in this call.
*
* @param idx The index of the requested vertex.
* @return A copy of the requested vertex.
*/
inline Vertex vertex(unsigned long idx) const
{
return sl::vertex(sh_, idx);
}
/**
* @brief Modify a vertex.
*
* Note that this method will invalidate every cached calculation result
* including polygon offset and transformations.
*
* @param idx The index of the requested vertex.
* @param v The new vertex data.
*/
inline void setVertex(unsigned long idx, const Vertex& v )
{
invalidateCache();
sl::vertex(sh_, idx) = v;
}
/**
* @brief Calculate the shape area.
*
* The method returns absolute value and does not reflect polygon
* orientation. The result is cached, subsequent calls will have very little
* cost.
* @return The shape area in floating point double precision.
*/
inline double area() const {
double ret ;
if(area_cache_valid_) ret = area_cache_;
else {
ret = sl::area(infaltedShape());
area_cache_ = ret;
area_cache_valid_ = true;
}
return ret;
}
inline bool isContourConvex() const {
bool ret = false;
switch(convexity_) {
case Convexity::UNCHECKED:
ret = sl::isConvex(sl::contour(transformedShape()));
convexity_ = ret? Convexity::C_TRUE : Convexity::C_FALSE;
break;
case Convexity::C_TRUE: ret = true; break;
case Convexity::C_FALSE:;
}
return ret;
}
inline bool isHoleConvex(unsigned /*holeidx*/) const {
return false;
}
inline bool areHolesConvex() const {
return false;
}
/// The number of the outer ring vertices.
inline size_t vertexCount() const {
return sl::contourVertexCount(sh_);
}
inline size_t holeCount() const {
return sl::holeCount(sh_);
}
/**
* @brief isPointInside
* @param p
* @return
*/
inline bool isInside(const Vertex& p) const
{
return sl::isInside(p, transformedShape());
}
inline bool isInside(const _Item& sh) const
{
return sl::isInside(transformedShape(), sh.transformedShape());
}
inline bool isInside(const RawShape& sh) const
{
return sl::isInside(transformedShape(), sh);
}
inline bool isInside(const _Box<TPoint<RawShape>>& box) const;
inline bool isInside(const _Circle<TPoint<RawShape>>& box) const;
inline void translate(const Vertex& d) BP2D_NOEXCEPT
{
translation(translation() + d);
}
inline void rotate(const Radians& rads) BP2D_NOEXCEPT
{
rotation(rotation() + rads);
}
inline void inflation(Coord distance) BP2D_NOEXCEPT
{
inflation_ = distance;
has_inflation_ = true;
invalidateCache();
}
inline Coord inflation() const BP2D_NOEXCEPT {
return inflation_;
}
inline void inflate(Coord distance) BP2D_NOEXCEPT
{
inflation(inflation() + distance);
}
inline Radians rotation() const BP2D_NOEXCEPT
{
return rotation_;
}
inline TPoint<RawShape> translation() const BP2D_NOEXCEPT
{
return translation_;
}
inline void rotation(Radians rot) BP2D_NOEXCEPT
{
if(rotation_ != rot) {
rotation_ = rot; has_rotation_ = true; tr_cache_valid_ = false;
rmt_valid_ = false; lmb_valid_ = false;
bb_cache_.valid = false;
}
}
inline void translation(const TPoint<RawShape>& tr) BP2D_NOEXCEPT
{
if(translation_ != tr) {
translation_ = tr; has_translation_ = true; tr_cache_valid_ = false;
//bb_cache_.valid = false;
}
}
inline const RawShape& transformedShape() const
{
if(tr_cache_valid_) return tr_cache_;
RawShape cpy = infaltedShape();
if(has_rotation_) sl::rotate(cpy, rotation_);
if(has_translation_) sl::translate(cpy, translation_);
tr_cache_ = cpy; tr_cache_valid_ = true;
rmt_valid_ = false; lmb_valid_ = false;
return tr_cache_;
}
inline operator RawShape() const
{
return transformedShape();
}
inline const RawShape& rawShape() const BP2D_NOEXCEPT
{
return sh_;
}
inline void resetTransformation() BP2D_NOEXCEPT
{
has_translation_ = false; has_rotation_ = false; has_inflation_ = false;
invalidateCache();
}
inline Box boundingBox() const {
if(!bb_cache_.valid) {
if(!has_rotation_)
bb_cache_.bb = sl::boundingBox(infaltedShape());
else {
// TODO make sure this works
auto rotsh = infaltedShape();
sl::rotate(rotsh, rotation_);
bb_cache_.bb = sl::boundingBox(rotsh);
}
bb_cache_.valid = true;
}
auto &bb = bb_cache_.bb; auto &tr = translation_;
return {bb.minCorner() + tr, bb.maxCorner() + tr };
}
inline Vertex referenceVertex() const {
return rightmostTopVertex();
}
inline Vertex rightmostTopVertex() const {
if(!rmt_valid_ || !tr_cache_valid_) { // find max x and max y vertex
auto& tsh = transformedShape();
rmt_ = std::max_element(sl::cbegin(tsh), sl::cend(tsh), vsort);
rmt_valid_ = true;
}
return *rmt_;
}
inline Vertex leftmostBottomVertex() const {
if(!lmb_valid_ || !tr_cache_valid_) { // find min x and min y vertex
auto& tsh = transformedShape();
lmb_ = std::min_element(sl::cbegin(tsh), sl::cend(tsh), vsort);
lmb_valid_ = true;
}
return *lmb_;
}
//Static methods:
inline static bool intersects(const _Item& sh1, const _Item& sh2)
{
return sl::intersects(sh1.transformedShape(),
sh2.transformedShape());
}
inline static bool touches(const _Item& sh1, const _Item& sh2)
{
return sl::touches(sh1.transformedShape(),
sh2.transformedShape());
}
private:
inline const RawShape& infaltedShape() const {
if(has_inflation_ ) {
if(inflate_cache_valid_) return inflate_cache_;
inflate_cache_ = sh_;
sl::offset(inflate_cache_, inflation_);
inflate_cache_valid_ = true;
return inflate_cache_;
}
return sh_;
}
inline void invalidateCache() const BP2D_NOEXCEPT
{
tr_cache_valid_ = false;
lmb_valid_ = false; rmt_valid_ = false;
area_cache_valid_ = false;
inflate_cache_valid_ = false;
bb_cache_.valid = false;
convexity_ = Convexity::UNCHECKED;
}
static inline bool vsort(const Vertex& v1, const Vertex& v2)
{
TCompute<Vertex> x1 = getX(v1), x2 = getX(v2);
TCompute<Vertex> y1 = getY(v1), y2 = getY(v2);
return y1 == y2 ? x1 < x2 : y1 < y2;
}
using Point = PointImpl;
using Coord = TCoord<PointImpl>;
using Box = _Box<PointImpl>;
using Segment = _Segment<PointImpl>;
using Circle = _Circle<PointImpl>;
using Item = _Item<PolygonImpl>;
using Rectangle = _Rectangle<PolygonImpl>;
using PackGroup = _PackGroup<PolygonImpl>;
using FillerSelection = selections::_FillerSelection<PolygonImpl>;
using FirstFitSelection = selections::_FirstFitSelection<PolygonImpl>;
using DJDHeuristic = selections::_DJDHeuristic<PolygonImpl>;
template<class Bin> // Generic placer for arbitrary bin types
using _NfpPlacer = placers::_NofitPolyPlacer<PolygonImpl, Bin>;
// NfpPlacer is with Box bin
using NfpPlacer = _NfpPlacer<Box>;
// This supports only box shaped bins
using BottomLeftPlacer = placers::_BottomLeftPlacer<PolygonImpl>;
#ifdef LIBNEST2D_STATIC
extern template class _Nester<NfpPlacer, FirstFitSelection>;
extern template class _Nester<BottomLeftPlacer, FirstFitSelection>;
extern template std::size_t _Nester<NfpPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
extern template std::size_t _Nester<BottomLeftPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
#endif
template<class Placer = NfpPlacer, class Selector = FirstFitSelection>
struct NestConfig {
typename Placer::Config placer_config;
typename Selector::Config selector_config;
using Placement = typename Placer::Config;
using Selection = typename Selector::Config;
NestConfig() = default;
NestConfig(const typename Placer::Config &cfg) : placer_config{cfg} {}
NestConfig(const typename Selector::Config &cfg) : selector_config{cfg} {}
NestConfig(const typename Placer::Config & pcfg,
const typename Selector::Config &scfg)
: placer_config{pcfg}, selector_config{scfg} {}
};
/**
* \brief Subclass of _Item for regular rectangle items.
*/
template<class RawShape>
class _Rectangle: public _Item<RawShape> {
using _Item<RawShape>::vertex;
using TO = Orientation;
public:
struct NestControl {
ProgressFunction progressfn;
StopCondition stopcond = []{ return false; };
using Unit = TCoord<TPoint<RawShape>>;
template<TO o = OrientationType<RawShape>::Value>
inline _Rectangle(Unit width, Unit height,
// disable this ctor if o != CLOCKWISE
enable_if_t< o == TO::CLOCKWISE, int> = 0 ):
_Item<RawShape>( sl::create<RawShape>( {
{0, 0},
{0, height},
{width, height},
{width, 0},
{0, 0}
} ))
{
}
template<TO o = OrientationType<RawShape>::Value>
inline _Rectangle(Unit width, Unit height,
// disable this ctor if o != COUNTER_CLOCKWISE
enable_if_t< o == TO::COUNTER_CLOCKWISE, int> = 0 ):
_Item<RawShape>( sl::create<RawShape>( {
{0, 0},
{width, 0},
{width, height},
{0, height},
{0, 0}
} ))
{
}
inline Unit width() const BP2D_NOEXCEPT {
return getX(vertex(2));
}
inline Unit height() const BP2D_NOEXCEPT {
return getY(vertex(2));
}
NestControl() = default;
NestControl(ProgressFunction pr) : progressfn{std::move(pr)} {}
NestControl(StopCondition sc) : stopcond{std::move(sc)} {}
NestControl(ProgressFunction pr, StopCondition sc)
: progressfn{std::move(pr)}, stopcond{std::move(sc)}
{}
};
template<class RawShape>
inline bool _Item<RawShape>::isInside(const _Box<TPoint<RawShape>>& box) const {
return sl::isInside(boundingBox(), box);
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Iterator = std::vector<Item>::iterator>
std::size_t nest(Iterator from, Iterator to,
const typename Placer::BinType & bin,
Coord dist = 0,
const NestConfig<Placer, Selector> &cfg = {},
NestControl ctl = {})
{
_Nester<Placer, Selector> nester{bin, dist, cfg.placer_config, cfg.selector_config};
if(ctl.progressfn) nester.progressIndicator(ctl.progressfn);
if(ctl.stopcond) nester.stopCondition(ctl.stopcond);
return nester.execute(from, to);
}
template<class RawShape> inline bool
_Item<RawShape>::isInside(const _Circle<TPoint<RawShape>>& circ) const {
return sl::isInside(transformedShape(), circ);
#ifdef LIBNEST2D_STATIC
extern template class _Nester<NfpPlacer, FirstFitSelection>;
extern template class _Nester<BottomLeftPlacer, FirstFitSelection>;
extern template std::size_t nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box & bin,
Coord dist,
const NestConfig<NfpPlacer, FirstFitSelection> &cfg,
NestControl ctl);
extern template std::size_t nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box & bin,
Coord dist,
const NestConfig<BottomLeftPlacer, FirstFitSelection> &cfg,
NestControl ctl);
#endif
template<class Placer = NfpPlacer,
class Selector = FirstFitSelection,
class Container = std::vector<Item>>
std::size_t nest(Container&& cont,
const typename Placer::BinType & bin,
Coord dist = 0,
const NestConfig<Placer, Selector> &cfg = {},
NestControl ctl = {})
{
return nest<Placer, Selector>(cont.begin(), cont.end(), bin, dist, cfg, ctl);
}
template<class RawShape> using _ItemRef = std::reference_wrapper<_Item<RawShape>>;
template<class RawShape> using _ItemGroup = std::vector<_ItemRef<RawShape>>;
/**
* \brief A list of packed item vectors. Each vector represents a bin.
*/
template<class RawShape>
using _PackGroup = std::vector<std::vector<_ItemRef<RawShape>>>;
template<class Iterator>
struct ConstItemRange {
Iterator from;
Iterator to;
bool valid = false;
ConstItemRange() = default;
ConstItemRange(Iterator f, Iterator t): from(f), to(t), valid(true) {}
};
template<class Container>
inline ConstItemRange<typename Container::const_iterator>
rem(typename Container::const_iterator it, const Container& cont) {
return {std::next(it), cont.end()};
}
/**
* \brief A wrapper interface (trait) class for any placement strategy provider.
*
* If a client wants to use its own placement algorithm, all it has to do is to
* specialize this class template and define all the ten methods it has. It can
* use the strategies::PlacerBoilerplace class for creating a new placement
* strategy where only the constructor and the trypack method has to be provided
* and it will work out of the box.
*/
template<class PlacementStrategy>
class PlacementStrategyLike {
PlacementStrategy impl_;
public:
using RawShape = typename PlacementStrategy::ShapeType;
/// The item type that the placer works with.
using Item = _Item<RawShape>;
/// The placer's config type. Should be a simple struct but can be anything.
using Config = typename PlacementStrategy::Config;
/**
* \brief The type of the bin that the placer works with.
*
* Can be a box or an arbitrary shape or just a width or height without a
* second dimension if an infinite bin is considered.
*/
using BinType = typename PlacementStrategy::BinType;
/**
* \brief Pack result that can be used to accept or discard it. See trypack
* method.
*/
using PackResult = typename PlacementStrategy::PackResult;
using ItemGroup = _ItemGroup<RawShape>;
using DefaultIterator = typename ItemGroup::const_iterator;
/**
* @brief Constructor taking the bin and an optional configuration.
* @param bin The bin object whose type is defined by the placement strategy.
* @param config The configuration for the particular placer.
*/
explicit PlacementStrategyLike(const BinType& bin,
const Config& config = Config()):
impl_(bin)
{
configure(config);
}
/**
* @brief Provide a different configuration for the placer.
*
* Note that it depends on the particular placer implementation how it
* reacts to config changes in the middle of a calculation.
*
* @param config The configuration object defined by the placement strategy.
*/
inline void configure(const Config& config) { impl_.configure(config); }
/**
* Try to pack an item with a result object that contains the packing
* information for later accepting it.
*
* \param item_store A container of items that are intended to be packed
* later. Can be used by the placer to switch tactics. When it's knows that
* many items will come a greedy strategy may not be the best.
* \param from The iterator to the item from which the packing should start,
* including the pointed item
* \param count How many items should be packed. If the value is 1, than
* just the item pointed to by "from" argument should be packed.
*/
template<class Iter = DefaultIterator>
inline PackResult trypack(
Item& item,
const ConstItemRange<Iter>& remaining = ConstItemRange<Iter>())
{
return impl_.trypack(item, remaining);
}
/**
* @brief A method to accept a previously tried item (or items).
*
* If the pack result is a failure the method should ignore it.
* @param r The result of a previous trypack call.
*/
inline void accept(PackResult& r) { impl_.accept(r); }
/**
* @brief pack Try to pack and immediately accept it on success.
*
* A default implementation would be to call
* { auto&& r = trypack(...); accept(r); return r; } but we should let the
* implementor of the placement strategy to harvest any optimizations from
* the absence of an intermediate step. The above version can still be used
* in the implementation.
*
* @param item The item to pack.
* @return Returns true if the item was packed or false if it could not be
* packed.
*/
template<class Range = ConstItemRange<DefaultIterator>>
inline bool pack(
Item& item,
const Range& remaining = Range())
{
return impl_.pack(item, remaining);
}
/**
* This method makes possible to "preload" some items into the placer. It
* will not move these items but will consider them as already packed.
*/
inline void preload(const ItemGroup& packeditems)
{
impl_.preload(packeditems);
}
/// Unpack the last element (remove it from the list of packed items).
inline void unpackLast() { impl_.unpackLast(); }
/// Get the bin object.
inline const BinType& bin() const { return impl_.bin(); }
/// Set a new bin object.
inline void bin(const BinType& bin) { impl_.bin(bin); }
/// Get the packed items.
inline ItemGroup getItems() { return impl_.getItems(); }
/// Clear the packed items so a new session can be started.
inline void clearItems() { impl_.clearItems(); }
inline double filledArea() const { return impl_.filledArea(); }
};
// The progress function will be called with the number of placed items
using ProgressFunction = std::function<void(unsigned)>;
using StopCondition = std::function<bool(void)>;
/**
* A wrapper interface (trait) class for any selections strategy provider.
*/
template<class SelectionStrategy>
class SelectionStrategyLike {
SelectionStrategy impl_;
public:
using RawShape = typename SelectionStrategy::ShapeType;
using Item = _Item<RawShape>;
using PackGroup = _PackGroup<RawShape>;
using Config = typename SelectionStrategy::Config;
/**
* @brief Provide a different configuration for the selection strategy.
*
* Note that it depends on the particular placer implementation how it
* reacts to config changes in the middle of a calculation.
*
* @param config The configuration object defined by the selection strategy.
*/
inline void configure(const Config& config) {
impl_.configure(config);
}
/**
* @brief A function callback which should be called whenever an item or
* a group of items where successfully packed.
* @param fn A function callback object taking one unsigned integer as the
* number of the remaining items to pack.
*/
void progressIndicator(ProgressFunction fn) { impl_.progressIndicator(fn); }
void stopCondition(StopCondition cond) { impl_.stopCondition(cond); }
/**
* \brief A method to start the calculation on the input sequence.
*
* \tparam TPlacer The only mandatory template parameter is the type of
* placer compatible with the PlacementStrategyLike interface.
*
* \param first, last The first and last iterator if the input sequence. It
* can be only an iterator of a type convertible to Item.
* \param bin. The shape of the bin. It has to be supported by the placement
* strategy.
* \param An optional config object for the placer.
*/
template<class TPlacer, class TIterator,
class TBin = typename PlacementStrategyLike<TPlacer>::BinType,
class PConfig = typename PlacementStrategyLike<TPlacer>::Config>
inline void packItems(
TIterator first,
TIterator last,
TBin&& bin,
PConfig&& config = PConfig() )
{
impl_.template packItems<TPlacer>(first, last,
std::forward<TBin>(bin),
std::forward<PConfig>(config));
}
/**
* @brief Get the items for a particular bin.
* @param binIndex The index of the requested bin.
* @return Returns a list of all items packed into the requested bin.
*/
inline const PackGroup& getResult() const {
return impl_.getResult();
}
void clear() { impl_.clear(); }
};
/**
* The _Nester is the front-end class for the libnest2d library. It takes the
* input items and changes their transformations to be inside the provided bin.
*/
template<class PlacementStrategy, class SelectionStrategy >
class _Nester {
using TSel = SelectionStrategyLike<SelectionStrategy>;
TSel selector_;
public:
using Item = typename PlacementStrategy::Item;
using ShapeType = typename Item::ShapeType;
using ItemRef = std::reference_wrapper<Item>;
using TPlacer = PlacementStrategyLike<PlacementStrategy>;
using BinType = typename TPlacer::BinType;
using PlacementConfig = typename TPlacer::Config;
using SelectionConfig = typename TSel::Config;
using Coord = TCoord<TPoint<typename Item::ShapeType>>;
using PackGroup = _PackGroup<typename Item::ShapeType>;
using ResultType = PackGroup;
private:
BinType bin_;
PlacementConfig pconfig_;
Coord min_obj_distance_;
using SItem = typename SelectionStrategy::Item;
using TPItem = remove_cvref_t<Item>;
using TSItem = remove_cvref_t<SItem>;
StopCondition stopfn_;
template<class It> using TVal = remove_ref_t<typename It::value_type>;
template<class It, class Out>
using ItemIteratorOnly =
enable_if_t<std::is_convertible<TVal<It>&, TPItem&>::value, Out>;
public:
/**
* \brief Constructor taking the bin as the only mandatory parameter.
*
* \param bin The bin shape that will be used by the placers. The type
* of the bin should be one that is supported by the placer type.
*/
template<class TBinType = BinType,
class PConf = PlacementConfig,
class SConf = SelectionConfig>
_Nester(TBinType&& bin, Coord min_obj_distance = 0,
const PConf& pconfig = PConf(), const SConf& sconfig = SConf()):
bin_(std::forward<TBinType>(bin)),
pconfig_(pconfig),
min_obj_distance_(min_obj_distance)
{
static_assert( std::is_same<TPItem, TSItem>::value,
"Incompatible placement and selection strategy!");
selector_.configure(sconfig);
}
void configure(const PlacementConfig& pconf) { pconfig_ = pconf; }
void configure(const SelectionConfig& sconf) { selector_.configure(sconf); }
void configure(const PlacementConfig& pconf, const SelectionConfig& sconf)
{
pconfig_ = pconf;
selector_.configure(sconf);
}
void configure(const SelectionConfig& sconf, const PlacementConfig& pconf)
{
pconfig_ = pconf;
selector_.configure(sconf);
}
/**
* \brief Arrange an input sequence of _Item-s.
*
* To get the result, call the translation(), rotation() and binId()
* methods of each item. If only the transformed polygon is needed, call
* transformedShape() to get the properly transformed shapes.
*
* The number of groups in the pack group is the number of bins opened by
* the selection algorithm.
*/
template<class It>
inline ItemIteratorOnly<It, void> execute(It from, It to)
{
auto infl = static_cast<Coord>(std::ceil(min_obj_distance_/2.0));
if(infl > 0) std::for_each(from, to, [this, infl](Item& item) {
item.inflate(infl);
});
selector_.template packItems<PlacementStrategy>(
from, to, bin_, pconfig_);
if(min_obj_distance_ > 0) std::for_each(from, to, [infl](Item& item) {
item.inflate(-infl);
});
}
/// Set a progress indicator function object for the selector.
inline _Nester& progressIndicator(ProgressFunction func)
{
selector_.progressIndicator(func); return *this;
}
/// Set a predicate to tell when to abort nesting.
inline _Nester& stopCondition(StopCondition fn)
{
stopfn_ = fn; selector_.stopCondition(fn); return *this;
}
inline const PackGroup& lastResult() const
{
return selector_.getResult();
}
};
}
#endif // LIBNEST2D_HPP

View File

@ -0,0 +1,869 @@
#ifndef NESTER_HPP
#define NESTER_HPP
#include <memory>
#include <vector>
#include <map>
#include <array>
#include <algorithm>
#include <functional>
#include <libnest2d/geometry_traits.hpp>
namespace libnest2d {
static const constexpr int BIN_ID_UNSET = -1;
/**
* \brief An item to be placed on a bin.
*
* It holds a copy of the original shape object but supports move construction
* from the shape objects if its an rvalue reference. This way we can construct
* the items without the cost of copying a potentially large amount of input.
*
* The results of some calculations are cached for maintaining fast run times.
* For this reason, memory demands are much higher but this should pay off.
*/
template<class RawShape>
class _Item {
using Coord = TCoord<TPoint<RawShape>>;
using Vertex = TPoint<RawShape>;
using Box = _Box<Vertex>;
using VertexConstIterator = typename TContour<RawShape>::const_iterator;
// The original shape that gets encapsulated.
RawShape sh_;
// Transformation data
Vertex translation_{0, 0};
Radians rotation_{0.0};
Coord inflation_{0};
// Info about whether the transformations will have to take place
// This is needed because if floating point is used, it is hard to say
// that a zero angle is not a rotation because of testing for equality.
bool has_rotation_ = false, has_translation_ = false, has_inflation_ = false;
// For caching the calculations as they can get pretty expensive.
mutable RawShape tr_cache_;
mutable bool tr_cache_valid_ = false;
mutable double area_cache_ = 0;
mutable bool area_cache_valid_ = false;
mutable RawShape inflate_cache_;
mutable bool inflate_cache_valid_ = false;
enum class Convexity: char {
UNCHECKED,
C_TRUE,
C_FALSE
};
mutable Convexity convexity_ = Convexity::UNCHECKED;
mutable VertexConstIterator rmt_; // rightmost top vertex
mutable VertexConstIterator lmb_; // leftmost bottom vertex
mutable bool rmt_valid_ = false, lmb_valid_ = false;
mutable struct BBCache {
Box bb; bool valid;
BBCache(): valid(false) {}
} bb_cache_;
int binid_{BIN_ID_UNSET}, priority_{0};
bool fixed_{false};
public:
/// The type of the shape which was handed over as the template argument.
using ShapeType = RawShape;
/**
* \brief Iterator type for the outer vertices.
*
* Only const iterators can be used. The _Item type is not intended to
* modify the carried shapes from the outside. The main purpose of this type
* is to cache the calculation results from the various operators it
* supports. Giving out a non const iterator would make it impossible to
* perform correct cache invalidation.
*/
using Iterator = VertexConstIterator;
/**
* @brief Get the orientation of the polygon.
*
* The orientation have to be specified as a specialization of the
* OrientationType struct which has a Value constant.
*
* @return The orientation type identifier for the _Item type.
*/
static BP2D_CONSTEXPR Orientation orientation() {
return OrientationType<RawShape>::Value;
}
/**
* @brief Constructing an _Item form an existing raw shape. The shape will
* be copied into the _Item object.
* @param sh The original shape object.
*/
explicit inline _Item(const RawShape& sh): sh_(sh) {}
/**
* @brief Construction of an item by moving the content of the raw shape,
* assuming that it supports move semantics.
* @param sh The original shape object.
*/
explicit inline _Item(RawShape&& sh): sh_(std::move(sh)) {}
/**
* @brief Create an item from an initializer list.
* @param il The initializer list of vertices.
*/
inline _Item(const std::initializer_list< Vertex >& il):
sh_(sl::create<RawShape>(il)) {}
inline _Item(const TContour<RawShape>& contour,
const THolesContainer<RawShape>& holes = {}):
sh_(sl::create<RawShape>(contour, holes)) {}
inline _Item(TContour<RawShape>&& contour,
THolesContainer<RawShape>&& holes):
sh_(sl::create<RawShape>(std::move(contour), std::move(holes))) {}
inline bool isFixed() const noexcept { return fixed_; }
inline void markAsFixedInBin(int binid)
{
fixed_ = binid >= 0;
binid_ = binid;
}
inline void binId(int idx) { binid_ = idx; }
inline int binId() const noexcept { return binid_; }
inline void priority(int p) { priority_ = p; }
inline int priority() const noexcept { return priority_; }
/**
* @brief Convert the polygon to string representation. The format depends
* on the implementation of the polygon.
* @return
*/
inline std::string toString() const
{
return sl::toString(sh_);
}
/// Iterator tho the first contour vertex in the polygon.
inline Iterator begin() const
{
return sl::cbegin(sh_);
}
/// Alias to begin()
inline Iterator cbegin() const
{
return sl::cbegin(sh_);
}
/// Iterator to the last contour vertex.
inline Iterator end() const
{
return sl::cend(sh_);
}
/// Alias to end()
inline Iterator cend() const
{
return sl::cend(sh_);
}
/**
* @brief Get a copy of an outer vertex within the carried shape.
*
* Note that the vertex considered here is taken from the original shape
* that this item is constructed from. This means that no transformation is
* applied to the shape in this call.
*
* @param idx The index of the requested vertex.
* @return A copy of the requested vertex.
*/
inline Vertex vertex(unsigned long idx) const
{
return sl::vertex(sh_, idx);
}
/**
* @brief Modify a vertex.
*
* Note that this method will invalidate every cached calculation result
* including polygon offset and transformations.
*
* @param idx The index of the requested vertex.
* @param v The new vertex data.
*/
inline void setVertex(unsigned long idx, const Vertex& v )
{
invalidateCache();
sl::vertex(sh_, idx) = v;
}
/**
* @brief Calculate the shape area.
*
* The method returns absolute value and does not reflect polygon
* orientation. The result is cached, subsequent calls will have very little
* cost.
* @return The shape area in floating point double precision.
*/
inline double area() const {
double ret ;
if(area_cache_valid_) ret = area_cache_;
else {
ret = sl::area(infaltedShape());
area_cache_ = ret;
area_cache_valid_ = true;
}
return ret;
}
inline bool isContourConvex() const {
bool ret = false;
switch(convexity_) {
case Convexity::UNCHECKED:
ret = sl::isConvex(sl::contour(transformedShape()));
convexity_ = ret? Convexity::C_TRUE : Convexity::C_FALSE;
break;
case Convexity::C_TRUE: ret = true; break;
case Convexity::C_FALSE:;
}
return ret;
}
inline bool isHoleConvex(unsigned /*holeidx*/) const {
return false;
}
inline bool areHolesConvex() const {
return false;
}
/// The number of the outer ring vertices.
inline size_t vertexCount() const {
return sl::contourVertexCount(sh_);
}
inline size_t holeCount() const {
return sl::holeCount(sh_);
}
/**
* @brief isPointInside
* @param p
* @return
*/
inline bool isInside(const Vertex& p) const
{
return sl::isInside(p, transformedShape());
}
inline bool isInside(const _Item& sh) const
{
return sl::isInside(transformedShape(), sh.transformedShape());
}
inline bool isInside(const RawShape& sh) const
{
return sl::isInside(transformedShape(), sh);
}
inline bool isInside(const _Box<TPoint<RawShape>>& box) const;
inline bool isInside(const _Circle<TPoint<RawShape>>& box) const;
inline void translate(const Vertex& d) BP2D_NOEXCEPT
{
translation(translation() + d);
}
inline void rotate(const Radians& rads) BP2D_NOEXCEPT
{
rotation(rotation() + rads);
}
inline void inflation(Coord distance) BP2D_NOEXCEPT
{
inflation_ = distance;
has_inflation_ = true;
invalidateCache();
}
inline Coord inflation() const BP2D_NOEXCEPT {
return inflation_;
}
inline void inflate(Coord distance) BP2D_NOEXCEPT
{
inflation(inflation() + distance);
}
inline Radians rotation() const BP2D_NOEXCEPT
{
return rotation_;
}
inline TPoint<RawShape> translation() const BP2D_NOEXCEPT
{
return translation_;
}
inline void rotation(Radians rot) BP2D_NOEXCEPT
{
if(rotation_ != rot) {
rotation_ = rot; has_rotation_ = true; tr_cache_valid_ = false;
rmt_valid_ = false; lmb_valid_ = false;
bb_cache_.valid = false;
}
}
inline void translation(const TPoint<RawShape>& tr) BP2D_NOEXCEPT
{
if(translation_ != tr) {
translation_ = tr; has_translation_ = true; tr_cache_valid_ = false;
//bb_cache_.valid = false;
}
}
inline const RawShape& transformedShape() const
{
if(tr_cache_valid_) return tr_cache_;
RawShape cpy = infaltedShape();
if(has_rotation_) sl::rotate(cpy, rotation_);
if(has_translation_) sl::translate(cpy, translation_);
tr_cache_ = cpy; tr_cache_valid_ = true;
rmt_valid_ = false; lmb_valid_ = false;
return tr_cache_;
}
inline operator RawShape() const
{
return transformedShape();
}
inline const RawShape& rawShape() const BP2D_NOEXCEPT
{
return sh_;
}
inline void resetTransformation() BP2D_NOEXCEPT
{
has_translation_ = false; has_rotation_ = false; has_inflation_ = false;
invalidateCache();
}
inline Box boundingBox() const {
if(!bb_cache_.valid) {
if(!has_rotation_)
bb_cache_.bb = sl::boundingBox(infaltedShape());
else {
// TODO make sure this works
auto rotsh = infaltedShape();
sl::rotate(rotsh, rotation_);
bb_cache_.bb = sl::boundingBox(rotsh);
}
bb_cache_.valid = true;
}
auto &bb = bb_cache_.bb; auto &tr = translation_;
return {bb.minCorner() + tr, bb.maxCorner() + tr };
}
inline Vertex referenceVertex() const {
return rightmostTopVertex();
}
inline Vertex rightmostTopVertex() const {
if(!rmt_valid_ || !tr_cache_valid_) { // find max x and max y vertex
auto& tsh = transformedShape();
rmt_ = std::max_element(sl::cbegin(tsh), sl::cend(tsh), vsort);
rmt_valid_ = true;
}
return *rmt_;
}
inline Vertex leftmostBottomVertex() const {
if(!lmb_valid_ || !tr_cache_valid_) { // find min x and min y vertex
auto& tsh = transformedShape();
lmb_ = std::min_element(sl::cbegin(tsh), sl::cend(tsh), vsort);
lmb_valid_ = true;
}
return *lmb_;
}
//Static methods:
inline static bool intersects(const _Item& sh1, const _Item& sh2)
{
return sl::intersects(sh1.transformedShape(),
sh2.transformedShape());
}
inline static bool touches(const _Item& sh1, const _Item& sh2)
{
return sl::touches(sh1.transformedShape(),
sh2.transformedShape());
}
private:
inline const RawShape& infaltedShape() const {
if(has_inflation_ ) {
if(inflate_cache_valid_) return inflate_cache_;
inflate_cache_ = sh_;
sl::offset(inflate_cache_, inflation_);
inflate_cache_valid_ = true;
return inflate_cache_;
}
return sh_;
}
inline void invalidateCache() const BP2D_NOEXCEPT
{
tr_cache_valid_ = false;
lmb_valid_ = false; rmt_valid_ = false;
area_cache_valid_ = false;
inflate_cache_valid_ = false;
bb_cache_.valid = false;
convexity_ = Convexity::UNCHECKED;
}
static inline bool vsort(const Vertex& v1, const Vertex& v2)
{
TCompute<Vertex> x1 = getX(v1), x2 = getX(v2);
TCompute<Vertex> y1 = getY(v1), y2 = getY(v2);
return y1 == y2 ? x1 < x2 : y1 < y2;
}
};
/**
* \brief Subclass of _Item for regular rectangle items.
*/
template<class RawShape>
class _Rectangle: public _Item<RawShape> {
using _Item<RawShape>::vertex;
using TO = Orientation;
public:
using Unit = TCoord<TPoint<RawShape>>;
template<TO o = OrientationType<RawShape>::Value>
inline _Rectangle(Unit width, Unit height,
// disable this ctor if o != CLOCKWISE
enable_if_t< o == TO::CLOCKWISE, int> = 0 ):
_Item<RawShape>( sl::create<RawShape>( {
{0, 0},
{0, height},
{width, height},
{width, 0},
{0, 0}
} ))
{
}
template<TO o = OrientationType<RawShape>::Value>
inline _Rectangle(Unit width, Unit height,
// disable this ctor if o != COUNTER_CLOCKWISE
enable_if_t< o == TO::COUNTER_CLOCKWISE, int> = 0 ):
_Item<RawShape>( sl::create<RawShape>( {
{0, 0},
{width, 0},
{width, height},
{0, height},
{0, 0}
} ))
{
}
inline Unit width() const BP2D_NOEXCEPT {
return getX(vertex(2));
}
inline Unit height() const BP2D_NOEXCEPT {
return getY(vertex(2));
}
};
template<class RawShape>
inline bool _Item<RawShape>::isInside(const _Box<TPoint<RawShape>>& box) const {
return sl::isInside(boundingBox(), box);
}
template<class RawShape> inline bool
_Item<RawShape>::isInside(const _Circle<TPoint<RawShape>>& circ) const {
return sl::isInside(transformedShape(), circ);
}
template<class RawShape> using _ItemRef = std::reference_wrapper<_Item<RawShape>>;
template<class RawShape> using _ItemGroup = std::vector<_ItemRef<RawShape>>;
/**
* \brief A list of packed item vectors. Each vector represents a bin.
*/
template<class RawShape>
using _PackGroup = std::vector<std::vector<_ItemRef<RawShape>>>;
template<class Iterator>
struct ConstItemRange {
Iterator from;
Iterator to;
bool valid = false;
ConstItemRange() = default;
ConstItemRange(Iterator f, Iterator t): from(f), to(t), valid(true) {}
};
template<class Container>
inline ConstItemRange<typename Container::const_iterator>
rem(typename Container::const_iterator it, const Container& cont) {
return {std::next(it), cont.end()};
}
/**
* \brief A wrapper interface (trait) class for any placement strategy provider.
*
* If a client wants to use its own placement algorithm, all it has to do is to
* specialize this class template and define all the ten methods it has. It can
* use the strategies::PlacerBoilerplace class for creating a new placement
* strategy where only the constructor and the trypack method has to be provided
* and it will work out of the box.
*/
template<class PlacementStrategy>
class PlacementStrategyLike {
PlacementStrategy impl_;
public:
using RawShape = typename PlacementStrategy::ShapeType;
/// The item type that the placer works with.
using Item = _Item<RawShape>;
/// The placer's config type. Should be a simple struct but can be anything.
using Config = typename PlacementStrategy::Config;
/**
* \brief The type of the bin that the placer works with.
*
* Can be a box or an arbitrary shape or just a width or height without a
* second dimension if an infinite bin is considered.
*/
using BinType = typename PlacementStrategy::BinType;
/**
* \brief Pack result that can be used to accept or discard it. See trypack
* method.
*/
using PackResult = typename PlacementStrategy::PackResult;
using ItemGroup = _ItemGroup<RawShape>;
using DefaultIterator = typename ItemGroup::const_iterator;
/**
* @brief Constructor taking the bin and an optional configuration.
* @param bin The bin object whose type is defined by the placement strategy.
* @param config The configuration for the particular placer.
*/
explicit PlacementStrategyLike(const BinType& bin,
const Config& config = Config()):
impl_(bin)
{
configure(config);
}
/**
* @brief Provide a different configuration for the placer.
*
* Note that it depends on the particular placer implementation how it
* reacts to config changes in the middle of a calculation.
*
* @param config The configuration object defined by the placement strategy.
*/
inline void configure(const Config& config) { impl_.configure(config); }
/**
* Try to pack an item with a result object that contains the packing
* information for later accepting it.
*
* \param item_store A container of items that are intended to be packed
* later. Can be used by the placer to switch tactics. When it's knows that
* many items will come a greedy strategy may not be the best.
* \param from The iterator to the item from which the packing should start,
* including the pointed item
* \param count How many items should be packed. If the value is 1, than
* just the item pointed to by "from" argument should be packed.
*/
template<class Iter = DefaultIterator>
inline PackResult trypack(
Item& item,
const ConstItemRange<Iter>& remaining = ConstItemRange<Iter>())
{
return impl_.trypack(item, remaining);
}
/**
* @brief A method to accept a previously tried item (or items).
*
* If the pack result is a failure the method should ignore it.
* @param r The result of a previous trypack call.
*/
inline void accept(PackResult& r) { impl_.accept(r); }
/**
* @brief pack Try to pack and immediately accept it on success.
*
* A default implementation would be to call
* { auto&& r = trypack(...); accept(r); return r; } but we should let the
* implementor of the placement strategy to harvest any optimizations from
* the absence of an intermediate step. The above version can still be used
* in the implementation.
*
* @param item The item to pack.
* @return Returns true if the item was packed or false if it could not be
* packed.
*/
template<class Range = ConstItemRange<DefaultIterator>>
inline bool pack(
Item& item,
const Range& remaining = Range())
{
return impl_.pack(item, remaining);
}
/**
* This method makes possible to "preload" some items into the placer. It
* will not move these items but will consider them as already packed.
*/
inline void preload(const ItemGroup& packeditems)
{
impl_.preload(packeditems);
}
/// Unpack the last element (remove it from the list of packed items).
inline void unpackLast() { impl_.unpackLast(); }
/// Get the bin object.
inline const BinType& bin() const { return impl_.bin(); }
/// Set a new bin object.
inline void bin(const BinType& bin) { impl_.bin(bin); }
/// Get the packed items.
inline ItemGroup getItems() { return impl_.getItems(); }
/// Clear the packed items so a new session can be started.
inline void clearItems() { impl_.clearItems(); }
inline double filledArea() const { return impl_.filledArea(); }
};
// The progress function will be called with the number of placed items
using ProgressFunction = std::function<void(unsigned)>;
using StopCondition = std::function<bool(void)>;
/**
* A wrapper interface (trait) class for any selections strategy provider.
*/
template<class SelectionStrategy>
class SelectionStrategyLike {
SelectionStrategy impl_;
public:
using RawShape = typename SelectionStrategy::ShapeType;
using Item = _Item<RawShape>;
using PackGroup = _PackGroup<RawShape>;
using Config = typename SelectionStrategy::Config;
/**
* @brief Provide a different configuration for the selection strategy.
*
* Note that it depends on the particular placer implementation how it
* reacts to config changes in the middle of a calculation.
*
* @param config The configuration object defined by the selection strategy.
*/
inline void configure(const Config& config) {
impl_.configure(config);
}
/**
* @brief A function callback which should be called whenever an item or
* a group of items where successfully packed.
* @param fn A function callback object taking one unsigned integer as the
* number of the remaining items to pack.
*/
void progressIndicator(ProgressFunction fn) { impl_.progressIndicator(fn); }
void stopCondition(StopCondition cond) { impl_.stopCondition(cond); }
/**
* \brief A method to start the calculation on the input sequence.
*
* \tparam TPlacer The only mandatory template parameter is the type of
* placer compatible with the PlacementStrategyLike interface.
*
* \param first, last The first and last iterator if the input sequence. It
* can be only an iterator of a type convertible to Item.
* \param bin. The shape of the bin. It has to be supported by the placement
* strategy.
* \param An optional config object for the placer.
*/
template<class TPlacer, class TIterator,
class TBin = typename PlacementStrategyLike<TPlacer>::BinType,
class PConfig = typename PlacementStrategyLike<TPlacer>::Config>
inline void packItems(
TIterator first,
TIterator last,
TBin&& bin,
PConfig&& config = PConfig() )
{
impl_.template packItems<TPlacer>(first, last,
std::forward<TBin>(bin),
std::forward<PConfig>(config));
}
/**
* @brief Get the items for a particular bin.
* @param binIndex The index of the requested bin.
* @return Returns a list of all items packed into the requested bin.
*/
inline const PackGroup& getResult() const {
return impl_.getResult();
}
void clear() { impl_.clear(); }
};
/**
* The _Nester is the front-end class for the libnest2d library. It takes the
* input items and changes their transformations to be inside the provided bin.
*/
template<class PlacementStrategy, class SelectionStrategy >
class _Nester {
using TSel = SelectionStrategyLike<SelectionStrategy>;
TSel selector_;
public:
using Item = typename PlacementStrategy::Item;
using ShapeType = typename Item::ShapeType;
using ItemRef = std::reference_wrapper<Item>;
using TPlacer = PlacementStrategyLike<PlacementStrategy>;
using BinType = typename TPlacer::BinType;
using PlacementConfig = typename TPlacer::Config;
using SelectionConfig = typename TSel::Config;
using Coord = TCoord<TPoint<typename Item::ShapeType>>;
using PackGroup = _PackGroup<typename Item::ShapeType>;
using ResultType = PackGroup;
private:
BinType bin_;
PlacementConfig pconfig_;
Coord min_obj_distance_;
using SItem = typename SelectionStrategy::Item;
using TPItem = remove_cvref_t<Item>;
using TSItem = remove_cvref_t<SItem>;
StopCondition stopfn_;
template<class It> using TVal = remove_ref_t<typename It::value_type>;
template<class It, class Out>
using ItemIteratorOnly =
enable_if_t<std::is_convertible<TVal<It>&, TPItem&>::value, Out>;
public:
/**
* \brief Constructor taking the bin as the only mandatory parameter.
*
* \param bin The bin shape that will be used by the placers. The type
* of the bin should be one that is supported by the placer type.
*/
template<class TBinType = BinType,
class PConf = PlacementConfig,
class SConf = SelectionConfig>
_Nester(TBinType&& bin, Coord min_obj_distance = 0,
const PConf& pconfig = PConf(), const SConf& sconfig = SConf()):
bin_(std::forward<TBinType>(bin)),
pconfig_(pconfig),
min_obj_distance_(min_obj_distance)
{
static_assert( std::is_same<TPItem, TSItem>::value,
"Incompatible placement and selection strategy!");
selector_.configure(sconfig);
}
void configure(const PlacementConfig& pconf) { pconfig_ = pconf; }
void configure(const SelectionConfig& sconf) { selector_.configure(sconf); }
void configure(const PlacementConfig& pconf, const SelectionConfig& sconf)
{
pconfig_ = pconf;
selector_.configure(sconf);
}
void configure(const SelectionConfig& sconf, const PlacementConfig& pconf)
{
pconfig_ = pconf;
selector_.configure(sconf);
}
/**
* \brief Arrange an input sequence of _Item-s.
*
* To get the result, call the translation(), rotation() and binId()
* methods of each item. If only the transformed polygon is needed, call
* transformedShape() to get the properly transformed shapes.
*
* The number of groups in the pack group is the number of bins opened by
* the selection algorithm.
*/
template<class It>
inline ItemIteratorOnly<It, size_t> execute(It from, It to)
{
auto infl = static_cast<Coord>(std::ceil(min_obj_distance_/2.0));
if(infl > 0) std::for_each(from, to, [this, infl](Item& item) {
item.inflate(infl);
});
selector_.template packItems<PlacementStrategy>(
from, to, bin_, pconfig_);
if(min_obj_distance_ > 0) std::for_each(from, to, [infl](Item& item) {
item.inflate(-infl);
});
return selector_.getResult().size();
}
/// Set a progress indicator function object for the selector.
inline _Nester& progressIndicator(ProgressFunction func)
{
selector_.progressIndicator(func); return *this;
}
/// Set a predicate to tell when to abort nesting.
inline _Nester& stopCondition(StopCondition fn)
{
stopfn_ = fn; selector_.stopCondition(fn); return *this;
}
inline const PackGroup& lastResult() const
{
return selector_.getResult();
}
};
}
#endif // NESTER_HPP

View File

@ -1,61 +0,0 @@
find_package(NLopt 1.4)
if(NOT NLopt_FOUND)
message(STATUS "NLopt not found so downloading "
"and automatic build is performed...")
include(DownloadProject)
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
set(URL_NLOPT "https://github.com/stevengj/nlopt.git"
CACHE STRING "Location of the nlopt git repository")
# set(NLopt_DIR ${CMAKE_BINARY_DIR}/nlopt)
include(DownloadProject)
download_project( PROJ nlopt
GIT_REPOSITORY ${URL_NLOPT}
GIT_TAG v2.5.0
# CMAKE_CACHE_ARGS -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${NLopt_DIR}
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
set(SHARED_LIBS_STATE BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(NLOPT_PYTHON OFF CACHE BOOL "" FORCE)
set(NLOPT_OCTAVE OFF CACHE BOOL "" FORCE)
set(NLOPT_MATLAB OFF CACHE BOOL "" FORCE)
set(NLOPT_GUILE OFF CACHE BOOL "" FORCE)
set(NLOPT_SWIG OFF CACHE BOOL "" FORCE)
set(NLOPT_LINK_PYTHON OFF CACHE BOOL "" FORCE)
add_subdirectory(${nlopt_SOURCE_DIR} ${nlopt_BINARY_DIR})
set(NLopt_LIBS nlopt)
set(NLopt_INCLUDE_DIR ${nlopt_BINARY_DIR} ${nlopt_BINARY_DIR}/src/api)
set(SHARED_LIBS_STATE ${SHARED_STATE})
add_library(nloptOptimizer INTERFACE)
target_link_libraries(nloptOptimizer INTERFACE nlopt)
target_include_directories(nloptOptimizer INTERFACE ${NLopt_INCLUDE_DIR})
else()
add_library(nloptOptimizer INTERFACE)
target_link_libraries(nloptOptimizer INTERFACE Nlopt::Nlopt)
endif()
#target_sources( nloptOptimizer INTERFACE
#${CMAKE_CURRENT_SOURCE_DIR}/simplex.hpp
#${CMAKE_CURRENT_SOURCE_DIR}/subplex.hpp
#${CMAKE_CURRENT_SOURCE_DIR}/genetic.hpp
#${CMAKE_CURRENT_SOURCE_DIR}/nlopt_boilerplate.hpp
#)
target_compile_definitions(nloptOptimizer INTERFACE LIBNEST2D_OPTIMIZER_NLOPT)
# And finally plug the nloptOptimizer into libnest2d
#target_link_libraries(libnest2d INTERFACE nloptOptimizer)

View File

@ -3,9 +3,6 @@
#include <cassert>
// For caching nfps
#include <unordered_map>
// For parallel for
#include <functional>
#include <iterator>
@ -76,55 +73,6 @@ inline void enumerate(
}
namespace __itemhash {
using Key = size_t;
template<class S>
Key hash(const _Item<S>& item) {
using Point = TPoint<S>;
using Segment = _Segment<Point>;
static const int N = 26;
static const int M = N*N - 1;
std::string ret;
auto& rhs = item.rawShape();
auto& ctr = sl::contour(rhs);
auto it = ctr.begin();
auto nx = std::next(it);
double circ = 0;
while(nx != ctr.end()) {
Segment seg(*it++, *nx++);
Radians a = seg.angleToXaxis();
double deg = Degrees(a);
int ms = 'A', ls = 'A';
while(deg > N) { ms++; deg -= N; }
ls += int(deg);
ret.push_back(char(ms)); ret.push_back(char(ls));
circ += std::sqrt(seg.template sqlength<double>());
}
it = ctr.begin(); nx = std::next(it);
while(nx != ctr.end()) {
Segment seg(*it++, *nx++);
auto l = int(M * std::sqrt(seg.template sqlength<double>()) / circ);
int ms = 'A', ls = 'A';
while(l > N) { ms++; l -= N; }
ls += l;
ret.push_back(char(ms)); ret.push_back(char(ls));
}
return std::hash<std::string>()(ret);
}
template<class S>
using Hash = std::unordered_map<Key, nfp::NfpResult<S>>;
}
namespace placers {
template<class RawShape>
@ -529,17 +477,9 @@ class _NofitPolyPlacer: public PlacerBoilerplate<_NofitPolyPlacer<RawShape, TBin
using MaxNfpLevel = nfp::MaxNfpLevel<RawShape>;
using ItemKeys = std::vector<__itemhash::Key>;
// Norming factor for the optimization function
const double norm_;
// Caching calculated nfps
__itemhash::Hash<RawShape> nfpcache_;
// Storing item hash keys
ItemKeys item_keys_;
public:
using Pile = nfp::Shapes<RawShape>;
@ -636,15 +576,12 @@ public:
private:
using Shapes = TMultiShape<RawShape>;
using ItemRef = std::reference_wrapper<Item>;
using ItemWithHash = const std::pair<ItemRef, __itemhash::Key>;
Shapes calcnfp(const ItemWithHash itsh, Lvl<nfp::NfpLevel::CONVEX_ONLY>)
Shapes calcnfp(const Item &trsh, Lvl<nfp::NfpLevel::CONVEX_ONLY>)
{
using namespace nfp;
Shapes nfps(items_.size());
const Item& trsh = itsh.first;
// /////////////////////////////////////////////////////////////////////
// TODO: this is a workaround and should be solved in Item with mutexes
@ -678,12 +615,11 @@ private:
template<class Level>
Shapes calcnfp( const ItemWithHash itsh, Level)
Shapes calcnfp(const Item &trsh, Level)
{ // Function for arbitrary level of nfp implementation
using namespace nfp;
Shapes nfps;
const Item& trsh = itsh.first;
auto& orb = trsh.transformedShape();
bool orbconvex = trsh.isContourConvex();
@ -849,8 +785,6 @@ private:
remlist.insert(remlist.end(), remaining.from, remaining.to);
}
size_t itemhash = __itemhash::hash(item);
if(items_.empty()) {
setInitialPosition(item);
best_overfit = overfit(item.transformedShape(), bin_);
@ -875,7 +809,7 @@ private:
// it is disjunct from the current merged pile
placeOutsideOfBin(item);
nfps = calcnfp({item, itemhash}, Lvl<MaxNfpLevel::value>());
nfps = calcnfp(item, Lvl<MaxNfpLevel::value>());
auto iv = item.referenceVertex();
@ -1112,7 +1046,6 @@ private:
if(can_pack) {
ret = PackResult(item);
item_keys_.emplace_back(itemhash);
} else {
ret = PackResult(best_overfit);
}
@ -1189,8 +1122,6 @@ private:
sl::rotate(sh, item.rotation());
Box bb = sl::boundingBox(sh);
bb.minCorner() += item.translation();
bb.maxCorner() += item.translation();
Vertex ci, cb;
auto bbin = sl::boundingBox(bin_);

View File

@ -1,7 +1,7 @@
#ifndef PLACER_BOILERPLATE_HPP
#define PLACER_BOILERPLATE_HPP
#include <libnest2d/libnest2d.hpp>
#include <libnest2d/nester.hpp>
namespace libnest2d { namespace placers {

View File

@ -2,7 +2,7 @@
#define SELECTION_BOILERPLATE_HPP
#include <atomic>
#include <libnest2d/libnest2d.hpp>
#include <libnest2d/nester.hpp>
namespace libnest2d { namespace selections {
@ -43,7 +43,7 @@ protected:
Placer p{bin};
p.configure(pcfg);
if (!p.pack(cpy)) it = c.erase(it);
if (itm.area() <= 0 || !p.pack(cpy)) it = c.erase(it);
else it++;
}
}

View File

@ -1,23 +1,26 @@
#include <libnest2d.h>
#include <libnest2d/libnest2d.hpp>
namespace libnest2d {
template class Nester<NfpPlacer, FirstFitSelection>;
template class Nester<BottomLeftPlacer, FirstFitSelection>;
template class _Nester<NfpPlacer, FirstFitSelection>;
template class _Nester<BottomLeftPlacer, FirstFitSelection>;
template PackGroup nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box& bin,
Coord dist = 0,
const NfpPlacer::Config& pconf,
const FirstFitSelection::Config& sconf);
template std::size_t _Nester<NfpPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
template std::size_t _Nester<BottomLeftPlacer, FirstFitSelection>::execute(
std::vector<Item>::iterator, std::vector<Item>::iterator);
template PackGroup nest(std::vector<Item>::iterator from,
template std::size_t nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box& bin,
ProgressFunction prg,
StopCondition scond,
Coord dist = 0,
const NfpPlacer::Config& pconf,
const FirstFitSelection::Config& sconf);
const Box & bin,
Coord dist,
const NestConfig<NfpPlacer, FirstFitSelection> &cfg,
NestControl ctl);
template std::size_t nest(std::vector<Item>::iterator from,
std::vector<Item>::iterator to,
const Box & bin,
Coord dist,
const NestConfig<BottomLeftPlacer, FirstFitSelection> &cfg,
NestControl ctl);
}

View File

@ -1,60 +0,0 @@
# Try to find existing GTest installation
find_package(GTest 1.7)
if(NOT GTEST_FOUND)
set(URL_GTEST "https://github.com/google/googletest.git"
CACHE STRING "Google test source code repository location.")
message(STATUS "GTest not found so downloading from ${URL_GTEST}")
# Go and download google test framework, integrate it with the build
set(GTEST_LIBS_TO_LINK gtest gtest_main)
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
include(DownloadProject)
download_project(PROJ googletest
GIT_REPOSITORY ${URL_GTEST}
GIT_TAG release-1.7.0
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
)
set(GTEST_INCLUDE_DIRS ${googletest_SOURCE_DIR}/include)
else()
find_package(Threads REQUIRED)
set(GTEST_LIBS_TO_LINK ${GTEST_BOTH_LIBRARIES} Threads::Threads)
endif()
add_executable(tests_clipper_nlopt
test.cpp
../tools/svgtools.hpp
# ../tools/libnfpglue.hpp
# ../tools/libnfpglue.cpp
printer_parts.h
printer_parts.cpp
)
target_link_libraries(tests_clipper_nlopt libnest2d ${GTEST_LIBS_TO_LINK} )
target_include_directories(tests_clipper_nlopt PRIVATE BEFORE ${GTEST_INCLUDE_DIRS})
if(NOT LIBNEST2D_HEADER_ONLY)
target_link_libraries(tests_clipper_nlopt ${LIBNAME})
else()
target_link_libraries(tests_clipper_nlopt libnest2d)
endif()
add_test(libnest2d_tests tests_clipper_nlopt)

View File

@ -375,7 +375,7 @@ public:
for(unsigned idx = 0; idx < fixeditems.size(); ++idx) {
Item& itm = fixeditems[idx];
itm.markAsFixed();
itm.markAsFixedInBin(itm.binId());
}
m_pck.configure(m_pconf);
@ -618,19 +618,21 @@ void arrange(ArrangePolygons & arrangables,
items.reserve(arrangables.size());
// Create Item from Arrangeable
auto process_arrangeable =
[](const ArrangePolygon &arrpoly, std::vector<Item> &outp)
auto process_arrangeable = [](const ArrangePolygon &arrpoly,
std::vector<Item> & outp)
{
Polygon p = arrpoly.poly.contour;
const Vec2crd & offs = arrpoly.translation;
const Vec2crd &offs = arrpoly.translation;
double rotation = arrpoly.rotation;
if (p.is_counter_clockwise()) p.reverse();
clppr::Polygon clpath(Slic3rMultiPoint_to_ClipperPath(p));
if (!clpath.Contour.empty()) {
auto firstp = clpath.Contour.front();
clpath.Contour.emplace_back(firstp);
}
outp.emplace_back(std::move(clpath));
outp.back().rotation(rotation);

View File

@ -15,7 +15,7 @@ public:
PointClass max;
bool defined;
BoundingBoxBase() : defined(false), min(PointClass::Zero()), max(PointClass::Zero()) {}
BoundingBoxBase() : min(PointClass::Zero()), max(PointClass::Zero()), defined(false) {}
BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) :
min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {}
BoundingBoxBase(const std::vector<PointClass>& points) : min(PointClass::Zero()), max(PointClass::Zero())
@ -59,7 +59,7 @@ template <class PointClass>
class BoundingBox3Base : public BoundingBoxBase<PointClass>
{
public:
BoundingBox3Base() : BoundingBoxBase<PointClass>() {};
BoundingBox3Base() : BoundingBoxBase<PointClass>() {}
BoundingBox3Base(const PointClass &pmin, const PointClass &pmax) :
BoundingBoxBase<PointClass>(pmin, pmax)
{ if (pmin(2) >= pmax(2)) BoundingBoxBase<PointClass>::defined = false; }
@ -100,6 +100,33 @@ public:
}
};
// Will prevent warnings caused by non existing definition of template in hpp
extern template void BoundingBoxBase<Point>::scale(double factor);
extern template void BoundingBoxBase<Vec2d>::scale(double factor);
extern template void BoundingBoxBase<Vec3d>::scale(double factor);
extern template void BoundingBoxBase<Point>::offset(coordf_t delta);
extern template void BoundingBoxBase<Vec2d>::offset(coordf_t delta);
extern template void BoundingBoxBase<Point>::merge(const Point &point);
extern template void BoundingBoxBase<Vec2d>::merge(const Vec2d &point);
extern template void BoundingBoxBase<Point>::merge(const Points &points);
extern template void BoundingBoxBase<Vec2d>::merge(const Pointfs &points);
extern template void BoundingBoxBase<Point>::merge(const BoundingBoxBase<Point> &bb);
extern template void BoundingBoxBase<Vec2d>::merge(const BoundingBoxBase<Vec2d> &bb);
extern template Point BoundingBoxBase<Point>::size() const;
extern template Vec2d BoundingBoxBase<Vec2d>::size() const;
extern template double BoundingBoxBase<Point>::radius() const;
extern template double BoundingBoxBase<Vec2d>::radius() const;
extern template Point BoundingBoxBase<Point>::center() const;
extern template Vec2d BoundingBoxBase<Vec2d>::center() const;
extern template void BoundingBox3Base<Vec3d>::merge(const Vec3d &point);
extern template void BoundingBox3Base<Vec3d>::merge(const Pointf3s &points);
extern template void BoundingBox3Base<Vec3d>::merge(const BoundingBox3Base<Vec3d> &bb);
extern template Vec3d BoundingBox3Base<Vec3d>::size() const;
extern template double BoundingBox3Base<Vec3d>::radius() const;
extern template void BoundingBox3Base<Vec3d>::offset(coordf_t delta);
extern template Vec3d BoundingBox3Base<Vec3d>::center() const;
extern template coordf_t BoundingBox3Base<Vec3d>::max_size() const;
class BoundingBox : public BoundingBoxBase<Point>
{
public:
@ -113,9 +140,9 @@ public:
// to encompass the original bounding box.
void align_to_grid(const coord_t cell_size);
BoundingBox() : BoundingBoxBase<Point>() {};
BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase<Point>(pmin, pmax) {};
BoundingBox(const Points &points) : BoundingBoxBase<Point>(points) {};
BoundingBox() : BoundingBoxBase<Point>() {}
BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase<Point>(pmin, pmax) {}
BoundingBox(const Points &points) : BoundingBoxBase<Point>(points) {}
BoundingBox(const Lines &lines);
friend BoundingBox get_extents_rotated(const Points &points, double angle);
@ -124,25 +151,25 @@ public:
class BoundingBox3 : public BoundingBox3Base<Vec3crd>
{
public:
BoundingBox3() : BoundingBox3Base<Vec3crd>() {};
BoundingBox3(const Vec3crd &pmin, const Vec3crd &pmax) : BoundingBox3Base<Vec3crd>(pmin, pmax) {};
BoundingBox3(const Points3& points) : BoundingBox3Base<Vec3crd>(points) {};
BoundingBox3() : BoundingBox3Base<Vec3crd>() {}
BoundingBox3(const Vec3crd &pmin, const Vec3crd &pmax) : BoundingBox3Base<Vec3crd>(pmin, pmax) {}
BoundingBox3(const Points3& points) : BoundingBox3Base<Vec3crd>(points) {}
};
class BoundingBoxf : public BoundingBoxBase<Vec2d>
{
public:
BoundingBoxf() : BoundingBoxBase<Vec2d>() {};
BoundingBoxf(const Vec2d &pmin, const Vec2d &pmax) : BoundingBoxBase<Vec2d>(pmin, pmax) {};
BoundingBoxf(const std::vector<Vec2d> &points) : BoundingBoxBase<Vec2d>(points) {};
BoundingBoxf() : BoundingBoxBase<Vec2d>() {}
BoundingBoxf(const Vec2d &pmin, const Vec2d &pmax) : BoundingBoxBase<Vec2d>(pmin, pmax) {}
BoundingBoxf(const std::vector<Vec2d> &points) : BoundingBoxBase<Vec2d>(points) {}
};
class BoundingBoxf3 : public BoundingBox3Base<Vec3d>
{
public:
BoundingBoxf3() : BoundingBox3Base<Vec3d>() {};
BoundingBoxf3(const Vec3d &pmin, const Vec3d &pmax) : BoundingBox3Base<Vec3d>(pmin, pmax) {};
BoundingBoxf3(const std::vector<Vec3d> &points) : BoundingBox3Base<Vec3d>(points) {};
BoundingBoxf3() : BoundingBox3Base<Vec3d>() {}
BoundingBoxf3(const Vec3d &pmin, const Vec3d &pmax) : BoundingBox3Base<Vec3d>(pmin, pmax) {}
BoundingBoxf3(const std::vector<Vec3d> &points) : BoundingBox3Base<Vec3d>(points) {}
BoundingBoxf3 transformed(const Transform3d& matrix) const;
};

View File

@ -7,7 +7,7 @@ namespace Slic3r {
BridgeDetector::BridgeDetector(
ExPolygon _expolygon,
const ExPolygonCollection &_lower_slices,
const ExPolygons &_lower_slices,
coord_t _spacing) :
// The original infill polygon, not inflated.
expolygons(expolygons_owned),
@ -21,7 +21,7 @@ BridgeDetector::BridgeDetector(
BridgeDetector::BridgeDetector(
const ExPolygons &_expolygons,
const ExPolygonCollection &_lower_slices,
const ExPolygons &_lower_slices,
coord_t _spacing) :
// The original infill polygon, not inflated.
expolygons(_expolygons),
@ -40,13 +40,17 @@ void BridgeDetector::initialize()
this->angle = -1.;
// Outset our bridge by an arbitrary amout; we'll use this outer margin for detecting anchors.
Polygons grown = offset(to_polygons(this->expolygons), this->spacing);
Polygons grown = offset(to_polygons(this->expolygons), float(this->spacing));
// Detect possible anchoring edges of this bridging region.
// Detect what edges lie on lower slices by turning bridge contour and holes
// into polylines and then clipping them with each lower slice's contour.
// Currently _edges are only used to set a candidate direction of the bridge (see bridge_direction_candidates()).
this->_edges = intersection_pl(to_polylines(grown), this->lower_slices.contours());
Polygons contours;
contours.reserve(this->lower_slices.size());
for (const ExPolygon &expoly : this->lower_slices)
contours.push_back(expoly.contour);
this->_edges = intersection_pl(to_polylines(grown), contours);
#ifdef SLIC3R_DEBUG
printf(" bridge has " PRINTF_ZU " support(s)\n", this->_edges.size());
@ -54,7 +58,7 @@ void BridgeDetector::initialize()
// detect anchors as intersection between our bridge expolygon and the lower slices
// safety offset required to avoid Clipper from detecting empty intersection while Boost actually found some edges
this->_anchor_regions = intersection_ex(grown, to_polygons(this->lower_slices.expolygons), true);
this->_anchor_regions = intersection_ex(grown, to_polygons(this->lower_slices), true);
/*
if (0) {
@ -303,7 +307,6 @@ Polygons BridgeDetector::coverage(double angle, bool precise) const {
}
#endif
}
return covered;
}
@ -316,7 +319,7 @@ BridgeDetector::unsupported_edges(double angle, Polylines* unsupported) const
if (angle == -1) angle = this->angle;
if (angle == -1) return;
Polygons grown_lower = offset(this->lower_slices.expolygons, this->spacing);
Polygons grown_lower = offset(this->lower_slices, float(this->spacing));
for (ExPolygons::const_iterator it_expoly = this->expolygons.begin(); it_expoly != this->expolygons.end(); ++ it_expoly) {
// get unsupported bridge edges (both contour and holes)

View File

@ -3,7 +3,6 @@
#include "libslic3r.h"
#include "ExPolygon.hpp"
#include "ExPolygonCollection.hpp"
#include <string>
namespace Slic3r {
@ -21,7 +20,7 @@ public:
// In case the caller gaves us the input polygons by a value, make a copy.
ExPolygons expolygons_owned;
// Lower slices, all regions.
const ExPolygonCollection &lower_slices;
const ExPolygons &lower_slices;
// Scaled extrusion width of the infill.
coord_t spacing;
// Angle resolution for the brute force search of the best bridging angle.
@ -29,8 +28,8 @@ public:
// The final optimal angle.
double angle;
BridgeDetector(ExPolygon _expolygon, const ExPolygonCollection &_lower_slices, coord_t _extrusion_width);
BridgeDetector(const ExPolygons &_expolygons, const ExPolygonCollection &_lower_slices, coord_t _extrusion_width);
BridgeDetector(ExPolygon _expolygon, const ExPolygons &_lower_slices, coord_t _extrusion_width);
BridgeDetector(const ExPolygons &_expolygons, const ExPolygons &_lower_slices, coord_t _extrusion_width);
// If bridge_direction_override != 0, then the angle is used instead of auto-detect.
bool detect_angle(double bridge_direction_override = 0.);
Polygons coverage(double angle = -1, bool precise = true) const;

View File

@ -22,6 +22,8 @@ add_library(libslic3r STATIC
Config.hpp
EdgeGrid.cpp
EdgeGrid.hpp
ElephantFootCompensation.cpp
ElephantFootCompensation.hpp
ExPolygon.cpp
ExPolygon.hpp
ExPolygonCollection.cpp
@ -73,6 +75,8 @@ add_library(libslic3r STATIC
Format/STL.hpp
GCode/Analyzer.cpp
GCode/Analyzer.hpp
GCode/ThumbnailData.cpp
GCode/ThumbnailData.hpp
GCode/CoolingBuffer.cpp
GCode/CoolingBuffer.hpp
GCode/PostProcessor.cpp
@ -102,7 +106,7 @@ add_library(libslic3r STATIC
Geometry.cpp
Geometry.hpp
Int128.hpp
# KdTree.hpp
KDTreeIndirect.hpp
Layer.cpp
Layer.hpp
LayerRegion.cpp
@ -135,8 +139,6 @@ add_library(libslic3r STATIC
PolygonTrimmer.hpp
Polyline.cpp
Polyline.hpp
PolylineCollection.cpp
PolylineCollection.hpp
Print.cpp
Print.hpp
PrintBase.cpp
@ -146,6 +148,8 @@ add_library(libslic3r STATIC
PrintObject.cpp
PrintRegion.cpp
Semver.cpp
ShortestPath.cpp
ShortestPath.hpp
SLAPrint.cpp
SLAPrint.hpp
SLA/SLAAutoSupports.hpp
@ -180,8 +184,13 @@ add_library(libslic3r STATIC
miniz_extension.cpp
SLA/SLACommon.hpp
SLA/SLABoilerPlate.hpp
SLA/SLABasePool.hpp
SLA/SLABasePool.cpp
SLA/SLAPad.hpp
SLA/SLAPad.cpp
SLA/SLASupportTreeBuilder.hpp
SLA/SLASupportTreeBuildsteps.hpp
SLA/SLASupportTreeBuildsteps.cpp
SLA/SLASupportTreeBuilder.cpp
SLA/SLAConcurrency.hpp
SLA/SLASupportTree.hpp
SLA/SLASupportTree.cpp
SLA/SLASupportTreeIGL.cpp
@ -193,6 +202,8 @@ add_library(libslic3r STATIC
SLA/SLARaster.cpp
SLA/SLARasterWriter.hpp
SLA/SLARasterWriter.cpp
SLA/ConcaveHull.hpp
SLA/ConcaveHull.cpp
)
encoding_check(libslic3r)
@ -201,7 +212,7 @@ if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE)
endif ()
target_compile_definitions(libslic3r PUBLIC -DUSE_TBB)
target_compile_definitions(libslic3r PUBLIC -DUSE_TBB -DTBB_USE_CAPTURED_EXCEPTION=0)
target_include_directories(libslic3r PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBNEST2D_INCLUDES} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(libslic3r
libnest2d
@ -218,7 +229,9 @@ target_link_libraries(libslic3r
poly2tri
qhull
semver
tbb
TBB::tbb
# OpenVDB::openvdb
${CMAKE_DL_LIBS}
)
if(WIN32)

View File

@ -1,5 +1,6 @@
#include "ClipperUtils.hpp"
#include "Geometry.hpp"
#include "ShortestPath.hpp"
// #define CLIPPER_UTILS_DEBUG
@ -106,8 +107,7 @@ void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, ExPolygons* ex
}
}
ExPolygons
PolyTreeToExPolygons(ClipperLib::PolyTree& polytree)
ExPolygons PolyTreeToExPolygons(ClipperLib::PolyTree& polytree)
{
ExPolygons retval;
for (int i = 0; i < polytree.ChildCount(); ++i)
@ -150,8 +150,7 @@ Slic3r::Polylines ClipperPaths_to_Slic3rPolylines(const ClipperLib::Paths &input
return retval;
}
ExPolygons
ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input)
ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input)
{
// init Clipper
ClipperLib::Clipper clipper;
@ -166,8 +165,7 @@ ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input)
return PolyTreeToExPolygons(polytree);
}
ClipperLib::Path
Slic3rMultiPoint_to_ClipperPath(const MultiPoint &input)
ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const MultiPoint &input)
{
ClipperLib::Path retval;
for (Points::const_iterator pit = input.points.begin(); pit != input.points.end(); ++pit)
@ -175,8 +173,7 @@ Slic3rMultiPoint_to_ClipperPath(const MultiPoint &input)
return retval;
}
ClipperLib::Path
Slic3rMultiPoint_to_ClipperPath_reversed(const Slic3r::MultiPoint &input)
ClipperLib::Path Slic3rMultiPoint_to_ClipperPath_reversed(const Slic3r::MultiPoint &input)
{
ClipperLib::Path output;
output.reserve(input.points.size());
@ -193,6 +190,19 @@ ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input)
return retval;
}
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const ExPolygons &input)
{
ClipperLib::Paths retval;
for (auto &ep : input) {
retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(ep.contour));
for (auto &h : ep.holes)
retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(h));
}
return retval;
}
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input)
{
ClipperLib::Paths retval;
@ -471,14 +481,16 @@ ExPolygons offset2_ex(const ExPolygons &expolygons, const double delta1,
return union_ex(polys);
}
template <class T>
T
_clipper_do(const ClipperLib::ClipType clipType, const Polygons &subject,
const Polygons &clip, const ClipperLib::PolyFillType fillType, const bool safety_offset_)
template<class T, class TSubj, class TClip>
T _clipper_do(const ClipperLib::ClipType clipType,
TSubj && subject,
TClip && clip,
const ClipperLib::PolyFillType fillType,
const bool safety_offset_)
{
// read input
ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject);
ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(clip);
ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(std::forward<TSubj>(subject));
ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(std::forward<TClip>(clip));
// perform safety offset
if (safety_offset_) {
@ -505,7 +517,7 @@ _clipper_do(const ClipperLib::ClipType clipType, const Polygons &subject,
// Fix of #117: A large fractal pyramid takes ages to slice
// The Clipper library has difficulties processing overlapping polygons.
// Namely, the function Clipper::JoinCommonEdges() has potentially a terrible time complexity if the output
// Namely, the function ClipperLib::JoinCommonEdges() has potentially a terrible time complexity if the output
// of the operation is of the PolyTree type.
// This function implmenets a following workaround:
// 1) Peform the Clipper operation with the output to Paths. This method handles overlaps in a reasonable time.
@ -647,12 +659,26 @@ _clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons
return retval;
}
ClipperLib::PolyTree
union_pt(const Polygons &subject, bool safety_offset_)
ClipperLib::PolyTree union_pt(const Polygons &subject, bool safety_offset_)
{
return _clipper_do<ClipperLib::PolyTree>(ClipperLib::ctUnion, subject, Polygons(), ClipperLib::pftEvenOdd, safety_offset_);
}
ClipperLib::PolyTree union_pt(const ExPolygons &subject, bool safety_offset_)
{
return _clipper_do<ClipperLib::PolyTree>(ClipperLib::ctUnion, subject, Polygons(), ClipperLib::pftEvenOdd, safety_offset_);
}
ClipperLib::PolyTree union_pt(Polygons &&subject, bool safety_offset_)
{
return _clipper_do<ClipperLib::PolyTree>(ClipperLib::ctUnion, std::move(subject), Polygons(), ClipperLib::pftEvenOdd, safety_offset_);
}
ClipperLib::PolyTree union_pt(ExPolygons &&subject, bool safety_offset_)
{
return _clipper_do<ClipperLib::PolyTree>(ClipperLib::ctUnion, std::move(subject), Polygons(), ClipperLib::pftEvenOdd, safety_offset_);
}
Polygons
union_pt_chained(const Polygons &subject, bool safety_offset_)
{
@ -663,30 +689,123 @@ union_pt_chained(const Polygons &subject, bool safety_offset_)
return retval;
}
void traverse_pt(ClipperLib::PolyNodes &nodes, Polygons* retval)
static ClipperLib::PolyNodes order_nodes(const ClipperLib::PolyNodes &nodes)
{
// collect ordering points
Points ordering_points;
ordering_points.reserve(nodes.size());
for (const ClipperLib::PolyNode *node : nodes)
ordering_points.emplace_back(Point(node->Contour.front().X, node->Contour.front().Y));
// perform the ordering
ClipperLib::PolyNodes ordered_nodes = chain_clipper_polynodes(ordering_points, nodes);
return ordered_nodes;
}
enum class e_ordering {
ORDER_POLYNODES,
DONT_ORDER_POLYNODES
};
template<e_ordering o>
void foreach_node(const ClipperLib::PolyNodes &nodes,
std::function<void(const ClipperLib::PolyNode *)> fn);
template<> void foreach_node<e_ordering::DONT_ORDER_POLYNODES>(
const ClipperLib::PolyNodes & nodes,
std::function<void(const ClipperLib::PolyNode *)> fn)
{
for (auto &n : nodes) fn(n);
}
template<> void foreach_node<e_ordering::ORDER_POLYNODES>(
const ClipperLib::PolyNodes & nodes,
std::function<void(const ClipperLib::PolyNode *)> fn)
{
auto ordered_nodes = order_nodes(nodes);
for (auto &n : ordered_nodes) fn(n);
}
template<e_ordering o>
void _traverse_pt(const ClipperLib::PolyNodes &nodes, Polygons *retval)
{
/* use a nearest neighbor search to order these children
TODO: supply start_near to chained_path() too? */
// collect ordering points
Points ordering_points;
ordering_points.reserve(nodes.size());
for (ClipperLib::PolyNodes::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
Point p((*it)->Contour.front().X, (*it)->Contour.front().Y);
ordering_points.emplace_back(p);
}
// perform the ordering
ClipperLib::PolyNodes ordered_nodes;
Slic3r::Geometry::chained_path_items(ordering_points, nodes, ordered_nodes);
// push results recursively
for (ClipperLib::PolyNodes::iterator it = ordered_nodes.begin(); it != ordered_nodes.end(); ++it) {
foreach_node<o>(nodes, [&retval](const ClipperLib::PolyNode *node) {
// traverse the next depth
traverse_pt((*it)->Childs, retval);
retval->emplace_back(ClipperPath_to_Slic3rPolygon((*it)->Contour));
if ((*it)->IsHole()) retval->back().reverse(); // ccw
}
_traverse_pt<o>(node->Childs, retval);
retval->emplace_back(ClipperPath_to_Slic3rPolygon(node->Contour));
if (node->IsHole()) retval->back().reverse(); // ccw
});
}
template<e_ordering o>
void _traverse_pt(const ClipperLib::PolyNode *tree, ExPolygons *retval)
{
if (!retval || !tree) return;
ExPolygons &retv = *retval;
std::function<void(const ClipperLib::PolyNode*, ExPolygon&)> hole_fn;
auto contour_fn = [&retv, &hole_fn](const ClipperLib::PolyNode *pptr) {
ExPolygon poly;
poly.contour.points = ClipperPath_to_Slic3rPolygon(pptr->Contour);
auto fn = std::bind(hole_fn, std::placeholders::_1, poly);
foreach_node<o>(pptr->Childs, fn);
retv.push_back(poly);
};
hole_fn = [&contour_fn](const ClipperLib::PolyNode *pptr, ExPolygon& poly)
{
poly.holes.emplace_back();
poly.holes.back().points = ClipperPath_to_Slic3rPolygon(pptr->Contour);
foreach_node<o>(pptr->Childs, contour_fn);
};
contour_fn(tree);
}
template<e_ordering o>
void _traverse_pt(const ClipperLib::PolyNodes &nodes, ExPolygons *retval)
{
// Here is the actual traverse
foreach_node<o>(nodes, [&retval](const ClipperLib::PolyNode *node) {
_traverse_pt<o>(node, retval);
});
}
void traverse_pt(const ClipperLib::PolyNode *tree, ExPolygons *retval)
{
_traverse_pt<e_ordering::ORDER_POLYNODES>(tree, retval);
}
void traverse_pt_unordered(const ClipperLib::PolyNode *tree, ExPolygons *retval)
{
_traverse_pt<e_ordering::DONT_ORDER_POLYNODES>(tree, retval);
}
void traverse_pt(const ClipperLib::PolyNodes &nodes, Polygons *retval)
{
_traverse_pt<e_ordering::ORDER_POLYNODES>(nodes, retval);
}
void traverse_pt(const ClipperLib::PolyNodes &nodes, ExPolygons *retval)
{
_traverse_pt<e_ordering::ORDER_POLYNODES>(nodes, retval);
}
void traverse_pt_unordered(const ClipperLib::PolyNodes &nodes, Polygons *retval)
{
_traverse_pt<e_ordering::DONT_ORDER_POLYNODES>(nodes, retval);
}
void traverse_pt_unordered(const ClipperLib::PolyNodes &nodes, ExPolygons *retval)
{
_traverse_pt<e_ordering::DONT_ORDER_POLYNODES>(nodes, retval);
}
Polygons simplify_polygons(const Polygons &subject, bool preserve_collinear)
@ -795,4 +914,330 @@ Polygons top_level_islands(const Slic3r::Polygons &polygons)
return out;
}
// Outer offset shall not split the input contour into multiples. It is expected, that the solution will be non empty and it will contain just a single polygon.
ClipperLib::Paths fix_after_outer_offset(const ClipperLib::Path &input, ClipperLib::PolyFillType filltype, bool reverse_result)
{
ClipperLib::Paths solution;
if (! input.empty()) {
ClipperLib::Clipper clipper;
clipper.AddPath(input, ClipperLib::ptSubject, true);
clipper.ReverseSolution(reverse_result);
clipper.Execute(ClipperLib::ctUnion, solution, filltype, filltype);
}
return solution;
}
// Inner offset may split the source contour into multiple contours, but one shall not be inside the other.
ClipperLib::Paths fix_after_inner_offset(const ClipperLib::Path &input, ClipperLib::PolyFillType filltype, bool reverse_result)
{
ClipperLib::Paths solution;
if (! input.empty()) {
ClipperLib::Clipper clipper;
clipper.AddPath(input, ClipperLib::ptSubject, true);
ClipperLib::IntRect r = clipper.GetBounds();
r.left -= 10; r.top -= 10; r.right += 10; r.bottom += 10;
if (filltype == ClipperLib::pftPositive)
clipper.AddPath({ ClipperLib::IntPoint(r.left, r.bottom), ClipperLib::IntPoint(r.left, r.top), ClipperLib::IntPoint(r.right, r.top), ClipperLib::IntPoint(r.right, r.bottom) }, ClipperLib::ptSubject, true);
else
clipper.AddPath({ ClipperLib::IntPoint(r.left, r.bottom), ClipperLib::IntPoint(r.right, r.bottom), ClipperLib::IntPoint(r.right, r.top), ClipperLib::IntPoint(r.left, r.top) }, ClipperLib::ptSubject, true);
clipper.ReverseSolution(reverse_result);
clipper.Execute(ClipperLib::ctUnion, solution, filltype, filltype);
if (! solution.empty())
solution.erase(solution.begin());
}
return solution;
}
ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::vector<float> &deltas, double miter_limit)
{
assert(contour.size() == deltas.size());
#ifndef NDEBUG
// Verify that the deltas are either all positive, or all negative.
bool positive = false;
bool negative = false;
for (float delta : deltas)
if (delta < 0.f)
negative = true;
else if (delta > 0.f)
positive = true;
assert(! (negative && positive));
#endif /* NDEBUG */
ClipperLib::Path out;
if (deltas.size() > 2)
{
out.reserve(contour.size() * 2);
// Clamp miter limit to 2.
miter_limit = (miter_limit > 2.) ? 2. / (miter_limit * miter_limit) : 0.5;
// perpenduclar vector
auto perp = [](const Vec2d &v) -> Vec2d { return Vec2d(v.y(), - v.x()); };
// Add a new point to the output, scale by CLIPPER_OFFSET_SCALE and round to ClipperLib::cInt.
auto add_offset_point = [&out](Vec2d pt) {
pt *= double(CLIPPER_OFFSET_SCALE);
pt += Vec2d(0.5 - (pt.x() < 0), 0.5 - (pt.y() < 0));
out.emplace_back(ClipperLib::cInt(pt.x()), ClipperLib::cInt(pt.y()));
};
// Minimum edge length, squared.
double lmin = *std::max_element(deltas.begin(), deltas.end()) * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR;
double l2min = lmin * lmin;
// Minimum angle to consider two edges to be parallel.
// Vojtech's estimate.
// const double sin_min_parallel = EPSILON + 1. / double(CLIPPER_OFFSET_SCALE);
// Implementation equal to Clipper.
const double sin_min_parallel = 1.;
// Find the last point further from pt by l2min.
Vec2d pt = contour.front().cast<double>();
size_t iprev = contour.size() - 1;
Vec2d ptprev;
for (; iprev > 0; -- iprev) {
ptprev = contour[iprev].cast<double>();
if ((ptprev - pt).squaredNorm() > l2min)
break;
}
if (iprev != 0) {
size_t ilast = iprev;
// Normal to the (pt - ptprev) segment.
Vec2d nprev = perp(pt - ptprev).normalized();
for (size_t i = 0; ; ) {
// Find the next point further from pt by l2min.
size_t j = i + 1;
Vec2d ptnext;
for (; j <= ilast; ++ j) {
ptnext = contour[j].cast<double>();
double l2 = (ptnext - pt).squaredNorm();
if (l2 > l2min)
break;
}
if (j > ilast) {
assert(i <= ilast);
// If the last edge is too short, merge it with the previous edge.
i = ilast;
ptnext = contour.front().cast<double>();
}
// Normal to the (ptnext - pt) segment.
Vec2d nnext = perp(ptnext - pt).normalized();
double delta = deltas[i];
double sin_a = clamp(-1., 1., cross2(nprev, nnext));
double convex = sin_a * delta;
if (convex <= - sin_min_parallel) {
// Concave corner.
add_offset_point(pt + nprev * delta);
add_offset_point(pt);
add_offset_point(pt + nnext * delta);
} else {
double dot = nprev.dot(nnext);
if (convex < sin_min_parallel && dot > 0.) {
// Nearly parallel.
add_offset_point((nprev.dot(nnext) > 0.) ? (pt + nprev * delta) : pt);
} else {
// Convex corner, possibly extremely sharp if convex < sin_min_parallel.
double r = 1. + dot;
if (r >= miter_limit)
add_offset_point(pt + (nprev + nnext) * (delta / r));
else {
double dx = std::tan(std::atan2(sin_a, dot) / 4.);
Vec2d newpt1 = pt + (nprev - perp(nprev) * dx) * delta;
Vec2d newpt2 = pt + (nnext + perp(nnext) * dx) * delta;
#ifndef NDEBUG
Vec2d vedge = 0.5 * (newpt1 + newpt2) - pt;
double dist_norm = vedge.norm();
assert(std::abs(dist_norm - std::abs(delta)) < SCALED_EPSILON);
#endif /* NDEBUG */
add_offset_point(newpt1);
add_offset_point(newpt2);
}
}
}
if (i == ilast)
break;
ptprev = pt;
nprev = nnext;
pt = ptnext;
i = j;
}
}
}
#if 0
{
ClipperLib::Path polytmp(out);
unscaleClipperPolygon(polytmp);
Slic3r::Polygon offsetted = ClipperPath_to_Slic3rPolygon(polytmp);
BoundingBox bbox = get_extents(contour);
bbox.merge(get_extents(offsetted));
static int iRun = 0;
SVG svg(debug_out_path("mittered_offset_path_scaled-%d.svg", iRun ++).c_str(), bbox);
svg.draw_outline(Polygon(contour), "blue", scale_(0.01));
svg.draw_outline(offsetted, "red", scale_(0.01));
svg.draw(contour, "blue", scale_(0.03));
svg.draw((Points)offsetted, "blue", scale_(0.03));
}
#endif
return out;
}
Polygons variable_offset_inner(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit)
{
#ifndef NDEBUG
// Verify that the deltas are all non positive.
for (const std::vector<float> &ds : deltas)
for (float delta : ds)
assert(delta <= 0.);
assert(expoly.holes.size() + 1 == deltas.size());
#endif /* NDEBUG */
// 1) Offset the outer contour.
ClipperLib::Paths contours = fix_after_inner_offset(mittered_offset_path_scaled(expoly.contour.points, deltas.front(), miter_limit), ClipperLib::pftNegative, true);
// 2) Offset the holes one by one, collect the results.
ClipperLib::Paths holes;
holes.reserve(expoly.holes.size());
for (const Polygon& hole : expoly.holes)
append(holes, fix_after_outer_offset(mittered_offset_path_scaled(hole, deltas[1 + &hole - expoly.holes.data()], miter_limit), ClipperLib::pftPositive, false));
// 3) Subtract holes from the contours.
ClipperLib::Paths output;
if (holes.empty())
output = std::move(contours);
else {
ClipperLib::Clipper clipper;
clipper.Clear();
clipper.AddPaths(contours, ClipperLib::ptSubject, true);
clipper.AddPaths(holes, ClipperLib::ptClip, true);
clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
}
// 4) Unscale the output.
unscaleClipperPolygons(output);
return ClipperPaths_to_Slic3rPolygons(output);
}
Polygons variable_offset_outer(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit)
{
#ifndef NDEBUG
// Verify that the deltas are all non positive.
for (const std::vector<float>& ds : deltas)
for (float delta : ds)
assert(delta >= 0.);
assert(expoly.holes.size() + 1 == deltas.size());
#endif /* NDEBUG */
// 1) Offset the outer contour.
ClipperLib::Paths contours = fix_after_outer_offset(mittered_offset_path_scaled(expoly.contour.points, deltas.front(), miter_limit), ClipperLib::pftPositive, false);
// 2) Offset the holes one by one, collect the results.
ClipperLib::Paths holes;
holes.reserve(expoly.holes.size());
for (const Polygon& hole : expoly.holes)
append(holes, fix_after_inner_offset(mittered_offset_path_scaled(hole, deltas[1 + &hole - expoly.holes.data()], miter_limit), ClipperLib::pftPositive, true));
// 3) Subtract holes from the contours.
ClipperLib::Paths output;
if (holes.empty())
output = std::move(contours);
else {
ClipperLib::Clipper clipper;
clipper.Clear();
clipper.AddPaths(contours, ClipperLib::ptSubject, true);
clipper.AddPaths(holes, ClipperLib::ptClip, true);
clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
}
// 4) Unscale the output.
unscaleClipperPolygons(output);
return ClipperPaths_to_Slic3rPolygons(output);
}
ExPolygons variable_offset_outer_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit)
{
#ifndef NDEBUG
// Verify that the deltas are all non positive.
for (const std::vector<float>& ds : deltas)
for (float delta : ds)
assert(delta >= 0.);
assert(expoly.holes.size() + 1 == deltas.size());
#endif /* NDEBUG */
// 1) Offset the outer contour.
ClipperLib::Paths contours = fix_after_outer_offset(mittered_offset_path_scaled(expoly.contour.points, deltas.front(), miter_limit), ClipperLib::pftPositive, false);
// 2) Offset the holes one by one, collect the results.
ClipperLib::Paths holes;
holes.reserve(expoly.holes.size());
for (const Polygon& hole : expoly.holes)
append(holes, fix_after_inner_offset(mittered_offset_path_scaled(hole, deltas[1 + &hole - expoly.holes.data()], miter_limit), ClipperLib::pftPositive, true));
// 3) Subtract holes from the contours.
unscaleClipperPolygons(contours);
ExPolygons output;
if (holes.empty()) {
output.reserve(contours.size());
for (ClipperLib::Path &path : contours)
output.emplace_back(ClipperPath_to_Slic3rPolygon(path));
} else {
ClipperLib::Clipper clipper;
unscaleClipperPolygons(holes);
clipper.AddPaths(contours, ClipperLib::ptSubject, true);
clipper.AddPaths(holes, ClipperLib::ptClip, true);
ClipperLib::PolyTree polytree;
clipper.Execute(ClipperLib::ctDifference, polytree, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
output = PolyTreeToExPolygons(polytree);
}
return output;
}
ExPolygons variable_offset_inner_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit)
{
#ifndef NDEBUG
// Verify that the deltas are all non positive.
for (const std::vector<float>& ds : deltas)
for (float delta : ds)
assert(delta <= 0.);
assert(expoly.holes.size() + 1 == deltas.size());
#endif /* NDEBUG */
// 1) Offset the outer contour.
ClipperLib::Paths contours = fix_after_inner_offset(mittered_offset_path_scaled(expoly.contour.points, deltas.front(), miter_limit), ClipperLib::pftNegative, false);
// 2) Offset the holes one by one, collect the results.
ClipperLib::Paths holes;
holes.reserve(expoly.holes.size());
for (const Polygon& hole : expoly.holes)
append(holes, fix_after_outer_offset(mittered_offset_path_scaled(hole, deltas[1 + &hole - expoly.holes.data()], miter_limit), ClipperLib::pftNegative, true));
// 3) Subtract holes from the contours.
unscaleClipperPolygons(contours);
ExPolygons output;
if (holes.empty()) {
output.reserve(contours.size());
for (ClipperLib::Path &path : contours)
output.emplace_back(ClipperPath_to_Slic3rPolygon(path));
} else {
ClipperLib::Clipper clipper;
unscaleClipperPolygons(holes);
clipper.AddPaths(contours, ClipperLib::ptSubject, true);
clipper.AddPaths(holes, ClipperLib::ptClip, true);
ClipperLib::PolyTree polytree;
clipper.Execute(ClipperLib::ctDifference, polytree, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
output = PolyTreeToExPolygons(polytree);
}
return output;
}
}

View File

@ -34,6 +34,7 @@ Slic3r::ExPolygons PolyTreeToExPolygons(ClipperLib::PolyTree& polytree);
ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const Slic3r::MultiPoint &input);
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input);
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const ExPolygons &input);
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input);
Slic3r::Polygon ClipperPath_to_Slic3rPolygon(const ClipperLib::Path &input);
Slic3r::Polyline ClipperPath_to_Slic3rPolyline(const ClipperLib::Path &input);
@ -223,8 +224,19 @@ inline Slic3r::ExPolygons union_ex(const Slic3r::ExPolygons &subject1, const Sli
}
ClipperLib::PolyTree union_pt(const Slic3r::Polygons &subject, bool safety_offset_ = false);
ClipperLib::PolyTree union_pt(const Slic3r::ExPolygons &subject, bool safety_offset_ = false);
ClipperLib::PolyTree union_pt(Slic3r::Polygons &&subject, bool safety_offset_ = false);
ClipperLib::PolyTree union_pt(Slic3r::ExPolygons &&subject, bool safety_offset_ = false);
Slic3r::Polygons union_pt_chained(const Slic3r::Polygons &subject, bool safety_offset_ = false);
void traverse_pt(ClipperLib::PolyNodes &nodes, Slic3r::Polygons* retval);
void traverse_pt(const ClipperLib::PolyNodes &nodes, Slic3r::Polygons *retval);
void traverse_pt(const ClipperLib::PolyNodes &nodes, Slic3r::ExPolygons *retval);
void traverse_pt(const ClipperLib::PolyNode *tree, Slic3r::ExPolygons *retval);
void traverse_pt_unordered(const ClipperLib::PolyNodes &nodes, Slic3r::Polygons *retval);
void traverse_pt_unordered(const ClipperLib::PolyNodes &nodes, Slic3r::ExPolygons *retval);
void traverse_pt_unordered(const ClipperLib::PolyNode *tree, Slic3r::ExPolygons *retval);
/* OTHER */
Slic3r::Polygons simplify_polygons(const Slic3r::Polygons &subject, bool preserve_collinear = false);
@ -234,6 +246,11 @@ void safety_offset(ClipperLib::Paths* paths);
Polygons top_level_islands(const Slic3r::Polygons &polygons);
Polygons variable_offset_inner(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
Polygons variable_offset_outer(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
ExPolygons variable_offset_outer_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
ExPolygons variable_offset_inner_ex(const ExPolygon &expoly, const std::vector<std::vector<float>> &deltas, double miter_limit = 2.);
}
#endif

View File

@ -302,8 +302,6 @@ ConfigOptionDef* ConfigDef::add_nullable(const t_config_option_key &opt_key, Con
return def;
}
std::string ConfigOptionDef::nocli = "~~~noCLI";
std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, std::function<bool(const ConfigOptionDef &)> filter) const
{
// prepare a function for wrapping text
@ -477,7 +475,30 @@ std::string ConfigBase::opt_serialize(const t_config_option_key &opt_key) const
return opt->serialize();
}
bool ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, bool append)
void ConfigBase::set(const std::string &opt_key, int value, bool create)
{
ConfigOption *opt = this->option_throw(opt_key, create);
switch (opt->type()) {
case coInt: static_cast<ConfigOptionInt*>(opt)->value = value; break;
case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
case coString: static_cast<ConfigOptionString*>(opt)->value = std::to_string(value); break;
default: throw BadOptionTypeException("Configbase::set() - conversion from int not possible");
}
}
void ConfigBase::set(const std::string &opt_key, double value, bool create)
{
ConfigOption *opt = this->option_throw(opt_key, create);
switch (opt->type()) {
case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
case coString: static_cast<ConfigOptionString*>(opt)->value = std::to_string(value); break;
default: throw BadOptionTypeException("Configbase::set() - conversion from float not possible");
}
}
bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src, const std::string &value_src, bool append)
{
t_config_option_key opt_key = opt_key_src;
std::string value = value_src;
@ -490,6 +511,18 @@ bool ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const s
return this->set_deserialize_raw(opt_key, value, append);
}
void ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, bool append)
{
if (! this->set_deserialize_nothrow(opt_key_src, value_src, append))
throw BadOptionTypeException("ConfigBase::set_deserialize() failed");
}
void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items)
{
for (const SetDeserializeItem &item : items)
this->set_deserialize(item.opt_key, item.opt_value, item.append);
}
bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, const std::string &value, bool append)
{
t_config_option_key opt_key = opt_key_src;
@ -729,6 +762,12 @@ void ConfigBase::null_nullables()
}
}
DynamicConfig::DynamicConfig(const ConfigBase& rhs, const t_config_option_keys& keys)
{
for (const t_config_option_key& opt_key : keys)
this->options[opt_key] = std::unique_ptr<ConfigOption>(rhs.option(opt_key)->clone());
}
bool DynamicConfig::operator==(const DynamicConfig &rhs) const
{
auto it1 = this->options.begin();
@ -878,7 +917,7 @@ bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra,
static_cast<ConfigOptionString*>(opt_base)->value = value;
} else {
// Any scalar value of a type different from Bool and String.
if (! this->set_deserialize(opt_key, value, false)) {
if (! this->set_deserialize_nothrow(opt_key, value, false)) {
boost::nowide::cerr << "Invalid value supplied for --" << token.c_str() << std::endl;
return false;
}

View File

@ -95,6 +95,16 @@ public:
std::runtime_error(std::string("Configuration exception: ") + opt_key) {}
};
/// Indicate that an unsupported accessor was called on a config option.
class BadOptionTypeException : public std::runtime_error
{
public:
BadOptionTypeException() :
std::runtime_error("Bad option type exception") {}
BadOptionTypeException(const char* message) :
std::runtime_error(message) {}
};
// Type of a configuration value.
enum ConfigOptionType {
coVectorType = 0x4000,
@ -145,6 +155,8 @@ enum PrinterTechnology : uint8_t
ptSLA = 1 << 1,
// Selective Laser-Sintering
ptSLS = 1 << 2,
// Any technology, useful for parameters compatible with both ptFFF and ptSLA
ptAny = 1+2+4,
// Unknown, useful for command line processing
ptUnknown = 1 << 7
};
@ -172,10 +184,10 @@ public:
virtual ConfigOption* clone() const = 0;
// Set a value from a ConfigOption. The two options should be compatible.
virtual void set(const ConfigOption *option) = 0;
virtual int getInt() const { throw std::runtime_error("Calling ConfigOption::getInt on a non-int ConfigOption"); }
virtual double getFloat() const { throw std::runtime_error("Calling ConfigOption::getFloat on a non-float ConfigOption"); }
virtual bool getBool() const { throw std::runtime_error("Calling ConfigOption::getBool on a non-boolean ConfigOption"); }
virtual void setInt(int /* val */) { throw std::runtime_error("Calling ConfigOption::setInt on a non-int ConfigOption"); }
virtual int getInt() const { throw BadOptionTypeException("Calling ConfigOption::getInt on a non-int ConfigOption"); }
virtual double getFloat() const { throw BadOptionTypeException("Calling ConfigOption::getFloat on a non-float ConfigOption"); }
virtual bool getBool() const { throw BadOptionTypeException("Calling ConfigOption::getBool on a non-boolean ConfigOption"); }
virtual void setInt(int /* val */) { throw BadOptionTypeException("Calling ConfigOption::setInt on a non-int ConfigOption"); }
virtual bool operator==(const ConfigOption &rhs) const = 0;
bool operator!=(const ConfigOption &rhs) const { return ! (*this == rhs); }
bool is_scalar() const { return (int(this->type()) & int(coVectorType)) == 0; }
@ -1498,7 +1510,7 @@ public:
std::vector<std::string> cli_args(const std::string &key) const;
// Assign this key to cli to disable CLI for this option.
static std::string nocli;
static const constexpr char *nocli = "~~~noCLI";
};
// Map from a config option name to its definition.
@ -1567,32 +1579,48 @@ protected:
public:
// Non-virtual methods:
bool has(const t_config_option_key &opt_key) const { return this->option(opt_key) != nullptr; }
const ConfigOption* option(const t_config_option_key &opt_key) const
{ return const_cast<ConfigBase*>(this)->option(opt_key, false); }
ConfigOption* option(const t_config_option_key &opt_key, bool create = false)
{ return this->optptr(opt_key, create); }
template<typename TYPE>
TYPE* option(const t_config_option_key &opt_key, bool create = false)
{
ConfigOption *opt = this->optptr(opt_key, create);
return (opt == nullptr || opt->type() != TYPE::static_type()) ? nullptr : static_cast<TYPE*>(opt);
}
template<typename TYPE>
const TYPE* option(const t_config_option_key &opt_key) const
{ return const_cast<ConfigBase*>(this)->option<TYPE>(opt_key, false); }
template<typename TYPE>
TYPE* option_throw(const t_config_option_key &opt_key, bool create = false)
ConfigOption* option_throw(const t_config_option_key &opt_key, bool create = false)
{
ConfigOption *opt = this->optptr(opt_key, create);
if (opt == nullptr)
throw UnknownOptionException(opt_key);
return opt;
}
const ConfigOption* option_throw(const t_config_option_key &opt_key) const
{ return const_cast<ConfigBase*>(this)->option_throw(opt_key, false); }
template<typename TYPE>
TYPE* option_throw(const t_config_option_key &opt_key, bool create = false)
{
ConfigOption *opt = this->option_throw(opt_key, create);
if (opt->type() != TYPE::static_type())
throw std::runtime_error("Conversion to a wrong type");
throw BadOptionTypeException("Conversion to a wrong type");
return static_cast<TYPE*>(opt);
}
template<typename TYPE>
const TYPE* option_throw(const t_config_option_key &opt_key) const
{ return const_cast<ConfigBase*>(this)->option_throw<TYPE>(opt_key, false); }
// Apply all keys of other ConfigBase defined by this->def() to this ConfigBase.
// An UnknownOptionException is thrown in case some option keys of other are not defined by this->def(),
// or this ConfigBase is of a StaticConfig type and it does not support some of the keys, and ignore_nonexistent is not set.
@ -1605,9 +1633,40 @@ public:
t_config_option_keys diff(const ConfigBase &other) const;
t_config_option_keys equal(const ConfigBase &other) const;
std::string opt_serialize(const t_config_option_key &opt_key) const;
// Set a value. Convert numeric types using a C style implicit conversion / promotion model.
// Throw if option is not avaiable and create is not enabled,
// or if the conversion is not possible.
// Conversion to string is always possible.
void set(const std::string &opt_key, bool value, bool create = false)
{ this->option_throw<ConfigOptionBool>(opt_key, create)->value = value; }
void set(const std::string &opt_key, int value, bool create = false);
void set(const std::string &opt_key, double value, bool create = false);
void set(const std::string &opt_key, const char *value, bool create = false)
{ this->option_throw<ConfigOptionString>(opt_key, create)->value = value; }
void set(const std::string &opt_key, const std::string &value, bool create = false)
{ this->option_throw<ConfigOptionString>(opt_key, create)->value = value; }
// Set a configuration value from a string, it will call an overridable handle_legacy()
// to resolve renamed and removed configuration keys.
bool set_deserialize(const t_config_option_key &opt_key, const std::string &str, bool append = false);
bool set_deserialize_nothrow(const t_config_option_key &opt_key_src, const std::string &value_src, bool append = false);
// May throw BadOptionTypeException() if the operation fails.
void set_deserialize(const t_config_option_key &opt_key, const std::string &str, bool append = false);
struct SetDeserializeItem {
SetDeserializeItem(const char *opt_key, const char *opt_value, bool append = false) : opt_key(opt_key), opt_value(opt_value), append(append) {}
SetDeserializeItem(const std::string &opt_key, const std::string &opt_value, bool append = false) : opt_key(opt_key), opt_value(opt_value), append(append) {}
SetDeserializeItem(const char *opt_key, const bool value, bool append = false) : opt_key(opt_key), opt_value(value ? "1" : "0"), append(append) {}
SetDeserializeItem(const std::string &opt_key, const bool value, bool append = false) : opt_key(opt_key), opt_value(value ? "1" : "0"), append(append) {}
SetDeserializeItem(const char *opt_key, const int value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const int value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const float value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const char *opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
SetDeserializeItem(const std::string &opt_key, const double value, bool append = false) : opt_key(opt_key), opt_value(std::to_string(value)), append(append) {}
std::string opt_key; std::string opt_value; bool append = false;
};
// May throw BadOptionTypeException() if the operation fails.
void set_deserialize(std::initializer_list<SetDeserializeItem> items);
double get_abs_value(const t_config_option_key &opt_key) const;
double get_abs_value(const t_config_option_key &opt_key, double ratio_over) const;
@ -1634,8 +1693,10 @@ class DynamicConfig : public virtual ConfigBase
{
public:
DynamicConfig() {}
DynamicConfig(const DynamicConfig& other) { *this = other; }
DynamicConfig(DynamicConfig&& other) : options(std::move(other.options)) { other.options.clear(); }
DynamicConfig(const DynamicConfig &rhs) { *this = rhs; }
DynamicConfig(DynamicConfig &&rhs) : options(std::move(rhs.options)) { rhs.options.clear(); }
explicit DynamicConfig(const ConfigBase &rhs, const t_config_option_keys &keys);
explicit DynamicConfig(const ConfigBase& rhs) : DynamicConfig(rhs, rhs.keys()) {}
virtual ~DynamicConfig() override { clear(); }
// Copy a content of one DynamicConfig to another DynamicConfig.

View File

@ -46,11 +46,29 @@ void EdgeGrid::Grid::create(const Polygons &polygons, coord_t resolution)
++ ncontours;
// Collect the contours.
m_contours.assign(ncontours, NULL);
m_contours.assign(ncontours, nullptr);
ncontours = 0;
for (size_t j = 0; j < polygons.size(); ++ j)
if (! polygons[j].points.empty())
m_contours[ncontours++] = &polygons[j].points;
m_contours[ncontours ++] = &polygons[j].points;
create_from_m_contours(resolution);
}
void EdgeGrid::Grid::create(const std::vector<Points> &polygons, coord_t resolution)
{
// Count the contours.
size_t ncontours = 0;
for (size_t j = 0; j < polygons.size(); ++ j)
if (! polygons[j].empty())
++ ncontours;
// Collect the contours.
m_contours.assign(ncontours, nullptr);
ncontours = 0;
for (size_t j = 0; j < polygons.size(); ++ j)
if (! polygons[j].empty())
m_contours[ncontours ++] = &polygons[j];
create_from_m_contours(resolution);
}
@ -66,7 +84,7 @@ void EdgeGrid::Grid::create(const ExPolygon &expoly, coord_t resolution)
++ ncontours;
// Collect the contours.
m_contours.assign(ncontours, NULL);
m_contours.assign(ncontours, nullptr);
ncontours = 0;
if (! expoly.contour.points.empty())
m_contours[ncontours++] = &expoly.contour.points;
@ -91,7 +109,7 @@ void EdgeGrid::Grid::create(const ExPolygons &expolygons, coord_t resolution)
}
// Collect the contours.
m_contours.assign(ncontours, NULL);
m_contours.assign(ncontours, nullptr);
ncontours = 0;
for (size_t i = 0; i < expolygons.size(); ++ i) {
const ExPolygon &expoly = expolygons[i];
@ -113,6 +131,7 @@ void EdgeGrid::Grid::create(const ExPolygonCollection &expolygons, coord_t resol
// m_contours has been initialized. Now fill in the edge grid.
void EdgeGrid::Grid::create_from_m_contours(coord_t resolution)
{
assert(resolution > 0);
// 1) Measure the bounding box.
for (size_t i = 0; i < m_contours.size(); ++ i) {
const Slic3r::Points &pts = *m_contours[i];
@ -281,7 +300,11 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution)
Visitor(std::vector<std::pair<size_t, size_t>> &cell_data, std::vector<Cell> &cells, size_t cols) :
cell_data(cell_data), cells(cells), cols(cols), i(0), j(0) {}
void operator()(coord_t iy, coord_t ix) { cell_data[cells[iy*cols + ix].end++] = std::pair<size_t, size_t>(i, j); }
inline bool operator()(coord_t iy, coord_t ix) {
cell_data[cells[iy*cols + ix].end++] = std::pair<size_t, size_t>(i, j);
// Continue traversing the grid along the edge.
return true;
}
std::vector<std::pair<size_t, size_t>> &cell_data;
std::vector<Cell> &cells;
@ -1018,7 +1041,138 @@ float EdgeGrid::Grid::signed_distance_bilinear(const Point &pt) const
return f;
}
bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radius, coordf_t &result_min_dist, bool *pon_segment) const {
EdgeGrid::Grid::ClosestPointResult EdgeGrid::Grid::closest_point(const Point &pt, coord_t search_radius) const
{
BoundingBox bbox;
bbox.min = bbox.max = Point(pt(0) - m_bbox.min(0), pt(1) - m_bbox.min(1));
bbox.defined = true;
// Upper boundary, round to grid and test validity.
bbox.max(0) += search_radius;
bbox.max(1) += search_radius;
ClosestPointResult result;
if (bbox.max(0) < 0 || bbox.max(1) < 0)
return result;
bbox.max(0) /= m_resolution;
bbox.max(1) /= m_resolution;
if ((size_t)bbox.max(0) >= m_cols)
bbox.max(0) = m_cols - 1;
if ((size_t)bbox.max(1) >= m_rows)
bbox.max(1) = m_rows - 1;
// Lower boundary, round to grid and test validity.
bbox.min(0) -= search_radius;
bbox.min(1) -= search_radius;
if (bbox.min(0) < 0)
bbox.min(0) = 0;
if (bbox.min(1) < 0)
bbox.min(1) = 0;
bbox.min(0) /= m_resolution;
bbox.min(1) /= m_resolution;
// Is the interval empty?
if (bbox.min(0) > bbox.max(0) ||
bbox.min(1) > bbox.max(1))
return result;
// Traverse all cells in the bounding box.
double d_min = double(search_radius);
// Signum of the distance field at pt.
int sign_min = 0;
double l2_seg_min = 1.;
for (int r = bbox.min(1); r <= bbox.max(1); ++ r) {
for (int c = bbox.min(0); c <= bbox.max(0); ++ c) {
const Cell &cell = m_cells[r * m_cols + c];
for (size_t i = cell.begin; i < cell.end; ++ i) {
const size_t contour_idx = m_cell_data[i].first;
const Slic3r::Points &pts = *m_contours[contour_idx];
size_t ipt = m_cell_data[i].second;
// End points of the line segment.
const Slic3r::Point &p1 = pts[ipt];
const Slic3r::Point &p2 = pts[(ipt + 1 == pts.size()) ? 0 : ipt + 1];
const Slic3r::Point v_seg = p2 - p1;
const Slic3r::Point v_pt = pt - p1;
// dot(p2-p1, pt-p1)
int64_t t_pt = int64_t(v_seg(0)) * int64_t(v_pt(0)) + int64_t(v_seg(1)) * int64_t(v_pt(1));
// l2 of seg
int64_t l2_seg = int64_t(v_seg(0)) * int64_t(v_seg(0)) + int64_t(v_seg(1)) * int64_t(v_seg(1));
if (t_pt < 0) {
// Closest to p1.
double dabs = sqrt(int64_t(v_pt(0)) * int64_t(v_pt(0)) + int64_t(v_pt(1)) * int64_t(v_pt(1)));
if (dabs < d_min) {
// Previous point.
const Slic3r::Point &p0 = pts[(ipt == 0) ? (pts.size() - 1) : ipt - 1];
Slic3r::Point v_seg_prev = p1 - p0;
int64_t t2_pt = int64_t(v_seg_prev(0)) * int64_t(v_pt(0)) + int64_t(v_seg_prev(1)) * int64_t(v_pt(1));
if (t2_pt > 0) {
// Inside the wedge between the previous and the next segment.
d_min = dabs;
// Set the signum depending on whether the vertex is convex or reflex.
int64_t det = int64_t(v_seg_prev(0)) * int64_t(v_seg(1)) - int64_t(v_seg_prev(1)) * int64_t(v_seg(0));
assert(det != 0);
sign_min = (det > 0) ? 1 : -1;
result.contour_idx = contour_idx;
result.start_point_idx = ipt;
result.t = 0.;
#ifndef NDEBUG
Vec2d vfoot = (p1 - pt).cast<double>();
double dist_foot = vfoot.norm();
double dist_foot_err = dist_foot - d_min;
assert(std::abs(dist_foot_err) < 1e-7 * d_min);
#endif /* NDEBUG */
}
}
}
else if (t_pt > l2_seg) {
// Closest to p2. Then p2 is the starting point of another segment, which shall be discovered in the same cell.
continue;
} else {
// Closest to the segment.
assert(t_pt >= 0 && t_pt <= l2_seg);
int64_t d_seg = int64_t(v_seg(1)) * int64_t(v_pt(0)) - int64_t(v_seg(0)) * int64_t(v_pt(1));
double d = double(d_seg) / sqrt(double(l2_seg));
double dabs = std::abs(d);
if (dabs < d_min) {
d_min = dabs;
sign_min = (d_seg < 0) ? -1 : ((d_seg == 0) ? 0 : 1);
l2_seg_min = l2_seg;
result.contour_idx = contour_idx;
result.start_point_idx = ipt;
result.t = t_pt;
#ifndef NDEBUG
Vec2d foot = p1.cast<double>() * (1. - result.t / l2_seg_min) + p2.cast<double>() * (result.t / l2_seg_min);
Vec2d vfoot = foot - pt.cast<double>();
double dist_foot = vfoot.norm();
double dist_foot_err = dist_foot - d_min;
assert(std::abs(dist_foot_err) < 1e-7 || std::abs(dist_foot_err) < 1e-7 * d_min);
#endif /* NDEBUG */
}
}
}
}
}
if (result.contour_idx != -1 && d_min <= double(search_radius)) {
result.distance = d_min * sign_min;
result.t /= l2_seg_min;
assert(result.t >= 0. && result.t < 1.);
#ifndef NDEBUG
{
const Slic3r::Points &pts = *m_contours[result.contour_idx];
const Slic3r::Point &p1 = pts[result.start_point_idx];
const Slic3r::Point &p2 = pts[(result.start_point_idx + 1 == pts.size()) ? 0 : result.start_point_idx + 1];
Vec2d vfoot;
if (result.t == 0)
vfoot = p1.cast<double>() - pt.cast<double>();
else
vfoot = p1.cast<double>() * (1. - result.t) + p2.cast<double>() * result.t - pt.cast<double>();
double dist_foot = vfoot.norm();
double dist_foot_err = dist_foot - std::abs(result.distance);
assert(std::abs(dist_foot_err) < 1e-7 || std::abs(dist_foot_err) < 1e-7 * std::abs(result.distance));
}
#endif /* NDEBUG */
} else
result = ClosestPointResult();
return result;
}
bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radius, coordf_t &result_min_dist, bool *pon_segment) const
{
BoundingBox bbox;
bbox.min = bbox.max = Point(pt(0) - m_bbox.min(0), pt(1) - m_bbox.min(1));
bbox.defined = true;
@ -1047,7 +1201,7 @@ bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radiu
bbox.min(1) > bbox.max(1))
return false;
// Traverse all cells in the bounding box.
float d_min = search_radius;
double d_min = double(search_radius);
// Signum of the distance field at pt.
int sign_min = 0;
bool on_segment = false;

View File

@ -21,10 +21,13 @@ public:
void set_bbox(const BoundingBox &bbox) { m_bbox = bbox; }
void create(const Polygons &polygons, coord_t resolution);
void create(const std::vector<Points> &polygons, coord_t resolution);
void create(const ExPolygon &expoly, coord_t resolution);
void create(const ExPolygons &expolygons, coord_t resolution);
void create(const ExPolygonCollection &expolygons, coord_t resolution);
const std::vector<const Slic3r::Points*>& contours() const { return m_contours; }
#if 0
// Test, whether the edges inside the grid intersect with the polygons provided.
bool intersect(const MultiPoint &polyline, bool closed);
@ -46,7 +49,19 @@ public:
float signed_distance_bilinear(const Point &pt) const;
// Calculate a signed distance to the contours in search_radius from the point.
bool signed_distance_edges(const Point &pt, coord_t search_radius, coordf_t &result_min_dist, bool *pon_segment = NULL) const;
struct ClosestPointResult {
size_t contour_idx = size_t(-1);
size_t start_point_idx = size_t(-1);
// Signed distance to the closest point.
double distance = std::numeric_limits<double>::max();
// Parameter of the closest point on edge starting with start_point_idx <0, 1)
double t = 0.;
bool valid() const { return contour_idx != size_t(-1); }
};
ClosestPointResult closest_point(const Point &pt, coord_t search_radius) const;
bool signed_distance_edges(const Point &pt, coord_t search_radius, coordf_t &result_min_dist, bool *pon_segment = nullptr) const;
// Calculate a signed distance to the contours in search_radius from the point. If no edge is found in search_radius,
// return an interpolated value from m_signed_distance_field, if it exists.
@ -65,7 +80,7 @@ public:
std::vector<std::pair<ContourEdge, ContourEdge>> intersecting_edges() const;
bool has_intersecting_edges() const;
template<typename FUNCTION> void visit_cells_intersecting_line(Slic3r::Point p1, Slic3r::Point p2, FUNCTION func) const
template<typename VISITOR> void visit_cells_intersecting_line(Slic3r::Point p1, Slic3r::Point p2, VISITOR &visitor) const
{
// End points of the line segment.
p1(0) -= m_bbox.min(0);
@ -82,8 +97,7 @@ public:
assert(ixb >= 0 && size_t(ixb) < m_cols);
assert(iyb >= 0 && size_t(iyb) < m_rows);
// Account for the end points.
func(iy, ix);
if (ix == ixb && iy == iyb)
if (! visitor(iy, ix) || (ix == ixb && iy == iyb))
// Both ends fall into the same cell.
return;
// Raster the centeral part of the line.
@ -113,7 +127,8 @@ public:
ey = int64_t(dx) * m_resolution;
iy += 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
else {
@ -131,7 +146,8 @@ public:
ey = int64_t(dx) * m_resolution;
iy -= 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
}
@ -153,7 +169,8 @@ public:
ey = int64_t(dx) * m_resolution;
iy += 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
else {
@ -185,12 +202,32 @@ public:
ey = int64_t(dx) * m_resolution;
iy -= 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
}
}
template<typename VISITOR> void visit_cells_intersecting_box(BoundingBox bbox, VISITOR &visitor) const
{
// End points of the line segment.
bbox.min -= m_bbox.min;
bbox.max -= m_bbox.min + Point(1, 1);
// Get the cells of the end points.
bbox.min /= m_resolution;
bbox.max /= m_resolution;
// Trim with the cells.
bbox.min.x() = std::max(bbox.min.x(), 0);
bbox.min.y() = std::max(bbox.min.y(), 0);
bbox.max.x() = std::min(bbox.max.x(), (coord_t)m_cols - 1);
bbox.max.y() = std::min(bbox.max.y(), (coord_t)m_rows - 1);
for (coord_t iy = bbox.min.y(); iy <= bbox.max.y(); ++ iy)
for (coord_t ix = bbox.min.x(); ix <= bbox.max.x(); ++ ix)
if (! visitor(iy, ix))
return;
}
std::pair<std::vector<std::pair<size_t, size_t>>::const_iterator, std::vector<std::pair<size_t, size_t>>::const_iterator> cell_data_range(coord_t row, coord_t col) const
{
const EdgeGrid::Grid::Cell &cell = m_cells[row * m_cols + col];

View File

@ -0,0 +1,609 @@
#include "clipper/clipper_z.hpp"
#include "libslic3r.h"
#include "ClipperUtils.hpp"
#include "EdgeGrid.hpp"
#include "ExPolygon.hpp"
#include "ElephantFootCompensation.hpp"
#include "Flow.hpp"
#include "Geometry.hpp"
#include "SVG.hpp"
#include "Utils.hpp"
#include <cmath>
#include <cassert>
// #define CONTOUR_DISTANCE_DEBUG_SVG
namespace Slic3r {
struct ResampledPoint {
ResampledPoint(size_t idx_src, bool interpolated, double curve_parameter) : idx_src(idx_src), interpolated(interpolated), curve_parameter(curve_parameter) {}
size_t idx_src;
// Is this point interpolated or initial?
bool interpolated;
// Euclidean distance along the curve from the 0th point.
double curve_parameter;
};
// Distance calculated using SDF (Shape Diameter Function).
// The distance is calculated by casting a fan of rays and measuring the intersection distance.
// Thus the calculation is relatively slow. For the Elephant foot compensation purpose, this distance metric does not avoid
// pinching off small pieces of a contour, thus this function has been superseded by contour_distance2().
std::vector<float> contour_distance(const EdgeGrid::Grid &grid, const size_t idx_contour, const Slic3r::Points &contour, const std::vector<ResampledPoint> &resampled_point_parameters, double search_radius)
{
assert(! contour.empty());
assert(contour.size() >= 2);
std::vector<float> out;
if (contour.size() > 2)
{
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
static int iRun = 0;
++ iRun;
BoundingBox bbox = get_extents(contour);
bbox.merge(grid.bbox());
ExPolygon expoly_grid;
expoly_grid.contour = Polygon(*grid.contours().front());
for (size_t i = 1; i < grid.contours().size(); ++ i)
expoly_grid.holes.emplace_back(Polygon(*grid.contours()[i]));
#endif
struct Visitor {
Visitor(const EdgeGrid::Grid &grid, const size_t idx_contour, const std::vector<ResampledPoint> &resampled_point_parameters, double dist_same_contour_reject) :
grid(grid), idx_contour(idx_contour), resampled_point_parameters(resampled_point_parameters), dist_same_contour_reject(dist_same_contour_reject) {}
void init(const size_t aidx_point_start, const Point &apt_start, Vec2d dir, const double radius) {
this->idx_point_start = aidx_point_start;
this->pt = apt_start.cast<double>() + SCALED_EPSILON * dir;
dir *= radius;
this->pt_start = this->pt.cast<coord_t>();
// Trim the vector by the grid's bounding box.
const BoundingBox &bbox = this->grid.bbox();
double t = 1.;
for (size_t axis = 0; axis < 2; ++ axis) {
double dx = std::abs(dir(axis));
if (dx >= EPSILON) {
double tedge = (dir(axis) > 0) ? (double(bbox.max(axis)) - SCALED_EPSILON - this->pt(axis)) : (this->pt(axis) - double(bbox.min(axis)) - SCALED_EPSILON);
if (tedge < dx)
t = std::min(t, tedge / dx);
}
}
this->dir = dir;
if (t < 1.)
dir *= t;
this->pt_end = (this->pt + dir).cast<coord_t>();
this->t_min = 1.;
assert(this->grid.bbox().contains(this->pt_start) && this->grid.bbox().contains(this->pt_end));
}
bool operator()(coord_t iy, coord_t ix) {
// Called with a row and colum of the grid cell, which is intersected by a line.
auto cell_data_range = this->grid.cell_data_range(iy, ix);
bool valid = true;
for (auto it_contour_and_segment = cell_data_range.first; it_contour_and_segment != cell_data_range.second; ++ it_contour_and_segment) {
// End points of the line segment and their vector.
auto segment = this->grid.segment(*it_contour_and_segment);
if (Geometry::segments_intersect(segment.first, segment.second, this->pt_start, this->pt_end)) {
// The two segments intersect. Calculate the intersection.
Vec2d pt2 = segment.first.cast<double>();
Vec2d dir2 = segment.second.cast<double>() - pt2;
Vec2d vptpt2 = pt - pt2;
double denom = dir(0) * dir2(1) - dir2(0) * dir(1);
if (std::abs(denom) >= EPSILON) {
double t = cross2(dir2, vptpt2) / denom;
assert(t > - EPSILON && t < 1. + EPSILON);
bool this_valid = true;
if (it_contour_and_segment->first == idx_contour) {
// The intersected segment originates from the same contour as the starting point.
// Reject the intersection if it is close to the starting point.
// Find the start and end points of this segment
double param_lo = resampled_point_parameters[idx_point_start].curve_parameter;
double param_hi;
double param_end = resampled_point_parameters.back().curve_parameter;
{
const Slic3r::Points &ipts = *grid.contours()[it_contour_and_segment->first];
size_t ipt = it_contour_and_segment->second;
ResampledPoint key(ipt, false, 0.);
auto lower = [](const ResampledPoint& l, const ResampledPoint r) { return l.idx_src < r.idx_src || (l.idx_src == r.idx_src && int(l.interpolated) > int(r.interpolated)); };
auto it = std::lower_bound(resampled_point_parameters.begin(), resampled_point_parameters.end(), key, lower);
assert(it != resampled_point_parameters.end() && it->idx_src == ipt && ! it->interpolated);
double t2 = cross2(dir, vptpt2) / denom;
assert(t2 > - EPSILON && t2 < 1. + EPSILON);
if (++ ipt == ipts.size())
param_hi = t2 * dir2.norm();
else
param_hi = it->curve_parameter + t2 * dir2.norm();
}
if (param_lo > param_hi)
std::swap(param_lo, param_hi);
assert(param_lo >= 0. && param_lo <= param_end);
assert(param_hi >= 0. && param_hi <= param_end);
this_valid = param_hi > param_lo + dist_same_contour_reject && param_hi - param_end < param_lo - dist_same_contour_reject;
}
if (t < this->t_min) {
this->t_min = t;
valid = this_valid;
}
}
}
if (! valid)
this->t_min = 1.;
}
// Continue traversing the grid along the edge.
return true;
}
const EdgeGrid::Grid &grid;
const size_t idx_contour;
const std::vector<ResampledPoint> &resampled_point_parameters;
const double dist_same_contour_reject;
size_t idx_point_start;
Point pt_start;
Point pt_end;
Vec2d pt;
Vec2d dir;
// Minium parameter along the vector (pt_end - pt_start).
double t_min;
} visitor(grid, idx_contour, resampled_point_parameters, search_radius);
const Point *pt_this = &contour.back();
size_t idx_pt_this = contour.size() - 1;
const Point *pt_prev = pt_this - 1;
// perpenduclar vector
auto perp = [](const Vec2d& v) -> Vec2d { return Vec2d(v.y(), -v.x()); };
Vec2d vprev = (*pt_this - *pt_prev).cast<double>().normalized();
out.reserve(contour.size() + 1);
for (const Point &pt_next : contour) {
Vec2d vnext = (pt_next - *pt_this).cast<double>().normalized();
Vec2d dir = - (perp(vprev) + perp(vnext)).normalized();
Vec2d dir_perp = perp(dir);
double cross = cross2(vprev, vnext);
double dot = vprev.dot(vnext);
double a = (cross < 0 || dot > 0.5) ? (M_PI / 3.) : (0.48 * acos(std::min(1., - dot)));
// Throw rays, collect distances.
std::vector<double> distances;
int num_rays = 15;
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
SVG svg(debug_out_path("contour_distance_raycasted-%d-%d.svg", iRun, &pt_next - contour.data()).c_str(), bbox);
svg.draw(expoly_grid);
svg.draw_outline(Polygon(contour), "blue", scale_(0.01));
svg.draw(*pt_this, "red", coord_t(scale_(0.1)));
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
for (int i = - num_rays + 1; i < num_rays; ++ i) {
double angle = a * i / (int)num_rays;
double c = cos(angle);
double s = sin(angle);
Vec2d v = c * dir + s * dir_perp;
visitor.init(idx_pt_this, *pt_this, v, search_radius);
grid.visit_cells_intersecting_line(visitor.pt_start, visitor.pt_end, visitor);
distances.emplace_back(visitor.t_min);
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
svg.draw(Line(visitor.pt_start, visitor.pt_end), "yellow", scale_(0.01));
if (visitor.t_min < 1.) {
Vec2d pt = visitor.pt + visitor.dir * visitor.t_min;
svg.draw(Point(pt), "red", coord_t(scale_(0.1)));
}
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
}
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
svg.Close();
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
std::sort(distances.begin(), distances.end());
#if 0
double median = distances[distances.size() / 2];
double standard_deviation = 0;
for (double d : distances)
standard_deviation += (d - median) * (d - median);
standard_deviation = sqrt(standard_deviation / (distances.size() - 1));
double avg = 0;
size_t cnt = 0;
for (double d : distances)
if (d > median - standard_deviation - EPSILON && d < median + standard_deviation + EPSILON) {
avg += d;
++ cnt;
}
avg /= double(cnt);
out.emplace_back(float(avg * search_radius));
#else
out.emplace_back(float(distances.front() * search_radius));
#endif
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
printf("contour_distance_raycasted-%d-%d.svg - distance %lf\n", iRun, int(&pt_next - contour.data()), unscale<double>(out.back()));
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
pt_this = &pt_next;
idx_pt_this = &pt_next - contour.data();
vprev = vnext;
}
// Rotate the vector by one item.
out.emplace_back(out.front());
out.erase(out.begin());
}
return out;
}
// Contour distance by measuring the closest point of an ExPolygon stored inside the EdgeGrid, while filtering out points of the same contour
// at concave regions, or convex regions with low curvature (curvature is estimated as a ratio between contour length and chordal distance crossing the contour ends).
std::vector<float> contour_distance2(const EdgeGrid::Grid &grid, const size_t idx_contour, const Slic3r::Points &contour, const std::vector<ResampledPoint> &resampled_point_parameters, double compensation, double search_radius)
{
assert(! contour.empty());
assert(contour.size() >= 2);
std::vector<float> out;
if (contour.size() > 2)
{
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
static int iRun = 0;
++ iRun;
BoundingBox bbox = get_extents(contour);
bbox.merge(grid.bbox());
ExPolygon expoly_grid;
expoly_grid.contour = Polygon(*grid.contours().front());
for (size_t i = 1; i < grid.contours().size(); ++ i)
expoly_grid.holes.emplace_back(Polygon(*grid.contours()[i]));
#endif
struct Visitor {
Visitor(const EdgeGrid::Grid &grid, const size_t idx_contour, const std::vector<ResampledPoint> &resampled_point_parameters, double dist_same_contour_accept, double dist_same_contour_reject) :
grid(grid), idx_contour(idx_contour), contour(*grid.contours()[idx_contour]), resampled_point_parameters(resampled_point_parameters), dist_same_contour_accept(dist_same_contour_accept), dist_same_contour_reject(dist_same_contour_reject) {}
void init(const Points &contour, const Point &apoint) {
this->idx_point = &apoint - contour.data();
this->point = apoint;
this->found = false;
this->dir_inside = this->dir_inside_at_point(contour, this->idx_point);
}
bool operator()(coord_t iy, coord_t ix) {
// Called with a row and colum of the grid cell, which is intersected by a line.
auto cell_data_range = this->grid.cell_data_range(iy, ix);
for (auto it_contour_and_segment = cell_data_range.first; it_contour_and_segment != cell_data_range.second; ++ it_contour_and_segment) {
// End points of the line segment and their vector.
std::pair<const Point&, const Point&> segment = this->grid.segment(*it_contour_and_segment);
const Vec2d v = (segment.second - segment.first).cast<double>();
const Vec2d va = (this->point - segment.first).cast<double>();
const double l2 = v.squaredNorm(); // avoid a sqrt
const double t = (l2 == 0.0) ? 0. : clamp(0., 1., va.dot(v) / l2);
// Closest point from this->point to the segment.
const Vec2d foot = segment.first.cast<double>() + t * v;
const Vec2d bisector = foot - this->point.cast<double>();
const double dist = bisector.norm();
if ((! this->found || dist < this->distance) && this->dir_inside.dot(bisector) > 0) {
bool accept = true;
if (it_contour_and_segment->first == idx_contour) {
// Complex case: The closest segment originates from the same contour as the starting point.
// Reject the closest point if its distance along the contour is reasonable compared to the current contour bisector (this->pt, foot).
double param_lo = resampled_point_parameters[this->idx_point].curve_parameter;
double param_hi;
double param_end = resampled_point_parameters.back().curve_parameter;
const Slic3r::Points &ipts = *grid.contours()[it_contour_and_segment->first];
const size_t ipt = it_contour_and_segment->second;
{
ResampledPoint key(ipt, false, 0.);
auto lower = [](const ResampledPoint& l, const ResampledPoint r) { return l.idx_src < r.idx_src || (l.idx_src == r.idx_src && int(l.interpolated) > int(r.interpolated)); };
auto it = std::lower_bound(resampled_point_parameters.begin(), resampled_point_parameters.end(), key, lower);
assert(it != resampled_point_parameters.end() && it->idx_src == ipt && ! it->interpolated);
param_hi = t * sqrt(l2);
if (ipt + 1 < ipts.size())
param_hi += it->curve_parameter;
}
if (param_lo > param_hi)
std::swap(param_lo, param_hi);
assert(param_lo > - SCALED_EPSILON && param_lo <= param_end + SCALED_EPSILON);
assert(param_hi > - SCALED_EPSILON && param_hi <= param_end + SCALED_EPSILON);
double dist_along_contour = std::min(param_hi - param_lo, param_lo + param_end - param_hi);
if (dist_along_contour < dist_same_contour_accept)
accept = false;
else if (dist < dist_same_contour_reject + SCALED_EPSILON) {
// this->point is close to foot. This point will only be accepted if the path along the contour is significantly
// longer than the bisector. That is, the path shall not bulge away from the bisector too much.
// Bulge is estimated by 0.6 of the circle circumference drawn around the bisector.
// Test whether the contour is convex or concave.
bool inside =
(t == 0.) ? this->inside_corner(ipts, ipt, this->point) :
(t == 1.) ? this->inside_corner(ipts, ipt + 1 == ipts.size() ? 0 : ipt + 1, this->point) :
this->left_of_segment(ipts, ipt, this->point);
accept = inside && dist_along_contour > 0.6 * M_PI * dist;
}
}
if (accept && (! this->found || dist < this->distance)) {
// Simple case: Just measure the shortest distance.
this->distance = dist;
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
this->closest_point = foot.cast<coord_t>();
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
this->found = true;
}
}
}
// Continue traversing the grid.
return true;
}
const EdgeGrid::Grid &grid;
const size_t idx_contour;
const Points &contour;
const std::vector<ResampledPoint> &resampled_point_parameters;
const double dist_same_contour_accept;
const double dist_same_contour_reject;
size_t idx_point;
Point point;
// Direction inside the contour from idx_point, not normalized.
Vec2d dir_inside;
bool found;
double distance;
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
Point closest_point;
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
private:
static Vec2d dir_inside_at_point(const Points &contour, size_t i) {
size_t iprev = prev_idx_modulo(i, contour);
size_t inext = next_idx_modulo(i, contour);
Vec2d v1 = (contour[i] - contour[iprev]).cast<double>();
Vec2d v2 = (contour[inext] - contour[i]).cast<double>();
return Vec2d(- v1.y() - v2.y(), v1.x() + v2.x());
}
static Vec2d dir_inside_at_segment(const Points& contour, size_t i) {
size_t inext = next_idx_modulo(i, contour);
Vec2d v = (contour[inext] - contour[i]).cast<double>();
return Vec2d(- v.y(), v.x());
}
static bool inside_corner(const Slic3r::Points &contour, size_t i, const Point &pt_oposite) {
const Vec2d pt = pt_oposite.cast<double>();
size_t iprev = prev_idx_modulo(i, contour);
size_t inext = next_idx_modulo(i, contour);
Vec2d v1 = (contour[i] - contour[iprev]).cast<double>();
Vec2d v2 = (contour[inext] - contour[i]).cast<double>();
bool left_of_v1 = cross2(v1, pt - contour[iprev].cast<double>()) > 0.;
bool left_of_v2 = cross2(v2, pt - contour[i ].cast<double>()) > 0.;
return cross2(v1, v2) > 0 ?
left_of_v1 && left_of_v2 : // convex corner
left_of_v1 || left_of_v2; // concave corner
}
static bool left_of_segment(const Slic3r::Points &contour, size_t i, const Point &pt_oposite) {
const Vec2d pt = pt_oposite.cast<double>();
size_t inext = next_idx_modulo(i, contour);
Vec2d v = (contour[inext] - contour[i]).cast<double>();
return cross2(v, pt - contour[i].cast<double>()) > 0.;
}
} visitor(grid, idx_contour, resampled_point_parameters, 0.5 * compensation * M_PI, search_radius);
out.reserve(contour.size());
Point radius_vector(search_radius, search_radius);
for (const Point &pt : contour) {
visitor.init(contour, pt);
grid.visit_cells_intersecting_box(BoundingBox(pt - radius_vector, pt + radius_vector), visitor);
out.emplace_back(float(visitor.found ? std::min(visitor.distance, search_radius) : search_radius));
#if 0
//#ifdef CONTOUR_DISTANCE_DEBUG_SVG
if (out.back() < search_radius) {
SVG svg(debug_out_path("contour_distance_filtered-%d-%d.svg", iRun, int(&pt - contour.data())).c_str(), bbox);
svg.draw(expoly_grid);
svg.draw_outline(Polygon(contour), "blue", scale_(0.01));
svg.draw(pt, "green", coord_t(scale_(0.1)));
svg.draw(visitor.closest_point, "red", coord_t(scale_(0.1)));
printf("contour_distance_filtered-%d-%d.svg - distance %lf\n", iRun, int(&pt - contour.data()), unscale<double>(out.back()));
}
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
}
#ifdef CONTOUR_DISTANCE_DEBUG_SVG
if (out.back() < search_radius) {
SVG svg(debug_out_path("contour_distance_filtered-final-%d.svg", iRun).c_str(), bbox);
svg.draw(expoly_grid);
svg.draw_outline(Polygon(contour), "blue", scale_(0.01));
for (size_t i = 0; i < contour.size(); ++ i)
svg.draw(contour[i], out[i] < float(search_radius - SCALED_EPSILON) ? "red" : "green", coord_t(scale_(0.1)));
}
#endif /* CONTOUR_DISTANCE_DEBUG_SVG */
}
return out;
}
Points resample_polygon(const Points &contour, double dist, std::vector<ResampledPoint> &resampled_point_parameters)
{
Points out;
out.reserve(contour.size());
resampled_point_parameters.reserve(contour.size());
if (contour.size() > 2) {
Vec2d pt_prev = contour.back().cast<double>();
for (const Point &pt : contour) {
size_t idx_this = &pt - contour.data();
const Vec2d pt_this = pt.cast<double>();
const Vec2d v = pt_this - pt_prev;
const double l = v.norm();
const size_t n = size_t(ceil(l / dist));
const double l_step = l / n;
for (size_t i = 1; i < n; ++ i) {
double interpolation_parameter = double(i) / n;
Vec2d new_pt = pt_prev + v * interpolation_parameter;
out.emplace_back(new_pt.cast<coord_t>());
resampled_point_parameters.emplace_back(idx_this, true, l_step);
}
out.emplace_back(pt);
resampled_point_parameters.emplace_back(idx_this, false, l_step);
pt_prev = pt_this;
}
for (size_t i = 1; i < resampled_point_parameters.size(); ++i)
resampled_point_parameters[i].curve_parameter += resampled_point_parameters[i - 1].curve_parameter;
}
return out;
}
static inline void smooth_compensation(std::vector<float> &compensation, float strength, size_t num_iterations)
{
std::vector<float> out(compensation);
for (size_t iter = 0; iter < num_iterations; ++ iter) {
for (size_t i = 0; i < compensation.size(); ++ i) {
float prev = prev_value_modulo(i, compensation);
float next = next_value_modulo(i, compensation);
float laplacian = compensation[i] * (1.f - strength) + 0.5f * strength * (prev + next);
// Compensations are negative. Only apply the laplacian if it leads to lower compensation.
out[i] = std::max(laplacian, compensation[i]);
}
out.swap(compensation);
}
}
static inline void smooth_compensation_banded(const Points &contour, float band, std::vector<float> &compensation, float strength, size_t num_iterations)
{
assert(contour.size() == compensation.size());
assert(contour.size() > 2);
std::vector<float> out(compensation);
float dist_min2 = band * band;
static constexpr bool use_min = false;
for (size_t iter = 0; iter < num_iterations; ++ iter) {
for (int i = 0; i < int(compensation.size()); ++ i) {
const Vec2f pthis = contour[i].cast<float>();
int j = prev_idx_modulo(i, contour);
Vec2f pprev = contour[j].cast<float>();
float prev = compensation[j];
float l2 = (pthis - pprev).squaredNorm();
if (l2 < dist_min2) {
float l = sqrt(l2);
int jprev = exchange(j, prev_idx_modulo(j, contour));
while (j != i) {
const Vec2f pp = contour[j].cast<float>();
const float lthis = (pp - pprev).norm();
const float lnext = l + lthis;
if (lnext > band) {
// Interpolate the compensation value.
prev = use_min ?
std::min(prev, lerp(compensation[jprev], compensation[j], (band - l) / lthis)) :
lerp(compensation[jprev], compensation[j], (band - l) / lthis);
break;
}
prev = use_min ? std::min(prev, compensation[j]) : compensation[j];
pprev = pp;
l = lnext;
jprev = exchange(j, prev_idx_modulo(j, contour));
}
}
j = next_idx_modulo(i, contour);
pprev = contour[j].cast<float>();
float next = compensation[j];
l2 = (pprev - pthis).squaredNorm();
if (l2 < dist_min2) {
float l = sqrt(l2);
int jprev = exchange(j, next_idx_modulo(j, contour));
while (j != i) {
const Vec2f pp = contour[j].cast<float>();
const float lthis = (pp - pprev).norm();
const float lnext = l + lthis;
if (lnext > band) {
// Interpolate the compensation value.
next = use_min ?
std::min(next, lerp(compensation[jprev], compensation[j], (band - l) / lthis)) :
lerp(compensation[jprev], compensation[j], (band - l) / lthis);
break;
}
next = use_min ? std::min(next, compensation[j]) : compensation[j];
pprev = pp;
l = lnext;
jprev = exchange(j, next_idx_modulo(j, contour));
}
}
float laplacian = compensation[i] * (1.f - strength) + 0.5f * strength * (prev + next);
// Compensations are negative. Only apply the laplacian if it leads to lower compensation.
out[i] = std::max(laplacian, compensation[i]);
}
out.swap(compensation);
}
}
ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, const Flow &external_perimeter_flow, const double compensation)
{
// The contour shall be wide enough to apply the external perimeter plus compensation on both sides.
double min_contour_width = double(external_perimeter_flow.scaled_width() + external_perimeter_flow.scaled_spacing());
double scaled_compensation = scale_(compensation);
double min_contour_width_compensated = min_contour_width + 2. * scaled_compensation;
// Make the search radius a bit larger for the averaging in contour_distance over a fan of rays to work.
double search_radius = min_contour_width_compensated + min_contour_width * 0.5;
BoundingBox bbox = get_extents(input_expoly.contour);
Point bbox_size = bbox.size();
ExPolygon out;
if (bbox_size.x() < min_contour_width_compensated + SCALED_EPSILON ||
bbox_size.y() < min_contour_width_compensated + SCALED_EPSILON ||
input_expoly.area() < min_contour_width_compensated * min_contour_width_compensated * 5.)
{
// The contour is tiny. Don't correct it.
out = input_expoly;
}
else
{
EdgeGrid::Grid grid;
ExPolygon simplified = input_expoly.simplify(SCALED_EPSILON).front();
BoundingBox bbox = get_extents(simplified.contour);
bbox.offset(SCALED_EPSILON);
grid.set_bbox(bbox);
grid.create(simplified, coord_t(0.7 * search_radius));
std::vector<std::vector<float>> deltas;
deltas.reserve(simplified.holes.size() + 1);
ExPolygon resampled(simplified);
double resample_interval = scale_(0.5);
for (size_t idx_contour = 0; idx_contour <= simplified.holes.size(); ++ idx_contour) {
Polygon &poly = (idx_contour == 0) ? resampled.contour : resampled.holes[idx_contour - 1];
std::vector<ResampledPoint> resampled_point_parameters;
poly.points = resample_polygon(poly.points, resample_interval, resampled_point_parameters);
std::vector<float> dists = contour_distance2(grid, idx_contour, poly.points, resampled_point_parameters, scaled_compensation, search_radius);
for (float &d : dists) {
// printf("Point %d, Distance: %lf\n", int(&d - dists.data()), unscale<double>(d));
// Convert contour width to available compensation distance.
if (d < min_contour_width)
d = 0.f;
else if (d > min_contour_width_compensated)
d = - float(scaled_compensation);
else
d = - (d - float(min_contour_width)) / 2.f;
assert(d >= - float(scaled_compensation) && d <= 0.f);
}
// smooth_compensation(dists, 0.4f, 10);
smooth_compensation_banded(poly.points, float(0.8 * resample_interval), dists, 0.3f, 3);
deltas.emplace_back(dists);
}
ExPolygons out_vec = variable_offset_inner_ex(resampled, deltas, 2.);
if (out_vec.size() == 1)
out = std::move(out_vec.front());
else {
// Something went wrong, don't compensate.
out = input_expoly;
#ifdef TESTS_EXPORT_SVGS
if (out_vec.size() > 1) {
static int iRun = 0;
SVG::export_expolygons(debug_out_path("elephant_foot_compensation-many_contours-%d.svg", iRun ++).c_str(),
{ { { input_expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } },
{ { out_vec }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } } });
}
#endif /* TESTS_EXPORT_SVGS */
assert(out_vec.size() == 1);
}
}
return out;
}
ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation)
{
ExPolygons out;
out.reserve(input.size());
for (const ExPolygon &expoly : input)
out.emplace_back(elephant_foot_compensation(expoly, external_perimeter_flow, compensation));
return out;
}
} // namespace Slic3r

View File

@ -0,0 +1,16 @@
#ifndef slic3r_ElephantFootCompensation_hpp_
#define slic3r_ElephantFootCompensation_hpp_
#include "libslic3r.h"
#include <vector>
namespace Slic3r {
class Flow;
ExPolygon elephant_foot_compensation(const ExPolygon &input, const Flow &external_perimeter_flow, const double compensation);
ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation);
} // Slic3r
#endif /* slic3r_ElephantFootCompensation_hpp_ */

View File

@ -20,6 +20,16 @@ public:
ExPolygon() {}
ExPolygon(const ExPolygon &other) : contour(other.contour), holes(other.holes) {}
ExPolygon(ExPolygon &&other) : contour(std::move(other.contour)), holes(std::move(other.holes)) {}
explicit ExPolygon(const Polygon &contour) : contour(contour) {}
explicit ExPolygon(Polygon &&contour) : contour(std::move(contour)) {}
explicit ExPolygon(const Points &contour) : contour(contour) {}
explicit ExPolygon(Points &&contour) : contour(std::move(contour)) {}
explicit ExPolygon(const Polygon &contour, const Polygon &hole) : contour(contour) { holes.emplace_back(hole); }
explicit ExPolygon(Polygon &&contour, Polygon &&hole) : contour(std::move(contour)) { holes.emplace_back(std::move(hole)); }
explicit ExPolygon(const Points &contour, const Points &hole) : contour(contour) { holes.emplace_back(hole); }
explicit ExPolygon(Points &&contour, Polygon &&hole) : contour(std::move(contour)) { holes.emplace_back(std::move(hole)); }
ExPolygon(std::initializer_list<Point> contour) : contour(contour) {}
ExPolygon(std::initializer_list<Point> contour, std::initializer_list<Point> hole) : contour(contour), holes({ hole }) {}
ExPolygon& operator=(const ExPolygon &other) { contour = other.contour; holes = other.holes; return *this; }
ExPolygon& operator=(ExPolygon &&other) { contour = std::move(other.contour); holes = std::move(other.holes); return *this; }
@ -68,8 +78,16 @@ public:
void triangulate_pp(Points *triangles) const;
void triangulate_p2t(Polygons* polygons) const;
Lines lines() const;
// Number of contours (outer contour with holes).
size_t num_contours() const { return this->holes.size() + 1; }
Polygon& contour_or_hole(size_t idx) { return (idx == 0) ? this->contour : this->holes[idx - 1]; }
const Polygon& contour_or_hole(size_t idx) const { return (idx == 0) ? this->contour : this->holes[idx - 1]; }
};
inline bool operator==(const ExPolygon &lhs, const ExPolygon &rhs) { return lhs.contour == rhs.contour && lhs.holes == rhs.holes; }
inline bool operator!=(const ExPolygon &lhs, const ExPolygon &rhs) { return lhs.contour != rhs.contour || lhs.holes != rhs.holes; }
// Count a nuber of polygons stored inside the vector of expolygons.
// Useful for allocating space for polygons when converting expolygons to polygons.
inline size_t number_polygons(const ExPolygons &expolys)
@ -316,6 +334,15 @@ inline bool expolygons_contain(ExPolygons &expolys, const Point &pt)
return false;
}
inline ExPolygons expolygons_simplify(const ExPolygons &expolys, double tolerance)
{
ExPolygons out;
out.reserve(expolys.size());
for (const ExPolygon &exp : expolys)
exp.simplify(tolerance, &out);
return out;
}
extern BoundingBox get_extents(const ExPolygon &expolygon);
extern BoundingBox get_extents(const ExPolygons &expolygons);
extern BoundingBox get_extents_rotated(const ExPolygon &poly, double angle);

View File

@ -11,7 +11,7 @@ ExPolygonCollection::ExPolygonCollection(const ExPolygon &expolygon)
ExPolygonCollection::operator Points() const
{
Points points;
Polygons pp = *this;
Polygons pp = (Polygons)*this;
for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) {
for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point)
points.push_back(*point);

View File

@ -13,15 +13,15 @@ typedef std::vector<ExPolygonCollection> ExPolygonCollections;
class ExPolygonCollection
{
public:
public:
ExPolygons expolygons;
ExPolygonCollection() {};
ExPolygonCollection(const ExPolygon &expolygon);
ExPolygonCollection(const ExPolygons &expolygons) : expolygons(expolygons) {};
operator Points() const;
operator Polygons() const;
operator ExPolygons&();
ExPolygonCollection() {}
explicit ExPolygonCollection(const ExPolygon &expolygon);
explicit ExPolygonCollection(const ExPolygons &expolygons) : expolygons(expolygons) {}
explicit operator Points() const;
explicit operator Polygons() const;
explicit operator ExPolygons&();
void scale(double factor);
void translate(double x, double y);
void rotate(double angle, const Point &center);

View File

@ -30,12 +30,12 @@ void ExtrusionVisitorConst::use(const ExtrusionEntityCollection &collection) { d
void
ExtrusionPath::intersect_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const
{
this->_inflate_collection(intersection_pl(this->polyline, collection), retval);
this->_inflate_collection(intersection_pl(this->polyline, (Polygons)collection), retval);
}
void ExtrusionPath::subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const
{
this->_inflate_collection(diff_pl(this->polyline, collection), retval);
this->_inflate_collection(diff_pl(this->polyline, (Polygons)collection), retval);
}
void ExtrusionPath::clip_end(double distance)

View File

@ -5,6 +5,8 @@
#include "Polygon.hpp"
#include "Polyline.hpp"
#include <assert.h>
namespace Slic3r {
class ExPolygonCollection;
@ -12,7 +14,7 @@ class ExtrusionEntityCollection;
class Extruder;
// Each ExtrusionRole value identifies a distinct set of { extruder, speed }
enum ExtrusionRole {
enum ExtrusionRole : uint8_t {
erNone,
erPerimeter,
erExternalPerimeter,
@ -132,8 +134,8 @@ public:
virtual ExtrusionEntity* clone_move() = 0;
virtual ~ExtrusionEntity() {}
virtual void reverse() = 0;
virtual Point first_point() const = 0;
virtual Point last_point() const = 0;
virtual const Point& first_point() const = 0;
virtual const Point& last_point() const = 0;
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
virtual void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const = 0;
@ -170,30 +172,23 @@ public:
float width;
// Height of the extrusion, used for visualization purposes.
float height;
// Feedrate of the extrusion, used for visualization purposes.
float feedrate;
// Id of the extruder, used for visualization purposes.
unsigned int extruder_id;
// Id of the color, used for visualization purposes in the color printing case.
unsigned int cp_color_id;
ExtrusionPath(ExtrusionRole role) : mm3_per_mm(-1), width(-1), height(-1), feedrate(0.0f), extruder_id(0), cp_color_id(0), m_role(role) {}
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : mm3_per_mm(mm3_per_mm), width(width), height(height), feedrate(0.0f), extruder_id(0), cp_color_id(0), m_role(role) {}
ExtrusionPath(const ExtrusionPath &rhs) : polyline(rhs.polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), feedrate(rhs.feedrate), extruder_id(rhs.extruder_id), cp_color_id(rhs.cp_color_id), m_role(rhs.m_role) {}
ExtrusionPath(const Polyline &polyline, const ExtrusionPath &rhs) : polyline(polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), feedrate(rhs.feedrate), extruder_id(rhs.extruder_id), cp_color_id(rhs.cp_color_id), m_role(rhs.m_role) {}
ExtrusionPath(ExtrusionPath &&rhs) : polyline(std::move(rhs.polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), feedrate(rhs.feedrate), extruder_id(rhs.extruder_id), cp_color_id(rhs.cp_color_id), m_role(rhs.m_role) {}
ExtrusionPath(Polyline &&polyline, const ExtrusionPath &rhs) : polyline(std::move(polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), feedrate(rhs.feedrate), extruder_id(rhs.extruder_id), cp_color_id(rhs.cp_color_id), m_role(rhs.m_role) {}
// ExtrusionPath(ExtrusionRole role, const Flow &flow) : m_role(role), mm3_per_mm(flow.mm3_per_mm()), width(flow.width), height(flow.height), feedrate(0.0f), extruder_id(0) {};
ExtrusionPath(ExtrusionRole role) : mm3_per_mm(-1), width(-1), height(-1), m_role(role) {};
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : mm3_per_mm(mm3_per_mm), width(width), height(height), m_role(role) {};
ExtrusionPath(const ExtrusionPath& rhs) : polyline(rhs.polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath(ExtrusionPath&& rhs) : polyline(std::move(rhs.polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath(const Polyline &polyline, const ExtrusionPath &rhs) : polyline(polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath(Polyline &&polyline, const ExtrusionPath &rhs) : polyline(std::move(polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath& operator=(const ExtrusionPath &rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->feedrate = rhs.feedrate; this->extruder_id = rhs.extruder_id; this->cp_color_id = rhs.cp_color_id; this->polyline = rhs.polyline; return *this; }
ExtrusionPath& operator=(ExtrusionPath &&rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->feedrate = rhs.feedrate; this->extruder_id = rhs.extruder_id; this->cp_color_id = rhs.cp_color_id; this->polyline = std::move(rhs.polyline); return *this; }
ExtrusionPath& operator=(const ExtrusionPath& rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->polyline = rhs.polyline; return *this; }
ExtrusionPath& operator=(ExtrusionPath&& rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height; this->polyline = std::move(rhs.polyline); return *this; }
virtual ExtrusionPath* clone() const override { return new ExtrusionPath(*this); }
// Create a new object, initialize it with this object using the move semantics.
virtual ExtrusionPath* clone_move() override { return new ExtrusionPath(std::move(*this)); }
void reverse() override { this->polyline.reverse(); }
Point first_point() const override { return this->polyline.points.front(); }
Point last_point() const override { return this->polyline.points.back(); }
const Point& first_point() const override { return this->polyline.points.front(); }
const Point& last_point() const override { return this->polyline.points.back(); }
size_t size() const { return this->polyline.size(); }
bool empty() const { return this->polyline.empty(); }
bool is_closed() const { return ! this->empty() && this->polyline.points.front() == this->polyline.points.back(); }
@ -247,10 +242,10 @@ public:
// ExtrusionPath(ExtrusionRole role, const Flow &flow) : m_role(role), mm3_per_mm(flow.mm3_per_mm()), width(flow.width), height(flow.height), feedrate(0.0f), extruder_id(0) {};
ExtrusionPath3D& operator=(const ExtrusionPath3D &rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height;
this->feedrate = rhs.feedrate, this->extruder_id = rhs.extruder_id, this->cp_color_id = rhs.cp_color_id, this->polyline = rhs.polyline; z_offsets = rhs.z_offsets; return *this;
this->polyline = rhs.polyline; z_offsets = rhs.z_offsets; return *this;
}
ExtrusionPath3D& operator=(ExtrusionPath3D &&rhs) { m_role = rhs.m_role; this->mm3_per_mm = rhs.mm3_per_mm; this->width = rhs.width; this->height = rhs.height;
this->feedrate = rhs.feedrate, this->extruder_id = rhs.extruder_id, this->cp_color_id = rhs.cp_color_id, this->polyline = std::move(rhs.polyline); z_offsets = std::move(rhs.z_offsets); return *this;
this->polyline = std::move(rhs.polyline); z_offsets = std::move(rhs.z_offsets); return *this;
}
virtual ExtrusionPath3D* clone() const { return new ExtrusionPath3D(*this); }
virtual ExtrusionPath3D* clone_move() override { return new ExtrusionPath3D(std::move(*this)); }
@ -281,8 +276,8 @@ public:
bool is_loop() const override { return false; }
ExtrusionRole role() const override { return this->paths.empty() ? erNone : this->paths.front().role(); }
virtual Point first_point() const override { return this->paths.back().as_polyline().points.back(); }
virtual Point last_point() const override { return this->paths.back().as_polyline().points.back(); }
virtual const Point& first_point() const override { return this->paths.back().as_polyline().points.back(); }
virtual const Point& last_point() const override { return this->paths.back().as_polyline().points.back(); }
virtual void reverse() override {
for (THING &entity : this->paths)
@ -407,8 +402,8 @@ public:
bool make_clockwise();
bool make_counter_clockwise();
virtual void reverse() override;
Point first_point() const override { return this->paths.front().polyline.points.front(); }
Point last_point() const override { assert(first_point() == this->paths.back().polyline.points.back()); return first_point(); }
const Point& first_point() const override { return this->paths.front().polyline.points.front(); }
const Point& last_point() const override { assert(this->first_point() == this->paths.back().polyline.points.back()); return this->first_point(); }
Polygon polygon() const;
double length() const override;
bool split_at_vertex(const Point &point);
@ -440,6 +435,15 @@ public:
//static inline std::string role_to_string(ExtrusionLoopRole role);
#ifndef NDEBUG
bool validate() const {
assert(this->first_point() == this->paths.back().polyline.points.back());
for (size_t i = 1; i < paths.size(); ++ i)
assert(this->paths[i - 1].polyline.points.back() == this->paths[i].polyline.points.front());
return true;
}
#endif /* NDEBUG */
private:
ExtrusionLoopRole m_loop_role;
};

View File

@ -1,4 +1,5 @@
#include "ExtrusionEntityCollection.hpp"
#include "ShortestPath.hpp"
#include <algorithm>
#include <cmath>
#include <map>
@ -16,7 +17,6 @@ ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const Extrusion
this->entities = other.entities;
for (size_t i = 0; i < this->entities.size(); ++i)
this->entities[i] = this->entities[i]->clone();
this->orig_indices = other.orig_indices;
this->no_sort = other.no_sort;
return *this;
}
@ -24,7 +24,6 @@ ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const Extrusion
void ExtrusionEntityCollection::swap(ExtrusionEntityCollection &c)
{
std::swap(this->entities, c.entities);
std::swap(this->orig_indices, c.orig_indices);
std::swap(this->no_sort, c.no_sort);
}
@ -77,82 +76,31 @@ void ExtrusionEntityCollection::remove(size_t i)
this->entities.erase(this->entities.begin() + i);
}
ExtrusionEntityCollection ExtrusionEntityCollection::chained_path(bool no_reverse, ExtrusionRole role) const
{
ExtrusionEntityCollection coll;
this->chained_path(&coll, no_reverse, role);
return coll;
}
void ExtrusionEntityCollection::chained_path(ExtrusionEntityCollection* retval, bool no_reverse, ExtrusionRole role, std::vector<size_t>* orig_indices) const
{
if (this->entities.empty()) return;
this->chained_path_from(this->entities.front()->first_point(), retval, no_reverse, role, orig_indices);
}
ExtrusionEntityCollection ExtrusionEntityCollection::chained_path_from(Point start_near, bool no_reverse, ExtrusionRole role) const
{
ExtrusionEntityCollection coll;
this->chained_path_from(start_near, &coll, no_reverse, role);
return coll;
}
void ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse, ExtrusionRole role, std::vector<size_t>* orig_indices) const
ExtrusionEntityCollection ExtrusionEntityCollection::chained_path_from(const Point &start_near, ExtrusionRole role) const
{
ExtrusionEntityCollection out;
if (this->no_sort) {
*retval = *this;
return;
}
retval->entities.reserve(this->entities.size());
retval->orig_indices.reserve(this->entities.size());
// if we're asked to return the original indices, build a map
std::map<ExtrusionEntity*,size_t> indices_map;
ExtrusionEntitiesPtr my_paths;
for (ExtrusionEntity * const &entity_src : this->entities) {
out = *this;
} else {
if (role == erMixed)
out = *this;
else {
for (const ExtrusionEntity *ee : this->entities) {
if (role != erMixed) {
// The caller wants only paths with a specific extrusion role.
ExtrusionRole role2 = entity_src->role();
auto role2 = ee->role();
if (role != role2) {
// This extrusion entity does not match the role asked.
assert(role2 != erMixed);
continue;
}
}
ExtrusionEntity *entity = entity_src->clone();
my_paths.push_back(entity);
if (orig_indices != nullptr)
indices_map[entity] = &entity_src - &this->entities.front();
}
Points endpoints;
for (const ExtrusionEntity *entity : my_paths) {
endpoints.push_back(entity->first_point());
if (no_reverse || !entity->can_reverse()) {
endpoints.push_back(entity->first_point());
} else {
endpoints.push_back(entity->last_point());
out.entities.emplace_back(ee->clone());
}
}
while (!my_paths.empty()) {
// find nearest point
int start_index = start_near.nearest_point_index(endpoints);
int path_index = start_index/2;
ExtrusionEntity* entity = my_paths.at(path_index);
// never reverse loops, since it's pointless for chained path and callers might depend on orientation
if (start_index % 2 && !no_reverse && entity->can_reverse())
entity->reverse();
retval->entities.push_back(my_paths.at(path_index));
if (orig_indices != nullptr)
orig_indices->push_back(indices_map[entity]);
my_paths.erase(my_paths.begin() + path_index);
endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
start_near = retval->entities.back()->last_point();
chain_and_reorder_extrusion_entities(out.entities, &start_near);
}
return out;
}
void ExtrusionEntityCollection::polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const
@ -179,39 +127,9 @@ CountEntities::use(const ExtrusionEntityCollection &coll) {
entity->visit(*this);
}
}
//
//void
//ExtrusionEntityCollection::flatten(ExtrusionEntityCollection* retval, bool preserve_ordering) const
//{
// if (this->no_sort && preserve_ordering) {
// /// if we want to preserve ordering and we can't sort, break out the unsorted ones first.
// ExtrusionEntityCollection *unsortable = new ExtrusionEntityCollection();
// unsortable->no_sort = true;
// unsortable->orig_indices = this->orig_indices;
// retval->append(*unsortable);
// for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
// if ((*it)->is_collection()) {
// ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it);
// collection->flatten(unsortable, preserve_ordering);
// } else {
// unsortable->append(**it);
// }
// }
// } else {
// for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
// if ((*it)->is_collection()) {
// ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it);
// retval->append(collection->flatten().entities);
// } else {
// retval->append(**it);
// }
// }
// }
//}
/* Returns a single vector of chained (new) pointers to all non-collection items contained in this one */
ExtrusionEntityCollection
ExtrusionEntityCollection::flatten(bool preserve_ordering) const
// Returns a single vector of pointers to all non-collection items contained in this one.
ExtrusionEntityCollection ExtrusionEntityCollection::flatten(bool preserve_ordering) const
{
//ExtrusionEntityCollection coll;
//this->flatten(&coll, preserve_ordering);

Some files were not shown because too many files have changed in this diff Show More