├── .clang-format ├── .github └── workflows │ ├── linux.yml │ ├── macos.yml │ └── windows.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── deps ├── CMakeLists.txt ├── MarchingCubeCpp │ ├── CMakeLists.txt │ ├── README.md │ └── include │ │ └── MarchingCube │ │ └── MC.h ├── args │ ├── LICENSE │ ├── README.md │ └── args │ │ └── args.hxx ├── glad │ ├── CMakeLists.txt │ ├── LICENSE │ ├── include │ │ ├── KHR │ │ │ └── khrplatform.h │ │ └── glad │ │ │ └── glad.h │ └── src │ │ ├── CMakeLists.txt │ │ └── glad.c ├── imgui │ └── CMakeLists.txt ├── json │ ├── CMakeLists.txt │ ├── LICENSE.MIT │ ├── README.md │ └── include │ │ └── nlohmann │ │ └── json.hpp └── stb │ ├── CMakeLists.txt │ ├── stb_image.h │ ├── stb_image_write.h │ └── stb_impl.cpp ├── examples └── demo-app │ ├── CMakeLists.txt │ ├── demo_app.cpp │ ├── simple_dot_mesh_parser.cpp │ ├── simple_dot_mesh_parser.h │ ├── surface_mesh_io.cpp │ └── surface_mesh_io.h ├── include └── polyscope │ ├── affine_remapper.h │ ├── affine_remapper.ipp │ ├── camera_parameters.h │ ├── camera_parameters.ipp │ ├── camera_view.h │ ├── camera_view.ipp │ ├── check_invalid_values.h │ ├── color_image_quantity.h │ ├── color_management.h │ ├── color_quantity.h │ ├── color_quantity.ipp │ ├── color_render_image_quantity.h │ ├── colors.h │ ├── combining_hash_functions.h │ ├── context.h │ ├── curve_network.h │ ├── curve_network.ipp │ ├── curve_network_color_quantity.h │ ├── curve_network_quantity.h │ ├── curve_network_scalar_quantity.h │ ├── curve_network_vector_quantity.h │ ├── depth_render_image_quantity.h │ ├── disjoint_sets.h │ ├── elementary_geometry.h │ ├── file_helpers.h │ ├── floating_quantities.h │ ├── floating_quantity.h │ ├── floating_quantity_structure.h │ ├── floating_quantity_structure.ipp │ ├── fullscreen_artist.h │ ├── group.h │ ├── histogram.h │ ├── image_quantity.h │ ├── image_quantity_base.h │ ├── imgui_config.h │ ├── implicit_helpers.h │ ├── implicit_helpers.ipp │ ├── internal.h │ ├── messages.h │ ├── numeric_helpers.h │ ├── options.h │ ├── parameterization_quantity.h │ ├── parameterization_quantity.ipp │ ├── persistent_value.h │ ├── pick.h │ ├── pick.ipp │ ├── point_cloud.h │ ├── point_cloud.ipp │ ├── point_cloud_color_quantity.h │ ├── point_cloud_parameterization_quantity.h │ ├── point_cloud_quantity.h │ ├── point_cloud_scalar_quantity.h │ ├── point_cloud_vector_quantity.h │ ├── polyscope.h │ ├── quantity.h │ ├── quantity.ipp │ ├── ragged_nested_array.h │ ├── raw_color_alpha_render_image_quantity.h │ ├── raw_color_render_image_quantity.h │ ├── render │ ├── color_maps.h │ ├── colormap_defs.h │ ├── engine.h │ ├── engine.ipp │ ├── ground_plane.h │ ├── managed_buffer.h │ ├── managed_buffer.ipp │ ├── material_defs.h │ ├── materials.h │ ├── mock_opengl │ │ └── mock_gl_engine.h │ ├── opengl │ │ ├── gl_engine.h │ │ ├── gl_engine_egl.h │ │ ├── gl_engine_glfw.h │ │ ├── gl_shaders.h │ │ └── shaders │ │ │ ├── common.h │ │ │ ├── cylinder_shaders.h │ │ │ ├── gizmo_shaders.h │ │ │ ├── grid_shaders.h │ │ │ ├── ground_plane_shaders.h │ │ │ ├── histogram_shaders.h │ │ │ ├── lighting_shaders.h │ │ │ ├── ribbon_shaders.h │ │ │ ├── rules.h │ │ │ ├── sphere_shaders.h │ │ │ ├── surface_mesh_shaders.h │ │ │ ├── texture_draw_shaders.h │ │ │ ├── vector_shaders.h │ │ │ └── volume_mesh_shaders.h │ ├── shader_builder.h │ └── templated_buffers.h │ ├── render_image_quantity_base.h │ ├── scalar_image_quantity.h │ ├── scalar_quantity.h │ ├── scalar_quantity.ipp │ ├── scalar_render_image_quantity.h │ ├── scaled_value.h │ ├── screenshot.h │ ├── simple_triangle_mesh.h │ ├── simple_triangle_mesh.ipp │ ├── slice_plane.h │ ├── standardize_data_array.h │ ├── structure.h │ ├── structure.ipp │ ├── surface_color_quantity.h │ ├── surface_mesh.h │ ├── surface_mesh.ipp │ ├── surface_mesh_quantity.h │ ├── surface_parameterization_quantity.h │ ├── surface_scalar_quantity.h │ ├── surface_vector_quantity.h │ ├── texture_map_quantity.h │ ├── texture_map_quantity.ipp │ ├── transformation_gizmo.h │ ├── types.h │ ├── utilities.h │ ├── vector_quantity.h │ ├── vector_quantity.ipp │ ├── view.h │ ├── volume_grid.h │ ├── volume_grid.ipp │ ├── volume_grid_quantity.h │ ├── volume_grid_scalar_quantity.h │ ├── volume_mesh.h │ ├── volume_mesh.ipp │ ├── volume_mesh_color_quantity.h │ ├── volume_mesh_quantity.h │ ├── volume_mesh_scalar_quantity.h │ ├── volume_mesh_vector_quantity.h │ ├── weak_handle.h │ └── widget.h ├── misc ├── file2c │ └── file2cpp.c ├── format_all_macOS.sh ├── generate_colormap_constant.py └── material_images │ ├── .gitignore │ ├── bin2vector.c │ ├── concrete_seamless.jpg │ ├── image2material.cpp │ ├── imagesrgb2material.cpp │ └── render_material.blend ├── src ├── CMakeLists.txt ├── camera_parameters.cpp ├── camera_view.cpp ├── color_image_quantity.cpp ├── color_management.cpp ├── color_render_image_quantity.cpp ├── curve_network.cpp ├── curve_network_color_quantity.cpp ├── curve_network_scalar_quantity.cpp ├── curve_network_vector_quantity.cpp ├── depth_render_image_quantity.cpp ├── disjoint_sets.cpp ├── elementary_geometry.cpp ├── file_helpers.cpp ├── floating_quantity.cpp ├── floating_quantity_structure.cpp ├── fullscreen_artist.cpp ├── group.cpp ├── histogram.cpp ├── image_quantity_base.cpp ├── imgui_config.cpp ├── internal.cpp ├── marching_cubes.cpp ├── messages.cpp ├── options.cpp ├── persistent_value.cpp ├── pick.cpp ├── point_cloud.cpp ├── point_cloud_color_quantity.cpp ├── point_cloud_parameterization_quantity.cpp ├── point_cloud_scalar_quantity.cpp ├── point_cloud_vector_quantity.cpp ├── polyscope.cpp ├── quantity.cpp ├── raw_color_alpha_render_image_quantity.cpp ├── raw_color_render_image_quantity.cpp ├── render │ ├── bindata │ │ ├── bindata_candy.cpp │ │ ├── bindata_ceramic.cpp │ │ ├── bindata_clay.cpp │ │ ├── bindata_flat.cpp │ │ ├── bindata_font_cousine_regular.cpp │ │ ├── bindata_font_lato_regular.cpp │ │ ├── bindata_jade.cpp │ │ ├── bindata_mud.cpp │ │ ├── bindata_normal.cpp │ │ ├── bindata_wax.cpp │ │ └── concrete_seamless.cpp │ ├── color_maps.cpp │ ├── engine.cpp │ ├── ground_plane.cpp │ ├── initialize_backend.cpp │ ├── managed_buffer.cpp │ ├── materials.cpp │ ├── mock_opengl │ │ └── mock_gl_engine.cpp │ ├── opengl │ │ ├── gl_engine.cpp │ │ ├── gl_engine_egl.cpp │ │ ├── gl_engine_glfw.cpp │ │ └── shaders │ │ │ ├── common.cpp │ │ │ ├── cylinder_shaders.cpp │ │ │ ├── gizmo_shaders.cpp │ │ │ ├── grid_shaders.cpp │ │ │ ├── ground_plane_shaders.cpp │ │ │ ├── histogram_shaders.cpp │ │ │ ├── lighting_shaders.cpp │ │ │ ├── ribbon_shaders.cpp │ │ │ ├── rules.cpp │ │ │ ├── sphere_shaders.cpp │ │ │ ├── surface_mesh_shaders.cpp │ │ │ ├── texture_draw_shaders.cpp │ │ │ ├── vector_shaders.cpp │ │ │ └── volume_mesh_shaders.cpp │ ├── shader_builder.cpp │ └── templated_buffers.cpp ├── render_image_quantity_base.cpp ├── scalar_image_quantity.cpp ├── scalar_render_image_quantity.cpp ├── screenshot.cpp ├── simple_triangle_mesh.cpp ├── slice_plane.cpp ├── state.cpp ├── structure.cpp ├── surface_color_quantity.cpp ├── surface_mesh.cpp ├── surface_parameterization_quantity.cpp ├── surface_scalar_quantity.cpp ├── surface_vector_quantity.cpp ├── transformation_gizmo.cpp ├── utilities.cpp ├── view.cpp ├── volume_grid.cpp ├── volume_grid_scalar_quantity.cpp ├── volume_mesh.cpp ├── volume_mesh_color_quantity.cpp ├── volume_mesh_scalar_quantity.cpp ├── volume_mesh_vector_quantity.cpp ├── weak_handle.cpp └── widget.cpp └── test ├── CMakeLists.txt ├── CMakeLists.txt.in ├── include └── polyscope_test.h └── src ├── array_adaptors_test.cpp ├── basics_test.cpp ├── camera_view_test.cpp ├── combo_test.cpp ├── curve_network_test.cpp ├── floating_test.cpp ├── group_test.cpp ├── interop_and_serialization_test.cpp ├── main_test.cpp ├── misc_test.cpp ├── point_cloud_test.cpp ├── surface_mesh_test.cpp ├── volume_grid_test.cpp └── volume_mesh_test.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | AlignAfterOpenBracket: Align 3 | AlignOperands: 'true' 4 | AllowShortBlocksOnASingleLine: 'false' 5 | AllowShortIfStatementsOnASingleLine: 'true' 6 | AllowShortLoopsOnASingleLine: 'true' 7 | AlwaysBreakTemplateDeclarations: 'true' 8 | BinPackParameters: 'true' 9 | BreakBeforeBraces: Attach 10 | ColumnLimit: '120' 11 | IndentWidth: '2' 12 | KeepEmptyLinesAtTheStartOfBlocks: 'true' 13 | MaxEmptyLinesToKeep: '2' 14 | PointerAlignment: Left 15 | ReflowComments: 'true' 16 | SpacesInAngles: 'false' 17 | SpacesInParentheses: 'false' 18 | SpacesInSquareBrackets: 'false' 19 | Standard: Cpp11 20 | UseTab: Never 21 | 22 | ... 23 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: linux 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest] 14 | runs-on: ${{ matrix.os }} 15 | if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 16 | steps: 17 | - uses: actions/checkout@v1 18 | with: 19 | submodules: true 20 | 21 | - name: install packages 22 | run: sudo apt-get update && sudo apt-get install -y xorg-dev libglu1-mesa-dev xpra xserver-xorg-video-dummy freeglut3-dev 23 | 24 | - name: configure 25 | run: cd test && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON .. 26 | 27 | - name: build 28 | run: cd test/build && make 29 | 30 | - name: run test mock backend 31 | run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock 32 | 33 | - name: run test egl backend 34 | # We get memory leaks inside of EGL that I can't track down. With ASAN, this means the exit code is always nonzero, 35 | # which is indistinguishable from tests failing. The ASAN_OPTIONS=detect_leaks=0 skips checking leaks for this test 36 | # as a workaround. 37 | run: cd test/build && ASAN_OPTIONS=detect_leaks=0 ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL3_egl 38 | 39 | build_shared: 40 | strategy: 41 | matrix: 42 | os: [ubuntu-latest] 43 | runs-on: ${{ matrix.os }} 44 | if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 45 | steps: 46 | - uses: actions/checkout@v1 47 | with: 48 | submodules: true 49 | 50 | - name: install packages 51 | run: sudo apt-get update && sudo apt-get install -y xorg-dev libglu1-mesa-dev xpra xserver-xorg-video-dummy freeglut3-dev 52 | 53 | - name: configure 54 | run: cd test && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON -DPOLYSCOPE_BACKEND_OPENGL3_EGL=ON .. 55 | 56 | - name: build 57 | run: cd test/build && make 58 | 59 | - name: run test mock backend 60 | run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock 61 | 62 | - name: run test egl backend 63 | # We get memory leaks inside of EGL that I can't track down. With ASAN, this means the exit code is always nonzero, 64 | # which is indistinguishable from tests failing. The ASAN_OPTIONS=detect_leaks=0 skips checking leaks for this test 65 | # as a workaround. 66 | run: cd test/build && ASAN_OPTIONS=detect_leaks=0 ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL3_egl 67 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: macOS 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: macos-latest 12 | if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 13 | steps: 14 | - uses: actions/checkout@v1 15 | with: 16 | submodules: true 17 | 18 | - name: configure 19 | run: cd test && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON .. 20 | 21 | - name: build 22 | run: cd test/build && make 23 | 24 | - name: run test 25 | run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock 26 | 27 | build_shared: 28 | runs-on: macos-latest 29 | if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 30 | steps: 31 | - uses: actions/checkout@v1 32 | with: 33 | submodules: true 34 | 35 | - name: configure 36 | run: cd test && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON .. 37 | 38 | - name: build 39 | run: cd test/build && make 40 | 41 | - name: run test 42 | run: cd test/build && ./bin/polyscope-test --gtest_catch_exceptions=0 backend=openGL_mock 43 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: windows 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: windows-latest 12 | if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 13 | steps: 14 | - uses: actions/checkout@v1 15 | with: 16 | submodules: true 17 | 18 | - name: configure 19 | run: cd test && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON .. 20 | 21 | - name: build 22 | run: cd test/build && cmake --build "." 23 | 24 | - name: run test 25 | run: cd test/build && ./bin/Debug/polyscope-test.exe --gtest_catch_exceptions=0 backend=openGL_mock 26 | 27 | # windows shared builds: disabled for now 28 | #build_shared: 29 | #runs-on: windows-latest 30 | #if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" 31 | #steps: 32 | #- uses: actions/checkout@v1 33 | #with: 34 | #submodules: true 35 | 36 | #- name: configure 37 | #run: cd test && mkdir build && cd build && cmake -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Debug -DPOLYSCOPE_BACKEND_OPENGL3_GLFW=ON -DPOLYSCOPE_BACKEND_OPENGL_MOCK=ON .. 38 | 39 | #- name: build 40 | #run: cd test/build && cmake --build "." 41 | 42 | #- name: run test 43 | #run: cd test/build && ./bin/Debug/polyscope-test.exe --gtest_catch_exceptions=0 backend=openGL_mock 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build directories 2 | build/ 3 | build_debug/ 4 | misc/file2c/file2cpp 5 | 6 | # Editor and OS things 7 | imgui.ini 8 | .DS_Store 9 | .vscode 10 | *.swp 11 | tags 12 | *.blend1 13 | .cache 14 | compile_commands.json 15 | 16 | # Prerequisites 17 | *.d 18 | 19 | # Compiled Object files 20 | *.slo 21 | *.lo 22 | *.o 23 | *.obj 24 | 25 | # Precompiled Headers 26 | *.gch 27 | *.pch 28 | 29 | # Compiled Dynamic libraries 30 | *.so 31 | *.dylib 32 | *.dll 33 | 34 | # Fortran module files 35 | *.mod 36 | *.smod 37 | 38 | # Compiled Static libraries 39 | *.lai 40 | *.la 41 | *.a 42 | *.lib 43 | 44 | # Executables 45 | *.exe 46 | *.out 47 | *.app 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/glfw"] 2 | path = deps/glfw 3 | url = https://github.com/glfw/glfw.git 4 | branch = master 5 | [submodule "deps/imgui/imgui"] 6 | path = deps/imgui/imgui 7 | url = https://github.com/ocornut/imgui.git 8 | branch = master 9 | [submodule "deps/happly"] 10 | path = deps/happly 11 | url = https://github.com/nmwsharp/happly.git 12 | [submodule "deps/glm"] 13 | path = deps/glm 14 | url = https://github.com/g-truc/glm.git 15 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5...3.22) 2 | 3 | project(polyscope) 4 | 5 | ### Policy settings 6 | cmake_policy(SET CMP0054 NEW) # don't implicitly dereference inside if() 7 | 8 | ## Project options 9 | 10 | # Backend 11 | set(POLYSCOPE_BACKEND_OPENGL3_GLFW "ON" CACHE BOOL "Enable openGL3_glfw backend") 12 | set(POLYSCOPE_BACKEND_OPENGL_MOCK "ON" CACHE BOOL "Enable openGL_mock backend") 13 | set(POLYSCOPE_BACKEND_OPENGL3_EGL "AUTO" CACHE STRING "Enable openGL3_egl backend") # 'AUTO' means "if we're on linux and EGL.h is available" 14 | 15 | ### Do anything needed for dependencies and bring their stuff in to scope 16 | add_subdirectory(deps) 17 | 18 | ### Add things for this project 19 | add_subdirectory(src) 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2019 Nicholas Sharp and the Polyscope contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /deps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}") 2 | 3 | ## Glad 4 | if(NOT TARGET glad) 5 | add_subdirectory(glad) 6 | endif() 7 | 8 | ## GLFW 9 | if(NOT TARGET glfw) 10 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) 11 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) 12 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 13 | set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) 14 | add_subdirectory(glfw) 15 | endif() 16 | endif() 17 | 18 | ## glm 19 | if(NOT TARGET glm::glm) 20 | add_subdirectory(glm) 21 | target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL) 22 | set_target_properties(glm PROPERTIES LINKER_LANGUAGE CXX) 23 | endif() 24 | 25 | ## Imgui 26 | if(NOT TARGET imgui) 27 | add_subdirectory(imgui) 28 | endif() 29 | 30 | ## Json 31 | if(NOT TARGET nlohmann_json::nlohmann_json) 32 | add_subdirectory(json) 33 | endif() 34 | 35 | ## MarchingCube 36 | if(NOT TARGET MarchingCube::MarchingCube) 37 | add_subdirectory(MarchingCubeCpp) 38 | endif() 39 | 40 | ## stb 41 | if(NOT TARGET stb) 42 | add_subdirectory(stb) 43 | endif() 44 | -------------------------------------------------------------------------------- /deps/MarchingCubeCpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(MarchingCube INTERFACE) 2 | add_library(MarchingCube::MarchingCube ALIAS MarchingCube) 3 | 4 | target_include_directories(MarchingCube INTERFACE include) 5 | -------------------------------------------------------------------------------- /deps/MarchingCubeCpp/README.md: -------------------------------------------------------------------------------- 1 | From: https://github.com/aparis69/MarchingCubeCpp 2 | 3 | nsharp: made small changes to use glm vector class and expose an isolevel argument 4 | 5 | ## Marching Cube C++ 6 | A public domain header-only marching cube implementation in C/C++ without anything fancy. Only dependencies are cmath 7 | and vector headers. I could get rid of vector and just use plain arrays, but it is more convenient for my personal 8 | projects to keep that way, though one could easily modify the implementation. 9 | 10 | This work was motivated by this public domain implementation of the marching cube: https://github.com/nsf/mc which gives 11 | a fully runnable example in OpenGL. I thought it could be simplified and could make a good header-only library. 12 | 13 | ## Behaviour 14 | Calling MC::marching_cube will create an indexed mesh with vertices and normals defined in their own std::vector's. 15 | By default, data is allocated for vertices, normals and triangle indices. You can change the default allocated 16 | space using the function MC::setDefaultArraySizes. 17 | 18 | The output mesh represents the zero-isosurface of the input scalar field. Coordinates of the vertices will follow 19 | the grid discretization: a 128x128x128 grid will create a mesh embedded in the axis-aligned box from Vec3(0) to Vec3(128). 20 | 21 | You can optionally enable double precision by defining MC_CPP_USE_DOUBLE_PRECISION before including the header. 22 | 23 | ## Use 24 | First define MC_CPP_ENABLE and then include MC.h in your project. Example: 25 | ```cpp 26 | #define MC_IMPLEM_ENABLE 27 | #include "MC.h" 28 | 29 | int main() 30 | { 31 | // First compute a scalar field 32 | const int n = 100; 33 | MC::MC_FLOAT* field = new MC::MC_FLOAT[n * n * n]; 34 | // [...] 35 | 36 | // Compute isosurface using marching cube 37 | MC::mcMesh mesh; 38 | MC::marching_cube(field, n, n, n, mesh); 39 | 40 | // Dot whatever you want with the mesh 41 | // [...] 42 | 43 | return 0; 44 | } 45 | ``` 46 | 47 | You may find a complete example in main.cpp file. Running the program in the repository will output an obj file showing 48 | the isosurface of a single perlin noise octave. 49 | 50 | ## Licence 51 | Double Licence, whatever fits you best: Public domain or MIT License. 52 | -------------------------------------------------------------------------------- /deps/args/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2017 Taylor C. Richberger and Pavel Belikov 2 | 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /deps/glad/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /deps/glad/LICENSE: -------------------------------------------------------------------------------- 1 | This file is not distributed by the glad authors. It is a placeholder to explain the licensing situation for 2 | this subdirectory. 3 | 4 | These source files are not the "glad" project, they are outputs _generated_ by the glad project. 5 | 6 | As of Apr 13, 2020, the Readme in the glad repository https://github.com/Dav1dde/glad states that generated files 7 | can be licensed as Public Domain. Quote: "The glad generated code itself is any of Public Domain, WTFPL or CC0" 8 | -------------------------------------------------------------------------------- /deps/glad/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # Create a library for the viewer code 4 | add_library( 5 | glad 6 | glad.c 7 | ) 8 | 9 | # Are we building a shared library? 10 | get_target_property(library_type glad TYPE) 11 | if (library_type STREQUAL SHARED_LIBRARY) 12 | # If so, define the macro GLAD_API_EXPORT on the command line. 13 | target_compile_definitions(glad PUBLIC GLAD_GLAPI_EXPORT PRIVATE GLAD_GLAPI_EXPORT_BUILD) 14 | endif() 15 | 16 | target_include_directories(glad PUBLIC "../include") 17 | 18 | set_target_properties(glad PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 19 | -------------------------------------------------------------------------------- /deps/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # Maybe stop from CMAKEing in the wrong place 4 | if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR) 5 | message(FATAL_ERROR "Source and build directories cannot be the same. Go use the /build directory.") 6 | endif() 7 | 8 | 9 | # Append Wno-error to avoid compiling imgui with Werror; imgui seems to trigger lots of warnings 10 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 11 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error") 12 | 13 | # apparently, this stronger command is needed to accomplish the same in Clang 14 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") 15 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything") 16 | endif() 17 | endif() 18 | 19 | 20 | if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}") 21 | 22 | set(SRCS imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imgui_demo.cpp imgui/backends/imgui_impl_glfw.cpp imgui/backends/imgui_impl_opengl3.cpp) 23 | 24 | add_library( 25 | imgui 26 | ${SRCS} 27 | ) 28 | 29 | target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/") 30 | target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glfw/include/") 31 | target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glad/include/") 32 | 33 | target_link_libraries(imgui PRIVATE glfw) 34 | 35 | if(APPLE) 36 | # On macOS, get openGL & friends from Frameworks; do not use GLAD at all 37 | 38 | add_definitions(-DGLFW_INCLUDE_GLCOREARB) 39 | 40 | # NOTE: This code is essentially duplicated here and in polyscope/src/CMakeLists.txt 41 | 42 | # Apple is playing hardball and deprecating openGL... we'll cross that bridge when we come to it 43 | # Silence warnings about openGL deprecation 44 | add_definitions(-DGL_SILENCE_DEPRECATION) 45 | find_library(opengl_library OpenGL) 46 | target_link_libraries(imgui PRIVATE ${opengl_library}) 47 | else() 48 | # On Windows/Linux, use the glad openGL loader 49 | 50 | add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD) 51 | target_link_libraries(imgui PRIVATE glad) 52 | endif() 53 | 54 | elseif("${POLYSCOPE_BACKEND_OPENGL_MOCK}") 55 | 56 | # Disable every platform-specific thing I can find in imgui 57 | add_definitions(-DIMGUI_DISABLE_OSX_FUNCTIONS) 58 | add_definitions(-DIMGUI_DISABLE_WIN32_FUNCTIONS) 59 | add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) 60 | add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) 61 | 62 | set(SRCS imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imgui_demo.cpp) 63 | 64 | add_library( 65 | imgui 66 | ${SRCS} 67 | ) 68 | 69 | target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/") 70 | 71 | endif() 72 | 73 | 74 | target_compile_features(imgui PUBLIC cxx_std_11) 75 | 76 | set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 77 | -------------------------------------------------------------------------------- /deps/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(nlohmann_json INTERFACE) 2 | add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json) 3 | 4 | target_include_directories(nlohmann_json INTERFACE include) 5 | target_compile_features(nlohmann_json INTERFACE cxx_std_11) 6 | -------------------------------------------------------------------------------- /deps/json/LICENSE.MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2017 Niels Lohmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /deps/stb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Create a library for the viewer code 2 | add_library( 3 | stb 4 | stb_impl.cpp 5 | ) 6 | 7 | target_include_directories(stb PUBLIC ".") 8 | 9 | set_target_properties(stb PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 10 | -------------------------------------------------------------------------------- /deps/stb/stb_impl.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "stb_image.h" 3 | 4 | #define STB_IMAGE_WRITE_IMPLEMENTATION 5 | #include "stb_image_write.h" 6 | -------------------------------------------------------------------------------- /examples/demo-app/simple_dot_mesh_parser.cpp: -------------------------------------------------------------------------------- 1 | #include "simple_dot_mesh_parser.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void parseVolumeDotMesh(std::string filename, std::vector>& vertsOut, 11 | std::vector>& cellsOut) { 12 | 13 | // Open the file 14 | std::ifstream in(filename); 15 | if (!in) throw std::invalid_argument("Could not open mesh file " + filename); 16 | 17 | vertsOut.clear(); 18 | cellsOut.clear(); 19 | 20 | while (in) { 21 | 22 | std::string token; 23 | in >> token; 24 | 25 | if (token == "MeshVersionFormatted") { 26 | in >> token; // eat version number 27 | } else if (token == "Dimension") { 28 | in >> token; // eat dimension number 29 | } else if (token == "End") { 30 | return; 31 | } else if (token == "Vertices") { 32 | size_t nVerts; 33 | in >> nVerts; 34 | 35 | vertsOut.resize(nVerts); 36 | for (size_t iVert = 0; iVert < nVerts; iVert++) { 37 | double x, y, z; 38 | int value; 39 | in >> x >> y >> z >> value; 40 | vertsOut[iVert][0] = x; 41 | vertsOut[iVert][1] = y; 42 | vertsOut[iVert][2] = z; 43 | // not sure what value even does 44 | } 45 | } else if (token == "Tetrahedra") { 46 | size_t nTet; 47 | in >> nTet; 48 | for (size_t iTet = 0; iTet < nTet; iTet++) { 49 | std::array cell; 50 | int value; 51 | for (int j = 0; j < 4; j++) { 52 | int64_t ind; 53 | in >> ind; 54 | cell[j] = ind - 1; 55 | } 56 | for (int j = 4; j < 8; j++) { 57 | cell[j] = -1; 58 | } 59 | in >> value; 60 | cellsOut.push_back(cell); 61 | } 62 | } else if (token == "Hexahedra") { 63 | size_t nHex; 64 | in >> nHex; 65 | for (size_t iHex = 0; iHex < nHex; iHex++) { 66 | std::array cell; 67 | int value; 68 | for (int j = 0; j < 8; j++) { 69 | int64_t ind; 70 | in >> ind; 71 | cell[j] = ind - 1; 72 | } 73 | in >> value; 74 | cellsOut.push_back(cell); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /examples/demo-app/simple_dot_mesh_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void parseVolumeDotMesh(std::string filename, std::vector>& vertsOut, 8 | std::vector>& cellsOut); 9 | -------------------------------------------------------------------------------- /examples/demo-app/surface_mesh_io.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/utilities.h" 6 | 7 | namespace polyscope { 8 | 9 | void loadPolygonSoup_OBJ(std::string filename, std::vector>& vertexPositionsOut, 10 | std::vector>& faceIndicesOut); 11 | 12 | void loadPolygonSoup_PLY(std::string filename, std::vector>& vertexPositionsOut, 13 | std::vector>& faceIndicesOut); 14 | 15 | // Load a mesh from a general file, detecting type from filename 16 | void loadPolygonSoup(std::string filename, std::vector>& vertexPositionsOut, 17 | std::vector>& faceIndicesOut); 18 | } // namespace polyscope 19 | -------------------------------------------------------------------------------- /include/polyscope/affine_remapper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/color_maps.h" 6 | #include "polyscope/types.h" 7 | #include "polyscope/utilities.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace polyscope { 16 | 17 | 18 | inline std::string defaultColorMap(DataType type); 19 | 20 | 21 | // What is the meaningful scale of an R3 vector? 22 | // Used to scale vector lengths in a meaningful way 23 | // STANDARD: no special meaning 24 | // AMBIENT: vector represent distances in the ambient space 25 | enum class VectorType { STANDARD = 0, AMBIENT }; 26 | 27 | 28 | // Field magnitude type 29 | template 30 | struct FIELD_MAG { 31 | typedef double type; 32 | }; 33 | template <> 34 | struct FIELD_MAG { 35 | typedef float type; 36 | }; 37 | 38 | 39 | template 40 | std::pair::type, typename FIELD_MAG::type> 41 | robustMinMax(const std::vector& data, typename FIELD_MAG::type rangeEPS = 1e-12); 42 | 43 | 44 | // Map data in to the range [0,1] 45 | template 46 | class AffineRemapper { 47 | 48 | public: 49 | // Create a new remapper 50 | AffineRemapper(const std::vector& data, DataType datatype = DataType::STANDARD); 51 | AffineRemapper(T offset, typename FIELD_MAG::type scale); 52 | AffineRemapper(typename FIELD_MAG::type minVal, typename FIELD_MAG::type maxVal, 53 | DataType datatype = DataType::STANDARD); 54 | AffineRemapper(); // identity mapper 55 | 56 | // Data that defines the map as f(x) = (x - offset) * scale 57 | T offset; 58 | typename FIELD_MAG::type scale, minVal, maxVal; 59 | 60 | T map(const T& x); 61 | void setMinMax(const std::vector& data); // useful when using identity mapper but want accurate bounds 62 | std::string printBounds(); 63 | 64 | // Helpers for logic on templated fields 65 | static T one(); 66 | static T zero(); 67 | }; 68 | 69 | } // namespace polyscope 70 | 71 | 72 | #include "polyscope/affine_remapper.ipp" 73 | -------------------------------------------------------------------------------- /include/polyscope/camera_parameters.ipp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace polyscope { 4 | 5 | template 6 | CameraExtrinsics CameraExtrinsics::fromVectors(const T1& root, const T2& lookDir, const T3& upDir) { 7 | 8 | glm::vec3 rootGLM = standardizeVector3D(root); 9 | glm::vec3 lookDirGLM = standardizeVector3D(lookDir); 10 | glm::vec3 upDirGLM = standardizeVector3D(upDir); 11 | 12 | glm::mat4 E = glm::lookAt(rootGLM, rootGLM + glm::normalize(lookDirGLM), glm::normalize(upDirGLM)); 13 | return CameraExtrinsics(E); 14 | } 15 | } // namespace polyscope 16 | -------------------------------------------------------------------------------- /include/polyscope/camera_view.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | namespace polyscope { 5 | 6 | inline CameraView* registerCameraView(std::string name, CameraParameters params) { 7 | CameraView* s = new CameraView(name, params); 8 | bool success = registerStructure(s); 9 | if (!success) { 10 | safeDelete(s); 11 | } 12 | return s; 13 | } 14 | 15 | // Shorthand to get a camera view from polyscope 16 | inline CameraView* getCameraView(std::string name) { 17 | return dynamic_cast(getStructure(CameraView::structureTypeName, name)); 18 | } 19 | inline bool hasCameraView(std::string name) { return hasStructure(CameraView::structureTypeName, name); } 20 | inline void removeCameraView(std::string name, bool errorIfAbsent) { 21 | removeStructure(CameraView::structureTypeName, name, errorIfAbsent); 22 | } 23 | 24 | 25 | } // namespace polyscope 26 | -------------------------------------------------------------------------------- /include/polyscope/check_invalid_values.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | template 16 | void checkInvalidValues(std::string name, const std::vector& data) { 17 | if (options::warnForInvalidValues) { 18 | for (const T& val : data) { 19 | if (!allComponentsFinite(val)) { 20 | info("Invalid +-inf or NaN values detected in buffer: " + name); 21 | break; 22 | } 23 | } 24 | } 25 | } 26 | 27 | } // namespace polyscope -------------------------------------------------------------------------------- /include/polyscope/color_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/image_quantity_base.h" 6 | #include "polyscope/persistent_value.h" 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | 12 | class ColorImageQuantity : public ImageQuantity { 13 | 14 | // TODO this should probably inherit from ColorQuantity 15 | 16 | public: 17 | ColorImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, const std::vector& data, 18 | ImageOrigin imageOrigin); 19 | 20 | virtual void buildCustomUI() override; 21 | 22 | virtual void refresh() override; 23 | 24 | virtual std::string niceName() override; 25 | 26 | render::ManagedBuffer colors; 27 | 28 | // == Setters and getters 29 | 30 | ColorImageQuantity* setEnabled(bool newEnabled) override; 31 | 32 | ColorImageQuantity* setIsPremultiplied(bool val); 33 | bool getIsPremultiplied(); 34 | 35 | 36 | protected: 37 | std::vector colorsData; 38 | 39 | PersistentValue isPremultiplied; 40 | 41 | // rendering internals 42 | std::shared_ptr fullscreenProgram, billboardProgram; 43 | void prepareFullscreen(); 44 | void prepareBillboard(); 45 | 46 | virtual void showFullscreen() override; 47 | virtual void showInImGuiWindow() override; 48 | virtual void showInBillboard(glm::vec3 center, glm::vec3 upVec, glm::vec3 rightVec) override; 49 | }; 50 | 51 | 52 | } // namespace polyscope 53 | -------------------------------------------------------------------------------- /include/polyscope/color_management.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/utilities.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | // Helpers for management colors (but not colorschemes) 15 | 16 | namespace polyscope { 17 | 18 | // Color conversions 19 | glm::vec3 RGBtoHSV(glm::vec3 rgb); 20 | glm::vec3 HSVtoRGB(glm::vec3 hsv); 21 | 22 | // Stateful helper to color things uniquely 23 | glm::vec3 getNextUniqueColor(); 24 | 25 | } // namespace polyscope 26 | -------------------------------------------------------------------------------- /include/polyscope/color_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/persistent_value.h" 6 | #include "polyscope/polyscope.h" 7 | #include "polyscope/render/engine.h" 8 | #include "polyscope/render/managed_buffer.h" 9 | #include "polyscope/standardize_data_array.h" 10 | 11 | namespace polyscope { 12 | 13 | // Encapsulates logic which is common to all scalar quantities 14 | 15 | template 16 | class ColorQuantity { 17 | public: 18 | ColorQuantity(QuantityT& parent, const std::vector& colors); 19 | 20 | // Build the ImGUI UIs for colors 21 | void buildColorUI(); 22 | virtual void buildColorOptionsUI(); // called inside of an options menu 23 | 24 | // Add rules to rendering programs for scalars 25 | std::vector addColorRules(std::vector rules); 26 | 27 | // Set uniforms in rendering programs for scalars 28 | void setColorUniforms(render::ShaderProgram& p); 29 | 30 | template 31 | void updateData(const V& newColors); 32 | 33 | // === Members 34 | QuantityT& quantity; 35 | render::ManagedBuffer colors; 36 | 37 | // === Get/set visualization parameters 38 | 39 | // === ~DANGER~ experimental/unsupported functions 40 | 41 | protected: 42 | std::vector colorsData; 43 | 44 | // === Visualization parameters 45 | 46 | // Parameters 47 | }; 48 | 49 | } // namespace polyscope 50 | 51 | 52 | #include "polyscope/color_quantity.ipp" 53 | -------------------------------------------------------------------------------- /include/polyscope/color_quantity.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | namespace polyscope { 4 | 5 | template 6 | ColorQuantity::ColorQuantity(QuantityT& quantity_, const std::vector& colors_) 7 | : quantity(quantity_), colors(&quantity, quantity.uniquePrefix() + "colors", colorsData), colorsData(colors_) { 8 | colors.checkInvalidValues(); 9 | } 10 | 11 | template 12 | void ColorQuantity::buildColorUI() {} 13 | 14 | template 15 | void ColorQuantity::buildColorOptionsUI() {} 16 | 17 | template 18 | void ColorQuantity::setColorUniforms(render::ShaderProgram& p) {} 19 | 20 | template 21 | std::vector ColorQuantity::addColorRules(std::vector rules) { 22 | return rules; 23 | } 24 | 25 | 26 | template 27 | template 28 | void ColorQuantity::updateData(const V& newColors) { 29 | validateSize(newColors, colors.size(), "color quantity"); 30 | colors.data = standardizeVectorArray(newColors); 31 | colors.markHostBufferUpdated(); 32 | } 33 | 34 | 35 | } // namespace polyscope 36 | -------------------------------------------------------------------------------- /include/polyscope/color_render_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render_image_quantity_base.h" 6 | #include "polyscope/types.h" 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | 12 | class ColorRenderImageQuantity : public RenderImageQuantityBase { 13 | 14 | // TODO this should probably inherit from ColorQuantity 15 | 16 | public: 17 | ColorRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 18 | const std::vector& depthData, const std::vector& normalData, 19 | const std::vector& colorsData, ImageOrigin imageOrigin); 20 | 21 | virtual void draw() override; 22 | virtual void drawDelayed() override; 23 | virtual void buildCustomUI() override; 24 | 25 | virtual void refresh() override; 26 | 27 | virtual std::string niceName() override; 28 | 29 | render::ManagedBuffer colors; 30 | 31 | template 32 | void updateBuffers(const T1& depthData, const T2& normalData, const T3& colorsData); 33 | 34 | // == Setters and getters 35 | 36 | 37 | protected: 38 | // === Visualization parameters 39 | 40 | // Store the raw data 41 | std::vector colorsData; 42 | 43 | // === Render data 44 | std::shared_ptr program; 45 | 46 | // === Helpers 47 | void prepare(); 48 | }; 49 | 50 | 51 | template 52 | void ColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& normalData, const T3& colorsData) { 53 | 54 | validateSize(depthData, dimX * dimY, "color render image depth data " + name); 55 | validateSize(normalData, {dimX * dimY, 0}, "color render image normal data " + name); 56 | validateSize(colorsData, dimX * dimY, "color render image color data " + name); 57 | 58 | // standardize 59 | std::vector standardDepth(standardizeArray(depthData)); 60 | std::vector standardNormal(standardizeVectorArray(normalData)); 61 | std::vector standardColor(standardizeVectorArray(colorsData)); 62 | 63 | colors.data = standardColor; 64 | colors.markHostBufferUpdated(); 65 | 66 | updateBaseBuffers(standardDepth, standardNormal); 67 | } 68 | 69 | 70 | } // namespace polyscope 71 | -------------------------------------------------------------------------------- /include/polyscope/colors.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | namespace polyscope {} // namespace polyscope 6 | -------------------------------------------------------------------------------- /include/polyscope/combining_hash_functions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | // Some useful hash functions that should really be in the standard library 9 | 10 | // See https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set 11 | // and elsewhere 12 | 13 | // Use with something like: 14 | // std::unordered_set, polyscope::hash_combine::hash>> seenEdges; 15 | 16 | namespace polyscope { 17 | namespace hash_combine { 18 | 19 | // Copy of the usual hash capabilities from std, but in this namespace so it gets picked up for non-combining types 20 | template 21 | struct hash { 22 | size_t operator()(TT const& tt) const { return std::hash()(tt); } 23 | }; 24 | 25 | // Combinie hash values in a not-completely-evil way 26 | // (I think this is borrowed from boost) 27 | namespace { 28 | template 29 | inline void hash_combine(std::size_t& seed, T const& v) { 30 | seed ^= std::hash()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 31 | } 32 | 33 | // Recursive template code derived from Matthieu M. 34 | template ::value - 1> 35 | struct HashValueImpl { 36 | static void apply(size_t& seed, Tuple const& tuple) { 37 | HashValueImpl::apply(seed, tuple); 38 | hash_combine(seed, std::get(tuple)); 39 | } 40 | }; 41 | 42 | template 43 | struct HashValueImpl { 44 | static void apply(size_t& seed, Tuple const& tuple) { hash_combine(seed, std::get<0>(tuple)); } 45 | }; 46 | } // namespace 47 | 48 | // Hash for tuples 49 | template 50 | struct hash> { 51 | size_t operator()(std::tuple const& tt) const { 52 | size_t seed = 0; 53 | HashValueImpl>::apply(seed, tt); 54 | return seed; 55 | } 56 | }; 57 | 58 | 59 | // Hash for pairs 60 | template 61 | struct hash> { 62 | std::size_t operator()(const std::pair& x) const { 63 | size_t hVal = std::hash()(x.first); 64 | hash_combine(hVal, x.second); 65 | return hVal; 66 | } 67 | }; 68 | 69 | // Hash for arrays 70 | template 71 | struct hash> { 72 | std::size_t operator()(const std::array& arr) const { 73 | std::hash hasher; 74 | size_t result = 0; 75 | for (size_t i = 0; i < N; i++) { 76 | hash_combine(result, arr[i]); 77 | } 78 | return result; 79 | } 80 | }; 81 | 82 | }; // namespace hash_combine 83 | }; // namespace polyscope 84 | -------------------------------------------------------------------------------- /include/polyscope/curve_network_color_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/color_quantity.h" 6 | #include "polyscope/curve_network.h" 7 | 8 | namespace polyscope { 9 | 10 | // forward declaration 11 | class CurveNetworkMeshQuantity; 12 | class CurveNetwork; 13 | 14 | class CurveNetworkColorQuantity : public CurveNetworkQuantity, public ColorQuantity { 15 | public: 16 | CurveNetworkColorQuantity(std::string name, CurveNetwork& network_, std::string definedOn, 17 | const std::vector& colorValues); 18 | 19 | virtual void draw() override; 20 | virtual std::string niceName() override; 21 | 22 | virtual void refresh() override; 23 | 24 | protected: 25 | // UI internals 26 | const std::string definedOn; 27 | std::shared_ptr nodeProgram; 28 | std::shared_ptr edgeProgram; 29 | 30 | // Helpers 31 | virtual void createProgram() = 0; 32 | }; 33 | 34 | // ======================================================== 35 | // ========== Node Color ========== 36 | // ======================================================== 37 | 38 | class CurveNetworkNodeColorQuantity : public CurveNetworkColorQuantity { 39 | public: 40 | CurveNetworkNodeColorQuantity(std::string name, std::vector values_, CurveNetwork& network_); 41 | 42 | virtual void createProgram() override; 43 | 44 | void buildNodeInfoGUI(size_t vInd) override; 45 | }; 46 | 47 | // ======================================================== 48 | // ========== Edge Color ========== 49 | // ======================================================== 50 | 51 | class CurveNetworkEdgeColorQuantity : public CurveNetworkColorQuantity { 52 | public: 53 | CurveNetworkEdgeColorQuantity(std::string name, std::vector values_, CurveNetwork& network_); 54 | 55 | virtual void createProgram() override; 56 | 57 | void buildEdgeInfoGUI(size_t eInd) override; 58 | 59 | render::ManagedBuffer nodeAverageColors; 60 | void updateNodeAverageColors(); 61 | 62 | private: 63 | std::vector nodeAverageColorsData; 64 | }; 65 | 66 | } // namespace polyscope 67 | -------------------------------------------------------------------------------- /include/polyscope/curve_network_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | namespace polyscope { 9 | 10 | // Forward declare 11 | class CurveNetwork; 12 | 13 | // Extend Quantity 14 | class CurveNetworkQuantity : public QuantityS { 15 | public: 16 | CurveNetworkQuantity(std::string name, CurveNetwork& parentStructure, bool dominates = false); 17 | virtual ~CurveNetworkQuantity() {}; 18 | 19 | // Build GUI info an element 20 | virtual void buildNodeInfoGUI(size_t vInd); 21 | virtual void buildEdgeInfoGUI(size_t fInd); 22 | }; 23 | 24 | 25 | } // namespace polyscope 26 | -------------------------------------------------------------------------------- /include/polyscope/curve_network_scalar_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/curve_network.h" 7 | #include "polyscope/histogram.h" 8 | #include "polyscope/render/color_maps.h" 9 | #include "polyscope/scalar_quantity.h" 10 | 11 | namespace polyscope { 12 | 13 | class CurveNetworkScalarQuantity : public CurveNetworkQuantity, public ScalarQuantity { 14 | public: 15 | CurveNetworkScalarQuantity(std::string name, CurveNetwork& network_, std::string definedOn, 16 | const std::vector& values, DataType dataType); 17 | 18 | virtual void draw() override; 19 | virtual void buildCustomUI() override; 20 | virtual std::string niceName() override; 21 | virtual void refresh() override; 22 | 23 | protected: 24 | // UI internals 25 | const std::string definedOn; 26 | std::shared_ptr nodeProgram; 27 | std::shared_ptr edgeProgram; 28 | 29 | // Helpers 30 | virtual void createProgram() = 0; 31 | }; 32 | 33 | // ======================================================== 34 | // ========== Node Scalar ========== 35 | // ======================================================== 36 | 37 | class CurveNetworkNodeScalarQuantity : public CurveNetworkScalarQuantity { 38 | public: 39 | CurveNetworkNodeScalarQuantity(std::string name, const std::vector& values_, CurveNetwork& network_, 40 | DataType dataType_ = DataType::STANDARD); 41 | 42 | virtual void createProgram() override; 43 | 44 | void buildNodeInfoGUI(size_t nInd) override; 45 | }; 46 | 47 | 48 | // ======================================================== 49 | // ========== Edge Scalar ========== 50 | // ======================================================== 51 | 52 | class CurveNetworkEdgeScalarQuantity : public CurveNetworkScalarQuantity { 53 | public: 54 | CurveNetworkEdgeScalarQuantity(std::string name, const std::vector& values_, CurveNetwork& network_, 55 | DataType dataType_ = DataType::STANDARD); 56 | 57 | virtual void createProgram() override; 58 | 59 | void buildEdgeInfoGUI(size_t edgeInd) override; 60 | 61 | render::ManagedBuffer nodeAverageValues; 62 | void updateNodeAverageValues(); 63 | 64 | private: 65 | std::vector nodeAverageValuesData; 66 | }; 67 | 68 | 69 | } // namespace polyscope 70 | -------------------------------------------------------------------------------- /include/polyscope/curve_network_vector_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/curve_network.h" 6 | #include "polyscope/vector_quantity.h" 7 | 8 | namespace polyscope { 9 | 10 | // ==== Common base class 11 | 12 | // Represents a vector field associated with a curve network 13 | // NOTE: This intermediate class is not really necessary anymore; it is subsumed by the VectorQuantity<> classes which 14 | // serve as common bases for ALL vector types. At this point it is just kept around for backward compatibility, to not 15 | // break user code which holds a reference to it. 16 | class CurveNetworkVectorQuantity : public CurveNetworkQuantity { 17 | public: 18 | CurveNetworkVectorQuantity(std::string name, CurveNetwork& network_); 19 | 20 | // === Option accessors 21 | 22 | protected: 23 | }; 24 | 25 | 26 | // ==== R3 vectors at nodes 27 | 28 | class CurveNetworkNodeVectorQuantity : public CurveNetworkVectorQuantity, 29 | public VectorQuantity { 30 | public: 31 | CurveNetworkNodeVectorQuantity(std::string name, std::vector vectors_, CurveNetwork& network_, 32 | VectorType vectorType_ = VectorType::STANDARD); 33 | 34 | virtual void draw() override; 35 | virtual void buildCustomUI() override; 36 | virtual std::string niceName() override; 37 | virtual void refresh() override; 38 | virtual void buildNodeInfoGUI(size_t vInd) override; 39 | }; 40 | 41 | 42 | // ==== R3 vectors at edges 43 | 44 | class CurveNetworkEdgeVectorQuantity : public CurveNetworkVectorQuantity, 45 | public VectorQuantity { 46 | public: 47 | CurveNetworkEdgeVectorQuantity(std::string name, std::vector vectors_, CurveNetwork& network_, 48 | VectorType vectorType_ = VectorType::STANDARD); 49 | 50 | virtual void draw() override; 51 | virtual void buildCustomUI() override; 52 | virtual std::string niceName() override; 53 | virtual void refresh() override; 54 | virtual void buildEdgeInfoGUI(size_t vInd) override; 55 | }; 56 | 57 | 58 | } // namespace polyscope 59 | -------------------------------------------------------------------------------- /include/polyscope/depth_render_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render_image_quantity_base.h" 6 | 7 | #include 8 | 9 | namespace polyscope { 10 | 11 | class DepthRenderImageQuantity : public RenderImageQuantityBase { 12 | 13 | public: 14 | DepthRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 15 | const std::vector& depthData, const std::vector& normalData, 16 | ImageOrigin imageOrigin); 17 | 18 | virtual void draw() override; 19 | virtual void drawDelayed() override; 20 | virtual void buildCustomUI() override; 21 | 22 | virtual void refresh() override; 23 | 24 | virtual std::string niceName() override; 25 | 26 | template 27 | void updateBuffers(const T1& depthData, const T2& normalData); 28 | 29 | // == Setters and getters 30 | 31 | // set the base color of the rendered geometry 32 | DepthRenderImageQuantity* setColor(glm::vec3 newVal); 33 | glm::vec3 getColor(); 34 | 35 | 36 | protected: 37 | // === Visualization parameters 38 | PersistentValue color; 39 | 40 | 41 | // === Render data 42 | std::shared_ptr program; 43 | 44 | // === Helpers 45 | void prepare(); 46 | }; 47 | 48 | 49 | template 50 | void DepthRenderImageQuantity::updateBuffers(const T1& depthData, const T2& normalData) { 51 | 52 | validateSize(depthData, dimX * dimY, "depth render image depth data " + name); 53 | validateSize(normalData, {dimX * dimY, 0}, "depth render image normal data " + name); 54 | 55 | // standardize 56 | std::vector standardDepth(standardizeArray(depthData)); 57 | std::vector standardNormal(standardizeVectorArray(normalData)); 58 | 59 | updateBaseBuffers(standardDepth, standardNormal); 60 | } 61 | 62 | 63 | } // namespace polyscope 64 | -------------------------------------------------------------------------------- /include/polyscope/disjoint_sets.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace polyscope { 9 | 10 | class DisjointSets { 11 | public: 12 | // Constructor 13 | DisjointSets(size_t n_); 14 | 15 | // Find parent of element x 16 | size_t find(size_t x); 17 | 18 | // Union by rank 19 | void merge(size_t x, size_t y); 20 | 21 | private: 22 | // Member variables 23 | size_t n; 24 | std::vector parent; 25 | std::vector rank; 26 | }; 27 | 28 | // Slight generalization of a disjoint set, which can track "marked" sets. 29 | class MarkedDisjointSets { 30 | public: 31 | // Constructor 32 | MarkedDisjointSets(size_t n_); 33 | 34 | // Find parent of element x 35 | size_t find(size_t x); 36 | 37 | // Union by rank 38 | // If either set in the union is marked, the result is marked 39 | void merge(size_t x, size_t y); 40 | 41 | // Mark/unmark a set 42 | void mark(size_t x); 43 | void unmark(size_t x); 44 | 45 | // Check if a set is marked 46 | bool isMarked(size_t x); 47 | 48 | private: 49 | // Member variables 50 | size_t n; 51 | std::vector parent; 52 | std::vector rank; 53 | std::vector marked; 54 | }; 55 | 56 | } // namespace polyscope 57 | -------------------------------------------------------------------------------- /include/polyscope/elementary_geometry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | 12 | // Compute t \in [0,1] for a point along hte line from lineStart -- lineEnd 13 | float computeTValAlongLine(glm::vec3 queryP, glm::vec3 lineStart, glm::vec3 lineEnd); 14 | 15 | // Project a point onto a plane. planeNormal must be unit 16 | glm::vec3 projectToPlane(glm::vec3 queryP, glm::vec3 planeNormal, glm::vec3 pointOnPlane); 17 | 18 | // Compute the signed area of triangle ABC which lies in the plane give by normal 19 | float signedTriangleArea(glm::vec3 normal, glm::vec3 pA, glm::vec3 pB, glm::vec3 pC); 20 | 21 | } // namespace polyscope -------------------------------------------------------------------------------- /include/polyscope/file_helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | 8 | namespace polyscope { 9 | 10 | std::string promptForFilename(std::string filename = "out"); 11 | } 12 | -------------------------------------------------------------------------------- /include/polyscope/floating_quantities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | // A catch-all header for floating quantity includes 6 | 7 | #include "polyscope/polyscope.h" 8 | 9 | #include "polyscope/floating_quantity.h" 10 | #include "polyscope/floating_quantity_structure.h" 11 | #include "polyscope/image_quantity.h" 12 | -------------------------------------------------------------------------------- /include/polyscope/floating_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | namespace polyscope { 9 | 10 | // Extend Quantity<> to add a few extra functions 11 | class FloatingQuantity : public Quantity { 12 | public: 13 | FloatingQuantity(std::string name, Structure& parentStructure); 14 | virtual ~FloatingQuantity() {}; 15 | 16 | virtual void buildUI() override; 17 | 18 | virtual FloatingQuantity* setEnabled(bool newEnabled) = 0; 19 | }; 20 | 21 | 22 | } // namespace polyscope 23 | -------------------------------------------------------------------------------- /include/polyscope/fullscreen_artist.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "polyscope/weak_handle.h" 10 | 11 | namespace polyscope { 12 | 13 | // This is a simple class which manages global state amongs Polyscope quanties which draw directly to the whole screen. 14 | // It allows us to ensure only one is drawing to the screen at a time. 15 | 16 | 17 | class FullscreenArtist : public virtual WeakReferrable { 18 | public: 19 | FullscreenArtist(); 20 | ~FullscreenArtist(); 21 | 22 | // no copy/move (we store in the set by pointer below) 23 | FullscreenArtist(const FullscreenArtist&) = delete; 24 | FullscreenArtist(FullscreenArtist&&) = delete; 25 | FullscreenArtist& operator=(const FullscreenArtist&) = delete; 26 | FullscreenArtist& operator=(FullscreenArtist&&) = delete; 27 | 28 | 29 | // Fullscreen artists must override this function; when called it should disable the arist from drawing anything 30 | // fullscreen. 31 | virtual void disableFullscreenDrawing() = 0; 32 | }; 33 | 34 | // Ensure no artist is drawing fullscreen currently. 35 | void disableAllFullscreenArtists(); 36 | 37 | } // namespace polyscope 38 | -------------------------------------------------------------------------------- /include/polyscope/group.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "polyscope/structure.h" 10 | #include "polyscope/weak_handle.h" 11 | 12 | namespace polyscope { 13 | 14 | // Groups track collections of structures (or other groups) which can be toggled together. 15 | // 16 | // Groups are non-owning. Any contained structures continue their normal lifetime unaffected 17 | // by the group. A structure can be in 0, 1, or multiple groups, and removing it from a group 18 | // does not destroy the structure. 19 | 20 | class Group : public virtual WeakReferrable { 21 | 22 | public: 23 | // End-users should not call this constructure, use polyscope::createGroup() 24 | Group(std::string name); 25 | ~Group(); 26 | 27 | // Draw the ImGUI ui elements 28 | void buildUI(); // draws the tree node and enabled checkbox, and calls 29 | // buildUI() for all children. 30 | 31 | // Is the group being displayed (0 no, 1 some children, 2 all children) 32 | int isEnabled(); // checks ALL descendants 33 | Group* setEnabled(bool newEnabled); // updates setting for ALL descendants 34 | 35 | void addChildGroup(Group& newChild); 36 | void addChildStructure(Structure& newChild); 37 | void removeChildGroup(Group& child); 38 | void removeChildStructure(Structure& child); 39 | void unparent(); 40 | 41 | bool isRootGroup(); 42 | Group* getTopLevelGrandparent(); 43 | void appendStructuresToSkip(std::unordered_set& skipSet); 44 | void appendAllDescendants(std::unordered_set& skipSet); 45 | 46 | std::string niceName(); 47 | std::string uniqueName(); 48 | 49 | Group* setShowChildDetails(bool newVal); 50 | bool getShowChildDetails(); 51 | 52 | Group* setHideDescendantsFromStructureLists(bool newVal); 53 | bool getHideDescendantsFromStructureLists(); 54 | 55 | // === Member variables === 56 | WeakHandle parentGroup; // the parent group of this group (if null, this is a root group) 57 | const std::string name; // a name for this group, which must be unique amongst groups on `parent` 58 | std::vector> childrenGroups; 59 | std::vector> childrenStructures; 60 | 61 | protected: 62 | // = State 63 | 64 | PersistentValue showChildDetails; 65 | PersistentValue hideDescendantsFromStructureLists; 66 | 67 | // helpers 68 | void cullExpiredChildren(); // remove any child 69 | }; 70 | 71 | 72 | } // namespace polyscope 73 | -------------------------------------------------------------------------------- /include/polyscope/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/color_maps.h" 6 | #include "polyscope/render/engine.h" 7 | 8 | #include 9 | 10 | 11 | namespace polyscope { 12 | 13 | // A histogram that shows up in ImGUI window 14 | // ONEDAY: we could definitely make a better histogram widget for categorical data... 15 | 16 | class Histogram { 17 | public: 18 | Histogram(); // must call buildHistogram() with data after 19 | Histogram(std::vector& values, DataType datatype); // internally calls buildHistogram() 20 | 21 | ~Histogram(); 22 | 23 | void buildHistogram(const std::vector& values, DataType datatype); 24 | void updateColormap(const std::string& newColormap); 25 | 26 | // Width = -1 means set automatically 27 | void buildUI(float width = -1.0); 28 | 29 | std::pair colormapRange; // in DATA values, not [0,1] 30 | 31 | private: 32 | // = Helpers 33 | 34 | // Manage the actual histogram 35 | void fillBuffers(); 36 | size_t rawHistBinCount = 51; 37 | 38 | DataType dataType = DataType::STANDARD; 39 | std::vector rawHistCurveY; 40 | std::vector> rawHistCurveX; 41 | std::pair dataRange; 42 | 43 | // Render to texture 44 | void renderToTexture(); 45 | void prepare(); 46 | 47 | unsigned int texDim = 600; 48 | std::shared_ptr texture = nullptr; 49 | std::shared_ptr framebuffer = nullptr; 50 | std::shared_ptr program = nullptr; 51 | std::string colormap = "viridis"; 52 | 53 | // A few parameters which control appearance 54 | float bottomBarHeight = 0.35; 55 | float bottomBarGap = 0.1; 56 | }; 57 | 58 | 59 | }; // namespace polyscope 60 | -------------------------------------------------------------------------------- /include/polyscope/image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #pragma once 5 | 6 | #include "polyscope/polyscope.h" 7 | 8 | // catchall to include all image-related things 9 | 10 | #include "polyscope/color_image_quantity.h" 11 | #include "polyscope/color_render_image_quantity.h" 12 | #include "polyscope/depth_render_image_quantity.h" 13 | #include "polyscope/floating_quantity_structure.h" 14 | #include "polyscope/raw_color_alpha_render_image_quantity.h" 15 | #include "polyscope/raw_color_render_image_quantity.h" 16 | #include "polyscope/scalar_image_quantity.h" 17 | #include "polyscope/scalar_render_image_quantity.h" 18 | -------------------------------------------------------------------------------- /include/polyscope/image_quantity_base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | #include "polyscope/floating_quantity.h" 8 | #include "polyscope/fullscreen_artist.h" 9 | 10 | #include 11 | 12 | namespace polyscope { 13 | 14 | // forward declaration since it appears as a class member below 15 | class CameraView; 16 | 17 | class ImageQuantity : public FloatingQuantity, public FullscreenArtist { 18 | 19 | public: 20 | ImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, ImageOrigin imageOrigin); 21 | 22 | 23 | virtual void draw() override; 24 | virtual void drawDelayed() override; 25 | virtual void disableFullscreenDrawing() override; 26 | 27 | Structure& parent; 28 | 29 | // == Setters and getters 30 | 31 | size_t nPix(); 32 | 33 | void setShowFullscreen(bool newVal); 34 | bool getShowFullscreen(); 35 | 36 | void setShowInImGuiWindow(bool newVal); 37 | bool getShowInImGuiWindow(); 38 | 39 | void setShowInCameraBillboard(bool newVal); 40 | bool getShowInCameraBillboard(); 41 | 42 | void setTransparency(float newVal); 43 | float getTransparency(); 44 | 45 | protected: 46 | // === Visualization parameters 47 | const size_t dimX, dimY; 48 | ImageOrigin imageOrigin; 49 | PersistentValue transparency; 50 | PersistentValue isShowingFullscreen, isShowingImGuiWindow, isShowingCameraBillboard; 51 | CameraView* parentStructureCameraView = nullptr; // a ptr to the parent structure ONLY if it is a CameraView 52 | 53 | // render the image fullscreen 54 | virtual void showFullscreen() = 0; 55 | 56 | // build a floating imgui window showing the texture 57 | virtual void showInImGuiWindow() = 0; 58 | 59 | // render to a rectangle in 3D 60 | // note that the magnitudes of upVec matters, it determines the size of the billboard in world space 61 | // the magnitude of rightVec is ignored and scaled to match the aspect ratio of the image 62 | virtual void showInBillboard(glm::vec3 center, glm::vec3 upVec, glm::vec3 rightVec) = 0; 63 | 64 | // you MUST call this at draw time if you intend to call showInImGuiWindow() later 65 | virtual void renderIntermediate(); 66 | 67 | bool parentIsCameraView(); 68 | void buildImageUI(); 69 | void buildImageOptionsUI(); 70 | }; 71 | 72 | } // namespace polyscope 73 | -------------------------------------------------------------------------------- /include/polyscope/imgui_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include "imgui.h" 8 | 9 | 10 | namespace polyscope { 11 | 12 | // Default implementations of callbacks to set ImGui style / fonts 13 | void configureImGuiStyle(); 14 | std::tuple prepareImGuiFonts(); 15 | 16 | } // namespace polyscope 17 | -------------------------------------------------------------------------------- /include/polyscope/internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | 9 | namespace polyscope { 10 | 11 | // forward declaration 12 | class FloatingQuantityStructure; 13 | 14 | 15 | namespace internal { 16 | 17 | 18 | // == Various nitty-gritty internal details of Polyscope, which end users certainly should not touch or depend on. 19 | 20 | // Get a unique identifier 21 | uint64_t getNextUniqueID(); 22 | 23 | // track various fire-once warnings 24 | extern bool& pointCloudEfficiencyWarningReported; 25 | 26 | // global members 27 | extern FloatingQuantityStructure*& globalFloatingQuantityStructure; 28 | 29 | } // namespace internal 30 | } // namespace polyscope 31 | -------------------------------------------------------------------------------- /include/polyscope/messages.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace polyscope { 8 | 9 | // == Register various kinds of messages 10 | 11 | // General details, things you would print to stdout. For now, that's exactly what it does 12 | void info(std::string message); // default verbosityLevel = 0 13 | void info(int verbosityLevel, std::string message); // only printed if verbosity > vebosityLevel 14 | 15 | // Non-fatal warnings. Warnings with the same base message are batched together, so the UI doesn't get completely 16 | // overwhelmed if you call this in a dense loop. 17 | void warning(std::string baseMessage, std::string detailMessage = ""); 18 | 19 | // Errors which are certainly big problems, and we may or may not be able to recover from. Blocks the UI 20 | void error(std::string message); 21 | 22 | // Errors which are so bad we won't even try to recover from them. Displays to the user before exiting the program. 23 | // Internally used for uncaught exceptions. 24 | void terminatingError(std::string message); 25 | 26 | // Wrapper used by polyscope to throw exceptions 27 | void exception(std::string message); 28 | 29 | // Process any warnings that have accumulated, showing them to the user and clearing the queue. 30 | void showDelayedWarnings(); 31 | void clearMessages(); 32 | } // namespace polyscope 33 | -------------------------------------------------------------------------------- /include/polyscope/parameterization_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/persistent_value.h" 6 | #include "polyscope/polyscope.h" 7 | #include "polyscope/render/engine.h" 8 | #include "polyscope/render/managed_buffer.h" 9 | #include "polyscope/scaled_value.h" 10 | #include "polyscope/standardize_data_array.h" 11 | 12 | namespace polyscope { 13 | 14 | // Encapsulates logic which is common to all scalar quantities 15 | 16 | template 17 | class ParameterizationQuantity { 18 | public: 19 | ParameterizationQuantity(QuantityT& quantity, const std::vector& coords_, ParamCoordsType type_, 20 | ParamVizStyle style_); 21 | 22 | void buildParameterizationUI(); 23 | virtual void buildParameterizationOptionsUI(); // called inside of an options menu 24 | 25 | template 26 | void updateCoords(const V& newCoords); 27 | 28 | // === Members 29 | QuantityT& quantity; 30 | 31 | 32 | // Wrapper around the actual buffers of data stored in the class. 33 | // Interaction with the data (updating it on CPU or GPU side, accessing it, etc) happens through this wrapper. 34 | render::ManagedBuffer coords; 35 | render::ManagedBuffer islandLabels; // only optionally populated. should be integers. 36 | 37 | const ParamCoordsType coordsType; 38 | 39 | // === Get/set visualization parameters 40 | 41 | // The color map 42 | 43 | // What visualization scheme to use 44 | QuantityT* setStyle(ParamVizStyle newStyle); 45 | ParamVizStyle getStyle(); 46 | 47 | // Colors for checkers 48 | QuantityT* setCheckerColors(std::pair colors); 49 | std::pair getCheckerColors(); 50 | 51 | // Colors for checkers 52 | QuantityT* setGridColors(std::pair colors); 53 | std::pair getGridColors(); 54 | 55 | // The size of checkers / stripes 56 | QuantityT* setCheckerSize(double newVal); 57 | double getCheckerSize(); 58 | 59 | // Color map for radial visualization 60 | QuantityT* setColorMap(std::string val); 61 | std::string getColorMap(); 62 | 63 | // Darkness for checkers (etc) 64 | QuantityT* setAltDarkness(double newVal); 65 | double getAltDarkness(); 66 | 67 | // === Helpers for rendering 68 | std::vector addParameterizationRules(std::vector rules); 69 | void fillParameterizationBuffers(render::ShaderProgram& p); 70 | void setParameterizationUniforms(render::ShaderProgram& p); 71 | 72 | protected: 73 | // Raw storage for the data. You should only interact with this via the managed buffer above 74 | std::vector coordsData; 75 | std::vector islandLabelsData; 76 | bool islandLabelsPopulated = false; 77 | 78 | // === Visualization parameters 79 | 80 | // Parameters 81 | PersistentValue checkerSize; 82 | PersistentValue vizStyle; 83 | PersistentValue checkColor1, checkColor2; // for checker (two colors to use) 84 | PersistentValue gridLineColor, gridBackgroundColor; // for GRID (two colors to use) 85 | PersistentValue altDarkness; 86 | PersistentValue cMap; 87 | float localRot = 0.; // for LOCAL (angular shift, in radians) 88 | 89 | // helpers 90 | bool haveIslandLabels(); 91 | }; 92 | 93 | } // namespace polyscope 94 | 95 | 96 | #include "polyscope/parameterization_quantity.ipp" 97 | -------------------------------------------------------------------------------- /include/polyscope/pick.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "polyscope/utilities.h" 10 | #include "polyscope/weak_handle.h" 11 | 12 | namespace polyscope { 13 | 14 | // Forward decls 15 | class Structure; 16 | 17 | // == Main query 18 | 19 | // Pick queries test a screen location in the rendered viewport, and return a variety of info about what is underneath 20 | // the pixel at that point, including what structure is under the cursor, and the scene depth and color. 21 | // 22 | // This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickResult) to get 23 | // structure-specific info, like which vertex/face was clicked on. 24 | 25 | // Return type for pick queries 26 | struct PickResult { 27 | bool isHit = false; 28 | Structure* structure = nullptr; 29 | WeakHandle structureHandle; // same as .structure, but with lifetime tracking 30 | std::string structureType = ""; 31 | std::string structureName = ""; 32 | glm::vec2 screenCoords; 33 | glm::ivec2 bufferInds; 34 | glm::vec3 position; 35 | float depth; 36 | uint64_t localIndex = INVALID_IND_64; 37 | }; 38 | 39 | // Query functions to evaluate a pick. 40 | // Internally, these do a render pass to populate relevant information, then query the resulting buffers. 41 | PickResult pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates 42 | PickResult pickAtBufferInds(glm::ivec2 bufferInds); // takes indices into render buffer 43 | 44 | 45 | // == Stateful picking: track and update a current selection 46 | 47 | // Get/Set the "selected" item, if there is one 48 | PickResult getSelection(); 49 | void setSelection(PickResult newPick); 50 | void resetSelection(); 51 | bool haveSelection(); 52 | void resetSelectionIfStructure(Structure* s); // If something from this structure is selected, clear the selection 53 | // (useful if a structure is being deleted) 54 | 55 | namespace pick { 56 | 57 | // Old, deprecated picking API. Use the above functions instead. 58 | // Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such 59 | // that 0 is the first index as returned from requestPickBufferRange()) 60 | std::pair pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates 61 | std::pair pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer 62 | std::pair evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates. 63 | 64 | 65 | // == Helpers 66 | 67 | // Set up picking (internal) 68 | // Called by a structure to figure out what data it should render to the pick buffer. 69 | // Request 'count' contiguous indices for drawing a pick buffer. The return value is the start of the range. 70 | uint64_t requestPickBufferRange(Structure* requestingStructure, uint64_t count); 71 | 72 | // Convert between global pick indexing for the whole program, and local per-structure pick indexing 73 | std::pair globalIndexToLocal(uint64_t globalInd); 74 | uint64_t localIndexToGlobal(std::pair localPick); 75 | 76 | // Convert indices to float3 color and back 77 | // Structures will want to use these to fill their pick buffers 78 | inline glm::vec3 indToVec(uint64_t globalInd); 79 | inline uint64_t vecToInd(glm::vec3 vec); 80 | 81 | } // namespace pick 82 | } // namespace polyscope 83 | 84 | #include "polyscope/pick.ipp" 85 | -------------------------------------------------------------------------------- /include/polyscope/pick.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | namespace polyscope { 6 | namespace pick { 7 | 8 | // Constant for bit-bashing functions below 9 | // single-precision floats always have at least 22 bits of integer mantissa, and 22*3 > 64, so we can safely store 64 10 | // bit integer quantities like size_t usually is in a vec3 11 | const uint64_t bitsForPickPacking = 22; 12 | // const int bitsForPickPacking = 7; // useful for testing, makes pick coloring visually distingushable 13 | 14 | inline glm::vec3 indToVec(size_t globalInd) { 15 | 16 | // Can comfortably fit a 22 bit integer exactly in a single precision float 17 | uint64_t factor = 1 << bitsForPickPacking; 18 | uint64_t mask = factor - 1; 19 | double factorF = factor; 20 | 21 | uint64_t low = globalInd & mask; 22 | globalInd = globalInd >> bitsForPickPacking; 23 | uint64_t med = globalInd & mask; 24 | globalInd = globalInd >> bitsForPickPacking; 25 | uint64_t high = globalInd; 26 | 27 | return glm::vec3{static_cast(low) / factorF, static_cast(med) / factorF, 28 | static_cast(high) / factorF}; 29 | } 30 | inline uint64_t vecToInd(glm::vec3 vec) { 31 | 32 | uint64_t factor = 1 << bitsForPickPacking; 33 | double factorF = factor; 34 | 35 | uint64_t low = static_cast(factorF * vec.x); 36 | uint64_t med = static_cast(factorF * vec.y); 37 | uint64_t high = static_cast(factorF * vec.z); 38 | 39 | // Debug check 40 | if (low != (factorF * vec.x) || med != (factorF * vec.y) || high != (factorF * vec.z)) { 41 | // throw std::logic_error("Float to index conversion failed, bad value in float."); 42 | // occasionally we get weird data back in unusually cases like clicking right on border or multiple monitors... 43 | // maybe one day we can debug it. 44 | return 0; 45 | } 46 | 47 | uint64_t ind = (high << (2 * bitsForPickPacking)) + (med << bitsForPickPacking) + low; 48 | return ind; 49 | } 50 | 51 | } // namespace pick 52 | } // namespace polyscope 53 | -------------------------------------------------------------------------------- /include/polyscope/point_cloud_color_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/color_quantity.h" 7 | #include "polyscope/histogram.h" 8 | #include "polyscope/point_cloud.h" 9 | #include "polyscope/point_cloud_quantity.h" 10 | 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | class PointCloudColorQuantity : public PointCloudQuantity, public ColorQuantity { 16 | public: 17 | PointCloudColorQuantity(std::string name, const std::vector& values, PointCloud& pointCloud_); 18 | 19 | virtual void draw() override; 20 | 21 | virtual void buildPickUI(size_t ind) override; 22 | virtual void refresh() override; 23 | 24 | virtual std::string niceName() override; 25 | 26 | // === Members 27 | 28 | protected: 29 | void createPointProgram(); 30 | 31 | std::shared_ptr pointProgram; 32 | }; 33 | 34 | 35 | } // namespace polyscope 36 | -------------------------------------------------------------------------------- /include/polyscope/point_cloud_parameterization_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/parameterization_quantity.h" 6 | #include "polyscope/point_cloud.h" 7 | #include "polyscope/point_cloud_quantity.h" 8 | 9 | #include 10 | 11 | namespace polyscope { 12 | 13 | class PointCloudParameterizationQuantity : public PointCloudQuantity, 14 | public ParameterizationQuantity { 15 | public: 16 | PointCloudParameterizationQuantity(std::string name, PointCloud& cloud_, const std::vector& coords_, 17 | ParamCoordsType type_, ParamVizStyle style_); 18 | 19 | virtual void draw() override; 20 | virtual void buildCustomUI() override; 21 | virtual void buildPickUI(size_t ind) override; 22 | virtual void refresh() override; 23 | virtual std::string niceName() override; 24 | 25 | 26 | protected: 27 | std::shared_ptr program; 28 | 29 | // Helpers 30 | void createProgram(); 31 | void fillCoordBuffers(render::ShaderProgram& p); 32 | }; 33 | 34 | 35 | } // namespace polyscope 36 | -------------------------------------------------------------------------------- /include/polyscope/point_cloud_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | namespace polyscope { 9 | 10 | // Forward delcare point cloud 11 | class PointCloud; 12 | 13 | // Extend Quantity to add a few extra functions 14 | class PointCloudQuantity : public QuantityS { 15 | public: 16 | PointCloudQuantity(std::string name, PointCloud& parentStructure, bool dominates = false); 17 | virtual ~PointCloudQuantity() {}; 18 | 19 | // Build GUI info about a point 20 | virtual void buildInfoGUI(size_t pointInd); 21 | }; 22 | 23 | 24 | } // namespace polyscope 25 | -------------------------------------------------------------------------------- /include/polyscope/point_cloud_scalar_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/histogram.h" 7 | #include "polyscope/point_cloud.h" 8 | #include "polyscope/render/color_maps.h" 9 | #include "polyscope/scalar_quantity.h" 10 | 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | class PointCloudScalarQuantity : public PointCloudQuantity, public ScalarQuantity { 16 | 17 | public: 18 | PointCloudScalarQuantity(std::string name, const std::vector& values, PointCloud& pointCloud_, 19 | DataType dataType); 20 | 21 | virtual void draw() override; 22 | virtual void buildCustomUI() override; 23 | 24 | virtual void buildPickUI(size_t ind) override; 25 | virtual void refresh() override; 26 | 27 | virtual std::string niceName() override; 28 | 29 | protected: 30 | void createProgram(); 31 | 32 | std::shared_ptr pointProgram; 33 | }; 34 | 35 | 36 | } // namespace polyscope 37 | -------------------------------------------------------------------------------- /include/polyscope/point_cloud_vector_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/point_cloud.h" 6 | #include "polyscope/vector_quantity.h" 7 | 8 | namespace polyscope { 9 | 10 | // Represents a general vector field associated with a point cloud 11 | class PointCloudVectorQuantity : public PointCloudQuantity, public VectorQuantity { 12 | 13 | public: 14 | PointCloudVectorQuantity(std::string name, std::vector vectors, PointCloud& pointCloud_, 15 | VectorType vectorType_ = VectorType::STANDARD); 16 | 17 | virtual void draw() override; 18 | virtual void buildCustomUI() override; 19 | virtual void buildPickUI(size_t ind) override; 20 | virtual std::string niceName() override; 21 | virtual void refresh() override; 22 | }; 23 | 24 | } // namespace polyscope 25 | -------------------------------------------------------------------------------- /include/polyscope/quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/persistent_value.h" 6 | 7 | #include "polyscope/render/managed_buffer.h" 8 | 9 | #include 10 | 11 | namespace polyscope { 12 | 13 | // A 'quantity' (in Polyscope terminology) is data which is associated with a structure; any structure might have many 14 | // quantities. For instance a mesh structure might have a scalar quantity associated with it, or a point cloud might 15 | // have a vector field quantity associated with it. 16 | 17 | // forward decalaration 18 | class Structure; 19 | 20 | // === General Quantities 21 | // (subclasses could be a structure-specific quantity or a floating quantity) 22 | 23 | class Quantity : public render::ManagedBufferRegistry { 24 | 25 | public: 26 | Quantity(std::string name, Structure& parentStructure); 27 | virtual ~Quantity(); 28 | 29 | // Draw the quantity. 30 | virtual void draw(); 31 | virtual void drawDelayed(); // drawing that should happen after the main phase 32 | 33 | // Draw the ImGUI ui elements 34 | virtual void buildUI(); // draws the tree node and enabled checkbox common to almost all quantities, and calls 35 | // drawCustomUI() below. Can still be overidden in case something else is wanted. 36 | virtual void buildCustomUI(); // overridden by children to add custom data to UI 37 | virtual void buildPickUI(size_t localPickInd); // overridden by children to add custom fields to pick menu 38 | 39 | // Enable and disable the quantity 40 | bool isEnabled(); 41 | // there is no setEnabled() here, only in subclasses, because subclasses have different return types 42 | 43 | // = Utility 44 | 45 | // Re-perform any setup work for the quantity, including regenerating shader programs. 46 | virtual void refresh(); 47 | 48 | // A decorated name for the quantity that will be used in headers. For instance, for surface scalar named "value" we 49 | // return "value (scalar)" 50 | virtual std::string niceName(); 51 | std::string uniquePrefix(); 52 | 53 | // === Member variables === 54 | Structure& parent; // the parent structure with which this quantity is associated 55 | const std::string name; // a name for this quantity, which must be unique amongst quantities on `parent` 56 | 57 | // Is this quantity currently being displayed? 58 | PersistentValue enabled; // should be set by setEnabled() 59 | }; 60 | 61 | // === Structure-specific Quantities 62 | 63 | template 64 | class QuantityS : public Quantity { 65 | public: 66 | QuantityS(std::string name, S& parentStructure, bool dominates = false); 67 | virtual ~QuantityS(); 68 | 69 | // Enable and disable the quantity 70 | virtual QuantityS* setEnabled(bool newEnabled); 71 | 72 | virtual void buildUI() override; 73 | 74 | S& parent; // note: this HIDES the more general member of the same name in the parent class 75 | 76 | // Track dominating quantities 77 | bool dominates = false; 78 | }; 79 | 80 | 81 | } // namespace polyscope 82 | 83 | 84 | #include "polyscope/quantity.ipp" 85 | -------------------------------------------------------------------------------- /include/polyscope/quantity.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "imgui.h" 4 | 5 | #include "polyscope/messages.h" 6 | #include "polyscope/structure.h" 7 | 8 | namespace polyscope { 9 | 10 | // forward declaration 11 | void requestRedraw(); 12 | 13 | // === Structure-specific Quantities 14 | 15 | template 16 | QuantityS::QuantityS(std::string name_, S& parentStructure_, bool dominates_) 17 | : Quantity(name_, parentStructure_), parent(parentStructure_), dominates(dominates_) { 18 | validateName(name); 19 | 20 | // Hack: if the quantity pulls enabled=true from the cache, need to make sure the logic from setEnabled(true) happens, 21 | // so toggle it real quick 22 | if (isEnabled()) { 23 | setEnabled(false); 24 | setEnabled(true); 25 | } 26 | } 27 | 28 | template 29 | QuantityS::~QuantityS() {} 30 | 31 | template 32 | QuantityS* QuantityS::setEnabled(bool newEnabled) { 33 | if (newEnabled == enabled.get()) return this; 34 | 35 | enabled = newEnabled; 36 | 37 | // Dominating quantities need to update themselves as their parent's dominating quantity 38 | if (dominates) { 39 | if (newEnabled == true) { 40 | parent.setDominantQuantity(this); 41 | } else { 42 | parent.clearDominantQuantity(); 43 | } 44 | } 45 | 46 | requestRedraw(); 47 | 48 | return this; 49 | } 50 | 51 | template 52 | void QuantityS::buildUI() { 53 | // NOTE: duplicated here and in the FloatingQuantity version 54 | 55 | if (ImGui::TreeNode(niceName().c_str())) { 56 | 57 | // Enabled checkbox 58 | bool enabledLocal = enabled.get(); 59 | if (ImGui::Checkbox("Enabled", &enabledLocal)) { 60 | setEnabled(enabledLocal); 61 | } 62 | 63 | // Call custom UI 64 | this->buildCustomUI(); 65 | 66 | ImGui::TreePop(); 67 | } 68 | } 69 | 70 | } // namespace polyscope 71 | -------------------------------------------------------------------------------- /include/polyscope/ragged_nested_array.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | 8 | namespace polyscope {} 9 | -------------------------------------------------------------------------------- /include/polyscope/raw_color_alpha_render_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render_image_quantity_base.h" 6 | #include "polyscope/types.h" 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | 12 | class RawColorAlphaRenderImageQuantity : public RenderImageQuantityBase { 13 | 14 | public: 15 | RawColorAlphaRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 16 | const std::vector& depthData, const std::vector& colorsData, 17 | ImageOrigin imageOrigin); 18 | 19 | virtual void draw() override; 20 | virtual void drawDelayed() override; 21 | virtual void buildCustomUI() override; 22 | 23 | virtual void refresh() override; 24 | 25 | virtual std::string niceName() override; 26 | 27 | render::ManagedBuffer colors; 28 | 29 | template 30 | void updateBuffers(const T1& depthData, const T2& colorsData); 31 | 32 | // == Setters and getters 33 | 34 | RawColorAlphaRenderImageQuantity* setIsPremultiplied(bool val); 35 | bool getIsPremultiplied(); 36 | 37 | protected: 38 | // Store the raw data 39 | std::vector colorsData; 40 | 41 | // === Visualization parameters 42 | PersistentValue isPremultiplied; 43 | 44 | // === Render data 45 | std::shared_ptr program; 46 | 47 | // === Helpers 48 | void prepare(); 49 | }; 50 | 51 | template 52 | void RawColorAlphaRenderImageQuantity::updateBuffers(const T1& depthData, const T2& colorsData) { 53 | 54 | validateSize(depthData, dimX * dimY, "color render image depth data " + name); 55 | validateSize(colorsData, dimX * dimY, "color render image color data " + name); 56 | 57 | // standardize 58 | std::vector standardDepth(standardizeArray(depthData)); 59 | std::vector standardNormal; 60 | std::vector standardColor(standardizeVectorArray(colorsData)); 61 | 62 | colors.data = standardColor; 63 | colors.markHostBufferUpdated(); 64 | 65 | updateBaseBuffers(standardDepth, standardNormal); 66 | } 67 | 68 | } // namespace polyscope 69 | -------------------------------------------------------------------------------- /include/polyscope/raw_color_render_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render_image_quantity_base.h" 6 | #include "polyscope/types.h" 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | 12 | class RawColorRenderImageQuantity : public RenderImageQuantityBase { 13 | 14 | public: 15 | RawColorRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 16 | const std::vector& depthData, const std::vector& colorsData, 17 | ImageOrigin imageOrigin); 18 | 19 | virtual void draw() override; 20 | virtual void drawDelayed() override; 21 | virtual void buildCustomUI() override; 22 | 23 | virtual void refresh() override; 24 | 25 | virtual std::string niceName() override; 26 | 27 | render::ManagedBuffer colors; 28 | 29 | template 30 | void updateBuffers(const T1& depthData, const T2& colorsData); 31 | 32 | // == Setters and getters 33 | 34 | 35 | protected: 36 | // === Visualization parameters 37 | 38 | // Store the raw data 39 | std::vector colorsData; 40 | 41 | // === Render data 42 | std::shared_ptr program; 43 | 44 | // === Helpers 45 | void prepare(); 46 | }; 47 | 48 | template 49 | void RawColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& colorsData) { 50 | 51 | validateSize(depthData, dimX * dimY, "color render image depth data " + name); 52 | validateSize(colorsData, dimX * dimY, "color render image color data " + name); 53 | 54 | // standardize 55 | std::vector standardDepth(standardizeArray(depthData)); 56 | std::vector standardNormal; 57 | std::vector standardColor(standardizeVectorArray(colorsData)); 58 | 59 | colors.data = standardColor; 60 | colors.markHostBufferUpdated(); 61 | 62 | updateBaseBuffers(standardDepth, standardNormal); 63 | } 64 | 65 | } // namespace polyscope 66 | -------------------------------------------------------------------------------- /include/polyscope/render/color_maps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include "polyscope/color_management.h" 8 | 9 | namespace polyscope { 10 | 11 | // Load a new colormap from a (horizontally oriented) image file 12 | void loadColorMap(std::string cmapName, std::string filename); 13 | 14 | namespace render { 15 | 16 | // Helper to build a ImGUI dropdown to select color maps. Returns true if changed. 17 | bool buildColormapSelector(std::string& cm, std::string fieldname = "##colormap_picker"); 18 | 19 | 20 | // ColorMaps currently available below 21 | // Sequential & perceptually uniform: 22 | // - viridis (CM_VIRIDIS) 23 | // - magma (CM_MAGMA) 24 | // - inferno (CM_INFERNO) 25 | // - plasma (CM_PLASMA) 26 | // - gray (CM_GRAY) 27 | // 28 | // Sequential: 29 | // - blues (CM_BLUES) 30 | // - reds (CM_REDS) 31 | // 32 | // Diverging: 33 | // - coolwarm (CM_COOLWARM) 34 | // - purple-green (CM_PIYG) 35 | // 36 | // Other: 37 | // - spectral (CM_SPECTRAL) 38 | // - rainbow (CM_RAINBOW) 39 | // - jet (CM_JET) 40 | // - turbo (CM_TURBO) 41 | // 42 | // Cyclic: 43 | // - phase (CM_PHASE) 44 | // 45 | // Generate more using the generate_colormap_constant.py script in the misc folder of this repo. 46 | // Should work on any colormap from http://matplotlib.org/examples/color/colormaps_reference.html 47 | // 48 | 49 | 50 | // Some colors, while we're at it 51 | const glm::vec3 RGB_TEAL = {0., 178. / 255., 178. / 255.}; 52 | const glm::vec3 RGB_BLUE = {150. / 255., 154. / 255., 255. / 255.}; 53 | const glm::vec3 RGB_SKYBLUE = {152. / 255., 158. / 255., 200. / 255.}; 54 | const glm::vec3 RGB_ORANGE = {1., 0.5, 0.}; 55 | const glm::vec3 RGB_BLACK = {0., 0., 0.}; 56 | const glm::vec3 RGB_WHITE = {1., 1., 1.}; 57 | const glm::vec3 RGB_RED = {0.8, 0., 0.}; 58 | const glm::vec3 RGB_DARKGRAY = {.2, .2, .2}; 59 | const glm::vec3 RGB_LIGHTGRAY = {.8, .8, .8}; 60 | const glm::vec3 RGB_DARKRED = {.2, .0, .0}; 61 | const glm::vec3 RGB_PINK = {249. / 255., 45. / 255., 94. / 255.}; 62 | 63 | // Represents a color map 64 | struct ValueColorMap { 65 | 66 | std::string name; 67 | 68 | std::vector values; 69 | 70 | // Samples "val" from the colormap, where val is clamped to [0,1]. 71 | // Returns a vector3 of rgb values, each from [0,1] 72 | glm::vec3 getValue(double val) const { 73 | if (!std::isfinite(val)) { 74 | return {0, 0, 0}; 75 | } 76 | 77 | val = glm::clamp(val, 0.0, 1.0); 78 | 79 | // Find the two nearest indices in to the colormap lookup table, then 80 | // return a linear blend between them. 81 | double scaledVal = val * (values.size() - 1); 82 | double lowerVal = std::floor(scaledVal); 83 | double upperBlendVal = scaledVal - lowerVal; 84 | unsigned int lowerInd = static_cast(lowerVal); 85 | unsigned int upperInd = lowerInd + 1; 86 | 87 | return (float)(1.0 - upperBlendVal) * values[lowerInd] + (float)upperBlendVal * values[upperInd]; 88 | } 89 | }; 90 | 91 | 92 | } // namespace render 93 | } // namespace polyscope 94 | -------------------------------------------------------------------------------- /include/polyscope/render/colormap_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace polyscope { 8 | 9 | namespace render { 10 | 11 | // === the default colormaps themselves 12 | // (stored in color_maps.cpp) 13 | 14 | extern const std::vector CM_GRAY; 15 | extern const std::vector CM_VIRIDIS; 16 | extern const std::vector CM_PLASMA; 17 | extern const std::vector CM_INFERNO; 18 | extern const std::vector CM_MAGMA; 19 | extern const std::vector CM_COOLWARM; 20 | extern const std::vector CM_BLUES; 21 | extern const std::vector CM_PIYG; 22 | extern const std::vector CM_SPECTRAL; 23 | extern const std::vector CM_RAINBOW; 24 | extern const std::vector CM_JET; 25 | extern const std::vector CM_TURBO; 26 | extern const std::vector CM_REDS; 27 | extern const std::vector CM_PHASE; 28 | extern const std::vector CM_HSV; 29 | 30 | 31 | } // namespace render 32 | } // namespace polyscope 33 | -------------------------------------------------------------------------------- /include/polyscope/render/engine.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #include 5 | #include 6 | 7 | using std::cout; 8 | using std::endl; 9 | 10 | namespace polyscope { 11 | namespace render {} // namespace render 12 | } // namespace polyscope 13 | -------------------------------------------------------------------------------- /include/polyscope/render/ground_plane.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/types.h" 6 | #include "polyscope/view.h" 7 | 8 | #include 9 | 10 | namespace polyscope { 11 | namespace render { 12 | 13 | // Forward declare necessary types 14 | // TODO get this out of the engine so this isn't necessary 15 | class ShaderProgram; 16 | class TextureBuffer; 17 | class FrameBuffer; 18 | class RenderBuffer; 19 | 20 | // Note: behavior is dictated by the global options::groundPlaneMode setting 21 | 22 | // There should probably only ever be one GroundPlane object, managed by the render::Engine. 23 | class GroundPlane { 24 | public: 25 | GroundPlane() {}; 26 | 27 | // Render the ground plane. 28 | // isRedraw allows for an optimization: for rendering modes where the ground gets drawn many times per-frame, we only 29 | // need to generate expensive reflections (etc) once. Setting isRedraw=true skips generating this data. 30 | void draw(bool isRedraw = false); 31 | 32 | void buildGui(); 33 | void prepare(); // does any and all setup work / allocations / etc. Should be called whenever the mode is changed. 34 | 35 | 36 | // == Appearance Parameters 37 | 38 | // These all now live in polyscope::options 39 | 40 | // How far should the ground plane be from the bottom of the scene? Measured as a multiple of the vertical bounding 41 | // box of the scene. 42 | // float groundPlaneHeightFactor = 0; 43 | 44 | // int blurIters = 4; // how much blurring to do for 45 | // float shadowDarkness = 0.4; // how dark to make the shadows 46 | 47 | private: 48 | // note: these buffers/programs are only optionally populated based on the mode 49 | 50 | std::shared_ptr groundPlaneProgram; 51 | std::shared_ptr sceneAltColorTexture; 52 | std::shared_ptr sceneAltDepthTexture; 53 | std::shared_ptr sceneAltFrameBuffer; 54 | 55 | // alternating blurring 56 | // result starts and ends in the first buffer 57 | std::array, 2> blurColorTextures; 58 | std::array, 2> blurFrameBuffers; 59 | std::shared_ptr blurProgram, copyTexProgram; 60 | 61 | void populateGroundPlaneGeometry(); 62 | bool groundPlanePrepared = false; 63 | // which direction the ground plane faces 64 | view::UpDir groundPlaneViewCached = view::UpDir::XUp; // not actually valid, must populate first time 65 | }; 66 | 67 | } // namespace render 68 | 69 | 70 | } // namespace polyscope 71 | -------------------------------------------------------------------------------- /include/polyscope/render/managed_buffer.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | namespace polyscope { 6 | namespace render { 7 | 8 | template 9 | ManagedBuffer& ManagedBufferRegistry::getManagedBuffer(std::string name) { 10 | return ManagedBufferMap::getManagedBufferMapRef(this).getManagedBuffer(name); 11 | } 12 | 13 | template 14 | bool ManagedBufferRegistry::hasManagedBuffer(std::string name) { 15 | return ManagedBufferMap::getManagedBufferMapRef(this).hasManagedBuffer(name); 16 | } 17 | 18 | template 19 | void ManagedBufferRegistry::addManagedBuffer(ManagedBuffer* buffer) { 20 | ManagedBufferMap::getManagedBufferMapRef(this).addManagedBuffer(buffer); 21 | } 22 | 23 | template 24 | void ManagedBufferMap::addManagedBuffer(ManagedBuffer* buffer) { 25 | for (ManagedBuffer* buff : allBuffers) { 26 | if (buff->name == buffer->name) { 27 | exception("managed buffer map already contains buffer of name " + buff->name); 28 | } 29 | } 30 | allBuffers.push_back(buffer); 31 | } 32 | 33 | 34 | template 35 | ManagedBuffer& ManagedBufferMap::getManagedBuffer(std::string name) { 36 | 37 | // WARNING: this logic is duplicated between has- and get- functions 38 | 39 | auto endsWith = [](std::string const& str, std::string const& query) -> bool { 40 | if (query.size() > str.size()) return false; 41 | return std::equal(query.rbegin(), query.rend(), str.rbegin()); 42 | }; 43 | 44 | 45 | for (ManagedBuffer* buff : allBuffers) { 46 | if (endsWith(buff->name, "#" + name)) { 47 | return *buff; 48 | } 49 | } 50 | 51 | exception("managed buffer map does not contain buffer of name " + name); 52 | return *allBuffers[0]; // invalid, never executed 53 | } 54 | 55 | template 56 | bool ManagedBufferMap::hasManagedBuffer(std::string name) { 57 | 58 | // WARNING: this logic is duplicated between has- and get- functions 59 | 60 | auto endsWith = [](std::string const& str, std::string const& query) -> bool { 61 | if (query.size() > str.size()) return false; 62 | return std::equal(query.rbegin(), query.rend(), str.rbegin()); 63 | }; 64 | 65 | 66 | for (ManagedBuffer* buff : allBuffers) { 67 | if (endsWith(buff->name, "#" + name)) { 68 | return true; 69 | } 70 | } 71 | 72 | return false; 73 | } 74 | 75 | } // namespace render 76 | } // namespace polyscope 77 | -------------------------------------------------------------------------------- /include/polyscope/render/material_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/materials.h" 6 | 7 | #include 8 | 9 | namespace polyscope { 10 | 11 | namespace render { 12 | 13 | // The arrays that hold the actual data. Stored as constants in render/bindata 14 | extern const std::array bindata_clay_r; 15 | extern const std::array bindata_clay_g; 16 | extern const std::array bindata_clay_b; 17 | extern const std::array bindata_clay_k; 18 | 19 | extern const std::array bindata_wax_r; 20 | extern const std::array bindata_wax_g; 21 | extern const std::array bindata_wax_b; 22 | extern const std::array bindata_wax_k; 23 | 24 | extern const std::array bindata_candy_r; 25 | extern const std::array bindata_candy_g; 26 | extern const std::array bindata_candy_b; 27 | extern const std::array bindata_candy_k; 28 | 29 | extern const std::array bindata_flat_r; 30 | extern const std::array bindata_flat_g; 31 | extern const std::array bindata_flat_b; 32 | extern const std::array bindata_flat_k; 33 | 34 | extern const std::array bindata_mud; 35 | extern const std::array bindata_ceramic; 36 | extern const std::array bindata_jade; 37 | extern const std::array bindata_normal; 38 | 39 | extern const std::array bindata_concrete; 40 | 41 | 42 | } // namespace render 43 | } // namespace polyscope 44 | -------------------------------------------------------------------------------- /include/polyscope/render/materials.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | // == Predefinied materials: 16 | // 17 | // RGB colorable materials: 18 | // - clay: Simple material without much specularity, default for most object. 19 | // - wax: Slightly more specular and exciting looking 20 | // - candy: Shiny and bright, useful for accents 21 | // - flat: Flat shading, plain RGB lookups 22 | // 23 | // Single-color materials: 24 | // - 25 | 26 | namespace render { 27 | 28 | // forward declare 29 | class TextureBuffer; 30 | class ShaderProgram; 31 | 32 | // Materials have _r, _g, _b, _k textures for blending with arbitrary surface colors. 33 | struct Material { 34 | std::string name; 35 | bool supportsRGB = false; 36 | std::array, 4> textureBuffers; 37 | std::vector rules; // substitution rules to add to shaders 38 | std::function setUniforms; // function to set uniforms for shaders 39 | }; 40 | 41 | // Build an ImGui option picker in a dropdown ui 42 | // Returns true if modified. 43 | bool buildMaterialOptionsGui(std::string& mat); 44 | 45 | // Read pre-defined materials in to textures 46 | void loadDefaultMaterials(); 47 | 48 | } // namespace render 49 | 50 | 51 | // Load new materials from file 52 | void loadBlendableMaterial(std::string matName, std::array filenames); 53 | void loadBlendableMaterial(std::string matName, std::string filenameBase, std::string filenameExt); 54 | void loadStaticMaterial(std::string matName, std::string filename); 55 | 56 | 57 | } // namespace polyscope 58 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/gl_engine_glfw.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/options.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/utilities.h" 8 | 9 | #ifdef __APPLE__ 10 | #define GLFW_INCLUDE_GLCOREARB 11 | #include "GLFW/glfw3.h" 12 | #else 13 | #include "glad/glad.h" 14 | // glad must come first 15 | #include "GLFW/glfw3.h" 16 | #endif 17 | 18 | #ifdef _WIN32 19 | #undef APIENTRY 20 | #define GLFW_EXPOSE_NATIVE_WIN32 21 | #define GLFW_EXPOSE_NATIVE_WGL 22 | #include 23 | #endif 24 | 25 | #include "imgui.h" 26 | #define IMGUI_IMPL_OPENGL_LOADER_GLAD 27 | #include "backends/imgui_impl_glfw.h" 28 | #include "backends/imgui_impl_opengl3.h" 29 | 30 | #include "polyscope/render/opengl/gl_engine.h" 31 | 32 | #include 33 | 34 | // Note: DO NOT include this header throughout polyscope, and do not directly make openGL calls. This header should only 35 | // be used to construct an instance of Engine. engine.h gives the render API, all render calls should pass through that. 36 | 37 | 38 | namespace polyscope { 39 | namespace render { 40 | namespace backend_openGL3 { 41 | 42 | 43 | class GLEngineGLFW : public GLEngine { 44 | 45 | public: 46 | GLEngineGLFW(); 47 | virtual ~GLEngineGLFW(); 48 | 49 | // High-level control 50 | void initialize(); 51 | virtual void shutdown() override; 52 | void swapDisplayBuffers() override; 53 | 54 | // === Windowing and framework things 55 | 56 | void makeContextCurrent() override; 57 | void pollEvents() override; 58 | 59 | void focusWindow() override; 60 | void showWindow() override; 61 | void hideWindow() override; 62 | void updateWindowSize(bool force = false) override; 63 | void applyWindowSize() override; 64 | void setWindowResizable(bool newVal) override; 65 | bool getWindowResizable() override; 66 | std::tuple getWindowPos() override; 67 | bool windowRequestsClose() override; 68 | 69 | bool isKeyPressed(char c) override; // for lowercase a-z and 0-9 only 70 | std::string getClipboardText() override; 71 | void setClipboardText(std::string text) override; 72 | 73 | 74 | // === ImGui 75 | 76 | void initializeImGui() override; 77 | void shutdownImGui() override; 78 | void ImGuiNewFrame() override; 79 | void ImGuiRender() override; 80 | void configureImGui() override; 81 | 82 | protected: 83 | // Internal windowing and engine details 84 | GLFWwindow* mainWindow = nullptr; 85 | 86 | void setUIScaleFromSystemDPI(); 87 | }; 88 | 89 | } // namespace backend_openGL3 90 | } // namespace render 91 | } // namespace polyscope 92 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/gl_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/engine.h" 6 | 7 | // crickets 8 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | // This file defines common routines used by 6 | // multiple shaders; it is combined at link time with all fragment 7 | // shaders compiled via the methods in the GLProgram class. 8 | 9 | namespace polyscope { 10 | namespace render { 11 | namespace backend_openGL3 { 12 | 13 | extern const char* shaderCommonSource; 14 | 15 | } // namespace backend_openGL3 16 | } // namespace render 17 | } // namespace polyscope 18 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/cylinder_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification FLEX_CYLINDER_VERT_SHADER; 13 | extern const ShaderStageSpecification FLEX_CYLINDER_GEOM_SHADER; 14 | extern const ShaderStageSpecification FLEX_CYLINDER_FRAG_SHADER; 15 | 16 | // Rules specific to cylinders 17 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_VALUE; 18 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_BLEND_VALUE; 19 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_NEAREST_VALUE; 20 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_COLOR; 21 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_BLEND_COLOR; 22 | extern const ShaderReplacementRule CYLINDER_PROPAGATE_PICK; 23 | extern const ShaderReplacementRule CYLINDER_CULLPOS_FROM_MID; 24 | extern const ShaderReplacementRule CYLINDER_VARIABLE_SIZE; 25 | 26 | 27 | } // namespace backend_openGL3 28 | } // namespace render 29 | } // namespace polyscope 30 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/gizmo_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // Stages 12 | extern const ShaderStageSpecification TRANSFORMATION_GIZMO_ROT_VERT; 13 | extern const ShaderStageSpecification TRANSFORMATION_GIZMO_ROT_FRAG; 14 | extern const ShaderStageSpecification SLICE_PLANE_VERT_SHADER; 15 | extern const ShaderStageSpecification SLICE_PLANE_FRAG_SHADER; 16 | 17 | // Rules 18 | extern const ShaderReplacementRule TRANSFORMATION_GIZMO_VEC; 19 | 20 | } // namespace backend_openGL3 21 | } // namespace render 22 | } // namespace polyscope 23 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/grid_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification FLEX_GRIDCUBE_VERT_SHADER; 13 | extern const ShaderStageSpecification FLEX_GRIDCUBE_GEOM_SHADER; 14 | extern const ShaderStageSpecification FLEX_GRIDCUBE_FRAG_SHADER; 15 | 16 | extern const ShaderStageSpecification FLEX_GRIDCUBE_PLANE_VERT_SHADER; 17 | extern const ShaderStageSpecification FLEX_GRIDCUBE_PLANE_FRAG_SHADER; 18 | 19 | // Rules 20 | extern const ShaderReplacementRule GRIDCUBE_PROPAGATE_NODE_VALUE; 21 | extern const ShaderReplacementRule GRIDCUBE_PROPAGATE_CELL_VALUE; 22 | extern const ShaderReplacementRule GRIDCUBE_WIREFRAME; 23 | extern const ShaderReplacementRule GRIDCUBE_CONSTANT_PICK; 24 | extern const ShaderReplacementRule GRIDCUBE_CULLPOS_FROM_CENTER; 25 | 26 | 27 | } // namespace backend_openGL3 28 | } // namespace render 29 | } // namespace polyscope 30 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/ground_plane_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | extern const ShaderStageSpecification GROUND_PLANE_VERT_SHADER; 12 | extern const ShaderStageSpecification GROUND_PLANE_TILE_FRAG_SHADER; 13 | extern const ShaderStageSpecification GROUND_PLANE_TILE_REFLECT_FRAG_SHADER; 14 | extern const ShaderStageSpecification GROUND_PLANE_SHADOW_FRAG_SHADER; 15 | 16 | // Rules 17 | // extern const ShaderReplacementRule RULE_NAME; 18 | 19 | } // namespace backend_openGL3 20 | } // namespace render 21 | } // namespace polyscope 22 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/histogram_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification HISTOGRAM_VERT_SHADER; 13 | extern const ShaderStageSpecification HISTOGRAM_FRAG_SHADER; 14 | extern const ShaderStageSpecification HISTOGRAM_CATEGORICAL_FRAG_SHADER; 15 | 16 | // Rules 17 | // extern const ShaderReplacementRule RULE_NAME; 18 | 19 | } // namespace backend_openGL3 20 | } // namespace render 21 | } // namespace polyscope 22 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/lighting_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification MAP_LIGHT_FRAG_SHADER; 13 | 14 | // Rules 15 | extern const ShaderReplacementRule DOWNSAMPLE_RESOLVE_1; 16 | extern const ShaderReplacementRule DOWNSAMPLE_RESOLVE_2; 17 | extern const ShaderReplacementRule DOWNSAMPLE_RESOLVE_3; 18 | extern const ShaderReplacementRule DOWNSAMPLE_RESOLVE_4; 19 | 20 | extern const ShaderReplacementRule INVERSE_TONEMAP; 21 | 22 | extern const ShaderReplacementRule TRANSPARENCY_RESOLVE_SIMPLE; 23 | extern const ShaderReplacementRule TRANSPARENCY_STRUCTURE; 24 | extern const ShaderReplacementRule TRANSPARENCY_PEEL_STRUCTURE; 25 | extern const ShaderReplacementRule TRANSPARENCY_PEEL_GROUND; 26 | 27 | } // namespace backend_openGL3 28 | } // namespace render 29 | } // namespace polyscope 30 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/ribbon_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification RIBBON_VERT_SHADER; 13 | extern const ShaderStageSpecification RIBBON_GEOM_SHADER; 14 | extern const ShaderStageSpecification RIBBON_FRAG_SHADER; 15 | 16 | // Rules 17 | // extern const ShaderReplacementRule RULE_NAME; 18 | 19 | } // namespace backend_openGL3 20 | } // namespace render 21 | } // namespace polyscope 22 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/rules.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/engine.h" 6 | 7 | // clang-format off 8 | 9 | namespace polyscope { 10 | namespace render { 11 | namespace backend_openGL3 { 12 | 13 | extern const ShaderReplacementRule GLSL_VERSION; 14 | extern const ShaderReplacementRule GLOBAL_FRAGMENT_FILTER; 15 | extern const ShaderReplacementRule LIGHT_MATCAP; 16 | extern const ShaderReplacementRule LIGHT_PASSTHRU; 17 | 18 | 19 | // Shading color generation policies (colormapping, etc) 20 | // all of these generate or modify `vec3 albedoColor` from some other data 21 | extern const ShaderReplacementRule SHADE_BASECOLOR; // constant from u_baseColor 22 | extern const ShaderReplacementRule SHADE_COLOR; // from shadeColor 23 | extern const ShaderReplacementRule SHADECOLOR_FROM_UNIFORM; 24 | extern const ShaderReplacementRule SHADE_COLORMAP_VALUE; // colormapped from shadeValue 25 | extern const ShaderReplacementRule SHADE_CATEGORICAL_COLORMAP; // use ints to sample distinct values from colormap 26 | extern const ShaderReplacementRule SHADE_COLORMAP_ANGULAR2; // colormapped from angle of shadeValue2 27 | extern const ShaderReplacementRule SHADE_GRID_VALUE2; // generate a two-color grid with lines from shadeValue2 28 | extern const ShaderReplacementRule SHADE_CHECKER_VALUE2; // generate a two-color checker from shadeValue2 29 | extern const ShaderReplacementRule SHADE_CHECKER_CATEGORY; // generate a checker with colors from a categorical int 30 | extern const ShaderReplacementRule SHADEVALUE_MAG_VALUE2; // generate a shadeValue from the magnitude of shadeValue2 31 | extern const ShaderReplacementRule ISOLINE_STRIPE_VALUECOLOR; // modulate albedoColor based on shadeValue 32 | extern const ShaderReplacementRule CONTOUR_VALUECOLOR; // modulate albedoColor based on shadeValue 33 | extern const ShaderReplacementRule CHECKER_VALUE2COLOR; // modulate albedoColor based on shadeValue2 34 | extern const ShaderReplacementRule SHADE_BASECOLOR; // constant from u_baseColor 35 | extern const ShaderReplacementRule PREMULTIPLY_COLOR; 36 | 37 | // Positions, culling, etc 38 | extern const ShaderReplacementRule GENERATE_VIEW_POS; // computes viewPos, position in viewspace for fragment 39 | extern const ShaderReplacementRule PROJ_AND_INV_PROJ_MAT; 40 | extern const ShaderReplacementRule COMPUTE_SHADE_NORMAL_FROM_POSITION; 41 | extern const ShaderReplacementRule PREMULTIPLY_LIT_COLOR; 42 | extern const ShaderReplacementRule CULL_POS_FROM_VIEW; 43 | 44 | ShaderReplacementRule generateSlicePlaneRule(std::string uniquePostfix); 45 | ShaderReplacementRule generateVolumeGridSlicePlaneRule(std::string uniquePostfix); 46 | 47 | // clang-format on 48 | 49 | } // namespace backend_openGL3 50 | } // namespace render 51 | } // namespace polyscope 52 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/sphere_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification FLEX_SPHERE_VERT_SHADER; 13 | extern const ShaderStageSpecification FLEX_SPHERE_GEOM_SHADER; 14 | extern const ShaderStageSpecification FLEX_SPHERE_FRAG_SHADER; 15 | 16 | extern const ShaderStageSpecification FLEX_POINTQUAD_VERT_SHADER; 17 | extern const ShaderStageSpecification FLEX_POINTQUAD_GEOM_SHADER; 18 | extern const ShaderStageSpecification FLEX_POINTQUAD_FRAG_SHADER; 19 | 20 | // Rules specific to spheres 21 | extern const ShaderReplacementRule SPHERE_PROPAGATE_VALUE; 22 | extern const ShaderReplacementRule SPHERE_PROPAGATE_VALUEALPHA; 23 | extern const ShaderReplacementRule SPHERE_PROPAGATE_VALUE2; 24 | extern const ShaderReplacementRule SPHERE_PROPAGATE_COLOR; 25 | extern const ShaderReplacementRule SPHERE_VARIABLE_SIZE; 26 | extern const ShaderReplacementRule SPHERE_CULLPOS_FROM_CENTER; 27 | extern const ShaderReplacementRule SPHERE_CULLPOS_FROM_CENTER_QUAD; 28 | 29 | 30 | } // namespace backend_openGL3 31 | } // namespace render 32 | } // namespace polyscope 33 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/surface_mesh_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification FLEX_MESH_VERT_SHADER; 13 | extern const ShaderStageSpecification FLEX_MESH_FRAG_SHADER; 14 | 15 | // Minimal mesh renders 16 | extern const ShaderStageSpecification SIMPLE_MESH_VERT_SHADER; 17 | extern const ShaderStageSpecification SIMPLE_MESH_FRAG_SHADER; 18 | 19 | // Rules specific to meshes 20 | extern const ShaderReplacementRule MESH_WIREFRAME_FROM_BARY; 21 | extern const ShaderReplacementRule MESH_WIREFRAME; 22 | extern const ShaderReplacementRule MESH_WIREFRAME_ONLY; 23 | extern const ShaderReplacementRule MESH_BACKFACE_NORMAL_FLIP; 24 | extern const ShaderReplacementRule MESH_BACKFACE_DIFFERENT; 25 | extern const ShaderReplacementRule MESH_BACKFACE_DARKEN; 26 | extern const ShaderReplacementRule MESH_PROPAGATE_VALUE; 27 | extern const ShaderReplacementRule MESH_PROPAGATE_VALUEALPHA; 28 | extern const ShaderReplacementRule MESH_PROPAGATE_FLAT_VALUE; 29 | extern const ShaderReplacementRule MESH_PROPAGATE_VALUE_CORNER_NEAREST; 30 | extern const ShaderReplacementRule MESH_PROPAGATE_INT; 31 | extern const ShaderReplacementRule MESH_PROPAGATE_VALUE2; 32 | extern const ShaderReplacementRule MESH_PROPAGATE_TCOORD; 33 | extern const ShaderReplacementRule MESH_PROPAGATE_COLOR; 34 | extern const ShaderReplacementRule MESH_PROPAGATE_HALFEDGE_VALUE; 35 | extern const ShaderReplacementRule MESH_PROPAGATE_CULLPOS; 36 | extern const ShaderReplacementRule MESH_PROPAGATE_PICK; 37 | extern const ShaderReplacementRule MESH_PROPAGATE_PICK_SIMPLE; 38 | extern const ShaderReplacementRule MESH_PROPAGATE_TYPE_AND_BASECOLOR2_SHADE; 39 | 40 | 41 | } // namespace backend_openGL3 42 | } // namespace render 43 | } // namespace polyscope 44 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/texture_draw_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | extern const ShaderStageSpecification TEXTURE_DRAW_VERT_SHADER; 12 | extern const ShaderStageSpecification TEXTURE_DRAW_UPPERLEFT_VERT_SHADER; 13 | extern const ShaderStageSpecification SPHEREBG_DRAW_VERT_SHADER; 14 | extern const ShaderStageSpecification SPHEREBG_DRAW_FRAG_SHADER; 15 | extern const ShaderStageSpecification PLAIN_TEXTURE_DRAW_FRAG_SHADER; 16 | extern const ShaderStageSpecification PLAIN_RENDERIMAGE_TEXTURE_DRAW_FRAG_SHADER; 17 | extern const ShaderStageSpecification PLAIN_RAW_RENDERIMAGE_TEXTURE_DRAW_FRAG_SHADER; 18 | extern const ShaderStageSpecification DOT3_TEXTURE_DRAW_FRAG_SHADER; 19 | extern const ShaderStageSpecification MAP3_TEXTURE_DRAW_FRAG_SHADER; 20 | extern const ShaderStageSpecification COMPOSITE_PEEL; 21 | extern const ShaderStageSpecification DEPTH_COPY; 22 | extern const ShaderStageSpecification DEPTH_TO_MASK; 23 | extern const ShaderStageSpecification BLUR_RGB; 24 | 25 | extern const ShaderStageSpecification SCALAR_TEXTURE_COLORMAP; 26 | 27 | 28 | // Rules 29 | // extern const ShaderReplacementRule RULE_NAME; 30 | extern const ShaderReplacementRule 31 | TEXTURE_ORIGIN_UPPERLEFT; // sample textures with (0,0) in the upper left, instead of the usual openGL lower left 32 | extern const ShaderReplacementRule 33 | TEXTURE_ORIGIN_LOWERLEFT; // sample textures with (0,0) in the lower left, which is the usual openGL rule 34 | extern const ShaderReplacementRule TEXTURE_SET_TRANSPARENCY; // apply a transparency uniform to the texture 35 | extern const ShaderReplacementRule 36 | TEXTURE_SET_TRANSPARENCY_PREMULTIPLIED; // apply a transparency uniform to the texture 37 | extern const ShaderReplacementRule TEXTURE_PREMULTIPLY_OUT; // premultiply color samples 38 | extern const ShaderReplacementRule TEXTURE_SHADE_COLOR; // sample a color from a texture and use it for shading 39 | extern const ShaderReplacementRule 40 | TEXTURE_SHADE_COLORALPHA; // sample a coloralpha from a texture and use it for shading 41 | extern const ShaderReplacementRule TEXTURE_PROPAGATE_VALUE; // sample a scalar from a texture and use it for shading 42 | extern const ShaderReplacementRule TEXTURE_PROPAGATE_COLOR; // sample a color from a texture and use it for shading 43 | extern const ShaderReplacementRule 44 | TEXTURE_BILLBOARD_FROM_UNIFORMS; // adjust a texture's billboard position via uniforms 45 | extern const ShaderReplacementRule SHADE_NORMAL_FROM_TEXTURE; 46 | extern const ShaderReplacementRule SHADE_NORMAL_FROM_VIEWPOS_VAR; 47 | 48 | 49 | // Shaders (which are used elsewhere) 50 | extern const ShaderStageSpecification TEXTURE_DRAW_VERT_SHADER; 51 | extern const ShaderStageSpecification SPHEREBG_DRAW_VERT_SHADER; 52 | 53 | } // namespace backend_openGL3 54 | } // namespace render 55 | } // namespace polyscope 56 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/vector_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification FLEX_VECTOR_VERT_SHADER; 13 | extern const ShaderStageSpecification FLEX_TANGENT_VECTOR_VERT_SHADER; 14 | extern const ShaderStageSpecification FLEX_VECTOR_GEOM_SHADER; 15 | extern const ShaderStageSpecification FLEX_VECTOR_FRAG_SHADER; 16 | 17 | // Rules specific to cylinders 18 | extern const ShaderReplacementRule VECTOR_PROPAGATE_COLOR; 19 | extern const ShaderReplacementRule VECTOR_CULLPOS_FROM_TAIL; 20 | 21 | } // namespace backend_openGL3 22 | } // namespace render 23 | } // namespace polyscope 24 | -------------------------------------------------------------------------------- /include/polyscope/render/opengl/shaders/volume_mesh_shaders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/opengl/gl_shaders.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | namespace backend_openGL3 { 10 | 11 | // High level pipeline 12 | extern const ShaderStageSpecification SLICE_TETS_VERT_SHADER; 13 | extern const ShaderStageSpecification SLICE_TETS_GEOM_SHADER; 14 | extern const ShaderStageSpecification SLICE_TETS_FRAG_SHADER; 15 | extern const ShaderReplacementRule SLICE_TETS_BASECOLOR_SHADE; 16 | extern const ShaderReplacementRule SLICE_TETS_MESH_WIREFRAME; 17 | extern const ShaderReplacementRule SLICE_TETS_PROPAGATE_VALUE; 18 | extern const ShaderReplacementRule SLICE_TETS_PROPAGATE_VECTOR; 19 | extern const ShaderReplacementRule SLICE_TETS_VECTOR_COLOR; 20 | 21 | 22 | } // namespace backend_openGL3 23 | } // namespace render 24 | } // namespace polyscope 25 | -------------------------------------------------------------------------------- /include/polyscope/render/shader_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/render/engine.h" 6 | 7 | namespace polyscope { 8 | namespace render { 9 | 10 | std::vector 11 | applyShaderReplacements(const std::vector& stages, 12 | const std::vector& replacementRules); 13 | 14 | } 15 | } // namespace polyscope 16 | -------------------------------------------------------------------------------- /include/polyscope/render/templated_buffers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include "polyscope/polyscope.h" 8 | #include "polyscope/render/engine.h" 9 | 10 | namespace polyscope { 11 | namespace render { 12 | 13 | // ========================================================== 14 | // === Attribute buffers 15 | // ========================================================== 16 | 17 | // Allocate a buffer to hold a given template type 18 | // (use std::arrays to get arraycount repeated attributes) 19 | template 20 | std::shared_ptr generateAttributeBuffer(Engine* engine); 21 | 22 | // Get a single data value from a buffer of a templated type 23 | // (use std::arrays to get arraycount repeated attributes) 24 | template 25 | T getAttributeBufferData(AttributeBuffer& buff, size_t ind); 26 | 27 | // Get a range of data values from a buffer of a templated type 28 | // (use std::arrays to get arraycount repeated attributes) 29 | template 30 | std::vector getAttributeBufferDataRange(AttributeBuffer& buff, size_t ind, size_t count); 31 | 32 | 33 | // ========================================================== 34 | // === Texture buffers 35 | // ========================================================== 36 | 37 | // Allocate a texture buffer to hold a given template type 38 | // (use std::arrays to get arraycount repeated attributes) 39 | template 40 | std::shared_ptr generateTextureBuffer(Engine* engine) { 41 | exception("bad call"); // default implementation, should be specialized to use 42 | return nullptr; 43 | } 44 | // this one dispatches dynamically on D 45 | template 46 | std::shared_ptr generateTextureBuffer(DeviceBufferType D, Engine* engine); 47 | 48 | // Get a single data value from a texturebuffer of a templated type 49 | // (use std::arrays to get arraycount repeated attributes) 50 | // openGL doesn't support this anyway... 51 | // template 52 | // T getTextureBufferData(TextureBuffer& buff, size_t indX, size_t indY = 0, size_t indZ = 0); 53 | 54 | // Get a range of data values from a buffer of a templated type 55 | // (use std::arrays to get arraycount repeated attributes) 56 | template 57 | std::vector getTextureBufferData(TextureBuffer& buff) { 58 | // TODO write these specializations 59 | exception("bad call"); // default implementation, should be specialized to use 60 | return std::vector(); 61 | } 62 | 63 | 64 | } // namespace render 65 | } // namespace polyscope 66 | -------------------------------------------------------------------------------- /include/polyscope/render_image_quantity_base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | #include "polyscope/floating_quantity.h" 8 | #include "polyscope/fullscreen_artist.h" 9 | #include "polyscope/render/managed_buffer.h" 10 | #include "polyscope/structure.h" 11 | 12 | #include 13 | 14 | /* 15 | * Base class for RenderImage classes, which are render-like data of onscreen geometry (buffers of depth, normals, etc) 16 | * which has been generated from some out-of-Polyscope process, and is to be rendered to the screen. 17 | * 18 | */ 19 | 20 | namespace polyscope { 21 | 22 | class RenderImageQuantityBase : public FloatingQuantity, public FullscreenArtist { 23 | 24 | public: 25 | RenderImageQuantityBase(Structure& parent_, std::string name, size_t dimX, size_t dimY, 26 | const std::vector& depthData, const std::vector& normalData, 27 | ImageOrigin imageOrigin); 28 | 29 | // virtual void draw() override; 30 | // virtual void drawDelayed() override; 31 | 32 | virtual void refresh() override; 33 | 34 | size_t nPix(); 35 | 36 | render::ManagedBuffer depths; 37 | render::ManagedBuffer normals; 38 | 39 | void updateBaseBuffers(const std::vector& newDepthData, const std::vector& newNormalData); 40 | 41 | virtual void disableFullscreenDrawing() override; 42 | 43 | // == Setters and getters 44 | 45 | virtual RenderImageQuantityBase* setEnabled(bool newEnabled) override; 46 | 47 | // Material 48 | RenderImageQuantityBase* setMaterial(std::string name); 49 | std::string getMaterial(); 50 | 51 | // Transparency 52 | RenderImageQuantityBase* setTransparency(float newVal); 53 | float getTransparency(); 54 | 55 | // Fullscreen compositing 56 | // This controls whether multiple of these been shown fullscreen at the same time, vs do they dominate each other and 57 | // allow only one to be enabled. By default, false, only one can be enabled. 58 | RenderImageQuantityBase* setAllowFullscreenCompositing(bool newVal); 59 | bool getAllowFullscreenCompositing(); 60 | 61 | 62 | protected: 63 | const size_t dimX, dimY; 64 | const bool hasNormals; 65 | ImageOrigin imageOrigin; 66 | 67 | // Store the raw data 68 | std::vector depthsData; 69 | std::vector normalsData; 70 | 71 | // === Visualization parameters 72 | PersistentValue material; 73 | PersistentValue transparency; 74 | PersistentValue allowFullscreenCompositing; 75 | 76 | // Helpers 77 | void prepareGeometryBuffers(); 78 | void addOptionsPopupEntries(); 79 | }; 80 | 81 | 82 | } // namespace polyscope 83 | -------------------------------------------------------------------------------- /include/polyscope/scalar_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/fullscreen_artist.h" 6 | #include "polyscope/image_quantity_base.h" 7 | #include "polyscope/render/color_maps.h" 8 | #include "polyscope/scalar_quantity.h" 9 | 10 | #include 11 | 12 | namespace polyscope { 13 | 14 | class ScalarImageQuantity : public ImageQuantity, public ScalarQuantity { 15 | 16 | public: 17 | ScalarImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, const std::vector& data, 18 | ImageOrigin imageOrigin, DataType dataType); 19 | 20 | virtual void buildCustomUI() override; 21 | 22 | virtual void refresh() override; 23 | 24 | virtual std::string niceName() override; 25 | 26 | // == Setters and getters 27 | 28 | virtual ScalarImageQuantity* setEnabled(bool newEnabled) override; 29 | 30 | protected: 31 | // rendering internals 32 | std::shared_ptr textureIntermediateRendered; 33 | std::shared_ptr fullscreenProgram, billboardProgram; 34 | std::shared_ptr framebufferIntermediate; 35 | 36 | void prepareFullscreen(); 37 | void prepareIntermediateRender(); 38 | void prepareBillboard(); 39 | 40 | virtual void showFullscreen() override; 41 | virtual void showInImGuiWindow() override; 42 | virtual void showInBillboard(glm::vec3 center, glm::vec3 upVec, glm::vec3 rightVec) override; 43 | virtual void renderIntermediate() override; 44 | }; 45 | 46 | 47 | } // namespace polyscope 48 | -------------------------------------------------------------------------------- /include/polyscope/scalar_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/histogram.h" 7 | #include "polyscope/persistent_value.h" 8 | #include "polyscope/polyscope.h" 9 | #include "polyscope/render/engine.h" 10 | #include "polyscope/render/managed_buffer.h" 11 | #include "polyscope/scaled_value.h" 12 | #include "polyscope/standardize_data_array.h" 13 | 14 | namespace polyscope { 15 | 16 | // Encapsulates logic which is common to all scalar quantities 17 | 18 | template 19 | class ScalarQuantity { 20 | public: 21 | ScalarQuantity(QuantityT& quantity, const std::vector& values, DataType dataType); 22 | 23 | // Build the ImGUI UIs for scalars 24 | void buildScalarUI(); 25 | virtual void buildScalarOptionsUI(); // called inside of an options menu 26 | 27 | // Add rules to rendering programs for scalars 28 | std::vector addScalarRules(std::vector rules); 29 | 30 | // Set uniforms in rendering programs for scalars 31 | void setScalarUniforms(render::ShaderProgram& p); 32 | 33 | template 34 | void updateData(const V& newValues); 35 | 36 | // === Members 37 | QuantityT& quantity; 38 | 39 | // Wrapper around the actual buffer of scalar data stored in the class. 40 | // Interaction with the data (updating it on CPU or GPU side, accessing it, etc) happens through this wrapper. 41 | render::ManagedBuffer values; 42 | 43 | // === Get/set visualization parameters 44 | 45 | // The color map 46 | QuantityT* setColorMap(std::string val); 47 | std::string getColorMap(); 48 | 49 | // Data limits mapped in to colormap 50 | QuantityT* setMapRange(std::pair val); 51 | std::pair getMapRange(); 52 | QuantityT* resetMapRange(); // reset to full range 53 | std::pair getDataRange(); 54 | 55 | // Isolines 56 | // NOTE there's a name typo, errant `s` in isolinesEnabled (leaving to avoid breaking change) 57 | QuantityT* setIsolinesEnabled(bool newEnabled); 58 | bool getIsolinesEnabled(); 59 | QuantityT* setIsolineStyle(IsolineStyle val); 60 | IsolineStyle getIsolineStyle(); 61 | QuantityT* setIsolinePeriod(double size, bool isRelative); 62 | double getIsolinePeriod(); 63 | QuantityT* setIsolineDarkness(double val); 64 | double getIsolineDarkness(); 65 | QuantityT* setIsolineContourThickness(double val); 66 | double getIsolineContourThickness(); 67 | 68 | // Old / depracted methods kept for compatability 69 | QuantityT* setIsolineWidth(double size, bool isRelative); 70 | double getIsolineWidth(); 71 | 72 | protected: 73 | std::vector valuesData; 74 | const DataType dataType; 75 | 76 | // === Visualization parameters 77 | 78 | // Affine data maps and limits 79 | std::pair dataRange; 80 | PersistentValue vizRangeMin; 81 | PersistentValue vizRangeMax; 82 | Histogram hist; 83 | 84 | // Parameters 85 | PersistentValue cMap; 86 | PersistentValue isolinesEnabled; 87 | PersistentValue isolineStyle; 88 | PersistentValue> isolinePeriod; 89 | PersistentValue isolineDarkness; 90 | PersistentValue isolineContourThickness; 91 | }; 92 | 93 | } // namespace polyscope 94 | 95 | 96 | #include "polyscope/scalar_quantity.ipp" 97 | -------------------------------------------------------------------------------- /include/polyscope/scalar_render_image_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/histogram.h" 7 | #include "polyscope/render/color_maps.h" 8 | #include "polyscope/render_image_quantity_base.h" 9 | #include "polyscope/scalar_quantity.h" 10 | 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | class ScalarRenderImageQuantity : public RenderImageQuantityBase, public ScalarQuantity { 16 | 17 | public: 18 | ScalarRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 19 | const std::vector& depthData, const std::vector& normalData, 20 | const std::vector& scalarData, ImageOrigin imageOrigin, DataType dataType); 21 | 22 | virtual void draw() override; 23 | virtual void drawDelayed() override; 24 | virtual void buildCustomUI() override; 25 | 26 | virtual void refresh() override; 27 | 28 | virtual std::string niceName() override; 29 | 30 | // == Setters and getters 31 | 32 | template 33 | void updateBuffers(const T1& depthData, const T2& normalData, const T3& scalarData); 34 | 35 | protected: 36 | // === Visualization parameters 37 | 38 | // === Render data 39 | std::shared_ptr program; 40 | 41 | // === Helpers 42 | void prepare(); 43 | }; 44 | 45 | template 46 | void ScalarRenderImageQuantity::updateBuffers(const T1& depthData, const T2& normalData, const T3& scalarData) { 47 | 48 | validateSize(depthData, dimX * dimY, "scalar render image depth data " + name); 49 | validateSize(normalData, {dimX * dimY, 0}, "scalar render image normal data " + name); 50 | validateSize(scalarData, dimX * dimY, "scalar render image color data " + name); 51 | 52 | // standardize 53 | std::vector standardDepth(standardizeArray(depthData)); 54 | std::vector standardNormal(standardizeVectorArray(normalData)); 55 | std::vector standardScalar(standardizeArray(scalarData)); 56 | 57 | values.data = standardScalar; 58 | values.markHostBufferUpdated(); 59 | 60 | updateBaseBuffers(standardDepth, standardNormal); 61 | } 62 | 63 | 64 | } // namespace polyscope 65 | -------------------------------------------------------------------------------- /include/polyscope/scaled_value.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | namespace polyscope { 6 | 7 | // Manages a value which is _either_ scaled by `state::lengthScale` (the default), or an absolute value which is not 8 | // scaled. That is, if `isRelative` is true, then `.get()` will return `val * state::lengthScale`. Otherwise it will 9 | // just return `val`. 10 | // 11 | // Since values are assumed to be relative by default, simplying assigning to a ScaledValue will create a relatve value. 12 | 13 | // forward declare 14 | namespace state { 15 | extern float& lengthScale; 16 | } 17 | 18 | template 19 | class ScaledValue { 20 | 21 | public: 22 | // Basic constructors 23 | ScaledValue() : relativeFlag(true), value() {} 24 | ScaledValue(T value_, bool relativeFlag_) : relativeFlag(relativeFlag_), value(value_) {} 25 | 26 | // Copy constructor from scaled value of convertible type 27 | template 28 | ScaledValue(const ScaledValue& otherValue) : relativeFlag(otherValue.relativeFlag), value(otherValue.value) {} 29 | 30 | // Named constructors 31 | static ScaledValue relative(T value_) { return ScaledValue(value_, true); } 32 | static ScaledValue absolute(T value_) { return ScaledValue(value_, false); } 33 | 34 | // Explicit getter (returns value in absolute coordinates always, scaling by length if needed) 35 | T asAbsolute() const { return relativeFlag ? value * state::lengthScale : value; } 36 | // Get a raw pointer to the underlying parameter (useful for e.g. imgui) 37 | T* getValuePtr() { return &value; } 38 | bool isRelative() const { return relativeFlag; } 39 | 40 | // Explicit setters 41 | void set(T value_, bool relativeFlag_ = true) { 42 | value = value_; 43 | relativeFlag = relativeFlag_; 44 | } 45 | // implicit conversion from scalar creates relative by default 46 | ScaledValue(const T& relativeValue) : relativeFlag(true), value(relativeValue) {} 47 | 48 | // Comparators etc 49 | bool operator==(const ScaledValue& rhs) const { 50 | return (value == rhs.value) && (relativeFlag == rhs.relativeFlag); 51 | } 52 | bool operator!=(const ScaledValue& rhs) const { return !operator==(rhs); } 53 | 54 | // Make all template variants friends, so conversion can access private members 55 | template 56 | friend class ScaledValue; 57 | 58 | private: 59 | bool relativeFlag; 60 | T value; 61 | }; 62 | 63 | 64 | // Create an absolute value of the given type 65 | template 66 | ScaledValue absoluteValue(T val) { 67 | return ScaledValue::absolute(val); 68 | } 69 | 70 | // Create an absolute value of the given type 71 | template 72 | ScaledValue relativeValue(T val) { 73 | return ScaledValue::relative(val); 74 | } 75 | 76 | 77 | } // namespace polyscope 78 | -------------------------------------------------------------------------------- /include/polyscope/screenshot.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | namespace polyscope { 8 | 9 | 10 | // Take a screenshot from the current view and write to file 11 | void screenshot(bool transparentBG = true); // automatic file names like `screenshot_000000.png` 12 | void screenshot(std::string filename, bool transparentBG = true); 13 | void screenshot(const char* filename); // this is needed because annoyingly overload resolution prefers the bool version 14 | void saveImage(std::string name, unsigned char* buffer, int w, int h, int channels); // helper 15 | void resetScreenshotIndex(); 16 | 17 | // Take a screenshot from the current view and return it as a buffer 18 | // the dimensions are view::bufferWidth and view::bufferHeight , with entries RGBA at 1 byte each. 19 | std::vector screenshotToBuffer(bool transparentBG = true); 20 | 21 | namespace state { 22 | 23 | // The current screenshot index for automatically numbered screenshots 24 | extern size_t screenshotInd; 25 | 26 | } // namespace state 27 | } // namespace polyscope 28 | -------------------------------------------------------------------------------- /include/polyscope/simple_triangle_mesh.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/utilities.h" 4 | 5 | #include 6 | 7 | namespace polyscope { 8 | 9 | // Shorthand to add a mesh to polyscope 10 | template 11 | SimpleTriangleMesh* registerSimpleTriangleMesh(std::string name, const V& vertexPositions, const F& faceIndices) { 12 | checkInitialized(); 13 | 14 | SimpleTriangleMesh* s = new SimpleTriangleMesh(name, standardizeVectorArray(vertexPositions), 15 | standardizeVectorArray(faceIndices)); 16 | 17 | bool success = registerStructure(s); 18 | if (!success) { 19 | safeDelete(s); 20 | } 21 | 22 | return s; 23 | } 24 | 25 | 26 | template 27 | void SimpleTriangleMesh::updateVertices(const V& newPositions) { 28 | validateSize(newPositions, vertices.size(), "newPositions"); 29 | vertices.data = standardizeVectorArray(newPositions); 30 | vertices.markHostBufferUpdated(); 31 | } 32 | 33 | template 34 | void SimpleTriangleMesh::update(const V& newPositions, const F& newFaces) { 35 | 36 | vertices.data = standardizeVectorArray(newPositions); 37 | vertices.markHostBufferUpdated(); 38 | 39 | faces.data = standardizeVectorArray(newFaces); 40 | faces.markHostBufferUpdated(); 41 | } 42 | 43 | // Shorthand to get a mesh from polyscope 44 | inline SimpleTriangleMesh* getSimpleTriangleMesh(std::string name) { 45 | return dynamic_cast(getStructure(SimpleTriangleMesh::structureTypeName, name)); 46 | } 47 | inline bool hasSimpleTriangleMesh(std::string name) { 48 | return hasStructure(SimpleTriangleMesh::structureTypeName, name); 49 | } 50 | inline void removeSimpleTriangleMesh(std::string name, bool errorIfAbsent) { 51 | removeStructure(SimpleTriangleMesh::structureTypeName, name, errorIfAbsent); 52 | } 53 | 54 | } // namespace polyscope 55 | -------------------------------------------------------------------------------- /include/polyscope/surface_color_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/color_quantity.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/surface_mesh.h" 8 | #include "polyscope/texture_map_quantity.h" 9 | 10 | namespace polyscope { 11 | 12 | // forward declarations 13 | class SurfaceMeshQuantity; 14 | class SurfaceMesh; 15 | class SurfaceParameterizationQuantity; 16 | 17 | class SurfaceColorQuantity : public SurfaceMeshQuantity, public ColorQuantity { 18 | public: 19 | SurfaceColorQuantity(std::string name, SurfaceMesh& mesh_, std::string definedOn, 20 | const std::vector& colorValues); 21 | 22 | virtual void draw() override; 23 | virtual void buildCustomUI() override; 24 | virtual std::string niceName() override; 25 | virtual void refresh() override; 26 | 27 | protected: 28 | // UI internals 29 | const std::string definedOn; 30 | std::shared_ptr program; 31 | 32 | // Helpers 33 | virtual void createProgram() = 0; 34 | }; 35 | 36 | // ======================================================== 37 | // ========== Vertex Color ========== 38 | // ======================================================== 39 | 40 | class SurfaceVertexColorQuantity : public SurfaceColorQuantity { 41 | public: 42 | SurfaceVertexColorQuantity(std::string name, SurfaceMesh& mesh_, std::vector values_); 43 | 44 | virtual void createProgram() override; 45 | virtual void buildColorOptionsUI() override; 46 | 47 | void buildVertexInfoGUI(size_t vInd) override; 48 | }; 49 | 50 | // ======================================================== 51 | // ========== Face Color ========== 52 | // ======================================================== 53 | 54 | class SurfaceFaceColorQuantity : public SurfaceColorQuantity { 55 | public: 56 | SurfaceFaceColorQuantity(std::string name, SurfaceMesh& mesh_, std::vector values_); 57 | 58 | virtual void createProgram() override; 59 | virtual void buildColorOptionsUI() override; 60 | 61 | void buildFaceInfoGUI(size_t fInd) override; 62 | }; 63 | 64 | 65 | // ======================================================== 66 | // ========== Texture Color ========== 67 | // ======================================================== 68 | 69 | class SurfaceTextureColorQuantity : public SurfaceColorQuantity, 70 | public TextureMapQuantity { 71 | public: 72 | SurfaceTextureColorQuantity(std::string name, SurfaceMesh& mesh_, SurfaceParameterizationQuantity& param_, 73 | size_t dimX, size_t dimY, std::vector values_, ImageOrigin origin_); 74 | 75 | virtual void createProgram() override; 76 | virtual void buildColorOptionsUI() override; 77 | 78 | protected: 79 | SurfaceParameterizationQuantity& param; 80 | }; 81 | 82 | } // namespace polyscope 83 | -------------------------------------------------------------------------------- /include/polyscope/surface_mesh_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | 9 | namespace polyscope { 10 | 11 | // Forward delcare surface mesh 12 | class SurfaceMesh; 13 | 14 | // Extend Quantity to add a few extra functions 15 | class SurfaceMeshQuantity : public QuantityS { 16 | public: 17 | SurfaceMeshQuantity(std::string name, SurfaceMesh& parentStructure, bool dominates = false); 18 | ~SurfaceMeshQuantity() {}; 19 | 20 | public: 21 | // Build GUI info about this element 22 | virtual void buildVertexInfoGUI(size_t vInd); 23 | virtual void buildFaceInfoGUI(size_t fInd); 24 | virtual void buildEdgeInfoGUI(size_t eInd); 25 | virtual void buildHalfedgeInfoGUI(size_t heInd); 26 | virtual void buildCornerInfoGUI(size_t heInd); 27 | }; 28 | 29 | } // namespace polyscope 30 | -------------------------------------------------------------------------------- /include/polyscope/texture_map_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/persistent_value.h" 6 | #include "polyscope/polyscope.h" 7 | #include "polyscope/render/engine.h" 8 | #include "polyscope/render/managed_buffer.h" 9 | #include "polyscope/standardize_data_array.h" 10 | 11 | namespace polyscope { 12 | 13 | // Encapsulates logic which is common to all texture map quantities 14 | 15 | template 16 | class TextureMapQuantity { 17 | public: 18 | TextureMapQuantity(QuantityT& parent, size_t dimX, size_t dimY, ImageOrigin origin_); 19 | 20 | // Build the ImGUI UIs for texture maps 21 | virtual void buildTextureMapOptionsUI(); // called inside of an options menu 22 | 23 | // === Members 24 | QuantityT& quantity; 25 | 26 | // NOTE: the main quantity types (scalar quantity, color quantity, etc) provide the buffer members, so this class just 27 | // has secondary options and such 28 | 29 | // what kind of texture filtering is used 30 | QuantityT* setFilterMode(FilterMode newFilterMode); 31 | FilterMode getFilterMode(); 32 | 33 | protected: 34 | size_t dimX, dimY; 35 | ImageOrigin imageOrigin; 36 | 37 | // === Visualization parameters 38 | PersistentValue filterMode; // default is FilterMode::Linear 39 | }; 40 | 41 | } // namespace polyscope 42 | 43 | #include "polyscope/texture_map_quantity.ipp" -------------------------------------------------------------------------------- /include/polyscope/texture_map_quantity.ipp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | namespace polyscope { 4 | 5 | template 6 | TextureMapQuantity::TextureMapQuantity(QuantityT& quantity_, size_t dimX_, size_t dimY_, ImageOrigin origin_) 7 | : quantity(quantity_), dimX(dimX_), dimY(dimY_), imageOrigin(origin_), 8 | filterMode(quantity.uniquePrefix() + "filterMode", FilterMode::Linear) {} 9 | 10 | template 11 | void TextureMapQuantity::buildTextureMapOptionsUI() { 12 | 13 | if (ImGui::BeginMenu("Filter Mode")) { 14 | if (ImGui::MenuItem("linear", NULL, filterMode.get() == FilterMode::Linear)) setFilterMode(FilterMode::Linear); 15 | if (ImGui::MenuItem("nearest", NULL, filterMode.get() == FilterMode::Nearest)) setFilterMode(FilterMode::Nearest); 16 | ImGui::EndMenu(); 17 | } 18 | } 19 | 20 | template 21 | QuantityT* TextureMapQuantity::setFilterMode(FilterMode newFilterMode) { 22 | filterMode = newFilterMode; 23 | quantity.refresh(); 24 | return &quantity; 25 | } 26 | 27 | template 28 | FilterMode TextureMapQuantity::getFilterMode() { 29 | return filterMode.get(); 30 | } 31 | 32 | } // namespace polyscope -------------------------------------------------------------------------------- /include/polyscope/transformation_gizmo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/persistent_value.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/utilities.h" 8 | #include "polyscope/widget.h" 9 | 10 | namespace polyscope { 11 | 12 | // A visual widget with handles for translations/rotations 13 | 14 | class TransformationGizmo : public Widget { 15 | 16 | public: 17 | // == Constructors 18 | 19 | TransformationGizmo(std::string name, glm::mat4& T, PersistentValue* Tpers = nullptr); 20 | 21 | 22 | // == Key members 23 | 24 | // a unique name 25 | const std::string name; 26 | 27 | // the main transform encoded by the gizmo 28 | PersistentValue enabled; 29 | 30 | // the main transform encoded by the gizmo 31 | // note that this is a reference set on construction; the gizmo wraps a transform defined somewhere else 32 | glm::mat4& T; 33 | PersistentValue* Tpers; // optional, a persistent value defined elsewhere that goes with T 34 | 35 | // == Member functions 36 | 37 | void prepare(); 38 | void draw() override; 39 | bool interact() override; 40 | 41 | protected: 42 | enum class TransformHandle { None, Rotation, Translation, Scale }; 43 | 44 | 45 | // parameters 46 | const float gizmoSizeRel = 0.08; 47 | const float diskWidthObj = 0.1; // in object coordinates, before transformation 48 | const float vecLength = 1.5; 49 | const float sphereRad = 0.32; 50 | const std::string material = "wax"; 51 | 52 | // state 53 | int selectedDim = -1; // must be {0,1,2} if selectedType == Rotation/Translation 54 | TransformHandle selectedType = TransformHandle::None; 55 | bool currentlyDragging = false; 56 | glm::vec3 dragPrevVec{1., 0., 57 | 0.}; // the normal vector from the previous frame of the drag OR previous translation center 58 | 59 | std::array niceRGB = {{glm::vec3{211 / 255., 45 / 255., 62 / 255.}, 60 | glm::vec3{65 / 255., 121 / 255., 225 / 255.}, 61 | glm::vec3{95 / 255., 175 / 255., 35 / 255.}}}; 62 | 63 | void markUpdated(); 64 | 65 | // Render stuff 66 | std::shared_ptr ringProgram; 67 | std::shared_ptr arrowProgram; 68 | std::shared_ptr sphereProgram; 69 | 70 | // Geometry helpers used to test hits 71 | 72 | // returns 73 | std::tuple circleTest(glm::vec3 raySource, glm::vec3 rayDir, glm::vec3 center, 74 | glm::vec3 normal, float radius); 75 | std::tuple lineTest(glm::vec3 raySource, glm::vec3 rayDir, glm::vec3 center, 76 | glm::vec3 tangent, float length); 77 | std::tuple sphereTest(glm::vec3 raySource, glm::vec3 rayDir, glm::vec3 center, float radius, 78 | bool allowHitSurface = true); 79 | 80 | 81 | std::tuple, std::vector, std::vector, std::vector, 82 | std::vector> 83 | triplePlaneCoords(); 84 | 85 | std::tuple, std::vector, std::vector, std::vector> 86 | tripleArrowCoords(); 87 | 88 | // std::tuple, std::vector> unitCubeCoords(); 89 | }; 90 | 91 | } // namespace polyscope 92 | -------------------------------------------------------------------------------- /include/polyscope/types.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | // Various types / enums / forward declarations which are broadly useful 6 | 7 | namespace polyscope { 8 | 9 | enum class NavigateStyle { Turntable = 0, Free, Planar, Arcball, None, FirstPerson }; 10 | enum class UpDir { XUp = 0, YUp, ZUp, NegXUp, NegYUp, NegZUp }; 11 | enum class FrontDir { XFront = 0, YFront, ZFront, NegXFront, NegYFront, NegZFront }; 12 | enum class BackgroundView { None = 0 }; 13 | enum class ProjectionMode { Perspective = 0, Orthographic }; 14 | enum class TransparencyMode { None = 0, Simple, Pretty }; 15 | enum class GroundPlaneMode { None, Tile, TileReflection, ShadowOnly }; 16 | enum class GroundPlaneHeightMode { Automatic = 0, Manual }; 17 | enum class BackFacePolicy { Identical, Different, Custom, Cull }; 18 | 19 | enum class PointRenderMode { Sphere = 0, Quad }; 20 | enum class MeshElement { VERTEX = 0, FACE, EDGE, HALFEDGE, CORNER }; 21 | enum class MeshShadeStyle { Smooth = 0, Flat, TriFlat }; 22 | enum class MeshSelectionMode { Auto = 0, VerticesOnly, FacesOnly }; 23 | enum class CurveNetworkElement { NODE = 0, EDGE }; 24 | enum class VolumeMeshElement { VERTEX = 0, EDGE, FACE, CELL }; 25 | enum class VolumeCellType { TET = 0, HEX }; 26 | enum class VolumeGridElement { NODE = 0, CELL }; 27 | enum class IsolineStyle { Stripe = 0, Contour }; 28 | 29 | enum class ImplicitRenderMode { SphereMarch, FixedStep }; 30 | enum class ImageOrigin { LowerLeft, UpperLeft }; 31 | enum class FilterMode { Nearest = 0, Linear }; 32 | 33 | enum class ParamCoordsType { UNIT = 0, WORLD }; // UNIT -> [0,1], WORLD -> length-valued 34 | enum class ParamVizStyle { 35 | CHECKER = 0, 36 | GRID, 37 | LOCAL_CHECK, 38 | LOCAL_RAD, 39 | CHECKER_ISLANDS 40 | }; // TODO add "UV" with test UV map 41 | 42 | enum class ManagedBufferType { 43 | Float, 44 | Double, 45 | Vec2, 46 | Vec3, 47 | Vec4, 48 | Arr2Vec3, 49 | Arr3Vec3, 50 | Arr4Vec3, 51 | UInt32, 52 | Int32, 53 | UVec2, 54 | UVec3, 55 | UVec4 56 | }; 57 | 58 | 59 | // What is the meaningful range of these values? 60 | // Used to set meaningful colormaps 61 | // STANDARD: [-inf, inf], zero does not mean anything special (ie, position) 62 | // SYMMETRIC: [-inf, inf], zero is special (ie, net profit/loss) 63 | // MAGNITUDE: [0, inf], zero is special (ie, length of a vector) 64 | // CATEGORICAL: data is integers corresponding to labels, etc 65 | enum class DataType { STANDARD = 0, SYMMETRIC, MAGNITUDE, CATEGORICAL }; 66 | 67 | 68 | }; // namespace polyscope 69 | -------------------------------------------------------------------------------- /include/polyscope/volume_grid_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | 9 | namespace polyscope { 10 | 11 | // Forward declare structure 12 | class VolumeGrid; 13 | 14 | // Extend Quantity to add a few extra functions 15 | class VolumeGridQuantity : public QuantityS { 16 | public: 17 | VolumeGridQuantity(std::string name, VolumeGrid& parentStructure, bool dominates = false); 18 | ~VolumeGridQuantity() {}; 19 | 20 | virtual bool isDrawingGridcubes() = 0; 21 | 22 | // Build GUI info about this element 23 | virtual void buildNodeInfoGUI(size_t vInd); 24 | virtual void buildCellInfoGUI(size_t vInd); 25 | }; 26 | 27 | } // namespace polyscope 28 | -------------------------------------------------------------------------------- /include/polyscope/volume_mesh_color_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/color_quantity.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/volume_mesh.h" 8 | 9 | namespace polyscope { 10 | 11 | // forward declaration 12 | class VolumeMeshQuantity; 13 | class VolumeMesh; 14 | 15 | class VolumeMeshColorQuantity : public VolumeMeshQuantity, public ColorQuantity { 16 | public: 17 | VolumeMeshColorQuantity(std::string name, VolumeMesh& mesh_, std::string definedOn, 18 | const std::vector& colorValues); 19 | 20 | virtual void draw() override; 21 | virtual std::string niceName() override; 22 | virtual void refresh() override; 23 | 24 | protected: 25 | // UI internals 26 | const std::string definedOn; 27 | std::shared_ptr program; 28 | std::shared_ptr sliceProgram; 29 | 30 | // Helpers 31 | virtual void createProgram() = 0; 32 | }; 33 | 34 | // ======================================================== 35 | // ========== Vertex Color ========== 36 | // ======================================================== 37 | 38 | class VolumeMeshVertexColorQuantity : public VolumeMeshColorQuantity { 39 | public: 40 | VolumeMeshVertexColorQuantity(std::string name, VolumeMesh& mesh_, const std::vector& values_); 41 | 42 | virtual void createProgram() override; 43 | virtual std::shared_ptr createSliceProgram() override; 44 | // void fillColorBuffers(render::ShaderProgram& p); 45 | void fillSliceColorBuffers(render::ShaderProgram& p); 46 | 47 | virtual void drawSlice(polyscope::SlicePlane* sp) override; 48 | 49 | void buildVertexInfoGUI(size_t vInd) override; 50 | }; 51 | 52 | // ======================================================== 53 | // ========== Cell Color ========== 54 | // ======================================================== 55 | 56 | class VolumeMeshCellColorQuantity : public VolumeMeshColorQuantity { 57 | public: 58 | VolumeMeshCellColorQuantity(std::string name, VolumeMesh& mesh_, const std::vector& values_); 59 | 60 | // TODO add slice drawing similar to the vertex case above 61 | 62 | virtual void createProgram() override; 63 | // void fillColorBuffers(render::ShaderProgram& p); 64 | 65 | void buildCellInfoGUI(size_t cInd) override; 66 | }; 67 | 68 | } // namespace polyscope 69 | -------------------------------------------------------------------------------- /include/polyscope/volume_mesh_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/quantity.h" 6 | #include "polyscope/structure.h" 7 | 8 | 9 | namespace polyscope { 10 | 11 | // Forward declare volume mesh 12 | class VolumeMesh; 13 | 14 | // Extend Quantity to add a few extra functions 15 | class VolumeMeshQuantity : public QuantityS { 16 | public: 17 | VolumeMeshQuantity(std::string name, VolumeMesh& parentStructure, bool dominates = false); 18 | ~VolumeMeshQuantity() {}; 19 | virtual std::shared_ptr createSliceProgram() { return nullptr; }; 20 | virtual void drawSlice(polyscope::SlicePlane* sp) {}; 21 | 22 | public: 23 | // Build GUI info about this element 24 | virtual void buildVertexInfoGUI(size_t vInd); 25 | virtual void buildEdgeInfoGUI(size_t eInd); 26 | virtual void buildFaceInfoGUI(size_t fInd); 27 | virtual void buildCellInfoGUI(size_t cInd); 28 | }; 29 | 30 | } // namespace polyscope 31 | -------------------------------------------------------------------------------- /include/polyscope/volume_mesh_scalar_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | #include "polyscope/affine_remapper.h" 8 | #include "polyscope/histogram.h" 9 | #include "polyscope/render/color_maps.h" 10 | #include "polyscope/render/engine.h" 11 | #include "polyscope/scalar_quantity.h" 12 | #include "polyscope/volume_mesh.h" 13 | 14 | namespace polyscope { 15 | 16 | class VolumeMeshScalarQuantity : public VolumeMeshQuantity, public ScalarQuantity { 17 | public: 18 | VolumeMeshScalarQuantity(std::string name, VolumeMesh& mesh_, std::string definedOn, 19 | const std::vector& values_, DataType dataType); 20 | 21 | virtual void draw() override; 22 | virtual void buildCustomUI() override; 23 | virtual std::string niceName() override; 24 | virtual void refresh() override; 25 | 26 | protected: 27 | const std::string definedOn; 28 | std::shared_ptr program; 29 | std::shared_ptr sliceProgram; 30 | 31 | // Helpers 32 | virtual void createProgram() = 0; 33 | }; 34 | 35 | // ======================================================== 36 | // ========== Vertex Scalar ========== 37 | // ======================================================== 38 | 39 | class VolumeMeshVertexScalarQuantity : public VolumeMeshScalarQuantity { 40 | public: 41 | VolumeMeshVertexScalarQuantity(std::string name, const std::vector& values_, VolumeMesh& mesh_, 42 | DataType dataType_ = DataType::STANDARD); 43 | 44 | virtual void createProgram() override; 45 | virtual std::shared_ptr createSliceProgram() override; 46 | virtual void draw() override; 47 | virtual void drawSlice(polyscope::SlicePlane* sp) override; 48 | 49 | void setLevelSetValue(float f); 50 | void setEnabledLevelSet(bool v); 51 | void setLevelSetVisibleQuantity(std::string name); 52 | void setLevelSetUniforms(render::ShaderProgram& p); 53 | void fillLevelSetData(render::ShaderProgram& p); 54 | std::shared_ptr levelSetProgram; 55 | 56 | void fillSliceColorBuffers(render::ShaderProgram& p); 57 | 58 | virtual void buildCustomUI() override; 59 | virtual void buildScalarOptionsUI() override; 60 | void buildVertexInfoGUI(size_t vInd) override; 61 | virtual void refresh() override; 62 | 63 | // TODO make these persistent values 64 | 65 | float levelSetValue; 66 | bool isDrawingLevelSet; 67 | VolumeMeshVertexScalarQuantity* showQuantity; 68 | }; 69 | 70 | 71 | // ======================================================== 72 | // ========== Cell Scalar ========== 73 | // ======================================================== 74 | 75 | class VolumeMeshCellScalarQuantity : public VolumeMeshScalarQuantity { 76 | public: 77 | VolumeMeshCellScalarQuantity(std::string name, const std::vector& values_, VolumeMesh& mesh_, 78 | DataType dataType_ = DataType::STANDARD); 79 | 80 | virtual void createProgram() override; 81 | 82 | void fillColorBuffers(render::ShaderProgram& p); 83 | 84 | void buildCellInfoGUI(size_t fInd) override; 85 | 86 | // TODO support level set things like in the scalar case above 87 | }; 88 | 89 | 90 | } // namespace polyscope 91 | -------------------------------------------------------------------------------- /include/polyscope/volume_mesh_vector_quantity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/affine_remapper.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/types.h" 8 | #include "polyscope/vector_quantity.h" 9 | #include "polyscope/volume_mesh.h" 10 | 11 | namespace polyscope { 12 | 13 | // ==== Common base class 14 | 15 | // Represents a general vector field associated with a surface mesh, including 16 | // R3 fields in the ambient space and R2 fields embedded in the surface 17 | 18 | // NOTE: This intermediate class is not really necessary anymore; it is subsumed by the VectorQuantity<> classes which 19 | // serve as common bases for ALL vector types. At this point it is just kept around for backward compatibility, to not 20 | // break user code which holds a reference to it. 21 | class VolumeMeshVectorQuantity : public VolumeMeshQuantity { 22 | public: 23 | VolumeMeshVectorQuantity(std::string name, VolumeMesh& mesh_, VolumeMeshElement definedOn_); 24 | 25 | protected: 26 | VolumeMeshElement definedOn; 27 | }; 28 | 29 | 30 | // ==== R3 vectors at vertices 31 | 32 | class VolumeMeshVertexVectorQuantity : public VolumeMeshVectorQuantity, 33 | public VectorQuantity { 34 | public: 35 | VolumeMeshVertexVectorQuantity(std::string name, std::vector vectors_, VolumeMesh& mesh_, 36 | VectorType vectorType_ = VectorType::STANDARD); 37 | 38 | virtual void draw() override; 39 | virtual void buildCustomUI() override; 40 | virtual void refresh() override; 41 | virtual std::string niceName() override; 42 | virtual void buildVertexInfoGUI(size_t vInd) override; 43 | }; 44 | 45 | 46 | // ==== R3 vectors at cells 47 | 48 | class VolumeMeshCellVectorQuantity : public VolumeMeshVectorQuantity, 49 | public VectorQuantity { 50 | public: 51 | VolumeMeshCellVectorQuantity(std::string name, std::vector vectors_, VolumeMesh& mesh_, 52 | VectorType vectorType_ = VectorType::STANDARD); 53 | 54 | virtual void draw() override; 55 | virtual void buildCustomUI() override; 56 | virtual void refresh() override; 57 | virtual std::string niceName() override; 58 | virtual void buildCellInfoGUI(size_t cInd) override; 59 | }; 60 | 61 | 62 | } // namespace polyscope 63 | -------------------------------------------------------------------------------- /include/polyscope/widget.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #pragma once 4 | 5 | #include "polyscope/weak_handle.h" 6 | 7 | namespace polyscope { 8 | 9 | // A base class for widgets in the scene. These need to be tracked globally so they drawn/handled in the user 10 | // interaction loop. The constructor/destructors take care of inserting the widget in to a global registery. 11 | class Widget : public virtual WeakReferrable { 12 | 13 | public: 14 | Widget(); 15 | virtual ~Widget(); 16 | 17 | // No copy constructor/assignment 18 | Widget(const Widget&) = delete; 19 | Widget& operator=(const Widget&) = delete; 20 | 21 | virtual void draw(); 22 | virtual bool interact(); // returns true if the mouse input was consumed 23 | virtual void buildGUI(); 24 | 25 | }; // namespace polyscope 26 | } // namespace polyscope 27 | -------------------------------------------------------------------------------- /misc/file2c/file2cpp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | FILE* open_or_exit(const char* fname, const char* mode) 5 | { 6 | FILE* f = fopen(fname, mode); 7 | if (f == NULL) { 8 | perror(fname); 9 | exit(EXIT_FAILURE); 10 | } 11 | return f; 12 | } 13 | 14 | int main(int argc, char** argv) 15 | { 16 | if (argc < 3) { 17 | fprintf(stderr, "USAGE: %s {sym} {rsrc}\n\n" 18 | " Creates {sym}.cpp from the contents of {rsrc}\n", 19 | argv[0]); 20 | return EXIT_FAILURE; 21 | } 22 | 23 | const char* sym = argv[1]; 24 | FILE* in = open_or_exit(argv[2], "r"); 25 | 26 | char symfile[256]; 27 | snprintf(symfile, sizeof(symfile), "%s.cpp", sym); 28 | 29 | FILE* out = open_or_exit(symfile,"w"); 30 | fprintf(out, "#include \n"); 31 | fprintf(out, "const unsigned char %s[] = {\n", sym); 32 | 33 | unsigned char buf[256]; 34 | size_t nread = 0; 35 | size_t linecount = 0; 36 | do { 37 | nread = fread(buf, 1, sizeof(buf), in); 38 | size_t i; 39 | for (i=0; i < nread; i++) { 40 | fprintf(out, "0x%02x, ", buf[i]); 41 | if (++linecount == 10) { fprintf(out, "\n"); linecount = 0; } 42 | } 43 | } while (nread > 0); 44 | if (linecount > 0) fprintf(out, "\n"); 45 | fprintf(out, "};\n"); 46 | fprintf(out, "const size_t %s_len = sizeof(%s);\n\n",sym,sym); 47 | 48 | fclose(in); 49 | fclose(out); 50 | 51 | return EXIT_SUCCESS; 52 | } 53 | -------------------------------------------------------------------------------- /misc/format_all_macOS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # run from project root 3 | clang-format -i src/*.cpp src/render/*.cpp src/render/opengl/*.cpp src/render/opengl/shaders/*.cpp src/render/mock_opengl/*.cpp 4 | find include/ -name '*.h' -print0 | xargs -0 clang-format -i 5 | find include/ -name '*.ipp' -print0 | xargs -0 clang-format -i 6 | find test/src/ -name '*.cpp' -print0 | xargs -0 clang-format -i 7 | find test/include/ -name '*.h' -print0 | xargs -0 clang-format -i 8 | find examples/ -path "./demo-app/build/" -prune -name '*.cpp' -print0 | xargs -0 clang-format -i 9 | find examples/ -path "./demo-app/build/" -prune -name '*.h' -print0 | xargs -0 clang-format -i 10 | -------------------------------------------------------------------------------- /misc/generate_colormap_constant.py: -------------------------------------------------------------------------------- 1 | # Samples from a matplotlib colormap and prints a constant string to stdout, which can then be embedded in a C++ program 2 | 3 | import numpy as np 4 | import matplotlib.cm 5 | import matplotlib.pyplot as plt 6 | import colorsys 7 | 8 | nValues = 500; 9 | 10 | # get a matplotlib colormap 11 | cmapName = 'hsv' 12 | cmap = plt.get_cmap(cmapName) 13 | 14 | # get a cmocean colormap 15 | # import cmocean 16 | # cmapName = 'phase' 17 | # cmap = cmocean.cm.phase 18 | 19 | 20 | print("static const Colormap CM_" + cmapName.upper() + " = {") 21 | print(" \"" + cmapName + "\",") 22 | 23 | def reduce_brightness_rgb(color, factor): 24 | r, g, b = color 25 | h, l, s = colorsys.rgb_to_hls(r, g, b) 26 | l = max(0, l * factor) # Ensure lightness remains non-negative 27 | r, g, b = colorsys.hls_to_rgb(h, l, s) 28 | return tuple(x for x in (r, g, b)) 29 | 30 | dataStr = "{" 31 | for i in range(nValues): 32 | 33 | floatInd = float(i) / (nValues-1) 34 | color = cmap(floatInd) 35 | color = (color[0], color[1], color[2]) 36 | # color = reduce_brightness_rgb(color, 0.85) # optional: dim bright colormaps a little 37 | 38 | dataStr += "{" + str(color[0]) + "," + str(color[1]) + "," + str(color[2]) + "}," 39 | 40 | dataStr += "}" 41 | print(dataStr) 42 | 43 | print("};") 44 | 45 | 46 | # Generate a constant colormap 47 | # constCmapName = 'const_red' 48 | # constCmapColor = (196/255., 133/255., 133/255.) 49 | 50 | # print("static const Colormap CM_" + constCmapName.upper() + " = {") 51 | # print(" \"" + constCmapName + "\",") 52 | 53 | # dataStr = "{" 54 | # for i in range(nValues): 55 | # dataStr += "{" + str(constCmapColor[0]) + "," + str(constCmapColor[1]) + "," + str(constCmapColor[2]) + "}," 56 | 57 | # dataStr += "}" 58 | # print(dataStr) 59 | 60 | # print("};") 61 | -------------------------------------------------------------------------------- /misc/material_images/.gitignore: -------------------------------------------------------------------------------- 1 | imagesrgb2material 2 | bin2vector 3 | -------------------------------------------------------------------------------- /misc/material_images/bin2vector.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | FILE* open_or_exit(const char* fname, const char* mode) { 5 | FILE* f = fopen(fname, mode); 6 | if (f == NULL) { 7 | perror(fname); 8 | exit(EXIT_FAILURE); 9 | } 10 | return f; 11 | } 12 | 13 | int main(int argc, char** argv) { 14 | if (argc < 2) { 15 | fprintf(stderr, "USAGE: %s FILE \n\n Creates bindata_FILE.cpp from the contents of FILE\n", argv[0]); 16 | return EXIT_FAILURE; 17 | } 18 | 19 | const char* inFilename = argv[1]; 20 | 21 | char symfile[256]; 22 | snprintf(symfile, sizeof(symfile), "bindata_%s.cpp", inFilename); 23 | 24 | FILE* out = open_or_exit(symfile, "w"); 25 | fprintf(out, "#include \n"); 26 | 27 | fprintf(out, "namespace polyscope { \n"); 28 | fprintf(out, "namespace gl { \n"); 29 | fprintf(out, "const std::vector bindata_%s = {\n", inFilename); 30 | 31 | FILE* in = open_or_exit(inFilename, "r"); 32 | unsigned char buf[256]; 33 | size_t nread = 0; 34 | size_t linecount = 0; 35 | do { 36 | nread = fread(buf, 1, sizeof(buf), in); 37 | size_t i; 38 | for (i = 0; i < nread; i++) { 39 | fprintf(out, "0x%02x, ", buf[i]); 40 | if (++linecount == 10) { 41 | fprintf(out, "\n"); 42 | linecount = 0; 43 | } 44 | } 45 | } while (nread > 0); 46 | if (linecount > 0) fprintf(out, "\n"); 47 | 48 | fclose(in); 49 | 50 | fprintf(out, "};\n"); 51 | fprintf(out, "}}"); 52 | fclose(out); 53 | 54 | return EXIT_SUCCESS; 55 | } 56 | -------------------------------------------------------------------------------- /misc/material_images/concrete_seamless.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmwsharp/polyscope/c82ec2e305532320fc7e7be89c7d05cc23daa648/misc/material_images/concrete_seamless.jpg -------------------------------------------------------------------------------- /misc/material_images/image2material.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | // this is a weird mix of C and C++, sorry world 8 | 9 | FILE* open_or_exit(const char* fname, const char* mode) { 10 | FILE* f = fopen(fname, mode); 11 | if (f == NULL) { 12 | perror(fname); 13 | exit(EXIT_FAILURE); 14 | } 15 | return f; 16 | } 17 | 18 | int main(int argc, char** argv) { 19 | if (argc < 2) { 20 | fprintf(stderr, 21 | "USAGE: %s {sym}\n\n" 22 | " Creates bindata_{sym}.cpp from the contents of {sym}.jpg (etc)\n", 23 | argv[0]); 24 | return EXIT_FAILURE; 25 | } 26 | 27 | const char* sym = argv[1]; 28 | 29 | char symfile[256]; 30 | snprintf(symfile, sizeof(symfile), "bindata_%s.cpp", sym); 31 | 32 | FILE* out = open_or_exit(symfile, "w"); 33 | fprintf(out, "#include \n"); 34 | 35 | fprintf(out, "#include \"polyscope/render/material_defs.h\"\n"); 36 | fprintf(out, "namespace polyscope { \n"); 37 | fprintf(out, "namespace render { \n\n"); 38 | 39 | fprintf(out, "// clang-format off \n"); 40 | 41 | 42 | char inFilename[256]; 43 | snprintf(inFilename, sizeof(inFilename), "%s.jpg", sym); 44 | 45 | FILE* in = open_or_exit(inFilename, "r"); 46 | unsigned char buf[256]; 47 | std::vector bytes; 48 | size_t nread = 0; 49 | do { 50 | nread = fread(buf, 1, sizeof(buf), in); 51 | size_t i; 52 | for (i = 0; i < nread; i++) { 53 | bytes.push_back(buf[i]); 54 | } 55 | } while (nread > 0); 56 | 57 | fprintf(out, "const std::array bindata_%s = {\n", (int)bytes.size(), sym); 58 | 59 | printf("extern const std::array bindata_%s;\n", (int)bytes.size(), sym); 60 | 61 | for (size_t iB = 0; iB < bytes.size(); iB++) { 62 | fprintf(out, "0x%02x, ", bytes[iB]); 63 | if (iB % 10 == 9) { 64 | fprintf(out, "\n"); 65 | } 66 | } 67 | 68 | fprintf(out, "\n };\n\n"); 69 | fclose(in); 70 | 71 | fprintf(out, "// clang-format on \n"); 72 | 73 | fprintf(out, "}\n"); 74 | fprintf(out, "}\n"); 75 | 76 | fclose(out); 77 | 78 | return EXIT_SUCCESS; 79 | } 80 | -------------------------------------------------------------------------------- /misc/material_images/imagesrgb2material.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | // this is a weird mix of C and C++, sorry world 8 | 9 | FILE* open_or_exit(const char* fname, const char* mode) { 10 | FILE* f = fopen(fname, mode); 11 | if (f == NULL) { 12 | perror(fname); 13 | exit(EXIT_FAILURE); 14 | } 15 | return f; 16 | } 17 | 18 | int main(int argc, char** argv) { 19 | if (argc < 2) { 20 | fprintf(stderr, 21 | "USAGE: %s {sym}\n\n" 22 | " Creates bindata_{sym}.cpp from the contents of {sym}_r.jpg (etc)\n", 23 | argv[0]); 24 | return EXIT_FAILURE; 25 | } 26 | 27 | const char* sym = argv[1]; 28 | 29 | char symfile[256]; 30 | snprintf(symfile, sizeof(symfile), "bindata_%s.cpp", sym); 31 | 32 | FILE* out = open_or_exit(symfile, "w"); 33 | fprintf(out, "#include \n"); 34 | 35 | fprintf(out, "#include \"polyscope/render/material_defs.h\"\n"); 36 | fprintf(out, "namespace polyscope { \n"); 37 | fprintf(out, "namespace render { \n\n"); 38 | 39 | fprintf(out, "// clang-format off \n"); 40 | 41 | 42 | for (int iComp = 0; iComp < 4; iComp++) { 43 | 44 | std::string postfix; 45 | if (iComp == 0) postfix = "_r"; 46 | if (iComp == 1) postfix = "_g"; 47 | if (iComp == 2) postfix = "_b"; 48 | if (iComp == 3) postfix = "_k"; 49 | 50 | 51 | char inFilename[256]; 52 | snprintf(inFilename, sizeof(inFilename), "%s%s.hdr", sym, postfix.c_str()); 53 | 54 | FILE* in = open_or_exit(inFilename, "r"); 55 | unsigned char buf[256]; 56 | std::vector bytes; 57 | size_t nread = 0; 58 | do { 59 | nread = fread(buf, 1, sizeof(buf), in); 60 | size_t i; 61 | for (i = 0; i < nread; i++) { 62 | bytes.push_back(buf[i]); 63 | } 64 | } while (nread > 0); 65 | 66 | fprintf(out, "const std::array bindata_%s%s = {\n", (int)bytes.size(), sym, postfix.c_str()); 67 | 68 | printf("extern const std::array bindata_%s%s;\n", (int)bytes.size(), sym, postfix.c_str()); 69 | 70 | for (size_t iB = 0; iB < bytes.size(); iB++) { 71 | fprintf(out, "0x%02x, ", bytes[iB]); 72 | if (iB % 10 == 9) { 73 | fprintf(out, "\n"); 74 | } 75 | } 76 | 77 | fprintf(out, "\n };\n\n"); 78 | fclose(in); 79 | } 80 | 81 | fprintf(out, "// clang-format on \n"); 82 | 83 | fprintf(out, "}\n"); 84 | fprintf(out, "}\n"); 85 | 86 | fclose(out); 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | -------------------------------------------------------------------------------- /misc/material_images/render_material.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmwsharp/polyscope/c82ec2e305532320fc7e7be89c7d05cc23daa648/misc/material_images/render_material.blend -------------------------------------------------------------------------------- /src/color_management.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/color_management.h" 4 | 5 | // Use for color conversion scripts 6 | #include "imgui.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace polyscope { 13 | 14 | namespace { 15 | 16 | // == Color management helpers 17 | 18 | // Clamp to [0,1] 19 | float unitClamp(float x) { return std::max(0.0f, std::min(1.0f, x)); } 20 | glm::vec3 unitClamp(glm::vec3 x) { return {unitClamp(x[0]), unitClamp(x[1]), unitClamp(x[2])}; } 21 | 22 | // Used to sample colors. Samples a series of most-distant values from a range [0,1] 23 | // offset from a starting value 'start' and wrapped around. index=0 returns start 24 | // 25 | // (We also use this logic via a duplicate implementation in some shaders) 26 | // 27 | // Example: if start = 0, emits f(0, i) = {0, 1/2, 1/4, 3/4, 1/8, 5/8, 3/8, 7/8, ...} 28 | // if start = 0.3 emits (0.3 + f(0, i)) % 1 29 | float getIndexedDistinctValue(float start, int index) { 30 | if (index < 0) { 31 | return 0.0; 32 | } 33 | 34 | // Bit shifty magic to evaluate f() 35 | float val = 0; 36 | float p = 0.5; 37 | while (index > 0) { 38 | if (index % 2 == 1) { 39 | val += p; 40 | } 41 | index = index >> 1; 42 | p /= 2.0; 43 | } 44 | 45 | // Apply modular offset 46 | val = std::fmod(val + start, 1.0); 47 | 48 | return unitClamp(val); 49 | } 50 | 51 | // Get an indexed offset color. Inputs and outputs in RGB 52 | glm::vec3 indexOffsetHue(glm::vec3 baseColor, int index) { 53 | glm::vec3 baseHSV = RGBtoHSV(baseColor); 54 | float newHue = getIndexedDistinctValue(baseHSV[0], index); 55 | glm::vec3 outHSV = {newHue, baseHSV[1], baseHSV[2]}; 56 | return HSVtoRGB(outHSV); 57 | } 58 | 59 | // Keep track of unique structure colors 60 | const glm::vec3 uniqueColorBase{28. / 255., 99. / 255., 227. / 255.}; 61 | int iUniqueColor = 0; 62 | 63 | 64 | } // namespace 65 | 66 | glm::vec3 getNextUniqueColor() { return indexOffsetHue(uniqueColorBase, iUniqueColor++); } 67 | 68 | glm::vec3 RGBtoHSV(glm::vec3 rgb) { 69 | glm::vec3 hsv; 70 | ImGui::ColorConvertRGBtoHSV(rgb[0], rgb[1], rgb[2], hsv[0], hsv[1], hsv[2]); 71 | return unitClamp(hsv); 72 | } 73 | 74 | glm::vec3 HSVtoRGB(glm::vec3 hsv) { 75 | glm::vec3 rgb; 76 | ImGui::ColorConvertHSVtoRGB(hsv[0], hsv[1], hsv[2], rgb[0], rgb[1], rgb[2]); 77 | return unitClamp(rgb); 78 | } 79 | 80 | 81 | } // namespace polyscope 82 | -------------------------------------------------------------------------------- /src/disjoint_sets.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/disjoint_sets.h" 4 | 5 | using std::vector; 6 | 7 | namespace polyscope { 8 | 9 | // Constructor 10 | DisjointSets::DisjointSets(size_t n_) : n(n_), parent(n + 1), rank(n + 1) { 11 | // Initialize all elements to be in different sets and to have rank 0 12 | for (size_t i = 0; i <= n; i++) { 13 | rank[i] = 0; 14 | parent[i] = i; 15 | } 16 | } 17 | 18 | // Find parent of element x 19 | size_t DisjointSets::find(size_t x) { 20 | if (x != parent[x]) parent[x] = find(parent[x]); 21 | return parent[x]; 22 | } 23 | 24 | // Union by rank 25 | void DisjointSets::merge(size_t x, size_t y) { 26 | x = find(x); 27 | y = find(y); 28 | 29 | // Smaller tree becomes a subtree of the larger tree 30 | if (rank[x] > rank[y]) 31 | parent[y] = x; 32 | else 33 | parent[x] = y; 34 | 35 | if (rank[x] == rank[y]) rank[y]++; 36 | } 37 | 38 | // Constructor 39 | MarkedDisjointSets::MarkedDisjointSets(size_t n_) : n(n_), parent(n + 1), rank(n + 1), marked(n + 1) { 40 | // Initialize all elements to be in different sets and to have rank 0 41 | for (size_t i = 0; i <= n; i++) { 42 | rank[i] = 0; 43 | parent[i] = i; 44 | marked[i] = false; 45 | } 46 | } 47 | 48 | void MarkedDisjointSets::mark(size_t x) { 49 | size_t p = find(x); 50 | marked[p] = true; 51 | } 52 | 53 | void MarkedDisjointSets::unmark(size_t x) { 54 | size_t p = find(x); 55 | marked[p] = false; 56 | } 57 | 58 | bool MarkedDisjointSets::isMarked(size_t x) { 59 | size_t p = find(x); 60 | return marked[p]; 61 | } 62 | 63 | // Find parent of element x 64 | size_t MarkedDisjointSets::find(size_t x) { 65 | if (x != parent[x]) parent[x] = find(parent[x]); 66 | return parent[x]; 67 | } 68 | 69 | // Union by rank 70 | void MarkedDisjointSets::merge(size_t x, size_t y) { 71 | x = find(x); 72 | y = find(y); 73 | 74 | // Smaller tree becomes a subtree of the larger tree 75 | if (rank[x] > rank[y]) 76 | parent[y] = x; 77 | else 78 | parent[x] = y; 79 | 80 | if (rank[x] == rank[y]) rank[y]++; 81 | 82 | // If either was marked, both are marked 83 | if (marked[x] || marked[y]) { 84 | marked[x] = true; 85 | marked[y] = true; 86 | } 87 | } 88 | 89 | } // namespace polyscope 90 | -------------------------------------------------------------------------------- /src/elementary_geometry.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/elementary_geometry.h" 4 | 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace polyscope { 12 | 13 | float computeTValAlongLine(glm::vec3 queryP, glm::vec3 lineStart, glm::vec3 lineEnd) { 14 | glm::vec3 lineVec = lineEnd - lineStart; 15 | glm::vec3 queryVec = queryP - lineStart; 16 | float len2 = glm::length2(lineVec); 17 | float t = glm::dot(queryVec, lineVec) / len2; 18 | t = glm::clamp(t, 0.f, 1.f); 19 | return t; 20 | } 21 | 22 | glm::vec3 projectToPlane(glm::vec3 queryP, glm::vec3 planeNormal, glm::vec3 pointOnPlane) { 23 | glm::vec3 pVec = queryP - pointOnPlane; 24 | glm::vec3 pVecOrtho = glm::dot(pVec, planeNormal) * planeNormal; 25 | return queryP - pVecOrtho; 26 | } 27 | 28 | float signedTriangleArea(glm::vec3 normal, glm::vec3 pA, glm::vec3 pB, glm::vec3 pC) { 29 | glm::vec3 cross = glm::cross(pB - pA, pC - pA); 30 | float sign = glm::sign(glm::dot(normal, cross)); 31 | float area = glm::length(cross) / 2.; 32 | return sign * area; 33 | } 34 | 35 | } // namespace polyscope -------------------------------------------------------------------------------- /src/file_helpers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/file_helpers.h" 4 | 5 | #include "imgui.h" 6 | #include "polyscope/polyscope.h" 7 | 8 | namespace polyscope { 9 | 10 | namespace { 11 | 12 | void filenamePromptCallback(char* buff, size_t len) { 13 | 14 | static bool windowOpen = true; 15 | ImGui::Begin("Enter filename", &windowOpen, ImGuiWindowFlags_AlwaysAutoResize); 16 | 17 | ImGui::PushItemWidth(500 * options::uiScale); 18 | ImGui::InputText("##filename", buff, len); 19 | 20 | if (ImGui::Button("Ok")) { 21 | popContext(); 22 | } 23 | 24 | ImGui::SameLine(); 25 | 26 | if (ImGui::Button("Cancel")) { 27 | // sprintf(buff, ""); 28 | buff[0] = 0; // because apparently gcc this this is clearer than that ^^^? 29 | popContext(); 30 | } 31 | 32 | ImGui::PopItemWidth(); 33 | ImGui::End(); 34 | } 35 | } // namespace 36 | 37 | 38 | std::string promptForFilename(std::string initName) { 39 | 40 | using namespace std::placeholders; 41 | 42 | // Register the callback which creates the UI and does the hard work 43 | const size_t BUFF_LEN = 2048; 44 | char* textBuff = new char[BUFF_LEN]; 45 | snprintf(textBuff, BUFF_LEN, "%s", initName.c_str()); 46 | auto func = std::bind(filenamePromptCallback, textBuff, BUFF_LEN); 47 | pushContext(func); 48 | 49 | std::string stringOut(textBuff); 50 | delete[] textBuff; 51 | 52 | return stringOut; 53 | } 54 | } // namespace polyscope 55 | -------------------------------------------------------------------------------- /src/floating_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #include "imgui.h" 5 | 6 | #include "polyscope/polyscope.h" 7 | 8 | #include "polyscope/floating_quantity.h" 9 | #include "polyscope/structure.h" 10 | 11 | namespace polyscope { 12 | 13 | void FloatingQuantity::buildUI() { 14 | 15 | // NOTE: duplicated here and in the QuantityS version 16 | 17 | if (ImGui::TreeNode(niceName().c_str())) { 18 | 19 | // Enabled checkbox 20 | bool enabledLocal = enabled.get(); 21 | if (ImGui::Checkbox("Enabled", &enabledLocal)) { 22 | setEnabled(enabledLocal); 23 | } 24 | 25 | // Call custom UI 26 | this->buildCustomUI(); 27 | 28 | ImGui::TreePop(); 29 | } 30 | } 31 | 32 | } // namespace polyscope 33 | -------------------------------------------------------------------------------- /src/fullscreen_artist.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include 4 | 5 | #include "polyscope/fullscreen_artist.h" 6 | 7 | namespace polyscope { 8 | 9 | // The static list 10 | std::vector> existingFullscreenArtists; 11 | 12 | FullscreenArtist::FullscreenArtist() { 13 | existingFullscreenArtists.emplace_back(this->getWeakHandle(this)); 14 | } 15 | 16 | FullscreenArtist::~FullscreenArtist() { 17 | // the weak handle will become invalid, let it get lazily delete at some later time 18 | } 19 | 20 | void disableAllFullscreenArtists() { 21 | 22 | // "erase-remove idiom" 23 | // (remove list entries for which the view weak_ptr has .expired() == true) 24 | existingFullscreenArtists.erase( 25 | std::remove_if(existingFullscreenArtists.begin(), existingFullscreenArtists.end(), 26 | [](const WeakHandle& entry) -> bool { return !entry.isValid(); }), 27 | existingFullscreenArtists.end()); 28 | 29 | for (WeakHandle& a : existingFullscreenArtists) { 30 | a.get().disableFullscreenDrawing(); 31 | } 32 | } 33 | 34 | } // namespace polyscope 35 | -------------------------------------------------------------------------------- /src/internal.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/internal.h" 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | namespace polyscope { 8 | namespace internal { 9 | 10 | uint64_t uniqueID = 42; 11 | 12 | uint64_t getNextUniqueID() { return uniqueID++; } 13 | 14 | bool& pointCloudEfficiencyWarningReported = state::globalContext.pointCloudEfficiencyWarningReported; 15 | FloatingQuantityStructure*& globalFloatingQuantityStructure = state::globalContext.globalFloatingQuantityStructure; 16 | 17 | } // namespace internal 18 | } // namespace polyscope 19 | -------------------------------------------------------------------------------- /src/marching_cubes.cpp: -------------------------------------------------------------------------------- 1 | #define MC_IMPLEM_ENABLE 2 | #include "MarchingCube/MC.h" 3 | -------------------------------------------------------------------------------- /src/options.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/options.h" 4 | #include "polyscope/imgui_config.h" 5 | 6 | namespace polyscope { 7 | namespace options { 8 | 9 | std::string programName = "Polyscope"; 10 | int verbosity = 2; 11 | std::string printPrefix = "[polyscope] "; 12 | bool allowHeadlessBackends = false; 13 | bool errorsThrowExceptions = false; 14 | bool debugDrawPickBuffer = false; 15 | int maxFPS = 60; 16 | 17 | #ifdef _WIN32 18 | // set the default vsync to false on windows, to workaround an glfw errors from an alleged driver bug 19 | bool enableVSync = false; 20 | #else 21 | bool enableVSync = true; 22 | #endif 23 | 24 | bool usePrefsFile = true; 25 | bool initializeWithDefaultStructures = true; 26 | bool alwaysRedraw = false; 27 | bool autocenterStructures = false; 28 | bool autoscaleStructures = false; 29 | bool automaticallyComputeSceneExtents = true; 30 | bool invokeUserCallbackForNestedShow = false; 31 | bool giveFocusOnShow = false; 32 | bool hideWindowAfterShow = true; 33 | bool warnForInvalidValues = true; 34 | bool displayMessagePopups = true; 35 | 36 | bool screenshotTransparency = true; 37 | std::string screenshotExtension = ".png"; 38 | 39 | // == Scene options 40 | 41 | // Ground plane / shadows 42 | bool groundPlaneEnabled = true; 43 | GroundPlaneMode groundPlaneMode = GroundPlaneMode::TileReflection; 44 | GroundPlaneHeightMode groundPlaneHeightMode = GroundPlaneHeightMode::Automatic; 45 | ScaledValue groundPlaneHeightFactor = 0; 46 | float groundPlaneHeight = 0.; 47 | int shadowBlurIters = 2; 48 | float shadowDarkness = 0.25; 49 | 50 | // Rendering options 51 | 52 | float uiScale = -1.0; // unset, must be set manually or during initialization 53 | int ssaaFactor = 1; 54 | 55 | // Transparency 56 | TransparencyMode transparencyMode = TransparencyMode::None; 57 | int transparencyRenderPasses = 8; 58 | 59 | // === Advanced ImGui configuration 60 | 61 | bool buildGui = true; 62 | bool userGuiIsOnRightSide = true; 63 | bool buildDefaultGuiPanels = true; 64 | bool renderScene = true; 65 | bool openImGuiWindowForUserCallback = true; 66 | std::function configureImGuiStyleCallback = configureImGuiStyle; 67 | std::function()> prepareImGuiFontsCallback = prepareImGuiFonts; 68 | 69 | // Backend and low-level options 70 | int eglDeviceIndex = -1; // means "try all of them" 71 | 72 | // enabled by default in debug mode 73 | #ifndef NDEBUG 74 | bool enableRenderErrorChecks = false; 75 | #else 76 | bool enableRenderErrorChecks = true; 77 | #endif 78 | 79 | } // namespace options 80 | } // namespace polyscope 81 | -------------------------------------------------------------------------------- /src/persistent_value.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/persistent_value.h" 4 | 5 | #include "polyscope/render/color_maps.h" 6 | 7 | namespace polyscope { 8 | namespace detail { 9 | // storage for persistent value global caches 10 | // clang-format off 11 | PersistentCache persistentCache_double; 12 | PersistentCache persistentCache_float; 13 | PersistentCache persistentCache_bool; 14 | PersistentCache persistentCache_string; 15 | PersistentCache persistentCache_glmvec3; 16 | PersistentCache persistentCache_glmmat4; 17 | PersistentCache> persistentCache_scaleddouble; 18 | PersistentCache> persistentCache_scaledfloat; 19 | PersistentCache> persistentCache_vectorstring; 20 | PersistentCache persistentCache_paramVizStyle; 21 | PersistentCache persistentCache_BackFacePolicy; 22 | PersistentCache persistentCache_MeshNormalType; 23 | PersistentCache persistentCache_FilterMode; 24 | PersistentCache persistentCache_IsolineStyle; 25 | PersistentCache persistentCache_MeshSelectionMode; 26 | // clang-format on 27 | } // namespace detail 28 | } // namespace polyscope 29 | -------------------------------------------------------------------------------- /src/point_cloud_color_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/point_cloud_color_quantity.h" 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | #include "imgui.h" 8 | 9 | namespace polyscope { 10 | 11 | 12 | PointCloudColorQuantity::PointCloudColorQuantity(std::string name, const std::vector& values_, 13 | PointCloud& pointCloud_) 14 | : PointCloudQuantity(name, pointCloud_, true), ColorQuantity(*this, values_) {} 15 | 16 | void PointCloudColorQuantity::draw() { 17 | if (!isEnabled()) return; 18 | 19 | // Make the program if we don't have one already 20 | if (pointProgram == nullptr) { 21 | createPointProgram(); 22 | } 23 | 24 | parent.setStructureUniforms(*pointProgram); 25 | parent.setPointCloudUniforms(*pointProgram); 26 | setColorUniforms(*pointProgram); 27 | render::engine->setMaterialUniforms(*pointProgram, parent.getMaterial()); 28 | 29 | pointProgram->draw(); 30 | } 31 | 32 | std::string PointCloudColorQuantity::niceName() { return name + " (color)"; } 33 | 34 | void PointCloudColorQuantity::createPointProgram() { 35 | 36 | // Create the program to draw this quantity 37 | // clang-format off 38 | pointProgram = render::engine->requestShader( parent.getShaderNameForRenderMode(), 39 | render::engine->addMaterialRules(parent.getMaterial(), 40 | addColorRules( 41 | parent.addPointCloudRules( 42 | {"SPHERE_PROPAGATE_COLOR", "SHADE_COLOR"} 43 | ) 44 | ) 45 | ) 46 | ); 47 | // clang-format on 48 | 49 | parent.setPointProgramGeometryAttributes(*pointProgram); 50 | pointProgram->setAttribute("a_color", colors.getRenderAttributeBuffer()); 51 | 52 | // Fill buffers 53 | render::engine->setMaterial(*pointProgram, parent.getMaterial()); 54 | } 55 | 56 | 57 | void PointCloudColorQuantity::refresh() { 58 | pointProgram.reset(); 59 | Quantity::refresh(); 60 | } 61 | 62 | 63 | void PointCloudColorQuantity::buildPickUI(size_t ind) { 64 | ImGui::TextUnformatted(name.c_str()); 65 | ImGui::NextColumn(); 66 | 67 | glm::vec3 color = colors.getValue(ind); 68 | ImGui::ColorEdit3("", &color[0], ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker); 69 | ImGui::SameLine(); 70 | std::string colorStr = to_string_short(color); 71 | ImGui::TextUnformatted(colorStr.c_str()); 72 | ImGui::NextColumn(); 73 | } 74 | 75 | } // namespace polyscope 76 | -------------------------------------------------------------------------------- /src/point_cloud_parameterization_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/point_cloud_parameterization_quantity.h" 4 | 5 | #include "polyscope/file_helpers.h" 6 | #include "polyscope/polyscope.h" 7 | #include "polyscope/render/engine.h" 8 | 9 | #include "imgui.h" 10 | 11 | namespace polyscope { 12 | 13 | PointCloudParameterizationQuantity::PointCloudParameterizationQuantity(std::string name, PointCloud& cloud_, 14 | const std::vector& coords_, 15 | ParamCoordsType type_, ParamVizStyle style_) 16 | : PointCloudQuantity(name, cloud_, true), ParameterizationQuantity(*this, coords_, type_, style_) {} 17 | 18 | 19 | void PointCloudParameterizationQuantity::draw() { 20 | if (!isEnabled()) return; 21 | 22 | if (program == nullptr) { 23 | createProgram(); 24 | } 25 | 26 | // Set uniforms 27 | setParameterizationUniforms(*program); 28 | parent.setStructureUniforms(*program); 29 | parent.setPointCloudUniforms(*program); 30 | render::engine->setMaterialUniforms(*program, parent.getMaterial()); 31 | 32 | program->draw(); 33 | } 34 | 35 | void PointCloudParameterizationQuantity::createProgram() { 36 | 37 | // Create the program to draw this quantity 38 | // clang-format off 39 | program = render::engine->requestShader(parent.getShaderNameForRenderMode(), 40 | render::engine->addMaterialRules(parent.getMaterial(), 41 | parent.addPointCloudRules( 42 | addParameterizationRules( 43 | {"SPHERE_PROPAGATE_VALUE2"} 44 | ) 45 | ) 46 | ) 47 | ); 48 | // clang-format on 49 | 50 | // Fill buffers 51 | fillCoordBuffers(*program); 52 | fillParameterizationBuffers(*program); 53 | parent.setPointProgramGeometryAttributes(*program); 54 | 55 | render::engine->setMaterial(*program, parent.getMaterial()); 56 | } 57 | 58 | void PointCloudParameterizationQuantity::fillCoordBuffers(render::ShaderProgram& p) { 59 | p.setAttribute("a_value2", coords.getRenderAttributeBuffer()); 60 | } 61 | 62 | void PointCloudParameterizationQuantity::buildCustomUI() { 63 | ImGui::SameLine(); 64 | 65 | // == Options popup 66 | if (ImGui::Button("Options")) { 67 | ImGui::OpenPopup("OptionsPopup"); 68 | } 69 | if (ImGui::BeginPopup("OptionsPopup")) { 70 | 71 | buildParameterizationOptionsUI(); 72 | 73 | ImGui::EndPopup(); 74 | } 75 | 76 | buildParameterizationUI(); 77 | } 78 | 79 | void PointCloudParameterizationQuantity::refresh() { 80 | program.reset(); 81 | Quantity::refresh(); 82 | } 83 | 84 | std::string PointCloudParameterizationQuantity::niceName() { return name + " (parameterization)"; } 85 | 86 | void PointCloudParameterizationQuantity::buildPickUI(size_t ind) { 87 | 88 | glm::vec2 coord = coords.getValue(ind); 89 | 90 | ImGui::TextUnformatted(name.c_str()); 91 | ImGui::NextColumn(); 92 | ImGui::Text("<%g,%g>", coord.x, coord.y); 93 | ImGui::NextColumn(); 94 | } 95 | 96 | 97 | } // namespace polyscope 98 | -------------------------------------------------------------------------------- /src/point_cloud_scalar_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/point_cloud_scalar_quantity.h" 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | #include "imgui.h" 8 | 9 | namespace polyscope { 10 | 11 | 12 | PointCloudScalarQuantity::PointCloudScalarQuantity(std::string name, const std::vector& values_, 13 | PointCloud& pointCloud_, DataType dataType_) 14 | : PointCloudQuantity(name, pointCloud_, true), ScalarQuantity(*this, values_, dataType_) {} 15 | 16 | void PointCloudScalarQuantity::draw() { 17 | if (!isEnabled()) return; 18 | 19 | // Make the program if we don't have one already 20 | if (pointProgram == nullptr) { 21 | createProgram(); 22 | } 23 | 24 | // Set uniforms 25 | parent.setStructureUniforms(*pointProgram); 26 | parent.setPointCloudUniforms(*pointProgram); 27 | setScalarUniforms(*pointProgram); 28 | render::engine->setMaterialUniforms(*pointProgram, parent.getMaterial()); 29 | 30 | pointProgram->draw(); 31 | } 32 | 33 | 34 | void PointCloudScalarQuantity::buildCustomUI() { 35 | ImGui::SameLine(); 36 | 37 | // == Options popup 38 | if (ImGui::Button("Options")) { 39 | ImGui::OpenPopup("OptionsPopup"); 40 | } 41 | if (ImGui::BeginPopup("OptionsPopup")) { 42 | 43 | buildScalarOptionsUI(); 44 | 45 | ImGui::EndPopup(); 46 | } 47 | 48 | buildScalarUI(); 49 | } 50 | 51 | 52 | void PointCloudScalarQuantity::createProgram() { 53 | 54 | // Create the program to draw this quantity 55 | // clang-format off 56 | pointProgram = render::engine->requestShader( 57 | parent.getShaderNameForRenderMode(), 58 | parent.addPointCloudRules( 59 | render::engine->addMaterialRules(parent.getMaterial(), 60 | addScalarRules( 61 | {"SPHERE_PROPAGATE_VALUE"} 62 | ) 63 | ) 64 | ) 65 | ); 66 | // clang-format on 67 | 68 | parent.setPointProgramGeometryAttributes(*pointProgram); 69 | pointProgram->setAttribute("a_value", values.getRenderAttributeBuffer()); 70 | 71 | // Fill buffers 72 | pointProgram->setTextureFromColormap("t_colormap", cMap.get()); 73 | render::engine->setMaterial(*pointProgram, parent.getMaterial()); 74 | } 75 | 76 | 77 | void PointCloudScalarQuantity::refresh() { 78 | pointProgram.reset(); 79 | Quantity::refresh(); 80 | } 81 | 82 | void PointCloudScalarQuantity::buildPickUI(size_t ind) { 83 | ImGui::TextUnformatted(name.c_str()); 84 | ImGui::NextColumn(); 85 | ImGui::Text("%g", values.getValue(ind)); 86 | ImGui::NextColumn(); 87 | } 88 | 89 | 90 | std::string PointCloudScalarQuantity::niceName() { return name + " (scalar)"; } 91 | 92 | } // namespace polyscope 93 | -------------------------------------------------------------------------------- /src/point_cloud_vector_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/point_cloud_vector_quantity.h" 4 | 5 | #include "polyscope/file_helpers.h" 6 | #include "polyscope/polyscope.h" 7 | 8 | #include "imgui.h" 9 | 10 | #include 11 | #include 12 | 13 | namespace polyscope { 14 | 15 | PointCloudVectorQuantity::PointCloudVectorQuantity(std::string name, std::vector vectors_, 16 | PointCloud& pointCloud_, VectorType vectorType_) 17 | 18 | : PointCloudQuantity(name, pointCloud_), 19 | VectorQuantity(*this, vectors_, parent.points, vectorType_) {} 20 | 21 | void PointCloudVectorQuantity::draw() { 22 | if (!isEnabled()) return; 23 | drawVectors(); 24 | } 25 | 26 | void PointCloudVectorQuantity::refresh() { 27 | refreshVectors(); 28 | Quantity::refresh(); 29 | } 30 | 31 | void PointCloudVectorQuantity::buildCustomUI() { buildVectorUI(); } 32 | 33 | void PointCloudVectorQuantity::buildPickUI(size_t ind) { 34 | ImGui::TextUnformatted(name.c_str()); 35 | ImGui::NextColumn(); 36 | 37 | std::stringstream buffer; 38 | glm::vec3 vec = vectors.getValue(ind); 39 | buffer << vec; 40 | ImGui::TextUnformatted(buffer.str().c_str()); 41 | 42 | ImGui::NextColumn(); 43 | ImGui::NextColumn(); 44 | ImGui::Text("magnitude: %g", glm::length(vec)); 45 | ImGui::NextColumn(); 46 | } 47 | 48 | 49 | std::string PointCloudVectorQuantity::niceName() { return name + " (vector)"; } 50 | 51 | } // namespace polyscope 52 | -------------------------------------------------------------------------------- /src/quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/quantity.h" 4 | 5 | #include "imgui.h" 6 | 7 | #include "polyscope/messages.h" 8 | #include "polyscope/structure.h" 9 | 10 | namespace polyscope { 11 | 12 | // === General Quantities 13 | // (subclasses could be a structure-specific quantity or a floating quantity) 14 | 15 | Quantity::Quantity(std::string name_, Structure& parentStructure_) 16 | : parent(parentStructure_), name(name_), enabled(uniquePrefix() + "enabled", false) { 17 | validateName(name); 18 | } 19 | 20 | Quantity::~Quantity() {}; 21 | 22 | void Quantity::draw() {} 23 | 24 | void Quantity::drawDelayed() {} 25 | 26 | void Quantity::buildUI() {} 27 | 28 | void Quantity::buildCustomUI() {} 29 | 30 | void Quantity::buildPickUI(size_t localPickInd) {} 31 | 32 | bool Quantity::isEnabled() { return enabled.get(); } 33 | 34 | void Quantity::refresh() { requestRedraw(); } 35 | 36 | std::string Quantity::niceName() { return name; } 37 | 38 | std::string Quantity::uniquePrefix() { return parent.uniquePrefix() + name + "#"; } 39 | 40 | } // namespace polyscope 41 | -------------------------------------------------------------------------------- /src/raw_color_render_image_quantity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #include "polyscope/polyscope.h" 5 | 6 | #include "polyscope/raw_color_render_image_quantity.h" 7 | 8 | #include "imgui.h" 9 | #include "polyscope/render/engine.h" 10 | 11 | namespace polyscope { 12 | 13 | 14 | RawColorRenderImageQuantity::RawColorRenderImageQuantity(Structure& parent_, std::string name, size_t dimX, size_t dimY, 15 | const std::vector& depthData, 16 | const std::vector& colorsData_, 17 | ImageOrigin imageOrigin) 18 | : RenderImageQuantityBase(parent_, name, dimX, dimY, depthData, std::vector(), imageOrigin), 19 | colors(this, uniquePrefix() + "colors", colorsData), colorsData(colorsData_) { 20 | colors.setTextureSize(dimX, dimY); 21 | } 22 | 23 | void RawColorRenderImageQuantity::draw() {} 24 | 25 | void RawColorRenderImageQuantity::drawDelayed() { 26 | if (!isEnabled()) return; 27 | 28 | if (!program) prepare(); 29 | 30 | // set uniforms 31 | glm::mat4 P = view::getCameraPerspectiveMatrix(); 32 | glm::mat4 Pinv = glm::inverse(P); 33 | 34 | program->setUniform("u_projMatrix", glm::value_ptr(P)); 35 | program->setUniform("u_invProjMatrix", glm::value_ptr(Pinv)); 36 | program->setUniform("u_viewport", render::engine->getCurrentViewport()); 37 | program->setUniform("u_transparency", transparency.get()); 38 | render::engine->setTonemapUniforms(*program); 39 | 40 | // draw 41 | program->draw(); 42 | } 43 | 44 | void RawColorRenderImageQuantity::buildCustomUI() { 45 | ImGui::SameLine(); 46 | 47 | // == Options popup 48 | if (ImGui::Button("Options")) { 49 | ImGui::OpenPopup("OptionsPopup"); 50 | } 51 | if (ImGui::BeginPopup("OptionsPopup")) { 52 | 53 | RenderImageQuantityBase::addOptionsPopupEntries(); 54 | 55 | ImGui::EndPopup(); 56 | } 57 | } 58 | 59 | 60 | void RawColorRenderImageQuantity::refresh() { 61 | program = nullptr; 62 | RenderImageQuantityBase::refresh(); 63 | } 64 | 65 | 66 | void RawColorRenderImageQuantity::prepare() { 67 | 68 | // Create the sourceProgram 69 | program = render::engine->requestShader( 70 | "TEXTURE_DRAW_RAW_RENDERIMAGE_PLAIN", 71 | {getImageOriginRule(imageOrigin), "TEXTURE_SHADE_COLOR", "INVERSE_TONEMAP", "PREMULTIPLY_LIT_COLOR"}, 72 | render::ShaderReplacementDefaults::Process); 73 | 74 | program->setAttribute("a_position", render::engine->screenTrianglesCoords()); 75 | program->setTextureFromBuffer("t_depth", depths.getRenderTextureBuffer().get()); 76 | program->setTextureFromBuffer("t_color", colors.getRenderTextureBuffer().get()); 77 | } 78 | 79 | 80 | std::string RawColorRenderImageQuantity::niceName() { return name + " (raw color render image)"; } 81 | 82 | // Instantiate a construction helper which is used to avoid header dependencies. See forward declaration and note in 83 | // structure.ipp. 84 | RawColorRenderImageQuantity* createRawColorRenderImage(Structure& parent, std::string name, size_t dimX, size_t dimY, 85 | const std::vector& depthData, 86 | const std::vector& colorData, 87 | ImageOrigin imageOrigin) { 88 | return new RawColorRenderImageQuantity(parent, name, dimX, dimY, depthData, colorData, imageOrigin); 89 | } 90 | 91 | } // namespace polyscope 92 | -------------------------------------------------------------------------------- /src/render/materials.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/render/materials.h" 4 | 5 | #include "polyscope/messages.h" 6 | #include "polyscope/render/engine.h" 7 | #include "polyscope/render/material_defs.h" 8 | 9 | #include "imgui.h" 10 | 11 | #include "stb_image.h" 12 | 13 | namespace polyscope { 14 | namespace render { 15 | 16 | bool buildMaterialOptionsGui(std::string& mat) { 17 | if (ImGui::BeginMenu("Material")) { 18 | for (const std::unique_ptr& o : render::engine->materials) { 19 | bool selected = (o->name == mat); 20 | std::string fancyName = o->name; 21 | if (o->supportsRGB) { 22 | fancyName += " (rgb)"; 23 | } 24 | if (ImGui::MenuItem(fancyName.c_str(), NULL, selected)) { 25 | mat = o->name; 26 | ImGui::EndMenu(); 27 | return true; 28 | } 29 | } 30 | ImGui::EndMenu(); 31 | } 32 | return false; 33 | } 34 | 35 | } // namespace render 36 | 37 | void loadBlendableMaterial(std::string matName, std::array filenames) { 38 | render::engine->loadBlendableMaterial(matName, filenames); 39 | } 40 | void loadBlendableMaterial(std::string matName, std::string filenameBase, std::string filenameExt) { 41 | render::engine->loadBlendableMaterial(matName, filenameBase, filenameExt); 42 | } 43 | void loadStaticMaterial(std::string matName, std::string filename) { 44 | render::engine->loadStaticMaterial(matName, filename); 45 | } 46 | 47 | } // namespace polyscope 48 | -------------------------------------------------------------------------------- /src/render/opengl/shaders/histogram_shaders.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #include "polyscope/render/opengl/shaders/histogram_shaders.h" 5 | 6 | namespace polyscope { 7 | namespace render { 8 | namespace backend_openGL3 { 9 | 10 | // clang-format off 11 | 12 | const ShaderStageSpecification HISTOGRAM_VERT_SHADER = { 13 | 14 | ShaderStageType::Vertex, 15 | 16 | {}, // uniforms 17 | 18 | // attributes 19 | { 20 | {"a_coord", RenderDataType::Vector2Float}, 21 | }, 22 | 23 | {}, // textures 24 | 25 | // source 26 | R"( 27 | ${ GLSL_VERSION }$ 28 | in vec2 a_coord; 29 | 30 | out float shadeValueRaw; 31 | 32 | void main() 33 | { 34 | shadeValueRaw = a_coord.x; 35 | vec2 scaledCoord = vec2(a_coord.x, a_coord.y * .85); 36 | gl_Position = vec4(2.*scaledCoord - vec2(1.0, 1.0),0.,1.); 37 | } 38 | )" 39 | }; 40 | 41 | const ShaderStageSpecification HISTOGRAM_FRAG_SHADER = { 42 | 43 | ShaderStageType::Fragment, 44 | 45 | // uniforms 46 | { 47 | }, 48 | 49 | // attributes 50 | { 51 | }, 52 | 53 | // textures 54 | { 55 | }, 56 | 57 | // source 58 | R"( 59 | ${ GLSL_VERSION }$ 60 | 61 | in float shadeValueRaw; 62 | 63 | ${ FRAG_DECLARATIONS }$ 64 | 65 | layout(location = 0) out vec4 outputF; 66 | 67 | void main() 68 | { 69 | 70 | float shadeValue = shadeValueRaw; 71 | 72 | ${ GENERATE_SHADE_COLOR }$ 73 | 74 | // Darken when outside range 75 | float darkFactor = 1.0; 76 | if(shadeValue < u_rangeLow || shadeValue > u_rangeHigh) { 77 | darkFactor = 0.6; 78 | } 79 | 80 | outputF = vec4(darkFactor*albedoColor.rgb, 1.0); 81 | } 82 | )" 83 | }; 84 | 85 | const ShaderStageSpecification HISTOGRAM_CATEGORICAL_FRAG_SHADER = { 86 | 87 | ShaderStageType::Fragment, 88 | 89 | // uniforms 90 | { 91 | {"u_dataRangeLow", RenderDataType::Float}, 92 | {"u_dataRangeHigh", RenderDataType::Float} 93 | }, 94 | 95 | // attributes 96 | { 97 | }, 98 | 99 | // textures 100 | { 101 | }, 102 | 103 | // source 104 | R"( 105 | ${ GLSL_VERSION }$ 106 | 107 | in float shadeValueRaw; 108 | uniform float u_dataRangeLow; 109 | uniform float u_dataRangeHigh; 110 | 111 | ${ FRAG_DECLARATIONS }$ 112 | 113 | layout(location = 0) out vec4 outputF; 114 | 115 | void main() 116 | { 117 | 118 | // Used to restore [0,1] tvals to the orininal data range for the categorical int remapping 119 | float shadeValue = mix(u_dataRangeLow, u_dataRangeHigh, shadeValueRaw); 120 | 121 | ${ GENERATE_SHADE_COLOR }$ 122 | 123 | outputF = vec4(albedoColor.rgb, 1.0); 124 | } 125 | )" 126 | }; 127 | 128 | // clang-format on 129 | 130 | } // namespace backend_openGL3 131 | } // namespace render 132 | } // namespace polyscope 133 | -------------------------------------------------------------------------------- /src/state.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/polyscope.h" 4 | 5 | namespace polyscope { 6 | 7 | namespace state { 8 | 9 | 10 | Context globalContext; 11 | 12 | // Map all of the named global variables as references to the context struct 13 | bool& initialized = globalContext.initialized; 14 | std::string& backend = globalContext.backend; 15 | std::map>>& structures = globalContext.structures; 16 | std::map>& groups = globalContext.groups; 17 | float& lengthScale = globalContext.lengthScale; 18 | std::tuple& boundingBox = globalContext.boundingBox; 19 | std::vector>& slicePlanes = globalContext.slicePlanes; 20 | std::vector>& widgets = globalContext.widgets; 21 | bool& doDefaultMouseInteraction = globalContext.doDefaultMouseInteraction; 22 | std::function& userCallback = globalContext.userCallback; 23 | 24 | } // namespace state 25 | } // namespace polyscope 26 | -------------------------------------------------------------------------------- /src/weak_handle.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/weak_handle.h" 4 | #include "polyscope/internal.h" 5 | 6 | namespace polyscope { 7 | 8 | WeakReferrable::WeakReferrable() 9 | : weakReferrableDummyRef(new WeakHandleDummyType()), weakReferableUniqueID(internal::getNextUniqueID()) {} 10 | 11 | bool GenericWeakHandle::isValid() const { return !sentinel.expired(); }; 12 | 13 | void GenericWeakHandle::reset() { sentinel.reset(); }; 14 | 15 | uint64_t GenericWeakHandle::getUniqueID() const { return targetUniqueID; }; 16 | 17 | 18 | } // namespace polyscope 19 | -------------------------------------------------------------------------------- /src/widget.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope/widget.h" 4 | 5 | #include "polyscope/polyscope.h" 6 | 7 | namespace polyscope { 8 | 9 | Widget::Widget() { state::widgets.push_back(getWeakHandle(this)); } 10 | 11 | Widget::~Widget() {} 12 | 13 | void Widget::draw() {} 14 | bool Widget::interact() { return false; } 15 | void Widget::buildGUI() {} 16 | 17 | } // namespace polyscope 18 | -------------------------------------------------------------------------------- /test/CMakeLists.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2...3.22) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG main 9 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 10 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 11 | CONFIGURE_COMMAND "" 12 | BUILD_COMMAND "" 13 | INSTALL_COMMAND "" 14 | TEST_COMMAND "" 15 | ) 16 | -------------------------------------------------------------------------------- /test/src/interop_and_serialization_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope_test.h" 4 | 5 | 6 | // ============================================================ 7 | // =============== Managed Buffer Access 8 | // ============================================================ 9 | 10 | TEST_F(PolyscopeTest, ManagedBufferAccess) { 11 | 12 | // register point cloud 13 | auto psPoints = registerPointCloud("test_cloud1"); 14 | std::vector vScalar(psPoints->nPoints(), 7.); 15 | auto q2 = psPoints->addScalarQuantity("vScalar", vScalar); 16 | q2->setEnabled(true); 17 | 18 | 19 | // make sure we can get its buffers 20 | polyscope::render::ManagedBuffer& bufferPos = psPoints->getManagedBuffer("points"); 21 | polyscope::render::ManagedBuffer& bufferScalar = q2->getManagedBuffer("values"); 22 | 23 | 24 | size_t dimX = 300; 25 | size_t dimY = 200; 26 | // register an image quantity 27 | std::vector> valsRGB(dimX * dimY, std::array{0.44, 0.55, 0.66}); 28 | polyscope::ColorImageQuantity* im = 29 | polyscope::addColorImageQuantity("im color", dimX, dimY, valsRGB, polyscope::ImageOrigin::UpperLeft); 30 | 31 | // make sure we can get its buffers 32 | polyscope::render::ManagedBuffer& bufferColor = im->getManagedBuffer("colors"); 33 | 34 | polyscope::removeAllStructures(); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/main_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | 4 | #include "polyscope_test.h" 5 | 6 | #include "gtest/gtest.h" 7 | 8 | #include 9 | #include 10 | 11 | using std::cout; 12 | using std::endl; 13 | 14 | // The global polyscope backend setting for tests 15 | std::string testBackend = "openGL_mock"; 16 | 17 | TEST(BasicTest, HelloWorldTest) { 18 | int two = 2; 19 | int four = two + two; 20 | EXPECT_EQ(four, 4); 21 | } 22 | 23 | int main(int argc, char** argv) { 24 | ::testing::InitGoogleTest(&argc, argv); 25 | 26 | // Process custom test args 27 | for (int i = 1; i < argc; ++i) { 28 | std::string arg(argv[i]); 29 | std::cout << "got arg " << arg << std::endl; 30 | 31 | { // look for a backend setting 32 | std::string prefix = "backend="; 33 | auto p = arg.rfind(prefix, 0); 34 | if (p == 0) { 35 | std::string val = arg.substr(prefix.size(), std::string::npos); 36 | testBackend = val; 37 | continue; 38 | } 39 | } 40 | 41 | throw std::runtime_error("unrecognized argument " + arg); 42 | } 43 | 44 | return RUN_ALL_TESTS(); 45 | } 46 | -------------------------------------------------------------------------------- /test/src/misc_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run 2 | 3 | #include "polyscope_test.h" 4 | 5 | // ============================================================ 6 | // =============== Scalar Quantity Tests 7 | // ============================================================ 8 | 9 | // We test these on a point cloud because it is convenient, but really we are testing the scalar quantity 10 | 11 | TEST_F(PolyscopeTest, TestScalarQuantity) { 12 | auto psPoints = registerPointCloud(); 13 | 14 | std::vector vScalar(psPoints->nPoints(), 7.); 15 | auto q1 = psPoints->addScalarQuantity("vScalar", vScalar); 16 | q1->setEnabled(true); 17 | polyscope::show(3); 18 | 19 | // get map range 20 | std::pair newRange = {-1., 1.}; 21 | q1->setMapRange(newRange); 22 | EXPECT_EQ(newRange, q1->getMapRange()); 23 | 24 | 25 | polyscope::show(3); 26 | 27 | polyscope::removeAllStructures(); 28 | } 29 | 30 | // ============================================================ 31 | // =============== Materials tests 32 | // ============================================================ 33 | 34 | TEST_F(PolyscopeTest, FlatMaterialTest) { 35 | auto psMesh = registerTriangleMesh(); 36 | 37 | // Test the flat material, it uses custom rules & uniforms and thus is different from others 38 | psMesh->setMaterial("flat"); 39 | EXPECT_EQ(psMesh->getMaterial(), "flat"); 40 | polyscope::show(3); 41 | 42 | polyscope::removeAllStructures(); 43 | } 44 | --------------------------------------------------------------------------------