├── .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 |
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