From e10db84ea6045c49b5a0032cb2929b2e57abd55d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Jun 2019 17:25:06 -0400 Subject: [PATCH 01/21] Modified AppVeyor build configuration settings --- .appveyor.yml | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 591ac67..a83263d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,17 +1,39 @@ version: 1.0.{build} os: Visual Studio 2017 -test: off -clone_folder: C:\projects\fish_deformation +platform: x64 +clone_folder: C:\projects\libigl +shallow_clone: true branches: only: - master + - dev +environment: + matrix: + - CONFIG: Debug + BOOST_ROOT: C:/Libraries/boost_1_65_1 + PYTHON: 37 + - CONFIG: Release + BOOST_ROOT: C:/Libraries/boost_1_65_1 + PYTHON: 37 install: - - git submodule update --init --recursive - cinstall: python +build: + parallel: true build_script: - - echo Running cmake... - - cd c:\projects\fish_deformation + - cd c:\projects\libigl + # Tutorials and tests + - set PATH=C:\Python%PYTHON%-x64;C:\Python%PYTHON%-x64\Scripts;%PATH% - mkdir build - cd build - - cmake -G "Visual Studio 15 2017 Win64" -T "host=x64" .. - - msbuild %MSBuildOptions% fish_deformation + - cmake -DCMAKE_BUILD_TYPE=%CONFIG% + -DLIBIGL_WITH_CGAL=ON + -DLIBIGL_WITH_COMISO=OFF + -G "Visual Studio 15 2017 Win64" + ../ + - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - set MSBuildOptions=/v:m /m /p:BuildInParallel=true /p:Configuration=%CONFIG% /logger:%MSBuildLogger% + - msbuild %MSBuildOptions% libigl.sln + +test_script: + - set CTEST_OUTPUT_ON_FAILURE=1 + - ctest -C %CONFIG% --verbose --output-on-failure -j 2 From c56303d29650ec234ca413beed2075c350b50444 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Jun 2019 17:55:30 -0400 Subject: [PATCH 02/21] Added installation of new software by AppVeyor --- .appveyor.yml | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index a83263d..cf505c8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,39 +1,32 @@ version: 1.0.{build} os: Visual Studio 2017 +test: off platform: x64 -clone_folder: C:\projects\libigl -shallow_clone: true +clone_folder: C:\projects\fish_deformation branches: only: - master - - dev -environment: - matrix: - - CONFIG: Debug - BOOST_ROOT: C:/Libraries/boost_1_65_1 - PYTHON: 37 - - CONFIG: Release - BOOST_ROOT: C:/Libraries/boost_1_65_1 - PYTHON: 37 + - michael install: + - git submodule update --init --recursive - cinstall: python build: parallel: true build_script: - - cd c:\projects\libigl - # Tutorials and tests + - echo Running cmake .. + - cd c:\tools\vcpkg + - .\vcpkg.exe --triplet x64-windows install mpir mpfr + - cd c:\projects\fish_deformation - set PATH=C:\Python%PYTHON%-x64;C:\Python%PYTHON%-x64\Scripts;%PATH% - mkdir build - cd build - - cmake -DCMAKE_BUILD_TYPE=%CONFIG% - -DLIBIGL_WITH_CGAL=ON - -DLIBIGL_WITH_COMISO=OFF - -G "Visual Studio 15 2017 Win64" - ../ + - cmake -G 'Visual Studio 15 2017 Win64' + -DCMAKE_PREFIX_PATH="C:/Qt/Qt5.10.1/5.10.1/msvc2017_64" + -DMPFR_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" + -DMPFR_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpfr.lib" + -DGMP_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" + -DGMP_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpir.lib" + -DBOOST_ROOT="C:/local/vcpkg/installed/x64-windows" ../ - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - set MSBuildOptions=/v:m /m /p:BuildInParallel=true /p:Configuration=%CONFIG% /logger:%MSBuildLogger% - - msbuild %MSBuildOptions% libigl.sln - -test_script: - - set CTEST_OUTPUT_ON_FAILURE=1 - - ctest -C %CONFIG% --verbose --output-on-failure -j 2 + - msbuild %MSBuildOptions% fish_deformation From 339892e99bd877470706beb0d7f239d9c57c0ce2 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Jun 2019 11:23:06 -0400 Subject: [PATCH 03/21] Modified AppVeyor build compilation settings --- .appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index cf505c8..3e1c53e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,13 +20,13 @@ build_script: - set PATH=C:\Python%PYTHON%-x64;C:\Python%PYTHON%-x64\Scripts;%PATH% - mkdir build - cd build - - cmake -G 'Visual Studio 15 2017 Win64' + - cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH="C:/Qt/Qt5.10.1/5.10.1/msvc2017_64" -DMPFR_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" -DMPFR_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpfr.lib" -DGMP_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" -DGMP_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpir.lib" - -DBOOST_ROOT="C:/local/vcpkg/installed/x64-windows" ../ + -DBOOST_ROOT="C:/Libraries/boost_1_65_1" ../ - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - set MSBuildOptions=/v:m /m /p:BuildInParallel=true /p:Configuration=%CONFIG% /logger:%MSBuildLogger% - - msbuild %MSBuildOptions% fish_deformation + - msbuild %MSBuildOptions% fish_deformation.sln From 56456065f818a0effc1395ac7931427bb7c379d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Jun 2019 15:03:07 -0400 Subject: [PATCH 04/21] Changed paths for AppVeyor build libraries --- .appveyor.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3e1c53e..59561b4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,6 @@ version: 1.0.{build} os: Visual Studio 2017 test: off -platform: x64 clone_folder: C:\projects\fish_deformation branches: only: @@ -21,12 +20,10 @@ build_script: - mkdir build - cd build - cmake -G "Visual Studio 15 2017 Win64" - -DCMAKE_PREFIX_PATH="C:/Qt/Qt5.10.1/5.10.1/msvc2017_64" + -DCMAKE_PREFIX_PATH="C:/Qt/5.10.1/msvc2017_64/lib/cmake" -DMPFR_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" -DMPFR_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpfr.lib" -DGMP_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" -DGMP_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpir.lib" -DBOOST_ROOT="C:/Libraries/boost_1_65_1" ../ - - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - - set MSBuildOptions=/v:m /m /p:BuildInParallel=true /p:Configuration=%CONFIG% /logger:%MSBuildLogger% - msbuild %MSBuildOptions% fish_deformation.sln From 548d8885a0bd5ce61379e10e9e8bf51fa61670bb Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Jun 2019 16:53:17 -0400 Subject: [PATCH 05/21] Added return value to header function --- src/utils/bounding_cage.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/bounding_cage.h b/src/utils/bounding_cage.h index 454854a..d530a0e 100644 --- a/src/utils/bounding_cage.h +++ b/src/utils/bounding_cage.h @@ -457,6 +457,7 @@ class BoundingCage { bool bump(double amount) { this->_origin += amount * this->normal(); + return true; } /// Rotate the coordinate frame counter-clockwise about the normal axis From e52ce30c0f396e28bd34ea5452062475cb63d0ca Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Jun 2019 17:26:17 -0400 Subject: [PATCH 06/21] Revised AppVeyor library compilation paths --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 59561b4..c48a045 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,9 +21,9 @@ build_script: - cd build - cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH="C:/Qt/5.10.1/msvc2017_64/lib/cmake" - -DMPFR_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" - -DMPFR_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpfr.lib" - -DGMP_INCLUDE_DIR:PATH="C:/local/vcpkg/installed/x64-windows/include" - -DGMP_LIBRARIES:FILEPATH="C:/local/vcpkg/installed/x64-windows/lib/mpir.lib" + -DMPFR_INCLUDE_DIR:PATH="C:/tools/vcpkg/installed/x64-windows/include" + -DMPFR_LIBRARIES:FILEPATH="C:/tools/vcpkg/installed/x64-windows/lib/mpfr.lib" + -DGMP_INCLUDE_DIR:PATH="C:/tools/vcpkg/installed/x64-windows/include" + -DGMP_LIBRARIES:FILEPATH="C:/tools/vcpkg/installed/x64-windows/lib/mpir.lib" -DBOOST_ROOT="C:/Libraries/boost_1_65_1" ../ - msbuild %MSBuildOptions% fish_deformation.sln From 0c5fd0e2ca87046744a5efd63f9e4281a4e7ec97 Mon Sep 17 00:00:00 2001 From: michizhou <33012425+michizhou@users.noreply.github.com> Date: Thu, 13 Jun 2019 10:22:07 -0400 Subject: [PATCH 07/21] Modified AppVeyor after build command script --- .appveyor.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index c48a045..b57e606 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,4 +26,16 @@ build_script: -DGMP_INCLUDE_DIR:PATH="C:/tools/vcpkg/installed/x64-windows/include" -DGMP_LIBRARIES:FILEPATH="C:/tools/vcpkg/installed/x64-windows/lib/mpir.lib" -DBOOST_ROOT="C:/Libraries/boost_1_65_1" ../ + - set MSBuildOptions=/v:m /p:Configuration=Release /p:Platform=x64 - msbuild %MSBuildOptions% fish_deformation.sln +after_build: + - cd .. + - mkdir unwind + - copy build\src\Release\unwind.exe unwind + - copy build\src\Release\mpir.dll unwind + - cd C:\Qt\latest\msvc2017_64\bin + - windeployqt C:\projects\fish_deformation\unwind\unwind.exe + - cd C:\projects\fish_deformation + - 7z a unwind.zip .\unwind\* +artifacts: + - path: unwind.zip From 7e186e067800b5fe3132a44aeb5f97943abd42be Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Jun 2019 15:05:01 -0400 Subject: [PATCH 08/21] Added Travis build instance --- .travis.yml | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f807c4b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,82 @@ +dist: trusty +sudo: true +language: cpp +cache: ccache +branches: + only: + - master + - michael +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-7 + - gcc-7 + - libblas-dev + - libboost-filesystem-dev + - libboost-system-dev + - libboost-thread-dev + - libglu1-mesa-dev + - liblapack-dev + - libmpfr-dev + - libpython3-dev + - python3-setuptools + - xorg-dev + homebrew: + packages: + - ccache +matrix: + include: + - os: linux + compiler: gcc # 4.8.4 by default on Trusty + env: + - MATRIX_EVAL="export CONFIG=Release PYTHON=python3" + - os: linux + compiler: gcc-7 + env: + - MATRIX_EVAL="export CC=gcc-7 CXX=g++-7 CONFIG=Release PYTHON=python3" + - os: linux # same config like above but with -DLIBIGL_USE_STATIC_LIBRARY=OFF to test static and header-only builds + compiler: gcc-7 + env: + - MATRIX_EVAL="export CC=gcc-7 CXX=g++-7 CONFIG=Release PYTHON=python3 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" + - os: linux + compiler: gcc-7 + env: + - MATRIX_EVAL="export CC=gcc-7 CXX=g++-7 CONFIG=Release PYTHON=python3 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'" + - os: osx + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1" + - os: osx # same config like above but with -DLIBIGL_USE_STATIC_LIBRARY=OFF to test static and header-only builds + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" + - os: osx + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'"" + +install: +- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi +- eval "${MATRIX_EVAL}" +- ccache --max-size=5.0G +- ccache -V && ccache --show-stats && ccache --zero-stats + +script: +# Tutorials and tests +- mkdir build +- pushd build +- cmake ${CMAKE_EXTRA} + -DCMAKE_BUILD_TYPE=$CONFIG + -DLIBIGL_CHECK_UNDEFINED=ON + -DLIBIGL_WITH_CGAL=ON + ../ +- make -j 2 +- ctest --verbose +- popd +- pushd python/tutorial +- ${PYTHON} 101_FileIO.py +- popd +- rm -rf build +- ccache --show-stats From d8799ed816741cb5ddc2019b2b38d8c3c8a6c466 Mon Sep 17 00:00:00 2001 From: michizhou <33012425+michizhou@users.noreply.github.com> Date: Fri, 14 Jun 2019 15:29:55 -0400 Subject: [PATCH 09/21] Modified Travis compiler environment settings --- .travis.yml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index f807c4b..0372cb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ addons: sources: - ubuntu-toolchain-r-test packages: + - cmake - g++-7 - gcc-7 - libblas-dev @@ -22,6 +23,7 @@ addons: - libmpfr-dev - libpython3-dev - python3-setuptools + - qt5-default - xorg-dev homebrew: packages: @@ -32,6 +34,7 @@ matrix: compiler: gcc # 4.8.4 by default on Trusty env: - MATRIX_EVAL="export CONFIG=Release PYTHON=python3" + - STDFLAGS="-std=c++11 -std=c++1y" - os: linux compiler: gcc-7 env: @@ -44,18 +47,6 @@ matrix: compiler: gcc-7 env: - MATRIX_EVAL="export CC=gcc-7 CXX=g++-7 CONFIG=Release PYTHON=python3 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'" - - os: osx - compiler: clang - env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1" - - os: osx # same config like above but with -DLIBIGL_USE_STATIC_LIBRARY=OFF to test static and header-only builds - compiler: clang - env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" - - os: osx - compiler: clang - env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'"" install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi @@ -72,11 +63,8 @@ script: -DLIBIGL_CHECK_UNDEFINED=ON -DLIBIGL_WITH_CGAL=ON ../ -- make -j 2 +- make -j8 - ctest --verbose - popd -- pushd python/tutorial -- ${PYTHON} 101_FileIO.py -- popd - rm -rf build - ccache --show-stats From 1b7fb812ea1d0077ca21232040622375e24ab4ef Mon Sep 17 00:00:00 2001 From: michizhou <33012425+michizhou@users.noreply.github.com> Date: Mon, 17 Jun 2019 11:15:13 -0400 Subject: [PATCH 10/21] Updated Travis build compiler configuration --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0372cb6..aa86097 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ addons: - ubuntu-toolchain-r-test packages: - cmake + - g++-6 + - gcc-6 - g++-7 - gcc-7 - libblas-dev @@ -31,10 +33,9 @@ addons: matrix: include: - os: linux - compiler: gcc # 4.8.4 by default on Trusty + compiler: gcc-6 env: - - MATRIX_EVAL="export CONFIG=Release PYTHON=python3" - - STDFLAGS="-std=c++11 -std=c++1y" + - MATRIX_EVAL="export CC=gcc-6 CXX=g++-6 CONFIG=Release PYTHON=python3" - os: linux compiler: gcc-7 env: From fc05c3a09ff061d9b17f6ee5c8dcf6047dbda2b2 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 17 Jul 2019 13:20:46 -0400 Subject: [PATCH 11/21] Modified source code for added compatibility on MacOS --- CMakeLists.txt | 6 +- src/main.cpp | 2 + src/ui/bounding_polygon_plugin.cpp | 13 ++- src/ui/bounding_polygon_plugin.h | 1 + src/ui/bounding_widget_2d.cpp | 12 +++ src/ui/endpoint_selection_plugin.cpp | 4 + src/ui/selection_plugin.cpp | 26 ++++++ src/ui/selection_plugin.h | 5 ++ src/utils/gl/point_line_rendering.cpp | 16 ++++ src/utils/gl/selection_renderer.cpp | 124 +++++++++++++++++--------- src/utils/gl/selection_renderer.h | 11 ++- src/utils/gl/volume_exporter.cpp | 12 +++ src/utils/gl/volume_renderer.cpp | 16 ++++ 13 files changed, 201 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2488f1..7a92a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(fish_deformation) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/voroffset/cmake) - +set(CMAKE_PREFIX_PATH /usr/local/opt/qt/lib/cmake) @@ -110,8 +110,8 @@ file(GLOB CT_SRCS external/Segmentangling/ContourTree/*.cpp) set(CT_INCLUDE_DIRS external/Segmentangling/ContourTree) list(REMOVE_ITEM CT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/external/Segmentangling/ContourTree/main.cpp") add_library(contourtree STATIC ${CT_SRCS}) -target_compile_options(contourtree PRIVATE "-fopenmp") -target_link_libraries(contourtree Qt5::Core Qt5::Widgets -fopenmp spdlog) +# target_compile_options(contourtree PRIVATE "-fopenmp") +target_link_libraries(contourtree Qt5::Core Qt5::Widgets spdlog) target_include_directories(contourtree PUBLIC ${CT_INCLUDE_DIRS}) target_compile_definitions(contourtree PUBLIC CONTOUR_TREE_USE_SPDLOG) diff --git a/src/main.cpp b/src/main.cpp index 62d0a54..54a5201 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,8 +56,10 @@ bool init(igl::opengl::glfw::Viewer& viewer) { ct_logger->set_level(CONTOURTREE_LOGGER_LEVEL); contourtree::Logger::setLogger(ct_logger); +#ifdef WIN32 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(log_opengl_debug, NULL); +#endif return false; } diff --git a/src/ui/bounding_polygon_plugin.cpp b/src/ui/bounding_polygon_plugin.cpp index 17c1cd9..d47653c 100644 --- a/src/ui/bounding_polygon_plugin.cpp +++ b/src/ui/bounding_polygon_plugin.cpp @@ -345,14 +345,25 @@ bool Bounding_Polygon_Menu::post_draw() { int window_width, window_height; glfwGetWindowSize(viewer->window, &window_width, &window_height); +#ifdef __APPLE__ + glViewport(-scaling_factor*window_width*view_hsplit, -(1.0+view_vsplit)*window_height, + scaling_factor*window_width, (scaling_factor*scaling_factor)*(1.0-view_vsplit)*window_height); + widget_2d.position = glm::vec2(0.f, view_vsplit*window_height/(scaling_factor*scaling_factor)); + widget_2d.size = glm::vec2(window_width*view_hsplit, (1.0-view_vsplit)*window_height/scaling_factor); +#else glViewport(0, 0, window_width, window_height); - widget_2d.position = glm::vec2(0.f, view_vsplit*window_height); widget_2d.size = glm::vec2(window_width*view_hsplit, (1.0-view_vsplit)*window_height); +#endif ret = widget_2d.post_draw(state.cage.keyframe_for_index(current_cut_index), is_2d_widget_in_focus()); +#ifdef __APPLE__ + Eigen::Vector4f widget_3d_viewport(scaling_factor*view_hsplit*window_width, scaling_factor*view_vsplit*window_height, + scaling_factor*(1.0-view_hsplit)*window_width, scaling_factor*(1.0-view_vsplit)*window_height); +#else Eigen::Vector4f widget_3d_viewport(view_hsplit*window_width, view_vsplit*window_height, (1.0-view_hsplit)*window_width, (1.0-view_vsplit)*window_height); +#endif viewer->core.viewport = widget_3d_viewport; if (draw_straight) { ret = widget_3d.post_draw_straight(G4f(widget_3d_viewport), state.cage.keyframe_for_index(current_cut_index)); diff --git a/src/ui/bounding_polygon_plugin.h b/src/ui/bounding_polygon_plugin.h index cde27e8..daa9c68 100644 --- a/src/ui/bounding_polygon_plugin.h +++ b/src/ui/bounding_polygon_plugin.h @@ -44,6 +44,7 @@ class Bounding_Polygon_Menu : public FishUIViewerPlugin { void post_draw_transfer_function(); + float scaling_factor = 2.0; // Scaling factor for window sizes of the two menus float view_hsplit = 0.5; // Horizontal split for the two menus (normalized distance float view_vsplit = 0.2; // Vertical split for the bottom menu (normalized distance from the bottom) diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index 7bcc7cc..bfe390e 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -563,7 +563,9 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Render the slice of the volume for this keyframe into an OpenGL texture // +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render slice"); +#endif { glUseProgram(plane.program); glBindVertexArray(empty_vao); @@ -600,13 +602,17 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } +#ifdef WIN32 glPopDebugGroup(); +#endif // // Render the bounding-box, center, and axes into the same texture // +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render polygon"); +#endif { const glm::vec2 centroid_2d = G2f(kf->centroid_2d()); const glm::vec2 r_axis = G2f(kf->right_rotated_2d()), u_axis = G2f(kf->up_rotated_2d()); @@ -647,7 +653,9 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool } } } +#ifdef WIN32 glPopDebugGroup(); +#endif // Restore the framebuffer and viewport glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -658,7 +666,9 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Blit the texture we just rendered to the screen // +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture Blit"); +#endif { int width; int height; @@ -709,7 +719,9 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } +#ifdef WIN32 glPopDebugGroup(); +#endif glEnable(GL_DEPTH_TEST); return false; diff --git a/src/ui/endpoint_selection_plugin.cpp b/src/ui/endpoint_selection_plugin.cpp index a4c1ebe..ed5be0a 100644 --- a/src/ui/endpoint_selection_plugin.cpp +++ b/src/ui/endpoint_selection_plugin.cpp @@ -146,7 +146,11 @@ void EndPoint_Selection_Menu::deinitialize() { bool EndPoint_Selection_Menu::pre_draw() { int window_width, window_height; glfwGetWindowSize(viewer->window, &window_width, &window_height); +#ifdef __APPLE__ + viewer->core.viewport = Eigen::RowVector4f(2.0*view_hsplit*window_width, 0, 2.0*(1.0-view_hsplit)*window_width, 2.0*window_height); +#else viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); +#endif bool ret = FishUIViewerPlugin::pre_draw(); const Eigen::MatrixXd& TV = state.dilated_tet_mesh.TV; diff --git a/src/ui/selection_plugin.cpp b/src/ui/selection_plugin.cpp index 0e5df37..f9f8fc5 100644 --- a/src/ui/selection_plugin.cpp +++ b/src/ui/selection_plugin.cpp @@ -96,7 +96,11 @@ void Selection_Menu::initialize() { void Selection_Menu::draw_selection_volume() { int window_width, window_height; glfwGetWindowSize(viewer->window, &window_width, &window_height); +#ifdef __APPLE__ + Eigen::RowVector4f viewport(2.0*view_hsplit*window_width, 0, 2.0*(1.0-view_hsplit)*window_width, 2.0*window_height); +#else Eigen::RowVector4f viewport(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); +#endif glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); viewer->core.viewport = viewport; @@ -203,6 +207,28 @@ bool Selection_Menu::key_down(int key, int modifiers) { return false; } +bool Selection_Menu::mouse_down(int button, int modifier) { + double current_press_time = glfwGetTime(); + bool left_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS; + bool right_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS; + if (left_mouse || right_mouse) { + if (!is_first_button_down) { + is_first_button_down = left_mouse || right_mouse; + mouse_down_time = current_press_time; + } + else { + double delta_time = current_press_time - mouse_down_time; + mouse_down_time = 0.0; + is_first_button_down = false; + if (delta_time < mouse_click_threshold) { // CLICK + should_select = true; + return true; + } + } + } + return false; +} + bool Selection_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); diff --git a/src/ui/selection_plugin.h b/src/ui/selection_plugin.h index 9abca9d..5c95211 100644 --- a/src/ui/selection_plugin.h +++ b/src/ui/selection_plugin.h @@ -17,6 +17,7 @@ class Selection_Menu : public FishUIViewerPlugin { void deinitialize(); bool key_down(int key, int modifiers) override; + bool mouse_down(int button, int modifier) override; bool post_draw() override; private: @@ -30,6 +31,10 @@ class Selection_Menu : public FishUIViewerPlugin { Parameters rendering_params; SelectionRenderer selection_renderer; + double mouse_down_time = 0.0; + double mouse_click_threshold = 0.2; + bool is_first_button_down = false; + glm::vec2 clicked_mouse_position = { 0.f, 0.f }; bool is_currently_interacting = false; int current_interaction_index = -1; diff --git a/src/utils/gl/point_line_rendering.cpp b/src/utils/gl/point_line_rendering.cpp index 25b2c49..3c3601e 100644 --- a/src/utils/gl/point_line_rendering.cpp +++ b/src/utils/gl/point_line_rendering.cpp @@ -68,7 +68,9 @@ void PointLineRenderer::destroy() { bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "update_polyline_3d"); +#endif if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -93,12 +95,16 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, G glBindBuffer(GL_ARRAY_BUFFER, 0); +#ifdef WIN32 glPopDebugGroup(); +#endif return true; } bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "update_polyline_3d"); +#endif if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -123,13 +129,17 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, g glDisableVertexAttribArray(1); glBindVertexArray(0); +#ifdef WIN32 glPopDebugGroup(); +#endif return true; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "add_polyline_3d"); +#endif Polyline polyline; @@ -170,13 +180,17 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsiz _polylines.push_back(polyline); } +#ifdef WIN32 glPopDebugGroup(); +#endif return polyline_id; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "add_polyline_3d"); +#endif Polyline polyline; @@ -210,7 +224,9 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsiz _polylines.push_back(polyline); } +#ifdef WIN32 glPopDebugGroup(); +#endif return polyline_id; } diff --git a/src/utils/gl/selection_renderer.cpp b/src/utils/gl/selection_renderer.cpp index 63a5192..17ec0f1 100644 --- a/src/utils/gl/selection_renderer.cpp +++ b/src/utils/gl/selection_renderer.cpp @@ -80,7 +80,7 @@ constexpr const char* VOLUME_PASS_VERTEX_SHADER = R"( // 7. Stop if either the ray is exhausted or the combined transparency is above an // early-ray termination threshold (0.99 in this case) constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( -#version 450 +#version 410 // Keep in sync with main.cpp UI_State::Emphasis const int SELECTION_EMPHASIS_TYPE_NONE = 0; const int SELECTION_EMPHASIS_TYPE_ONSELECTION = 1; @@ -89,15 +89,8 @@ constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( in vec2 uv; out vec4 out_color; - layout (std430, binding = 0) buffer Contour { - uint nFeatures; - uint values[]; - } contour; - - layout (std430, binding = 1) buffer SelectionList { - uint nFeatures; - uint features[]; - } selection; + uniform usamplerBuffer contour; + uniform usamplerBuffer selection; uniform sampler2D entry_texture; uniform sampler2D exit_texture; @@ -204,8 +197,8 @@ constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( } bool is_feature_selected(uint feature) { - for (int i = 0; i < selection.nFeatures; ++i) { - if (selection.features[i] == feature) { + for (int i = 0; i < int(texelFetch(selection, 0).r); ++i) { + if (int(texelFetch(selection, i + 1).r) == feature) { return true; } } @@ -213,7 +206,7 @@ constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( } float selection_factor(bool is_selected) { - if (selection.nFeatures == 0) { + if (int(texelFetch(selection, 0).r) == 0) { return 1.f; } @@ -261,13 +254,13 @@ constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( vec3 sample_pos = entry + t * normalized_ray_direction; uint segVoxel = texture(index_volume, sample_pos).r; - uint feature = contour.values[segVoxel] + 1; + uint feature = texelFetch(contour, int(segVoxel) + 1).r + 1; if (feature != 0) { float value = texture(volume_texture, sample_pos).r; vec4 color; if (color_by_identifier == 1) { - const float normFeature = float(feature) / float(contour.nFeatures); + float normFeature = float(feature) / float(texelFetch(contour, 0).r); color.rgb = colormap(normFeature).rgb; color.a = selection_factor(is_feature_selected(feature)); } else { @@ -321,15 +314,11 @@ constexpr const char* SELECTION_RENDERING_FRAG_SHADER = R"( // 7. Stop if either the ray is exhausted or the combined transparency is above an // early-ray termination threshold (0.99 in this case) constexpr const char* SELECTION_PICKING_PASS_FRAG_SHADER = R"( -#version 450 +#version 410 in vec2 uv; out vec4 out_color; - layout (std430, binding = 0) buffer Contour { - uint nFeatures; - uint values[]; - } contour; - + uniform usamplerBuffer contour; uniform sampler2D entry_texture; uniform sampler2D exit_texture; @@ -362,8 +351,8 @@ constexpr const char* SELECTION_PICKING_PASS_FRAG_SHADER = R"( float t = 0.0; while (t < t_end) { vec3 sample_pos = entry + t * normalized_ray_direction; - const uint segVoxel = texture(index_volume, sample_pos).r; - const uint feature = contour.values[segVoxel]; + uint segVoxel = texture(index_volume, sample_pos).r; + uint feature = texelFetch(contour, int(segVoxel) + 1).r; if (feature != -1) { out_color = vec4(vec3(float(feature + 1)), 1.0); return; @@ -450,6 +439,11 @@ void SelectionRenderer::initialize(const glm::ivec2& viewport_size) igl::opengl::create_shader_program(VOLUME_PASS_VERTEX_SHADER, SELECTION_RENDERING_FRAG_SHADER, {}, _gl_state.volume_pass.program_object); + _gl_state.volume_pass.uniform_location.contour_texture = glGetUniformLocation( + _gl_state.volume_pass.program_object, "contour"); + _gl_state.volume_pass.uniform_location.selection_texture = glGetUniformLocation( + _gl_state.volume_pass.program_object, "selection"); + _gl_state.volume_pass.uniform_location.entry_texture = glGetUniformLocation( _gl_state.volume_pass.program_object, "entry_texture"); _gl_state.volume_pass.uniform_location.exit_texture = glGetUniformLocation( @@ -490,6 +484,10 @@ void SelectionRenderer::initialize(const glm::ivec2& viewport_size) igl::opengl::create_shader_program(VOLUME_PASS_VERTEX_SHADER, SELECTION_PICKING_PASS_FRAG_SHADER, {}, _gl_state.picking_pass.program_object); + _gl_state.picking_pass.uniform_location.contour_texture = + glGetUniformLocation( + _gl_state.picking_pass.program_object, "contour" + ); _gl_state.picking_pass.uniform_location.entry_texture = glGetUniformLocation( _gl_state.picking_pass.program_object, "entry_texture" @@ -574,9 +572,19 @@ void SelectionRenderer::initialize(const glm::ivec2& viewport_size) glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - // SSBO - glGenBuffers(1, &_gl_state.volume_pass.contour_information_ssbo); - glGenBuffers(1, &_gl_state.volume_pass.selection_list_ssbo); + // Initialize contour buffer texture + glGenTextures(1, &_gl_state.volume_pass.contour_texture); + glBindTexture(GL_TEXTURE_BUFFER, _gl_state.volume_pass.contour_texture); + + + // Initialize selection buffer texture + glGenTextures(1, &_gl_state.volume_pass.selection_texture); + glBindTexture(GL_TEXTURE_BUFFER, _gl_state.volume_pass.selection_texture); + + + // Contour and selection texture buffer objects + glGenBuffers(1, &_gl_state.volume_pass.contour_information_tbo); + glGenBuffers(1, &_gl_state.volume_pass.selection_list_tbo); } @@ -585,13 +593,15 @@ void SelectionRenderer::destroy() { std::vector buffers = { _gl_state.geometry_pass.vbo, _gl_state.geometry_pass.ibo, - _gl_state.volume_pass.contour_information_ssbo, - _gl_state.volume_pass.selection_list_ssbo }; + _gl_state.volume_pass.contour_information_tbo, + _gl_state.volume_pass.selection_list_tbo }; std::vector textures = { _gl_state.geometry_pass.entry_texture, _gl_state.geometry_pass.exit_texture, _gl_state.volume_pass.transfer_function_texture, - _gl_state.picking_pass.picking_texture, + _gl_state.volume_pass.selection_texture, + _gl_state.volume_pass.contour_texture, + _gl_state.picking_pass.picking_texture }; std::vector framebuffers = { _gl_state.geometry_pass.entry_framebuffer, @@ -610,7 +620,9 @@ void SelectionRenderer::destroy() { } void SelectionRenderer::set_transfer_function(const std::vector &tf) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Update Transfer Function"); +#endif constexpr const int TRANSFER_FUNCTION_WIDTH = 512; @@ -684,12 +696,16 @@ void SelectionRenderer::set_transfer_function(const std::vector &tf) { GL_UNSIGNED_BYTE, transfer_function_data.data()); glBindTexture(GL_TEXTURE_1D, 0); +#ifdef WIN32 glPopDebugGroup(); +#endif } void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_matrix, glm::mat4 proj_matrix) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Bounding Box"); +#endif const glm::vec4 color_transparent(0.0); @@ -749,11 +765,15 @@ void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_mat glDisable(GL_CULL_FACE); } +#ifdef WIN32 glPopDebugGroup(); +#endif } void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, GLuint volume_texture) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Volume"); +#endif // // Setup @@ -771,12 +791,10 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, // Contour Buffer - glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_state.volume_pass.contour_information_ssbo); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, _gl_state.volume_pass.contour_information_ssbo); + glBindBuffer(GL_TEXTURE_BUFFER, _gl_state.volume_pass.contour_information_tbo); // Selection Buffer - glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_state.volume_pass.selection_list_ssbo); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, _gl_state.volume_pass.selection_list_ssbo); + glBindBuffer(GL_TEXTURE_BUFFER, _gl_state.volume_pass.selection_list_tbo); glUniform1i(_gl_state.volume_pass.uniform_location.color_by_identifier, parameters.color_by_id ? 1 : 0); @@ -794,7 +812,7 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, // Exit points texture glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, _gl_state.geometry_pass.exit_texture); - glUniform1i(_gl_state.volume_pass.uniform_location.entry_texture, 1); + glUniform1i(_gl_state.volume_pass.uniform_location.exit_texture, 1); // Volume texture glActiveTexture(GL_TEXTURE2); @@ -810,6 +828,18 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_3D, index_texture); glUniform1i(_gl_state.volume_pass.uniform_location.index_volume, 4); + + // Contour buffer texture + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_BUFFER, _gl_state.volume_pass.contour_texture); + glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, _gl_state.volume_pass.contour_information_tbo); + glUniform1i(_gl_state.volume_pass.uniform_location.contour_texture, 5); + + // Selection buffer texture + glActiveTexture(GL_TEXTURE6); + glBindTexture(GL_TEXTURE_BUFFER, _gl_state.volume_pass.selection_texture); + glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, _gl_state.volume_pass.selection_list_tbo); + glUniform1i(_gl_state.volume_pass.uniform_location.selection_texture, 6); glUniform1f(_gl_state.volume_pass.uniform_location.sampling_rate, parameters.sampling_rate); @@ -839,7 +869,9 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, glBindVertexArray(0); +#ifdef WIN32 glPopDebugGroup(); +#endif } glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mouse_position, GLuint index_texture, GLuint volume_texture) { @@ -848,7 +880,9 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindTexture(GL_TEXTURE_3D, index_texture); glUniform1i(_gl_state.picking_pass.uniform_location.index_volume, 4); +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Pick Volume"); +#endif glBindFramebuffer(GL_FRAMEBUFFER, _gl_state.picking_pass.picking_framebuffer); glClear(GL_COLOR_BUFFER_BIT); @@ -863,7 +897,7 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous // Exit points texture glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, _gl_state.geometry_pass.exit_texture); - glUniform1i(_gl_state.picking_pass.uniform_location.entry_texture, 1); + glUniform1i(_gl_state.picking_pass.uniform_location.exit_texture, 1); // Volume texture glActiveTexture(GL_TEXTURE2); @@ -874,6 +908,12 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_1D, _gl_state.volume_pass.transfer_function_texture); glUniform1i(_gl_state.picking_pass.uniform_location.transfer_function, 3); + + // Contour buffer texture + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_BUFFER, _gl_state.volume_pass.contour_texture); + glTexBuffer(GL_TEXTURE_BUFFER, GL_R32UI, _gl_state.volume_pass.contour_information_tbo); + glUniform1i(_gl_state.picking_pass.uniform_location.contour_texture, 5); glUniform1f(_gl_state.picking_pass.uniform_location.sampling_rate, parameters.sampling_rate); @@ -898,7 +938,9 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindVertexArray(0); +#ifdef WIN32 glPopDebugGroup(); +#endif return { colors[0], @@ -908,15 +950,15 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous } void SelectionRenderer::set_contour_data(uint32_t* contour_features, size_t num_features) { - glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_state.volume_pass.contour_information_ssbo); - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(uint32_t) * num_features, contour_features, GL_DYNAMIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + glBindBuffer(GL_TEXTURE_BUFFER, _gl_state.volume_pass.contour_information_tbo); + glBufferData(GL_TEXTURE_BUFFER, sizeof(uint32_t) * num_features, contour_features, GL_DYNAMIC_DRAW); + glBindBuffer(GL_TEXTURE_BUFFER, 0); } void SelectionRenderer::set_selection_data(uint32_t* selection_list, size_t num_features) { - glBindBuffer(GL_SHADER_STORAGE_BUFFER, _gl_state.volume_pass.selection_list_ssbo); - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(uint32_t) * num_features, selection_list, GL_DYNAMIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + glBindBuffer(GL_TEXTURE_BUFFER, _gl_state.volume_pass.selection_list_tbo); + glBufferData(GL_TEXTURE_BUFFER, sizeof(uint32_t) * num_features, selection_list, GL_DYNAMIC_DRAW); + glBindBuffer(GL_TEXTURE_BUFFER, 0); } void SelectionRenderer::resize_framebuffer(glm::ivec2 framebuffer_size) { diff --git a/src/utils/gl/selection_renderer.h b/src/utils/gl/selection_renderer.h index d801799..3e14f93 100644 --- a/src/utils/gl/selection_renderer.h +++ b/src/utils/gl/selection_renderer.h @@ -54,10 +54,16 @@ class SelectionRenderer { GLuint program_object = 0; GLuint transfer_function_texture; - GLuint selection_list_ssbo; - GLuint contour_information_ssbo; + GLuint selection_texture; + GLuint contour_texture; + + GLuint selection_list_tbo; + GLuint contour_information_tbo; struct { + GLint selection_texture = 0; + GLint contour_texture = 0; + GLint entry_texture = 0; GLint exit_texture = 0; GLint volume_texture = 0; @@ -87,6 +93,7 @@ class SelectionRenderer { GLuint picking_texture = 0; struct { + GLint contour_texture = 0; GLint entry_texture = 0; GLint exit_texture = 0; GLint volume_texture = 0; diff --git a/src/utils/gl/volume_exporter.cpp b/src/utils/gl/volume_exporter.cpp index c08d03f..1b02436 100644 --- a/src/utils/gl/volume_exporter.cpp +++ b/src/utils/gl/volume_exporter.cpp @@ -68,7 +68,9 @@ void main() { )"; void VolumeExporter::write_texture_data_to_file(std::string filename) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Export"); +#endif const size_t num_voxels = size_t(w)*size_t(h)*size_t(d); std::vector out_data; out_data.resize(num_voxels*4); @@ -82,7 +84,9 @@ void VolumeExporter::write_texture_data_to_file(std::string filename) { real_data.resize(num_voxels); for (size_t i = 0; i < num_voxels; i++) { real_data[i] = out_data[4*i]; } NRRD::save3D (filename, real_data.data(), this->w, this->h, this->d); +#ifdef WIN32 glPopDebugGroup(); +#endif } void VolumeExporter::set_export_dims(GLsizei w, GLsizei h, GLsizei d) { @@ -103,7 +107,9 @@ void VolumeExporter::destroy() { } void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Init Slice"); +#endif igl::opengl::create_shader_program(SLICE_VERTEX_SHADER, SLICE_FRAGMENT_SHADER, {}, slice.program); slice.ll_location = glGetUniformLocation(slice.program, "ll"); @@ -130,7 +136,9 @@ void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { glGenFramebuffers(1, &framebuffer); glBindTexture(GL_TEXTURE_3D, 0); +#ifdef WIN32 glPopDebugGroup(); +#endif } @@ -140,7 +148,9 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Export Slice"); +#endif glUseProgram(slice.program); glBindVertexArray(empty_vao); @@ -203,7 +213,9 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec glBindVertexArray(0); glUseProgram(0); glBindTexture(GL_TEXTURE_3D, 0); +#ifdef WIN32 glPopDebugGroup(); +#endif glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); } diff --git a/src/utils/gl/volume_renderer.cpp b/src/utils/gl/volume_renderer.cpp index 9806f55..ce562ac 100644 --- a/src/utils/gl/volume_renderer.cpp +++ b/src/utils/gl/volume_renderer.cpp @@ -501,7 +501,9 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ // Generate multipass buffers if enabled +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Init VolumeRenderer Multipass"); +#endif for (int i = 0; i < 2; i++) { glGenTextures(1, &_gl_state.multipass.texture[i]); glBindTexture(GL_TEXTURE_2D, _gl_state.multipass.texture[i]); @@ -517,11 +519,15 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ } glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); +#ifdef WIN32 glPopDebugGroup(); +#endif } void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm::mat4& view_matrix, const glm::mat4& proj_matrix) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Bounding Box"); +#endif { const glm::vec4 color_transparent(0.0); @@ -578,11 +584,15 @@ void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm: glDisable(GL_CULL_FACE); } } +#ifdef WIN32 glPopDebugGroup(); +#endif } void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ivec3& volume_dims, GLuint volume_tex, GLuint multipass_tex) { +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Volume TEST"); +#endif // // Setup @@ -640,7 +650,9 @@ void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ive glBindVertexArray(0); +#ifdef WIN32 glPopDebugGroup(); +#endif } void VolumeRenderer::begin(const glm::ivec3& volume_dims, GLuint tex) { @@ -682,7 +694,9 @@ void VolumeRenderer::render_pass( const int current_buf = _current_multipass_buf; const int last_buf = (_current_multipass_buf+1) % 2; +#ifdef WIN32 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Multipass render"); +#endif GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); @@ -709,7 +723,9 @@ void VolumeRenderer::render_pass( volume_pass(light_position, _current_volume_dims, volume_tex, _gl_state.multipass.texture[last_buf]); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); +#ifdef WIN32 glPopDebugGroup(); +#endif } From 525b13aba27ce2f4afa1042b26501f7948909ec0 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Mon, 22 Jul 2019 15:03:29 -0400 Subject: [PATCH 12/21] Changed features for rendering and UI functionality on MacOS --- src/main.cpp | 4 +-- src/ui/bounding_polygon_plugin.cpp | 18 +++++----- src/ui/bounding_polygon_plugin.h | 1 + src/ui/bounding_widget_2d.cpp | 47 +++++++++++++-------------- src/ui/bounding_widget_2d.h | 2 ++ src/ui/endpoint_selection_plugin.cpp | 14 ++++---- src/ui/endpoint_selection_plugin.h | 1 + src/ui/fish_ui_viewer_plugin.cpp | 13 +++++++- src/ui/fish_ui_viewer_plugin.h | 2 ++ src/ui/meshing_plugin.cpp | 2 +- src/ui/selection_plugin.cpp | 34 ++++--------------- src/ui/selection_plugin.h | 7 ++-- src/ui/state.cpp | 8 +++++ src/ui/state.h | 2 +- src/utils/bounding_cage.h | 1 - src/utils/gl/point_line_rendering.cpp | 34 ++++++------------- src/utils/gl/selection_renderer.cpp | 32 +++++------------- src/utils/gl/volume_exporter.cpp | 26 +++++---------- src/utils/gl/volume_renderer.cpp | 33 +++++-------------- src/utils/utils.cpp | 11 +++++++ src/utils/utils.h | 2 ++ 21 files changed, 124 insertions(+), 170 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 54a5201..759ee96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ void log_opengl_debug(GLenum source, GLenum type, GLuint id, GLenum severity, "OpenGL Debug msg: Source: {}, Type: {}, Id: {}, Severity: {}, Message: {}", source, type, id, severity, std::string(message) ); -#ifdef WIN32 +#if !defined(__APPLE__) DebugBreak(); #endif } @@ -56,7 +56,7 @@ bool init(igl::opengl::glfw::Viewer& viewer) { ct_logger->set_level(CONTOURTREE_LOGGER_LEVEL); contourtree::Logger::setLogger(ct_logger); -#ifdef WIN32 +#if !defined(__APPLE__) glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(log_opengl_debug, NULL); #endif diff --git a/src/ui/bounding_polygon_plugin.cpp b/src/ui/bounding_polygon_plugin.cpp index d47653c..1b98368 100644 --- a/src/ui/bounding_polygon_plugin.cpp +++ b/src/ui/bounding_polygon_plugin.cpp @@ -344,12 +344,12 @@ bool Bounding_Polygon_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); + state.get_window_size(viewer->window, &window_width, &window_height); #ifdef __APPLE__ - glViewport(-scaling_factor*window_width*view_hsplit, -(1.0+view_vsplit)*window_height, - scaling_factor*window_width, (scaling_factor*scaling_factor)*(1.0-view_vsplit)*window_height); - widget_2d.position = glm::vec2(0.f, view_vsplit*window_height/(scaling_factor*scaling_factor)); - widget_2d.size = glm::vec2(window_width*view_hsplit, (1.0-view_vsplit)*window_height/scaling_factor); + glViewport(-window_width*view_hsplit, -(1.0+view_vsplit)*window_height/scaling_factor, + window_width, scaling_factor*(1.0-view_vsplit)*window_height); + widget_2d.position = glm::vec2(0.f, view_vsplit*window_height/(scaling_factor*scaling_factor*scaling_factor)); + widget_2d.size = glm::vec2(window_width*view_hsplit/scaling_factor, (1.0-view_vsplit)*window_height/(scaling_factor*scaling_factor)); #else glViewport(0, 0, window_width, window_height); widget_2d.position = glm::vec2(0.f, view_vsplit*window_height); @@ -357,13 +357,8 @@ bool Bounding_Polygon_Menu::post_draw() { #endif ret = widget_2d.post_draw(state.cage.keyframe_for_index(current_cut_index), is_2d_widget_in_focus()); -#ifdef __APPLE__ - Eigen::Vector4f widget_3d_viewport(scaling_factor*view_hsplit*window_width, scaling_factor*view_vsplit*window_height, - scaling_factor*(1.0-view_hsplit)*window_width, scaling_factor*(1.0-view_vsplit)*window_height); -#else Eigen::Vector4f widget_3d_viewport(view_hsplit*window_width, view_vsplit*window_height, (1.0-view_hsplit)*window_width, (1.0-view_vsplit)*window_height); -#endif viewer->core.viewport = widget_3d_viewport; if (draw_straight) { ret = widget_3d.post_draw_straight(G4f(widget_3d_viewport), state.cage.keyframe_for_index(current_cut_index)); @@ -375,6 +370,9 @@ bool Bounding_Polygon_Menu::post_draw() { ImGui::SetNextWindowBgAlpha(0.5f); float window_height_float = static_cast(window_height); float window_width_float = static_cast(window_width); +#ifdef __APPLE__ + window_height_float /= 2, window_width_float /= 2; +#endif ImGui::SetNextWindowPos(ImVec2(0.f, (1.0-view_vsplit)*window_height_float), ImGuiSetCond_Always); ImGui::SetNextWindowSize(ImVec2(window_width_float, window_height_float*view_vsplit), ImGuiSetCond_Always); ImGui::Begin("Select Boundary", nullptr, diff --git a/src/ui/bounding_polygon_plugin.h b/src/ui/bounding_polygon_plugin.h index daa9c68..407ceb7 100644 --- a/src/ui/bounding_polygon_plugin.h +++ b/src/ui/bounding_polygon_plugin.h @@ -70,6 +70,7 @@ class Bounding_Polygon_Menu : public FishUIViewerPlugin { std::string save_name_error_message; int output_dims[3] = {-1, -1, -1}; bool output_preserve_aspect_ratio = true; + // bool output_export_hires_texture = true; double front_bump_amount = 0.0; double back_bump_amount = 0.0; diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index bfe390e..36ca685 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -2,6 +2,8 @@ #include "bounding_polygon_plugin.h" +#include "utils/utils.h" + #include #include #include @@ -143,9 +145,13 @@ struct BlitData { Bounding_Polygon_Widget::Bounding_Polygon_Widget(State& state) : state(state) {} glm::vec2 Bounding_Polygon_Widget::convert_position_mainwindow_to_keyframe(const glm::vec2& p) const { +#ifdef __APPLE__ + glm::vec2 window_ll = glm::vec2(position.x, size.y); + glm::vec2 window_ur = window_ll + glm::vec2(widget_scaling_factor*size.y, widget_scaling_factor*size.y); +#else glm::vec2 window_ll = position; glm::vec2 window_ur = position + size; - +#endif // Map mouse into [0, 1]^2 in the subwindow glm::vec2 normalized_mouse = (p - window_ll) / (window_ur - window_ll); @@ -163,11 +169,16 @@ glm::vec2 Bounding_Polygon_Widget::convert_position_keyframe_to_ndc(const glm::v bool Bounding_Polygon_Widget::is_point_in_widget(glm::ivec2 p) const { int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); + state.get_window_size(viewer->window, &window_width, &window_height); const glm::ivec2 p_tx(p.x, window_height - p.y); +#ifdef __APPLE__ + const glm::ivec2 ll = glm::ivec2(position.x, size.y); + const glm::ivec2 ur = ll + glm::ivec2(view_scaling_factor*size.y, view_scaling_factor*size.y); +#else const glm::ivec2 ll = position; const glm::ivec2 ur = position + size; +#endif return p_tx.x >= ll.x && p_tx.x <= ur.x && p_tx.y >= ll.y && p_tx.y <= ur.y; } @@ -189,7 +200,7 @@ void Bounding_Polygon_Widget::update_selection() { }; glm::ivec2 window_size; - glfwGetWindowSize(viewer->window, &window_size.x, &window_size.y); + state.get_window_size(viewer->window, &window_size.x, &window_size.y); glm::vec2 current_mouse = { viewer->current_mouse_x, window_size.y - viewer->current_mouse_y }; // In main window pixel space glm::vec2 kf_mouse = convert_position_mainwindow_to_keyframe(current_mouse); // In keyframe ndc @@ -297,7 +308,7 @@ void Bounding_Polygon_Widget::initialize(igl::opengl::glfw::Viewer* viewer, Boun bool Bounding_Polygon_Widget::mouse_move(int mouse_x, int mouse_y, bool in_focus) { glm::ivec2 window_size; - glfwGetWindowSize(viewer->window, &window_size.x, &window_size.y); + state.get_window_size(viewer->window, &window_size.x, &window_size.y); mouse_state.current_position = glm::ivec2(mouse_x, mouse_y); if (!in_focus) { //!is_point_in_widget(glm::ivec2(mouse_x, mouse_y)) || @@ -415,7 +426,7 @@ bool Bounding_Polygon_Widget::mouse_move(int mouse_x, int mouse_y, bool in_focus bool Bounding_Polygon_Widget::mouse_down(int button, int modifier, bool in_focus) { glm::ivec2 window_size; - glfwGetWindowSize(viewer->window, &window_size.x, &window_size.y); + state.get_window_size(viewer->window, &window_size.x, &window_size.y); bool left_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS; bool right_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS; @@ -563,9 +574,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Render the slice of the volume for this keyframe into an OpenGL texture // -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render slice"); -#endif + debug_group_action("PUSH", "Render slice"); { glUseProgram(plane.program); glBindVertexArray(empty_vao); @@ -602,17 +611,13 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); // // Render the bounding-box, center, and axes into the same texture // -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render polygon"); -#endif + debug_group_action("PUSH", "Render polygon"); { const glm::vec2 centroid_2d = G2f(kf->centroid_2d()); const glm::vec2 r_axis = G2f(kf->right_rotated_2d()), u_axis = G2f(kf->up_rotated_2d()); @@ -639,7 +644,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // Render rotation handle if (mouse_state.is_rotate_modifier_down && in_focus) { glm::ivec2 window_size; - glfwGetWindowSize(viewer->window, &window_size.x, &window_size.y); + state.get_window_size(viewer->window, &window_size.x, &window_size.y); glm::vec2 current_mouse = { viewer->current_mouse_x, window_size.y - viewer->current_mouse_y }; glm::vec2 kf_mouse = convert_position_mainwindow_to_keyframe(current_mouse); @@ -653,9 +658,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool } } } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); // Restore the framebuffer and viewport glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -666,9 +669,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Blit the texture we just rendered to the screen // -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture Blit"); -#endif + debug_group_action("PUSH", "Texture Blit"); { int width; int height; @@ -719,9 +720,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); glEnable(GL_DEPTH_TEST); return false; diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index 19fbcf6..a62a35a 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -39,6 +39,8 @@ class Bounding_Polygon_Widget { float split_point_size = 7.f; float center_point_size = 12.f; float selected_center_point_size = 14.f; + float view_scaling_factor = 3.f; + float widget_scaling_factor = 4.5f; glm::vec4 rotation_handle_reference_color = glm::vec4(0.5f, 0.5f, 0.2f, 1.0f); glm::vec4 rotation_handle_color = glm::vec4(0.9f, 0.9f, 0.2f, 1.0f); diff --git a/src/ui/endpoint_selection_plugin.cpp b/src/ui/endpoint_selection_plugin.cpp index ed5be0a..df7b3be 100644 --- a/src/ui/endpoint_selection_plugin.cpp +++ b/src/ui/endpoint_selection_plugin.cpp @@ -115,7 +115,7 @@ void EndPoint_Selection_Menu::initialize() { old_viewport = viewer->core.viewport; int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); + state.get_window_size(viewer->window, &window_width, &window_height); viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); if (state.dirty_flags.endpoints_dirty) { @@ -145,12 +145,12 @@ void EndPoint_Selection_Menu::deinitialize() { bool EndPoint_Selection_Menu::pre_draw() { int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); -#ifdef __APPLE__ - viewer->core.viewport = Eigen::RowVector4f(2.0*view_hsplit*window_width, 0, 2.0*(1.0-view_hsplit)*window_width, 2.0*window_height); -#else + state.get_window_size(viewer->window, &window_width, &window_height); +// #ifdef __APPLE__ +// window_width *= scaling_factor; +// window_height *= scaling_factor; +// #endif viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); -#endif bool ret = FishUIViewerPlugin::pre_draw(); const Eigen::MatrixXd& TV = state.dilated_tet_mesh.TV; @@ -275,7 +275,7 @@ void EndPoint_Selection_Menu::debug_draw_intermediate_state() { bool EndPoint_Selection_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); + state.get_window_size(viewer->window, &window_width, &window_height); viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); int width; diff --git a/src/ui/endpoint_selection_plugin.h b/src/ui/endpoint_selection_plugin.h index ca6a807..a97de8c 100644 --- a/src/ui/endpoint_selection_plugin.h +++ b/src/ui/endpoint_selection_plugin.h @@ -31,6 +31,7 @@ class EndPoint_Selection_Menu : public FishUIViewerPlugin { Eigen::Vector4f old_viewport; + float scaling_factor = 2.f; float view_hsplit = 0.2f; bool selecting_endpoints = false; diff --git a/src/ui/fish_ui_viewer_plugin.cpp b/src/ui/fish_ui_viewer_plugin.cpp index 271161b..51e0742 100644 --- a/src/ui/fish_ui_viewer_plugin.cpp +++ b/src/ui/fish_ui_viewer_plugin.cpp @@ -1,3 +1,4 @@ +#include "state.h" #include "fish_ui_viewer_plugin.h" #include @@ -102,6 +103,13 @@ bool FishUIViewerPlugin::key_up(int key, int modifiers) { return ImGui::GetIO().WantCaptureKeyboard; } +void FishUIViewerPlugin::window_size(GLFWwindow* handle, int* width, int* height) { + glfwGetWindowSize(handle, width, height); +#ifdef __APPLE__ + *width *= 2; + *height *= 2; +#endif +} float FishUIViewerPlugin::pixel_ratio() { // Computes pixel ratio for hidpi devices @@ -111,7 +119,7 @@ float FishUIViewerPlugin::pixel_ratio() { glfwGetFramebufferSize(window, &buf_size[0], &buf_size[1]); int win_size[2]; - glfwGetWindowSize(window, &win_size[0], &win_size[1]); + window_size(window, &win_size[0], &win_size[1]); return static_cast(buf_size[0]) / static_cast(win_size[0]); } @@ -121,6 +129,9 @@ float FishUIViewerPlugin::hidpi_scaling() { float xscale, yscale; glfwGetWindowContentScale(window, &xscale, &yscale); +#ifdef __APPLE__ + xscale /= 2, yscale /= 2; +#endif return 0.5f * (xscale + yscale); } diff --git a/src/ui/fish_ui_viewer_plugin.h b/src/ui/fish_ui_viewer_plugin.h index a6626fc..fbbf862 100644 --- a/src/ui/fish_ui_viewer_plugin.h +++ b/src/ui/fish_ui_viewer_plugin.h @@ -34,6 +34,8 @@ class FishUIViewerPlugin : public igl::opengl::glfw::ViewerPlugin { void draw_text(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string& text); + void window_size(GLFWwindow* handle, int* width, int* height); + float pixel_ratio(); float hidpi_scaling(); float menu_scaling() { return hidpi_scaling_ / pixel_ratio_; } diff --git a/src/ui/meshing_plugin.cpp b/src/ui/meshing_plugin.cpp index 3a7d05e..efa9f89 100644 --- a/src/ui/meshing_plugin.cpp +++ b/src/ui/meshing_plugin.cpp @@ -180,7 +180,7 @@ bool Meshing_Menu::post_draw() { if (is_meshing) { int width; int height; - glfwGetWindowSize(viewer->window, &width, &height); + _state.get_window_size(viewer->window, &width, &height); ImGui::SetNextWindowPos(ImVec2(0.f, 0.f), ImGuiSetCond_Always); float w = static_cast(width); float h = static_cast(height); diff --git a/src/ui/selection_plugin.cpp b/src/ui/selection_plugin.cpp index f9f8fc5..198c7e5 100644 --- a/src/ui/selection_plugin.cpp +++ b/src/ui/selection_plugin.cpp @@ -42,7 +42,7 @@ void Selection_Menu::initialize() { target_viewport_size = { -1.f, -1.f, -1.f, -1.f }; int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); + _state.get_window_size(viewer->window, &window_width, &window_height); const int maxDim = glm::compMax(rendering_params.volume_dimensions); const float md = static_cast(maxDim); @@ -95,12 +95,12 @@ void Selection_Menu::initialize() { void Selection_Menu::draw_selection_volume() { int window_width, window_height; - glfwGetWindowSize(viewer->window, &window_width, &window_height); -#ifdef __APPLE__ - Eigen::RowVector4f viewport(2.0*view_hsplit*window_width, 0, 2.0*(1.0-view_hsplit)*window_width, 2.0*window_height); -#else + _state.get_window_size(viewer->window, &window_width, &window_height); +// #ifdef __APPLE__ +// window_width *= scaling_factor; +// window_height *= scaling_factor; +// #endif Eigen::RowVector4f viewport(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); -#endif glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); viewer->core.viewport = viewport; @@ -207,28 +207,6 @@ bool Selection_Menu::key_down(int key, int modifiers) { return false; } -bool Selection_Menu::mouse_down(int button, int modifier) { - double current_press_time = glfwGetTime(); - bool left_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS; - bool right_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS; - if (left_mouse || right_mouse) { - if (!is_first_button_down) { - is_first_button_down = left_mouse || right_mouse; - mouse_down_time = current_press_time; - } - else { - double delta_time = current_press_time - mouse_down_time; - mouse_down_time = 0.0; - is_first_button_down = false; - if (delta_time < mouse_click_threshold) { // CLICK - should_select = true; - return true; - } - } - } - return false; -} - bool Selection_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); diff --git a/src/ui/selection_plugin.h b/src/ui/selection_plugin.h index 5c95211..f7feb7a 100644 --- a/src/ui/selection_plugin.h +++ b/src/ui/selection_plugin.h @@ -12,16 +12,17 @@ struct State; class Selection_Menu : public FishUIViewerPlugin { public: Selection_Menu(State& state); + void get_window_size(GLFWwindow* handle, int* width, int* height); void initialize(); void deinitialize(); bool key_down(int key, int modifiers) override; - bool mouse_down(int button, int modifier) override; bool post_draw() override; private: Eigen::RowVector4f old_viewport; + float scaling_factor = 2.f; float view_hsplit = 0.2f; void draw_selection_volume(); @@ -31,10 +32,6 @@ class Selection_Menu : public FishUIViewerPlugin { Parameters rendering_params; SelectionRenderer selection_renderer; - double mouse_down_time = 0.0; - double mouse_click_threshold = 0.2; - bool is_first_button_down = false; - glm::vec2 clicked_mouse_position = { 0.f, 0.f }; bool is_currently_interacting = false; int current_interaction_index = -1; diff --git a/src/ui/state.cpp b/src/ui/state.cpp index 89bbde0..61c7540 100644 --- a/src/ui/state.cpp +++ b/src/ui/state.cpp @@ -37,6 +37,14 @@ void State::LoadedVolume::preprocess_volume_texture(std::vector& byte_d } +void State::get_window_size(GLFWwindow* handle, int* width, int* height) { + glfwGetWindowSize(handle, width, height); +#ifdef __APPLE__ + *width *= 2, *height *= 2; +#endif +} + + void State::load_volume_data(State::LoadedVolume& volume, std::string prefix, bool load_topology) { std::string prefix_with_path = input_metadata.output_dir + "/" + prefix; diff --git a/src/ui/state.h b/src/ui/state.h index 04aad97..e8ef537 100644 --- a/src/ui/state.h +++ b/src/ui/state.h @@ -161,7 +161,7 @@ struct State { } skeleton_estimation_parameters; - + void get_window_size(GLFWwindow* handle, int* width, int* height); void load_volume_data(LoadedVolume& volume, std::string prefix, bool load_topology); BoundingCage cage; diff --git a/src/utils/bounding_cage.h b/src/utils/bounding_cage.h index d530a0e..454854a 100644 --- a/src/utils/bounding_cage.h +++ b/src/utils/bounding_cage.h @@ -457,7 +457,6 @@ class BoundingCage { bool bump(double amount) { this->_origin += amount * this->normal(); - return true; } /// Rotate the coordinate frame counter-clockwise about the normal axis diff --git a/src/utils/gl/point_line_rendering.cpp b/src/utils/gl/point_line_rendering.cpp index 3c3601e..9f3be1e 100644 --- a/src/utils/gl/point_line_rendering.cpp +++ b/src/utils/gl/point_line_rendering.cpp @@ -1,5 +1,7 @@ #include "point_line_rendering.h" +#include "utils/utils.h" + #include #include @@ -68,9 +70,7 @@ void PointLineRenderer::destroy() { bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "update_polyline_3d"); -#endif + debug_group_action("PUSH", "update_polyline_3d"); if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -95,16 +95,12 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, G glBindBuffer(GL_ARRAY_BUFFER, 0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); return true; } bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "update_polyline_3d"); -#endif + debug_group_action("PUSH", "update_polyline_3d"); if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -129,17 +125,13 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, g glDisableVertexAttribArray(1); glBindVertexArray(0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); return true; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "add_polyline_3d"); -#endif + debug_group_action("PUSH", "add_polyline_3d"); Polyline polyline; @@ -180,17 +172,13 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsiz _polylines.push_back(polyline); } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); return polyline_id; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "add_polyline_3d"); -#endif + debug_group_action("PUSH", "add_polyline_3d"); Polyline polyline; @@ -224,9 +212,7 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsiz _polylines.push_back(polyline); } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); return polyline_id; } diff --git a/src/utils/gl/selection_renderer.cpp b/src/utils/gl/selection_renderer.cpp index 17ec0f1..e6d7a0a 100644 --- a/src/utils/gl/selection_renderer.cpp +++ b/src/utils/gl/selection_renderer.cpp @@ -620,9 +620,7 @@ void SelectionRenderer::destroy() { } void SelectionRenderer::set_transfer_function(const std::vector &tf) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Update Transfer Function"); -#endif + debug_group_action("PUSH", "Update Transfer Function"); constexpr const int TRANSFER_FUNCTION_WIDTH = 512; @@ -696,16 +694,12 @@ void SelectionRenderer::set_transfer_function(const std::vector &tf) { GL_UNSIGNED_BYTE, transfer_function_data.data()); glBindTexture(GL_TEXTURE_1D, 0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_matrix, glm::mat4 proj_matrix) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Bounding Box"); -#endif + debug_group_action("PUSH", "Render Bounding Box"); const glm::vec4 color_transparent(0.0); @@ -765,15 +759,11 @@ void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_mat glDisable(GL_CULL_FACE); } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, GLuint volume_texture) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Volume"); -#endif + debug_group_action("PUSH", "Render Volume"); // // Setup @@ -869,9 +859,7 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, glBindVertexArray(0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mouse_position, GLuint index_texture, GLuint volume_texture) { @@ -880,9 +868,7 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindTexture(GL_TEXTURE_3D, index_texture); glUniform1i(_gl_state.picking_pass.uniform_location.index_volume, 4); -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Pick Volume"); -#endif + debug_group_action("PUSH", "Pick Volume"); glBindFramebuffer(GL_FRAMEBUFFER, _gl_state.picking_pass.picking_framebuffer); glClear(GL_COLOR_BUFFER_BIT); @@ -938,9 +924,7 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindVertexArray(0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); return { colors[0], diff --git a/src/utils/gl/volume_exporter.cpp b/src/utils/gl/volume_exporter.cpp index 1b02436..afef6fb 100644 --- a/src/utils/gl/volume_exporter.cpp +++ b/src/utils/gl/volume_exporter.cpp @@ -9,6 +9,8 @@ #include #include +#include "utils/utils.h" + constexpr const char* SLICE_VERTEX_SHADER = R"( #version 150 // Create two triangles that are filling the entire screen [-1, 1] @@ -68,9 +70,7 @@ void main() { )"; void VolumeExporter::write_texture_data_to_file(std::string filename) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Export"); -#endif + debug_group_action("PUSH", "Export"); const size_t num_voxels = size_t(w)*size_t(h)*size_t(d); std::vector out_data; out_data.resize(num_voxels*4); @@ -84,9 +84,7 @@ void VolumeExporter::write_texture_data_to_file(std::string filename) { real_data.resize(num_voxels); for (size_t i = 0; i < num_voxels; i++) { real_data[i] = out_data[4*i]; } NRRD::save3D (filename, real_data.data(), this->w, this->h, this->d); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void VolumeExporter::set_export_dims(GLsizei w, GLsizei h, GLsizei d) { @@ -107,9 +105,7 @@ void VolumeExporter::destroy() { } void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Init Slice"); -#endif + debug_group_action("PUSH", "Init Slice"); igl::opengl::create_shader_program(SLICE_VERTEX_SHADER, SLICE_FRAGMENT_SHADER, {}, slice.program); slice.ll_location = glGetUniformLocation(slice.program, "ll"); @@ -136,9 +132,7 @@ void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { glGenFramebuffers(1, &framebuffer); glBindTexture(GL_TEXTURE_3D, 0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } @@ -148,9 +142,7 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Export Slice"); -#endif + debug_group_action("PUSH", "Export Slice"); glUseProgram(slice.program); glBindVertexArray(empty_vao); @@ -213,9 +205,7 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec glBindVertexArray(0); glUseProgram(0); glBindTexture(GL_TEXTURE_3D, 0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); } diff --git a/src/utils/gl/volume_renderer.cpp b/src/utils/gl/volume_renderer.cpp index ce562ac..c5acd20 100644 --- a/src/utils/gl/volume_renderer.cpp +++ b/src/utils/gl/volume_renderer.cpp @@ -9,6 +9,7 @@ #include #include +#include "utils/utils.h" namespace { @@ -501,9 +502,7 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ // Generate multipass buffers if enabled -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Init VolumeRenderer Multipass"); -#endif + debug_group_action("PUSH", "Init VolumeRenderer Multipass"); for (int i = 0; i < 2; i++) { glGenTextures(1, &_gl_state.multipass.texture[i]); glBindTexture(GL_TEXTURE_2D, _gl_state.multipass.texture[i]); @@ -519,15 +518,11 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ } glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm::mat4& view_matrix, const glm::mat4& proj_matrix) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Bounding Box"); -#endif + debug_group_action("PUSH", "Render Bounding Box"); { const glm::vec4 color_transparent(0.0); @@ -584,15 +579,11 @@ void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm: glDisable(GL_CULL_FACE); } } -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ivec3& volume_dims, GLuint volume_tex, GLuint multipass_tex) { -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Render Volume TEST"); -#endif + debug_group_action("PUSH", "Render Volume TEST"); // // Setup @@ -650,9 +641,7 @@ void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ive glBindVertexArray(0); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } void VolumeRenderer::begin(const glm::ivec3& volume_dims, GLuint tex) { @@ -694,9 +683,7 @@ void VolumeRenderer::render_pass( const int current_buf = _current_multipass_buf; const int last_buf = (_current_multipass_buf+1) % 2; -#ifdef WIN32 - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Multipass render"); -#endif + debug_group_action("PUSH", "Multipass render"); GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); @@ -723,9 +710,7 @@ void VolumeRenderer::render_pass( volume_pass(light_position, _current_volume_dims, volume_tex, _gl_state.multipass.texture[last_buf]); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); -#ifdef WIN32 - glPopDebugGroup(); -#endif + debug_group_action("POP"); } diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 2a7e8b1..93f5e3e 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -189,6 +189,17 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims return true; } +void debug_group_action(const std::string& action, const std::string& message) { +#if !defined(__APPLE__) + if (action == "PUSH") { + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, message); + } + else if (action == "POP") { + glPopDebugGroup(); + } +#endif +} + void edge_endpoints(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, Eigen::MatrixXd& V1, diff --git a/src/utils/utils.h b/src/utils/utils.h index d959aad..9368039 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -42,6 +42,8 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims, std::vector &out, std::shared_ptr logger); +void debug_group_action(const std::string& action, const std::string& message=""); + void edge_endpoints(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, Eigen::MatrixXd& V1, From 0013a210df5055cd8b1d65813be1f01f6983b265 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 24 Jul 2019 06:12:45 -0400 Subject: [PATCH 13/21] Resolved MacOS bounding polygon selection and rendering issues --- src/ui/bounding_polygon_plugin.cpp | 9 ++++++++- src/ui/bounding_polygon_plugin.h | 1 - src/ui/bounding_widget_2d.cpp | 2 +- src/ui/bounding_widget_2d.h | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ui/bounding_polygon_plugin.cpp b/src/ui/bounding_polygon_plugin.cpp index 1b98368..e12e43d 100644 --- a/src/ui/bounding_polygon_plugin.cpp +++ b/src/ui/bounding_polygon_plugin.cpp @@ -60,7 +60,11 @@ void Bounding_Polygon_Menu::deinitialize() { bool Bounding_Polygon_Menu::is_2d_widget_in_focus() { double mouse_x, mouse_y; +#ifdef __APPLE__ + mouse_x = viewer->current_mouse_x, mouse_y = viewer->current_mouse_y; +#else glfwGetCursorPos(viewer->window, &mouse_x, &mouse_y); +#endif glm::vec2 p(mouse_x, mouse_y); return widget_2d.is_point_in_widget(p) && !mouse_in_popup; } @@ -371,7 +375,7 @@ bool Bounding_Polygon_Menu::post_draw() { float window_height_float = static_cast(window_height); float window_width_float = static_cast(window_width); #ifdef __APPLE__ - window_height_float /= 2, window_width_float /= 2; + window_height_float /= scaling_factor, window_width_float /= scaling_factor; #endif ImGui::SetNextWindowPos(ImVec2(0.f, (1.0-view_vsplit)*window_height_float), ImGuiSetCond_Always); ImGui::SetNextWindowSize(ImVec2(window_width_float, window_height_float*view_vsplit), ImGuiSetCond_Always); @@ -410,6 +414,9 @@ bool Bounding_Polygon_Menu::post_draw() { ImGui::SameLine(); ImVec2 cursor_pos = ImGui::GetCursorScreenPos(); +#ifdef __APPLE__ + cursor_pos.x *= (1.0+keyframe_nudge_amount); +#endif ImGui::PushItemWidth(ImGui::GetWindowWidth() - 2.f*cursor_pos.x); if(ImGui::SliderFloat("", ¤t_cut_index, static_cast(state.cage.min_index()), diff --git a/src/ui/bounding_polygon_plugin.h b/src/ui/bounding_polygon_plugin.h index 407ceb7..daa9c68 100644 --- a/src/ui/bounding_polygon_plugin.h +++ b/src/ui/bounding_polygon_plugin.h @@ -70,7 +70,6 @@ class Bounding_Polygon_Menu : public FishUIViewerPlugin { std::string save_name_error_message; int output_dims[3] = {-1, -1, -1}; bool output_preserve_aspect_ratio = true; - // bool output_export_hires_texture = true; double front_bump_amount = 0.0; double back_bump_amount = 0.0; diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index 36ca685..be1c285 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -174,7 +174,7 @@ bool Bounding_Polygon_Widget::is_point_in_widget(glm::ivec2 p) const { const glm::ivec2 p_tx(p.x, window_height - p.y); #ifdef __APPLE__ const glm::ivec2 ll = glm::ivec2(position.x, size.y); - const glm::ivec2 ur = ll + glm::ivec2(view_scaling_factor*size.y, view_scaling_factor*size.y); + const glm::ivec2 ur = ll + glm::ivec2(widget_scaling_factor*size.y, widget_scaling_factor*size.y); #else const glm::ivec2 ll = position; const glm::ivec2 ur = position + size; diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index a62a35a..010fcdd 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -39,7 +39,6 @@ class Bounding_Polygon_Widget { float split_point_size = 7.f; float center_point_size = 12.f; float selected_center_point_size = 14.f; - float view_scaling_factor = 3.f; float widget_scaling_factor = 4.5f; glm::vec4 rotation_handle_reference_color = glm::vec4(0.5f, 0.5f, 0.2f, 1.0f); From 35e12f75b2ca65109a820c7c64d0e912ce6a93c3 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 24 Jul 2019 07:15:28 -0400 Subject: [PATCH 14/21] Added dependencies for debug group functions --- src/main.cpp | 2 +- src/utils/utils.cpp | 2 +- src/utils/utils.h | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 759ee96..481f522 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ void log_opengl_debug(GLenum source, GLenum type, GLuint id, GLenum severity, "OpenGL Debug msg: Source: {}, Type: {}, Id: {}, Severity: {}, Message: {}", source, type, id, severity, std::string(message) ); -#if !defined(__APPLE__) +#ifdef WIN32 DebugBreak(); #endif } diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 93f5e3e..2350f3d 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -189,7 +189,7 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims return true; } -void debug_group_action(const std::string& action, const std::string& message) { +void debug_group_action(const std::string& action, const char* message) { #if !defined(__APPLE__) if (action == "PUSH") { glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, message); diff --git a/src/utils/utils.h b/src/utils/utils.h index 9368039..00e9096 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include #ifdef _MSC_VER @@ -42,7 +44,7 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims, std::vector &out, std::shared_ptr logger); -void debug_group_action(const std::string& action, const std::string& message=""); +void debug_group_action(const std::string& action, const char* message=""); void edge_endpoints(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, From b38e0ec12c05563f0ba2b99c8490acacfaf8dc67 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 24 Jul 2019 16:28:45 -0400 Subject: [PATCH 15/21] Added MacOS environment builds to Travis --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.travis.yml b/.travis.yml index aa86097..c15e266 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,6 +48,21 @@ matrix: compiler: gcc-7 env: - MATRIX_EVAL="export CC=gcc-7 CXX=g++-7 CONFIG=Release PYTHON=python3 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'" + - os: osx + osx_image: xcode10.2 + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1" + - os: osx + osx_image: xcode10.2 + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" + - os: osx + osx_image: xcode10.2 + compiler: clang + env: + - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'"" install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi From 246fe306a9942e80791fc378ea434cf0bd9cd1eb Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 24 Jul 2019 22:47:51 -0400 Subject: [PATCH 16/21] Modified OpenMP and Qt5 compilation settings --- .appveyor.yml | 2 +- .travis.yml | 6 +++--- CMakeLists.txt | 13 +++++++++---- src/utils/bounding_cage.h | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b57e606..ff04e40 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -36,6 +36,6 @@ after_build: - cd C:\Qt\latest\msvc2017_64\bin - windeployqt C:\projects\fish_deformation\unwind\unwind.exe - cd C:\projects\fish_deformation - - 7z a unwind.zip .\unwind\* + - 7z a unwind.zip unwind\ artifacts: - path: unwind.zip diff --git a/.travis.yml b/.travis.yml index c15e266..1b0bb5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,17 +52,17 @@ matrix: osx_image: xcode10.2 compiler: clang env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1" + - MATRIX_EVAL="export CONFIG=Release PYTHON=python3 LIBIGL_NUM_THREADS=1" - os: osx osx_image: xcode10.2 compiler: clang env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" + - MATRIX_EVAL="export CONFIG=Release PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_USE_STATIC_LIBRARY=OFF'" - os: osx osx_image: xcode10.2 compiler: clang env: - - MATRIX_EVAL="export CONFIG=Debug PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'"" + - MATRIX_EVAL="export CONFIG=Release PYTHON=python3 LIBIGL_NUM_THREADS=1 CMAKE_EXTRA='-DLIBIGL_EIGEN_VERSION=3.3.7'"" install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a92a71..24e8a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,9 @@ project(fish_deformation) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/voroffset/cmake) -set(CMAKE_PREFIX_PATH /usr/local/opt/qt/lib/cmake) - +if (APPLE) + set(CMAKE_PREFIX_PATH /usr/local/opt/qt/lib/cmake) +endif () ################################# @@ -110,8 +111,12 @@ file(GLOB CT_SRCS external/Segmentangling/ContourTree/*.cpp) set(CT_INCLUDE_DIRS external/Segmentangling/ContourTree) list(REMOVE_ITEM CT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/external/Segmentangling/ContourTree/main.cpp") add_library(contourtree STATIC ${CT_SRCS}) -# target_compile_options(contourtree PRIVATE "-fopenmp") -target_link_libraries(contourtree Qt5::Core Qt5::Widgets spdlog) +if (NOT APPLE) + target_compile_options(contourtree PRIVATE "-fopenmp") + target_link_libraries(contourtree Qt5::Core Qt5::Widgets -fopenmp spdlog) +else () + target_link_libraries(contourtree Qt5::Core Qt5::Widgets spdlog) +endif () target_include_directories(contourtree PUBLIC ${CT_INCLUDE_DIRS}) target_compile_definitions(contourtree PUBLIC CONTOUR_TREE_USE_SPDLOG) diff --git a/src/utils/bounding_cage.h b/src/utils/bounding_cage.h index 454854a..d530a0e 100644 --- a/src/utils/bounding_cage.h +++ b/src/utils/bounding_cage.h @@ -457,6 +457,7 @@ class BoundingCage { bool bump(double amount) { this->_origin += amount * this->normal(); + return true; } /// Rotate the coordinate frame counter-clockwise about the normal axis From 91116d18e4f611aa6e548ea273498bd7925c4cc7 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Thu, 25 Jul 2019 11:47:17 -0400 Subject: [PATCH 17/21] Refactored helper functions and state constants --- CMakeLists.txt | 3 ++- src/main.cpp | 6 ++---- src/ui/bounding_polygon_plugin.cpp | 16 ++++---------- src/ui/bounding_widget_2d.cpp | 26 +++++++++++------------ src/ui/bounding_widget_2d.h | 4 +++- src/ui/endpoint_selection_plugin.cpp | 10 +++------ src/ui/endpoint_selection_plugin.h | 1 - src/ui/fish_ui_viewer_plugin.cpp | 1 + src/ui/meshing_plugin.cpp | 2 +- src/ui/selection_plugin.cpp | 8 ++----- src/ui/selection_plugin.h | 2 -- src/ui/state.cpp | 10 --------- src/ui/state.h | 2 -- src/utils/gl/point_line_rendering.cpp | 16 +++++++------- src/utils/gl/selection_renderer.cpp | 16 +++++++------- src/utils/gl/volume_exporter.cpp | 12 +++++------ src/utils/gl/volume_renderer.cpp | 16 +++++++------- src/utils/utils.cpp | 30 ++++++++++++++++++++------- src/utils/utils.h | 10 +++++++-- 19 files changed, 92 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24e8a02..bc942c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,8 @@ list(FILTER UTILS_HEADER EXCLUDE REGEX cgal*) add_library(utils STATIC ${UTILS_SRCS} ${UTILS_HEADER}) set_property(TARGET utils PROPERTY CXX_STANDARD 14) set_property(TARGET utils PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(utils igl::core igl::opengl igl::cgal igl::triangle spdlog Qt5::Core Qt5::Widgets spdlog) +include_directories(external/libigl/external/glfw/include) +target_link_libraries(utils igl::core igl::opengl igl::cgal igl::triangle spdlog Qt5::Core Qt5::Widgets spdlog glfw ${GLFW_LIBRARIES}) target_include_directories(utils PUBLIC ${UTILS_INCLUDE_DIRS}) target_include_directories(utils SYSTEM PUBLIC "${PROJECT_SOURCE_DIR}/external/glm") diff --git a/src/main.cpp b/src/main.cpp index 481f522..24ce8d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "ui/endpoint_selection_plugin.h" #include "ui/bounding_polygon_plugin.h" #include "ui/state.h" +#include "utils/utils.h" #include "Logger.hpp" State _state; @@ -56,10 +57,7 @@ bool init(igl::opengl::glfw::Viewer& viewer) { ct_logger->set_level(CONTOURTREE_LOGGER_LEVEL); contourtree::Logger::setLogger(ct_logger); -#if !defined(__APPLE__) - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback(log_opengl_debug, NULL); -#endif + init_opengl_debug(); return false; } diff --git a/src/ui/bounding_polygon_plugin.cpp b/src/ui/bounding_polygon_plugin.cpp index e12e43d..266955e 100644 --- a/src/ui/bounding_polygon_plugin.cpp +++ b/src/ui/bounding_polygon_plugin.cpp @@ -59,13 +59,7 @@ void Bounding_Polygon_Menu::deinitialize() { } bool Bounding_Polygon_Menu::is_2d_widget_in_focus() { - double mouse_x, mouse_y; -#ifdef __APPLE__ - mouse_x = viewer->current_mouse_x, mouse_y = viewer->current_mouse_y; -#else - glfwGetCursorPos(viewer->window, &mouse_x, &mouse_y); -#endif - glm::vec2 p(mouse_x, mouse_y); + glm::vec2 p(viewer->current_mouse_x, viewer->current_mouse_y); return widget_2d.is_point_in_widget(p) && !mouse_in_popup; } @@ -348,7 +342,7 @@ bool Bounding_Polygon_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); int window_width, window_height; - state.get_window_size(viewer->window, &window_width, &window_height); + get_window_size(viewer->window, &window_width, &window_height); #ifdef __APPLE__ glViewport(-window_width*view_hsplit, -(1.0+view_vsplit)*window_height/scaling_factor, window_width, scaling_factor*(1.0-view_vsplit)*window_height); @@ -515,10 +509,8 @@ bool Bounding_Polygon_Menu::post_draw() { ImVec2 popup_size = ImGui::GetWindowSize(); tf_widget.post_draw(!show_save_popup /* active */); - double mouse_x, mouse_y; - glfwGetCursorPos(viewer->window, &mouse_x, &mouse_y); - bool in_window_x = (mouse_x >= popup_pos[0]) && (mouse_x <= (popup_pos[0] + popup_size[0])); - bool in_window_y = (mouse_y >= popup_pos[1]) && (mouse_y <= (popup_pos[1] + popup_size[1])); + bool in_window_x = (viewer->current_mouse_x >= popup_pos[0]) && (viewer->current_mouse_x <= (popup_pos[0] + popup_size[0])); + bool in_window_y = (viewer->current_mouse_y >= popup_pos[1]) && (viewer->current_mouse_y <= (popup_pos[1] + popup_size[1])); mouse_in_popup = (in_window_x && in_window_y); ImGui::Separator(); diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index be1c285..d66c208 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -147,7 +147,7 @@ Bounding_Polygon_Widget::Bounding_Polygon_Widget(State& state) : state(state) {} glm::vec2 Bounding_Polygon_Widget::convert_position_mainwindow_to_keyframe(const glm::vec2& p) const { #ifdef __APPLE__ glm::vec2 window_ll = glm::vec2(position.x, size.y); - glm::vec2 window_ur = window_ll + glm::vec2(widget_scaling_factor*size.y, widget_scaling_factor*size.y); + glm::vec2 window_ur = window_ll + glm::vec2(macos_widget_scaling_factor*size.y, macos_widget_scaling_factor*size.y); #else glm::vec2 window_ll = position; glm::vec2 window_ur = position + size; @@ -169,12 +169,12 @@ glm::vec2 Bounding_Polygon_Widget::convert_position_keyframe_to_ndc(const glm::v bool Bounding_Polygon_Widget::is_point_in_widget(glm::ivec2 p) const { int window_width, window_height; - state.get_window_size(viewer->window, &window_width, &window_height); + get_window_size(viewer->window, &window_width, &window_height); const glm::ivec2 p_tx(p.x, window_height - p.y); #ifdef __APPLE__ const glm::ivec2 ll = glm::ivec2(position.x, size.y); - const glm::ivec2 ur = ll + glm::ivec2(widget_scaling_factor*size.y, widget_scaling_factor*size.y); + const glm::ivec2 ur = ll + glm::ivec2(macos_widget_scaling_factor*size.y, macos_widget_scaling_factor*size.y); #else const glm::ivec2 ll = position; const glm::ivec2 ur = position + size; @@ -200,7 +200,7 @@ void Bounding_Polygon_Widget::update_selection() { }; glm::ivec2 window_size; - state.get_window_size(viewer->window, &window_size.x, &window_size.y); + get_window_size(viewer->window, &window_size.x, &window_size.y); glm::vec2 current_mouse = { viewer->current_mouse_x, window_size.y - viewer->current_mouse_y }; // In main window pixel space glm::vec2 kf_mouse = convert_position_mainwindow_to_keyframe(current_mouse); // In keyframe ndc @@ -308,7 +308,7 @@ void Bounding_Polygon_Widget::initialize(igl::opengl::glfw::Viewer* viewer, Boun bool Bounding_Polygon_Widget::mouse_move(int mouse_x, int mouse_y, bool in_focus) { glm::ivec2 window_size; - state.get_window_size(viewer->window, &window_size.x, &window_size.y); + get_window_size(viewer->window, &window_size.x, &window_size.y); mouse_state.current_position = glm::ivec2(mouse_x, mouse_y); if (!in_focus) { //!is_point_in_widget(glm::ivec2(mouse_x, mouse_y)) || @@ -426,7 +426,7 @@ bool Bounding_Polygon_Widget::mouse_move(int mouse_x, int mouse_y, bool in_focus bool Bounding_Polygon_Widget::mouse_down(int button, int modifier, bool in_focus) { glm::ivec2 window_size; - state.get_window_size(viewer->window, &window_size.x, &window_size.y); + get_window_size(viewer->window, &window_size.x, &window_size.y); bool left_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS; bool right_mouse = glfwGetMouseButton(viewer->window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS; @@ -574,7 +574,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Render the slice of the volume for this keyframe into an OpenGL texture // - debug_group_action("PUSH", "Render slice"); + push_gl_debug_group("Render slice"); { glUseProgram(plane.program); glBindVertexArray(empty_vao); @@ -611,13 +611,13 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } - debug_group_action("POP"); + pop_gl_debug_group(); // // Render the bounding-box, center, and axes into the same texture // - debug_group_action("PUSH", "Render polygon"); + push_gl_debug_group("Render polygon"); { const glm::vec2 centroid_2d = G2f(kf->centroid_2d()); const glm::vec2 r_axis = G2f(kf->right_rotated_2d()), u_axis = G2f(kf->up_rotated_2d()); @@ -644,7 +644,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // Render rotation handle if (mouse_state.is_rotate_modifier_down && in_focus) { glm::ivec2 window_size; - state.get_window_size(viewer->window, &window_size.x, &window_size.y); + get_window_size(viewer->window, &window_size.x, &window_size.y); glm::vec2 current_mouse = { viewer->current_mouse_x, window_size.y - viewer->current_mouse_y }; glm::vec2 kf_mouse = convert_position_mainwindow_to_keyframe(current_mouse); @@ -658,7 +658,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool } } } - debug_group_action("POP"); + pop_gl_debug_group(); // Restore the framebuffer and viewport glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -669,7 +669,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool // // Blit the texture we just rendered to the screen // - debug_group_action("PUSH", "Texture Blit"); + push_gl_debug_group("Texture Blit"); { int width; int height; @@ -720,7 +720,7 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool glBindVertexArray(0); glUseProgram(0); } - debug_group_action("POP"); + pop_gl_debug_group(); glEnable(GL_DEPTH_TEST); return false; diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index 010fcdd..5fd9883 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -39,7 +39,9 @@ class Bounding_Polygon_Widget { float split_point_size = 7.f; float center_point_size = 12.f; float selected_center_point_size = 14.f; - float widget_scaling_factor = 4.5f; +#ifdef __APPLE__ + float macos_widget_scaling_factor = 4.5f; // Scaling factor for widget window range on macOS +#endif glm::vec4 rotation_handle_reference_color = glm::vec4(0.5f, 0.5f, 0.2f, 1.0f); glm::vec4 rotation_handle_color = glm::vec4(0.9f, 0.9f, 0.2f, 1.0f); diff --git a/src/ui/endpoint_selection_plugin.cpp b/src/ui/endpoint_selection_plugin.cpp index df7b3be..794c5e5 100644 --- a/src/ui/endpoint_selection_plugin.cpp +++ b/src/ui/endpoint_selection_plugin.cpp @@ -115,7 +115,7 @@ void EndPoint_Selection_Menu::initialize() { old_viewport = viewer->core.viewport; int window_width, window_height; - state.get_window_size(viewer->window, &window_width, &window_height); + get_window_size(viewer->window, &window_width, &window_height); viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); if (state.dirty_flags.endpoints_dirty) { @@ -145,11 +145,7 @@ void EndPoint_Selection_Menu::deinitialize() { bool EndPoint_Selection_Menu::pre_draw() { int window_width, window_height; - state.get_window_size(viewer->window, &window_width, &window_height); -// #ifdef __APPLE__ -// window_width *= scaling_factor; -// window_height *= scaling_factor; -// #endif + get_window_size(viewer->window, &window_width, &window_height); viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); bool ret = FishUIViewerPlugin::pre_draw(); @@ -275,7 +271,7 @@ void EndPoint_Selection_Menu::debug_draw_intermediate_state() { bool EndPoint_Selection_Menu::post_draw() { bool ret = FishUIViewerPlugin::post_draw(); int window_width, window_height; - state.get_window_size(viewer->window, &window_width, &window_height); + get_window_size(viewer->window, &window_width, &window_height); viewer->core.viewport = Eigen::RowVector4f(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); int width; diff --git a/src/ui/endpoint_selection_plugin.h b/src/ui/endpoint_selection_plugin.h index a97de8c..ca6a807 100644 --- a/src/ui/endpoint_selection_plugin.h +++ b/src/ui/endpoint_selection_plugin.h @@ -31,7 +31,6 @@ class EndPoint_Selection_Menu : public FishUIViewerPlugin { Eigen::Vector4f old_viewport; - float scaling_factor = 2.f; float view_hsplit = 0.2f; bool selecting_endpoints = false; diff --git a/src/ui/fish_ui_viewer_plugin.cpp b/src/ui/fish_ui_viewer_plugin.cpp index 51e0742..09f80a9 100644 --- a/src/ui/fish_ui_viewer_plugin.cpp +++ b/src/ui/fish_ui_viewer_plugin.cpp @@ -130,6 +130,7 @@ float FishUIViewerPlugin::hidpi_scaling() { float xscale, yscale; glfwGetWindowContentScale(window, &xscale, &yscale); #ifdef __APPLE__ + // Offsets high window dpi screen resolution scaling on macOS xscale /= 2, yscale /= 2; #endif diff --git a/src/ui/meshing_plugin.cpp b/src/ui/meshing_plugin.cpp index efa9f89..79a3c49 100644 --- a/src/ui/meshing_plugin.cpp +++ b/src/ui/meshing_plugin.cpp @@ -180,7 +180,7 @@ bool Meshing_Menu::post_draw() { if (is_meshing) { int width; int height; - _state.get_window_size(viewer->window, &width, &height); + get_window_size(viewer->window, &width, &height); ImGui::SetNextWindowPos(ImVec2(0.f, 0.f), ImGuiSetCond_Always); float w = static_cast(width); float h = static_cast(height); diff --git a/src/ui/selection_plugin.cpp b/src/ui/selection_plugin.cpp index 198c7e5..b991089 100644 --- a/src/ui/selection_plugin.cpp +++ b/src/ui/selection_plugin.cpp @@ -42,7 +42,7 @@ void Selection_Menu::initialize() { target_viewport_size = { -1.f, -1.f, -1.f, -1.f }; int window_width, window_height; - _state.get_window_size(viewer->window, &window_width, &window_height); + get_window_size(viewer->window, &window_width, &window_height); const int maxDim = glm::compMax(rendering_params.volume_dimensions); const float md = static_cast(maxDim); @@ -95,11 +95,7 @@ void Selection_Menu::initialize() { void Selection_Menu::draw_selection_volume() { int window_width, window_height; - _state.get_window_size(viewer->window, &window_width, &window_height); -// #ifdef __APPLE__ -// window_width *= scaling_factor; -// window_height *= scaling_factor; -// #endif + get_window_size(viewer->window, &window_width, &window_height); Eigen::RowVector4f viewport(view_hsplit*window_width, 0, (1.0-view_hsplit)*window_width, window_height); glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); viewer->core.viewport = viewport; diff --git a/src/ui/selection_plugin.h b/src/ui/selection_plugin.h index f7feb7a..9abca9d 100644 --- a/src/ui/selection_plugin.h +++ b/src/ui/selection_plugin.h @@ -12,7 +12,6 @@ struct State; class Selection_Menu : public FishUIViewerPlugin { public: Selection_Menu(State& state); - void get_window_size(GLFWwindow* handle, int* width, int* height); void initialize(); void deinitialize(); @@ -22,7 +21,6 @@ class Selection_Menu : public FishUIViewerPlugin { private: Eigen::RowVector4f old_viewport; - float scaling_factor = 2.f; float view_hsplit = 0.2f; void draw_selection_volume(); diff --git a/src/ui/state.cpp b/src/ui/state.cpp index 61c7540..6538836 100644 --- a/src/ui/state.cpp +++ b/src/ui/state.cpp @@ -36,15 +36,6 @@ void State::LoadedVolume::preprocess_volume_texture(std::vector& byte_d ); } - -void State::get_window_size(GLFWwindow* handle, int* width, int* height) { - glfwGetWindowSize(handle, width, height); -#ifdef __APPLE__ - *width *= 2, *height *= 2; -#endif -} - - void State::load_volume_data(State::LoadedVolume& volume, std::string prefix, bool load_topology) { std::string prefix_with_path = input_metadata.output_dir + "/" + prefix; @@ -73,7 +64,6 @@ void State::load_volume_data(State::LoadedVolume& volume, std::string prefix, bo } } - void State::LoadedVolume::load_gl_volume_texture(const std::vector& byte_data) { if (byte_data.size() == 0) { return; diff --git a/src/ui/state.h b/src/ui/state.h index e8ef537..80d3f19 100644 --- a/src/ui/state.h +++ b/src/ui/state.h @@ -160,8 +160,6 @@ struct State { std::vector> endpoint_pairs; } skeleton_estimation_parameters; - - void get_window_size(GLFWwindow* handle, int* width, int* height); void load_volume_data(LoadedVolume& volume, std::string prefix, bool load_topology); BoundingCage cage; diff --git a/src/utils/gl/point_line_rendering.cpp b/src/utils/gl/point_line_rendering.cpp index 9f3be1e..9419804 100644 --- a/src/utils/gl/point_line_rendering.cpp +++ b/src/utils/gl/point_line_rendering.cpp @@ -70,7 +70,7 @@ void PointLineRenderer::destroy() { bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { - debug_group_action("PUSH", "update_polyline_3d"); + push_gl_debug_group("update_polyline_3d"); if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -95,12 +95,12 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, G glBindBuffer(GL_ARRAY_BUFFER, 0); - debug_group_action("POP"); + pop_gl_debug_group(); return true; } bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { - debug_group_action("PUSH", "update_polyline_3d"); + push_gl_debug_group("update_polyline_3d"); if (polyline_id >= _polylines.size() || polyline_id < 0) { return false; } @@ -125,13 +125,13 @@ bool PointLineRenderer::update_polyline_3d(int polyline_id, GLfloat* vertices, g glDisableVertexAttribArray(1); glBindVertexArray(0); - debug_group_action("POP"); + pop_gl_debug_group(); return true; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsizei num_vertices, PolylineStyle style) { - debug_group_action("PUSH", "add_polyline_3d"); + push_gl_debug_group("add_polyline_3d"); Polyline polyline; @@ -172,13 +172,13 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, GLfloat* colors, GLsiz _polylines.push_back(polyline); } - debug_group_action("POP"); + pop_gl_debug_group(); return polyline_id; } int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsizei num_vertices, PolylineStyle style) { - debug_group_action("PUSH", "add_polyline_3d"); + push_gl_debug_group("add_polyline_3d"); Polyline polyline; @@ -212,7 +212,7 @@ int PointLineRenderer::add_polyline_3d(GLfloat* vertices, glm::vec4 color, GLsiz _polylines.push_back(polyline); } - debug_group_action("POP"); + pop_gl_debug_group(); return polyline_id; } diff --git a/src/utils/gl/selection_renderer.cpp b/src/utils/gl/selection_renderer.cpp index e6d7a0a..640bf81 100644 --- a/src/utils/gl/selection_renderer.cpp +++ b/src/utils/gl/selection_renderer.cpp @@ -620,7 +620,7 @@ void SelectionRenderer::destroy() { } void SelectionRenderer::set_transfer_function(const std::vector &tf) { - debug_group_action("PUSH", "Update Transfer Function"); + push_gl_debug_group("Update Transfer Function"); constexpr const int TRANSFER_FUNCTION_WIDTH = 512; @@ -694,12 +694,12 @@ void SelectionRenderer::set_transfer_function(const std::vector &tf) { GL_UNSIGNED_BYTE, transfer_function_data.data()); glBindTexture(GL_TEXTURE_1D, 0); - debug_group_action("POP"); + pop_gl_debug_group(); } void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_matrix, glm::mat4 proj_matrix) { - debug_group_action("PUSH", "Render Bounding Box"); + push_gl_debug_group("Render Bounding Box"); const glm::vec4 color_transparent(0.0); @@ -759,11 +759,11 @@ void SelectionRenderer::geometry_pass(glm::mat4 model_matrix, glm::mat4 view_mat glDisable(GL_CULL_FACE); } - debug_group_action("POP"); + pop_gl_debug_group(); } void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, GLuint volume_texture) { - debug_group_action("PUSH", "Render Volume"); + push_gl_debug_group("Render Volume"); // // Setup @@ -859,7 +859,7 @@ void SelectionRenderer::volume_pass(Parameters parameters, GLuint index_texture, glBindVertexArray(0); - debug_group_action("POP"); + pop_gl_debug_group(); } glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mouse_position, GLuint index_texture, GLuint volume_texture) { @@ -868,7 +868,7 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindTexture(GL_TEXTURE_3D, index_texture); glUniform1i(_gl_state.picking_pass.uniform_location.index_volume, 4); - debug_group_action("PUSH", "Pick Volume"); + push_gl_debug_group("Pick Volume"); glBindFramebuffer(GL_FRAMEBUFFER, _gl_state.picking_pass.picking_framebuffer); glClear(GL_COLOR_BUFFER_BIT); @@ -924,7 +924,7 @@ glm::vec3 SelectionRenderer::picking_pass(Parameters parameters, glm::ivec2 mous glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindVertexArray(0); - debug_group_action("POP"); + pop_gl_debug_group(); return { colors[0], diff --git a/src/utils/gl/volume_exporter.cpp b/src/utils/gl/volume_exporter.cpp index afef6fb..463ef23 100644 --- a/src/utils/gl/volume_exporter.cpp +++ b/src/utils/gl/volume_exporter.cpp @@ -70,7 +70,7 @@ void main() { )"; void VolumeExporter::write_texture_data_to_file(std::string filename) { - debug_group_action("PUSH", "Export"); + push_gl_debug_group("Export"); const size_t num_voxels = size_t(w)*size_t(h)*size_t(d); std::vector out_data; out_data.resize(num_voxels*4); @@ -84,7 +84,7 @@ void VolumeExporter::write_texture_data_to_file(std::string filename) { real_data.resize(num_voxels); for (size_t i = 0; i < num_voxels; i++) { real_data[i] = out_data[4*i]; } NRRD::save3D (filename, real_data.data(), this->w, this->h, this->d); - debug_group_action("POP"); + pop_gl_debug_group(); } void VolumeExporter::set_export_dims(GLsizei w, GLsizei h, GLsizei d) { @@ -105,7 +105,7 @@ void VolumeExporter::destroy() { } void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { - debug_group_action("PUSH", "Init Slice"); + push_gl_debug_group("Init Slice"); igl::opengl::create_shader_program(SLICE_VERTEX_SHADER, SLICE_FRAGMENT_SHADER, {}, slice.program); slice.ll_location = glGetUniformLocation(slice.program, "ll"); @@ -132,7 +132,7 @@ void VolumeExporter::init(GLsizei w, GLsizei h, GLsizei d) { glGenFramebuffers(1, &framebuffer); glBindTexture(GL_TEXTURE_3D, 0); - debug_group_action("POP"); + pop_gl_debug_group(); } @@ -142,7 +142,7 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); - debug_group_action("PUSH", "Export Slice"); + push_gl_debug_group("Export Slice"); glUseProgram(slice.program); glBindVertexArray(empty_vao); @@ -205,7 +205,7 @@ void VolumeExporter::update(BoundingCage& cage, GLuint volume_texture, glm::ivec glBindVertexArray(0); glUseProgram(0); glBindTexture(GL_TEXTURE_3D, 0); - debug_group_action("POP"); + pop_gl_debug_group(); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); } diff --git a/src/utils/gl/volume_renderer.cpp b/src/utils/gl/volume_renderer.cpp index c5acd20..b50a2f7 100644 --- a/src/utils/gl/volume_renderer.cpp +++ b/src/utils/gl/volume_renderer.cpp @@ -502,7 +502,7 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ // Generate multipass buffers if enabled - debug_group_action("PUSH", "Init VolumeRenderer Multipass"); + push_gl_debug_group("Init VolumeRenderer Multipass"); for (int i = 0; i < 2; i++) { glGenTextures(1, &_gl_state.multipass.texture[i]); glBindTexture(GL_TEXTURE_2D, _gl_state.multipass.texture[i]); @@ -518,11 +518,11 @@ void VolumeRenderer::init(const glm::ivec2 &viewport_size, const char *fragment_ } glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); - debug_group_action("POP"); + pop_gl_debug_group(); } void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm::mat4& view_matrix, const glm::mat4& proj_matrix) { - debug_group_action("PUSH", "Render Bounding Box"); + push_gl_debug_group("Render Bounding Box"); { const glm::vec4 color_transparent(0.0); @@ -579,11 +579,11 @@ void VolumeRenderer::ray_endpoint_pass(const glm::mat4& model_matrix, const glm: glDisable(GL_CULL_FACE); } } - debug_group_action("POP"); + pop_gl_debug_group(); } void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ivec3& volume_dims, GLuint volume_tex, GLuint multipass_tex) { - debug_group_action("PUSH", "Render Volume TEST"); + push_gl_debug_group("Render Volume TEST"); // // Setup @@ -641,7 +641,7 @@ void VolumeRenderer::volume_pass(const glm::vec3& light_position, const glm::ive glBindVertexArray(0); - debug_group_action("POP"); + pop_gl_debug_group(); } void VolumeRenderer::begin(const glm::ivec3& volume_dims, GLuint tex) { @@ -683,7 +683,7 @@ void VolumeRenderer::render_pass( const int current_buf = _current_multipass_buf; const int last_buf = (_current_multipass_buf+1) % 2; - debug_group_action("PUSH", "Multipass render"); + push_gl_debug_group("Multipass render"); GLint old_viewport[4]; glGetIntegerv(GL_VIEWPORT, old_viewport); @@ -710,7 +710,7 @@ void VolumeRenderer::render_pass( volume_pass(light_position, _current_volume_dims, volume_tex, _gl_state.multipass.texture[last_buf]); glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); - debug_group_action("POP"); + pop_gl_debug_group(); } diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 2350f3d..8aa7e63 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -189,14 +189,30 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims return true; } -void debug_group_action(const std::string& action, const char* message) { +void init_opengl_debug() { #if !defined(__APPLE__) - if (action == "PUSH") { - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, message); - } - else if (action == "POP") { - glPopDebugGroup(); - } + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glDebugMessageCallback(log_opengl_debug, NULL); +#endif +} + +void push_gl_debug_group(const char* message) { +#if !defined(__APPLE__) + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, message); +#endif +} + +void pop_gl_debug_group() { +#if !defined(__APPLE__) + glPopDebugGroup(); +#endif +} + +void get_window_size(GLFWwindow* handle, int* width, int* height) { + glfwGetWindowSize(handle, width, height); +#ifdef __APPLE__ + // Provides proper scaling for window dimensions on macOS + *width *= 2, *height *= 2; #endif } diff --git a/src/utils/utils.h b/src/utils/utils.h index 00e9096..043df13 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #ifdef _MSC_VER @@ -44,7 +44,13 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims, std::vector &out, std::shared_ptr logger); -void debug_group_action(const std::string& action, const char* message=""); +void init_opengl_debug(); + +void push_gl_debug_group(const char* message); + +void pop_gl_debug_group(); + +void get_window_size(GLFWwindow* handle, int* width, int* height); void edge_endpoints(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, From ccdc39a60c388ac6dda60dd965041c8ded3fe616 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Thu, 25 Jul 2019 14:50:17 -0400 Subject: [PATCH 18/21] Added onto comments and debug helper function --- CMakeLists.txt | 1 - src/main.cpp | 2 +- src/ui/bounding_widget_2d.h | 11 ++++++++++- src/ui/fish_ui_viewer_plugin.cpp | 8 +++++++- src/utils/utils.cpp | 5 +++-- src/utils/utils.h | 3 ++- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc942c5..efb4a75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ list(FILTER UTILS_HEADER EXCLUDE REGEX cgal*) add_library(utils STATIC ${UTILS_SRCS} ${UTILS_HEADER}) set_property(TARGET utils PROPERTY CXX_STANDARD 14) set_property(TARGET utils PROPERTY CXX_STANDARD_REQUIRED ON) -include_directories(external/libigl/external/glfw/include) target_link_libraries(utils igl::core igl::opengl igl::cgal igl::triangle spdlog Qt5::Core Qt5::Widgets spdlog glfw ${GLFW_LIBRARIES}) target_include_directories(utils PUBLIC ${UTILS_INCLUDE_DIRS}) target_include_directories(utils SYSTEM PUBLIC "${PROJECT_SOURCE_DIR}/external/glm") diff --git a/src/main.cpp b/src/main.cpp index 24ce8d8..ee8f766 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ bool init(igl::opengl::glfw::Viewer& viewer) { ct_logger->set_level(CONTOURTREE_LOGGER_LEVEL); contourtree::Logger::setLogger(ct_logger); - init_opengl_debug(); + init_opengl_debug(log_opengl_debug); return false; } diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index 5fd9883..fc245b0 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -40,7 +40,16 @@ class Bounding_Polygon_Widget { float center_point_size = 12.f; float selected_center_point_size = 14.f; #ifdef __APPLE__ - float macos_widget_scaling_factor = 4.5f; // Scaling factor for widget window range on macOS + // Ensures full coverage of macOS 2D widget window over the entire area for selection and + // rendering covered by 2D widget viewer by scaling up the 2D widget size, which is many + // times smaller than usual since larger widget size values causes the widget view to zoom + // out into multiple slice views, ruining the widget display. The value of 4.5 was chosen + // as it was the minimum factor by which the diminished 2D widget size needed to be scaled + // up in order to achieve this effect. The window is 1280 pixels wide and 1132.8 pixels tall + // while the area covered by the 2D widget size is initially set at 283.2 pixels tall and + // 640 pixels wide. The y dimension of the 2D widget size (283.2 pixels) was chosen to be + // scaled up due to its more flexible smaller value, dictating the size of the scaling factor. + float macos_widget_scaling_factor = 4.5f; #endif glm::vec4 rotation_handle_reference_color = glm::vec4(0.5f, 0.5f, 0.2f, 1.0f); diff --git a/src/ui/fish_ui_viewer_plugin.cpp b/src/ui/fish_ui_viewer_plugin.cpp index 09f80a9..c747467 100644 --- a/src/ui/fish_ui_viewer_plugin.cpp +++ b/src/ui/fish_ui_viewer_plugin.cpp @@ -130,7 +130,13 @@ float FishUIViewerPlugin::hidpi_scaling() { float xscale, yscale; glfwGetWindowContentScale(window, &xscale, &yscale); #ifdef __APPLE__ - // Offsets high window dpi screen resolution scaling on macOS + // Offsets high window dpi screen resolution scaling on macOS by decreasing + // the relative scale of the application's rendered elements and text. Due to + // widespread inclusion of hidpi resolution in macOS devices, the size of the + // the application's elements was roughly four times their relative size on + // Linux platforms with the double the width and height. To get these elements + // to appear in normal resolution, the level of hidpi scaling had to be reduced + // by a factor of two both on the horizonal and vertical scales. xscale /= 2, yscale /= 2; #endif diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 8aa7e63..ab494e2 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -189,10 +189,11 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims return true; } -void init_opengl_debug() { +// void init_opengl_debug(void (*)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar *, const void *) callback) { +void init_opengl_debug(GLDEBUGPROC callback) { #if !defined(__APPLE__) glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback(log_opengl_debug, NULL); + glDebugMessageCallback(callback, NULL); #endif } diff --git a/src/utils/utils.h b/src/utils/utils.h index 043df13..16348dc 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -44,7 +44,8 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims, std::vector &out, std::shared_ptr logger); -void init_opengl_debug(); +// void init_opengl_debug(typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam) callback); +void init_opengl_debug(GLDEBUGPROC callback); void push_gl_debug_group(const char* message); From db06ce5167dac5acdd89c375f249f35e6e1a7746 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Thu, 25 Jul 2019 21:39:05 -0400 Subject: [PATCH 19/21] Modified debug helper function implementation --- src/utils/utils.cpp | 1 - src/utils/utils.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index ab494e2..107fa33 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -189,7 +189,6 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims return true; } -// void init_opengl_debug(void (*)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar *, const void *) callback) { void init_opengl_debug(GLDEBUGPROC callback) { #if !defined(__APPLE__) glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); diff --git a/src/utils/utils.h b/src/utils/utils.h index 16348dc..df4aa5a 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -44,7 +44,6 @@ bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims bool load_rawfile(const std::string& rawfilename, const Eigen::RowVector3i& dims, std::vector &out, std::shared_ptr logger); -// void init_opengl_debug(typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam) callback); void init_opengl_debug(GLDEBUGPROC callback); void push_gl_debug_group(const char* message); From 1964a44defc904fb4915fd3beaccdcb4c4cd8a88 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Mon, 29 Jul 2019 10:12:19 -0400 Subject: [PATCH 20/21] Corrected mouse coordinate discrepancies with scaling --- src/main.cpp | 2 ++ src/ui/bounding_widget_2d.cpp | 10 +++++++--- src/ui/bounding_widget_2d.h | 12 ++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ee8f766..24893b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,9 +27,11 @@ void log_opengl_debug(GLenum source, GLenum type, GLuint id, GLenum severity, if (id == 131185 || id == 7 || id == 131218) { return; } +#if !defined(__APPLE__) if (source == GL_DEBUG_SOURCE_APPLICATION) { return; } +#endif _state.logger->error( "OpenGL Debug msg: Source: {}, Type: {}, Id: {}, Severity: {}, Message: {}", source, type, id, severity, std::string(message) diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index d66c208..0a41126 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -147,7 +147,7 @@ Bounding_Polygon_Widget::Bounding_Polygon_Widget(State& state) : state(state) {} glm::vec2 Bounding_Polygon_Widget::convert_position_mainwindow_to_keyframe(const glm::vec2& p) const { #ifdef __APPLE__ glm::vec2 window_ll = glm::vec2(position.x, size.y); - glm::vec2 window_ur = window_ll + glm::vec2(macos_widget_scaling_factor*size.y, macos_widget_scaling_factor*size.y); + glm::vec2 window_ur = window_ll + glm::vec2(macos_widget_scaling_factor*size.x, macos_widget_scaling_factor*macos_widget_scaling_factor*size.y); #else glm::vec2 window_ll = position; glm::vec2 window_ur = position + size; @@ -158,6 +158,10 @@ glm::vec2 Bounding_Polygon_Widget::convert_position_mainwindow_to_keyframe(const // Convert to [-1, 1] glm::vec2 mapped_mouse = (normalized_mouse - glm::vec2(0.5f)) * 2.f; +#ifdef __APPLE__ + mapped_mouse.y *= mouse_coord_scaling_factor; +#endif + return mapped_mouse * view.zoom + view.offset; } @@ -173,8 +177,8 @@ bool Bounding_Polygon_Widget::is_point_in_widget(glm::ivec2 p) const { const glm::ivec2 p_tx(p.x, window_height - p.y); #ifdef __APPLE__ - const glm::ivec2 ll = glm::ivec2(position.x, size.y); - const glm::ivec2 ur = ll + glm::ivec2(macos_widget_scaling_factor*size.y, macos_widget_scaling_factor*size.y); + glm::vec2 ll = glm::vec2(position.x, size.y); + glm::vec2 ur = ll + glm::vec2(macos_widget_scaling_factor*size.x, macos_widget_scaling_factor*macos_widget_scaling_factor*size.y); #else const glm::ivec2 ll = position; const glm::ivec2 ur = position + size; diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index fc245b0..baccdeb 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -43,13 +43,21 @@ class Bounding_Polygon_Widget { // Ensures full coverage of macOS 2D widget window over the entire area for selection and // rendering covered by 2D widget viewer by scaling up the 2D widget size, which is many // times smaller than usual since larger widget size values causes the widget view to zoom - // out into multiple slice views, ruining the widget display. The value of 4.5 was chosen + // out into multiple slice views, ruining the widget display. The value of 2.0 was chosen // as it was the minimum factor by which the diminished 2D widget size needed to be scaled // up in order to achieve this effect. The window is 1280 pixels wide and 1132.8 pixels tall // while the area covered by the 2D widget size is initially set at 283.2 pixels tall and // 640 pixels wide. The y dimension of the 2D widget size (283.2 pixels) was chosen to be // scaled up due to its more flexible smaller value, dictating the size of the scaling factor. - float macos_widget_scaling_factor = 4.5f; + float macos_widget_scaling_factor = 2.f; + // Ensures mouse coordinates on the y scale (vertical dimension) are properly normalized to + // synchronize with y coordinates of bounding box vertices for ease of box area selection. + // When used on MacOS, the y mouse coordinates of the cursor are out of sync with the actual + // y coordinates of points in relation to the bounds of the widget view. The value of 0.8 was + // chosen since that was the scaling factor needed to correct the imbalance, as the magnitudes + // of the incorrect mouse y coordinates were 1.25 larger than they should have been. With this + // correction factor, the bounding box selection process by the user works as expected. + float mouse_coord_scaling_factor = 0.8f; #endif glm::vec4 rotation_handle_reference_color = glm::vec4(0.5f, 0.5f, 0.2f, 1.0f); From 441b95503353c92c8ab8e549ff86b5dcec0de124 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Wed, 31 Jul 2019 14:58:18 -0400 Subject: [PATCH 21/21] Addendum 1 --- src/ui/bounding_polygon_plugin.cpp | 18 ++++++++---------- src/ui/bounding_widget_2d.cpp | 20 +++++++++----------- src/ui/bounding_widget_2d.h | 8 +++----- src/ui/fish_ui_viewer_plugin.cpp | 19 +------------------ src/ui/initial_file_selection_state.cpp | 11 ++++++----- src/utils/utils.cpp | 14 +++++++++++--- src/utils/utils.h | 2 ++ 7 files changed, 40 insertions(+), 52 deletions(-) diff --git a/src/ui/bounding_polygon_plugin.cpp b/src/ui/bounding_polygon_plugin.cpp index 266955e..4a95f94 100644 --- a/src/ui/bounding_polygon_plugin.cpp +++ b/src/ui/bounding_polygon_plugin.cpp @@ -346,13 +346,12 @@ bool Bounding_Polygon_Menu::post_draw() { #ifdef __APPLE__ glViewport(-window_width*view_hsplit, -(1.0+view_vsplit)*window_height/scaling_factor, window_width, scaling_factor*(1.0-view_vsplit)*window_height); - widget_2d.position = glm::vec2(0.f, view_vsplit*window_height/(scaling_factor*scaling_factor*scaling_factor)); - widget_2d.size = glm::vec2(window_width*view_hsplit/scaling_factor, (1.0-view_vsplit)*window_height/(scaling_factor*scaling_factor)); + widget_2d.position = glm::vec2(0.f, view_vsplit*window_height/(scaling_factor*scaling_factor)); #else glViewport(0, 0, window_width, window_height); widget_2d.position = glm::vec2(0.f, view_vsplit*window_height); - widget_2d.size = glm::vec2(window_width*view_hsplit, (1.0-view_vsplit)*window_height); #endif + widget_2d.size = glm::vec2(window_width*view_hsplit, (1.0-view_vsplit)*window_height); ret = widget_2d.post_draw(state.cage.keyframe_for_index(current_cut_index), is_2d_widget_in_focus()); Eigen::Vector4f widget_3d_viewport(view_hsplit*window_width, view_vsplit*window_height, @@ -364,13 +363,12 @@ bool Bounding_Polygon_Menu::post_draw() { ret = widget_3d.post_draw_curved(G4f(widget_3d_viewport), state.cage.keyframe_for_index(current_cut_index)); } + float window_scaling_factor; + get_scaling_factor(&window_scaling_factor); ImGui::SetNextWindowBgAlpha(0.5f); - float window_height_float = static_cast(window_height); - float window_width_float = static_cast(window_width); -#ifdef __APPLE__ - window_height_float /= scaling_factor, window_width_float /= scaling_factor; -#endif + float window_height_float = static_cast(window_height/window_scaling_factor); + float window_width_float = static_cast(window_width/window_scaling_factor); ImGui::SetNextWindowPos(ImVec2(0.f, (1.0-view_vsplit)*window_height_float), ImGuiSetCond_Always); ImGui::SetNextWindowSize(ImVec2(window_width_float, window_height_float*view_vsplit), ImGuiSetCond_Always); ImGui::Begin("Select Boundary", nullptr, @@ -503,7 +501,7 @@ bool Bounding_Polygon_Menu::post_draw() { } } if (show_edit_transfer_function) { - ImGui::SetNextWindowSize(ImVec2(window_width*view_vsplit, 0), ImGuiSetCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(window_width*view_vsplit/window_scaling_factor, 0), ImGuiSetCond_FirstUseEver); ImGui::Begin("Edit Transfer Function", &show_edit_transfer_function, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); ImVec2 popup_pos = ImGui::GetWindowPos(); ImVec2 popup_size = ImGui::GetWindowSize(); @@ -610,7 +608,7 @@ bool Bounding_Polygon_Menu::post_draw() { show_save_popup = true; } if (show_save_popup) { - post_draw_save(window_width); + post_draw_save(window_width/window_scaling_factor); } ImGui::End(); diff --git a/src/ui/bounding_widget_2d.cpp b/src/ui/bounding_widget_2d.cpp index 0a41126..b55ea0d 100644 --- a/src/ui/bounding_widget_2d.cpp +++ b/src/ui/bounding_widget_2d.cpp @@ -145,13 +145,12 @@ struct BlitData { Bounding_Polygon_Widget::Bounding_Polygon_Widget(State& state) : state(state) {} glm::vec2 Bounding_Polygon_Widget::convert_position_mainwindow_to_keyframe(const glm::vec2& p) const { -#ifdef __APPLE__ - glm::vec2 window_ll = glm::vec2(position.x, size.y); - glm::vec2 window_ur = window_ll + glm::vec2(macos_widget_scaling_factor*size.x, macos_widget_scaling_factor*macos_widget_scaling_factor*size.y); +#ifdef __APPLE__ + const glm::vec2 window_ll = glm::vec2(position.x, macos_widget_scaling_factor*position.y); #else - glm::vec2 window_ll = position; - glm::vec2 window_ur = position + size; + const glm::vec2 window_ll = position; #endif + const glm::vec2 window_ur = window_ll + size; // Map mouse into [0, 1]^2 in the subwindow glm::vec2 normalized_mouse = (p - window_ll) / (window_ur - window_ll); @@ -177,12 +176,11 @@ bool Bounding_Polygon_Widget::is_point_in_widget(glm::ivec2 p) const { const glm::ivec2 p_tx(p.x, window_height - p.y); #ifdef __APPLE__ - glm::vec2 ll = glm::vec2(position.x, size.y); - glm::vec2 ur = ll + glm::vec2(macos_widget_scaling_factor*size.x, macos_widget_scaling_factor*macos_widget_scaling_factor*size.y); + const glm::vec2 ll = glm::vec2(position.x, macos_widget_scaling_factor*position.y); #else - const glm::ivec2 ll = position; - const glm::ivec2 ur = position + size; + const glm::vec2 ll = position; #endif + const glm::vec2 ur = ll + size; return p_tx.x >= ll.x && p_tx.x <= ur.x && p_tx.y >= ll.y && p_tx.y <= ur.y; } @@ -677,14 +675,14 @@ bool Bounding_Polygon_Widget::post_draw(BoundingCage::KeyFrameIterator kf, bool { int width; int height; - glfwGetWindowSize(viewer->window, &width, &height); + get_window_size(viewer->window, &width, &height); glUseProgram(blit.program); glBindVertexArray(blit.vao); glBindBuffer(GL_ARRAY_BUFFER, blit.vbo); { - glm::vec2 size_ndc = size / glm::vec2(width, height) * 2.f; + glm::vec2 size_ndc = size / glm::vec2(width, height) * glm::vec2(2.f, 1.f); glm::vec2 pos_ndc = (position / glm::vec2(width, height) - glm::vec2(0.5)) * 2.f; BlitData box_ll = { diff --git a/src/ui/bounding_widget_2d.h b/src/ui/bounding_widget_2d.h index baccdeb..99f667a 100644 --- a/src/ui/bounding_widget_2d.h +++ b/src/ui/bounding_widget_2d.h @@ -43,13 +43,11 @@ class Bounding_Polygon_Widget { // Ensures full coverage of macOS 2D widget window over the entire area for selection and // rendering covered by 2D widget viewer by scaling up the 2D widget size, which is many // times smaller than usual since larger widget size values causes the widget view to zoom - // out into multiple slice views, ruining the widget display. The value of 2.0 was chosen + // out into multiple slice views, ruining the widget display. The value of 4.0 was chosen // as it was the minimum factor by which the diminished 2D widget size needed to be scaled - // up in order to achieve this effect. The window is 1280 pixels wide and 1132.8 pixels tall - // while the area covered by the 2D widget size is initially set at 283.2 pixels tall and - // 640 pixels wide. The y dimension of the 2D widget size (283.2 pixels) was chosen to be + // up in order to achieve this effect. The y dimension of the 2D widget size was chosen to be // scaled up due to its more flexible smaller value, dictating the size of the scaling factor. - float macos_widget_scaling_factor = 2.f; + float macos_widget_scaling_factor = 4.f; // Ensures mouse coordinates on the y scale (vertical dimension) are properly normalized to // synchronize with y coordinates of bounding box vertices for ease of box area selection. // When used on MacOS, the y mouse coordinates of the cursor are out of sync with the actual diff --git a/src/ui/fish_ui_viewer_plugin.cpp b/src/ui/fish_ui_viewer_plugin.cpp index c747467..796bd5b 100644 --- a/src/ui/fish_ui_viewer_plugin.cpp +++ b/src/ui/fish_ui_viewer_plugin.cpp @@ -103,13 +103,6 @@ bool FishUIViewerPlugin::key_up(int key, int modifiers) { return ImGui::GetIO().WantCaptureKeyboard; } -void FishUIViewerPlugin::window_size(GLFWwindow* handle, int* width, int* height) { - glfwGetWindowSize(handle, width, height); -#ifdef __APPLE__ - *width *= 2; - *height *= 2; -#endif -} float FishUIViewerPlugin::pixel_ratio() { // Computes pixel ratio for hidpi devices @@ -119,7 +112,7 @@ float FishUIViewerPlugin::pixel_ratio() { glfwGetFramebufferSize(window, &buf_size[0], &buf_size[1]); int win_size[2]; - window_size(window, &win_size[0], &win_size[1]); + glfwGetWindowSize(window, &win_size[0], &win_size[1]); return static_cast(buf_size[0]) / static_cast(win_size[0]); } @@ -129,16 +122,6 @@ float FishUIViewerPlugin::hidpi_scaling() { float xscale, yscale; glfwGetWindowContentScale(window, &xscale, &yscale); -#ifdef __APPLE__ - // Offsets high window dpi screen resolution scaling on macOS by decreasing - // the relative scale of the application's rendered elements and text. Due to - // widespread inclusion of hidpi resolution in macOS devices, the size of the - // the application's elements was roughly four times their relative size on - // Linux platforms with the double the width and height. To get these elements - // to appear in normal resolution, the level of hidpi scaling had to be reduced - // by a factor of two both on the horizonal and vertical scales. - xscale /= 2, yscale /= 2; -#endif return 0.5f * (xscale + yscale); } diff --git a/src/ui/initial_file_selection_state.cpp b/src/ui/initial_file_selection_state.cpp index 5c95682..61161a1 100644 --- a/src/ui/initial_file_selection_state.cpp +++ b/src/ui/initial_file_selection_state.cpp @@ -113,8 +113,8 @@ bool Initial_File_Selection_Menu::post_draw() { ImGui::SameLine(); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.2f); if (ImGui::Button("Select##FirstScan")) { - std::string first_scan = open_image_file_dialog(); - if (first_scan.size() > 0) { + // std::string first_scan = open_image_file_dialog(); + std::string first_scan = "/Users/michaelzhou/Desktop/PtapinBMP/Plaagiotremus_tapinosoma_9.9um_2k__rec_Tra0002.bmp"; if (first_scan.size() > 0) { strcpy(first_image_path_buf, first_scan.c_str()); _state.dirty_flags.file_loading_dirty = true; fix_path(first_image_path_buf); @@ -134,8 +134,8 @@ bool Initial_File_Selection_Menu::post_draw() { ImGui::SameLine(); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.2f); if (ImGui::Button("Select##LastScan")) { - std::string last_scan = open_image_file_dialog(); - if (last_scan.size() > 0) { + // std::string last_scan = open_image_file_dialog(); + std::string last_scan = "/Users/michaelzhou/Desktop/PtapinBMP/Plaagiotremus_tapinosoma_9.9um_2k__rec_Tra1798.bmp"; if (last_scan.size() > 0) { strcpy(last_image_path_buf, last_scan.c_str()); _state.dirty_flags.file_loading_dirty = true; fix_path(last_image_path_buf); @@ -154,7 +154,8 @@ bool Initial_File_Selection_Menu::post_draw() { ImGui::SameLine(); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.2f); if (ImGui::Button("Select##Outfolder")) { - std::string folder = open_folder_dialog(); + // std::string folder = open_folder_dialog(); + std::string folder = "/Users/michaelzhou/Desktop/FishScanResults"; if (folder.size() > 0) { strcpy(output_dir_path_buf, folder.c_str()); _state.dirty_flags.file_loading_dirty = true; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 107fa33..19786c0 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -209,11 +209,19 @@ void pop_gl_debug_group() { } void get_window_size(GLFWwindow* handle, int* width, int* height) { + float window_scale; + get_scaling_factor(&window_scale); glfwGetWindowSize(handle, width, height); -#ifdef __APPLE__ // Provides proper scaling for window dimensions on macOS - *width *= 2, *height *= 2; -#endif + *width *= window_scale, *height *= window_scale; +} + +void get_scaling_factor(float* scaling) { + // int count; + // GLFWmonitor** monitors = glfwGetMonitors(&count); + // glfwGetMonitorContentScale(monitors[1], scaling, NULL); + GLFWmonitor* primary = glfwGetPrimaryMonitor(); + glfwGetMonitorContentScale(primary, scaling, NULL); } void edge_endpoints(const Eigen::MatrixXd& V, diff --git a/src/utils/utils.h b/src/utils/utils.h index df4aa5a..79d6358 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -52,6 +52,8 @@ void pop_gl_debug_group(); void get_window_size(GLFWwindow* handle, int* width, int* height); +void get_scaling_factor(float* scaling); + void edge_endpoints(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, Eigen::MatrixXd& V1,