From 1cbfbbbe8ea5365b31d45d3ae435519a25e4d972 Mon Sep 17 00:00:00 2001 From: Luciano Arnaldo Romero Calla Date: Tue, 24 Oct 2023 18:24:56 +0200 Subject: [PATCH 1/5] fix clang warnings: AppleClang 15 --- src/gproshan/app_viewer.cpp | 4 ++-- src/gproshan/mdict/image_denoising.cpp | 6 +++++- src/gproshan/mdict/msparse_coding.cpp | 4 ++-- src/gproshan/scenes/scanner.cpp | 6 +++++- src/gproshan/viewer/frame.cpp | 30 +++++++++++++------------- src/gproshan/viewer/viewer.cpp | 6 +++++- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/gproshan/app_viewer.cpp b/src/gproshan/app_viewer.cpp index a68b0be8..8fc831bd 100644 --- a/src/gproshan/app_viewer.cpp +++ b/src/gproshan/app_viewer.cpp @@ -693,11 +693,11 @@ bool app_viewer::process_mdict_patch(viewer * p_view) } avg_nvp /= mesh.selected.size(); - gproshan_debug_var(avg_nvp); + gproshan_log_var(avg_nvp); delete [] toplevel; TOC(view->time) - gproshan_debug_var(view->time); + gproshan_log_var(view->time); return false; } diff --git a/src/gproshan/mdict/image_denoising.cpp b/src/gproshan/mdict/image_denoising.cpp index 0db3be1b..3df9215f 100644 --- a/src/gproshan/mdict/image_denoising.cpp +++ b/src/gproshan/mdict/image_denoising.cpp @@ -1,9 +1,13 @@ #include +#ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" -#include + #include #pragma GCC diagnostic pop +#else + #include +#endif // __clang__ using namespace cimg_library; diff --git a/src/gproshan/mdict/msparse_coding.cpp b/src/gproshan/mdict/msparse_coding.cpp index 1dbb7ccf..8ce2cb25 100644 --- a/src/gproshan/mdict/msparse_coding.cpp +++ b/src/gproshan/mdict/msparse_coding.cpp @@ -254,8 +254,8 @@ void msparse_coding::load_sampling() S.save(tmp_file_path(key_name + ".rsampl")); gproshan_debug_var(m_params.sum_thres); - gproshan_debug_var(count); - gproshan_debug_var(count_cov); + gproshan_log_var(count); + gproshan_log_var(count_cov); gproshan_debug_var(seeds.size()); gproshan_debug_var(m_params.n_patches); diff --git a/src/gproshan/scenes/scanner.cpp b/src/gproshan/scenes/scanner.cpp index 2a9f855b..38426b44 100644 --- a/src/gproshan/scenes/scanner.cpp +++ b/src/gproshan/scenes/scanner.cpp @@ -3,10 +3,14 @@ #include #include +#ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" -#include + #include #pragma GCC diagnostic pop +#else + #include +#endif // __clang__ using namespace cimg_library; diff --git a/src/gproshan/viewer/frame.cpp b/src/gproshan/viewer/frame.cpp index dc6b75cd..f4eb1a7a 100644 --- a/src/gproshan/viewer/frame.cpp +++ b/src/gproshan/viewer/frame.cpp @@ -66,33 +66,33 @@ frame::operator const GLuint & () const vec4 * frame::map_pbo(bool cuda) { -#ifdef GPROSHAN_CUDA - if(cuda) + if(!cuda) { - vec4 * img = nullptr; + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + return (vec4 *) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); + } + + vec4 * img = nullptr; + #ifdef GPROSHAN_CUDA size_t num_bytes = 0; cudaGraphicsMapResources(1, &pbo_cuda, 0); cudaGraphicsResourceGetMappedPointer((void **) &img, &num_bytes, pbo_cuda); - return img; - } -#endif // GPROSHAN_CUDA - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - return (vec4 *) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); + #endif // GPROSHAN_CUDA + return img; } void frame::unmap_pbo(bool cuda) { -#ifdef GPROSHAN_CUDA - if(cuda) + if(!cuda) { - cudaGraphicsUnmapResources(1, &pbo_cuda, 0); + glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); return; } -#endif // GPROSHAN_CUDA - glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + #ifdef GPROSHAN_CUDA + cudaGraphicsUnmapResources(1, &pbo_cuda, 0); + #endif // GPROSHAN_CUDA } bool frame::resize(const size_t & w, const size_t & h) diff --git a/src/gproshan/viewer/viewer.cpp b/src/gproshan/viewer/viewer.cpp index b66dc54d..04a27523 100644 --- a/src/gproshan/viewer/viewer.cpp +++ b/src/gproshan/viewer/viewer.cpp @@ -23,10 +23,14 @@ #endif // GPROSHAN_OPTIX +#ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" -#include + #include #pragma GCC diagnostic pop +#else + #include +#endif // __clang__ using namespace cimg_library; From 9250e10f994d384cce4a5159911468147f34c773 Mon Sep 17 00:00:00 2001 From: Luciano Arnaldo Romero Calla Date: Wed, 25 Oct 2023 17:19:13 +0200 Subject: [PATCH 2/5] mesh: move load mesh to che static method --- include/gproshan/app_viewer.h | 2 +- include/gproshan/mesh/che.h | 1 + src/gproshan/app_viewer.cpp | 29 +------------------------- src/gproshan/mesh/che.cpp | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/include/gproshan/app_viewer.h b/include/gproshan/app_viewer.h index 575c7c88..8d09f6cf 100644 --- a/include/gproshan/app_viewer.h +++ b/include/gproshan/app_viewer.h @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include #include #include diff --git a/include/gproshan/mesh/che.h b/include/gproshan/mesh/che.h index e2b6d123..5d714c4e 100644 --- a/include/gproshan/mesh/che.h +++ b/include/gproshan/mesh/che.h @@ -168,6 +168,7 @@ class che public: static std::vector trig_convex_polygon(const index_t * P, const size_t & n); + static che * load_mesh(const std::string & file_path); friend struct CHE; }; diff --git a/src/gproshan/app_viewer.cpp b/src/gproshan/app_viewer.cpp index 8fc831bd..d2d1c7e3 100644 --- a/src/gproshan/app_viewer.cpp +++ b/src/gproshan/app_viewer.cpp @@ -20,33 +20,6 @@ app_viewer::~app_viewer() delete *m; } -che * app_viewer::load_mesh(const std::string & file_path) -{ - size_t pos = file_path.rfind('.'); - assert(pos != std::string::npos); - - std::string extension = file_path.substr(pos + 1); - - if(extension == "obj") - { - scene * sc = new scene(file_path); - if(!sc->is_scene()) - { - delete sc; - return new che_obj(file_path); - } - return sc; - } - if(extension == "off") return new che_off(file_path); - if(extension == "ply") return new che_ply(file_path); - if(extension == "ptx") return new che_ptx(file_path); - if(extension == "xyz") return new che_xyz(file_path); - if(extension == "pts") return new che_pts(file_path); - if(extension == "pcd") return new che_pcd(file_path); - - return new che_img(file_path); -} - int app_viewer::main(int nargs, const char ** args) { if(nargs < 2) @@ -57,7 +30,7 @@ int app_viewer::main(int nargs, const char ** args) TIC(time) for(int i = 1; i < nargs; ++i) - add_mesh(load_mesh(args[i])); + add_mesh(che::load_mesh(args[i])); TOC(time) update_status_message("meshes loaded in %.3fs", time); diff --git a/src/gproshan/mesh/che.cpp b/src/gproshan/mesh/che.cpp index 474c33e6..9e004db6 100644 --- a/src/gproshan/mesh/che.cpp +++ b/src/gproshan/mesh/che.cpp @@ -1,5 +1,16 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + #include #include #include @@ -1117,6 +1128,33 @@ std::vector che::trig_convex_polygon(const index_t * P, const size_t & return trigs; } +che * che::load_mesh(const std::string & file_path) +{ + size_t pos = file_path.rfind('.'); + assert(pos != std::string::npos); + + std::string extension = file_path.substr(pos + 1); + + if(extension == "obj") + { + scene * sc = new scene(file_path); + if(!sc->is_scene()) + { + delete sc; + return new che_obj(file_path); + } + return sc; + } + if(extension == "off") return new che_off(file_path); + if(extension == "ply") return new che_ply(file_path); + if(extension == "ptx") return new che_ptx(file_path); + if(extension == "xyz") return new che_xyz(file_path); + if(extension == "pts") return new che_pts(file_path); + if(extension == "pcd") return new che_pcd(file_path); + + return new che_img(file_path); +} + // iterator classes methods From 3e63deb7d41f1a5b42dee2a1baa59343aed9b432 Mon Sep 17 00:00:00 2001 From: Luciano Arnaldo Romero Calla Date: Thu, 26 Oct 2023 16:19:00 +0200 Subject: [PATCH 3/5] util: adding partitions iterator --- include/gproshan/util.h | 37 +++++++++++++++++++++++++++++++++++++ src/gproshan/util.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/include/gproshan/util.h b/include/gproshan/util.h index 446f8a2b..f649d054 100644 --- a/include/gproshan/util.h +++ b/include/gproshan/util.h @@ -3,11 +3,48 @@ #include +#include +#include + // geometry processing and shape analysis framework namespace gproshan { +class partitions +{ + struct part; + + std::vector splits; + index_t * sorted = nullptr; + + public: + part operator () (const index_t & i) const; +}; + +struct partitions::part +{ + struct iterator; + + index_t _begin = 0; + index_t _end = 0; + const index_t * sorted = nullptr; + + iterator begin() const; + iterator end() const; +}; + +struct partitions::part::iterator +{ + index_t i = 0; + const index_t * sorted = nullptr; + + iterator & operator ++ (); + bool operator != (const iterator & it) const; + const index_t & operator * (); +}; + + void copy_real_t_array(float * destination, const float * source, const size_t & n_elem); void copy_real_t_array(float * destination, const double * source, const size_t & n_elem); diff --git a/src/gproshan/util.cpp b/src/gproshan/util.cpp index 18d30b16..aae2cbab 100644 --- a/src/gproshan/util.cpp +++ b/src/gproshan/util.cpp @@ -7,6 +7,39 @@ namespace gproshan { +partitions::part partitions::operator () (const index_t & i) const +{ + assert(i > 0 && i < splits.size()); + return {splits[i - 1], splits[i], sorted}; +} + +partitions::part::iterator partitions::part::begin() const +{ + return {_begin, sorted}; +} + +partitions::part::iterator partitions::part::end() const +{ + return {_end, sorted}; +} + +partitions::part::iterator & partitions::part::iterator::operator ++ () +{ + ++i; + return *this; +} + +bool partitions::part::iterator::operator != (const iterator & it) const +{ + return i != it.i; +} + +const index_t & partitions::part::iterator::operator * () +{ + return sorted ? sorted[i] : i; +} + + void copy_real_t_array(float * destination, const float * source, const size_t & n_elem) { memcpy(destination, source, n_elem * sizeof(float)); From 3f2d38119663b512b94e9390281ee86b589c7fab Mon Sep 17 00:00:00 2001 From: Luciano Arnaldo Romero Calla Date: Thu, 26 Oct 2023 17:19:46 +0200 Subject: [PATCH 4/5] util: partitions iterator cuda --- include/gproshan/geometry/vec.h | 6 ----- include/gproshan/include.h | 6 +++++ include/gproshan/util.h | 46 +++++++++++++++++++++++++-------- src/gproshan/util.cpp | 26 ------------------- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/include/gproshan/geometry/vec.h b/include/gproshan/geometry/vec.h index 1e8d227f..9083c3ae 100644 --- a/include/gproshan/geometry/vec.h +++ b/include/gproshan/geometry/vec.h @@ -8,12 +8,6 @@ #include #include -#ifdef __CUDACC__ - #define __host_device__ __host__ __device__ -#else - #define __host_device__ -#endif // __CUDACC__ - // geometry processing and shape analysis framework namespace gproshan { diff --git a/include/gproshan/include.h b/include/gproshan/include.h index 7c0837f5..3b5cfabc 100644 --- a/include/gproshan/include.h +++ b/include/gproshan/include.h @@ -12,6 +12,12 @@ #define NIL (0u - 1) +#ifdef __CUDACC__ + #define __host_device__ __host__ __device__ +#else + #define __host_device__ +#endif // __CUDACC__ + // geometry processing and shape analysis framework namespace gproshan { diff --git a/include/gproshan/util.h b/include/gproshan/util.h index f649d054..9b088a50 100644 --- a/include/gproshan/util.h +++ b/include/gproshan/util.h @@ -24,24 +24,48 @@ class partitions struct partitions::part { - struct iterator; + struct iterator + { + index_t i = 0; + const index_t * sorted = nullptr; + + __host_device__ + iterator & operator ++ () + { + ++i; + return *this; + } + + __host_device__ + bool operator != (const iterator & it) const + { + return i != it.i; + } + + __host_device__ + const index_t & operator * () + { + return sorted ? sorted[i] : i; + } + }; + index_t _begin = 0; index_t _end = 0; const index_t * sorted = nullptr; - iterator begin() const; - iterator end() const; -}; -struct partitions::part::iterator -{ - index_t i = 0; - const index_t * sorted = nullptr; + __host_device__ + iterator begin() const + { + return {_begin, sorted}; + } - iterator & operator ++ (); - bool operator != (const iterator & it) const; - const index_t & operator * (); + __host_device__ + iterator end() const + { + return {_end, sorted}; + } }; diff --git a/src/gproshan/util.cpp b/src/gproshan/util.cpp index aae2cbab..b81b31a7 100644 --- a/src/gproshan/util.cpp +++ b/src/gproshan/util.cpp @@ -13,32 +13,6 @@ partitions::part partitions::operator () (const index_t & i) const return {splits[i - 1], splits[i], sorted}; } -partitions::part::iterator partitions::part::begin() const -{ - return {_begin, sorted}; -} - -partitions::part::iterator partitions::part::end() const -{ - return {_end, sorted}; -} - -partitions::part::iterator & partitions::part::iterator::operator ++ () -{ - ++i; - return *this; -} - -bool partitions::part::iterator::operator != (const iterator & it) const -{ - return i != it.i; -} - -const index_t & partitions::part::iterator::operator * () -{ - return sorted ? sorted[i] : i; -} - void copy_real_t_array(float * destination, const float * source, const size_t & n_elem) { From 176703912d8e37d79d1311310aff4e1bd8404a16 Mon Sep 17 00:00:00 2001 From: Luciano Arnaldo Romero Calla Date: Wed, 1 Nov 2023 15:29:25 +0100 Subject: [PATCH 5/5] update cmake and install dependencies --- CMakeLists.txt | 2 +- gproshanConfig.cmake.in | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ba2b09b..7bc0f6fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.24) +cmake_minimum_required(VERSION 3.27) project(gproshan VERSION 3.14) diff --git a/gproshanConfig.cmake.in b/gproshanConfig.cmake.in index 17dbafb5..ae2a9f6b 100644 --- a/gproshanConfig.cmake.in +++ b/gproshanConfig.cmake.in @@ -2,24 +2,19 @@ include(CMakeFindDependencyMacro) -find_dependency(CUDAToolkit 12) -if(CUDAToolkit_FOUND) - add_definitions(-DGPROSHAN_CUDA) -endif(CUDAToolkit_FOUND) +find_package(CUDAToolkit 12) -find_dependency(embree 4 REQUIRED) -find_dependency(Threads REQUIRED) -find_dependency(OpenMP REQUIRED) -find_dependency(OpenGL REQUIRED) -find_dependency(GLEW REQUIRED) -find_dependency(glfw3 REQUIRED) -find_dependency(X11 REQUIRED) -find_dependency(Armadillo REQUIRED) -find_dependency(Eigen3 REQUIRED) -find_dependency(CGAL REQUIRED) -find_dependency(SuiteSparse REQUIRED) -find_dependency(flann REQUIRED) -find_dependency(Boost COMPONENTS thread system) +find_dependency(embree 4) +find_dependency(OpenMP) +find_dependency(OpenGL) +find_dependency(GLEW) +find_dependency(glfw3) +find_dependency(X11) +find_dependency(Armadillo) +find_dependency(Eigen3) +find_dependency(CGAL) +find_dependency(SuiteSparse) +find_dependency(flann) include(${CMAKE_CURRENT_LIST_DIR}/gproshanTargets.cmake)