Skip to content

Compile for Mac #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,6 @@ cython_debug/
#######################################
# get rid of output folder
_build/

# macos
.DS_Store
152 changes: 92 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
cmake_minimum_required(VERSION 3.16.)
project(diffCheck VERSION 1.3.0 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")

# Force usage of libc++ and proper visibility on macOS
# For some reason, without this, there will be a segfault in test
if(APPLE)
add_compile_options(-stdlib=libc++ -fvisibility=hidden -Wall)
add_link_options(-stdlib=libc++)
endif()

# # Set rpath for Python extension loading on macOS
# set(CMAKE_MACOSX_RPATH ON)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Expand Down Expand Up @@ -40,27 +51,31 @@ endif()
set(SHARED_LIB_NAME diffCheck)

file(GLOB_RECURSE SOURCES_LIB
src/diffCheck.hh # diffCheck interface
src/diffCheck/*.cc src/diffCheck/*.hh # diffCheck src
)

add_library(${SHARED_LIB_NAME} SHARED ${SOURCES_LIB})
src/diffCheck.hh # diffCheck interface
src/diffCheck/*.cc src/diffCheck/*.hh # diffCheck src
src/diffCheck/*/*.cc src/diffCheck/*/*.hh # diffCheck submodules
)

# print the sources founded
add_library(${SHARED_LIB_NAME} STATIC ${SOURCES_LIB})

# if (WIN32)
# set_target_properties(${SHARED_LIB_NAME} PROPERTIES
# WINDOWS_EXPORT_ALL_SYMBOLS TRUE
# )
# endif()
set_target_properties(${SHARED_LIB_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

if (WIN32)
set_target_properties(${SHARED_LIB_NAME} PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
)
endif()
set_target_properties(${SHARED_LIB_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin # for dll
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib # for lib
)
target_include_directories(${SHARED_LIB_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)
)

#set the MD_DynamicRelease flag for MSVC since we are compiling with /MD for py wrap
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")


#--------------------------------------------------------------------------
Expand All @@ -73,29 +88,31 @@ add_subdirectory(deps/eigen)
target_link_libraries(${SHARED_LIB_NAME} PUBLIC Eigen3::Eigen)

# Open3D (pre-built binaries) ---------------------------------------------
download_submodule_project(open3d)
set(Open3D_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/open3d/win/0_18/CMake)
find_package(Open3D 0.18.0 REQUIRED)
# download_submodule_project(open3d)
# set(Open3D_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/open3d/win/0_18/CMake)
# find_package(Open3D 0.18.0 REQUIRED)

# # print the version debug or release of the package
# message(STATUS "Open3D version: ${Open3D_VERSION}"
# "Open3D include dir: ${Open3D_INCLUDE_DIRS}"
# "Open3D library dir: ${Open3D_LIBRARIES}")

# print the version debug or release of the package
message(STATUS "Open3D version: ${Open3D_VERSION}"
"Open3D include dir: ${Open3D_INCLUDE_DIRS}"
"Open3D library dir: ${Open3D_LIBRARIES}")

find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/cmake)
# link the release version of the open3d library
target_link_libraries(${SHARED_LIB_NAME} PUBLIC Open3D::Open3D)

# On Windows if BUILD_SHARED_LIBS is enabled, copy .dll files to the executable directory
if(WIN32)
get_target_property(open3d_type Open3D::Open3D TYPE)
if(open3d_type STREQUAL "SHARED_LIBRARY")
message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
add_custom_command(TARGET ${SHARED_LIB_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:Open3D::Open3D>
$<TARGET_FILE_DIR:${SHARED_LIB_NAME}>)
endif()
endif()
# if(WIN32)
# get_target_property(open3d_type Open3D::Open3D TYPE)
# if(open3d_type STREQUAL "SHARED_LIBRARY")
# message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
# add_custom_command(TARGET ${SHARED_LIB_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# $<TARGET_FILE:Open3D::Open3D>
# $<TARGET_FILE_DIR:${SHARED_LIB_NAME}>)
# endif()
# endif()

# Boost (header only) -----------------------------------------------------
download_submodule_project(boost)
Expand All @@ -116,28 +133,30 @@ target_link_libraries(${SHARED_LIB_NAME} PUBLIC loguru::loguru)
#--------------------------------------------------------------------------
# executable for prototyping
#--------------------------------------------------------------------------
set(APP_NAME_EXE diffCheckApp)
# set(APP_NAME_EXE diffCheckApp)

add_executable(${APP_NAME_EXE} src/diffCheckApp.cc)
# add_executable(${APP_NAME_EXE} src/diffCheckApp.cc)

set_target_properties(${APP_NAME_EXE} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# set_target_properties(${APP_NAME_EXE} PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# )

target_link_libraries(${APP_NAME_EXE} ${SHARED_LIB_NAME})
# target_link_libraries(${APP_NAME_EXE} ${SHARED_LIB_NAME})

target_include_directories(${APP_NAME_EXE}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)
# target_include_directories(${APP_NAME_EXE}
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
# )

#--------------------------------------------------------------------------
# pybind11
#--------------------------------------------------------------------------
add_definitions(-D_GLIBCXX_DEBUG)

if (BUILD_PYTHON_MODULE)
set(PYBINDMODULE_NAME diffcheck_bindings)
set(PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck)
set(TARGET_DLL_PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck/dlls)
set(SPHINX_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doc)
# set(PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck)
# set(TARGET_DLL_PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck/dlls)
# set(SPHINX_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doc)

download_submodule_project(pybind11)
add_subdirectory(deps/pybind11)
Expand All @@ -151,27 +170,40 @@ if (BUILD_PYTHON_MODULE)

set(PYBIND11_PYTHON_VERSION 3.9.10)

pybind11_add_module(${PYBINDMODULE_NAME} src/diffCheckBindings.cc)
pybind11_add_module(${PYBINDMODULE_NAME}
MODULE
src/diffCheckBindings.cc
)

target_link_libraries(${PYBINDMODULE_NAME} PUBLIC ${SHARED_LIB_NAME})
target_include_directories(${PYBINDMODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PYBINDMODULE_NAME} PUBLIC ${SHARED_LIB_NAME})

# copy the pyd file to the pypi directory
add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${PYBINDMODULE_NAME}>
${PYPI_DIR}
)
copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
# copy the pyd/dlls for the sphinx documentation
add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:${PYBINDMODULE_NAME}>
${SPHINX_DOC_DIR}
)
copy_dlls(${SPHINX_DOC_DIR} ${PYBINDMODULE_NAME})
# add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# $<TARGET_FILE:${PYBINDMODULE_NAME}>
# ${PYPI_DIR}
# )
# copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
# # copy the pyd/dlls for the sphinx documentation
# add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# $<TARGET_FILE:${PYBINDMODULE_NAME}>
# ${SPHINX_DOC_DIR}
# )
# copy_dlls(${SPHINX_DOC_DIR} ${PYBINDMODULE_NAME})
endif()

# install the diffCheck shared library to the system path
install(TARGETS ${SHARED_LIB_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)




#--------------------------------------------------------------------------
# Tests
#--------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions portability_experiment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Experiment on Mac
1. Install diffCheck library (replace <user_name> with your user name)
```
/Users/<user_name>/.rhinocode/py39-rh8/python3.9 -m pip install diffcheck-1.3.0-py3-none-any.whl --force-reinstal
```

2. Open the `subtractive_gh_v1_mac_portability.gh` file, the expected result would be:
![](./expected_result.png)

There should be no error before the Segmentation.
Binary file not shown.
Binary file added portability_experiment/expected_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions portability_experiment/subtractive_gh_v1_mac_portability.gh
Git LFS file not shown
26 changes: 24 additions & 2 deletions src/diffCheck/geometry/DFPointCloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,33 @@ namespace diffCheck::geometry

std::vector<Eigen::Vector3d> DFPointCloud::GetAxixAlignedBoundingBox()
{
if (this->Points.empty()) {
return {Eigen::Vector3d::Zero(), Eigen::Vector3d::Zero()};
}

Eigen::Vector3d minBound, maxBound;

#ifdef __APPLE__
// Compute min and max bounds directly from points
minBound = this->Points.front();
maxBound = this->Points.front();

for (const auto& point : this->Points) {
minBound = minBound.cwiseMin(point);
maxBound = maxBound.cwiseMax(point);
}
#else
auto O3DPointCloud = this->Cvt2O3DPointCloud();
auto boundingBox = O3DPointCloud->GetAxisAlignedBoundingBox();
std::vector<Eigen::Vector3d> extremePoints;
extremePoints.push_back(boundingBox.GetMinBound());

boundingBox.GetMinBound());
extremePoints.push_back(boundingBox.GetMaxBound());

#endif
std::vector<Eigen::Vector3d> extremePoints;
extremePoints.push_back(minBound);
extremePoints.push_back(maxBound);

return extremePoints;
}

Expand Down
30 changes: 15 additions & 15 deletions src/diffCheck/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace diffCheck
{
void Log::Init()
{
int argc = 1;
char* argv[] = { "loguru", nullptr };
loguru::init(argc, argv);
loguru::add_file("diffCheckEvery.log", loguru::Truncate, loguru::Verbosity_MAX);
loguru::add_file("diffCheckErrors.log", loguru::Truncate, loguru::Verbosity_ERROR);
// void Log::Init()
// {
// int argc = 1;
// char* argv[] = { "loguru", nullptr };
// loguru::init(argc, argv);
// loguru::add_file("diffCheckEvery.log", loguru::Truncate, loguru::Verbosity_MAX);
// loguru::add_file("diffCheckErrors.log", loguru::Truncate, loguru::Verbosity_ERROR);

loguru::g_stderr_verbosity = 1;
loguru::g_colorlogtostderr = true;
loguru::g_preamble = false;
}
// loguru::g_stderr_verbosity = 1;
// loguru::g_colorlogtostderr = true;
// loguru::g_preamble = false;
// }

void Log::Shutdown()
{
loguru::shutdown();
}
// void Log::Shutdown()
// {
// loguru::shutdown();
// }
}
21 changes: 19 additions & 2 deletions src/diffCheck/log.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@ namespace diffCheck
~Log() { Shutdown(); }

private:
void Init();
void Shutdown();
// void Init();
// void Shutdown();
void Init()
{
// int argc = 1;
// char* argv[] = { "loguru", nullptr };
// loguru::init(argc, argv);
// loguru::add_file("diffCheckEvery.log", loguru::Truncate, loguru::Verbosity_MAX);
// loguru::add_file("diffCheckErrors.log", loguru::Truncate, loguru::Verbosity_ERROR);

// loguru::g_stderr_verbosity = 1;
// loguru::g_colorlogtostderr = true;
// loguru::g_preamble = false;
}

void Shutdown()
{
// loguru::shutdown();
}
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/diffCheck/segmentation/DFSegmentation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace diffCheck::segmentation
* @param associationThreshold the threshold to consider the points of a segment and a mesh face as associable. It is the ratio between the surface of the closest mesh triangle and the sum of the areas of the three triangles that form the rest of the pyramid described by the mesh triangle and the point we want to associate or not. The lower the number, the more strict the association will be and some poinnts on the mesh face might be wrongfully excluded.
* @return std::shared_ptr<geometry::DFPointCloud> The unified segments
*/
static std::vector<std::shared_ptr<geometry::DFPointCloud>> DFSegmentation::AssociateClustersToMeshes(
static std::vector<std::shared_ptr<geometry::DFPointCloud>> AssociateClustersToMeshes(
bool isCylinder,
std::vector<std::shared_ptr<geometry::DFMesh>> referenceMesh,
std::vector<std::shared_ptr<geometry::DFPointCloud>> &clusters,
Expand All @@ -49,7 +49,7 @@ namespace diffCheck::segmentation
* * @param angleThreshold the threshold to consider the a cluster as potential candidate for association. the value passed is the minimum sine of the angles. A value of 0 requires perfect alignment (angle = 0), while a value of 0.1 allows an angle of 5.7 degrees.
* @param associationThreshold the threshold to consider the points of a segment and a mesh face as associable. It is the ratio between the surface of the closest mesh triangle and the sum of the areas of the three triangles that form the rest of the pyramid described by the mesh triangle and the point we want to associate or not. The lower the number, the more strict the association will be and some poinnts on the mesh face might be wrongfully excluded.
*/
static void DFSegmentation::CleanUnassociatedClusters(
static void CleanUnassociatedClusters(
bool isCylinder,
std::vector<std::shared_ptr<geometry::DFPointCloud>> &unassociatedClusters,
std::vector<std::shared_ptr<geometry::DFPointCloud>> &existingPointCloudSegments,
Expand Down
1 change: 1 addition & 0 deletions src/diffCheckApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

int main()
{

std::cout << "Hello, World!" << std::endl;
return 0;
}
19 changes: 19 additions & 0 deletions src/gh/components/DF_pose_comparator/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! python3



from ghpythonlib.componentbase import executingcomponent as component


class DFPoseComparator(component):
def RunScript(self,
i_scan,
i_assembly):
# dump the xml
o_xml = None
xml: str = i_assembly.to_xml()
if i_dump:
i_assembly.dump_xml(xml, i_export_dir)
o_xml = xml

return o_xml
Binary file added src/gh/components/DF_pose_comparator/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading