diff --git a/CMakeLists.txt b/CMakeLists.txt index 08735c288..e250eb98b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ option(BUILD_TOOLS "Build tools including lvr2_reconstruct" ON) option(BUILD_TOOLS_EXPERIMENTAL "Build experimental tools" OFF) option(WITH_DRACO "Build libraries with draco enabled" OFF) +## Compile as C++17 +add_compile_options(-std=c++17) +set(CMAKE_CXX_STANDARD 17) # DEFAULT RELEASE if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt) @@ -613,7 +616,7 @@ add_subdirectory(src/liblvr2) if(BUILD_TOOLS) add_subdirectory(src/tools/lvr2_reconstruct) add_subdirectory(src/tools/lvr2_mesh_reducer) - add_subdirectory(src/tools/lvr2_hdf5_mesh_builder) + add_subdirectory(src/tools/lvr2_hdf5_mesh_tool) endif(BUILD_TOOLS) if(BUILD_TOOLS_EXPERIMENTAL) diff --git a/include/lvr2/geometry/BaseVector.tcc b/include/lvr2/geometry/BaseVector.tcc index 18151ae32..5e53cd156 100644 --- a/include/lvr2/geometry/BaseVector.tcc +++ b/include/lvr2/geometry/BaseVector.tcc @@ -35,6 +35,7 @@ #include #include "Normal.hpp" #include "lvr2/util/Panic.hpp" +#include "lvr2/util/TypeTraits.hpp" namespace lvr2 { @@ -258,7 +259,7 @@ BaseVector BaseVector::average(const CollectionT& vecs) for (auto v: vecs) { static_assert( - std::is_same>::value, + arg_has_type >(v), "Collection has to contain Vectors" ); acc += v; @@ -276,7 +277,7 @@ BaseVector BaseVector::centroid(const CollectionT& points) for (auto p: points) { static_assert( - std::is_same>::value, + arg_has_type >(p), "Type mismatch in centroid calculation." ); acc += p; diff --git a/include/lvr2/geometry/Normal.tcc b/include/lvr2/geometry/Normal.tcc index f91c8df47..3e8696c66 100644 --- a/include/lvr2/geometry/Normal.tcc +++ b/include/lvr2/geometry/Normal.tcc @@ -34,6 +34,7 @@ #include "lvr2/util/Panic.hpp" +#include "lvr2/util/TypeTraits.hpp" namespace lvr2 @@ -66,7 +67,7 @@ Normal& Normal::average(const CollectionT& normals) for (auto n: normals) { static_assert( - std::is_same>::value, + arg_has_type >(n), "Collection has to contain Vectors" ); acc += n.asVector(); diff --git a/include/lvr2/util/TypeTraits.hpp b/include/lvr2/util/TypeTraits.hpp new file mode 100644 index 000000000..43d1f8c5c --- /dev/null +++ b/include/lvr2/util/TypeTraits.hpp @@ -0,0 +1,48 @@ +#ifndef LVR2_UTIL_TYPE_TRAITS_HPP +#define LVR2_UTIL_TYPE_TRAITS_HPP + +#include + +namespace lvr2 { + +/** + * @brief This type trait was necessary to + * + * Usage: + * + * @code + * auto v = vector[0]; + * + * static_assert( + * arg_has_type >(v), + * "Error: Type mismatch" + * ); + * + * @endcode + * + * Why? + * The following code snipped was compiling in .cpp files but not in .cu + * - Ubuntu 20, GCC 9.4.0, NVCC 12.4 + * + * @code + * auto v = vector[0]; + * + * static_assert( + * std::is_same >::value, + * "Error: Type mismatch" + * ); + * @endcode + * + * Since cuda code sometimes includes BaseVector.hpp all cuda libraries wont compile. + * Problem was that `decltype` in .cu file is not working as expected + * +*/ +template +static constexpr bool arg_has_type(const AutoType& t1) +{ + return std::is_same::value; +} + +} // namespace lvr2 + +#endif // LVR2_UTIL_TYPE_TRAITS_HPP \ No newline at end of file diff --git a/src/liblvr2/CMakeLists.txt b/src/liblvr2/CMakeLists.txt index 9f667f4d8..92d32f8bb 100644 --- a/src/liblvr2/CMakeLists.txt +++ b/src/liblvr2/CMakeLists.txt @@ -191,7 +191,8 @@ endif( NOT MSVC) ##################################################################################### if(CUDA_FOUND) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(CUDA_SEPARABLE_COMPILATION ON) # List of CUDA kernel code sources set(LVR2_CUDA_SRC @@ -214,6 +215,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") endif(VTK_FOUND) message(STATUS "Building static LVR CUDA library") + + cuda_add_library(lvr2cuda_static STATIC ${LVR2_CUDA_SRC}) target_link_libraries(lvr2cuda_static lvr2_static) @@ -225,6 +228,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") cuda_add_library(lvr2cuda SHARED ${LVR2_CUDA_CPP_SRC} ${LVR2_CUDA_SRC}) target_link_libraries(lvr2cuda lvr2) + add_dependencies(lvr2cuda lvr2) install( TARGETS lvr2cuda_static lvr2cuda @@ -233,5 +237,5 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) -endif() +endif(CUDA_FOUND) diff --git a/src/tools/lvr2_hdf5_mesh_builder/CMakeLists.txt b/src/tools/lvr2_hdf5_mesh_tool/CMakeLists.txt similarity index 100% rename from src/tools/lvr2_hdf5_mesh_builder/CMakeLists.txt rename to src/tools/lvr2_hdf5_mesh_tool/CMakeLists.txt diff --git a/src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp b/src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp similarity index 100% rename from src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp rename to src/tools/lvr2_hdf5_mesh_tool/HDF5MeshTool.cpp diff --git a/src/tools/lvr2_hdf5_mesh_builder/Options.cpp b/src/tools/lvr2_hdf5_mesh_tool/Options.cpp similarity index 100% rename from src/tools/lvr2_hdf5_mesh_builder/Options.cpp rename to src/tools/lvr2_hdf5_mesh_tool/Options.cpp diff --git a/src/tools/lvr2_hdf5_mesh_builder/Options.hpp b/src/tools/lvr2_hdf5_mesh_tool/Options.hpp similarity index 100% rename from src/tools/lvr2_hdf5_mesh_builder/Options.hpp rename to src/tools/lvr2_hdf5_mesh_tool/Options.hpp