├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── config.cmake.in ├── data └── scan.pcd ├── img ├── 1.png ├── 2.png ├── 3.png ├── 4.png └── example │ ├── scene1.png │ ├── scene2.png │ ├── scene3.png │ ├── scene4.png │ ├── scene5.png │ └── scene6.png ├── output ├── 1683550379929702850.png ├── 1683612946010494123.png ├── 1683622164831973710.png ├── 1683702144062947378.png ├── 1683726471910906777.png ├── 1683794904023740133.view └── 1683795147461499635.cam ├── readme.md └── src ├── CMakeLists.txt ├── include └── tiny-viewer │ ├── core │ ├── multi_viewer.h │ ├── pose.hpp │ ├── rendertree.h │ ├── shader.h │ ├── utils.hpp │ ├── viewer.h │ └── viewer_configor.h │ ├── entity │ ├── arrow.h │ ├── circle.h │ ├── cone.h │ ├── coordinate.h │ ├── cube.h │ ├── cylinder.h │ ├── entity.h │ ├── line.h │ ├── path.h │ ├── point_cloud.hpp │ ├── polygon.h │ └── utils.h │ └── object │ ├── aligned_cloud.hpp │ ├── camera.h │ ├── imu.h │ ├── landmark.h │ ├── lidar.h │ ├── plane.h │ ├── radar.h │ └── surfel.h ├── main.cpp └── src ├── core ├── multi_viewer.cpp ├── pose.cpp ├── viewer.cpp └── viewer_configor.cpp ├── entity ├── arrow.cpp ├── circle.cpp ├── cone.cpp ├── coordinate.cpp ├── cube.cpp ├── cylinder.cpp ├── entity.cpp ├── line.cpp ├── path.cpp ├── polygon.cpp └── util.cpp └── object ├── camera.cpp ├── imu.cpp ├── landmark.cpp ├── lidar.cpp ├── plane.cpp ├── radar.cpp └── surfel.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | AccessModifierOffset: -4 5 | Standard: c++17 6 | IndentWidth: 4 7 | TabWidth: 4 8 | UseTab: Never 9 | ColumnLimit: 100 10 | AlignAfterOpenBracket: Align 11 | BinPackParameters: false 12 | AlignEscapedNewlines: Left 13 | AlwaysBreakTemplateDeclarations: Yes 14 | PackConstructorInitializers: Never 15 | BreakConstructorInitializersBeforeComma: false 16 | IndentPPDirectives: BeforeHash 17 | SortIncludes: Never 18 | ... 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /cmake-build-debug/ 3 | /cmake-build-release/ 4 | /build 5 | /config 6 | /install -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | # Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | # https://github.com/Unsigned-Long/tiny-viewer.git 4 | # 5 | # Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | # GitHub: https://github.com/Unsigned-Long 7 | # ORCID: 0000-0002-5283-9057 8 | # 9 | # Purpose: See .h/.hpp file. 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions are met: 13 | # 14 | # * Redistributions of source code must retain the above copyright notice, 15 | # this list of conditions and the following disclaimer. 16 | # * Redistributions in binary form must reproduce the above copyright notice, 17 | # this list of conditions and the following disclaimer in the documentation 18 | # and/or other materials provided with the distribution. 19 | # * The names of its contributors can not be 20 | # used to endorse or promote products derived from this software without 21 | # specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | 35 | cmake_minimum_required(VERSION 3.16) 36 | 37 | project(tiny-viewer VERSION 1.0) 38 | 39 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3") 40 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3") 41 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native") 42 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native") 43 | 44 | # ---------------------- 45 | # set lib name and space 46 | # ---------------------- 47 | set(LIBRARY_NAME tiny-viewer) 48 | 49 | set(CMAKE_CXX_STANDARD 17) 50 | 51 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 52 | 53 | set(CMAKE_BUILD_TYPE "Release") 54 | 55 | #if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16") 56 | # set(CMAKE_UNITY_BUILD ON) 57 | # message(STATUS "use 'CMAKE_UNITY_BUILD' in building!") 58 | #else () 59 | # message(STATUS "do not use 'CMAKE_UNITY_BUILD' in building!") 60 | #endif () 61 | 62 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3") 63 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3") 64 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native") 65 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native") 66 | 67 | if (NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS) 68 | set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings") 69 | endif () 70 | 71 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) 72 | 73 | # ----------- 74 | # for install 75 | # ----------- 76 | 77 | # Configuration 78 | set(CONFIG_INSTALL_DIR "lib/cmake/${LIBRARY_NAME}") 79 | set(INCLUDE_INSTALL_DIR "include") 80 | set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_NAME}ConfigVersion.cmake") 81 | set(PROJ_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_NAME}Config.cmake") 82 | set(TARGETS_EXPORT_NAME "${LIBRARY_NAME}Targets") 83 | 84 | # Include module with function 'write_basic_package_version_file' 85 | include(CMakePackageConfigHelpers) 86 | 87 | write_basic_package_version_file("${VERSION_CONFIG}" COMPATIBILITY SameMajorVersion) 88 | 89 | configure_package_config_file( 90 | ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in 91 | "${PROJ_CONFIG}" 92 | INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}" 93 | ) 94 | 95 | export( 96 | TARGETS ${LIBRARY_NAME} 97 | FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_EXPORT_NAME}.cmake" 98 | ) 99 | 100 | install( 101 | TARGETS ${LIBRARY_NAME} 102 | EXPORT "${TARGETS_EXPORT_NAME}" 103 | LIBRARY DESTINATION "lib" 104 | ARCHIVE DESTINATION "lib" 105 | RUNTIME DESTINATION "bin" 106 | INCLUDES DESTINATION "${INCLUDE_INSTALL_DIR}" 107 | ) 108 | 109 | install( 110 | FILES "${PROJ_CONFIG}" "${VERSION_CONFIG}" 111 | DESTINATION "${CONFIG_INSTALL_DIR}" 112 | ) 113 | 114 | install( 115 | EXPORT "${TARGETS_EXPORT_NAME}" 116 | NAMESPACE "${namespace}" 117 | DESTINATION "${CONFIG_INSTALL_DIR}" 118 | ) 119 | 120 | install( 121 | DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/include/${LIBRARY_NAME} 122 | DESTINATION ${INCLUDE_INSTALL_DIR} 123 | FILES_MATCHING PATTERN "*.h" 124 | PATTERN "*.hpp" 125 | ) -------------------------------------------------------------------------------- /config.cmake.in: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | find_dependency(PCL REQUIRED) 4 | find_dependency(Eigen3 REQUIRED) 5 | find_dependency(Pangolin REQUIRED) 6 | 7 | # Add the targets file 8 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 9 | -------------------------------------------------------------------------------- /data/scan.pcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/data/scan.pcd -------------------------------------------------------------------------------- /img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/1.png -------------------------------------------------------------------------------- /img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/2.png -------------------------------------------------------------------------------- /img/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/3.png -------------------------------------------------------------------------------- /img/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/4.png -------------------------------------------------------------------------------- /img/example/scene1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene1.png -------------------------------------------------------------------------------- /img/example/scene2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene2.png -------------------------------------------------------------------------------- /img/example/scene3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene3.png -------------------------------------------------------------------------------- /img/example/scene4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene4.png -------------------------------------------------------------------------------- /img/example/scene5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene5.png -------------------------------------------------------------------------------- /img/example/scene6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/img/example/scene6.png -------------------------------------------------------------------------------- /output/1683550379929702850.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683550379929702850.png -------------------------------------------------------------------------------- /output/1683612946010494123.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683612946010494123.png -------------------------------------------------------------------------------- /output/1683622164831973710.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683622164831973710.png -------------------------------------------------------------------------------- /output/1683702144062947378.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683702144062947378.png -------------------------------------------------------------------------------- /output/1683726471910906777.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683726471910906777.png -------------------------------------------------------------------------------- /output/1683794904023740133.view: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unsigned-Long/tiny-viewer/c4591290bf26c9d9c3670fcdfa5509bf85a1ba50/output/1683794904023740133.view -------------------------------------------------------------------------------- /output/1683795147461499635.cam: -------------------------------------------------------------------------------- 1 | { 2 | "cam_view": { 3 | "projection_mat": { 4 | "value0": 1.3125, 5 | "value1": 0.0, 6 | "value2": 0.0, 7 | "value3": 0.0, 8 | "value4": 0.0, 9 | "value5": 1.75, 10 | "value6": 0.0, 11 | "value7": 0.0, 12 | "value8": 0.0, 13 | "value9": 0.0, 14 | "value10": -1.0002000200020003, 15 | "value11": -1.0, 16 | "value12": 0.0, 17 | "value13": 0.0, 18 | "value14": -0.020002000200020004, 19 | "value15": 0.0 20 | }, 21 | "model_view_mat": { 22 | "value0": -0.760960158594116, 23 | "value1": -0.37733237263677107, 24 | "value2": -0.5277877580928914, 25 | "value3": 0.0, 26 | "value4": 0.47102647797028149, 27 | "value5": -0.8807314320628381, 28 | "value6": -0.04945909044302958, 29 | "value7": 0.0, 30 | "value8": -0.44617675206506265, 31 | "value9": -0.2862384061177736, 32 | "value10": 0.8479350687286286, 33 | "value11": 0.0, 34 | "value12": 1.3506747675140756, 35 | "value13": 3.3587839151980845, 36 | "value14": -8.198162087713554, 37 | "value15": 1.0 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Tiny-Viewer 2 | 3 | ## 1. Overview 4 | 5 | Try to draw sample but beautiful entities & objects in the pangolin-based scene viewer! 6 | 7 | 8 | 9 | ## 2. Examples 10 | 11 |
12 | 13 | River 14 | 15 | 16 | MI-Calib 17 | 18 | 19 | RIs-Calib 20 | 21 | 22 | iKalibr 23 | 24 | 25 | iKalibr 26 | 27 | 28 | iKalibr 29 | 30 |
31 | 32 | ## 3. Why 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | # Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | # https://github.com/Unsigned-Long/tiny-viewer.git 4 | # 5 | # Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | # GitHub: https://github.com/Unsigned-Long 7 | # ORCID: 0000-0002-5283-9057 8 | # 9 | # Purpose: See .h/.hpp file. 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions are met: 13 | # 14 | # * Redistributions of source code must retain the above copyright notice, 15 | # this list of conditions and the following disclaimer. 16 | # * Redistributions in binary form must reproduce the above copyright notice, 17 | # this list of conditions and the following disclaimer in the documentation 18 | # and/or other materials provided with the distribution. 19 | # * The names of its contributors can not be 20 | # used to endorse or promote products derived from this software without 21 | # specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | 35 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 36 | 37 | find_package(Eigen3 REQUIRED) 38 | find_package(PCL REQUIRED) 39 | find_package(Pangolin REQUIRED) 40 | 41 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/core CORE_SRC_FILES) 42 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/entity ENTITY_SRC_FILES) 43 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/object OBJECT_SRC_FILES) 44 | 45 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/include/tiny-viewer/core CORE_HEADER_FILES) 46 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/include/tiny-viewer/entity ENTITY_HEADER_FILES) 47 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/include/tiny-viewer/object OBJECT_HEADER_FILES) 48 | 49 | add_library( 50 | ${LIBRARY_NAME} SHARED 51 | ${CORE_SRC_FILES} ${ENTITY_SRC_FILES} ${OBJECT_SRC_FILES} 52 | ${CORE_HEADER_FILES} ${ENTITY_HEADER_FILES} ${OBJECT_HEADER_FILES} 53 | ) 54 | 55 | set(ADDITIONAL_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIRS} ${Pangolin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS}) 56 | 57 | target_include_directories( 58 | ${LIBRARY_NAME} PUBLIC 59 | # only when building from the source tree 60 | $ 61 | # only when using the lib from the install path 62 | $ 63 | ${ADDITIONAL_INCLUDE_DIRS} 64 | ) 65 | 66 | target_link_libraries( 67 | ${LIBRARY_NAME} PUBLIC 68 | ${PCL_LIBRARIES} 69 | ${Pangolin_LIBRARIES} 70 | pthread 71 | ) 72 | 73 | # example & test 74 | 75 | add_executable(${PROJECT_NAME}_prog ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) 76 | 77 | target_link_libraries( 78 | ${PROJECT_NAME}_prog PRIVATE 79 | ${LIBRARY_NAME} 80 | ) 81 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/multi_viewer.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_MULTI_VIEWER_H 36 | #define TINY_VIEWER_MULTI_VIEWER_H 37 | 38 | #include "iostream" 39 | #include "memory" 40 | #include "mutex" 41 | #include "pangolin/gl/opengl_render_state.h" 42 | #include "thread" 43 | #include "tiny-viewer/core/viewer_configor.h" 44 | #include 45 | 46 | namespace ns_viewer { 47 | 48 | #define LOCKER_MULTI_VIEWER std::unique_lock viewerLock(MultiViewer::MUTEX); 49 | 50 | struct Entity; 51 | using EntityPtr = std::shared_ptr; 52 | template 53 | struct Pose; 54 | using Posef = Pose; 55 | 56 | class MultiViewer { 57 | public: 58 | using Ptr = std::shared_ptr; 59 | 60 | protected: 61 | MultiViewerConfigor _configor; 62 | std::shared_ptr _thread; 63 | 64 | public: 65 | static std::mutex MUTEX; 66 | 67 | protected: 68 | // sub window name, entities 69 | std::unordered_map> _entities; 70 | std::unordered_map _camView; 71 | bool _isActive; 72 | 73 | std::unordered_map> 74 | _geometries; 75 | 76 | public: 77 | explicit MultiViewer(MultiViewerConfigor configor); 78 | 79 | explicit MultiViewer(const std::string &configPath); 80 | 81 | static Ptr Create(const MultiViewerConfigor &configor); 82 | 83 | static Ptr Create(const std::string &configPath); 84 | 85 | // used for load viewer from file 86 | explicit MultiViewer(char) 87 | : _configor({}), 88 | _thread(nullptr), 89 | _isActive(false) {} 90 | 91 | virtual ~MultiViewer(); 92 | 93 | void RunInSingleThread(); 94 | 95 | void RunInMultiThread(); 96 | 97 | std::size_t AddEntity(const EntityPtr &entity, const std::string &subWinName); 98 | 99 | std::size_t AddObjEntity(const std::string &filename, const std::string &subWinName); 100 | 101 | void RemoveObjEntity(std::size_t id, const std::string &subWinName); 102 | 103 | std::vector AddEntity(const std::vector &entities, 104 | const std::string &subWinName); 105 | 106 | bool RemoveEntity(std::size_t id, const std::string &subWinName); 107 | 108 | bool RemoveEntity(const std::vector &ids, const std::string &subWinName); 109 | 110 | bool RemoveEntity(const std::string &subWinName); 111 | 112 | bool RemoveEntity(); 113 | 114 | void SetCamView(const pangolin::OpenGlRenderState &camView, const std::string &subWinName); 115 | 116 | void SetCamView(const std::string &filename, const std::string &subWinName); 117 | 118 | void SetCamView(Posef T_CamToWorld, const std::string &subWinName); 119 | 120 | void Save(const std::string &filename, bool binaryMode = true) const; 121 | 122 | static Ptr Load(const std::string &filename, bool binaryMode = true); 123 | 124 | MultiViewerConfigor &GetConfigor(); 125 | 126 | bool IsActive() const; 127 | 128 | bool WaitForActive(double waitTimeMs) const; 129 | 130 | protected: 131 | void InitMultiViewer(bool initCamViewFromConfigor); 132 | 133 | void Run(); 134 | 135 | void SaveScreenShotCallBack() const; 136 | 137 | void SaveCameraCallBack() const; 138 | 139 | void SaveMultiViewerCallBack() const; 140 | 141 | void VideoRecordCallBack() const; 142 | 143 | public: 144 | template 145 | void serialize(Archive &archive) { 146 | archive(cereal::make_nvp("configor", _configor), cereal::make_nvp("entities", _entities), 147 | cereal::make_nvp("camera_view", _camView)); 148 | } 149 | }; 150 | } // namespace ns_viewer 151 | 152 | #endif // TINY_VIEWER_MULTI_VIEWER_H 153 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/pose.hpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef SLAM_SCENE_VIEWER_POSE_H 36 | #define SLAM_SCENE_VIEWER_POSE_H 37 | 38 | #include "utils.hpp" 39 | #include "Eigen/Geometry" 40 | #include "random" 41 | #include "chrono" 42 | 43 | namespace ns_viewer { 44 | template 45 | struct Pose { 46 | public: 47 | using Scale = ScalarType; 48 | using Rotation = Matrix; 49 | using Translation = Vector3; 50 | using Transform = Matrix; 51 | 52 | public: 53 | double timeStamp; 54 | Rotation rotation; 55 | Translation translation; 56 | 57 | explicit Pose(const Transform &transform, double timeStamp = INVALID_TIME_STAMP) 58 | : timeStamp(timeStamp), 59 | rotation(transform.topLeftCorner(3, 3)), 60 | translation(transform.topRightCorner(3, 1)) {} 61 | 62 | explicit Pose(const Rotation &rotation = Rotation::Identity(), 63 | const Translation &translation = Translation::Zero(), 64 | double timeStamp = INVALID_TIME_STAMP) 65 | : timeStamp(timeStamp), 66 | rotation(rotation), 67 | translation(translation) {} 68 | 69 | static Pose Random(ScalarType bound) { 70 | std::default_random_engine engine( 71 | std::chrono::steady_clock::now().time_since_epoch().count()); 72 | std::uniform_real_distribution ut(-bound, bound); 73 | std::uniform_real_distribution ur(-M_PI, M_PI); 74 | Translation t(ut(engine), ut(engine), ut(engine)); 75 | Eigen::AngleAxis a1(ur(engine), Translation(0.0, 0.0, 1.0)); 76 | Eigen::AngleAxis a2(ur(engine), Translation(0.0, 1.0, 0.0)); 77 | Eigen::AngleAxis a3(ur(engine), Translation(1.0, 0.0, 0.0)); 78 | Rotation r = (a3 * a2 * a1).toRotationMatrix(); 79 | return Pose(r, t, INVALID_TIME_STAMP); 80 | } 81 | 82 | Transform matrix44() const { 83 | Transform transform = Transform::Identity(); 84 | transform.topLeftCorner(3, 3) = rotation; 85 | transform.topRightCorner(3, 1) = translation; 86 | return transform; 87 | } 88 | 89 | Matrix34 matrix34() const { 90 | ns_viewer::Matrix34 transform = ns_viewer::Matrix34::Identity(); 91 | transform.topLeftCorner(3, 3) = rotation; 92 | transform.topRightCorner(3, 1) = translation; 93 | return transform; 94 | } 95 | 96 | Vector3 trans(const Vector3 &p) const { return rotation * p + translation; } 97 | 98 | Eigen::Quaternion quaternion() const { return Eigen::Quaternion(rotation); } 99 | 100 | Pose inverse() const { 101 | return Pose(rotation.inverse(), -rotation.inverse() * translation, timeStamp); 102 | } 103 | 104 | template 105 | Pose cast() const { 106 | return Pose(rotation.template cast(), 107 | translation.template cast()); 108 | } 109 | }; 110 | 111 | using Posed = Pose; 112 | using Posef = Pose; 113 | 114 | extern template struct Pose; 115 | extern template struct Pose; 116 | } // namespace ns_viewer 117 | 118 | #endif // SLAM_SCENE_VIEWER_POSE_H 119 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/rendertree.h: -------------------------------------------------------------------------------- 1 | 2 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 3 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 4 | // https://github.com/Unsigned-Long/tiny-viewer.git 5 | // 6 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 7 | // GitHub: https://github.com/Unsigned-Long 8 | // ORCID: 0000-0002-5283-9057 9 | // 10 | // Purpose: See .h/.hpp file. 11 | // 12 | // Redistribution and use in source and binary forms, with or without 13 | // modification, are permitted provided that the following conditions are met: 14 | // 15 | // * Redistributions of source code must retain the above copyright notice, 16 | // this list of conditions and the following disclaimer. 17 | // * Redistributions in binary form must reproduce the above copyright notice, 18 | // this list of conditions and the following disclaimer in the documentation 19 | // and/or other materials provided with the distribution. 20 | // * The names of its contributors can not be 21 | // used to endorse or promote products derived from this software without 22 | // specific prior written permission. 23 | // 24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 28 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | // POSSIBILITY OF SUCH DAMAGE. 35 | 36 | #ifndef TINY_VIEWER_RENDER_TREE_H 37 | #define TINY_VIEWER_RENDER_TREE_H 38 | 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | struct Renderable { 45 | virtual ~Renderable() {} 46 | 47 | Renderable() 48 | : show(true) {} 49 | 50 | virtual void Render(pangolin::GlSlProgram & /*prog*/, 51 | const pangolin::GlTexture * /*matcap*/) const {} 52 | 53 | inline virtual Eigen::AlignedBox3f GetAABB() const { return Eigen::AlignedBox3f(); } 54 | 55 | bool show; 56 | }; 57 | 58 | struct GlGeomRenderable : public Renderable { 59 | GlGeomRenderable(pangolin::GlGeometry &&glgeom, const Eigen::AlignedBox3f &aabb) 60 | : glgeom(std::move(glgeom)), 61 | aabb(aabb) {} 62 | 63 | void Render(pangolin::GlSlProgram &prog, const pangolin::GlTexture *matcap) const override { 64 | if (show) { 65 | pangolin::GlDraw(prog, glgeom, matcap); 66 | } 67 | } 68 | 69 | Eigen::AlignedBox3f GetAABB() const override { return aabb; } 70 | 71 | pangolin::GlGeometry glgeom; 72 | Eigen::AlignedBox3f aabb; 73 | }; 74 | 75 | struct RenderableTransform { 76 | virtual ~RenderableTransform() {} 77 | 78 | virtual Eigen::Matrix4f GetT_pc() const = 0; 79 | }; 80 | 81 | struct FixedTransform : public RenderableTransform { 82 | FixedTransform(Eigen::Matrix4f T_pc = Eigen::Matrix4f::Identity()) 83 | : T_pc(T_pc) {} 84 | 85 | Eigen::Matrix4f GetT_pc() const override { return T_pc; } 86 | 87 | Eigen::Matrix4f T_pc; 88 | }; 89 | 90 | struct SpinTransform : public RenderableTransform { 91 | SpinTransform(pangolin::AxisDirection dir) 92 | : dir(dir), 93 | start(std::chrono::steady_clock::now()) {} 94 | 95 | Eigen::Matrix4f GetT_pc() const override { 96 | if (dir != pangolin::AxisNone) { 97 | const double rad_per_sec = 0.5; 98 | const double rad = 99 | rad_per_sec * (std::chrono::steady_clock::now() - start).count() / 1E9; 100 | const Eigen::Map> axis( 101 | pangolin::AxisDirectionVector[dir]); 102 | Eigen::AngleAxisf aa(rad, axis.cast()); 103 | Eigen::Matrix4f T_pc = Eigen::Matrix4f::Identity(); 104 | T_pc.block<3, 3>(0, 0) = aa.toRotationMatrix(); 105 | return T_pc; 106 | } else { 107 | return Eigen::Matrix4f::Identity(); 108 | } 109 | } 110 | 111 | pangolin::AxisDirection dir; 112 | std::chrono::steady_clock::time_point start; 113 | }; 114 | 115 | using RenderNode = 116 | pangolin::TreeNode, std::shared_ptr>; 117 | 118 | static void render_tree(pangolin::GlSlProgram &prog, 119 | RenderNode &node, 120 | const pangolin::OpenGlMatrix &K, 121 | const pangolin::OpenGlMatrix &T_camera_node, 122 | pangolin::GlTexture *matcap) { 123 | if (node.item) { 124 | prog.SetUniform("KT_cw", K * T_camera_node); 125 | prog.SetUniform("T_cam_norm", T_camera_node); 126 | node.item->Render(prog, matcap); 127 | } 128 | for (auto &e : node.edges) { 129 | render_tree(prog, e.node, K, 130 | T_camera_node * (pangolin::OpenGlMatrix)e.parent_child->GetT_pc(), matcap); 131 | } 132 | } 133 | 134 | #endif -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/shader.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_SHADER_H 36 | #define TINY_VIEWER_SHADER_H 37 | 38 | namespace pangolin { 39 | 40 | const std::string default_model_shader = R"Shader( 41 | ///////////////////////////////////////// 42 | @start vertex 43 | #version 120 44 | 45 | #expect SHOW_COLOR 46 | #expect SHOW_NORMAL 47 | #expect SHOW_TEXTURE 48 | #expect SHOW_MATCAP 49 | #expect SHOW_UV 50 | 51 | uniform mat4 T_cam_norm; 52 | uniform mat4 KT_cw; 53 | attribute vec3 vertex; 54 | 55 | #if SHOW_COLOR 56 | attribute vec4 color; 57 | varying vec4 vColor; 58 | void main() { 59 | vColor = color; 60 | #elif SHOW_NORMAL 61 | attribute vec3 normal; 62 | varying vec3 vNormal; 63 | void main() { 64 | vNormal = mat3(T_cam_norm) * normal; 65 | #elif SHOW_TEXTURE 66 | attribute vec2 uv; 67 | varying vec2 vUV; 68 | void main() { 69 | vUV = uv; 70 | #elif SHOW_MATCAP 71 | attribute vec3 normal; 72 | varying vec3 vNormalCam; 73 | void main() { 74 | vNormalCam = mat3(T_cam_norm) * normal; 75 | #elif SHOW_UV 76 | attribute vec2 uv; 77 | varying vec2 vUV; 78 | void main() { 79 | vUV = uv; 80 | #else 81 | varying vec3 vP; 82 | void main() { 83 | vP = vertex; 84 | #endif 85 | gl_Position = KT_cw * vec4(vertex, 1.0); 86 | } 87 | 88 | ///////////////////////////////////////// 89 | @start fragment 90 | #version 120 91 | #expect SHOW_COLOR 92 | #expect SHOW_NORMAL 93 | #expect SHOW_TEXTURE 94 | #expect SHOW_MATCAP 95 | #expect SHOW_UV 96 | 97 | #if SHOW_COLOR 98 | varying vec4 vColor; 99 | #elif SHOW_NORMAL 100 | varying vec3 vNormal; 101 | #elif SHOW_TEXTURE 102 | varying vec2 vUV; 103 | uniform sampler2D texture_0; 104 | #elif SHOW_MATCAP 105 | varying vec3 vNormalCam; 106 | uniform sampler2D matcap; 107 | #elif SHOW_UV 108 | varying vec2 vUV; 109 | #else 110 | varying vec3 vP; 111 | #endif 112 | 113 | void main() { 114 | #if SHOW_COLOR 115 | gl_FragColor = vColor; 116 | #elif SHOW_NORMAL 117 | gl_FragColor = vec4((vNormal + vec3(1.0,1.0,1.0)) / 2.0, 1.0); 118 | #elif SHOW_TEXTURE 119 | gl_FragColor = texture2D(texture_0, vUV); 120 | #elif SHOW_MATCAP 121 | vec2 uv = 0.5 * vNormalCam.xy + vec2(0.5, 0.5); 122 | gl_FragColor = texture2D(matcap, uv); 123 | #elif SHOW_UV 124 | gl_FragColor = vec4(vUV,1.0-vUV.x,1.0); 125 | #else 126 | gl_FragColor = vec4(vP / 100.0,1.0); 127 | #endif 128 | } 129 | )Shader"; 130 | 131 | const std::string equi_env_shader = R"Shader( 132 | ///////////////////////////////////////// 133 | @start vertex 134 | #version 120 135 | attribute vec2 vertex; 136 | attribute vec2 xy; 137 | varying vec2 vXY; 138 | 139 | void main() { 140 | vXY = xy; 141 | gl_Position = vec4(vertex,0.0,1.0); 142 | } 143 | 144 | @start fragment 145 | #version 120 146 | #define M_PI 3.1415926538 147 | uniform sampler2D texture_0; 148 | uniform mat3 R_env_camKinv; 149 | varying vec2 vXY; 150 | 151 | vec2 RayToEquirect(vec3 ray) 152 | { 153 | float n = 1.0; 154 | float m = 1.0; 155 | float lamda = acos(ray.y/sqrt(1.0-ray.z*ray.z)); 156 | if(ray.x < 0) lamda = -lamda; 157 | float phi = asin(ray.z); 158 | float u = n*lamda/(2.0*M_PI)+n/2.0; 159 | float v = m/2.0 + m*phi/M_PI; 160 | return vec2(u,v); 161 | } 162 | 163 | void main() { 164 | vec3 ray_env = normalize(R_env_camKinv * vec3(vXY, 1.0)); 165 | gl_FragColor = texture2D(texture_0, RayToEquirect(ray_env)); 166 | } 167 | )Shader"; 168 | 169 | } // namespace pangolin 170 | #endif -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/utils.hpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef SLAM_SCENE_VIEWER_UTILS_HPP 36 | #define SLAM_SCENE_VIEWER_UTILS_HPP 37 | 38 | #include "Eigen/Dense" 39 | 40 | namespace ns_viewer { 41 | 42 | template 43 | using Vector = Eigen::Matrix; 44 | 45 | template 46 | using Vector2 = Vector; 47 | using Vector2f = Vector2; 48 | using Vector2d = Vector2; 49 | 50 | template 51 | using Vector3 = Vector; 52 | using Vector3f = Vector3; 53 | using Vector3d = Vector3; 54 | 55 | template 56 | using Vector4 = Vector; 57 | using Vector4f = Vector4; 58 | using Vector4d = Vector4; 59 | 60 | template 61 | using Vector6 = Vector; 62 | using Vector6f = Vector6; 63 | using Vector6d = Vector6; 64 | 65 | template 66 | using Vector7 = Vector; 67 | using Vector7f = Vector7; 68 | using Vector7d = Vector7; 69 | 70 | template 71 | using Matrix = Eigen::Matrix; 72 | 73 | template 74 | using Matrix2 = Matrix; 75 | using Matrix2f = Matrix2; 76 | using Matrix2d = Matrix2; 77 | 78 | template 79 | using Matrix3 = Matrix; 80 | using Matrix3f = Matrix3; 81 | using Matrix3d = Matrix3; 82 | 83 | template 84 | using Matrix4 = Matrix; 85 | using Matrix4f = Matrix4; 86 | using Matrix4d = Matrix4; 87 | 88 | template 89 | using Matrix6 = Matrix; 90 | using Matrix6f = Matrix6; 91 | using Matrix6d = Matrix6; 92 | 93 | template 94 | using Matrix7 = Matrix; 95 | using Matrix7f = Matrix7; 96 | using Matrix7d = Matrix7; 97 | 98 | template 99 | using Matrix34 = Matrix; 100 | using Matrix34f = Matrix34; 101 | using Matrix34d = Matrix34; 102 | 103 | #define INVALID_TIME_STAMP (-1.0) 104 | 105 | static const float DEG_TO_RAD = M_PI / 180.0; 106 | 107 | static const float RAD_TO_DEG = 180.0 / M_PI; 108 | 109 | } // namespace ns_viewer 110 | 111 | #endif // SLAM_SCENE_VIEWER_UTILS_HPP 112 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/viewer.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_VIEWER_H 36 | #define TINY_VIEWER_VIEWER_H 37 | 38 | #include "iostream" 39 | #include "memory" 40 | #include "mutex" 41 | #include "pangolin/gl/opengl_render_state.h" 42 | #include "thread" 43 | #include "tiny-viewer/core/viewer_configor.h" 44 | #include "utility" 45 | #include 46 | 47 | namespace ns_viewer { 48 | 49 | #define LOCKER_VIEWER std::unique_lock viewerLock(Viewer::MUTEX); 50 | 51 | struct Entity; 52 | using EntityPtr = std::shared_ptr; 53 | template 54 | struct Pose; 55 | using Posef = Pose; 56 | 57 | class Viewer { 58 | public: 59 | using Ptr = std::shared_ptr; 60 | 61 | protected: 62 | ViewerConfigor _configor; 63 | std::shared_ptr _thread; 64 | 65 | public: 66 | static std::mutex MUTEX; 67 | 68 | protected: 69 | std::unordered_map _entities; 70 | pangolin::OpenGlRenderState _camView; 71 | bool _isActive; 72 | pangolin::Viewport _viewport; 73 | 74 | std::unordered_map _geometry; 75 | 76 | public: 77 | explicit Viewer(ViewerConfigor configor = ViewerConfigor()); 78 | 79 | explicit Viewer(const std::string &configPath); 80 | 81 | static Ptr Create(const ViewerConfigor &configor = ViewerConfigor()); 82 | 83 | static Ptr Create(const std::string &configPath); 84 | 85 | // used for load viewer from file 86 | explicit Viewer(char) 87 | : _thread(nullptr), 88 | _isActive(false) {} 89 | 90 | virtual ~Viewer(); 91 | 92 | void RunInSingleThread(); 93 | 94 | void RunInMultiThread(); 95 | 96 | std::size_t AddEntity(const EntityPtr &entity); 97 | 98 | std::size_t AddObjEntity(const std::string &filename); 99 | 100 | void RemoveObjEntity(std::size_t id); 101 | 102 | std::vector AddEntity(const std::vector &entities); 103 | 104 | bool RemoveEntity(std::size_t id); 105 | 106 | bool RemoveEntity(const std::vector &ids); 107 | 108 | bool RemoveEntity(); 109 | 110 | void SetCamView(const pangolin::OpenGlRenderState &camView); 111 | 112 | void SetCamView(const std::string &filename); 113 | 114 | void SetCamView(Posef T_CamToWorld); 115 | 116 | void Save(const std::string &filename, bool binaryMode = true) const; 117 | 118 | static Ptr Load(const std::string &filename, bool binaryMode = true); 119 | 120 | ViewerConfigor &GetConfigor(); 121 | 122 | bool IsActive() const; 123 | 124 | // negative number means waiting forever 125 | bool WaitForActive(double waitTimeMs = -1.0) const; 126 | 127 | const pangolin::Viewport &GetViewport() const; 128 | 129 | protected: 130 | void InitViewer(bool initCamViewFromConfigor); 131 | 132 | void Run(); 133 | 134 | void SaveScreenShotCallBack() const; 135 | 136 | void SaveCameraCallBack() const; 137 | 138 | void SaveViewerCallBack() const; 139 | 140 | void VideoRecordCallBack() const; 141 | 142 | public: 143 | template 144 | void serialize(Archive &archive) { 145 | archive(cereal::make_nvp("configor", _configor), cereal::make_nvp("entities", _entities), 146 | cereal::make_nvp("camera_view", _camView)); 147 | } 148 | }; 149 | } // namespace ns_viewer 150 | 151 | #endif // TINY_VIEWER_VIEWER_H 152 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/core/viewer_configor.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_VIEWER_CONFIGOR_H 36 | #define TINY_VIEWER_VIEWER_CONFIGOR_H 37 | 38 | #include "cereal/cereal.hpp" 39 | #include "tiny-viewer/entity/utils.h" 40 | #include "pangolin/display/view.h" 41 | 42 | namespace ns_viewer { 43 | // GlSl Graphics shader program for display 44 | enum class ObjRenderMode { UV = 0, TEX, COLOR, NORMAL, MATCAP, VERTEX, NUM_MODES }; 45 | 46 | struct Window { 47 | std::string name = "Tiny Viewer"; 48 | Colour backGroundColor = Colour::White(); 49 | int width = 640 * 2; 50 | int height = 480 * 2; 51 | pangolin::Layout layout = pangolin::LayoutEqual; 52 | 53 | public: 54 | template 55 | void serialize(Archive &ar) { 56 | ar(CEREAL_NVP(name), CEREAL_NVP(backGroundColor), CEREAL_NVP(width), CEREAL_NVP(height), 57 | CEREAL_NVP(layout)); 58 | } 59 | }; 60 | 61 | struct Output { 62 | std::string dataOutputPath; 63 | 64 | public: 65 | template 66 | void serialize(Archive &ar) { 67 | ar(CEREAL_NVP(dataOutputPath)); 68 | } 69 | }; 70 | 71 | struct ConfigCamera { 72 | int width = 640, height = 480; 73 | double fx = 420, fy = 420; 74 | double cx = 320, cy = 240; 75 | double near = 0.01, far = 100; 76 | 77 | std::vector initPos = {6.0f, 6.0f, 6.0f}; 78 | std::vector initViewPoint = {0.0f, 0.0f, 0.0f}; 79 | 80 | public: 81 | template 82 | void serialize(Archive &ar) { 83 | ar(CEREAL_NVP(width), CEREAL_NVP(height), CEREAL_NVP(fx), CEREAL_NVP(fy), CEREAL_NVP(cx), 84 | CEREAL_NVP(cy), CEREAL_NVP(near), CEREAL_NVP(far), CEREAL_NVP(initPos), 85 | CEREAL_NVP(initViewPoint)); 86 | } 87 | }; 88 | 89 | struct Grid { 90 | bool showGrid = true; 91 | bool showIdentityCoord = true; 92 | 93 | int cellCount = 10; 94 | float cellSize = 1.0f; 95 | // 0: xy, 1: yz, 2: zx 96 | int planePos = 0; 97 | 98 | Colour color = Colour::Black().WithAlpha(0.3f); 99 | 100 | public: 101 | template 102 | void serialize(Archive &ar) { 103 | ar(CEREAL_NVP(showGrid), CEREAL_NVP(showIdentityCoord), CEREAL_NVP(cellCount), 104 | CEREAL_NVP(cellSize), CEREAL_NVP(planePos), CEREAL_NVP(color)); 105 | } 106 | }; 107 | 108 | struct ViewerConfigor { 109 | public: 110 | Window window; 111 | 112 | Output output; 113 | 114 | ConfigCamera camera; 115 | 116 | Grid grid; 117 | 118 | ObjRenderMode render; 119 | 120 | std::map> callBacks; 121 | 122 | public: 123 | template 124 | void serialize(Archive &ar) { 125 | ar(CEREAL_NVP(window), CEREAL_NVP(output), CEREAL_NVP(camera), CEREAL_NVP(grid), 126 | CEREAL_NVP(render)); 127 | } 128 | 129 | public: 130 | explicit ViewerConfigor(const std::string &winName = "Tiny Viewer"); 131 | 132 | // load configure information from the json file 133 | static ViewerConfigor LoadConfigure(const std::string &filename); 134 | 135 | // load configure information from the json file 136 | bool SaveConfigure(const std::string &filename); 137 | 138 | ViewerConfigor &WithWinName(const std::string &winName); 139 | 140 | ViewerConfigor &WithScreenShotSaveDir(const std::string &dir); 141 | }; 142 | 143 | struct MultiViewerConfigor { 144 | public: 145 | Window window; 146 | 147 | Output output; 148 | 149 | std::unordered_map camera; 150 | 151 | std::unordered_map grid; 152 | 153 | std::vector subWinNames; 154 | 155 | ObjRenderMode render; 156 | 157 | std::map> callBacks; 158 | 159 | public: 160 | template 161 | void serialize(Archive &ar) { 162 | ar(CEREAL_NVP(window), CEREAL_NVP(output), CEREAL_NVP(camera), CEREAL_NVP(grid), 163 | CEREAL_NVP(subWinNames), CEREAL_NVP(render)); 164 | } 165 | 166 | public: 167 | explicit MultiViewerConfigor(const std::vector &subWinNames, 168 | const std::string &winName = "Tiny Viewer"); 169 | 170 | // load configure information from the json file 171 | static MultiViewerConfigor LoadConfigure(const std::string &filename); 172 | 173 | // load configure information from the json file 174 | bool SaveConfigure(const std::string &filename); 175 | 176 | MultiViewerConfigor &WithWinName(const std::string &winName); 177 | 178 | MultiViewerConfigor &WithScreenShotSaveDir(const std::string &dir); 179 | }; 180 | } // namespace ns_viewer 181 | 182 | #endif // TINY_VIEWER_VIEWER_CONFIGOR_H 183 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/arrow.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_ARROW_H 36 | #define TINY_VIEWER_ARROW_H 37 | 38 | #include "entity.h" 39 | 40 | namespace ns_viewer { 41 | struct Arrow : public Entity { 42 | public: 43 | using Ptr = std::shared_ptr; 44 | 45 | protected: 46 | Eigen::Vector3f sp; 47 | Eigen::Vector3f ep; 48 | Eigen::Vector3f mp; 49 | 50 | std::array verts; 51 | 52 | float size{}; 53 | Colour color; 54 | 55 | public: 56 | Arrow(Eigen::Vector3f sp, 57 | Eigen::Vector3f ep, 58 | float size = DefaultLineSize, 59 | const Colour &color = GetUniqueColour()); 60 | 61 | Arrow(Eigen::Vector3f sp, 62 | Eigen::Vector3f ep, 63 | const Colour &color, 64 | float size = DefaultLineSize); 65 | 66 | static Ptr Create(const Eigen::Vector3f &sp, 67 | const Eigen::Vector3f &ep, 68 | float size = DefaultLineSize, 69 | const Colour &color = GetUniqueColour()); 70 | 71 | static Ptr Create(const Eigen::Vector3f &sp, 72 | const Eigen::Vector3f &ep, 73 | const Colour &color, 74 | float size = DefaultLineSize); 75 | 76 | ~Arrow() override; 77 | 78 | void Draw() const override; 79 | 80 | Arrow() = default; 81 | 82 | public: 83 | template 84 | void serialize(Archive &archive) { 85 | Entity::serialize(archive); 86 | archive(CEREAL_NVP(sp), CEREAL_NVP(ep), CEREAL_NVP(mp), CEREAL_NVP(verts), 87 | CEREAL_NVP(color), CEREAL_NVP(size)); 88 | } 89 | }; 90 | } // namespace ns_viewer 91 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Arrow, "Arrow") 92 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Arrow) 93 | 94 | #endif // TINY_VIEWER_ARROW_H 95 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/circle.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_CIRCLE_H 36 | #define TINY_VIEWER_CIRCLE_H 37 | 38 | #include "tiny-viewer/entity/coordinate.h" 39 | #include "tiny-viewer/entity/entity.h" 40 | #include "tiny-viewer/entity/polygon.h" 41 | 42 | namespace ns_viewer { 43 | template 44 | struct Pose; 45 | using Posef = Pose; 46 | 47 | struct Circle : public Entity { 48 | public: 49 | using Ptr = std::shared_ptr; 50 | 51 | protected: 52 | Coordinate coord; 53 | Polygon poly; 54 | bool drawCoord{}; 55 | 56 | public: 57 | explicit Circle(const Posef &pose, 58 | float radius, 59 | bool lineMode = true, 60 | bool drawCoord = true, 61 | const Colour &color = GetUniqueColour(), 62 | pangolin::AxisDirection nAxis = pangolin::AxisZ, 63 | int ptCount = 16); 64 | 65 | static Ptr Create(const Posef &pose, 66 | float radius, 67 | bool lineMode = true, 68 | bool drawCoord = true, 69 | const Colour &color = GetUniqueColour(), 70 | pangolin::AxisDirection nAxis = pangolin::AxisZ, 71 | int ptCount = 16); 72 | 73 | ~Circle() override; 74 | 75 | void Draw() const override; 76 | 77 | Circle() = default; 78 | 79 | public: 80 | template 81 | void serialize(Archive &archive) { 82 | Entity::serialize(archive); 83 | archive(CEREAL_NVP(coord), CEREAL_NVP(poly)); 84 | } 85 | }; 86 | } // namespace ns_viewer 87 | 88 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Circle, "Circle") 89 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Circle) 90 | 91 | #endif // TINY_VIEWER_CIRCLE_H 92 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/cone.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_CONE_H 36 | #define TINY_VIEWER_CONE_H 37 | 38 | #include "entity.h" 39 | #include "coordinate.h" 40 | 41 | namespace ns_viewer { 42 | template 43 | struct Pose; 44 | using Posef = Pose; 45 | 46 | struct Cone : public Entity { 47 | public: 48 | using Ptr = std::shared_ptr; 49 | 50 | protected: 51 | Eigen::Vector3f tp; 52 | Eigen::Vector3f bp; 53 | 54 | std::array verts; 55 | 56 | Colour color; 57 | 58 | public: 59 | Cone(const Posef &pose, float height, float angle, const Colour &color = GetUniqueColour()); 60 | 61 | static Ptr Create(const Posef &pose, 62 | float height, 63 | float angle, 64 | const Colour &color = GetUniqueColour()); 65 | 66 | ~Cone() override; 67 | 68 | void Draw() const override; 69 | 70 | Cone() = default; 71 | 72 | public: 73 | template 74 | void serialize(Archive &archive) { 75 | Entity::serialize(archive); 76 | archive(CEREAL_NVP(tp), CEREAL_NVP(bp), CEREAL_NVP(verts), CEREAL_NVP(color)); 77 | } 78 | }; 79 | } // namespace ns_viewer 80 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Cone, "Cone") 81 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Cone) 82 | 83 | #endif // TINY_VIEWER_CONE_H 84 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/coordinate.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_COORDINATE_H 36 | #define TINY_VIEWER_COORDINATE_H 37 | 38 | #include "entity.h" 39 | 40 | namespace ns_viewer { 41 | template 42 | struct Pose; 43 | using Posef = Pose; 44 | 45 | struct Coordinate : public Entity { 46 | public: 47 | using Ptr = std::shared_ptr; 48 | 49 | protected: 50 | Eigen::Matrix4f pose; 51 | float size{}; 52 | 53 | public: 54 | explicit Coordinate(const Posef &pose, float size = DefaultCoordSize); 55 | 56 | static Ptr Create(const Posef &pose, float size = DefaultCoordSize); 57 | 58 | ~Coordinate() override; 59 | 60 | void Draw() const override; 61 | 62 | Coordinate() = default; 63 | 64 | public: 65 | template 66 | void serialize(Archive &archive) { 67 | Entity::serialize(archive); 68 | archive(CEREAL_NVP(size), CEREAL_NVP(pose)); 69 | } 70 | }; 71 | } // namespace ns_viewer 72 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Coordinate, "Coordinate") 73 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Coordinate) 74 | 75 | #endif // TINY_VIEWER_COORDINATE_H 76 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/cube.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_CUBE_H 36 | #define TINY_VIEWER_CUBE_H 37 | 38 | #include "entity.h" 39 | 40 | namespace ns_viewer { 41 | template 42 | struct Pose; 43 | using Posef = Pose; 44 | 45 | struct Cube : public Entity { 46 | public: 47 | using Ptr = std::shared_ptr; 48 | 49 | protected: 50 | Eigen::Vector3f v1; 51 | Eigen::Vector3f v2; 52 | Eigen::Vector3f v3; 53 | Eigen::Vector3f v4; 54 | 55 | Eigen::Vector3f v5; 56 | Eigen::Vector3f v6; 57 | Eigen::Vector3f v7; 58 | Eigen::Vector3f v8; 59 | 60 | bool lineMode{}; 61 | Colour color; 62 | 63 | public: 64 | Cube(const Posef &pose, 65 | bool lineMode, 66 | float xWidth = DefaultCubeSize, 67 | float yWidth = DefaultCubeSize, 68 | float zWidth = DefaultCubeSize, 69 | const Colour &color = GetUniqueColour()); 70 | 71 | Cube(const Posef &pose, 72 | bool lineMode, 73 | const Colour &color, 74 | float xWidth = DefaultCubeSize, 75 | float yWidth = DefaultCubeSize, 76 | float zWidth = DefaultCubeSize); 77 | 78 | static Ptr Create(const Posef &pose, 79 | bool lineMode, 80 | float xWidth = DefaultCubeSize, 81 | float yWidth = DefaultCubeSize, 82 | float zWidth = DefaultCubeSize, 83 | const Colour &color = GetUniqueColour()); 84 | 85 | static Ptr Create(const Posef &pose, 86 | bool lineMode, 87 | const Colour &color, 88 | float xWidth = DefaultCubeSize, 89 | float yWidth = DefaultCubeSize, 90 | float zWidth = DefaultCubeSize); 91 | 92 | [[nodiscard]] Eigen::Vector3f GetCenter() const; 93 | 94 | [[nodiscard]] std::array GetVertices() const; 95 | 96 | ~Cube() override; 97 | 98 | void Draw() const override; 99 | 100 | Cube() = default; 101 | 102 | public: 103 | template 104 | void serialize(Archive &archive) { 105 | Entity::serialize(archive); 106 | archive(CEREAL_NVP(v1), CEREAL_NVP(v2), CEREAL_NVP(v3), CEREAL_NVP(v4), CEREAL_NVP(v5), 107 | CEREAL_NVP(v6), CEREAL_NVP(v7), CEREAL_NVP(v8), CEREAL_NVP(color), 108 | CEREAL_NVP(lineMode)); 109 | } 110 | }; 111 | } // namespace ns_viewer 112 | 113 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Cube, "Cube") 114 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Cube) 115 | 116 | #endif // TINY_VIEWER_CUBE_H 117 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/cylinder.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_CYLINDER_H 36 | #define TINY_VIEWER_CYLINDER_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | 40 | namespace ns_viewer { 41 | template 42 | struct Pose; 43 | using Posef = Pose; 44 | 45 | struct Cylinder : public Entity { 46 | public: 47 | using Ptr = std::shared_ptr; 48 | 49 | protected: 50 | std::array tops; 51 | std::array bottoms; 52 | 53 | Colour color; 54 | 55 | public: 56 | explicit Cylinder(const Posef &pose, 57 | float height, 58 | float radius, 59 | const Colour &color = GetUniqueColour()); 60 | 61 | Ptr static Create(const Posef &pose, 62 | float height, 63 | float radius, 64 | const Colour &color = GetUniqueColour()); 65 | 66 | ~Cylinder() override; 67 | 68 | void Draw() const override; 69 | 70 | Cylinder() = default; 71 | 72 | public: 73 | template 74 | void serialize(Archive &archive) { 75 | Entity::serialize(archive); 76 | archive(CEREAL_NVP(tops), CEREAL_NVP(bottoms), CEREAL_NVP(color)); 77 | } 78 | }; 79 | } // namespace ns_viewer 80 | 81 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Cylinder, "Cylinder") 82 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Cylinder) 83 | 84 | #endif // TINY_VIEWER_CYLINDER_H 85 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/entity.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_ENTITY_H 36 | #define TINY_VIEWER_ENTITY_H 37 | 38 | #include "utils.h" 39 | 40 | namespace ns_viewer { 41 | 42 | struct Entity { 43 | public: 44 | using Ptr = std::shared_ptr; 45 | 46 | private: 47 | std::size_t id; 48 | static std::size_t counter; 49 | static ColourWheel COLOR_WHEEL; 50 | 51 | public: 52 | explicit Entity(); 53 | 54 | virtual ~Entity(); 55 | 56 | virtual void Draw() const = 0; 57 | 58 | static Colour GetUniqueColour(); 59 | 60 | [[nodiscard]] const std::size_t &GetId() const; 61 | 62 | private: 63 | static std::size_t GenUniqueName(); 64 | 65 | public: 66 | template 67 | void serialize(Archive &archive) { 68 | std::size_t counterBackup = counter; 69 | archive(CEREAL_NVP(id), CEREAL_NVP(counter)); 70 | if (counter < counterBackup) { 71 | counter = counterBackup; 72 | } 73 | } 74 | }; 75 | } // namespace ns_viewer 76 | 77 | #endif // TINY_VIEWER_ENTITY_H 78 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/line.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_LINE_H 36 | #define TINY_VIEWER_LINE_H 37 | 38 | #include "entity.h" 39 | 40 | namespace ns_viewer { 41 | 42 | struct Line : public Entity { 43 | public: 44 | using Ptr = std::shared_ptr; 45 | 46 | protected: 47 | Eigen::Vector3f sp; 48 | Eigen::Vector3f ep; 49 | 50 | float size{}; 51 | Colour color; 52 | 53 | public: 54 | Line(Eigen::Vector3f sp, 55 | Eigen::Vector3f ep, 56 | float size = DefaultLineSize, 57 | const Colour &color = GetUniqueColour()); 58 | 59 | Line(Eigen::Vector3f sp, Eigen::Vector3f ep, const Colour &color, float size = DefaultLineSize); 60 | 61 | static Ptr Create(const Eigen::Vector3f &sp, 62 | const Eigen::Vector3f &ep, 63 | float size = DefaultLineSize, 64 | const Colour &color = GetUniqueColour()); 65 | 66 | static Ptr Create(const Eigen::Vector3f &sp, 67 | const Eigen::Vector3f &ep, 68 | const Colour &color, 69 | float size = DefaultLineSize); 70 | 71 | ~Line() override; 72 | 73 | void Draw() const override; 74 | 75 | Line() = default; 76 | 77 | public: 78 | template 79 | void serialize(Archive &archive) { 80 | Entity::serialize(archive); 81 | archive(CEREAL_NVP(sp), CEREAL_NVP(ep), CEREAL_NVP(color), CEREAL_NVP(size)); 82 | } 83 | }; 84 | } // namespace ns_viewer 85 | 86 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Line, "Line") 87 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Line) 88 | 89 | #endif // TINY_VIEWER_LINE_H 90 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/path.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_PATH_H 36 | #define TINY_VIEWER_PATH_H 37 | 38 | #include "entity.h" 39 | #include "line.h" 40 | 41 | namespace ns_viewer { 42 | struct Bezier { 43 | public: 44 | static std::vector Solve(const std::vector &controlPoints, 45 | std::size_t num); 46 | 47 | protected: 48 | static Eigen::Vector3f Solve(float t, 49 | const std::vector &controlPoints, 50 | std::size_t beg, 51 | std::size_t end); 52 | }; 53 | 54 | /** 55 | * M = moveto, L = lineto, S = smooth curveto, Z = closepath 56 | * Uppercase means absolute position, lowercase means relative position 57 | */ 58 | struct Path : public Entity { 59 | public: 60 | using Ptr = std::shared_ptr; 61 | 62 | protected: 63 | std::vector lines; 64 | 65 | public: 66 | explicit Path(const std::string &svgCode, 67 | float size = DefaultLineSize, 68 | const Colour &color = GetUniqueColour()); 69 | 70 | explicit Path(const std::string &svgCode, const Colour &color, float size = DefaultLineSize); 71 | 72 | static Ptr Create(const std::string &svgCode, 73 | float size = DefaultLineSize, 74 | const Colour &color = GetUniqueColour()); 75 | 76 | static Ptr Create(const std::string &svgCode, 77 | const Colour &color, 78 | float size = DefaultLineSize); 79 | 80 | ~Path() override = default; 81 | 82 | void Draw() const override; 83 | 84 | Path() = default; 85 | 86 | protected: 87 | static std::vector ParseSVGCode(const std::string &svgCode, 88 | float size, 89 | const Colour &color); 90 | 91 | static bool IsSVGPathControlCode(const std::string &str); 92 | 93 | static float CurveLength(const std::vector &pts); 94 | 95 | public: 96 | template 97 | void serialize(Archive &archive) { 98 | Entity::serialize(archive); 99 | archive(CEREAL_NVP(lines)); 100 | } 101 | }; 102 | } // namespace ns_viewer 103 | 104 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Path, "Path") 105 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Path) 106 | 107 | #endif // TINY_VIEWER_PATH_H 108 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/polygon.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_POLYGON_H 36 | #define TINY_VIEWER_POLYGON_H 37 | 38 | #include "entity.h" 39 | 40 | namespace ns_viewer { 41 | struct Polygon : public Entity { 42 | public: 43 | using Ptr = std::shared_ptr; 44 | 45 | protected: 46 | std::vector verts; 47 | 48 | bool lineMode{}; 49 | Colour color; 50 | 51 | public: 52 | Polygon(const std::vector &verts, 53 | bool lineMode, 54 | const Colour &color = GetUniqueColour()); 55 | 56 | static Ptr Create(const std::vector &verts, 57 | bool lineMode, 58 | const Colour &color = GetUniqueColour()); 59 | 60 | ~Polygon() override; 61 | 62 | void Draw() const override; 63 | 64 | Polygon() = default; 65 | 66 | public: 67 | template 68 | void serialize(Archive &archive) { 69 | Entity::serialize(archive); 70 | archive(CEREAL_NVP(verts), CEREAL_NVP(color), CEREAL_NVP(lineMode)); 71 | } 72 | }; 73 | } // namespace ns_viewer 74 | 75 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Polygon, "Polygon") 76 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Polygon) 77 | 78 | #endif // TINY_VIEWER_POLYGON_H 79 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/entity/utils.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_UTILS_H 36 | #define TINY_VIEWER_UTILS_H 37 | 38 | #include "pcl/visualization/pcl_visualizer.h" 39 | #include "cereal/cereal.hpp" 40 | #include "cereal/types/vector.hpp" 41 | #include "cereal/types/array.hpp" 42 | #include "cereal/types/unordered_map.hpp" 43 | #include "cereal/archives/json.hpp" 44 | #include "cereal/archives/xml.hpp" 45 | #include "cereal/archives/binary.hpp" 46 | #include "cereal/types/polymorphic.hpp" 47 | #include "fstream" 48 | #include "pangolin/gl/colour.h" 49 | #include "pangolin/gl/opengl_render_state.h" 50 | 51 | namespace ns_viewer { 52 | 53 | #define DefaultLineSize (2.0f) 54 | #define DefaultCoordSize (1.0f) 55 | #define DefaultCubeSize (0.5f) 56 | #define DefaultPointSize (4.0f) 57 | #define DefaultIMUSize (0.2f) 58 | #define DefaultCameraSize (0.2f) 59 | #define DefaultRadarSize (0.2f) 60 | #define DefaultLiDARSize (0.2f) 61 | #define DefaultLandmarkSize (0.05f) 62 | 63 | #define ExpandVec3(v) v(0), v(1), v(2) 64 | #define ExpandStdVec3(v) v.at(0), v.at(1), v.at(2) 65 | #define ExpandAryVec3(v) v[0], v[1], v[2] 66 | #define ExpandPCLPointXYZ(p) p.x, p.y, p.z 67 | #define ExpandColor(c) c.r, c.g, c.b, c.a 68 | #define ExpandPCLColor(p) p.r * 0.00392, p.g * 0.00392, p.b * 0.00392, p.a * 0.00392 69 | 70 | using IntensityMode = pcl::visualization::LookUpTableRepresentationProperties; 71 | using ColourWheel = pangolin::ColourWheel; 72 | using Colour = pangolin::Colour; 73 | 74 | vtkSmartPointer GetColormapLUT( 75 | pcl::visualization::LookUpTableRepresentationProperties colormapType, double minmax[2]); 76 | 77 | std::pair TangentBasis(const Eigen::Vector3f &v); 78 | 79 | std::optional LinePlaneIntersection(const Eigen::Vector3f &ls, 80 | const Eigen::Vector3f &le, 81 | const Eigen::Vector3f &norm, 82 | float d); 83 | 84 | std::vector StringSplit(const std::string &str, char splitor, bool ignoreEmpty = true); 85 | } // namespace ns_viewer 86 | 87 | namespace Eigen { 88 | template 89 | void serialize(Archive &archive, Eigen::Matrix &m) { 90 | for (int i = 0; i < Rows; ++i) { 91 | for (int j = 0; j < Cols; ++j) { 92 | archive(cereal::make_nvp('r' + std::to_string(i) + 'c' + std::to_string(j), m(i, j))); 93 | } 94 | } 95 | } 96 | 97 | template 98 | void serialize(Archive &archive, Eigen::Matrix &m) { 99 | for (int i = 0; i < m.rows(); ++i) { 100 | for (int j = 0; j < Cols; ++j) { 101 | archive(cereal::make_nvp('r' + std::to_string(i) + 'c' + std::to_string(j), m(i, j))); 102 | } 103 | } 104 | } 105 | 106 | template 107 | void serialize(Archive &archive, Eigen::Matrix &m) { 108 | for (int i = 0; i < m.rows(); ++i) { 109 | for (int j = 0; j < m.cols(); ++j) { 110 | archive(cereal::make_nvp('r' + std::to_string(i) + 'c' + std::to_string(j), m(i, j))); 111 | } 112 | } 113 | } 114 | 115 | template 116 | void serialize(Archive &archive, Eigen::Quaternion &q) { 117 | archive(cereal::make_nvp("qx", q.coeffs()[0]), cereal::make_nvp("qy", q.coeffs()[1]), 118 | cereal::make_nvp("qz", q.coeffs()[2]), cereal::make_nvp("qw", q.coeffs()[3])); 119 | } 120 | } // namespace Eigen 121 | 122 | namespace pangolin { 123 | template 124 | void serialize(Archive &ar, ns_viewer::Colour &color) { 125 | ar(cereal::make_nvp("red", color.red), cereal::make_nvp("green", color.green), 126 | cereal::make_nvp("blue", color.blue), cereal::make_nvp("alpha", color.alpha)); 127 | } 128 | 129 | template 130 | void serialize(Archive &ar, OpenGlMatrix &m) { 131 | for (double &i : m.m) { 132 | ar(i); 133 | } 134 | } 135 | 136 | template 137 | void serialize(Archive &ar, OpenGlRenderState &m) { 138 | ar(cereal::make_nvp("projection_mat", m.GetProjectionMatrix()), 139 | cereal::make_nvp("model_view_mat", m.GetModelViewMatrix())); 140 | } 141 | } // namespace pangolin 142 | 143 | namespace pcl { 144 | template 145 | void serialize(Archive &ar, PCLHeader &h) { 146 | ar(cereal::make_nvp("stamp", h.stamp), cereal::make_nvp("frame_id", h.frame_id), 147 | cereal::make_nvp("seq", h.seq)); 148 | } 149 | 150 | template 151 | void serialize(Archive &ar, pcl::PointXYZI &p) { 152 | ar(cereal::make_nvp("x", p.x), cereal::make_nvp("y", p.y), cereal::make_nvp("z", p.z), 153 | cereal::make_nvp("intensity", p.intensity)); 154 | } 155 | 156 | template 157 | void serialize(Archive &ar, pcl::PointXYZRGB &p) { 158 | ar(cereal::make_nvp("x", p.x), cereal::make_nvp("y", p.y), cereal::make_nvp("z", p.z), 159 | cereal::make_nvp("r", p.r), cereal::make_nvp("g", p.g), cereal::make_nvp("b", p.b)); 160 | } 161 | 162 | template 163 | void serialize(Archive &ar, pcl::PointXYZRGBA &p) { 164 | ar(cereal::make_nvp("x", p.x), cereal::make_nvp("y", p.y), cereal::make_nvp("z", p.z), 165 | cereal::make_nvp("r", p.r), cereal::make_nvp("g", p.g), cereal::make_nvp("b", p.b), 166 | cereal::make_nvp("a", p.a)); 167 | } 168 | 169 | template 170 | void serialize(Archive &ar, pcl::PointXYZ &p) { 171 | ar(cereal::make_nvp("x", p.x), cereal::make_nvp("y", p.y), cereal::make_nvp("z", p.z)); 172 | } 173 | 174 | template 175 | void serialize(Archive &ar, pcl::PointCloud &cloud) { 176 | ar(cereal::make_nvp("header", cloud.header), cereal::make_nvp("points", cloud.points), 177 | cereal::make_nvp("width", cloud.width), cereal::make_nvp("height", cloud.height), 178 | cereal::make_nvp("is_dense", cloud.is_dense), 179 | cereal::make_nvp("sensor_orientation_", cloud.sensor_orientation_), 180 | cereal::make_nvp("sensor_origin_", cloud.sensor_origin_)); 181 | } 182 | } // namespace pcl 183 | 184 | #endif // TINY_VIEWER_UTILS_H 185 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/aligned_cloud.hpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_ALIGNED_CLOUD_HPP 36 | #define TINY_VIEWER_ALIGNED_CLOUD_HPP 37 | 38 | #include "tiny-viewer/entity/point_cloud.hpp" 39 | 40 | namespace ns_viewer { 41 | template 42 | struct AlignedCloud : public Entity { 43 | public: 44 | using Ptr = std::shared_ptr; 45 | 46 | protected: 47 | using PointCloud = pcl::PointCloud; 48 | using PointCloudPtr = typename PointCloud::Ptr; 49 | 50 | Cloud cloud; 51 | 52 | public: 53 | explicit AlignedCloud(const PointCloudPtr &inputCloud, 54 | const Eigen::Vector3f &dir, 55 | float size = DefaultPointSize, 56 | IntensityMode mode = IntensityMode::PCL_VISUALIZER_LUT_HSV) 57 | : Entity(), 58 | cloud(ColorizeCloudByDirection(inputCloud, dir), size, mode) {} 59 | 60 | static Ptr Create(const PointCloudPtr &inputCloud, 61 | const Eigen::Vector3f &dir, 62 | float size = DefaultPointSize, 63 | IntensityMode mode = IntensityMode::PCL_VISUALIZER_LUT_HSV) { 64 | return std::make_shared(inputCloud, dir, size, mode); 65 | } 66 | 67 | ~AlignedCloud() override = default; 68 | 69 | void Draw() const override { cloud.Draw(); } 70 | 71 | AlignedCloud() = default; 72 | 73 | static auto Random(float bound, 74 | std::size_t count, 75 | const Eigen::Vector3f ¢er, 76 | const Eigen::Vector3f &dir) { 77 | std::default_random_engine engine( 78 | std::chrono::steady_clock::now().time_since_epoch().count()); 79 | std::uniform_real_distribution u(-bound, bound); 80 | pcl::PointCloud::Ptr cloud(new pcl::PointCloud); 81 | cloud->resize(count); 82 | for (int i = 0; i < static_cast(count); ++i) { 83 | auto &p = cloud->at(i); 84 | // x, y, z 85 | p.x = u(engine) + center(0); 86 | p.y = u(engine) + center(1); 87 | p.z = u(engine) + center(2); 88 | } 89 | return AlignedCloud::Create(cloud, dir); 90 | } 91 | 92 | [[nodiscard]] const Cloud &GetCloud() const { return cloud; } 93 | 94 | public: 95 | template 96 | void serialize(Archive &archive) { 97 | Entity::serialize(archive); 98 | archive(cereal::make_nvp("data", cloud)); 99 | } 100 | 101 | protected: 102 | static pcl::PointCloud::Ptr ColorizeCloudByDirection( 103 | const typename pcl::PointCloud::Ptr &iCloud, const Eigen::Vector3f &dir) { 104 | pcl::PointCloud::Ptr oCloud(new pcl::PointCloud); 105 | oCloud->resize(iCloud->size()); 106 | for (int i = 0; i < static_cast(iCloud->size()); ++i) { 107 | const auto &ip = iCloud->at(i); 108 | auto &op = oCloud->at(i); 109 | op.x = ip.x, op.y = ip.y, op.z = ip.z; 110 | op.intensity = -Eigen::Vector3f(ip.x, ip.y, ip.z).dot(dir); 111 | } 112 | return oCloud; 113 | } 114 | }; 115 | } // namespace ns_viewer 116 | 117 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::AlignedCloud, "AlignedCloud::PointXYZ") 118 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::AlignedCloud) 119 | 120 | #endif // TINY_VIEWER_ALIGNED_CLOUD_HPP 121 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/camera.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_CAMERA_H 36 | #define TINY_VIEWER_CAMERA_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/coordinate.h" 40 | #include "tiny-viewer/entity/cube.h" 41 | 42 | namespace ns_viewer { 43 | 44 | struct Camera : public Entity { 45 | public: 46 | using Ptr = std::shared_ptr; 47 | 48 | protected: 49 | Coordinate coord; 50 | 51 | Eigen::Vector3f v0; 52 | Eigen::Vector3f v1; 53 | Eigen::Vector3f v2; 54 | Eigen::Vector3f v3; 55 | Eigen::Vector3f v4; 56 | 57 | Colour color; 58 | 59 | public: 60 | explicit Camera(const Posef &pose, 61 | float size = DefaultCameraSize, 62 | const Colour &color = Colour::Green()); 63 | 64 | explicit Camera(const Posef &pose, const Colour &color, float size = DefaultCameraSize); 65 | 66 | static Ptr Create(const Posef &pose, 67 | float size = DefaultCameraSize, 68 | const Colour &color = Colour::Green()); 69 | 70 | static Ptr Create(const Posef &pose, const Colour &color, float size = DefaultCameraSize); 71 | 72 | ~Camera() override; 73 | 74 | void Draw() const override; 75 | 76 | Camera() = default; 77 | 78 | public: 79 | template 80 | void serialize(Archive &archive) { 81 | Entity::serialize(archive); 82 | archive(CEREAL_NVP(coord), CEREAL_NVP(v0), CEREAL_NVP(v1), CEREAL_NVP(v2), CEREAL_NVP(v3), 83 | CEREAL_NVP(v4), CEREAL_NVP(color)); 84 | } 85 | }; 86 | 87 | struct CubeCamera : public Entity { 88 | public: 89 | using Ptr = std::shared_ptr; 90 | 91 | protected: 92 | Coordinate coord; 93 | 94 | Eigen::Vector3f v0; 95 | Eigen::Vector3f v1; 96 | Eigen::Vector3f v2; 97 | Eigen::Vector3f v3; 98 | Eigen::Vector3f v4; 99 | 100 | Colour color; 101 | Cube cube; 102 | 103 | public: 104 | explicit CubeCamera(const Posef &pose, 105 | float size = DefaultCameraSize, 106 | const Colour &color = Colour::Green()); 107 | 108 | explicit CubeCamera(const Posef &pose, const Colour &color, float size = DefaultCameraSize); 109 | 110 | static Ptr Create(const Posef &pose, 111 | float size = DefaultCameraSize, 112 | const Colour &color = Colour::Green()); 113 | 114 | static Ptr Create(const Posef &pose, const Colour &color, float size = DefaultCameraSize); 115 | 116 | ~CubeCamera() override; 117 | 118 | void Draw() const override; 119 | 120 | CubeCamera() = default; 121 | 122 | public: 123 | template 124 | void serialize(Archive &archive) { 125 | Entity::serialize(archive); 126 | archive(CEREAL_NVP(coord), CEREAL_NVP(v0), CEREAL_NVP(v1), CEREAL_NVP(v2), CEREAL_NVP(v3), 127 | CEREAL_NVP(v4), CEREAL_NVP(cube), CEREAL_NVP(color)); 128 | } 129 | }; 130 | } // namespace ns_viewer 131 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Camera, "camera") 132 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Camera) 133 | 134 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::CubeCamera, "CubeCamera") 135 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::CubeCamera) 136 | 137 | #endif // TINY_VIEWER_CAMERA_H 138 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/imu.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_IMU_H 36 | #define TINY_VIEWER_IMU_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/coordinate.h" 40 | #include "tiny-viewer/entity/cube.h" 41 | 42 | namespace ns_viewer { 43 | 44 | struct IMU : public Entity { 45 | public: 46 | using Ptr = std::shared_ptr; 47 | 48 | protected: 49 | Coordinate coord; 50 | Cube cube; 51 | 52 | public: 53 | explicit IMU(const Posef &pose, 54 | float size = DefaultIMUSize, 55 | const Colour &colour = Colour::Red()); 56 | 57 | explicit IMU(const Posef &pose, const Colour &colour, float size = DefaultIMUSize); 58 | 59 | static Ptr Create(const Posef &pose, 60 | float size = DefaultIMUSize, 61 | const Colour &colour = Colour::Red()); 62 | 63 | static Ptr Create(const Posef &pose, const Colour &colour, float size = DefaultIMUSize); 64 | 65 | ~IMU() override; 66 | 67 | void Draw() const override; 68 | 69 | IMU() = default; 70 | 71 | public: 72 | template 73 | void serialize(Archive &archive) { 74 | Entity::serialize(archive); 75 | archive(CEREAL_NVP(coord), CEREAL_NVP(cube)); 76 | } 77 | }; 78 | } // namespace ns_viewer 79 | 80 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::IMU, "IMU") 81 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::IMU) 82 | 83 | #endif // TINY_VIEWER_IMU_H 84 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/landmark.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_LANDMARK_H 36 | #define TINY_VIEWER_LANDMARK_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/point_cloud.hpp" 40 | #include "chrono" 41 | 42 | namespace ns_viewer { 43 | struct Landmark : public Entity { 44 | public: 45 | using Ptr = std::shared_ptr; 46 | 47 | protected: 48 | std::array verts; 49 | Colour color; 50 | float size{}; 51 | 52 | public: 53 | explicit Landmark(const Eigen::Vector3f &p, 54 | float size = DefaultLandmarkSize, 55 | const Colour &color = GetUniqueColour()); 56 | 57 | Landmark(const Eigen::Vector3f &p, const Colour &color, float size = DefaultLandmarkSize); 58 | 59 | static Ptr Create(const Eigen::Vector3f &p, 60 | float size = DefaultLandmarkSize, 61 | const Colour &color = GetUniqueColour()); 62 | 63 | static Ptr Create(const Eigen::Vector3f &p, 64 | const Colour &color, 65 | float size = DefaultLandmarkSize); 66 | 67 | ~Landmark() override = default; 68 | 69 | void Draw() const override; 70 | 71 | Landmark() = default; 72 | 73 | public: 74 | template 75 | void serialize(Archive &archive) { 76 | Entity::serialize(archive); 77 | archive(CEREAL_NVP(verts), CEREAL_NVP(color), CEREAL_NVP(size)); 78 | } 79 | }; 80 | 81 | template <> 82 | struct Cloud : public Entity { 83 | public: 84 | using Ptr = std::shared_ptr; 85 | 86 | protected: 87 | using PointCloud = pcl::PointCloud; 88 | using PointCloudPtr = PointCloud::Ptr; 89 | 90 | using RGBPointCloud = pcl::PointCloud; 91 | using RGBPointCloudPtr = RGBPointCloud::Ptr; 92 | 93 | using RGBAPointCloud = pcl::PointCloud; 94 | using RGBAPointCloudPtr = RGBAPointCloud::Ptr; 95 | 96 | std::vector landmarks; 97 | 98 | public: 99 | explicit Cloud(const PointCloudPtr &cloud, float size = DefaultLandmarkSize) 100 | : Entity() { 101 | landmarks.resize(cloud->size()); 102 | for (int i = 0; i < static_cast(cloud->size()); ++i) { 103 | const auto &p = cloud->at(i); 104 | landmarks.at(i) = Landmark({ExpandPCLPointXYZ(p)}, size); 105 | } 106 | } 107 | 108 | explicit Cloud(const RGBPointCloudPtr &cloud, float size = DefaultLandmarkSize) 109 | : Entity() { 110 | landmarks.resize(cloud->size()); 111 | for (int i = 0; i < static_cast(cloud->size()); ++i) { 112 | const auto &p = cloud->at(i); 113 | landmarks.at(i) = Landmark({ExpandPCLPointXYZ(p)}, size, Colour(ExpandPCLColor(p))); 114 | } 115 | } 116 | 117 | explicit Cloud(const RGBAPointCloudPtr &cloud, float size = DefaultLandmarkSize) 118 | : Entity() { 119 | landmarks.resize(cloud->size()); 120 | for (int i = 0; i < static_cast(cloud->size()); ++i) { 121 | const auto &p = cloud->at(i); 122 | landmarks.at(i) = Landmark({ExpandPCLPointXYZ(p)}, size, Colour(ExpandPCLColor(p))); 123 | } 124 | } 125 | 126 | static Ptr Create(const PointCloudPtr &cloud, float size = DefaultLandmarkSize) { 127 | return std::make_shared(cloud, size); 128 | } 129 | 130 | static Cloud::Ptr Random(float bound, std::size_t count, const Eigen::Vector3f ¢er) { 131 | std::default_random_engine engine( 132 | std::chrono::steady_clock::now().time_since_epoch().count()); 133 | std::uniform_real_distribution u(-bound, bound); 134 | PointCloudPtr cloud(new PointCloud); 135 | cloud->resize(count); 136 | for (int i = 0; i < static_cast(count); ++i) { 137 | pcl::PointXYZ &p = cloud->at(i); 138 | // x, y, z 139 | p.x = u(engine) + center(0); 140 | p.y = u(engine) + center(1); 141 | p.z = u(engine) + center(2); 142 | } 143 | return Cloud::Create(cloud); 144 | } 145 | 146 | ~Cloud() override = default; 147 | 148 | void Draw() const override { 149 | for (const auto &lm : landmarks) { 150 | lm.Draw(); 151 | } 152 | } 153 | 154 | Cloud() = default; 155 | 156 | public: 157 | template 158 | void serialize(Archive &archive) { 159 | Entity::serialize(archive); 160 | archive(cereal::make_nvp("landmarks", landmarks)); 161 | } 162 | }; 163 | } // namespace ns_viewer 164 | 165 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Landmark, "Landmark") 166 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Landmark) 167 | 168 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Cloud, "Cloud::Landmark") 169 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Cloud) 170 | #endif // TINY_VIEWER_LANDMARK_H 171 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/lidar.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_LIDAR_H 36 | #define TINY_VIEWER_LIDAR_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/coordinate.h" 40 | #include "tiny-viewer/entity/cylinder.h" 41 | #include "tiny-viewer/entity/cube.h" 42 | #include "tiny-viewer/entity/line.h" 43 | 44 | namespace ns_viewer { 45 | struct LiDAR : public Entity { 46 | public: 47 | using Ptr = std::shared_ptr; 48 | 49 | protected: 50 | Coordinate coord; 51 | 52 | Cylinder cylinder; 53 | 54 | public: 55 | explicit LiDAR(const Posef &pose, 56 | float size = DefaultLiDARSize, 57 | const Colour &color = Colour::Blue()); 58 | 59 | explicit LiDAR(const Posef &pose, const Colour &color, float size = DefaultLiDARSize); 60 | 61 | Ptr static Create(const Posef &pose, 62 | float size = DefaultLiDARSize, 63 | const Colour &color = Colour::Blue()); 64 | 65 | Ptr static Create(const Posef &pose, const Colour &color, float size = DefaultLiDARSize); 66 | 67 | ~LiDAR() override; 68 | 69 | void Draw() const override; 70 | 71 | LiDAR() = default; 72 | 73 | public: 74 | template 75 | void serialize(Archive &archive) { 76 | Entity::serialize(archive); 77 | archive(CEREAL_NVP(coord), CEREAL_NVP(cylinder)); 78 | } 79 | }; 80 | 81 | struct LivoxLiDAR : public Entity { 82 | public: 83 | using Ptr = std::shared_ptr; 84 | 85 | protected: 86 | Coordinate coord; 87 | Cube cube; 88 | std::array lines; 89 | 90 | public: 91 | explicit LivoxLiDAR(const Posef &pose, 92 | float size = DefaultLiDARSize, 93 | const Colour &color = Colour::Blue()); 94 | 95 | explicit LivoxLiDAR(const Posef &pose, const Colour &color, float size = DefaultLiDARSize); 96 | 97 | Ptr static Create(const Posef &pose, 98 | float size = DefaultLiDARSize, 99 | const Colour &color = Colour::Blue()); 100 | 101 | Ptr static Create(const Posef &pose, const Colour &color, float size = DefaultLiDARSize); 102 | 103 | ~LivoxLiDAR() override; 104 | 105 | void Draw() const override; 106 | 107 | LivoxLiDAR() = default; 108 | 109 | public: 110 | template 111 | void serialize(Archive &archive) { 112 | Entity::serialize(archive); 113 | archive(CEREAL_NVP(coord), CEREAL_NVP(cube), CEREAL_NVP(lines)); 114 | } 115 | }; 116 | } // namespace ns_viewer 117 | 118 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::LiDAR, "LiDAR") 119 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::LiDAR) 120 | 121 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::LivoxLiDAR, "LivoxLiDAR") 122 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::LivoxLiDAR) 123 | 124 | #endif // TINY_VIEWER_LIDAR_H 125 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/plane.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_PLANE_H 36 | #define TINY_VIEWER_PLANE_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "pangolin/gl/opengl_render_state.h" 40 | #include "tiny-viewer/entity/coordinate.h" 41 | 42 | namespace ns_viewer { 43 | struct Plane : public Entity { 44 | public: 45 | using Ptr = std::shared_ptr; 46 | 47 | protected: 48 | Eigen::Vector3f v1; 49 | Eigen::Vector3f v2; 50 | Eigen::Vector3f v3; 51 | Eigen::Vector3f v4; 52 | 53 | bool lineMode{}; 54 | Colour color; 55 | 56 | Coordinate coord; 57 | 58 | public: 59 | Plane(const Posef &pose, 60 | float mainWidth, 61 | float subWidth, 62 | bool lineMode, 63 | const Colour &color = GetUniqueColour(), 64 | pangolin::AxisDirection mainAxis = pangolin::AxisX, 65 | pangolin::AxisDirection subAxis = pangolin::AxisY); 66 | 67 | Plane(const Eigen::Vector4f &plane, 68 | float mainWidth, 69 | float subWidth, 70 | bool lineMode, 71 | const Colour &color = GetUniqueColour(), 72 | pangolin::AxisDirection mainAxis = pangolin::AxisX, 73 | pangolin::AxisDirection subAxis = pangolin::AxisY); 74 | 75 | static Ptr Create(const Posef &pose, 76 | float mainWidth, 77 | float subWidth, 78 | bool lineMode, 79 | const Colour &color = GetUniqueColour(), 80 | pangolin::AxisDirection mainAxis = pangolin::AxisX, 81 | pangolin::AxisDirection subAxis = pangolin::AxisY); 82 | 83 | static Ptr Create(const Eigen::Vector4f &plane, 84 | float mainWidth, 85 | float subWidth, 86 | bool lineMode, 87 | const Colour &color = GetUniqueColour(), 88 | pangolin::AxisDirection mainAxis = pangolin::AxisX, 89 | pangolin::AxisDirection subAxis = pangolin::AxisY); 90 | 91 | ~Plane() override; 92 | 93 | void Draw() const override; 94 | 95 | Plane() = default; 96 | 97 | public: 98 | template 99 | void serialize(Archive &archive) { 100 | Entity::serialize(archive); 101 | archive(CEREAL_NVP(v1), CEREAL_NVP(v2), CEREAL_NVP(v3), CEREAL_NVP(v4), CEREAL_NVP(color), 102 | CEREAL_NVP(lineMode), CEREAL_NVP(coord)); 103 | } 104 | }; 105 | } // namespace ns_viewer 106 | 107 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Plane, "Plane") 108 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Plane) 109 | #endif // TINY_VIEWER_PLANE_H 110 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/radar.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_RADAR_H 36 | #define TINY_VIEWER_RADAR_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/coordinate.h" 40 | 41 | namespace ns_viewer { 42 | 43 | struct Radar : public Entity { 44 | public: 45 | using Ptr = std::shared_ptr; 46 | 47 | protected: 48 | Coordinate coord; 49 | 50 | std::array tVerts; 51 | Eigen::Vector3f cenVert; 52 | std::array bVerts; 53 | 54 | Colour color; 55 | 56 | public: 57 | explicit Radar(const Posef &pose, 58 | float size = DefaultRadarSize, 59 | const Colour &color = Colour(0.2f, 0.2f, 0.2f)); 60 | 61 | explicit Radar(const Posef &pose, const Colour &color, float size = DefaultRadarSize); 62 | 63 | static Ptr Create(const Posef &pose, 64 | float size = DefaultRadarSize, 65 | const Colour &color = Colour(0.2f, 0.2f, 0.2f)); 66 | 67 | static Ptr Create(const Posef &pose, const Colour &color, float size = DefaultRadarSize); 68 | 69 | ~Radar() override = default; 70 | 71 | void Draw() const override; 72 | 73 | Radar() = default; 74 | 75 | public: 76 | template 77 | void serialize(Archive &archive) { 78 | Entity::serialize(archive); 79 | archive(CEREAL_NVP(coord), CEREAL_NVP(tVerts), CEREAL_NVP(cenVert), CEREAL_NVP(bVerts), 80 | CEREAL_NVP(color)); 81 | } 82 | }; 83 | } // namespace ns_viewer 84 | 85 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Radar, "Radar") 86 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Radar) 87 | 88 | #endif // TINY_VIEWER_RADAR_H 89 | -------------------------------------------------------------------------------- /src/include/tiny-viewer/object/surfel.h: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #ifndef TINY_VIEWER_SURFEL_H 36 | #define TINY_VIEWER_SURFEL_H 37 | 38 | #include "tiny-viewer/entity/entity.h" 39 | #include "tiny-viewer/entity/cube.h" 40 | #include "tiny-viewer/entity/polygon.h" 41 | 42 | namespace ns_viewer { 43 | struct Surfel : public Entity { 44 | public: 45 | using Ptr = std::shared_ptr; 46 | 47 | protected: 48 | Polygon polygon; 49 | bool drawCube{}; 50 | Cube cube; 51 | 52 | public: 53 | Surfel(const Eigen::Vector4f &plane, 54 | const Cube &cube, 55 | bool lineMode, 56 | bool drawCube = true, 57 | const Colour &color = GetUniqueColour()); 58 | 59 | static Ptr Create(const Eigen::Vector4f &plane, 60 | const Cube &cube, 61 | bool lineMode, 62 | bool drawCube = true, 63 | const Colour &color = GetUniqueColour()); 64 | 65 | ~Surfel() override; 66 | 67 | void Draw() const override; 68 | 69 | static Ptr Random(float bound); 70 | 71 | Surfel() = default; 72 | 73 | public: 74 | template 75 | void serialize(Archive &archive) { 76 | Entity::serialize(archive); 77 | archive(CEREAL_NVP(polygon), CEREAL_NVP(cube), CEREAL_NVP(drawCube)); 78 | } 79 | }; 80 | } // namespace ns_viewer 81 | 82 | CEREAL_REGISTER_TYPE_WITH_NAME(ns_viewer::Surfel, "Surfel") 83 | CEREAL_REGISTER_POLYMORPHIC_RELATION(ns_viewer::Entity, ns_viewer::Surfel) 84 | 85 | #endif // TINY_VIEWER_SURFEL_H 86 | -------------------------------------------------------------------------------- /src/src/core/pose.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/core/pose.hpp" 36 | 37 | namespace ns_viewer { 38 | template struct Pose; 39 | template struct Pose; 40 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/core/viewer_configor.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/core/viewer_configor.h" 36 | 37 | namespace ns_viewer { 38 | 39 | // -------------- 40 | // ViewerConfigor 41 | // -------------- 42 | ViewerConfigor::ViewerConfigor(const std::string &winName) 43 | : render(ObjRenderMode::NORMAL) { 44 | window.name = winName; 45 | } 46 | 47 | ViewerConfigor ViewerConfigor::LoadConfigure(const std::string &filename) { 48 | std::ifstream file(filename); 49 | ViewerConfigor configor; 50 | cereal::JSONInputArchive archive(file); 51 | archive(cereal::make_nvp("Configor", configor)); 52 | return configor; 53 | } 54 | 55 | bool ViewerConfigor::SaveConfigure(const std::string &filename) { 56 | std::ofstream file(filename); 57 | cereal::JSONOutputArchive archive(file); 58 | archive(cereal::make_nvp("Configor", *this)); 59 | return true; 60 | } 61 | 62 | ViewerConfigor &ViewerConfigor::WithWinName(const std::string &winName) { 63 | window.name = winName; 64 | return *this; 65 | } 66 | 67 | ViewerConfigor &ViewerConfigor::WithScreenShotSaveDir(const std::string &dir) { 68 | output.dataOutputPath = dir; 69 | return *this; 70 | } 71 | 72 | // ------------------- 73 | // MultiViewerConfigor 74 | // ------------------- 75 | 76 | MultiViewerConfigor::MultiViewerConfigor(const std::vector &subWinNames, 77 | const std::string &winName) 78 | : subWinNames(subWinNames), 79 | render(ObjRenderMode::NORMAL) { 80 | window.name = winName; 81 | for (const auto &name : this->subWinNames) { 82 | camera.insert({name, {}}); 83 | grid.insert({name, {}}); 84 | } 85 | window.width = static_cast(window.width * 2.0 * 0.8); 86 | window.height = static_cast(window.height * 0.8); 87 | } 88 | 89 | MultiViewerConfigor MultiViewerConfigor::LoadConfigure(const std::string &filename) { 90 | std::ifstream file(filename); 91 | MultiViewerConfigor configor({}); 92 | cereal::JSONInputArchive archive(file); 93 | archive(cereal::make_nvp("Configor", configor)); 94 | return configor; 95 | } 96 | 97 | bool MultiViewerConfigor::SaveConfigure(const std::string &filename) { 98 | std::ofstream file(filename); 99 | cereal::JSONOutputArchive archive(file); 100 | archive(cereal::make_nvp("Configor", *this)); 101 | return true; 102 | } 103 | 104 | MultiViewerConfigor &MultiViewerConfigor::WithWinName(const std::string &winName) { 105 | window.name = winName; 106 | return *this; 107 | } 108 | 109 | MultiViewerConfigor &MultiViewerConfigor::WithScreenShotSaveDir(const std::string &dir) { 110 | output.dataOutputPath = dir; 111 | return *this; 112 | } 113 | 114 | } // namespace ns_viewer 115 | -------------------------------------------------------------------------------- /src/src/entity/arrow.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE.00 34 | 35 | #include "tiny-viewer/entity/arrow.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/utils.hpp" 38 | 39 | namespace ns_viewer { 40 | Arrow::Arrow(Eigen::Vector3f sp, Eigen::Vector3f ep, float size, const Colour &color) 41 | : Entity(), 42 | sp(std::move(sp)), 43 | ep(std::move(ep)), 44 | size(size), 45 | color(color) { 46 | Eigen::Vector3f vec = this->ep - this->sp; 47 | float len = vec.norm(); 48 | Eigen::Vector3f dir = len * 0.05f * vec.normalized(); 49 | Eigen::Vector3f r = len * 0.025f * TangentBasis(dir).first; 50 | mp = this->sp + dir; 51 | 52 | const float deltaAng = M_PI * 2.0f / 4.0f; 53 | 54 | for (int i = 0; i < 4; ++i) { 55 | float ang = deltaAng * static_cast(i); 56 | Vector3f rv = Eigen::AngleAxisf(ang, dir.normalized()) * r; 57 | verts.at(i) = this->sp + dir + rv; 58 | } 59 | } 60 | 61 | Arrow::Arrow(Eigen::Vector3f sp, Eigen::Vector3f ep, const Colour &color, float size) 62 | : Arrow(std::move(sp), std::move(ep), size, color) {} 63 | 64 | Arrow::~Arrow() = default; 65 | 66 | void Arrow::Draw() const { 67 | glColor4f(ExpandColor(color)); 68 | glLineWidth(size); 69 | pangolin::glDrawLine(ExpandVec3(sp), ExpandVec3(ep)); 70 | for (int i = 0; i < 4; ++i) { 71 | pangolin::glDrawLine(ExpandVec3(verts.at(i)), ExpandVec3(sp)); 72 | pangolin::glDrawLine(ExpandVec3(verts.at(i)), ExpandVec3(mp)); 73 | } 74 | 75 | glPointSize(size * 2.0f); 76 | glBegin(GL_POINTS); 77 | glVertex3f(ExpandVec3(sp)); 78 | glVertex3f(ExpandVec3(ep)); 79 | glVertex3f(ExpandVec3(mp)); 80 | for (int i = 0; i < 4; ++i) { 81 | glVertex3f(ExpandVec3(verts.at(i))); 82 | } 83 | glEnd(); 84 | } 85 | 86 | std::shared_ptr Arrow::Create(const Vector3f &sp, 87 | const Vector3f &ep, 88 | const Colour &color, 89 | float size) { 90 | return std::make_shared(sp, ep, size, color); 91 | } 92 | 93 | std::shared_ptr Arrow::Create(const Vector3f &sp, 94 | const Vector3f &ep, 95 | float size, 96 | const Colour &color) { 97 | return std::make_shared(sp, ep, size, color); 98 | } 99 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/circle.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/circle.h" 36 | #include 37 | #include "pangolin/gl/gldraw.h" 38 | #include "pangolin/gl/gl.h" 39 | 40 | namespace ns_viewer { 41 | Circle::Circle(const Posef& pose, 42 | float radius, 43 | bool lineMode, 44 | bool drawCoord, 45 | const Colour& color, 46 | pangolin::AxisDirection nAxis, 47 | int ptCount) 48 | : coord(pose, radius), 49 | drawCoord(drawCoord) { 50 | std::pair basis; 51 | if (nAxis == pangolin::AxisX || nAxis == pangolin::AxisNegX) { 52 | basis.first = pose.rotation.col(1), basis.second = pose.rotation.col(2); 53 | } else if (nAxis == pangolin::AxisY || nAxis == pangolin::AxisNegY) { 54 | basis.first = pose.rotation.col(2), basis.second = pose.rotation.col(0); 55 | } else { 56 | basis.first = pose.rotation.col(0), basis.second = pose.rotation.col(1); 57 | } 58 | basis.first *= radius, basis.second *= radius; 59 | 60 | std::vector verts(ptCount); 61 | const float deltaAng = M_PI * 2.0f / static_cast(verts.size()); 62 | 63 | for (int i = 0; i < static_cast(verts.size()); ++i) { 64 | float ang = deltaAng * static_cast(i); 65 | float c = std::cos(ang); 66 | float s = std::sin(ang); 67 | verts.at(i) = pose.translation + c * basis.first + s * basis.second; 68 | } 69 | poly = Polygon(verts, lineMode, color); 70 | } 71 | 72 | Circle::Ptr Circle::Create(const Posef& pose, 73 | float radius, 74 | bool lineMode, 75 | bool drawCoord, 76 | const Colour& color, 77 | pangolin::AxisDirection nAxis, 78 | int ptCount) { 79 | return std::make_shared(pose, radius, lineMode, drawCoord, color, nAxis, ptCount); 80 | } 81 | 82 | Circle::~Circle() = default; 83 | 84 | void Circle::Draw() const { 85 | if (drawCoord) { 86 | coord.Draw(); 87 | } 88 | poly.Draw(); 89 | } 90 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/cone.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/cone.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Cone::Cone(const Posef &pose, float height, float angle, const Colour &color) 42 | : Entity(), 43 | color(color) { 44 | bp = pose.translation; 45 | Eigen::Vector3f x = pose.rotation.col(0); 46 | Eigen::Vector3f z = pose.rotation.col(2); 47 | tp = bp + z * height; 48 | 49 | const float deltaAng = M_PI * 2.0f / 8.0f; 50 | const float r = height * std::sin(angle); 51 | 52 | for (int i = 0; i < 8; ++i) { 53 | float ang = deltaAng * static_cast(i); 54 | Vector3f rv = Eigen::AngleAxisf(ang, z) * x * r; 55 | verts.at(i) = bp + rv; 56 | } 57 | } 58 | 59 | Cone::~Cone() = default; 60 | 61 | void Cone::Draw() const { 62 | glColor4f(ExpandColor(color)); 63 | glLineWidth(DefaultLineSize); 64 | for (int i = 0; i < 8; ++i) { 65 | const Eigen::Vector3f &vj = verts.at((i + 1) % 8); 66 | pangolin::glDrawLine(ExpandVec3(verts.at(i)), ExpandVec3(tp)); 67 | pangolin::glDrawLine(ExpandVec3(verts.at(i)), ExpandVec3(bp)); 68 | pangolin::glDrawLine(ExpandVec3(verts.at(i)), ExpandVec3(vj)); 69 | } 70 | 71 | glPointSize(DefaultPointSize); 72 | glBegin(GL_POINTS); 73 | glVertex3f(ExpandVec3(tp)); 74 | glVertex3f(ExpandVec3(bp)); 75 | for (int i = 0; i < 8; ++i) { 76 | glVertex3f(ExpandVec3(verts.at(i))); 77 | } 78 | glEnd(); 79 | } 80 | 81 | Cone::Ptr Cone::Create(const Posef &pose, float height, float angle, const Colour &color) { 82 | return std::make_shared(pose, height, angle, color); 83 | } 84 | 85 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/coordinate.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/coordinate.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | Coordinate::Coordinate(const ns_viewer::Posef &pose, float size) 41 | : Entity(), 42 | pose(pose.matrix44()), 43 | size(size) {} 44 | 45 | void Coordinate::Draw() const { 46 | glLineWidth(5.0f); 47 | pangolin::glDrawAxis(pose, size); 48 | } 49 | 50 | Coordinate::Ptr Coordinate::Create(const Posef &pose, float size) { 51 | return std::make_shared(pose, size); 52 | } 53 | 54 | Coordinate::~Coordinate() = default; 55 | } // namespace ns_viewer 56 | -------------------------------------------------------------------------------- /src/src/entity/cube.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/cube.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Cube::Cube( 42 | const Posef &pose, bool lineMode, float xWidth, float yWidth, float zWidth, const Colour &color) 43 | : Entity(), 44 | lineMode(lineMode), 45 | color(color) { 46 | Eigen::Vector3f p = pose.translation; 47 | Eigen::Vector3f x = pose.rotation.col(0) * xWidth * 0.5f; 48 | Eigen::Vector3f y = pose.rotation.col(1) * yWidth * 0.5f; 49 | Eigen::Vector3f z = pose.rotation.col(2) * zWidth * 0.5f; 50 | 51 | v1 = p + x + y + z; 52 | v2 = p + x - y + z; 53 | v3 = p + x + y - z; 54 | v4 = p + x - y - z; 55 | 56 | v5 = p - x + y + z; 57 | v6 = p - x - y + z; 58 | v7 = p - x + y - z; 59 | v8 = p - x - y - z; 60 | } 61 | 62 | Cube::Cube( 63 | const Posef &pose, bool lineMode, const Colour &color, float xWidth, float yWidth, float zWidth) 64 | : Cube(pose, lineMode, xWidth, yWidth, zWidth, color) {} 65 | 66 | Cube::~Cube() = default; 67 | 68 | void Cube::Draw() const { 69 | glColor4f(ExpandColor(color)); 70 | 71 | if (lineMode) { 72 | glLineWidth(DefaultLineSize); 73 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v2)); 74 | pangolin::glDrawLine(ExpandVec3(v3), ExpandVec3(v4)); 75 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v3)); 76 | pangolin::glDrawLine(ExpandVec3(v2), ExpandVec3(v4)); 77 | 78 | pangolin::glDrawLine(ExpandVec3(v5), ExpandVec3(v6)); 79 | pangolin::glDrawLine(ExpandVec3(v7), ExpandVec3(v8)); 80 | pangolin::glDrawLine(ExpandVec3(v5), ExpandVec3(v7)); 81 | pangolin::glDrawLine(ExpandVec3(v6), ExpandVec3(v8)); 82 | 83 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v5)); 84 | pangolin::glDrawLine(ExpandVec3(v2), ExpandVec3(v6)); 85 | pangolin::glDrawLine(ExpandVec3(v3), ExpandVec3(v7)); 86 | pangolin::glDrawLine(ExpandVec3(v4), ExpandVec3(v8)); 87 | 88 | } else { 89 | const GLfloat verts[] = { 90 | ExpandVec3(v1), ExpandVec3(v2), ExpandVec3(v3), ExpandVec3(v4), // FRONT 91 | ExpandVec3(v5), ExpandVec3(v6), ExpandVec3(v7), ExpandVec3(v8), // BACK 92 | ExpandVec3(v1), ExpandVec3(v3), ExpandVec3(v5), ExpandVec3(v7), // LEFT 93 | ExpandVec3(v2), ExpandVec3(v4), ExpandVec3(v6), ExpandVec3(v8), // RIGHT 94 | ExpandVec3(v1), ExpandVec3(v2), ExpandVec3(v5), ExpandVec3(v6), // TOP 95 | ExpandVec3(v3), ExpandVec3(v4), ExpandVec3(v7), ExpandVec3(v8) // BOTTOM 96 | }; 97 | 98 | glVertexPointer(3, GL_FLOAT, 0, verts); 99 | glEnableClientState(GL_VERTEX_ARRAY); 100 | 101 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 102 | glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); 103 | 104 | glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); 105 | glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); 106 | 107 | glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); 108 | glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); 109 | 110 | glDisableClientState(GL_VERTEX_ARRAY); 111 | } 112 | 113 | glPointSize(DefaultPointSize); 114 | glBegin(GL_POINTS); 115 | glVertex3f(ExpandVec3(v1)); 116 | glVertex3f(ExpandVec3(v2)); 117 | glVertex3f(ExpandVec3(v3)); 118 | glVertex3f(ExpandVec3(v4)); 119 | glVertex3f(ExpandVec3(v5)); 120 | glVertex3f(ExpandVec3(v6)); 121 | glVertex3f(ExpandVec3(v7)); 122 | glVertex3f(ExpandVec3(v8)); 123 | glEnd(); 124 | } 125 | 126 | Cube::Ptr Cube::Create(const Posef &pose, 127 | bool lineMode, 128 | float xWidth, 129 | float yWidth, 130 | float zWidth, 131 | const Colour &color) { 132 | return std::make_shared(pose, lineMode, xWidth, yWidth, zWidth, color); 133 | } 134 | 135 | Cube::Ptr Cube::Create(const Posef &pose, 136 | bool lineMode, 137 | const Colour &color, 138 | float xWidth, 139 | float yWidth, 140 | float zWidth) { 141 | return std::make_shared(pose, lineMode, xWidth, yWidth, zWidth, color); 142 | } 143 | 144 | std::array Cube::GetVertices() const { 145 | return {v1, v2, v3, v4, v5, v6, v7, v8}; 146 | } 147 | 148 | Eigen::Vector3f Cube::GetCenter() const { return (v1 + v2 + v7 + v8) * 0.25f; } 149 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/cylinder.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/cylinder.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "pangolin/gl/gl.h" 38 | #include "tiny-viewer/core/pose.hpp" 39 | 40 | namespace ns_viewer { 41 | Cylinder::Cylinder(const Posef &pose, float height, float radius, const Colour &color) 42 | : Entity(), 43 | color(color) { 44 | Eigen::Vector3f p = pose.translation; 45 | Eigen::Vector3f x = pose.rotation.col(0) * radius; 46 | Eigen::Vector3f y = pose.rotation.col(1) * radius; 47 | Eigen::Vector3f z = pose.rotation.col(2) * height * 0.5f; 48 | const float deltaAng = M_PI * 2.0f / 8.0f; 49 | 50 | for (int i = 0; i < 8; ++i) { 51 | float ang = deltaAng * static_cast(i); 52 | float c = std::cos(ang); 53 | float s = std::sin(ang); 54 | tops.at(i) = p + c * x + s * y + z; 55 | bottoms.at(i) = p + c * x + s * y - z; 56 | } 57 | } 58 | 59 | Cylinder::Ptr Cylinder::Create(const Posef &pose, float height, float radius, const Colour &color) { 60 | return std::make_shared(pose, height, radius, color); 61 | } 62 | 63 | Cylinder::~Cylinder() = default; 64 | 65 | void Cylinder::Draw() const { 66 | glColor4f(ExpandColor(color)); 67 | glLineWidth(DefaultLineSize); 68 | 69 | for (int i = 0; i < 8; ++i) { 70 | int j = (i + 1) % 8; 71 | const Eigen::Vector3f &tvi = tops.at(i); 72 | const Eigen::Vector3f &tvj = tops.at(j); 73 | pangolin::glDrawLine(ExpandVec3(tvi), ExpandVec3(tvj)); 74 | 75 | const Eigen::Vector3f &bvi = bottoms.at(i); 76 | const Eigen::Vector3f &bvj = bottoms.at(j); 77 | pangolin::glDrawLine(ExpandVec3(bvi), ExpandVec3(bvj)); 78 | 79 | pangolin::glDrawLine(ExpandVec3(tvi), ExpandVec3(bvi)); 80 | } 81 | glPointSize(DefaultPointSize); 82 | glBegin(GL_POINTS); 83 | for (int i = 0; i < 8; ++i) { 84 | const Eigen::Vector3f &tvi = tops.at(i); 85 | const Eigen::Vector3f &bvi = bottoms.at(i); 86 | glVertex3f(ExpandVec3(tvi)); 87 | glVertex3f(ExpandVec3(bvi)); 88 | } 89 | glEnd(); 90 | } 91 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/entity.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/entity.h" 36 | 37 | namespace ns_viewer { 38 | 39 | ColourWheel Entity::COLOR_WHEEL = ColourWheel(1.0f); 40 | std::size_t Entity::counter = 0; 41 | 42 | Entity::Entity() 43 | : id(GenUniqueName()) {} 44 | 45 | Entity::~Entity() = default; 46 | 47 | std::size_t Entity::GenUniqueName() { return counter++; } 48 | 49 | Colour Entity::GetUniqueColour() { return COLOR_WHEEL.GetUniqueColour(); } 50 | 51 | const std::size_t &Entity::GetId() const { return id; } 52 | } // namespace ns_viewer 53 | -------------------------------------------------------------------------------- /src/src/entity/line.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/line.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/utils.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Line::Line(Eigen::Vector3f sp, Eigen::Vector3f ep, float size, const Colour &color) 42 | : Entity(), 43 | sp(std::move(sp)), 44 | ep(std::move(ep)), 45 | size(size), 46 | color(color) {} 47 | 48 | Line::Line(Eigen::Vector3f sp, Eigen::Vector3f ep, const Colour &color, float size) 49 | : Line(std::move(sp), std::move(ep), size, color) {} 50 | 51 | Line::~Line() = default; 52 | 53 | void Line::Draw() const { 54 | glColor4f(ExpandColor(color)); 55 | glLineWidth(size); 56 | pangolin::glDrawLine(ExpandVec3(sp), ExpandVec3(ep)); 57 | glPointSize(size * 2.0f); 58 | glBegin(GL_POINTS); 59 | glVertex3f(ExpandVec3(sp)); 60 | glVertex3f(ExpandVec3(ep)); 61 | glEnd(); 62 | } 63 | 64 | std::shared_ptr Line::Create(const Vector3f &sp, 65 | const Vector3f &ep, 66 | const Colour &color, 67 | float size) { 68 | return std::make_shared(sp, ep, size, color); 69 | } 70 | 71 | std::shared_ptr Line::Create(const Vector3f &sp, 72 | const Vector3f &ep, 73 | float size, 74 | const Colour &color) { 75 | return std::make_shared(sp, ep, size, color); 76 | } 77 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/path.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/path.h" 36 | 37 | namespace ns_viewer { 38 | 39 | std::vector Bezier::Solve(const std::vector &controlPoints, 40 | std::size_t num) { 41 | float t = 0.0f, delta = 1.0f / static_cast(num - 1); 42 | std::vector result(num); 43 | 44 | for (int i = 0; i < static_cast(num); ++i) { 45 | result[i] = Solve(t, controlPoints, 0, controlPoints.size()); 46 | t += delta; 47 | } 48 | return result; 49 | } 50 | 51 | Eigen::Vector3f Bezier::Solve(float t, 52 | const std::vector &controlPoints, 53 | std::size_t beg, 54 | std::size_t end) { 55 | if (end - beg == 1) { 56 | return controlPoints[beg]; 57 | } else { 58 | auto p1 = Solve(t, controlPoints, beg, end - 1); 59 | p1(0) *= 1 - t; 60 | p1(1) *= 1 - t; 61 | p1(2) *= 1 - t; 62 | auto p2 = Solve(t, controlPoints, beg + 1, end); 63 | p2(0) *= t; 64 | p2(1) *= t; 65 | p2(2) *= t; 66 | return {p1(0) + p2(0), p1(1) + p2(1), p1(2) + p2(2)}; 67 | } 68 | } 69 | 70 | Path::Path(const std::string &svgCode, float size, const Colour &color) 71 | : lines(ParseSVGCode(svgCode, size, color)) {} 72 | 73 | Path::Path(const std::string &svgCode, const Colour &color, float size) 74 | : Path(svgCode, size, color) {} 75 | 76 | void Path::Draw() const { 77 | for (const auto &line : lines) { 78 | line.Draw(); 79 | } 80 | } 81 | 82 | Path::Ptr Path::Create(const std::string &svgCode, float size, const Colour &color) { 83 | return std::make_shared(svgCode, size, color); 84 | } 85 | 86 | Path::Ptr Path::Create(const std::string &svgCode, const Colour &color, float size) { 87 | return std::make_shared(svgCode, color, size); 88 | } 89 | 90 | std::vector Path::ParseSVGCode(const std::string &svgCode, float size, const Colour &color) { 91 | auto codes = StringSplit(svgCode, ' ', true); 92 | std::vector>> data; 93 | for (int i = 0; i < static_cast(codes.size());) { 94 | const auto &code = codes.at(i); 95 | if (IsSVGPathControlCode(code)) { 96 | // control code 97 | data.push_back({code.front(), {}}); 98 | int j = i + 1; 99 | for (; j < static_cast(codes.size()); ++j) { 100 | auto nextCode = codes.at(j); 101 | if (IsSVGPathControlCode(nextCode)) { 102 | break; 103 | } 104 | data.back().second.push_back(std::stof(nextCode)); 105 | } 106 | i = j; 107 | } 108 | } 109 | if (data.front().first != 'M' && data.front().first != 'm') { 110 | return {}; 111 | } 112 | 113 | std::vector lines; 114 | Eigen::Vector3f firPoint = Eigen::Vector3f::Zero(), lastPoint = Eigen::Vector3f::Zero(); 115 | for (const auto &[code, vec] : data) { 116 | switch (code) { 117 | case 'M': { 118 | Eigen::Vector3f curPoint = {vec.at(0), vec.at(1), vec.at(2)}; 119 | lastPoint = curPoint; 120 | firPoint = curPoint; 121 | break; 122 | } 123 | case 'm': { 124 | Eigen::Vector3f curPoint = 125 | lastPoint + Eigen::Vector3f{vec.at(0), vec.at(1), vec.at(2)}; 126 | lastPoint = curPoint; 127 | firPoint = curPoint; 128 | break; 129 | } 130 | case 'L': { 131 | Eigen::Vector3f curPoint = {vec.at(0), vec.at(1), vec.at(2)}; 132 | lines.emplace_back(lastPoint, curPoint, size, color); 133 | lastPoint = curPoint; 134 | break; 135 | } 136 | case 'l': { 137 | Eigen::Vector3f curPoint = 138 | lastPoint + Eigen::Vector3f{vec.at(0), vec.at(1), vec.at(2)}; 139 | lines.emplace_back(lastPoint, curPoint, size, color); 140 | lastPoint = curPoint; 141 | break; 142 | } 143 | case 'S': { 144 | std::vector cps(1 + vec.size() / 3); 145 | cps.front() = lastPoint; 146 | for (int i = 0; i < static_cast(vec.size()); ++i) { 147 | cps.at(1 + i / 3)(i % 3) = vec.at(i); 148 | } 149 | auto pts = 150 | Bezier::Solve(cps, 2 + static_cast(CurveLength(cps) / 0.25f)); 151 | for (int i = 0; i < static_cast(pts.size()) - 1; ++i) { 152 | lines.emplace_back(pts.at(i), pts.at(i + 1), size, color); 153 | } 154 | lastPoint = cps.back(); 155 | break; 156 | } 157 | case 's': { 158 | std::vector cps(1 + vec.size() / 3); 159 | cps.front() = lastPoint; 160 | for (int i = 0; i < static_cast(vec.size()); ++i) { 161 | cps.at(1 + i / 3)(i % 3) = vec.at(i); 162 | } 163 | for (int i = 1; i < static_cast(cps.size()); ++i) { 164 | cps.at(i) += cps.at(i - 1); 165 | } 166 | 167 | auto pts = 168 | Bezier::Solve(cps, 2 + static_cast(CurveLength(cps) / 0.25f)); 169 | for (int i = 0; i < static_cast(pts.size()) - 1; ++i) { 170 | lines.emplace_back(pts.at(i), pts.at(i + 1), size, color); 171 | } 172 | lastPoint = cps.back(); 173 | break; 174 | } 175 | case 'Z': 176 | case 'z': { 177 | lines.emplace_back(lastPoint, firPoint, size, color); 178 | break; 179 | } 180 | default: 181 | break; 182 | } 183 | } 184 | 185 | return lines; 186 | } 187 | 188 | bool Path::IsSVGPathControlCode(const std::string &str) { 189 | if (str.size() != 1) { 190 | return false; 191 | } 192 | auto code = str.front(); 193 | if (code == 'M' || code == 'm' || code == 'L' || code == 'l' || code == 'Z' || code == 'z' || 194 | code == 'S' || code == 's') { 195 | return true; 196 | } else { 197 | return false; 198 | } 199 | } 200 | 201 | float Path::CurveLength(const std::vector &pts) { 202 | float len = 0.0f; 203 | for (int i = 0; i < static_cast(pts.size()) - 1; ++i) { 204 | const Eigen::Vector3f &p1 = pts.at(i); 205 | const Eigen::Vector3f &p2 = pts.at(i + 1); 206 | len += (p1 - p2).norm(); 207 | } 208 | return len; 209 | } 210 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/polygon.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/polygon.h" 36 | #include "pangolin/gl/gldraw.h" 37 | 38 | namespace ns_viewer { 39 | 40 | Polygon::Polygon(const std::vector &verts, bool lineMode, const Colour &color) 41 | : Entity(), 42 | verts(verts), 43 | lineMode(lineMode), 44 | color(color) {} 45 | 46 | Polygon::~Polygon() = default; 47 | 48 | Polygon::Ptr Polygon::Create(const std::vector &verts, 49 | bool lineMode, 50 | const Colour &color) { 51 | return std::make_shared(verts, lineMode, color); 52 | } 53 | 54 | void Polygon::Draw() const { 55 | glColor4f(ExpandColor(color)); 56 | if (lineMode) { 57 | glPointSize(DefaultPointSize); 58 | glBegin(GL_POINTS); 59 | for (const auto &v : verts) { 60 | glVertex3f(ExpandVec3(v)); 61 | } 62 | glEnd(); 63 | glLineWidth(DefaultLineSize); 64 | glBegin(GL_LINE_LOOP); 65 | for (const auto &v : verts) { 66 | glVertex3f(ExpandVec3(v)); 67 | } 68 | glEnd(); 69 | } else { 70 | glBegin(GL_POLYGON); 71 | for (const auto &v : verts) { 72 | glVertex3f(ExpandVec3(v)); 73 | } 74 | glEnd(); 75 | } 76 | } 77 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/entity/util.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/entity/utils.h" 36 | 37 | namespace ns_viewer { 38 | 39 | vtkSmartPointer GetColormapLUT( 40 | pcl::visualization::LookUpTableRepresentationProperties colormapType, double *minmax) { 41 | vtkSmartPointer table = vtkSmartPointer::New(); 42 | table->SetTableRange(minmax[0], minmax[1]); 43 | 44 | switch (colormapType) { 45 | case IntensityMode::PCL_VISUALIZER_LUT_JET: { 46 | table->SetHueRange(0, 0.667); 47 | table->SetSaturationRange(1, 1); 48 | table->SetAlphaRange(1, 1); 49 | break; 50 | } 51 | case IntensityMode::PCL_VISUALIZER_LUT_JET_INVERSE: { 52 | table->SetHueRange(0.667, 0); 53 | table->SetSaturationRange(1, 1); 54 | table->SetAlphaRange(1, 1); 55 | break; 56 | } 57 | case IntensityMode::PCL_VISUALIZER_LUT_HSV: { 58 | table->SetHueRange(0, 1); 59 | table->SetSaturationRange(1, 1); 60 | table->SetAlphaRange(1, 1); 61 | break; 62 | } 63 | case IntensityMode::PCL_VISUALIZER_LUT_HSV_INVERSE: { 64 | table->SetHueRange(1, 0); 65 | table->SetSaturationRange(1, 1); 66 | table->SetAlphaRange(1, 1); 67 | break; 68 | } 69 | case IntensityMode::PCL_VISUALIZER_LUT_GREY: { 70 | table->SetValueRange(0, 1); 71 | table->SetHueRange(0, 0); 72 | table->SetSaturationRange(0, 0); 73 | table->SetAlphaRange(1, 1); 74 | break; 75 | } 76 | case IntensityMode::PCL_VISUALIZER_LUT_BLUE2RED: { 77 | table->SetSaturationRange(1, 1); 78 | table->SetAlphaRange(1, 1); 79 | table->SetNumberOfTableValues(256); 80 | 81 | double red[3] = {1.0, 0.0, 0.0}; 82 | double white[3] = {1.0, 1.0, 1.0}; 83 | double blue[3] = {0.0, 0.0, 1.0}; 84 | 85 | for (std::size_t i = 0; i < 128; i++) { 86 | double weight = static_cast(i) / 128.0; 87 | table->SetTableValue(static_cast(i), 88 | white[0] * weight + blue[0] * (1 - weight), 89 | white[1] * weight + blue[1] * (1 - weight), 90 | white[2] * weight + blue[2] * (1 - weight)); 91 | } 92 | 93 | for (std::size_t i = 128; i < 256; i++) { 94 | double weight = (static_cast(i) - 128.0) / 128.0; 95 | table->SetTableValue(static_cast(i), 96 | red[0] * weight + white[0] * (1 - weight), 97 | red[1] * weight + white[1] * (1 - weight), 98 | red[2] * weight + white[2] * (1 - weight)); 99 | } 100 | break; 101 | } 102 | case IntensityMode::PCL_VISUALIZER_LUT_VIRIDIS: { 103 | table->SetSaturationRange(1, 1); 104 | table->SetAlphaRange(1, 1); 105 | table->SetNumberOfTableValues(static_cast(pcl::ViridisLUT::size())); 106 | for (std::size_t i = 0; i < pcl::ViridisLUT::size(); i++) { 107 | pcl::RGB c = pcl::ViridisLUT::at(i); 108 | table->SetTableValue(static_cast(i), static_cast(c.r) / 255.0, 109 | static_cast(c.g) / 255.0, 110 | static_cast(c.b) / 255.0); 111 | } 112 | break; 113 | } 114 | default: { 115 | table->SetHueRange(0, 0.667); 116 | table->SetSaturationRange(1, 1); 117 | table->SetAlphaRange(1, 1); 118 | break; 119 | } 120 | } 121 | table->Build(); 122 | return table; 123 | } 124 | 125 | std::pair TangentBasis(const Eigen::Vector3f &v) { 126 | Eigen::Vector3f b, c; 127 | Eigen::Vector3f a = v.normalized(); 128 | Eigen::Vector3f tmp(0, 0, 1); 129 | if (a == tmp || a == -tmp) tmp << 1, 0, 0; 130 | b = (tmp - a * (a.transpose() * tmp)).normalized(); 131 | c = a.cross(b); 132 | return {b, c}; 133 | } 134 | 135 | std::optional LinePlaneIntersection(const Eigen::Vector3f &ls, 136 | const Eigen::Vector3f &le, 137 | const Eigen::Vector3f &norm, 138 | float d) { 139 | float ds = norm.dot(ls) + d; 140 | float de = norm.dot(le) + d; 141 | if (ds * de > 0.0) { 142 | // small side 143 | return {}; 144 | } else if (ds == 0.0) { 145 | // ls in plane 146 | return ls; 147 | } else if (de == 0.0) { 148 | // le in plane 149 | return le; 150 | } else { 151 | // intersection 152 | float nds = std::abs(ds), nde = std::abs(de); 153 | return (nds * le + nde * ls) / (nds + nde); 154 | } 155 | } 156 | 157 | std::vector StringSplit(const std::string &str, char splitor, bool ignoreEmpty) { 158 | std::vector vec; 159 | auto iter = str.cbegin(); 160 | while (true) { 161 | auto pos = std::find(iter, str.cend(), splitor); 162 | auto elem = std::string(iter, pos); 163 | if (!(elem.empty() && ignoreEmpty)) { 164 | vec.push_back(elem); 165 | } 166 | if (pos == str.cend()) { 167 | break; 168 | } 169 | iter = ++pos; 170 | } 171 | return vec; 172 | } 173 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/camera.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/camera.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | //------- 42 | // camera 43 | // ------ 44 | Camera::Camera(const Posef &pose, float size, const Colour &color) 45 | : Entity(), 46 | coord(pose, size), 47 | color(color) { 48 | v0 = pose.translation; 49 | Eigen::Vector3f x = pose.rotation.col(0) * size; 50 | Eigen::Vector3f y = pose.rotation.col(1) * size; 51 | Eigen::Vector3f z = pose.rotation.col(2) * size; 52 | 53 | v1 = v0 - x - y * 0.75f + z; 54 | v2 = v0 + x - y * 0.75f + z; 55 | v3 = v0 - x + y * 0.75f + z; 56 | v4 = v0 + x + y * 0.75f + z; 57 | } 58 | 59 | Camera::Camera(const Posef &pose, const Colour &color, float size) 60 | : Camera(pose, size, color) {} 61 | 62 | Camera::~Camera() = default; 63 | 64 | Camera::Ptr Camera::Create(const Posef &pose, float size, const Colour &color) { 65 | return std::make_shared(pose, size, color); 66 | } 67 | 68 | Camera::Ptr Camera::Create(const Posef &pose, const Colour &color, float size) { 69 | return std::make_shared(pose, size, color); 70 | } 71 | 72 | void Camera::Draw() const { 73 | coord.Draw(); 74 | glColor4f(ExpandColor(color)); 75 | glLineWidth(DefaultLineSize); 76 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v1)); 77 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v2)); 78 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v3)); 79 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v4)); 80 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v2)); 81 | pangolin::glDrawLine(ExpandVec3(v3), ExpandVec3(v4)); 82 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v3)); 83 | pangolin::glDrawLine(ExpandVec3(v2), ExpandVec3(v4)); 84 | glPointSize(DefaultPointSize); 85 | glBegin(GL_POINTS); 86 | glVertex3f(ExpandVec3(v0)); 87 | glVertex3f(ExpandVec3(v1)); 88 | glVertex3f(ExpandVec3(v2)); 89 | glVertex3f(ExpandVec3(v3)); 90 | glVertex3f(ExpandVec3(v4)); 91 | glEnd(); 92 | } 93 | 94 | //------- 95 | // camera 96 | // ------ 97 | CubeCamera::CubeCamera(const Posef &pose, float size, const Colour &color) 98 | : Entity(), 99 | coord(pose, size), 100 | color(color), 101 | cube(pose, true) { 102 | v0 = pose.translation; 103 | Eigen::Vector3f x = pose.rotation.col(0) * size; 104 | Eigen::Vector3f y = pose.rotation.col(1) * size; 105 | Eigen::Vector3f z = pose.rotation.col(2) * size; 106 | 107 | v1 = v0 - x * 0.6f - y * 0.6f + z; 108 | v2 = v0 + x * 0.6f - y * 0.6f + z; 109 | v3 = v0 - x * 0.6f + y * 0.6f + z; 110 | v4 = v0 + x * 0.6f + y * 0.6f + z; 111 | 112 | cube = Cube(Posef(pose.rotation, v0 - z * 0.75f), true, size * 1.2f, size * 1.2f, size * 1.5f, 113 | color); 114 | } 115 | 116 | CubeCamera::CubeCamera(const Posef &pose, const Colour &color, float size) 117 | : CubeCamera(pose, size, color) {} 118 | 119 | CubeCamera::~CubeCamera() = default; 120 | 121 | CubeCamera::Ptr CubeCamera::Create(const Posef &pose, float size, const Colour &color) { 122 | return std::make_shared(pose, size, color); 123 | } 124 | 125 | CubeCamera::Ptr CubeCamera::Create(const Posef &pose, const Colour &color, float size) { 126 | return std::make_shared(pose, size, color); 127 | } 128 | 129 | void CubeCamera::Draw() const { 130 | coord.Draw(); 131 | cube.Draw(); 132 | glColor4f(ExpandColor(color)); 133 | glLineWidth(DefaultLineSize); 134 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v1)); 135 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v2)); 136 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v3)); 137 | pangolin::glDrawLine(ExpandVec3(v0), ExpandVec3(v4)); 138 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v2)); 139 | pangolin::glDrawLine(ExpandVec3(v3), ExpandVec3(v4)); 140 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v3)); 141 | pangolin::glDrawLine(ExpandVec3(v2), ExpandVec3(v4)); 142 | glPointSize(DefaultPointSize); 143 | glBegin(GL_POINTS); 144 | glVertex3f(ExpandVec3(v0)); 145 | glVertex3f(ExpandVec3(v1)); 146 | glVertex3f(ExpandVec3(v2)); 147 | glVertex3f(ExpandVec3(v3)); 148 | glVertex3f(ExpandVec3(v4)); 149 | glEnd(); 150 | } 151 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/imu.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/imu.h" 36 | 37 | namespace ns_viewer { 38 | 39 | IMU::IMU(const Posef &pose, float size, const Colour &colour) 40 | : Entity(), 41 | coord(pose, size), 42 | cube(pose, true, size * 2.0f, size * 2.0f, size * 2.0f, colour) {} 43 | 44 | IMU::~IMU() = default; 45 | 46 | IMU::Ptr IMU::Create(const Posef &pose, float size, const Colour &colour) { 47 | return std::make_shared(pose, size, colour); 48 | } 49 | 50 | IMU::IMU(const Posef &pose, const Colour &colour, float size) 51 | : IMU(pose, size, colour) {} 52 | 53 | IMU::Ptr IMU::Create(const Posef &pose, const Colour &colour, float size) { 54 | return std::make_shared(pose, size, colour); 55 | } 56 | 57 | void IMU::Draw() const { 58 | cube.Draw(); 59 | coord.Draw(); 60 | } 61 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/landmark.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/landmark.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Landmark::Landmark(const Vector3f &p, float size, const Colour &color) 42 | : color(color), 43 | size(size) { 44 | constexpr float scales[7][3] = { 45 | {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, 46 | {0.58f, 0.58f, 0.58f}, {-0.58f, 0.58f, 0.58f}, {0.58f, 0.58f, -0.58f}, 47 | {-0.58f, 0.58f, -0.58f}, 48 | }; 49 | 50 | for (int i = 0; i < static_cast(verts.size()); i += 2) { 51 | Eigen::Vector3f delta = 52 | Eigen::Vector3f{scales[i / 2][0], scales[i / 2][1], scales[i / 2][2]} * size; 53 | verts.at(i + 0) = p + delta, verts.at(i + 1) = p - delta; 54 | } 55 | } 56 | 57 | Landmark::Landmark(const Vector3f &p, const Colour &color, float size) 58 | : Landmark(p, size, color) {} 59 | 60 | Landmark::Ptr Landmark::Create(const Vector3f &p, float size, const Colour &color) { 61 | return std::make_shared(p, size, color); 62 | } 63 | 64 | Landmark::Ptr Landmark::Create(const Vector3f &p, const Colour &color, float size) { 65 | return std::make_shared(p, color, size); 66 | } 67 | 68 | void Landmark::Draw() const { 69 | glColor4f(ExpandColor(color)); 70 | glLineWidth(DefaultLineSize); 71 | for (int i = 0; i < static_cast(verts.size()); i += 2) { 72 | pangolin::glDrawLine(ExpandVec3(verts.at(i + 0)), ExpandVec3(verts.at(i + 1))); 73 | } 74 | } 75 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/lidar.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/lidar.h" 36 | 37 | namespace ns_viewer { 38 | 39 | LiDAR::LiDAR(const Posef &pose, float size, const Colour &color) 40 | : Entity(), 41 | coord(pose, size), 42 | cylinder(pose, size * 2.0f, size, color) {} 43 | 44 | LiDAR::LiDAR(const Posef &pose, const Colour &color, float size) 45 | : LiDAR(pose, size, color) {} 46 | 47 | LiDAR::Ptr LiDAR::Create(const Posef &pose, const Colour &color, float size) { 48 | return std::make_shared(pose, size, color); 49 | } 50 | 51 | LiDAR::Ptr LiDAR::Create(const Posef &pose, float size, const Colour &color) { 52 | return std::make_shared(pose, size, color); 53 | } 54 | 55 | LiDAR::~LiDAR() = default; 56 | 57 | void LiDAR::Draw() const { 58 | coord.Draw(); 59 | cylinder.Draw(); 60 | } 61 | 62 | LivoxLiDAR::LivoxLiDAR(const Posef &pose, float size, const Colour &color) 63 | : Entity(), 64 | coord(pose, size), 65 | cube(pose, true, size * 2.0f, size, size, color) { 66 | const auto &vertices = cube.GetVertices(); 67 | Eigen::Vector3f v1 = vertices.at(0) + 0.25f * (vertices.at(3) - vertices.at(0)); 68 | Eigen::Vector3f v2 = vertices.at(3) + 0.25f * (vertices.at(0) - vertices.at(3)); 69 | Eigen::Vector3f v3 = vertices.at(1) + 0.25f * (vertices.at(2) - vertices.at(1)); 70 | Eigen::Vector3f v4 = vertices.at(2) + 0.25f * (vertices.at(1) - vertices.at(2)); 71 | 72 | lines.at(0) = Line(v1, vertices.at(0), color); 73 | lines.at(1) = Line(v2, vertices.at(3), color); 74 | lines.at(2) = Line(v3, vertices.at(1), color); 75 | lines.at(3) = Line(v4, vertices.at(2), color); 76 | 77 | lines.at(4) = Line(v1, v3, color); 78 | lines.at(5) = Line(v1, v4, color); 79 | lines.at(6) = Line(v2, v3, color); 80 | lines.at(7) = Line(v2, v4, color); 81 | 82 | lines.at(8) = Line(vertices.at(4), vertices.at(7), color); 83 | lines.at(9) = Line(vertices.at(6), vertices.at(5), color); 84 | } 85 | 86 | LivoxLiDAR::LivoxLiDAR(const Posef &pose, const Colour &color, float size) 87 | : LivoxLiDAR(pose, size, color) {} 88 | 89 | LivoxLiDAR::Ptr LivoxLiDAR::Create(const Posef &pose, const Colour &color, float size) { 90 | return std::make_shared(pose, size, color); 91 | } 92 | 93 | LivoxLiDAR::Ptr LivoxLiDAR::Create(const Posef &pose, float size, const Colour &color) { 94 | return std::make_shared(pose, size, color); 95 | } 96 | 97 | LivoxLiDAR::~LivoxLiDAR() = default; 98 | 99 | void LivoxLiDAR::Draw() const { 100 | coord.Draw(); 101 | cube.Draw(); 102 | for (const auto &line : lines) { 103 | line.Draw(); 104 | } 105 | } 106 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/plane.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "pangolin/gl/gldraw.h" 36 | #include "tiny-viewer/object/plane.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Plane::Plane(const Posef &pose, 42 | float mainWidth, 43 | float subWidth, 44 | bool lineMode, 45 | const Colour &color, 46 | pangolin::AxisDirection mainAxis, 47 | pangolin::AxisDirection subAxis) 48 | : Entity(), 49 | lineMode(lineMode), 50 | color(color), 51 | coord(pose, 0.5f * std::min(mainWidth, subWidth)) { 52 | Eigen::Vector3f p = pose.translation; 53 | 54 | Eigen::Vector3f ma = 0.5f * mainWidth * pose.rotation * 55 | Eigen::Vector3f(ExpandAryVec3(pangolin::AxisDirectionVector[mainAxis])); 56 | Eigen::Vector3f sa = 0.5f * subWidth * pose.rotation * 57 | Eigen::Vector3f(ExpandAryVec3(pangolin::AxisDirectionVector[subAxis])); 58 | 59 | v1 = p + ma + sa; 60 | v2 = p + ma - sa; 61 | v3 = p - ma - sa; 62 | v4 = p - ma + sa; 63 | } 64 | 65 | Plane::Plane(const Vector4f &plane, 66 | float mainWidth, 67 | float subWidth, 68 | bool lineMode, 69 | const Colour &color, 70 | pangolin::AxisDirection mainAxis, 71 | pangolin::AxisDirection subAxis) 72 | : Plane( 73 | [&plane]() { 74 | Eigen::Vector3f zAxis = plane.block<3, 1>(0, 0); 75 | std::pair axis = TangentBasis(zAxis); 76 | Eigen::Matrix3f rotMat; 77 | rotMat.col(0) = axis.first; 78 | rotMat.col(1) = axis.second; 79 | rotMat.col(2) = zAxis; 80 | return Posef(rotMat, -plane(3, 0) * zAxis); 81 | }(), 82 | mainWidth, 83 | subWidth, 84 | lineMode, 85 | color, 86 | mainAxis, 87 | subAxis) {} 88 | 89 | Plane::Ptr Plane::Create(const Posef &pose, 90 | float mainWidth, 91 | float subWidth, 92 | bool lineMode, 93 | const Colour &color, 94 | pangolin::AxisDirection mainAxis, 95 | pangolin::AxisDirection subAxis) { 96 | return std::make_shared(pose, mainWidth, subWidth, lineMode, color, mainAxis, subAxis); 97 | } 98 | 99 | Plane::Ptr Plane::Create(const Vector4f &plane, 100 | float mainWidth, 101 | float subWidth, 102 | bool lineMode, 103 | const Colour &color, 104 | pangolin::AxisDirection mainAxis, 105 | pangolin::AxisDirection subAxis) { 106 | return std::make_shared(plane, mainWidth, subWidth, lineMode, color, mainAxis, subAxis); 107 | } 108 | 109 | Plane::~Plane() = default; 110 | 111 | void Plane::Draw() const { 112 | coord.Draw(); 113 | glColor4f(ExpandColor(color)); 114 | if (lineMode) { 115 | glLineWidth(DefaultLineSize); 116 | pangolin::glDrawLine(ExpandVec3(v1), ExpandVec3(v2)); 117 | pangolin::glDrawLine(ExpandVec3(v2), ExpandVec3(v3)); 118 | pangolin::glDrawLine(ExpandVec3(v3), ExpandVec3(v4)); 119 | pangolin::glDrawLine(ExpandVec3(v4), ExpandVec3(v1)); 120 | } else { 121 | const GLfloat verts[] = { 122 | ExpandVec3(v1), ExpandVec3(v2), ExpandVec3(v3), 123 | ExpandVec3(v1), ExpandVec3(v3), ExpandVec3(v4), 124 | }; 125 | 126 | glVertexPointer(3, GL_FLOAT, 0, verts); 127 | glEnableClientState(GL_VERTEX_ARRAY); 128 | glDrawArrays(GL_TRIANGLES, 0, 6); 129 | 130 | glDisableClientState(GL_VERTEX_ARRAY); 131 | } 132 | glPointSize(DefaultPointSize); 133 | glBegin(GL_POINTS); 134 | glVertex3f(ExpandVec3(v1)); 135 | glVertex3f(ExpandVec3(v2)); 136 | glVertex3f(ExpandVec3(v3)); 137 | glVertex3f(ExpandVec3(v4)); 138 | glEnd(); 139 | } 140 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/radar.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/radar.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/pose.hpp" 38 | 39 | namespace ns_viewer { 40 | 41 | Radar::Radar(const Posef &pose, float size, const Colour &color) 42 | : coord(pose, size), 43 | color(color) { 44 | cenVert = pose.translation; 45 | Eigen::Vector3f x = pose.rotation.col(0); 46 | Eigen::Vector3f y = pose.rotation.col(1); 47 | Eigen::Vector3f z = pose.rotation.col(2); 48 | 49 | { 50 | Eigen::Vector3f ep = cenVert + x * size; 51 | const float deltaAng = M_PI * 2.0f / 8.0f; 52 | const auto r = static_cast(size * std::tan(M_PI / 5.0)); 53 | 54 | for (int i = 0; i < 8; ++i) { 55 | float ang = deltaAng * static_cast(i); 56 | Eigen::Vector3f rv = y * r * std::cos(ang) + z * r * std::sin(ang); 57 | tVerts.at(i) = ep + rv; 58 | } 59 | } 60 | { 61 | Eigen::Vector3f ep = cenVert - z * size; 62 | const float deltaAng = M_PI * 2.0f / 4.0f; 63 | const auto r = static_cast(size * std::tan(M_PI / 8.0)); 64 | for (int i = 0; i < 4; ++i) { 65 | float ang = deltaAng * static_cast(i); 66 | Eigen::Vector3f rv = x * r * std::cos(ang) + y * r * std::sin(ang); 67 | bVerts.at(i) = ep + rv; 68 | } 69 | } 70 | } 71 | 72 | void Radar::Draw() const { 73 | coord.Draw(); 74 | 75 | glColor4f(ExpandColor(color)); 76 | glLineWidth(DefaultLineSize); 77 | for (int i = 0; i < 8; ++i) { 78 | const Eigen::Vector3f &vj = tVerts.at((i + 1) % 8); 79 | pangolin::glDrawLine(ExpandVec3(tVerts.at(i)), ExpandVec3(cenVert)); 80 | pangolin::glDrawLine(ExpandVec3(tVerts.at(i)), ExpandVec3(vj)); 81 | } 82 | for (int i = 0; i < 4; ++i) { 83 | const Eigen::Vector3f &vj = bVerts.at((i + 1) % 4); 84 | pangolin::glDrawLine(ExpandVec3(bVerts.at(i)), ExpandVec3(cenVert)); 85 | pangolin::glDrawLine(ExpandVec3(bVerts.at(i)), ExpandVec3(vj)); 86 | } 87 | 88 | glPointSize(DefaultPointSize); 89 | glBegin(GL_POINTS); 90 | glVertex3f(ExpandVec3(cenVert)); 91 | for (int i = 0; i < 8; ++i) { 92 | glVertex3f(ExpandVec3(tVerts.at(i))); 93 | } 94 | for (int i = 0; i < 4; ++i) { 95 | glVertex3f(ExpandVec3(bVerts.at(i))); 96 | } 97 | glEnd(); 98 | } 99 | 100 | Radar::Ptr Radar::Create(const Posef &pose, float size, const Colour &color) { 101 | return std::make_shared(pose, size, color); 102 | } 103 | 104 | Radar::Ptr Radar::Create(const Posef &pose, const Colour &color, float size) { 105 | return std::make_shared(pose, color, size); 106 | } 107 | 108 | Radar::Radar(const Posef &pose, const Colour &color, float size) 109 | : Radar(pose, size, color) {} 110 | } // namespace ns_viewer -------------------------------------------------------------------------------- /src/src/object/surfel.cpp: -------------------------------------------------------------------------------- 1 | // Tiny-Viewer: Tiny But Powerful Graphic Entity And Object Visualization 2 | // Copyright 2024, the School of Geodesy and Geomatics (SGG), Wuhan University, China 3 | // https://github.com/Unsigned-Long/tiny-viewer.git 4 | // 5 | // Author: Shuolong Chen (shlchen@whu.edu.cn) 6 | // GitHub: https://github.com/Unsigned-Long 7 | // ORCID: 0000-0002-5283-9057 8 | // 9 | // Purpose: See .h/.hpp file. 10 | // 11 | // Redistribution and use in source and binary forms, with or without 12 | // modification, are permitted provided that the following conditions are met: 13 | // 14 | // * Redistributions of source code must retain the above copyright notice, 15 | // this list of conditions and the following disclaimer. 16 | // * Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // * The names of its contributors can not be 20 | // used to endorse or promote products derived from this software without 21 | // specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | 35 | #include "tiny-viewer/object/surfel.h" 36 | #include "pangolin/gl/gldraw.h" 37 | #include "tiny-viewer/core/utils.hpp" 38 | #include "tiny-viewer/core/pose.hpp" 39 | #include "random" 40 | 41 | namespace ns_viewer { 42 | 43 | Surfel::Surfel(const Vector4f &plane, 44 | const Cube &cube, 45 | const bool lineMode, 46 | bool drawCube, 47 | const Colour &color) 48 | : Entity(), 49 | drawCube(drawCube), 50 | cube(cube) { 51 | auto v = cube.GetVertices(); 52 | Eigen::Vector3f norm = plane.block<3, 1>(0, 0); 53 | float dist = plane(3, 0); 54 | 55 | std::vector verts; 56 | verts.reserve(10); 57 | 58 | #define INTERSECT_HELP(i, j) \ 59 | if (auto p = LinePlaneIntersection(v[i], v[j], norm, dist); p) { \ 60 | verts.push_back(*p); \ 61 | } 62 | 63 | INTERSECT_HELP(0, 1) 64 | INTERSECT_HELP(2, 3) 65 | INTERSECT_HELP(4, 5) 66 | INTERSECT_HELP(6, 7) 67 | 68 | INTERSECT_HELP(0, 2) 69 | INTERSECT_HELP(1, 3) 70 | INTERSECT_HELP(4, 6) 71 | INTERSECT_HELP(5, 7) 72 | 73 | INTERSECT_HELP(0, 4) 74 | INTERSECT_HELP(1, 5) 75 | INTERSECT_HELP(2, 6) 76 | INTERSECT_HELP(3, 7) 77 | 78 | Eigen::Vector3f cen = cube.GetCenter(); 79 | std::pair axis = TangentBasis(norm); 80 | 81 | std::sort(verts.begin(), verts.end(), 82 | [&cen, &axis](const Eigen::Vector3f &v1, const Eigen::Vector3f &v2) { 83 | Eigen::Vector3f d1 = v1 - cen, d2 = v2 - cen; 84 | float theta1 = std::atan2(d1.dot(axis.second), d1.dot(axis.first)); 85 | float theta2 = std::atan2(d2.dot(axis.second), d2.dot(axis.first)); 86 | return theta1 < theta2; 87 | }); 88 | 89 | #undef INTERSECT_HELP 90 | polygon = Polygon(verts, lineMode, color); 91 | } 92 | 93 | Surfel::~Surfel() = default; 94 | 95 | void Surfel::Draw() const { 96 | if (drawCube) { 97 | cube.Draw(); 98 | } 99 | polygon.Draw(); 100 | } 101 | 102 | Surfel::Ptr Surfel::Create( 103 | const Vector4f &plane, const Cube &cube, bool lineMode, bool drawCube, const Colour &color) { 104 | return std::make_shared(plane, cube, lineMode, drawCube, color); 105 | } 106 | 107 | Surfel::Ptr Surfel::Random(float bound) { 108 | std::default_random_engine engine(std::chrono::steady_clock::now().time_since_epoch().count()); 109 | std::uniform_real_distribution u1(0.5f, 1.0f); 110 | std::uniform_real_distribution u2(-bound, bound); 111 | Eigen::Vector3f norm = Eigen::Vector3f(u2(engine), u2(engine), u2(engine)).normalized(); 112 | auto pose = Posef::Random(bound); 113 | return Surfel::Create({ExpandVec3(norm), -pose.translation.dot(norm)}, 114 | Cube(pose, true, u1(engine), u1(engine), u1(engine)), false); 115 | } 116 | } // namespace ns_viewer --------------------------------------------------------------------------------