Spaces:
Sleeping
Sleeping
fdb148a938e069f29f1ee84c16b5db040cb743b8bffcc1ce2cfc429d88d8feea
Browse files- third-party/DPVO/Pangolin/components/pango_python/src/pypangolin/window.hpp +37 -0
- third-party/DPVO/Pangolin/components/pango_python/src/pypangolin_embed.cpp +32 -0
- third-party/DPVO/Pangolin/components/pango_python/src/pypangolin_module.cpp +33 -0
- third-party/DPVO/Pangolin/components/pango_scene/CMakeLists.txt +15 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/axis.h +117 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/interactive.h +69 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/interactive_index.h +115 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/renderable.h +79 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/scenehandler.h +192 -0
- third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/tree.h +49 -0
- third-party/DPVO/Pangolin/components/pango_scene/src/renderable.cpp +66 -0
- third-party/DPVO/Pangolin/components/pango_tools/CMakeLists.txt +15 -0
- third-party/DPVO/Pangolin/components/pango_tools/include/pangolin/tools/video_viewer.h +106 -0
- third-party/DPVO/Pangolin/components/pango_tools/src/video_viewer.cpp +452 -0
- third-party/DPVO/Pangolin/components/pango_vars/CMakeLists.txt +22 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/var.h +172 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varextra.h +92 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varinit.h +71 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varstate.h +269 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvalue.h +135 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvaluegeneric.h +111 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvaluet.h +46 -0
- third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varwrapper.h +87 -0
- third-party/DPVO/Pangolin/components/pango_vars/src/vars.cpp +57 -0
- third-party/DPVO/Pangolin/components/pango_vars/src/varstate.cpp +233 -0
- third-party/DPVO/Pangolin/components/pango_vars/tests/test_all.cpp +409 -0
- third-party/DPVO/Pangolin/components/pango_video/CMakeLists.txt +241 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/debayer.h +130 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/deinterlace.h +62 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/depthsense.h +170 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg.h +87 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_common.h +127 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_convert.h +100 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_output.h +111 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/firewire.h +253 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/gamma.h +85 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/images.h +121 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/images_out.h +60 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/join.h +80 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/merge.h +69 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/mjpeg.h +77 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni.h +70 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni2.h +145 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni_common.h +154 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pack.h +83 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pango.h +105 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pango_video_output.h +69 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pleora.h +195 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/realsense.h +80 -0
- third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/realsense2.h +80 -0
third-party/DPVO/Pangolin/components/pango_python/src/pypangolin/window.hpp
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) Andrey Mnatsakanov
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pybind11/pybind11.h>
|
31 |
+
|
32 |
+
namespace py_pangolin {
|
33 |
+
|
34 |
+
void bind_window(pybind11::module &m);
|
35 |
+
|
36 |
+
} // py_pangolin
|
37 |
+
|
third-party/DPVO/Pangolin/components/pango_python/src/pypangolin_embed.cpp
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#include "pypangolin/pypangolin.h"
|
29 |
+
|
30 |
+
PYBIND11_EMBEDDED_MODULE(pypangolin, m) {
|
31 |
+
pypangolin::PopulateModule(m);
|
32 |
+
}
|
third-party/DPVO/Pangolin/components/pango_python/src/pypangolin_module.cpp
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#include "pypangolin/pypangolin.h"
|
29 |
+
|
30 |
+
PYBIND11_MODULE(pypangolin, m) {
|
31 |
+
pypangolin::PopulateModule(m);
|
32 |
+
}
|
33 |
+
|
third-party/DPVO/Pangolin/components/pango_scene/CMakeLists.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME)
|
2 |
+
|
3 |
+
target_sources( ${COMPONENT}
|
4 |
+
PRIVATE
|
5 |
+
${CMAKE_CURRENT_LIST_DIR}/src/renderable.cpp
|
6 |
+
)
|
7 |
+
|
8 |
+
target_link_libraries(${COMPONENT} PUBLIC pango_opengl)
|
9 |
+
target_include_directories(${COMPONENT} PUBLIC
|
10 |
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
11 |
+
$<INSTALL_INTERFACE:include>
|
12 |
+
)
|
13 |
+
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include"
|
14 |
+
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
15 |
+
)
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/axis.h
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/gl/opengl_render_state.h>
|
4 |
+
#include <pangolin/gl/viewport.h>
|
5 |
+
#include <pangolin/gl/gldraw.h>
|
6 |
+
|
7 |
+
#include <pangolin/scene/renderable.h>
|
8 |
+
#include <pangolin/scene/interactive_index.h>
|
9 |
+
|
10 |
+
#ifdef HAVE_EIGEN
|
11 |
+
# include <Eigen/Geometry>
|
12 |
+
#endif
|
13 |
+
|
14 |
+
namespace pangolin {
|
15 |
+
|
16 |
+
struct Axis : public Renderable, public Interactive
|
17 |
+
{
|
18 |
+
Axis()
|
19 |
+
: axis_length(1.0),
|
20 |
+
label_x(InteractiveIndex::I().Store(this)),
|
21 |
+
label_y(InteractiveIndex::I().Store(this)),
|
22 |
+
label_z(InteractiveIndex::I().Store(this))
|
23 |
+
{
|
24 |
+
}
|
25 |
+
|
26 |
+
void Render(const RenderParams&) override {
|
27 |
+
glColor4f(1,0,0,1);
|
28 |
+
glPushName(label_x.Id());
|
29 |
+
glDrawLine(0,0,0, axis_length,0,0);
|
30 |
+
glPopName();
|
31 |
+
|
32 |
+
glColor4f(0,1,0,1);
|
33 |
+
glPushName(label_y.Id());
|
34 |
+
glDrawLine(0,0,0, 0,axis_length,0);
|
35 |
+
glPopName();
|
36 |
+
|
37 |
+
glColor4f(0,0,1,1);
|
38 |
+
glPushName(label_z.Id());
|
39 |
+
glDrawLine(0,0,0, 0,0,axis_length);
|
40 |
+
glPopName();
|
41 |
+
}
|
42 |
+
|
43 |
+
bool Mouse(
|
44 |
+
int button,
|
45 |
+
const GLprecision /*win*/[3], const GLprecision /*obj*/[3], const GLprecision /*normal*/[3],
|
46 |
+
bool /*pressed*/, int button_state, int pickId
|
47 |
+
) override
|
48 |
+
{
|
49 |
+
PANGOLIN_UNUSED(button);
|
50 |
+
PANGOLIN_UNUSED(button_state);
|
51 |
+
PANGOLIN_UNUSED(pickId);
|
52 |
+
|
53 |
+
#ifdef HAVE_EIGEN
|
54 |
+
if((button == MouseWheelUp || button == MouseWheelDown) ) {
|
55 |
+
float scale = (button == MouseWheelUp) ? 0.01f : -0.01f;
|
56 |
+
if(button_state & KeyModifierShift) scale /= 10;
|
57 |
+
|
58 |
+
Eigen::Vector3d rot = Eigen::Vector3d::Zero();
|
59 |
+
Eigen::Vector3d xyz = Eigen::Vector3d::Zero();
|
60 |
+
|
61 |
+
|
62 |
+
if(button_state & KeyModifierCtrl) {
|
63 |
+
// rotate
|
64 |
+
if(pickId == label_x.Id()) {
|
65 |
+
rot << 1,0,0;
|
66 |
+
}else if(pickId == label_y.Id()) {
|
67 |
+
rot << 0,1,0;
|
68 |
+
}else if(pickId == label_z.Id()) {
|
69 |
+
rot << 0,0,1;
|
70 |
+
}else{
|
71 |
+
return false;
|
72 |
+
}
|
73 |
+
}else if(button_state & KeyModifierShift){
|
74 |
+
// translate
|
75 |
+
if(pickId == label_x.Id()) {
|
76 |
+
xyz << 1,0,0;
|
77 |
+
}else if(pickId == label_y.Id()) {
|
78 |
+
xyz << 0,1,0;
|
79 |
+
}else if(pickId == label_z.Id()) {
|
80 |
+
xyz << 0,0,1;
|
81 |
+
}else{
|
82 |
+
return false;
|
83 |
+
}
|
84 |
+
}else{
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
|
88 |
+
// old from new
|
89 |
+
Eigen::Matrix<double,4,4> T_on = Eigen::Matrix<double,4,4>::Identity();
|
90 |
+
T_on.block<3,3>(0,0) = Eigen::AngleAxis<double>(scale,rot).toRotationMatrix();
|
91 |
+
T_on.block<3,1>(0,3) = scale*xyz;
|
92 |
+
|
93 |
+
// Update
|
94 |
+
T_pc = (ToEigen<double>(T_pc) * T_on.inverse()).eval();
|
95 |
+
|
96 |
+
return true;
|
97 |
+
}
|
98 |
+
#endif // HAVE_EIGEN
|
99 |
+
|
100 |
+
return false;
|
101 |
+
}
|
102 |
+
|
103 |
+
virtual bool MouseMotion(
|
104 |
+
const GLprecision /*win*/[3], const GLprecision /*obj*/[3], const GLprecision /*normal*/[3],
|
105 |
+
int /*button_state*/, int /*pickId*/
|
106 |
+
) override
|
107 |
+
{
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
|
111 |
+
float axis_length;
|
112 |
+
const InteractiveIndex::Token label_x;
|
113 |
+
const InteractiveIndex::Token label_y;
|
114 |
+
const InteractiveIndex::Token label_z;
|
115 |
+
};
|
116 |
+
|
117 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/interactive.h
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/gl/glplatform.h>
|
31 |
+
#include <pangolin/gl/opengl_render_state.h>
|
32 |
+
|
33 |
+
namespace pangolin {
|
34 |
+
|
35 |
+
|
36 |
+
struct Interactive
|
37 |
+
{
|
38 |
+
static __thread GLuint current_id;
|
39 |
+
|
40 |
+
virtual ~Interactive() {}
|
41 |
+
|
42 |
+
virtual bool Mouse(
|
43 |
+
int button,
|
44 |
+
const GLprecision win[3], const GLprecision obj[3], const GLprecision normal[3],
|
45 |
+
bool pressed, int button_state, int pickId
|
46 |
+
) = 0;
|
47 |
+
|
48 |
+
virtual bool MouseMotion(
|
49 |
+
const GLprecision win[3], const GLprecision obj[3], const GLprecision normal[3],
|
50 |
+
int button_state, int pickId
|
51 |
+
) = 0;
|
52 |
+
};
|
53 |
+
|
54 |
+
struct RenderParams
|
55 |
+
{
|
56 |
+
RenderParams()
|
57 |
+
: render_mode(GL_RENDER)
|
58 |
+
{
|
59 |
+
}
|
60 |
+
|
61 |
+
GLint render_mode;
|
62 |
+
};
|
63 |
+
|
64 |
+
struct Manipulator : public Interactive
|
65 |
+
{
|
66 |
+
virtual void Render(const RenderParams& params) = 0;
|
67 |
+
};
|
68 |
+
|
69 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/interactive_index.h
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <map>
|
31 |
+
|
32 |
+
#include <pangolin/scene/interactive.h>
|
33 |
+
|
34 |
+
namespace pangolin {
|
35 |
+
|
36 |
+
class InteractiveIndex
|
37 |
+
{
|
38 |
+
public:
|
39 |
+
class Token
|
40 |
+
{
|
41 |
+
public:
|
42 |
+
friend class InteractiveIndex;
|
43 |
+
|
44 |
+
Token()
|
45 |
+
: id(0)
|
46 |
+
{
|
47 |
+
}
|
48 |
+
|
49 |
+
Token(Token&& o)
|
50 |
+
: id(o.id)
|
51 |
+
{
|
52 |
+
o.id = 0;
|
53 |
+
}
|
54 |
+
|
55 |
+
GLint Id() const
|
56 |
+
{
|
57 |
+
return id;
|
58 |
+
}
|
59 |
+
|
60 |
+
~Token()
|
61 |
+
{
|
62 |
+
if(id) {
|
63 |
+
InteractiveIndex::I().Unstore(*this);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
private:
|
68 |
+
Token(GLint id)
|
69 |
+
: id(id)
|
70 |
+
{
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
GLint id;
|
75 |
+
};
|
76 |
+
|
77 |
+
static InteractiveIndex& I()
|
78 |
+
{
|
79 |
+
static InteractiveIndex instance;
|
80 |
+
return instance;
|
81 |
+
}
|
82 |
+
|
83 |
+
Interactive* Find(GLuint id)
|
84 |
+
{
|
85 |
+
auto kv = index.find(id);
|
86 |
+
if(kv != index.end()) {
|
87 |
+
return kv->second;
|
88 |
+
}
|
89 |
+
return nullptr;
|
90 |
+
}
|
91 |
+
|
92 |
+
Token Store(Interactive* r)
|
93 |
+
{
|
94 |
+
index[next_id] = r;
|
95 |
+
return Token(next_id++);
|
96 |
+
}
|
97 |
+
|
98 |
+
void Unstore(Token& t)
|
99 |
+
{
|
100 |
+
index.erase(t.id);
|
101 |
+
t.id = 0;
|
102 |
+
}
|
103 |
+
|
104 |
+
private:
|
105 |
+
// Private constructor.
|
106 |
+
InteractiveIndex()
|
107 |
+
: next_id(1)
|
108 |
+
{
|
109 |
+
}
|
110 |
+
|
111 |
+
GLint next_id;
|
112 |
+
std::map<GLint, Interactive*> index;
|
113 |
+
};
|
114 |
+
|
115 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/renderable.h
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <memory>
|
31 |
+
#include <map>
|
32 |
+
#include <random>
|
33 |
+
|
34 |
+
#include <pangolin/gl/opengl_render_state.h>
|
35 |
+
#include <pangolin/scene/interactive.h>
|
36 |
+
|
37 |
+
namespace pangolin {
|
38 |
+
|
39 |
+
class Renderable
|
40 |
+
{
|
41 |
+
public:
|
42 |
+
using guid_t = GLuint;
|
43 |
+
|
44 |
+
static guid_t UniqueGuid();
|
45 |
+
|
46 |
+
Renderable(const std::weak_ptr<Renderable>& parent = std::weak_ptr<Renderable>());
|
47 |
+
|
48 |
+
virtual ~Renderable();
|
49 |
+
|
50 |
+
// Default implementation simply renders children.
|
51 |
+
virtual void Render(const RenderParams& params = RenderParams());
|
52 |
+
|
53 |
+
void RenderChildren(const RenderParams& params);
|
54 |
+
|
55 |
+
std::shared_ptr<Renderable> FindChild(guid_t guid);
|
56 |
+
|
57 |
+
Renderable& Add(const std::shared_ptr<Renderable>& child);
|
58 |
+
|
59 |
+
void Remove(const std::shared_ptr<Renderable>& child)
|
60 |
+
{
|
61 |
+
if(child) {
|
62 |
+
children.erase(child->guid);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
// Renderable properties
|
67 |
+
const guid_t guid;
|
68 |
+
std::weak_ptr<Renderable> parent;
|
69 |
+
pangolin::OpenGlMatrix T_pc;
|
70 |
+
bool should_show;
|
71 |
+
|
72 |
+
// Children
|
73 |
+
std::map<guid_t, std::shared_ptr<Renderable>> children;
|
74 |
+
|
75 |
+
// Manipulator (handler, thing)
|
76 |
+
std::shared_ptr<Manipulator> manipulator;
|
77 |
+
};
|
78 |
+
|
79 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/scenehandler.h
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/handler/handler.h>
|
4 |
+
#include <pangolin/scene/renderable.h>
|
5 |
+
#include <pangolin/scene/interactive_index.h>
|
6 |
+
|
7 |
+
namespace pangolin {
|
8 |
+
|
9 |
+
inline void gluPickMatrix(
|
10 |
+
GLdouble x, GLdouble y,
|
11 |
+
GLdouble width, GLdouble height,
|
12 |
+
GLint viewport[4]
|
13 |
+
) {
|
14 |
+
GLfloat m[16];
|
15 |
+
GLfloat sx, sy;
|
16 |
+
GLfloat tx, ty;
|
17 |
+
sx = viewport[2] / (GLfloat)width;
|
18 |
+
sy = viewport[3] / (GLfloat)height;
|
19 |
+
tx = (viewport[2] + 2.0f * (viewport[0] - (GLfloat)x)) / (GLfloat)width;
|
20 |
+
ty = (viewport[3] + 2.0f * (viewport[1] - (GLfloat)y)) / (GLfloat)height;
|
21 |
+
#define M(row, col) m[col*4+row]
|
22 |
+
M(0, 0) = sx;
|
23 |
+
M(0, 1) = 0.0f;
|
24 |
+
M(0, 2) = 0.0f;
|
25 |
+
M(0, 3) = tx;
|
26 |
+
M(1, 0) = 0.0f;
|
27 |
+
M(1, 1) = sy;
|
28 |
+
M(1, 2) = 0.0f;
|
29 |
+
M(1, 3) = ty;
|
30 |
+
M(2, 0) = 0.0f;
|
31 |
+
M(2, 1) = 0.0f;
|
32 |
+
M(2, 2) = 1.0f;
|
33 |
+
M(2, 3) = 0.0f;
|
34 |
+
M(3, 0) = 0.0f;
|
35 |
+
M(3, 1) = 0.0f;
|
36 |
+
M(3, 2) = 0.0f;
|
37 |
+
M(3, 3) = 1.0f;
|
38 |
+
#undef M
|
39 |
+
glMultMatrixf(m);
|
40 |
+
}
|
41 |
+
|
42 |
+
struct SelectedObject {
|
43 |
+
|
44 |
+
SelectedObject(const GLuint pickId, Interactive* const interactive)
|
45 |
+
: pickId(pickId), interactive(interactive) {}
|
46 |
+
|
47 |
+
GLuint pickId;
|
48 |
+
Interactive* interactive;
|
49 |
+
};
|
50 |
+
|
51 |
+
struct SceneHandler : public Handler3D
|
52 |
+
{
|
53 |
+
SceneHandler(
|
54 |
+
Renderable& scene,
|
55 |
+
OpenGlRenderState& cam_state
|
56 |
+
) : Handler3D(cam_state), scene(scene)
|
57 |
+
{
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
void ProcessHitBuffer(GLint hits, GLuint* buf, std::map<GLuint, SelectedObject>& hit_map )
|
62 |
+
{
|
63 |
+
for (int hit = 0; hit < hits; hit++)
|
64 |
+
{
|
65 |
+
// buf[0] is the amount of named objects
|
66 |
+
// buf[1] is the z distance
|
67 |
+
// buf[2] is an array of names (aka pickId) with length buf[0]
|
68 |
+
for(unsigned int name = 0; name < buf[0]; name++)
|
69 |
+
{
|
70 |
+
const int pickId = (buf + 3)[name];
|
71 |
+
hit_map.emplace(std::pair(buf[1],
|
72 |
+
SelectedObject(pickId, InteractiveIndex::I().Find(pickId))));
|
73 |
+
}
|
74 |
+
buf += buf[0] + 3;
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
void ComputeHits(pangolin::View& view,
|
79 |
+
const pangolin::OpenGlRenderState& cam_state,
|
80 |
+
int x, int y, int grab_width,
|
81 |
+
std::map<GLuint, SelectedObject>& hit_objects )
|
82 |
+
{
|
83 |
+
// Get views viewport / modelview /projection
|
84 |
+
GLint viewport[4] = {view.v.l, view.v.b, view.v.w, view.v.h};
|
85 |
+
pangolin::OpenGlMatrix mv = cam_state.GetModelViewMatrix();
|
86 |
+
pangolin::OpenGlMatrix proj = cam_state.GetProjectionMatrix();
|
87 |
+
|
88 |
+
// Prepare hit buffer object
|
89 |
+
const unsigned int MAX_SEL_SIZE = 64;
|
90 |
+
GLuint vSelectBuf[MAX_SEL_SIZE];
|
91 |
+
glSelectBuffer(MAX_SEL_SIZE, vSelectBuf);
|
92 |
+
|
93 |
+
// Load and adjust modelview projection matrices
|
94 |
+
glMatrixMode(GL_PROJECTION);
|
95 |
+
glLoadIdentity();
|
96 |
+
gluPickMatrix(x, y, grab_width, grab_width, viewport);
|
97 |
+
proj.Multiply();
|
98 |
+
glMatrixMode(GL_MODELVIEW);
|
99 |
+
mv.Load();
|
100 |
+
|
101 |
+
// Render scenegraph in 'select' mode
|
102 |
+
glRenderMode(GL_SELECT);
|
103 |
+
glInitNames();
|
104 |
+
RenderParams select;
|
105 |
+
select.render_mode = GL_SELECT;
|
106 |
+
scene.Render(select);
|
107 |
+
glFlush();
|
108 |
+
|
109 |
+
GLint nHits = glRenderMode(GL_RENDER);
|
110 |
+
if (nHits > 0) {
|
111 |
+
ProcessHitBuffer(nHits, vSelectBuf, hit_objects);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
void Mouse(pangolin::View& view, pangolin::MouseButton button,
|
116 |
+
int x, int y, bool pressed, int button_state)
|
117 |
+
{
|
118 |
+
GetPosNormal(view, x, y, p, Pw, Pc, n);
|
119 |
+
bool handled = false;
|
120 |
+
|
121 |
+
if (pressed) {
|
122 |
+
m_selected_objects.clear();
|
123 |
+
ComputeHits(view, *cam_state, x, y, 2*hwin+1, m_selected_objects);
|
124 |
+
}
|
125 |
+
|
126 |
+
for ( auto selected_object_it = m_selected_objects.begin();
|
127 |
+
!handled && selected_object_it != m_selected_objects.end();
|
128 |
+
selected_object_it++ )
|
129 |
+
{
|
130 |
+
Interactive* ir = dynamic_cast<Interactive*>(selected_object_it->second.interactive);
|
131 |
+
handled |= ir && ir->Mouse( button, p, Pw, n, pressed, button_state, selected_object_it->second.pickId);
|
132 |
+
}
|
133 |
+
|
134 |
+
if (!handled) {
|
135 |
+
Handler3D::Mouse(view, button, x, y, pressed, button_state);
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
void MouseMotion(pangolin::View& view, int x, int y, int button_state)
|
140 |
+
{
|
141 |
+
GetPosNormal(view, x, y, p, Pw, Pc, n);
|
142 |
+
bool handled = false;
|
143 |
+
|
144 |
+
for ( auto selected_object_it = m_selected_objects.begin();
|
145 |
+
!handled && selected_object_it != m_selected_objects.end();
|
146 |
+
selected_object_it++ )
|
147 |
+
{
|
148 |
+
Interactive* ir = dynamic_cast<Interactive*>(selected_object_it->second.interactive);
|
149 |
+
handled |= ir && ir->MouseMotion( p, Pw, n, button_state, selected_object_it->second.pickId);
|
150 |
+
}
|
151 |
+
if (!handled) {
|
152 |
+
pangolin::Handler3D::MouseMotion(view, x, y, button_state);
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
void Special(pangolin::View& view, pangolin::InputSpecial inType,
|
157 |
+
float x, float y, float p1, float p2, float p3, float p4,
|
158 |
+
int button_state)
|
159 |
+
{
|
160 |
+
GetPosNormal(view, (int)x, (int)y, p, Pw, Pc, n);
|
161 |
+
|
162 |
+
bool handled = false;
|
163 |
+
|
164 |
+
if (inType == pangolin::InputSpecialScroll)
|
165 |
+
{
|
166 |
+
m_selected_objects.clear();
|
167 |
+
ComputeHits(view, *cam_state, (int)x, (int)y, 2*hwin+1, m_selected_objects);
|
168 |
+
|
169 |
+
const MouseButton button = p2 > 0 ? MouseWheelUp : MouseWheelDown;
|
170 |
+
|
171 |
+
for ( auto selected_object_it = m_selected_objects.begin();
|
172 |
+
!handled && selected_object_it != m_selected_objects.end();
|
173 |
+
selected_object_it++ )
|
174 |
+
{
|
175 |
+
Interactive* ir = dynamic_cast<Interactive*>(selected_object_it->second.interactive);
|
176 |
+
handled |= ir && ir->Mouse( button, p, Pw, n, true, button_state, selected_object_it->second.pickId);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
|
180 |
+
if (!handled) {
|
181 |
+
pangolin::Handler3D::Special(view, inType, x, y,
|
182 |
+
p1, p2, p3, p4, button_state);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
// map from z distance to interactive element with pick id
|
187 |
+
std::map<GLuint, SelectedObject> m_selected_objects;
|
188 |
+
Renderable& scene;
|
189 |
+
unsigned int grab_width;
|
190 |
+
};
|
191 |
+
|
192 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/include/pangolin/scene/tree.h
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <map>
|
4 |
+
#include <pangolin/gl/opengl_render_state.h>
|
5 |
+
|
6 |
+
namespace pangolin {
|
7 |
+
|
8 |
+
template<typename T, typename TEdge>
|
9 |
+
struct TreeNode
|
10 |
+
{
|
11 |
+
struct Edge
|
12 |
+
{
|
13 |
+
TEdge parent_child;
|
14 |
+
TreeNode node;
|
15 |
+
};
|
16 |
+
|
17 |
+
T item;
|
18 |
+
std::vector<Edge> edges;
|
19 |
+
};
|
20 |
+
|
21 |
+
template<typename T, typename TEdge>
|
22 |
+
using NodeFunction = std::function<void(TreeNode<T,TEdge>&,const TEdge&)>;
|
23 |
+
|
24 |
+
//template<typename T, typename TEdge>
|
25 |
+
//void VisitDepthFirst(TreeNode<T,TEdge>& node, const NodeFunction<T,TEdge>& func, const TEdge& T_root_node = TEdge())
|
26 |
+
//{
|
27 |
+
// func(node, T_root_node);
|
28 |
+
// for(auto& e : node.edges) {
|
29 |
+
// const TEdge T_root_child = T_root_node * e.parent_child;
|
30 |
+
// VisitDepthFirst(e.node, func, T_root_child);
|
31 |
+
// }
|
32 |
+
//}
|
33 |
+
|
34 |
+
//void Eg()
|
35 |
+
//{
|
36 |
+
// using RenderNode = TreeNode<std::shared_ptr<Renderable>,OpenGlMatrix>;
|
37 |
+
|
38 |
+
// RenderNode root;
|
39 |
+
// VisitDepthFirst<std::shared_ptr<Renderable>,OpenGlMatrix>(
|
40 |
+
// root, [](RenderNode& node, const OpenGlMatrix& T_root_node) {
|
41 |
+
// if(node.item) {
|
42 |
+
// node.item->DoRender();
|
43 |
+
// }
|
44 |
+
// }, IdentityMatrix());
|
45 |
+
|
46 |
+
//}
|
47 |
+
|
48 |
+
|
49 |
+
}
|
third-party/DPVO/Pangolin/components/pango_scene/src/renderable.cpp
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <pangolin/scene/renderable.h>
|
2 |
+
|
3 |
+
namespace pangolin {
|
4 |
+
|
5 |
+
|
6 |
+
Renderable::guid_t Renderable::UniqueGuid()
|
7 |
+
{
|
8 |
+
static std::random_device rd;
|
9 |
+
static std::mt19937 gen(rd());
|
10 |
+
return (guid_t)gen();
|
11 |
+
}
|
12 |
+
|
13 |
+
Renderable::Renderable(const std::weak_ptr<Renderable>& parent)
|
14 |
+
: guid(UniqueGuid()), parent(parent), T_pc(IdentityMatrix()), should_show(true)
|
15 |
+
{
|
16 |
+
}
|
17 |
+
|
18 |
+
Renderable::~Renderable()
|
19 |
+
{
|
20 |
+
}
|
21 |
+
|
22 |
+
// Default implementation simply renders children.
|
23 |
+
void Renderable::Render(const RenderParams& params) {
|
24 |
+
RenderChildren(params);
|
25 |
+
}
|
26 |
+
|
27 |
+
void Renderable::RenderChildren(const RenderParams& params)
|
28 |
+
{
|
29 |
+
for(auto& p : children) {
|
30 |
+
Renderable& r = *p.second;
|
31 |
+
if(r.should_show) {
|
32 |
+
glPushMatrix();
|
33 |
+
r.T_pc.Multiply();
|
34 |
+
r.Render(params);
|
35 |
+
if(r.manipulator) {
|
36 |
+
r.manipulator->Render(params);
|
37 |
+
}
|
38 |
+
glPopMatrix();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
std::shared_ptr<Renderable> Renderable::FindChild(guid_t guid)
|
44 |
+
{
|
45 |
+
auto o = children.find(guid);
|
46 |
+
if(o != children.end()) {
|
47 |
+
return o->second;
|
48 |
+
}
|
49 |
+
|
50 |
+
for(auto& kv : children ) {
|
51 |
+
std::shared_ptr<Renderable> c = kv.second->FindChild(guid);
|
52 |
+
if(c) return c;
|
53 |
+
}
|
54 |
+
|
55 |
+
return std::shared_ptr<Renderable>();
|
56 |
+
}
|
57 |
+
|
58 |
+
Renderable& Renderable::Add(const std::shared_ptr<Renderable>& child)
|
59 |
+
{
|
60 |
+
if(child) {
|
61 |
+
children[child->guid] = child;
|
62 |
+
};
|
63 |
+
return *this;
|
64 |
+
}
|
65 |
+
|
66 |
+
}
|
third-party/DPVO/Pangolin/components/pango_tools/CMakeLists.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME)
|
2 |
+
|
3 |
+
target_sources( ${COMPONENT}
|
4 |
+
PRIVATE
|
5 |
+
${CMAKE_CURRENT_LIST_DIR}/src/video_viewer.cpp
|
6 |
+
)
|
7 |
+
|
8 |
+
target_link_libraries(${COMPONENT} PUBLIC pango_display pango_video)
|
9 |
+
target_include_directories(${COMPONENT} PUBLIC
|
10 |
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
11 |
+
$<INSTALL_INTERFACE:include>
|
12 |
+
)
|
13 |
+
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include"
|
14 |
+
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
15 |
+
)
|
third-party/DPVO/Pangolin/components/pango_tools/include/pangolin/tools/video_viewer.h
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/platform.h>
|
4 |
+
#include <pangolin/windowing/window.h>
|
5 |
+
#include <pangolin/video/video_input.h>
|
6 |
+
|
7 |
+
#include <functional>
|
8 |
+
#include <mutex>
|
9 |
+
#include <string>
|
10 |
+
#include <thread>
|
11 |
+
|
12 |
+
namespace pangolin
|
13 |
+
{
|
14 |
+
|
15 |
+
PANGOLIN_EXPORT
|
16 |
+
class VideoViewer
|
17 |
+
{
|
18 |
+
public:
|
19 |
+
typedef std::function<void(const unsigned char* data,
|
20 |
+
const std::vector<Image<unsigned char> >& images,
|
21 |
+
const picojson::value& properties)> FrameChangedCallbackFn;
|
22 |
+
|
23 |
+
static constexpr int FRAME_SKIP = 30;
|
24 |
+
|
25 |
+
VideoViewer(const std::string& window_name, const std::string& input_uri, const std::string& output_uri = "video.pango" );
|
26 |
+
VideoViewer(const VideoViewer&) = delete;
|
27 |
+
|
28 |
+
virtual ~VideoViewer();
|
29 |
+
|
30 |
+
void Run();
|
31 |
+
void RunAsync();
|
32 |
+
|
33 |
+
void Quit();
|
34 |
+
void QuitAndWait();
|
35 |
+
|
36 |
+
inline int TotalFrames() const
|
37 |
+
{
|
38 |
+
return video_playback ? video_playback->GetTotalFrames() : std::numeric_limits<int>::max();
|
39 |
+
}
|
40 |
+
|
41 |
+
// Control playback
|
42 |
+
void OpenInput(const std::string& input_uri);
|
43 |
+
void CloseInput();
|
44 |
+
|
45 |
+
// Control recording
|
46 |
+
void Record();
|
47 |
+
void RecordOneFrame();
|
48 |
+
void StopRecording();
|
49 |
+
|
50 |
+
// Useful for user-control
|
51 |
+
void TogglePlay();
|
52 |
+
void ToggleRecord();
|
53 |
+
void ToggleDiscardBufferedFrames();
|
54 |
+
void ToggleWaitForFrames();
|
55 |
+
void SetDiscardBufferedFrames(bool new_state);
|
56 |
+
void SetWaitForFrames(bool new_state);
|
57 |
+
void Skip(int frames);
|
58 |
+
bool ChangeExposure(int delta_us);
|
59 |
+
bool ChangeGain(float delta);
|
60 |
+
void SetActiveCamera(int delta);
|
61 |
+
void DrawEveryNFrames(int n);
|
62 |
+
|
63 |
+
|
64 |
+
// Register to be notified of new image data
|
65 |
+
void SetFrameChangedCallback(FrameChangedCallbackFn cb);
|
66 |
+
|
67 |
+
void WaitUntilExit();
|
68 |
+
|
69 |
+
|
70 |
+
VideoInput& Video() {return video;}
|
71 |
+
const VideoInput& Video() const {return video;}
|
72 |
+
|
73 |
+
void SetRecordNthFrame(int record_nth_frame_) {
|
74 |
+
record_nth_frame = record_nth_frame_;
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
protected:
|
79 |
+
void RegisterDefaultKeyShortcutsAndPangoVariables();
|
80 |
+
|
81 |
+
std::mutex control_mutex;
|
82 |
+
std::string window_name;
|
83 |
+
std::thread vv_thread;
|
84 |
+
|
85 |
+
VideoInput video;
|
86 |
+
VideoPlaybackInterface* video_playback;
|
87 |
+
VideoInterface* video_interface;
|
88 |
+
|
89 |
+
std::string output_uri;
|
90 |
+
|
91 |
+
int current_frame;
|
92 |
+
int grab_until;
|
93 |
+
int record_nth_frame;
|
94 |
+
int draw_nth_frame;
|
95 |
+
bool video_grab_wait;
|
96 |
+
bool video_grab_newest;
|
97 |
+
bool should_run;
|
98 |
+
uint16_t active_cam;
|
99 |
+
|
100 |
+
FrameChangedCallbackFn frame_changed_callback;
|
101 |
+
};
|
102 |
+
|
103 |
+
|
104 |
+
void PANGOLIN_EXPORT RunVideoViewerUI(const std::string& input_uri, const std::string& output_uri);
|
105 |
+
|
106 |
+
}
|
third-party/DPVO/Pangolin/components/pango_tools/src/video_viewer.cpp
ADDED
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <pangolin/tools/video_viewer.h>
|
2 |
+
|
3 |
+
#include <pangolin/gl/gldraw.h>
|
4 |
+
#include <pangolin/gl/glpixformat.h>
|
5 |
+
#include <pangolin/gl/gltexturecache.h>
|
6 |
+
#include <pangolin/display/image_view.h>
|
7 |
+
#include <pangolin/display/widgets.h>
|
8 |
+
#include <pangolin/utils/file_utils.h>
|
9 |
+
#include <pangolin/utils/sigstate.h>
|
10 |
+
#include <pangolin/video/video_input.h>
|
11 |
+
#include <pangolin/handler/handler_image.h>
|
12 |
+
#include <pangolin/var/var.h>
|
13 |
+
|
14 |
+
|
15 |
+
namespace pangolin
|
16 |
+
{
|
17 |
+
|
18 |
+
void videoviewer_signal_quit(int) {
|
19 |
+
pango_print_info("Caught signal. Program will exit after any IO is complete.\n");
|
20 |
+
pangolin::QuitAll();
|
21 |
+
}
|
22 |
+
|
23 |
+
VideoViewer::VideoViewer(const std::string& window_name, const std::string& input_uri, const std::string& output_uri)
|
24 |
+
: window_name(window_name),
|
25 |
+
video_playback(nullptr),
|
26 |
+
video_interface(nullptr),
|
27 |
+
output_uri(output_uri),
|
28 |
+
current_frame(-1),
|
29 |
+
grab_until(std::numeric_limits<int>::max()),
|
30 |
+
record_nth_frame(1),
|
31 |
+
draw_nth_frame(1),
|
32 |
+
video_grab_wait(true),
|
33 |
+
video_grab_newest(false),
|
34 |
+
should_run(true),
|
35 |
+
active_cam(0)
|
36 |
+
{
|
37 |
+
pangolin::Var<int>::Attach("ui.frame", current_frame);
|
38 |
+
pangolin::Var<int>::Attach("ui.record_nth_frame", record_nth_frame);
|
39 |
+
pangolin::Var<int>::Attach("ui.draw_nth_frame", draw_nth_frame);
|
40 |
+
|
41 |
+
|
42 |
+
if(!input_uri.empty()) {
|
43 |
+
OpenInput(input_uri);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
VideoViewer::~VideoViewer()
|
48 |
+
{
|
49 |
+
QuitAndWait();
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
void VideoViewer::Quit()
|
54 |
+
{
|
55 |
+
// Signal any running thread to stop
|
56 |
+
should_run = false;
|
57 |
+
}
|
58 |
+
|
59 |
+
void VideoViewer::QuitAndWait()
|
60 |
+
{
|
61 |
+
Quit();
|
62 |
+
|
63 |
+
if(vv_thread.joinable()) {
|
64 |
+
vv_thread.join();
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
void VideoViewer::RunAsync()
|
69 |
+
{
|
70 |
+
if(!should_run) {
|
71 |
+
// Make sure any other thread has finished
|
72 |
+
if(vv_thread.joinable()) {
|
73 |
+
vv_thread.join();
|
74 |
+
}
|
75 |
+
|
76 |
+
// Launch in another thread
|
77 |
+
vv_thread = std::thread(&VideoViewer::Run, this);
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
void VideoViewer::Run()
|
82 |
+
{
|
83 |
+
should_run = true;
|
84 |
+
|
85 |
+
/////////////////////////////////////////////////////////////////////////
|
86 |
+
/// Register pangolin variables
|
87 |
+
/////////////////////////////////////////////////////////////////////////
|
88 |
+
|
89 |
+
std::unique_ptr<unsigned char[]> buffer(new unsigned char[video.SizeBytes()+1]);
|
90 |
+
|
91 |
+
const int slider_size = (TotalFrames() < std::numeric_limits<int>::max() ? 20 : 0);
|
92 |
+
|
93 |
+
// Create OpenGL window - guess sensible dimensions
|
94 |
+
pangolin::CreateWindowAndBind( window_name,
|
95 |
+
(int)(video.Width() * video.Streams().size()),
|
96 |
+
(int)(video.Height() + slider_size)
|
97 |
+
);
|
98 |
+
glEnable (GL_BLEND);
|
99 |
+
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
100 |
+
|
101 |
+
pangolin::Var<int> frame("ui.frame");
|
102 |
+
pangolin::Slider frame_slider("frame", frame.Ref() );
|
103 |
+
|
104 |
+
if(video_playback && TotalFrames() < std::numeric_limits<int>::max())
|
105 |
+
{
|
106 |
+
// frame_slider should be added first so that it can be rendered correctly.
|
107 |
+
pangolin::DisplayBase().AddDisplay(frame_slider);
|
108 |
+
frame_slider.SetBounds(0.0, pangolin::Attach::Pix(slider_size), 0.0, 1.0);
|
109 |
+
}
|
110 |
+
|
111 |
+
pangolin::View& container = pangolin::Display("streams");
|
112 |
+
container.SetLayout(pangolin::LayoutEqual)
|
113 |
+
.SetBounds(pangolin::Attach::Pix(slider_size), 1.0, 0.0, 1.0);
|
114 |
+
|
115 |
+
std::vector<ImageView> stream_views(video.Streams().size());
|
116 |
+
for(auto& sv : stream_views) {
|
117 |
+
container.AddDisplay(sv);
|
118 |
+
}
|
119 |
+
|
120 |
+
pangolin::View& record_graphic = pangolin::Display("record_glyph").
|
121 |
+
SetBounds(pangolin::Attach::Pix(-28),1.0f, pangolin::Attach::Pix(-28), 1.0f);
|
122 |
+
record_graphic.extern_draw_function = [&](pangolin::View& v){
|
123 |
+
if(video.IsRecording()) {
|
124 |
+
v.ActivatePixelOrthographic();
|
125 |
+
pangolin::glRecordGraphic(14.0f, 14.0f, 7.0f);
|
126 |
+
}
|
127 |
+
};
|
128 |
+
|
129 |
+
std::vector<pangolin::Image<unsigned char> > images;
|
130 |
+
|
131 |
+
/////////////////////////////////////////////////////////////////////////
|
132 |
+
/// Register key shortcuts
|
133 |
+
/////////////////////////////////////////////////////////////////////////
|
134 |
+
|
135 |
+
RegisterDefaultKeyShortcutsAndPangoVariables();
|
136 |
+
|
137 |
+
const char show_hide_keys[] = {'1','2','3','4','5','6','7','8','9'};
|
138 |
+
const char screenshot_keys[] = {'!','@','#','$','%','^','&','*','('};
|
139 |
+
|
140 |
+
// Show/hide streams
|
141 |
+
for(size_t v=0; v < container.NumChildren() && v < 9; v++) {
|
142 |
+
pangolin::RegisterKeyPressCallback(show_hide_keys[v], [v,&container](){
|
143 |
+
container[v].ToggleShow();
|
144 |
+
} );
|
145 |
+
pangolin::RegisterKeyPressCallback(screenshot_keys[v], [this,v,&images](){
|
146 |
+
if(v < images.size() && images[v].ptr) {
|
147 |
+
try{
|
148 |
+
pangolin::SaveImage(
|
149 |
+
images[v], video.Streams()[v].PixFormat(),
|
150 |
+
pangolin::MakeUniqueFilename("capture.png")
|
151 |
+
);
|
152 |
+
}catch(const std::exception& e){
|
153 |
+
pango_print_error("Unable to save frame: %s\n", e.what());
|
154 |
+
}
|
155 |
+
}
|
156 |
+
} );
|
157 |
+
}
|
158 |
+
|
159 |
+
video.Start();
|
160 |
+
|
161 |
+
// Stream and display video
|
162 |
+
while(should_run && !pangolin::ShouldQuit())
|
163 |
+
{
|
164 |
+
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
165 |
+
glColor3f(1.0f, 1.0f, 1.0f);
|
166 |
+
|
167 |
+
{
|
168 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
169 |
+
|
170 |
+
if(frame.GuiChanged()) {
|
171 |
+
if(video_playback) {
|
172 |
+
frame = video_playback->Seek(frame) -1;
|
173 |
+
}
|
174 |
+
grab_until = frame + 1;
|
175 |
+
}
|
176 |
+
|
177 |
+
if ( frame < grab_until && video.Grab(&buffer[0], images, video_grab_wait, video_grab_newest)) {
|
178 |
+
frame = frame +1;
|
179 |
+
|
180 |
+
if(frame_changed_callback) {
|
181 |
+
frame_changed_callback(buffer.get(), images, GetVideoFrameProperties(video_interface));
|
182 |
+
}
|
183 |
+
|
184 |
+
// Update images
|
185 |
+
if((frame-1) % draw_nth_frame == 0) {
|
186 |
+
for(unsigned int i=0; i<images.size(); ++i)
|
187 |
+
if(stream_views[i].IsShown()) {
|
188 |
+
stream_views[i].SetImage(images[i], pangolin::GlPixFormat(video.Streams()[i].PixFormat() ));
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
// leave in pixel orthographic for slider to render.
|
195 |
+
pangolin::DisplayBase().ActivatePixelOrthographic();
|
196 |
+
pangolin::FinishFrame();
|
197 |
+
}
|
198 |
+
|
199 |
+
pangolin::DestroyWindow(window_name);
|
200 |
+
}
|
201 |
+
|
202 |
+
void VideoViewer::RegisterDefaultKeyShortcutsAndPangoVariables()
|
203 |
+
{
|
204 |
+
pangolin::RegisterKeyPressCallback(' ', [this](){TogglePlay();} );
|
205 |
+
pangolin::RegisterKeyPressCallback('r', [this](){ToggleRecord();});
|
206 |
+
pangolin::RegisterKeyPressCallback('w', [this](){ToggleWaitForFrames();} );
|
207 |
+
pangolin::RegisterKeyPressCallback('d', [this](){ToggleDiscardBufferedFrames();} );
|
208 |
+
pangolin::RegisterKeyPressCallback(',', [this](){Skip(-1);} );
|
209 |
+
pangolin::RegisterKeyPressCallback('.', [this](){Skip(+1);} );
|
210 |
+
pangolin::RegisterKeyPressCallback('<', [this](){Skip(-FRAME_SKIP);} );
|
211 |
+
pangolin::RegisterKeyPressCallback('>', [this](){Skip(+FRAME_SKIP);} );
|
212 |
+
pangolin::RegisterKeyPressCallback('0', [this](){RecordOneFrame();} );
|
213 |
+
pangolin::RegisterKeyPressCallback('E', [this](){ChangeExposure(1000);} );
|
214 |
+
pangolin::RegisterKeyPressCallback('e', [this](){ChangeExposure(-1000);} );
|
215 |
+
pangolin::RegisterKeyPressCallback('G', [this](){ChangeGain(1);} );
|
216 |
+
pangolin::RegisterKeyPressCallback('g', [this](){ChangeGain(-1);} );
|
217 |
+
pangolin::RegisterKeyPressCallback('c', [this](){SetActiveCamera(+1);} );
|
218 |
+
}
|
219 |
+
|
220 |
+
void VideoViewer::OpenInput(const std::string& input_uri)
|
221 |
+
{
|
222 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
223 |
+
video.Open(input_uri, output_uri);
|
224 |
+
|
225 |
+
// Output details of video stream
|
226 |
+
for(size_t s = 0; s < video.Streams().size(); ++s) {
|
227 |
+
const pangolin::StreamInfo& si = video.Streams()[s];
|
228 |
+
std::cout << FormatString(
|
229 |
+
"Stream %: % x % % (pitch: % bytes)",
|
230 |
+
s, si.Width(), si.Height(), si.PixFormat().format, si.Pitch()
|
231 |
+
) << std::endl;
|
232 |
+
}
|
233 |
+
|
234 |
+
if(video.Streams().size() == 0) {
|
235 |
+
pango_print_error("No video streams from device.\n");
|
236 |
+
return;
|
237 |
+
}
|
238 |
+
|
239 |
+
video_playback = pangolin::FindFirstMatchingVideoInterface<pangolin::VideoPlaybackInterface>(video);
|
240 |
+
video_interface = pangolin::FindFirstMatchingVideoInterface<pangolin::VideoInterface>(video);
|
241 |
+
|
242 |
+
if(TotalFrames() < std::numeric_limits<int>::max() ) {
|
243 |
+
std::cout << "Video length: " << TotalFrames() << " frames" << std::endl;
|
244 |
+
grab_until = 0;
|
245 |
+
}
|
246 |
+
|
247 |
+
pangolin::Var<int> frame("ui.frame");
|
248 |
+
frame.Meta().range[0] = 0;
|
249 |
+
frame.Meta().range[1] = TotalFrames()-1;
|
250 |
+
}
|
251 |
+
|
252 |
+
void VideoViewer::CloseInput()
|
253 |
+
{
|
254 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
255 |
+
video.Close();
|
256 |
+
}
|
257 |
+
|
258 |
+
void VideoViewer::Record()
|
259 |
+
{
|
260 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
261 |
+
if(!video.IsRecording()) {
|
262 |
+
video.Record();
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
void VideoViewer::RecordOneFrame()
|
267 |
+
{
|
268 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
269 |
+
video.RecordOneFrame();
|
270 |
+
}
|
271 |
+
|
272 |
+
void VideoViewer::StopRecording()
|
273 |
+
{
|
274 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
275 |
+
if(video.IsRecording()) {
|
276 |
+
video.Stop();
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
void VideoViewer::TogglePlay()
|
281 |
+
{
|
282 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
283 |
+
grab_until = (current_frame < grab_until) ? current_frame: std::numeric_limits<int>::max();
|
284 |
+
}
|
285 |
+
|
286 |
+
void VideoViewer::ToggleRecord()
|
287 |
+
{
|
288 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
289 |
+
if(!video.IsRecording()) {
|
290 |
+
video.SetTimelapse( static_cast<size_t>(record_nth_frame) );
|
291 |
+
video.Record();
|
292 |
+
pango_print_info("Started Recording.\n");
|
293 |
+
}else{
|
294 |
+
video.Stop();
|
295 |
+
pango_print_info("Finished recording.\n");
|
296 |
+
}
|
297 |
+
fflush(stdout);
|
298 |
+
}
|
299 |
+
|
300 |
+
void VideoViewer::ToggleDiscardBufferedFrames()
|
301 |
+
{
|
302 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
303 |
+
video_grab_newest = !video_grab_newest;
|
304 |
+
if(video_grab_newest) {
|
305 |
+
pango_print_info("Discarding old frames.\n");
|
306 |
+
}else{
|
307 |
+
pango_print_info("Not discarding old frames.\n");
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
void VideoViewer::ToggleWaitForFrames()
|
312 |
+
{
|
313 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
314 |
+
video_grab_wait = !video_grab_wait;
|
315 |
+
if(video_grab_wait) {
|
316 |
+
pango_print_info("Gui wait's for video frame.\n");
|
317 |
+
}else{
|
318 |
+
pango_print_info("Gui doesn't wait for video frame.\n");
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
void VideoViewer::SetDiscardBufferedFrames(bool new_state)
|
323 |
+
{
|
324 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
325 |
+
video_grab_newest = new_state;
|
326 |
+
if(video_grab_newest) {
|
327 |
+
pango_print_info("Discarding old frames.\n");
|
328 |
+
}else{
|
329 |
+
pango_print_info("Not discarding old frames.\n");
|
330 |
+
}
|
331 |
+
}
|
332 |
+
|
333 |
+
|
334 |
+
void VideoViewer::DrawEveryNFrames(int n)
|
335 |
+
{
|
336 |
+
if(n <= 0) {
|
337 |
+
pango_print_warn("Cannot draw every %d frames. Ignoring request.\n",n);
|
338 |
+
return;
|
339 |
+
}
|
340 |
+
|
341 |
+
if(n != draw_nth_frame && n == 1)
|
342 |
+
pango_print_info("Drawing every frame.\n");
|
343 |
+
if(n != draw_nth_frame && n > 1)
|
344 |
+
pango_print_info("Drawing one in every %d frames.\n",n);
|
345 |
+
|
346 |
+
draw_nth_frame=n;
|
347 |
+
}
|
348 |
+
|
349 |
+
|
350 |
+
|
351 |
+
void VideoViewer::SetWaitForFrames(bool new_state)
|
352 |
+
{
|
353 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
354 |
+
video_grab_wait = new_state;
|
355 |
+
if(video_grab_wait) {
|
356 |
+
pango_print_info("Gui wait's for video frame.\n");
|
357 |
+
}else{
|
358 |
+
pango_print_info("Gui doesn't wait for video frame.\n");
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
+
void VideoViewer::Skip(int frames)
|
363 |
+
{
|
364 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
365 |
+
|
366 |
+
if(video_playback) {
|
367 |
+
const int next_frame = current_frame + frames;
|
368 |
+
if (next_frame >= 0) {
|
369 |
+
current_frame = video_playback->Seek(next_frame) -1;
|
370 |
+
grab_until = current_frame + 1;
|
371 |
+
}
|
372 |
+
}else{
|
373 |
+
if(frames >= 0) {
|
374 |
+
grab_until = current_frame + frames;
|
375 |
+
}else{
|
376 |
+
pango_print_warn("Unable to skip backward.");
|
377 |
+
}
|
378 |
+
}
|
379 |
+
|
380 |
+
}
|
381 |
+
|
382 |
+
bool VideoViewer::ChangeExposure(int delta_us)
|
383 |
+
{
|
384 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
385 |
+
|
386 |
+
std::vector<pangolin::GenicamVideoInterface*> ifs = FindMatchingVideoInterfaces<pangolin::GenicamVideoInterface>(video);
|
387 |
+
std::string exposure_time;
|
388 |
+
if (ifs[active_cam]->GetParameter("ExposureTime",exposure_time))
|
389 |
+
{
|
390 |
+
return false;
|
391 |
+
}
|
392 |
+
|
393 |
+
int exp = atoi(exposure_time.c_str());
|
394 |
+
|
395 |
+
return ifs[active_cam]->SetParameter("ExposureTime", std::to_string(exp+delta_us));
|
396 |
+
}
|
397 |
+
|
398 |
+
bool VideoViewer::ChangeGain(float delta)
|
399 |
+
{
|
400 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
401 |
+
|
402 |
+
std::vector<pangolin::GenicamVideoInterface*> ifs = FindMatchingVideoInterfaces<pangolin::GenicamVideoInterface>(video);
|
403 |
+
|
404 |
+
std::string gain_string;
|
405 |
+
if (!ifs[active_cam]->GetParameter("Gain", gain_string))
|
406 |
+
{
|
407 |
+
return false;
|
408 |
+
}
|
409 |
+
double gain = atoi(gain_string.c_str());
|
410 |
+
|
411 |
+
return ifs[active_cam]->SetParameter("Gain", std::to_string(gain+delta));
|
412 |
+
}
|
413 |
+
|
414 |
+
|
415 |
+
void VideoViewer::SetActiveCamera(int delta)
|
416 |
+
{
|
417 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
418 |
+
|
419 |
+
std::vector<pangolin::GenicamVideoInterface*> ifs = FindMatchingVideoInterfaces<pangolin::GenicamVideoInterface>(video);
|
420 |
+
|
421 |
+
active_cam += delta;
|
422 |
+
|
423 |
+
if(active_cam >= ifs.size()) {active_cam = 0;}
|
424 |
+
}
|
425 |
+
|
426 |
+
|
427 |
+
void VideoViewer::SetFrameChangedCallback(FrameChangedCallbackFn cb)
|
428 |
+
{
|
429 |
+
std::lock_guard<std::mutex> lock(control_mutex);
|
430 |
+
frame_changed_callback=cb;
|
431 |
+
}
|
432 |
+
|
433 |
+
|
434 |
+
|
435 |
+
void VideoViewer::WaitUntilExit()
|
436 |
+
{
|
437 |
+
if(vv_thread.joinable()) {
|
438 |
+
vv_thread.join();
|
439 |
+
}
|
440 |
+
}
|
441 |
+
|
442 |
+
|
443 |
+
void RunVideoViewerUI(const std::string& input_uri, const std::string& output_uri)
|
444 |
+
{
|
445 |
+
RegisterNewSigCallback(videoviewer_signal_quit, nullptr, SIGINT);
|
446 |
+
RegisterNewSigCallback(videoviewer_signal_quit, nullptr, SIGTERM);
|
447 |
+
|
448 |
+
VideoViewer vv("VideoViewer", input_uri, output_uri);
|
449 |
+
vv.Run();
|
450 |
+
}
|
451 |
+
|
452 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/CMakeLists.txt
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME)
|
2 |
+
|
3 |
+
target_sources( ${COMPONENT}
|
4 |
+
PRIVATE
|
5 |
+
${CMAKE_CURRENT_LIST_DIR}/src/vars.cpp
|
6 |
+
${CMAKE_CURRENT_LIST_DIR}/src/varstate.cpp
|
7 |
+
)
|
8 |
+
|
9 |
+
target_link_libraries(${COMPONENT} PUBLIC pango_core)
|
10 |
+
target_include_directories(${COMPONENT} PUBLIC
|
11 |
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
12 |
+
$<INSTALL_INTERFACE:include>
|
13 |
+
)
|
14 |
+
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include"
|
15 |
+
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
16 |
+
)
|
17 |
+
|
18 |
+
if(BUILD_TESTS)
|
19 |
+
add_executable(test_vars ${CMAKE_CURRENT_LIST_DIR}/tests/test_all.cpp)
|
20 |
+
target_link_libraries(test_vars PRIVATE Catch2::Catch2 ${COMPONENT})
|
21 |
+
catch_discover_tests(test_vars)
|
22 |
+
endif()
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/var.h
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <stdexcept>
|
31 |
+
#include <string.h>
|
32 |
+
#include <cmath>
|
33 |
+
|
34 |
+
#include <pangolin/utils/is_streamable.h>
|
35 |
+
#include <pangolin/var/varvalue.h>
|
36 |
+
#include <pangolin/var/varwrapper.h>
|
37 |
+
#include <pangolin/var/varstate.h>
|
38 |
+
|
39 |
+
namespace pangolin
|
40 |
+
{
|
41 |
+
|
42 |
+
template<typename T>
|
43 |
+
class Var
|
44 |
+
{
|
45 |
+
public:
|
46 |
+
static T& Attach( T& variable, const VarMeta& meta ) {
|
47 |
+
VarState::I().AttachVar<T&>(variable,meta);
|
48 |
+
return variable;
|
49 |
+
}
|
50 |
+
|
51 |
+
static T& Attach( const std::string& name, T& variable )
|
52 |
+
{
|
53 |
+
return Attach(variable, VarMeta(name));
|
54 |
+
}
|
55 |
+
|
56 |
+
static T& Attach(
|
57 |
+
const std::string& name, T& variable,
|
58 |
+
double min, double max, bool logscale = false
|
59 |
+
) {
|
60 |
+
return Attach(variable, VarMeta(name, min, max, DefaultIncrementForType<T>(min,max), META_FLAG_NONE, logscale));
|
61 |
+
}
|
62 |
+
|
63 |
+
static T& Attach( const std::string& name, T& variable, int flags )
|
64 |
+
{
|
65 |
+
return Attach(variable, VarMeta(name, 0., 0., 0., flags) );
|
66 |
+
}
|
67 |
+
|
68 |
+
static T& Attach( const std::string& name, T& variable, bool toggle )
|
69 |
+
{
|
70 |
+
return Attach(variable, VarMeta(name, 0., 0., 0., toggle ? META_FLAG_TOGGLE : META_FLAG_NONE) );
|
71 |
+
}
|
72 |
+
|
73 |
+
~Var()
|
74 |
+
{
|
75 |
+
}
|
76 |
+
|
77 |
+
Var( const std::shared_ptr<VarValueGeneric>& v )
|
78 |
+
: var(InitialiseFromPreviouslyTypedVar<T>(v))
|
79 |
+
{
|
80 |
+
}
|
81 |
+
|
82 |
+
Var( const T& value, const VarMeta& meta )
|
83 |
+
: var(InitialiseFromPreviouslyTypedVar<T>(VarState::I().GetOrCreateVar<T>(value, meta)))
|
84 |
+
{
|
85 |
+
}
|
86 |
+
|
87 |
+
Var( const std::string& name, const T& value = T() )
|
88 |
+
: Var(value, VarMeta(name))
|
89 |
+
{
|
90 |
+
}
|
91 |
+
|
92 |
+
Var(const std::string& name, const T& value, int flags)
|
93 |
+
: Var(value, VarMeta(name, 0., 0.,0., flags))
|
94 |
+
{
|
95 |
+
}
|
96 |
+
|
97 |
+
Var(const std::string& name, const T& value, bool toggle)
|
98 |
+
: Var(value, VarMeta(name, 0., 0.,0., toggle ? META_FLAG_TOGGLE : META_FLAG_NONE))
|
99 |
+
{
|
100 |
+
}
|
101 |
+
|
102 |
+
Var(const std::string& name, const T& value,
|
103 |
+
double min, double max, bool logscale = false)
|
104 |
+
: Var(value, VarMeta(name, min, max, DefaultIncrementForType<T>(min,max), META_FLAG_NONE, logscale))
|
105 |
+
{
|
106 |
+
}
|
107 |
+
|
108 |
+
void Reset()
|
109 |
+
{
|
110 |
+
var->Reset();
|
111 |
+
}
|
112 |
+
|
113 |
+
void Detach()
|
114 |
+
{
|
115 |
+
VarState::I().Remove(Meta().full_name);
|
116 |
+
}
|
117 |
+
|
118 |
+
const T& Get() const
|
119 |
+
{
|
120 |
+
return var->Get();
|
121 |
+
}
|
122 |
+
|
123 |
+
operator const T& () const
|
124 |
+
{
|
125 |
+
return Get();
|
126 |
+
}
|
127 |
+
|
128 |
+
const T* operator->()
|
129 |
+
{
|
130 |
+
return &(var->Get());
|
131 |
+
}
|
132 |
+
|
133 |
+
Var<T>& operator=(const T& val)
|
134 |
+
{
|
135 |
+
var->Set(val);
|
136 |
+
return *this;
|
137 |
+
}
|
138 |
+
|
139 |
+
Var<T>& operator=(const Var<T>& v)
|
140 |
+
{
|
141 |
+
var->Set(v.var->Get());
|
142 |
+
return *this;
|
143 |
+
}
|
144 |
+
|
145 |
+
VarMeta& Meta()
|
146 |
+
{
|
147 |
+
return var->Meta();
|
148 |
+
}
|
149 |
+
|
150 |
+
bool GuiChanged()
|
151 |
+
{
|
152 |
+
return Meta().gui_changed && !(Meta().gui_changed = false);
|
153 |
+
}
|
154 |
+
|
155 |
+
std::shared_ptr<VarValueT<T>> Ref()
|
156 |
+
{
|
157 |
+
return var;
|
158 |
+
}
|
159 |
+
|
160 |
+
// Holds reference to stored variable object
|
161 |
+
// N.B. mutable because it is a cached value and Get() is advertised as const.
|
162 |
+
mutable std::shared_ptr<VarValueT<T>> var;
|
163 |
+
};
|
164 |
+
|
165 |
+
template<typename T>
|
166 |
+
inline std::ostream& operator<<(std::ostream& s, Var<T>& rhs)
|
167 |
+
{
|
168 |
+
s << rhs.operator const T &();
|
169 |
+
return s;
|
170 |
+
}
|
171 |
+
|
172 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varextra.h
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/platform.h>
|
31 |
+
#include <pangolin/var/var.h>
|
32 |
+
#include <vector>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
PANGOLIN_EXPORT
|
38 |
+
void ParseVarsFile(const std::string& filename);
|
39 |
+
|
40 |
+
PANGOLIN_EXPORT
|
41 |
+
void LoadJsonFile(const std::string& filename, const std::string& prefix="");
|
42 |
+
|
43 |
+
PANGOLIN_EXPORT
|
44 |
+
void SaveJsonFile(const std::string& filename, const std::string& prefix="");
|
45 |
+
|
46 |
+
template<typename T>
|
47 |
+
struct SetVarFunctor
|
48 |
+
{
|
49 |
+
SetVarFunctor(const std::string& name, T val) : varName(name), setVal(val) {}
|
50 |
+
void operator()() { Var<T>(varName).Ref()->Set(setVal); }
|
51 |
+
std::string varName;
|
52 |
+
T setVal;
|
53 |
+
};
|
54 |
+
|
55 |
+
struct ToggleVarFunctor
|
56 |
+
{
|
57 |
+
ToggleVarFunctor(const std::string& name) : varName(name) {}
|
58 |
+
void operator()() { Var<bool> val(varName,false); val = !val; }
|
59 |
+
std::string varName;
|
60 |
+
};
|
61 |
+
|
62 |
+
inline bool Pushed(bool& button)
|
63 |
+
{
|
64 |
+
return button && !(button = false);
|
65 |
+
}
|
66 |
+
|
67 |
+
inline bool Pushed(Var<bool>& button)
|
68 |
+
{
|
69 |
+
return (bool)button && !(button = false);
|
70 |
+
}
|
71 |
+
|
72 |
+
// Just forward to the static method
|
73 |
+
// The benefit here is that we can get type inference
|
74 |
+
template<typename T, typename... Ts>
|
75 |
+
T& AttachVar(const std::string& name, T& var, Ts... ts)
|
76 |
+
{
|
77 |
+
return Var<T>::Attach(name, var, ts...);
|
78 |
+
}
|
79 |
+
|
80 |
+
inline void DetachVarByName(const std::string& name)
|
81 |
+
{
|
82 |
+
VarState::I().Remove(name);
|
83 |
+
}
|
84 |
+
|
85 |
+
template<typename T>
|
86 |
+
void DetachVar(const T& value)
|
87 |
+
{
|
88 |
+
auto var = VarState::I().GetByReference<T>(value);
|
89 |
+
if(var) DetachVarByName(var->Meta().full_name);
|
90 |
+
}
|
91 |
+
|
92 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varinit.h
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <pangolin/var/varvalue.h>
|
2 |
+
#include <cstring>
|
3 |
+
|
4 |
+
namespace pangolin {
|
5 |
+
|
6 |
+
template<typename T>
|
7 |
+
inline double DefaultIncrementForType(double min, double max) {
|
8 |
+
return (std::is_integral<T>::value) ? 1.0 : (max - min) / 100.0;
|
9 |
+
}
|
10 |
+
|
11 |
+
template <typename T, typename S>
|
12 |
+
typename std::enable_if<is_streamable<S>::value && is_streamable<T>::value, std::shared_ptr<VarValueT<T>>>::type
|
13 |
+
Wrapped(const std::shared_ptr<VarValueT<S>>& src) noexcept
|
14 |
+
{
|
15 |
+
return std::make_shared<VarWrapper<T,S>>(src);
|
16 |
+
}
|
17 |
+
|
18 |
+
template <typename T, typename S>
|
19 |
+
typename std::enable_if<!(is_streamable<S>::value && is_streamable<T>::value), std::shared_ptr<VarValueT<T>>>::type
|
20 |
+
Wrapped(const std::shared_ptr<VarValueT<S>>&)
|
21 |
+
{
|
22 |
+
throw std::runtime_error("Unable to wrap Var");
|
23 |
+
}
|
24 |
+
|
25 |
+
template<typename T>
|
26 |
+
typename std::enable_if<!is_streamable<T>::value, std::shared_ptr<VarValue<T>>>::type
|
27 |
+
InitialiseFromPreviouslyGenericVar(const std::shared_ptr<VarValueGeneric>& v)
|
28 |
+
{
|
29 |
+
// We can't initialize this variable from a 'generic' string type.
|
30 |
+
throw BadInputException();
|
31 |
+
}
|
32 |
+
template<typename T>
|
33 |
+
typename std::enable_if<is_streamable<T>::value, std::shared_ptr<VarValue<T>>>::type
|
34 |
+
InitialiseFromPreviouslyGenericVar(const std::shared_ptr<VarValueGeneric>& v)
|
35 |
+
{
|
36 |
+
return std::make_shared<VarValue<T>>( Convert<T,std::string>::Do( v->str->Get() ) );
|
37 |
+
}
|
38 |
+
|
39 |
+
// Initialise from existing variable, obtain data / accessor
|
40 |
+
template<typename T>
|
41 |
+
std::shared_ptr<VarValueT<T>> InitialiseFromPreviouslyTypedVar(const std::shared_ptr<VarValueGeneric>& v)
|
42 |
+
{
|
43 |
+
// Macro hack to prevent code duplication
|
44 |
+
# define PANGO_VAR_TYPES(x) \
|
45 |
+
x(bool) x(int8_t) x(uint8_t) x(int16_t) x(uint16_t) \
|
46 |
+
x(int32_t) x(uint32_t) x(int64_t) x(uint64_t) \
|
47 |
+
x(float) x(double)
|
48 |
+
|
49 |
+
if( !strcmp(v->TypeId(), typeid(T).name()) ) {
|
50 |
+
// Same type
|
51 |
+
return std::dynamic_pointer_cast<VarValueT<T>>(v);
|
52 |
+
}else if( std::is_same<T,std::string>::value ) {
|
53 |
+
// Use types string accessor
|
54 |
+
return std::dynamic_pointer_cast<VarValueT<T>>(v->str);
|
55 |
+
}else
|
56 |
+
# define PANGO_CHECK_WRAP(x) \
|
57 |
+
if( !strcmp(v->TypeId(), typeid(x).name() ) ) { \
|
58 |
+
std::shared_ptr<VarValueT<x>> xval = std::dynamic_pointer_cast<VarValueT<x>>(v); \
|
59 |
+
return Wrapped<T,x>(xval); \
|
60 |
+
}else
|
61 |
+
PANGO_VAR_TYPES(PANGO_CHECK_WRAP)
|
62 |
+
{
|
63 |
+
// other types: have to go via string
|
64 |
+
// Wrapper, owned by this object
|
65 |
+
return Wrapped<T,std::string>(v->str);
|
66 |
+
}
|
67 |
+
#undef PANGO_VAR_TYPES
|
68 |
+
#undef PANGO_CHECK_WRAP
|
69 |
+
}
|
70 |
+
|
71 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varstate.h
ADDED
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <map>
|
31 |
+
#include <vector>
|
32 |
+
#include <memory>
|
33 |
+
#include <any>
|
34 |
+
#include <cassert>
|
35 |
+
#include <pangolin/platform.h>
|
36 |
+
#include <pangolin/var/varvalue.h>
|
37 |
+
#include <pangolin/utils/file_utils.h>
|
38 |
+
#include <pangolin/utils/signal_slot.h>
|
39 |
+
#include <pangolin/var/varinit.h>
|
40 |
+
|
41 |
+
namespace pangolin
|
42 |
+
{
|
43 |
+
|
44 |
+
class PANGOLIN_EXPORT VarState
|
45 |
+
{
|
46 |
+
public:
|
47 |
+
static VarState& I();
|
48 |
+
|
49 |
+
VarState();
|
50 |
+
~VarState();
|
51 |
+
|
52 |
+
/// \returns true iff a pangolin var with key name \param key exists in the index.
|
53 |
+
bool Exists(const std::string& key) const;
|
54 |
+
|
55 |
+
/// Register a user defined variable in memory into the VarState index.
|
56 |
+
/// Note that the user memory must have a lifetime which exceeds all accesses through
|
57 |
+
/// pangolin::Vars. The parameter remains owned by the user who must take care of
|
58 |
+
/// appropriate deallocation.
|
59 |
+
///
|
60 |
+
/// \tparam T The type of \param variable to register
|
61 |
+
/// \param variable The variable to make available in the VarState index.
|
62 |
+
/// \param meta Meta information about the variable that will allow tools to introspect
|
63 |
+
/// and modify it. In particular, \param meta.name is the user accessible name
|
64 |
+
/// and is also used as input to lookup any Var in the index.
|
65 |
+
template<typename T>
|
66 |
+
std::shared_ptr<VarValueGeneric> AttachVar( T& variable, const VarMeta& meta );
|
67 |
+
|
68 |
+
/// Get a reference to an existing Var in the index, or create one if it doesn't exist.
|
69 |
+
/// The variable name to be used is inside of \param meta.name. Lifetime of Created
|
70 |
+
/// variables is managed through shared_ptr reference counting.
|
71 |
+
///
|
72 |
+
/// \tparam T The underlying type of the Var to create
|
73 |
+
/// \param value The initial value for the Var if it doesn't already exist and gets created
|
74 |
+
/// \param meta Meta information about the variable that will allow tools to introspect
|
75 |
+
/// and modify it. In particular, \param meta.name is the user accessible name
|
76 |
+
/// and is also used as input to lookup any Var in the index.
|
77 |
+
template<typename T>
|
78 |
+
std::shared_ptr<VarValueGeneric> GetOrCreateVar( const T& value, const VarMeta& meta );
|
79 |
+
|
80 |
+
/// \return A reference to the corresponding var with name \param full_name, or nullptr
|
81 |
+
/// if no such Var exists
|
82 |
+
std::shared_ptr<VarValueGeneric> GetByName(const std::string& full_name);
|
83 |
+
|
84 |
+
/// \return A reference to the corresponding var with underlying memory \param value, or nullptr
|
85 |
+
/// if no such Var exists
|
86 |
+
template<typename T>
|
87 |
+
std::shared_ptr<VarValueGeneric> GetByReference(const T& value);
|
88 |
+
|
89 |
+
/// Callback Event structure for notification of Var Additions and Deletions
|
90 |
+
struct Event {
|
91 |
+
/// Function signature for user callbacks
|
92 |
+
using Function = std::function<void(const Event&)>;
|
93 |
+
|
94 |
+
/// Type of Var Event
|
95 |
+
enum class Action {
|
96 |
+
Added, // A Var was added to the VarState index
|
97 |
+
Removed // A Var was removed from the VarState index
|
98 |
+
};
|
99 |
+
|
100 |
+
/// The kind of event
|
101 |
+
Action action;
|
102 |
+
|
103 |
+
/// The Var in question
|
104 |
+
/// Note: removals occur immediately following the callback
|
105 |
+
std::shared_ptr<VarValueGeneric> var;
|
106 |
+
};
|
107 |
+
|
108 |
+
/// Register to be informed of Var additions and removals
|
109 |
+
/// \param callback_function User callback to use for notifications
|
110 |
+
/// \param include_historic Request to receive addition callbacks for current Vars
|
111 |
+
/// \returns A \class Connection object for handling \param callback_function lifetime
|
112 |
+
sigslot::connection RegisterForVarEvents( Event::Function callback_function, bool include_historic);
|
113 |
+
|
114 |
+
/// Type of Var settings file
|
115 |
+
enum class FileKind
|
116 |
+
{
|
117 |
+
detected, // detect based on filename / contents
|
118 |
+
json, // use json format
|
119 |
+
config // use config format
|
120 |
+
};
|
121 |
+
|
122 |
+
/// Clear the VarState index of pangolin Vars.
|
123 |
+
/// Any remaining user instances of pangolin::Vars will remain valid but the
|
124 |
+
/// underlying data will be deallocated appropriately when no longer referenced
|
125 |
+
void Clear();
|
126 |
+
|
127 |
+
/// Removes a Var with the given name from the VarState index if it exists
|
128 |
+
/// \returns true iff a var was found to remove
|
129 |
+
bool Remove(const std::string& name);
|
130 |
+
|
131 |
+
/// Load Var state from file
|
132 |
+
void LoadFromFile(const std::string& filename, FileKind kind = FileKind::detected);
|
133 |
+
|
134 |
+
/// Save current Var state to file
|
135 |
+
void SaveToFile(const std::string& filename, FileKind kind = FileKind::json);
|
136 |
+
|
137 |
+
private:
|
138 |
+
typedef std::map<std::string, std::shared_ptr<VarValueGeneric>> VarStoreMap;
|
139 |
+
typedef std::map<const void*, std::weak_ptr<VarValueGeneric>> VarStoreMapReverse;
|
140 |
+
typedef std::vector<std::weak_ptr<VarValueGeneric>> VarStoreAdditions;
|
141 |
+
|
142 |
+
template<typename T>
|
143 |
+
VarStoreMap::iterator AddVar(
|
144 |
+
const std::shared_ptr<VarValue<T>>& var,
|
145 |
+
bool record_and_notify = true
|
146 |
+
);
|
147 |
+
|
148 |
+
template<typename T>
|
149 |
+
VarStoreMap::iterator AddUpgradedVar(
|
150 |
+
const std::shared_ptr<VarValue<T>>& var,
|
151 |
+
const VarStoreMap::iterator& existing,
|
152 |
+
bool record_and_notify = true
|
153 |
+
);
|
154 |
+
|
155 |
+
void AddOrSetGeneric(const std::string& name, const std::string& value);
|
156 |
+
std::string ProcessVal(const std::string& val );
|
157 |
+
|
158 |
+
void LoadFromJsonStream(std::istream& is);
|
159 |
+
void LoadFromConfigStream(std::istream& is);
|
160 |
+
void SaveToJsonStream(std::ostream& os);
|
161 |
+
|
162 |
+
sigslot::signal<Event> VarEventSignal;
|
163 |
+
|
164 |
+
VarStoreMap vars;
|
165 |
+
VarStoreMapReverse vars_reverse;
|
166 |
+
VarStoreAdditions vars_add_order;
|
167 |
+
};
|
168 |
+
|
169 |
+
|
170 |
+
/////////////////////////////////////////////////////////////////////////////
|
171 |
+
/// Implementation
|
172 |
+
/////////////////////////////////////////////////////////////////////////////
|
173 |
+
|
174 |
+
template<typename T>
|
175 |
+
std::shared_ptr<VarValueGeneric> VarState::AttachVar(
|
176 |
+
T& variable, const VarMeta& meta
|
177 |
+
) {
|
178 |
+
VarStoreMap::iterator it = vars.find(meta.full_name);
|
179 |
+
|
180 |
+
if (it != vars.end()) {
|
181 |
+
std::shared_ptr<VarValueGeneric> generic = it->second;
|
182 |
+
|
183 |
+
// Variable already exists
|
184 |
+
std::shared_ptr<VarValue<T>> tval = std::dynamic_pointer_cast<VarValue<T>>(it->second);
|
185 |
+
|
186 |
+
// We have a problem if the variable doesn't point to the same thing.
|
187 |
+
if( !tval || (&(tval->Get()) != &variable) ) {
|
188 |
+
throw std::runtime_error("Different Var with that name already exists.");
|
189 |
+
}
|
190 |
+
}else{
|
191 |
+
it = AddVar(std::make_shared<VarValue<T>>(variable, meta) );
|
192 |
+
}
|
193 |
+
return it->second;
|
194 |
+
}
|
195 |
+
|
196 |
+
template<typename T>
|
197 |
+
std::shared_ptr<VarValueGeneric> VarState::GetOrCreateVar(
|
198 |
+
const T& value, const VarMeta& meta
|
199 |
+
) {
|
200 |
+
VarStoreMap::iterator it = vars.find(meta.full_name);
|
201 |
+
|
202 |
+
if (it != vars.end()) {
|
203 |
+
if(it->second->Meta().generic) {
|
204 |
+
// upgrade from untyped 'generic' type now we have first typed reference
|
205 |
+
AddUpgradedVar(InitialiseFromPreviouslyGenericVar<T>(it->second), it);
|
206 |
+
}
|
207 |
+
}else{
|
208 |
+
it = AddVar(std::make_shared<VarValue<T>>( value, meta ) );
|
209 |
+
}
|
210 |
+
|
211 |
+
return it->second;
|
212 |
+
}
|
213 |
+
|
214 |
+
inline std::shared_ptr<VarValueGeneric> VarState::GetByName(const std::string& full_name) {
|
215 |
+
VarStoreMap::iterator it = vars.find(full_name);
|
216 |
+
|
217 |
+
if (it != vars.end()) {
|
218 |
+
return it->second;
|
219 |
+
}
|
220 |
+
|
221 |
+
return nullptr;
|
222 |
+
}
|
223 |
+
|
224 |
+
template<typename T>
|
225 |
+
std::shared_ptr<VarValueGeneric> VarState::GetByReference(const T& value)
|
226 |
+
{
|
227 |
+
const void* backingValue = &value;
|
228 |
+
auto it = vars_reverse.find(backingValue);
|
229 |
+
|
230 |
+
if (it != vars_reverse.end())
|
231 |
+
if( auto p_var = it->second.lock())
|
232 |
+
return p_var;
|
233 |
+
|
234 |
+
return nullptr;
|
235 |
+
}
|
236 |
+
|
237 |
+
template<typename T>
|
238 |
+
VarState::VarStoreMap::iterator VarState::AddVar(
|
239 |
+
const std::shared_ptr<VarValue<T>>& var,
|
240 |
+
bool record_and_notify
|
241 |
+
) {
|
242 |
+
const auto [it, success] = vars.insert(VarStoreMap::value_type(var->Meta().full_name, var));
|
243 |
+
assert(success);
|
244 |
+
|
245 |
+
if(record_and_notify) {
|
246 |
+
vars_reverse[&var->Get()] = var;
|
247 |
+
vars_add_order.push_back(var);
|
248 |
+
VarEventSignal(Event{Event::Action::Added, var});
|
249 |
+
}
|
250 |
+
return it;
|
251 |
+
}
|
252 |
+
|
253 |
+
template<typename T>
|
254 |
+
VarState::VarStoreMap::iterator VarState::AddUpgradedVar(
|
255 |
+
const std::shared_ptr<VarValue<T>>& var,
|
256 |
+
const VarStoreMap::iterator& existing,
|
257 |
+
bool record_and_notify
|
258 |
+
) {
|
259 |
+
existing->second = var;
|
260 |
+
|
261 |
+
if(record_and_notify) {
|
262 |
+
vars_reverse[&var->Get()] = var;
|
263 |
+
vars_add_order.push_back(var);
|
264 |
+
VarEventSignal(Event{Event::Action::Added, var});
|
265 |
+
}
|
266 |
+
return existing;
|
267 |
+
}
|
268 |
+
|
269 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvalue.h
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/var/varvaluet.h>
|
31 |
+
#include <pangolin/var/varwrapper.h>
|
32 |
+
#include <pangolin/utils/is_streamable.h>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
template<typename T>
|
38 |
+
class VarValue : public VarValueT<typename std::remove_reference<T>::type>
|
39 |
+
{
|
40 |
+
public:
|
41 |
+
typedef typename std::remove_reference<T>::type VarT;
|
42 |
+
|
43 |
+
|
44 |
+
VarValue(const T& value, const VarT& default_value, const VarMeta& meta = VarMeta())
|
45 |
+
: value(value), default_value(default_value), meta(meta)
|
46 |
+
{
|
47 |
+
Init();
|
48 |
+
}
|
49 |
+
|
50 |
+
VarValue(const T& value, const VarMeta& meta = VarMeta())
|
51 |
+
: VarValue(value, value, meta)
|
52 |
+
{
|
53 |
+
}
|
54 |
+
|
55 |
+
VarValue()
|
56 |
+
: VarValue(T(), T())
|
57 |
+
{
|
58 |
+
}
|
59 |
+
|
60 |
+
const char* TypeId() const
|
61 |
+
{
|
62 |
+
return typeid(VarT).name();
|
63 |
+
}
|
64 |
+
|
65 |
+
void Reset()
|
66 |
+
{
|
67 |
+
value = default_value;
|
68 |
+
}
|
69 |
+
|
70 |
+
VarMeta& Meta()
|
71 |
+
{
|
72 |
+
return meta;
|
73 |
+
}
|
74 |
+
|
75 |
+
const VarT& Get() const
|
76 |
+
{
|
77 |
+
return value;
|
78 |
+
}
|
79 |
+
|
80 |
+
VarT& Get()
|
81 |
+
{
|
82 |
+
return value;
|
83 |
+
}
|
84 |
+
|
85 |
+
void Set(const VarT& val)
|
86 |
+
{
|
87 |
+
value = val;
|
88 |
+
}
|
89 |
+
|
90 |
+
protected:
|
91 |
+
// Specialization dummy for non-serializable types
|
92 |
+
struct ExceptionVarValue : public VarValueT<std::string>
|
93 |
+
{
|
94 |
+
typedef typename std::string VarT;
|
95 |
+
ExceptionVarValue() {}
|
96 |
+
const char* TypeId() const override { throw BadInputException(); }
|
97 |
+
virtual void Reset() override { throw BadInputException(); }
|
98 |
+
VarMeta& Meta() override { throw BadInputException(); }
|
99 |
+
const VarT& Get() const override { throw BadInputException(); }
|
100 |
+
void Set(const VarT& val) override { throw BadInputException(); }
|
101 |
+
};
|
102 |
+
|
103 |
+
template<typename TT> static
|
104 |
+
typename std::enable_if<is_streamable<TT>::value, std::shared_ptr<VarValueT<std::string>>>::type
|
105 |
+
MakeStringWrapper( const std::shared_ptr<VarValueT<TT>>& v )
|
106 |
+
{
|
107 |
+
return std::make_shared<VarWrapper<std::string,VarT>>(v);
|
108 |
+
}
|
109 |
+
|
110 |
+
template<typename TT> static
|
111 |
+
typename std::enable_if<!is_streamable<TT>::value, std::shared_ptr<VarValueT<std::string>>>::type
|
112 |
+
MakeStringWrapper( const std::shared_ptr<VarValueT<TT>>& v )
|
113 |
+
{
|
114 |
+
return std::make_shared<ExceptionVarValue>();
|
115 |
+
}
|
116 |
+
|
117 |
+
void Init()
|
118 |
+
{
|
119 |
+
// shared_ptr reference to self without deleter.
|
120 |
+
auto self = std::shared_ptr<VarValueT<VarT>>(this, [](VarValueT<VarT>*){} );
|
121 |
+
|
122 |
+
if(std::is_same<VarT,std::string>::value) {
|
123 |
+
// str is reference to this - remove shared_ptr's deleter
|
124 |
+
this->str = std::dynamic_pointer_cast<VarValueT<std::string>>(self);
|
125 |
+
}else{
|
126 |
+
this->str = MakeStringWrapper<VarT>(self);
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
T value;
|
131 |
+
VarT default_value;
|
132 |
+
VarMeta meta;
|
133 |
+
};
|
134 |
+
|
135 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvaluegeneric.h
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <string>
|
31 |
+
#include <memory>
|
32 |
+
#include <cmath>
|
33 |
+
#include <pangolin/utils/file_utils.h>
|
34 |
+
|
35 |
+
namespace pangolin
|
36 |
+
{
|
37 |
+
constexpr int META_FLAG_NONE = 0x0000;
|
38 |
+
constexpr int META_FLAG_TOGGLE = 0x0001;
|
39 |
+
constexpr int META_FLAG_READONLY = 0x0002;
|
40 |
+
|
41 |
+
struct VarMeta
|
42 |
+
{
|
43 |
+
VarMeta(
|
44 |
+
const std::string& full_name = "",
|
45 |
+
double min_val = 0.0, double max_val = 0.0,
|
46 |
+
double increment = 0.0, int flags = META_FLAG_NONE,
|
47 |
+
bool logscale = false, bool generic = false
|
48 |
+
) :
|
49 |
+
full_name(full_name),
|
50 |
+
increment(increment),
|
51 |
+
flags(flags),
|
52 |
+
gui_changed(false),
|
53 |
+
logscale(logscale),
|
54 |
+
generic(generic)
|
55 |
+
{
|
56 |
+
SetName(full_name);
|
57 |
+
if(logscale) {
|
58 |
+
if (min_val <= 0 || max_val <= 0) {
|
59 |
+
throw std::runtime_error("LogScale: range of numbers must be positive!");
|
60 |
+
}
|
61 |
+
range[0] = std::log(min_val);
|
62 |
+
range[1] = std::log(max_val);
|
63 |
+
}else{
|
64 |
+
range[0] = min_val;
|
65 |
+
range[1] = max_val;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
void SetName(const std::string& full_name)
|
70 |
+
{
|
71 |
+
this->full_name = full_name;
|
72 |
+
const std::vector<std::string> parts = pangolin::Split(full_name, '.');
|
73 |
+
friendly = parts.size() > 0 ? parts[parts.size()-1] : "";
|
74 |
+
}
|
75 |
+
|
76 |
+
std::string full_name;
|
77 |
+
std::string friendly;
|
78 |
+
double range[2];
|
79 |
+
double increment;
|
80 |
+
int flags;
|
81 |
+
bool gui_changed;
|
82 |
+
bool logscale;
|
83 |
+
bool generic;
|
84 |
+
};
|
85 |
+
|
86 |
+
// Forward declaration
|
87 |
+
template<typename T>
|
88 |
+
class VarValueT;
|
89 |
+
|
90 |
+
//! Abstract base class for named Pangolin variables
|
91 |
+
class VarValueGeneric
|
92 |
+
{
|
93 |
+
public:
|
94 |
+
VarValueGeneric()
|
95 |
+
{
|
96 |
+
}
|
97 |
+
|
98 |
+
virtual ~VarValueGeneric()
|
99 |
+
{
|
100 |
+
}
|
101 |
+
|
102 |
+
virtual const char* TypeId() const = 0;
|
103 |
+
virtual void Reset() = 0;
|
104 |
+
virtual VarMeta& Meta() = 0;
|
105 |
+
|
106 |
+
//protected:
|
107 |
+
// String serialisation object.
|
108 |
+
std::shared_ptr<VarValueT<std::string>> str;
|
109 |
+
};
|
110 |
+
|
111 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varvaluet.h
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/var/varvaluegeneric.h>
|
31 |
+
#include <pangolin/compat/type_traits.h>
|
32 |
+
|
33 |
+
namespace pangolin
|
34 |
+
{
|
35 |
+
|
36 |
+
template<typename T>
|
37 |
+
class VarValueT : public VarValueGeneric
|
38 |
+
{
|
39 |
+
public:
|
40 |
+
typedef typename std::remove_reference<T>::type VarT;
|
41 |
+
|
42 |
+
virtual const VarT& Get() const = 0;
|
43 |
+
virtual void Set(const VarT& val) = 0;
|
44 |
+
};
|
45 |
+
|
46 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/include/pangolin/var/varwrapper.h
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/var/varvaluegeneric.h>
|
31 |
+
#include <pangolin/compat/type_traits.h>
|
32 |
+
#include <pangolin/utils/type_convert.h>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
template<typename T, typename S>
|
38 |
+
class VarWrapper : public VarValueT<T>
|
39 |
+
{
|
40 |
+
public:
|
41 |
+
typedef typename std::remove_reference<S>::type VarS;
|
42 |
+
|
43 |
+
VarWrapper(const std::shared_ptr<VarValueT<S>>& src)
|
44 |
+
: src(src)
|
45 |
+
{
|
46 |
+
this->str = src->str;
|
47 |
+
}
|
48 |
+
|
49 |
+
const char* TypeId() const
|
50 |
+
{
|
51 |
+
return typeid(T).name();
|
52 |
+
}
|
53 |
+
|
54 |
+
void Reset()
|
55 |
+
{
|
56 |
+
src->Reset();
|
57 |
+
|
58 |
+
// If reset throws, it will go up to the user, since there is nothing
|
59 |
+
// more we can do
|
60 |
+
cache = Convert<T,VarS>::Do(src->Get());
|
61 |
+
}
|
62 |
+
|
63 |
+
VarMeta& Meta()
|
64 |
+
{
|
65 |
+
return src->Meta();
|
66 |
+
}
|
67 |
+
|
68 |
+
const T& Get() const
|
69 |
+
{
|
70 |
+
// This might throw, but we can't reset because this is a const method
|
71 |
+
cache = Convert<T,VarS>::Do(src->Get());
|
72 |
+
return cache;
|
73 |
+
}
|
74 |
+
|
75 |
+
void Set(const T& val)
|
76 |
+
{
|
77 |
+
cache = val;
|
78 |
+
// This might throw - needs to be dealt with by user
|
79 |
+
src->Set( Convert<VarS, T>::Do(val) );
|
80 |
+
}
|
81 |
+
|
82 |
+
protected:
|
83 |
+
mutable T cache;
|
84 |
+
std::shared_ptr<VarValueT<S>> src;
|
85 |
+
};
|
86 |
+
|
87 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/src/vars.cpp
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#include <pangolin/var/varextra.h>
|
29 |
+
#include <pangolin/var/varstate.h>
|
30 |
+
#include <pangolin/utils/file_utils.h>
|
31 |
+
#include <pangolin/utils/picojson.h>
|
32 |
+
#include <pangolin/utils/transform.h>
|
33 |
+
|
34 |
+
#include <iostream>
|
35 |
+
#include <fstream>
|
36 |
+
|
37 |
+
using namespace std;
|
38 |
+
|
39 |
+
namespace pangolin
|
40 |
+
{
|
41 |
+
|
42 |
+
void ParseVarsFile(const string& filename)
|
43 |
+
{
|
44 |
+
VarState::I().LoadFromFile(filename, VarState::FileKind::config);
|
45 |
+
}
|
46 |
+
|
47 |
+
void LoadJsonFile(const std::string& filename, const string &prefix)
|
48 |
+
{
|
49 |
+
VarState::I().LoadFromFile(filename, VarState::FileKind::json);
|
50 |
+
}
|
51 |
+
|
52 |
+
void SaveJsonFile(const std::string& filename, const string &prefix)
|
53 |
+
{
|
54 |
+
VarState::I().SaveToFile(filename, VarState::FileKind::json);
|
55 |
+
}
|
56 |
+
|
57 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/src/varstate.cpp
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <iostream>
|
2 |
+
#include <fstream>
|
3 |
+
#include <pangolin/var/varstate.h>
|
4 |
+
#include <pangolin/utils/picojson.h>
|
5 |
+
#include <pangolin/utils/transform.h>
|
6 |
+
|
7 |
+
namespace pangolin
|
8 |
+
{
|
9 |
+
|
10 |
+
namespace {
|
11 |
+
template< typename ContainerT, typename PredicateT >
|
12 |
+
void erase_if( ContainerT& items, const PredicateT& predicate ) {
|
13 |
+
for( auto it = items.begin(); it != items.end(); ) {
|
14 |
+
if( predicate(*it) ) it = items.erase(it);
|
15 |
+
else ++it;
|
16 |
+
}
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
VarState& VarState::I() {
|
21 |
+
static VarState singleton;
|
22 |
+
return singleton;
|
23 |
+
}
|
24 |
+
|
25 |
+
VarState::VarState()
|
26 |
+
{
|
27 |
+
}
|
28 |
+
|
29 |
+
VarState::~VarState() {
|
30 |
+
Clear();
|
31 |
+
}
|
32 |
+
|
33 |
+
void VarState::Clear() {
|
34 |
+
vars.clear();
|
35 |
+
vars_reverse.clear();
|
36 |
+
vars_add_order.clear();
|
37 |
+
}
|
38 |
+
|
39 |
+
bool VarState::Remove(const std::string& name)
|
40 |
+
{
|
41 |
+
VarStoreMap::iterator it = vars.find(name);
|
42 |
+
if(it != vars.end()) {
|
43 |
+
auto to_remove = it->second;
|
44 |
+
erase_if(vars_reverse, [&to_remove](auto el){return to_remove == el.second.lock();} );
|
45 |
+
erase_if(vars_add_order, [&to_remove](auto el){return to_remove == el.lock();} );
|
46 |
+
vars.erase(it);
|
47 |
+
VarEventSignal(Event{Event::Action::Removed, to_remove});
|
48 |
+
return true;
|
49 |
+
}
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
|
53 |
+
bool VarState::Exists(const std::string& key) const
|
54 |
+
{
|
55 |
+
return vars.find(key) != vars.end();
|
56 |
+
}
|
57 |
+
|
58 |
+
sigslot::connection VarState::RegisterForVarEvents( Event::Function callback_function, bool include_historic)
|
59 |
+
{
|
60 |
+
if(include_historic) {
|
61 |
+
for (auto it = vars_add_order.begin(); it != vars_add_order.end(); ++it)
|
62 |
+
{
|
63 |
+
if (auto p_var = it->lock()) {
|
64 |
+
callback_function({Event::Action::Added, p_var});
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
return VarEventSignal.connect(callback_function);
|
69 |
+
}
|
70 |
+
|
71 |
+
//void AddAlias(const string& alias, const string& name)
|
72 |
+
//{
|
73 |
+
// std::map<std::string,_Var*>::iterator vi = vars.find(name);
|
74 |
+
|
75 |
+
// if( vi != vars.end() )
|
76 |
+
// {
|
77 |
+
// _Var * v = vi->second;
|
78 |
+
// vars[alias].create(v->val,v->val_default,v->type_name);
|
79 |
+
// vars[alias].Meta().friendly = alias;
|
80 |
+
// v->generic = false;
|
81 |
+
// vars[alias].generic = false;
|
82 |
+
// }else{
|
83 |
+
// pango_print_error("Variable %s does not exist to alias.\n", name);
|
84 |
+
// }
|
85 |
+
//}
|
86 |
+
|
87 |
+
void VarState::AddOrSetGeneric(const std::string& name, const std::string& value)
|
88 |
+
{
|
89 |
+
const auto it = vars.find(name);
|
90 |
+
|
91 |
+
if (it != vars.end()) {
|
92 |
+
it->second->str->Set(value);
|
93 |
+
}else{
|
94 |
+
AddVar(std::make_shared<VarValue<std::string>>(
|
95 |
+
value, VarMeta(name, 0.0, 0.0, 0.0, 0, false, true)), false);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
void VarState::LoadFromJsonStream(std::istream& is)
|
100 |
+
{
|
101 |
+
picojson::value file_json(picojson::object_type,true);
|
102 |
+
const std::string err = picojson::parse(file_json,is);
|
103 |
+
if(err.empty()) {
|
104 |
+
if(file_json.contains("vars") ) {
|
105 |
+
picojson::value var_json = file_json["vars"];
|
106 |
+
if(var_json.is<picojson::object>()) {
|
107 |
+
for(picojson::object::iterator
|
108 |
+
i = var_json.get<picojson::object>().begin();
|
109 |
+
i!= var_json.get<picojson::object>().end();
|
110 |
+
++i)
|
111 |
+
{
|
112 |
+
const std::string& name = i->first;
|
113 |
+
const std::string& val = i->second.get<std::string>();
|
114 |
+
AddOrSetGeneric(name, val);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}else{
|
119 |
+
pango_print_error("%s\n", err.c_str());
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
// Recursively expand val
|
124 |
+
std::string VarState::ProcessVal(const std::string& val )
|
125 |
+
{
|
126 |
+
return Transform(val, [this](const std::string& k) -> std::string {
|
127 |
+
auto var = GetByName(k);
|
128 |
+
if( var && var->str ) {
|
129 |
+
return var->str->Get();
|
130 |
+
}else{
|
131 |
+
return std::string("#");
|
132 |
+
}
|
133 |
+
});
|
134 |
+
}
|
135 |
+
|
136 |
+
void VarState::LoadFromConfigStream(std::istream& is)
|
137 |
+
{
|
138 |
+
while( !is.bad() && !is.eof()) {
|
139 |
+
const int c = is.peek();
|
140 |
+
|
141 |
+
if( isspace(c) ) {
|
142 |
+
// ignore leading whitespace
|
143 |
+
is.get();
|
144 |
+
}else{
|
145 |
+
if( c == '#' || c == '%' ) {
|
146 |
+
// ignore lines starting # or %
|
147 |
+
std::string comment;
|
148 |
+
getline(is,comment);
|
149 |
+
}else{
|
150 |
+
// Otherwise, find name and value, seperated by '=' and ';'
|
151 |
+
std::string name;
|
152 |
+
std::string val;
|
153 |
+
getline(is,name,'=');
|
154 |
+
getline(is,val,';');
|
155 |
+
name = Trim(name, " \t\n\r");
|
156 |
+
val = Trim(val, " \t\n\r");
|
157 |
+
|
158 |
+
if( name.size() >0 && val.size() > 0 ) {
|
159 |
+
if( !val.substr(0,1).compare("@") ) {
|
160 |
+
// AddAlias(name,val.substr(1));
|
161 |
+
}else{
|
162 |
+
AddOrSetGeneric(name, val);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
void VarState::SaveToJsonStream(std::ostream &os)
|
171 |
+
{
|
172 |
+
picojson::value json_vars(picojson::object_type,true);
|
173 |
+
|
174 |
+
for(const auto& key_value : vars)
|
175 |
+
{
|
176 |
+
const std::string& name = key_value.first;
|
177 |
+
try{
|
178 |
+
json_vars[name] = key_value.second->str->Get();
|
179 |
+
}catch(const BadInputException&)
|
180 |
+
{
|
181 |
+
// Ignore things we can't serialise
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
picojson::value file_json(picojson::object_type,true);
|
186 |
+
file_json["vars"] = json_vars;
|
187 |
+
os << file_json.serialize(true);
|
188 |
+
}
|
189 |
+
|
190 |
+
void VarState::LoadFromFile(const std::string& filename, FileKind kind)
|
191 |
+
{
|
192 |
+
std::ifstream f(filename.c_str());
|
193 |
+
if( f.is_open() ) {
|
194 |
+
switch(kind)
|
195 |
+
{
|
196 |
+
case FileKind::detected:
|
197 |
+
{
|
198 |
+
const auto fl = ToLowerCopy(filename);
|
199 |
+
if(EndsWith(fl, ".json") || EndsWith(fl, ".jsn")) {
|
200 |
+
LoadFromJsonStream(f);
|
201 |
+
}else{
|
202 |
+
LoadFromConfigStream(f);
|
203 |
+
}
|
204 |
+
break;
|
205 |
+
}
|
206 |
+
case FileKind::config:
|
207 |
+
LoadFromConfigStream(f);
|
208 |
+
break;
|
209 |
+
case FileKind::json:
|
210 |
+
LoadFromJsonStream(f);
|
211 |
+
break;
|
212 |
+
}
|
213 |
+
}else{
|
214 |
+
pango_print_error("Unable to open file %s\n", filename.c_str());
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
void VarState::SaveToFile(const std::string& filename, FileKind kind)
|
219 |
+
{
|
220 |
+
std::ofstream f(filename);
|
221 |
+
if(f.is_open()) {
|
222 |
+
if(kind == FileKind::json) {
|
223 |
+
SaveToJsonStream(f);
|
224 |
+
}else{
|
225 |
+
throw std::runtime_error("Only support saving to JSON file right now.");
|
226 |
+
}
|
227 |
+
|
228 |
+
}else{
|
229 |
+
pango_print_error("Unable to serialise to %s\n", filename.c_str());
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
}
|
third-party/DPVO/Pangolin/components/pango_vars/tests/test_all.cpp
ADDED
@@ -0,0 +1,409 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#define CATCH_CONFIG_MAIN
|
2 |
+
#include <catch2/catch.hpp>
|
3 |
+
|
4 |
+
#include <pangolin/var/var.h>
|
5 |
+
#include <pangolin/var/varextra.h>
|
6 |
+
|
7 |
+
using namespace pangolin;
|
8 |
+
|
9 |
+
struct CustomType{
|
10 |
+
float a; int b;
|
11 |
+
};
|
12 |
+
std::ostream& operator<<(std::ostream& os, const CustomType& x)
|
13 |
+
{
|
14 |
+
return os << x.a << "," << x.b;
|
15 |
+
}
|
16 |
+
std::istream& operator>>(std::istream& is, CustomType& x)
|
17 |
+
{
|
18 |
+
is >> x.a;
|
19 |
+
if( is.get() != ',') throw BadInputException();
|
20 |
+
is >> x.b;
|
21 |
+
return is;
|
22 |
+
}
|
23 |
+
|
24 |
+
struct CustomTypeNoStream{
|
25 |
+
float a; int b;
|
26 |
+
};
|
27 |
+
|
28 |
+
|
29 |
+
SCENARIO( "Native Var Types" ) {
|
30 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
31 |
+
VarState::I().Clear();
|
32 |
+
|
33 |
+
GIVEN( "A Var with some type" ) {
|
34 |
+
Var<double> x1("some_double", 3.14);
|
35 |
+
|
36 |
+
REQUIRE( x1 == 3.14 );
|
37 |
+
REQUIRE( x1.Get() == 3.14 );
|
38 |
+
REQUIRE( x1.Meta().full_name == "some_double" );
|
39 |
+
REQUIRE( x1.Meta().friendly == "some_double" );
|
40 |
+
REQUIRE( x1.Meta().generic == false );
|
41 |
+
|
42 |
+
WHEN( "the Var is set" ) {
|
43 |
+
x1 = 6.7;
|
44 |
+
|
45 |
+
THEN( "the Var and underlying variable change" ) {
|
46 |
+
REQUIRE( x1 == 6.7 );
|
47 |
+
REQUIRE( x1.Get() == 6.7 );
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
WHEN( "a new Var with the same name is created" ) {
|
52 |
+
Var<double> alias_x1("some_double", 9.2);
|
53 |
+
|
54 |
+
THEN( "the Var references the original unchanged value" ) {
|
55 |
+
REQUIRE( alias_x1 == x1);
|
56 |
+
REQUIRE( alias_x1 == 3.14);
|
57 |
+
REQUIRE( &(alias_x1.Get()) == &(x1.Get()) );
|
58 |
+
}
|
59 |
+
|
60 |
+
WHEN( "the original Var is changed") {
|
61 |
+
x1 = 10.2;
|
62 |
+
|
63 |
+
THEN( "The new Var also changes") {
|
64 |
+
REQUIRE(alias_x1 == 10.2);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
WHEN( "the new Var is changed") {
|
69 |
+
alias_x1 = 10.3;
|
70 |
+
|
71 |
+
THEN( "The original var is also changed") {
|
72 |
+
REQUIRE(x1 == 10.3);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
WHEN( "a new Var of compatible type is created with the same name" ) {
|
78 |
+
Var<float> x2("some_double", 1.2);
|
79 |
+
Var<int> x3("some_double", 4);
|
80 |
+
|
81 |
+
THEN( "The variables are linked, and converted") {
|
82 |
+
REQUIRE(x2 == 3.14f);
|
83 |
+
REQUIRE(x3 == 3);
|
84 |
+
REQUIRE((void*)&(x2.Get()) != (void*)&(x1.Get()));
|
85 |
+
REQUIRE((void*)&(x3.Get()) != (void*)&(x1.Get()));
|
86 |
+
}
|
87 |
+
|
88 |
+
WHEN( "The new Var is changed") {
|
89 |
+
x3 = 2101;
|
90 |
+
|
91 |
+
THEN( "So is the original") {
|
92 |
+
REQUIRE(x1 == 2101.0);
|
93 |
+
}
|
94 |
+
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
WHEN( "a string Var is created with the same name") {
|
99 |
+
Var<std::string> xs("some_double", "test");
|
100 |
+
|
101 |
+
REQUIRE( xs.Get() == "3.14" );
|
102 |
+
|
103 |
+
WHEN( "it's changed to a compatible value") {
|
104 |
+
xs = "4.14";
|
105 |
+
|
106 |
+
THEN( "the original is updated") {
|
107 |
+
REQUIRE( x1 == 4.14 );
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
WHEN( "it's changed to an incompatible value") {
|
112 |
+
// This should really throw
|
113 |
+
REQUIRE_THROWS_AS(xs = "chortle", BadInputException);
|
114 |
+
|
115 |
+
THEN( "the original remains unchanged") {
|
116 |
+
REQUIRE( x1 == 3.14);
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
WHEN( "a new Var of incompatible type is created with the same name") {
|
122 |
+
// TODO: Should probably throw here instead
|
123 |
+
Var<CustomType> x4("some_double", {1.0,2});
|
124 |
+
|
125 |
+
THEN( "access results in a serialization exception") {
|
126 |
+
REQUIRE_THROWS_AS(x4.Get(), BadInputException);
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
SCENARIO( "String Var types" ) {
|
134 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
135 |
+
VarState::I().Clear();
|
136 |
+
|
137 |
+
GIVEN( "A string Pangolin Var") {
|
138 |
+
Var<std::string> x1("some_string", "0.7");
|
139 |
+
|
140 |
+
// REQUIRE( x1 == "0.7" ); // compile error?
|
141 |
+
REQUIRE( x1.Get() == "0.7");
|
142 |
+
REQUIRE( x1.Meta().generic == false );
|
143 |
+
|
144 |
+
WHEN( "A specialized Var is instantiated") {
|
145 |
+
Var<double> x2("some_string", 0.2);
|
146 |
+
|
147 |
+
THEN( "It takes the original value if compatible'") {
|
148 |
+
REQUIRE(x2 == 0.7);
|
149 |
+
}
|
150 |
+
|
151 |
+
WHEN( "The specialized Var is updated" ) {
|
152 |
+
x2 = 104.89;
|
153 |
+
|
154 |
+
THEN( "The original Var is also updated") {
|
155 |
+
REQUIRE( x1.Get() == "104.89" );
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
WHEN( "The original Var is updated" ) {
|
160 |
+
x1 = "55.0";
|
161 |
+
|
162 |
+
THEN( "The new var is also updated") {
|
163 |
+
REQUIRE( x2 == 55.0);
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
WHEN( "the original var is updated and not compatible") {
|
168 |
+
x1 = "sheeple";
|
169 |
+
|
170 |
+
REQUIRE( x1.Get() == std::string("sheeple") );
|
171 |
+
|
172 |
+
THEN( "Accessing the specialized new var causes an exception") {
|
173 |
+
REQUIRE_THROWS_AS(x2.Ref()->Get(), BadInputException);
|
174 |
+
// TODO: Var.Get() current catches and ignores this exception!?
|
175 |
+
REQUIRE_THROWS_AS(x2.Get(), BadInputException);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
SCENARIO( "Custom Var Types" )
|
183 |
+
{
|
184 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
185 |
+
VarState::I().Clear();
|
186 |
+
|
187 |
+
GIVEN("A Var with custom type with stream operators") {
|
188 |
+
Var<CustomType> x1("x1", {1.2f,3});
|
189 |
+
|
190 |
+
THEN("We can access and set it") {
|
191 |
+
REQUIRE(x1.Get().a == 1.2f);
|
192 |
+
REQUIRE(x1.Get().b == 3);
|
193 |
+
|
194 |
+
x1 = CustomType{4.3f, 90};
|
195 |
+
REQUIRE(x1.Get().a == 4.3f);
|
196 |
+
REQUIRE(x1.Get().b == 90);
|
197 |
+
}
|
198 |
+
|
199 |
+
THEN("We can access it as a string type") {
|
200 |
+
Var<std::string> str_x1("x1");
|
201 |
+
REQUIRE(str_x1.Get() == "1.2,3");
|
202 |
+
|
203 |
+
str_x1 = "5.6,100";
|
204 |
+
REQUIRE(x1.Get().a == 5.6f);
|
205 |
+
REQUIRE(x1.Get().b == 100);
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
GIVEN("A Var with custom type without stream operators") {
|
210 |
+
Var<CustomTypeNoStream> x2("x2", {7.7f, 40});
|
211 |
+
|
212 |
+
THEN("We can access and set it") {
|
213 |
+
REQUIRE(x2.Get().a == 7.7f);
|
214 |
+
REQUIRE(x2.Get().b == 40);
|
215 |
+
|
216 |
+
x2 = CustomTypeNoStream{4.4f, 91};
|
217 |
+
REQUIRE(x2.Get().a == 4.4f);
|
218 |
+
REQUIRE(x2.Get().b == 91);
|
219 |
+
}
|
220 |
+
|
221 |
+
THEN("Can be accessed through an aliasing Var") {
|
222 |
+
Var<CustomTypeNoStream> alias_x2("x2");
|
223 |
+
|
224 |
+
REQUIRE(alias_x2.Get().a == 7.7f);
|
225 |
+
REQUIRE(alias_x2.Get().b == 40);
|
226 |
+
|
227 |
+
alias_x2 = CustomTypeNoStream{4.4f, 91};
|
228 |
+
REQUIRE(x2.Get().a == 4.4f);
|
229 |
+
REQUIRE(x2.Get().b == 91);
|
230 |
+
}
|
231 |
+
|
232 |
+
THEN("Generic use through string accessors throws") {
|
233 |
+
Var<std::string> str_x2("x2");
|
234 |
+
|
235 |
+
REQUIRE_THROWS(str_x2.Get());
|
236 |
+
REQUIRE_THROWS(str_x2 = "1.2,3");
|
237 |
+
}
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
SCENARIO("Attaching Vars")
|
242 |
+
{
|
243 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
244 |
+
VarState::I().Clear();
|
245 |
+
|
246 |
+
GIVEN( "An attached Pangolin Var") {
|
247 |
+
double x1 = 0.5;
|
248 |
+
Var<double>::Attach("x1", x1);
|
249 |
+
|
250 |
+
THEN("The var is accessible through standard vars") {
|
251 |
+
REQUIRE( Var<double>("x1").Get() == 0.5 );
|
252 |
+
REQUIRE( Var<std::string>("x1").Get() == "0.5");
|
253 |
+
}
|
254 |
+
|
255 |
+
WHEN("The attached var is changed") {
|
256 |
+
x1 = 10.0;
|
257 |
+
REQUIRE(Var<double>("x1").Get() == x1 );
|
258 |
+
}
|
259 |
+
|
260 |
+
WHEN("The pangolin var is set") {
|
261 |
+
Var<double>("x1") = 2.6;
|
262 |
+
REQUIRE(x1 == 2.6);
|
263 |
+
|
264 |
+
Var<std::string>("x1") = "7.8";
|
265 |
+
REQUIRE(x1 == 7.8);
|
266 |
+
}
|
267 |
+
|
268 |
+
WHEN("Another var is attached with the same name") {
|
269 |
+
int x1_int;
|
270 |
+
REQUIRE_THROWS_AS(Var<int>::Attach("x1", x1_int), std::runtime_error);
|
271 |
+
}
|
272 |
+
|
273 |
+
}
|
274 |
+
|
275 |
+
GIVEN( "An ordinary Pangolin Var") {
|
276 |
+
Var<double> x1("x1", 0.5);
|
277 |
+
|
278 |
+
THEN( "Trying to attach a Var with the same name throws") {
|
279 |
+
double x1_attach = 1.0;
|
280 |
+
REQUIRE_THROWS_AS(Var<double>::Attach("x1",x1_attach) = 2.0, std::runtime_error);
|
281 |
+
}
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
SCENARIO("Detaching Vars")
|
286 |
+
{
|
287 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
288 |
+
VarState::I().Clear();
|
289 |
+
|
290 |
+
GIVEN( "An attached Pangolin Var") {
|
291 |
+
double x1 = 0.5;
|
292 |
+
Var<double>::Attach("x1", x1);
|
293 |
+
|
294 |
+
REQUIRE(VarState::I().Exists("x1"));
|
295 |
+
|
296 |
+
WHEN("An alias is created")
|
297 |
+
{
|
298 |
+
Var<double> alias_x1("x1");
|
299 |
+
REQUIRE(alias_x1.Get() == x1);
|
300 |
+
|
301 |
+
THEN("Changes are synchronized") {
|
302 |
+
x1=0.7;
|
303 |
+
REQUIRE(alias_x1 == 0.7);
|
304 |
+
|
305 |
+
alias_x1 = 0.9;
|
306 |
+
REQUIRE(x1 == 0.9);
|
307 |
+
}
|
308 |
+
|
309 |
+
WHEN("Var is detached") {
|
310 |
+
DetachVar(x1);
|
311 |
+
|
312 |
+
REQUIRE(!VarState::I().Exists("x1"));
|
313 |
+
|
314 |
+
THEN("Changes are still synchronized since alias still in scope") {
|
315 |
+
x1=0.7;
|
316 |
+
REQUIRE(alias_x1 == 0.7);
|
317 |
+
|
318 |
+
alias_x1 = 0.9;
|
319 |
+
REQUIRE(x1 == 0.9);
|
320 |
+
}
|
321 |
+
|
322 |
+
THEN("Var with same name created is independent") {
|
323 |
+
Var<double> new_x1("x1");
|
324 |
+
REQUIRE(VarState::I().Exists("x1"));
|
325 |
+
|
326 |
+
new_x1 = 1.2;
|
327 |
+
REQUIRE(x1 == 0.5);
|
328 |
+
|
329 |
+
x1 = 2.3;
|
330 |
+
REQUIRE(new_x1 == 1.2);
|
331 |
+
|
332 |
+
WHEN("New Var for x1 created and changed") {
|
333 |
+
Var<double> alias_new_x1("x1");
|
334 |
+
REQUIRE(alias_new_x1 == 1.2);
|
335 |
+
|
336 |
+
alias_new_x1 = 3.7;
|
337 |
+
REQUIRE(new_x1 == 3.7);
|
338 |
+
REQUIRE(x1 == 2.3);
|
339 |
+
}
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
}
|
344 |
+
}
|
345 |
+
|
346 |
+
SCENARIO("Var Events")
|
347 |
+
{
|
348 |
+
// Pangolin Var's have enduring lifetime and we must reset state
|
349 |
+
VarState::I().Clear();
|
350 |
+
|
351 |
+
Var<double> x1("x1");
|
352 |
+
Var<std::string> x2("x2");
|
353 |
+
|
354 |
+
WHEN("Registering for callbaks without historically added vars") {
|
355 |
+
std::vector<std::string> names;
|
356 |
+
|
357 |
+
sigslot::scoped_connection conn = VarState::I().RegisterForVarEvents([&names](const VarState::Event& e){
|
358 |
+
REQUIRE(e.action == VarState::Event::Action::Added);
|
359 |
+
names.push_back(e.var->Meta().full_name);
|
360 |
+
}, false);
|
361 |
+
|
362 |
+
THEN("We dont get them") {
|
363 |
+
REQUIRE(names.size() == 0);
|
364 |
+
}
|
365 |
+
}
|
366 |
+
|
367 |
+
WHEN("Registering for historic events") {
|
368 |
+
std::vector<std::string> added;
|
369 |
+
std::vector<std::string> removed;
|
370 |
+
sigslot::scoped_connection conn1 = VarState::I().RegisterForVarEvents([&added,&removed](const VarState::Event& e){
|
371 |
+
auto& vec = (e.action == VarState::Event::Action::Added) ? added : removed;
|
372 |
+
vec.push_back(e.var->Meta().full_name);
|
373 |
+
}, true);
|
374 |
+
|
375 |
+
THEN("We get them") {
|
376 |
+
REQUIRE(added.size() == 2);
|
377 |
+
REQUIRE(added[0] == "x1");
|
378 |
+
REQUIRE(added[1] == "x2");
|
379 |
+
}
|
380 |
+
|
381 |
+
WHEN("We remove a var, we get an event") {
|
382 |
+
DetachVarByName("x2");
|
383 |
+
REQUIRE(removed.size() == 1);
|
384 |
+
REQUIRE(removed[0] == "x2");
|
385 |
+
}
|
386 |
+
|
387 |
+
WHEN("We add another listener") {
|
388 |
+
sigslot::scoped_connection conn2 = VarState::I().RegisterForVarEvents([&added,&removed](const VarState::Event& e){
|
389 |
+
auto& vec = (e.action == VarState::Event::Action::Added) ? added : removed;
|
390 |
+
vec.push_back(e.var->Meta().full_name + "_");
|
391 |
+
}, false);
|
392 |
+
|
393 |
+
THEN("They both get called!")
|
394 |
+
{
|
395 |
+
double x3 = 99.0;
|
396 |
+
AttachVar("x3", x3);
|
397 |
+
|
398 |
+
REQUIRE(added.size() == 4);
|
399 |
+
REQUIRE(added[2] == "x3");
|
400 |
+
REQUIRE(added[3] == "x3_");
|
401 |
+
|
402 |
+
DetachVar(x3);
|
403 |
+
REQUIRE(removed.size() == 2);
|
404 |
+
REQUIRE(removed[0] == "x3");
|
405 |
+
REQUIRE(removed[1] == "x3_");
|
406 |
+
}
|
407 |
+
}
|
408 |
+
}
|
409 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/CMakeLists.txt
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME)
|
2 |
+
|
3 |
+
set(DRIVER_DIR "${CMAKE_CURRENT_LIST_DIR}/src/drivers")
|
4 |
+
|
5 |
+
target_sources( ${COMPONENT}
|
6 |
+
PRIVATE
|
7 |
+
${CMAKE_CURRENT_LIST_DIR}/src/stream_encoder_factory.cpp
|
8 |
+
${CMAKE_CURRENT_LIST_DIR}/src/video_input.cpp
|
9 |
+
${CMAKE_CURRENT_LIST_DIR}/src/video_output.cpp
|
10 |
+
${CMAKE_CURRENT_LIST_DIR}/src/video.cpp
|
11 |
+
${CMAKE_CURRENT_LIST_DIR}/src/video_help.cpp
|
12 |
+
${DRIVER_DIR}/test.cpp
|
13 |
+
${DRIVER_DIR}/images.cpp
|
14 |
+
${DRIVER_DIR}/images_out.cpp
|
15 |
+
${DRIVER_DIR}/split.cpp
|
16 |
+
${DRIVER_DIR}/truncate.cpp
|
17 |
+
${DRIVER_DIR}/pango.cpp
|
18 |
+
${DRIVER_DIR}/pango_video_output.cpp
|
19 |
+
${DRIVER_DIR}/debayer.cpp
|
20 |
+
${DRIVER_DIR}/shift.cpp
|
21 |
+
${DRIVER_DIR}/transform.cpp
|
22 |
+
${DRIVER_DIR}/unpack.cpp
|
23 |
+
${DRIVER_DIR}/pack.cpp
|
24 |
+
${DRIVER_DIR}/join.cpp
|
25 |
+
${DRIVER_DIR}/merge.cpp
|
26 |
+
${DRIVER_DIR}/json.cpp
|
27 |
+
${DRIVER_DIR}/thread.cpp
|
28 |
+
${DRIVER_DIR}/mjpeg.cpp
|
29 |
+
)
|
30 |
+
|
31 |
+
PangolinRegisterFactory(
|
32 |
+
VideoInterface
|
33 |
+
TestVideo ImagesVideo SplitVideo TruncateVideo PangoVideo
|
34 |
+
DebayerVideo ShiftVideo TransformVideo UnpackVideo PackVideo
|
35 |
+
JoinVideo MergeVideo JsonVideo MjpegVideo
|
36 |
+
)
|
37 |
+
|
38 |
+
PangolinRegisterFactory(
|
39 |
+
VideoOutputInterface
|
40 |
+
ImagesVideoOutput PangoVideoOutput
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
#########################################################
|
46 |
+
# Search for third-party libraries
|
47 |
+
|
48 |
+
if (UNIX)
|
49 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/shared_memory.cpp )
|
50 |
+
PangolinRegisterFactory( VideoInterface ThreadVideo )
|
51 |
+
endif()
|
52 |
+
|
53 |
+
option(BUILD_PANGOLIN_LIBDC1394 "Build support for libdc1394 video input" ON)
|
54 |
+
if(BUILD_PANGOLIN_LIBDC1394)
|
55 |
+
find_package(DC1394 QUIET)
|
56 |
+
if(DC1394_FOUND)
|
57 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/firewire.cpp ${DRIVER_DIR}/deinterlace.cpp)
|
58 |
+
target_link_libraries(${COMPONENT} PRIVATE ${DC1394_LIBRARY} )
|
59 |
+
target_include_directories(${COMPONENT} PRIVATE ${DC1394_INCLUDE_DIR} )
|
60 |
+
PangolinRegisterFactory( VideoInterface FirewireVideo DeinterlaceVideo)
|
61 |
+
message(STATUS "libdc1394 Found and Enabled")
|
62 |
+
endif()
|
63 |
+
endif()
|
64 |
+
|
65 |
+
option(BUILD_PANGOLIN_V4L "Build support for V4L video input" ON)
|
66 |
+
if(BUILD_PANGOLIN_V4L AND _LINUX_)
|
67 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/v4l.cpp)
|
68 |
+
PangolinRegisterFactory( VideoInterface V4lVideo )
|
69 |
+
message(STATUS "V4L Found and Enabled")
|
70 |
+
endif()
|
71 |
+
|
72 |
+
option(BUILD_PANGOLIN_FFMPEG "Build support for ffmpeg video input" ON)
|
73 |
+
if(BUILD_PANGOLIN_FFMPEG)
|
74 |
+
find_package(FFMPEG QUIET)
|
75 |
+
if(FFMPEG_FOUND)
|
76 |
+
target_sources( ${COMPONENT} PRIVATE
|
77 |
+
${DRIVER_DIR}/ffmpeg.cpp
|
78 |
+
${DRIVER_DIR}/ffmpeg_convert.cpp
|
79 |
+
${DRIVER_DIR}/ffmpeg_output.cpp
|
80 |
+
)
|
81 |
+
target_link_libraries(${COMPONENT} PRIVATE ${FFMPEG_LIBRARIES} )
|
82 |
+
target_include_directories(${COMPONENT} PRIVATE ${FFMPEG_INCLUDE_DIRS} )
|
83 |
+
PangolinRegisterFactory( VideoInterface FfmpegVideo)
|
84 |
+
PangolinRegisterFactory( VideoInterface FfmpegVideo FfmpegVideoConvert)
|
85 |
+
PangolinRegisterFactory( VideoOutputInterface FfmpegVideoOutput)
|
86 |
+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
87 |
+
# FFMPEG is a real pain for deprecating the API.
|
88 |
+
set_source_files_properties(${DRIVER_DIR}/ffmpeg.cpp PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
|
89 |
+
endif()
|
90 |
+
message(STATUS "ffmpeg Found and Enabled: ${FFMPEG_INCLUDE_DIRS}")
|
91 |
+
endif()
|
92 |
+
endif()
|
93 |
+
|
94 |
+
option(BUILD_PANGOLIN_REALSENSE "Build support for RealSense video input" ON)
|
95 |
+
if(BUILD_PANGOLIN_REALSENSE)
|
96 |
+
find_package(RealSense QUIET)
|
97 |
+
if(REALSENSE_FOUND)
|
98 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/realsense.cpp)
|
99 |
+
target_link_libraries(${COMPONENT} PRIVATE ${REALSENSE_LIBRARIES} )
|
100 |
+
target_include_directories(${COMPONENT} PRIVATE ${REALSENSE_INCLUDE_DIRS} )
|
101 |
+
PangolinRegisterFactory( VideoInterface RealSenseVideo )
|
102 |
+
message(STATUS "RealSense Found and Enabled")
|
103 |
+
endif()
|
104 |
+
endif()
|
105 |
+
|
106 |
+
option(BUILD_PANGOLIN_REALSENSE2 "Build support for RealSense2 video input" ON)
|
107 |
+
if(BUILD_PANGOLIN_REALSENSE2)
|
108 |
+
find_package(RealSense2 QUIET)
|
109 |
+
if(REALSENSE2_FOUND)
|
110 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/realsense2.cpp)
|
111 |
+
target_link_libraries(${COMPONENT} PRIVATE ${REALSENSE2_LIBRARIES} )
|
112 |
+
target_include_directories(${COMPONENT} PRIVATE ${REALSENSE2_INCLUDE_DIRS} )
|
113 |
+
PangolinRegisterFactory( VideoInterface RealSense2Video )
|
114 |
+
message(STATUS "RealSense2 Found and Enabled")
|
115 |
+
endif()
|
116 |
+
endif()
|
117 |
+
|
118 |
+
option(BUILD_PANGOLIN_OPENNI "Build support for OpenNI video input" ON)
|
119 |
+
if(BUILD_PANGOLIN_OPENNI)
|
120 |
+
find_package(OpenNI QUIET)
|
121 |
+
if(OPENNI_FOUND)
|
122 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/openni.cpp)
|
123 |
+
target_link_libraries(${COMPONENT} PRIVATE ${OPENNI_LIBRARIES} )
|
124 |
+
target_include_directories(${COMPONENT} PRIVATE ${OPENNI_INCLUDE_DIRS} )
|
125 |
+
PangolinRegisterFactory( VideoInterface OpenNiVideo )
|
126 |
+
message(STATUS "OpenNI Found and Enabled")
|
127 |
+
endif()
|
128 |
+
endif()
|
129 |
+
|
130 |
+
option(BUILD_PANGOLIN_OPENNI2 "Build support for OpenNI2 video input" ON)
|
131 |
+
if(BUILD_PANGOLIN_OPENNI2)
|
132 |
+
find_package(OpenNI2 QUIET)
|
133 |
+
if(OPENNI2_FOUND)
|
134 |
+
if(LINUX)
|
135 |
+
target_compile_definitions(${COMPONENT} PRIVATE linux)
|
136 |
+
endif()
|
137 |
+
|
138 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/openni2.cpp)
|
139 |
+
target_link_libraries(${COMPONENT} PRIVATE ${OPENNI2_LIBRARIES} )
|
140 |
+
target_include_directories(${COMPONENT} PRIVATE ${OPENNI2_INCLUDE_DIRS} )
|
141 |
+
PangolinRegisterFactory( VideoInterface OpenNi2Video )
|
142 |
+
message(STATUS "OpenNI2 Found and Enabled")
|
143 |
+
endif()
|
144 |
+
endif()
|
145 |
+
|
146 |
+
option(BUILD_PANGOLIN_LIBUVC "Build support for libuvc video input" ON)
|
147 |
+
if(BUILD_PANGOLIN_LIBUVC)
|
148 |
+
find_package(uvc QUIET)
|
149 |
+
if(uvc_FOUND)
|
150 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/uvc.cpp)
|
151 |
+
target_link_libraries(${COMPONENT} PRIVATE ${uvc_LIBRARIES} )
|
152 |
+
target_include_directories(${COMPONENT} PRIVATE ${uvc_INCLUDE_DIRS} )
|
153 |
+
PangolinRegisterFactory( VideoInterface UvcVideo )
|
154 |
+
if(WIN32 OR WIN64)
|
155 |
+
find_package(pthread REQUIRED QUIET)
|
156 |
+
find_package(libusb1 REQUIRED QUIET)
|
157 |
+
target_link_libraries(${COMPONENT} PRIVATE
|
158 |
+
${pthread_LIBRARIES} ${libusb1_LIBRARIES}
|
159 |
+
)
|
160 |
+
endif()
|
161 |
+
message(STATUS "libuvc Found and Enabled")
|
162 |
+
endif()
|
163 |
+
endif()
|
164 |
+
|
165 |
+
option(BUILD_PANGOLIN_UVC_MEDIAFOUNDATION "Build support for MediaFoundation UVC input" ON)
|
166 |
+
if (BUILD_PANGOLIN_UVC_MEDIAFOUNDATION)
|
167 |
+
find_package(MediaFoundation QUIET)
|
168 |
+
if (MediaFoundation_FOUND)
|
169 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/uvc_mediafoundation.cpp)
|
170 |
+
target_link_libraries(${COMPONENT} PRIVATE ${MediaFoundation_LIBRARIES} )
|
171 |
+
PangolinRegisterFactory( VideoInterface UvcMediaFoundationVideo )
|
172 |
+
message(STATUS "MediaFoundation Found and Enabled")
|
173 |
+
endif()
|
174 |
+
endif()
|
175 |
+
|
176 |
+
option(BUILD_PANGOLIN_DEPTHSENSE "Build support for DepthSense video input" ON)
|
177 |
+
if(BUILD_PANGOLIN_DEPTHSENSE)
|
178 |
+
find_package(DepthSense QUIET)
|
179 |
+
if(DepthSense_FOUND)
|
180 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/depthsense.cpp)
|
181 |
+
target_link_libraries(${COMPONENT} PRIVATE ${DepthSense_LIBRARIES} )
|
182 |
+
target_include_directories(${COMPONENT} PRIVATE ${DepthSense_INCLUDE_DIRS} )
|
183 |
+
PangolinRegisterFactory( VideoInterface DepthSenseVideo )
|
184 |
+
message(STATUS "DepthSense Found and Enabled")
|
185 |
+
endif()
|
186 |
+
endif()
|
187 |
+
|
188 |
+
option(BUILD_PANGOLIN_TELICAM "Build support for TeliCam video input" ON)
|
189 |
+
if(BUILD_PANGOLIN_TELICAM)
|
190 |
+
find_package(TeliCam QUIET)
|
191 |
+
if(TeliCam_FOUND)
|
192 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/teli.cpp)
|
193 |
+
target_link_libraries(${COMPONENT} PRIVATE ${TeliCam_LIBRARIES} )
|
194 |
+
target_include_directories(${COMPONENT} PRIVATE ${TeliCam_INCLUDE_DIRS} )
|
195 |
+
PangolinRegisterFactory( VideoInterface TeliVideo )
|
196 |
+
message(STATUS "TeliCam Found and Enabled" )
|
197 |
+
endif()
|
198 |
+
endif()
|
199 |
+
|
200 |
+
option(BUILD_PANGOLIN_PLEORA "Build support for Pleora video input" ON)
|
201 |
+
if(BUILD_PANGOLIN_PLEORA)
|
202 |
+
find_package(Pleora QUIET)
|
203 |
+
if(Pleora_FOUND)
|
204 |
+
target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/pleora.cpp)
|
205 |
+
target_link_libraries(${COMPONENT} PRIVATE ${Pleora_LIBRARIES} )
|
206 |
+
target_include_directories(${COMPONENT} PRIVATE ${Pleora_INCLUDE_DIRS} )
|
207 |
+
PangolinRegisterFactory( VideoInterface PleoraVideo )
|
208 |
+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
209 |
+
# Suppress warnings generated from Pleora SDK.
|
210 |
+
set_source_files_properties(${DRIVER_DIR}/pleora.cpp PROPERTIES COMPILE_FLAGS -Wno-unknown-pragmas)
|
211 |
+
endif()
|
212 |
+
message(STATUS "Pleora Found and Enabled" )
|
213 |
+
endif()
|
214 |
+
endif()
|
215 |
+
|
216 |
+
#########################################################
|
217 |
+
|
218 |
+
target_link_libraries(${COMPONENT} PUBLIC pango_core pango_image pango_packetstream)
|
219 |
+
target_include_directories(${COMPONENT} PUBLIC
|
220 |
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
221 |
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
222 |
+
$<INSTALL_INTERFACE:include>
|
223 |
+
)
|
224 |
+
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX})
|
225 |
+
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX})
|
226 |
+
|
227 |
+
# Create RegisterFactoriesVideoInterface() method call file to load built drivers and add as source
|
228 |
+
create_factory_registry_file( "${CMAKE_CURRENT_BINARY_DIR}/include/pangolin/factory" VideoInterface )
|
229 |
+
create_factory_registry_file( "${CMAKE_CURRENT_BINARY_DIR}/include/pangolin/factory" VideoOutputInterface )
|
230 |
+
target_sources(${COMPONENT} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/pangolin/factory/RegisterFactoriesVideoInterface.h")
|
231 |
+
target_sources(${COMPONENT} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/pangolin/factory/RegisterFactoriesVideoOutputInterface.h")
|
232 |
+
|
233 |
+
|
234 |
+
if(BUILD_TESTS)
|
235 |
+
add_executable(test_video_uris ${CMAKE_CURRENT_LIST_DIR}/tests/tests_video_uri.cpp)
|
236 |
+
target_link_libraries(test_video_uris PRIVATE Catch2::Catch2 ${COMPONENT})
|
237 |
+
catch_discover_tests(test_video_uris)
|
238 |
+
add_executable(test_video_loading ${CMAKE_CURRENT_LIST_DIR}/tests/tests_video_loading.cpp)
|
239 |
+
target_link_libraries(test_video_loading PRIVATE Catch2::Catch2 ${COMPONENT})
|
240 |
+
catch_discover_tests(test_video_loading)
|
241 |
+
endif()
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/debayer.h
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
|
32 |
+
namespace pangolin
|
33 |
+
{
|
34 |
+
|
35 |
+
struct WbGains {
|
36 |
+
WbGains():r(1.0f), g(1.0f), b(1.0f){}
|
37 |
+
WbGains(float r_in, float g_in, float b_in):r(r_in), g(g_in), b(b_in){
|
38 |
+
PANGO_ASSERT(r_in >= 0.0f && r_in <= 1.0f &&
|
39 |
+
g_in >= 0.0f && g_in <= 1.0f &&
|
40 |
+
b_in >= 0.0f && b_in <= 1.0f ,
|
41 |
+
"[Debayer] White balance gains must be between 0.0 and 1.0");
|
42 |
+
}
|
43 |
+
float r;
|
44 |
+
float g;
|
45 |
+
float b;
|
46 |
+
};
|
47 |
+
|
48 |
+
// Enum to match libdc1394's dc1394_bayer_method_t
|
49 |
+
typedef enum {
|
50 |
+
BAYER_METHOD_NEAREST = 0,
|
51 |
+
BAYER_METHOD_SIMPLE,
|
52 |
+
BAYER_METHOD_BILINEAR,
|
53 |
+
BAYER_METHOD_HQLINEAR,
|
54 |
+
BAYER_METHOD_DOWNSAMPLE_,
|
55 |
+
BAYER_METHOD_EDGESENSE,
|
56 |
+
BAYER_METHOD_VNG,
|
57 |
+
BAYER_METHOD_AHD,
|
58 |
+
|
59 |
+
// Pangolin custom defines
|
60 |
+
BAYER_METHOD_NONE = 512,
|
61 |
+
BAYER_METHOD_DOWNSAMPLE,
|
62 |
+
BAYER_METHOD_DOWNSAMPLE_MONO
|
63 |
+
} bayer_method_t;
|
64 |
+
|
65 |
+
// Enum to match libdc1394's dc1394_color_filter_t
|
66 |
+
typedef enum {
|
67 |
+
DC1394_COLOR_FILTER_RGGB = 512,
|
68 |
+
DC1394_COLOR_FILTER_GBRG,
|
69 |
+
DC1394_COLOR_FILTER_GRBG,
|
70 |
+
DC1394_COLOR_FILTER_BGGR
|
71 |
+
} color_filter_t;
|
72 |
+
|
73 |
+
// Video class that debayers its video input using the given method.
|
74 |
+
class PANGOLIN_EXPORT DebayerVideo :
|
75 |
+
public VideoInterface,
|
76 |
+
public VideoFilterInterface,
|
77 |
+
public BufferAwareVideoInterface
|
78 |
+
{
|
79 |
+
public:
|
80 |
+
DebayerVideo(std::unique_ptr<VideoInterface>& videoin, const std::vector<bayer_method_t> &method, color_filter_t tile, const WbGains& input_wb_gains);
|
81 |
+
~DebayerVideo();
|
82 |
+
|
83 |
+
//! Implement VideoInput::Start()
|
84 |
+
void Start();
|
85 |
+
|
86 |
+
//! Implement VideoInput::Stop()
|
87 |
+
void Stop();
|
88 |
+
|
89 |
+
//! Implement VideoInput::SizeBytes()
|
90 |
+
size_t SizeBytes() const;
|
91 |
+
|
92 |
+
//! Implement VideoInput::Streams()
|
93 |
+
const std::vector<StreamInfo>& Streams() const;
|
94 |
+
|
95 |
+
//! Implement VideoInput::GrabNext()
|
96 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
97 |
+
|
98 |
+
//! Implement VideoInput::GrabNewest()
|
99 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
100 |
+
|
101 |
+
std::vector<VideoInterface*>& InputStreams();
|
102 |
+
|
103 |
+
static color_filter_t ColorFilterFromString(std::string str);
|
104 |
+
|
105 |
+
static bayer_method_t BayerMethodFromString(std::string str);
|
106 |
+
|
107 |
+
uint32_t AvailableFrames() const;
|
108 |
+
|
109 |
+
bool DropNFrames(uint32_t n);
|
110 |
+
|
111 |
+
protected:
|
112 |
+
void ProcessStreams(unsigned char* out, const unsigned char* in);
|
113 |
+
|
114 |
+
std::unique_ptr<VideoInterface> src;
|
115 |
+
std::vector<VideoInterface*> videoin;
|
116 |
+
std::vector<StreamInfo> streams;
|
117 |
+
|
118 |
+
size_t size_bytes;
|
119 |
+
std::unique_ptr<unsigned char[]> buffer;
|
120 |
+
|
121 |
+
std::vector<bayer_method_t> methods;
|
122 |
+
color_filter_t tile;
|
123 |
+
|
124 |
+
WbGains wb_gains;
|
125 |
+
|
126 |
+
picojson::value device_properties;
|
127 |
+
picojson::value frame_properties;
|
128 |
+
};
|
129 |
+
|
130 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/deinterlace.h
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2013 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <vector>
|
32 |
+
|
33 |
+
namespace pangolin
|
34 |
+
{
|
35 |
+
|
36 |
+
class PANGOLIN_EXPORT DeinterlaceVideo
|
37 |
+
: public VideoInterface
|
38 |
+
{
|
39 |
+
public:
|
40 |
+
DeinterlaceVideo(std::unique_ptr<VideoInterface>& videoin);
|
41 |
+
~DeinterlaceVideo();
|
42 |
+
|
43 |
+
size_t SizeBytes() const;
|
44 |
+
|
45 |
+
const std::vector<StreamInfo>& Streams() const;
|
46 |
+
|
47 |
+
void Start();
|
48 |
+
|
49 |
+
void Stop();
|
50 |
+
|
51 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
52 |
+
|
53 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
54 |
+
|
55 |
+
protected:
|
56 |
+
std::unique_ptr<VideoInterface> videoin;
|
57 |
+
std::vector<StreamInfo> streams;
|
58 |
+
unsigned char* buffer;
|
59 |
+
};
|
60 |
+
|
61 |
+
|
62 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/depthsense.h
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <thread>
|
31 |
+
#include <mutex>
|
32 |
+
#include <condition_variable>
|
33 |
+
|
34 |
+
#include <pangolin/video/video_interface.h>
|
35 |
+
#include <pangolin/video/iostream_operators.h>
|
36 |
+
|
37 |
+
// DepthSense SDK for SoftKinetic cameras from Creative
|
38 |
+
#include <DepthSense.hxx>
|
39 |
+
|
40 |
+
namespace pangolin
|
41 |
+
{
|
42 |
+
|
43 |
+
enum DepthSenseSensorType
|
44 |
+
{
|
45 |
+
DepthSenseUnassigned = -1,
|
46 |
+
DepthSenseRgb = 0,
|
47 |
+
DepthSenseDepth
|
48 |
+
};
|
49 |
+
|
50 |
+
// Video class that outputs test video signal.
|
51 |
+
class PANGOLIN_EXPORT DepthSenseVideo :
|
52 |
+
public VideoInterface, public VideoPropertiesInterface
|
53 |
+
{
|
54 |
+
public:
|
55 |
+
DepthSenseVideo(DepthSense::Device device, DepthSenseSensorType s1, DepthSenseSensorType s2, ImageDim dim1, ImageDim dim2, unsigned int fps1, unsigned int fps2, const Uri& uri);
|
56 |
+
~DepthSenseVideo();
|
57 |
+
|
58 |
+
//! Implement VideoInput::Start()
|
59 |
+
void Start();
|
60 |
+
|
61 |
+
//! Implement VideoInput::Stop()
|
62 |
+
void Stop();
|
63 |
+
|
64 |
+
//! Implement VideoInput::SizeBytes()
|
65 |
+
size_t SizeBytes() const;
|
66 |
+
|
67 |
+
//! Implement VideoInput::Streams()
|
68 |
+
const std::vector<StreamInfo>& Streams() const;
|
69 |
+
|
70 |
+
//! Implement VideoInput::GrabNext()
|
71 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
72 |
+
|
73 |
+
//! Implement VideoInput::GrabNewest()
|
74 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
75 |
+
|
76 |
+
//! Implement VideoInput::DeviceProperties()
|
77 |
+
const picojson::value& DeviceProperties() const {
|
78 |
+
return device_properties;
|
79 |
+
}
|
80 |
+
|
81 |
+
//! Implement VideoInput::DeviceProperties()
|
82 |
+
const picojson::value& FrameProperties() const {
|
83 |
+
return frame_properties;
|
84 |
+
}
|
85 |
+
protected:
|
86 |
+
void onNewColorSample(DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data);
|
87 |
+
void onNewDepthSample(DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data);
|
88 |
+
|
89 |
+
struct SensorConfig
|
90 |
+
{
|
91 |
+
DepthSenseSensorType type;
|
92 |
+
ImageDim dim;
|
93 |
+
unsigned int fps;
|
94 |
+
};
|
95 |
+
|
96 |
+
void UpdateParameters(const DepthSense::Node& node, const Uri& uri);
|
97 |
+
void ConfigureNodes(const Uri& uri);
|
98 |
+
void ConfigureDepthNode(const SensorConfig& sensorConfig, const Uri& uri);
|
99 |
+
void ConfigureColorNode(const SensorConfig& sensorConfig, const Uri& uri);
|
100 |
+
|
101 |
+
double GetDeltaTime() const;
|
102 |
+
|
103 |
+
std::vector<StreamInfo> streams;
|
104 |
+
picojson::value device_properties;
|
105 |
+
picojson::value frame_properties;
|
106 |
+
picojson::value* streams_properties;
|
107 |
+
|
108 |
+
|
109 |
+
DepthSense::Device device;
|
110 |
+
DepthSense::DepthNode g_dnode;
|
111 |
+
DepthSense::ColorNode g_cnode;
|
112 |
+
|
113 |
+
unsigned char* fill_image;
|
114 |
+
|
115 |
+
int depthmap_stream;
|
116 |
+
int rgb_stream;
|
117 |
+
|
118 |
+
int gotDepth;
|
119 |
+
int gotColor;
|
120 |
+
std::mutex update_mutex;
|
121 |
+
std::condition_variable cond_image_filled;
|
122 |
+
std::condition_variable cond_image_requested;
|
123 |
+
|
124 |
+
SensorConfig sensorConfig[2];
|
125 |
+
|
126 |
+
bool enableDepth;
|
127 |
+
bool enableColor;
|
128 |
+
double depthTs;
|
129 |
+
double colorTs;
|
130 |
+
|
131 |
+
size_t size_bytes;
|
132 |
+
};
|
133 |
+
|
134 |
+
class DepthSenseContext
|
135 |
+
{
|
136 |
+
friend class DepthSenseVideo;
|
137 |
+
|
138 |
+
public:
|
139 |
+
// Singleton Instance
|
140 |
+
static DepthSenseContext& I();
|
141 |
+
|
142 |
+
DepthSenseVideo* GetDepthSenseVideo(size_t device_num, DepthSenseSensorType s1, DepthSenseSensorType s2, ImageDim dim1, ImageDim dim2, unsigned int fps1, unsigned int fps2, const Uri& uri);
|
143 |
+
|
144 |
+
protected:
|
145 |
+
// Protected Constructor
|
146 |
+
DepthSenseContext();
|
147 |
+
~DepthSenseContext();
|
148 |
+
|
149 |
+
DepthSense::Context& Context();
|
150 |
+
|
151 |
+
void NewDeviceRunning();
|
152 |
+
void DeviceClosing();
|
153 |
+
|
154 |
+
void StartNodes();
|
155 |
+
void StopNodes();
|
156 |
+
|
157 |
+
void EventLoop();
|
158 |
+
|
159 |
+
void onDeviceConnected(DepthSense::Context context, DepthSense::Context::DeviceAddedData data);
|
160 |
+
void onDeviceDisconnected(DepthSense::Context context, DepthSense::Context::DeviceRemovedData data);
|
161 |
+
|
162 |
+
DepthSense::Context g_context;
|
163 |
+
|
164 |
+
std::thread event_thread;
|
165 |
+
bool is_running;
|
166 |
+
|
167 |
+
int running_devices;
|
168 |
+
};
|
169 |
+
|
170 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg.h
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/video/iostream_operators.h>
|
32 |
+
#include <pangolin/video/drivers/ffmpeg_common.h>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
class PANGOLIN_EXPORT FfmpegVideo : public VideoInterface, public VideoPlaybackInterface
|
38 |
+
{
|
39 |
+
public:
|
40 |
+
FfmpegVideo(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false, int user_video_stream = -1, ImageDim size = ImageDim(0,0));
|
41 |
+
~FfmpegVideo();
|
42 |
+
|
43 |
+
//! Implement VideoInput::Start()
|
44 |
+
void Start() override;
|
45 |
+
|
46 |
+
//! Implement VideoInput::Stop()
|
47 |
+
void Stop() override;
|
48 |
+
|
49 |
+
//! Implement VideoInput::SizeBytes()
|
50 |
+
size_t SizeBytes() const override;
|
51 |
+
|
52 |
+
//! Implement VideoInput::Streams()
|
53 |
+
const std::vector<StreamInfo>& Streams() const override;
|
54 |
+
|
55 |
+
//! Implement VideoInput::GrabNext()
|
56 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
57 |
+
|
58 |
+
//! Implement VideoInput::GrabNewest()
|
59 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
60 |
+
|
61 |
+
//! VideoPlaybackInterface methods
|
62 |
+
size_t GetCurrentFrameId() const override;
|
63 |
+
size_t GetTotalFrames() const override;
|
64 |
+
size_t Seek(size_t frameid) override;
|
65 |
+
|
66 |
+
protected:
|
67 |
+
void InitUrl(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false , int user_video_stream = -1, ImageDim size= ImageDim(0,0));
|
68 |
+
|
69 |
+
std::vector<StreamInfo> streams;
|
70 |
+
|
71 |
+
SwsContext *img_convert_ctx;
|
72 |
+
AVFormatContext *pFormatCtx;
|
73 |
+
int videoStream;
|
74 |
+
int64_t numFrames;
|
75 |
+
int64_t ptsPerFrame;
|
76 |
+
const AVCodec *pVidCodec;
|
77 |
+
const AVCodec *pAudCodec;
|
78 |
+
AVCodecContext *pCodecContext;
|
79 |
+
AVFrame *pFrame;
|
80 |
+
AVFrame *pFrameOut;
|
81 |
+
AVPacket *packet;
|
82 |
+
int numBytesOut;
|
83 |
+
AVPixelFormat fmtout;
|
84 |
+
int64_t next_frame;
|
85 |
+
};
|
86 |
+
|
87 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_common.h
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/video/video_exception.h>
|
4 |
+
#include <pangolin/utils/file_utils.h>
|
5 |
+
|
6 |
+
extern "C"
|
7 |
+
{
|
8 |
+
|
9 |
+
// HACK for some versions of FFMPEG
|
10 |
+
#ifndef INT64_C
|
11 |
+
#define INT64_C(c) (c ## LL)
|
12 |
+
#define UINT64_C(c) (c ## ULL)
|
13 |
+
#endif
|
14 |
+
|
15 |
+
#include <libavformat/avformat.h>
|
16 |
+
#include <libswscale/swscale.h>
|
17 |
+
#include <libavutil/pixdesc.h>
|
18 |
+
#include <libavcodec/avcodec.h>
|
19 |
+
#include <libavutil/imgutils.h>
|
20 |
+
|
21 |
+
// Some versions of FFMPEG define this horrid macro in global scope.
|
22 |
+
#undef PixelFormat
|
23 |
+
}
|
24 |
+
|
25 |
+
namespace pangolin
|
26 |
+
{
|
27 |
+
|
28 |
+
inline AVPixelFormat FfmpegFmtFromString(const std::string fmt)
|
29 |
+
{
|
30 |
+
const std::string lfmt = ToLowerCopy(fmt);
|
31 |
+
if(!lfmt.compare("gray8") || !lfmt.compare("grey8") || !lfmt.compare("grey")) {
|
32 |
+
return AV_PIX_FMT_GRAY8;
|
33 |
+
}
|
34 |
+
return av_get_pix_fmt(lfmt.c_str());
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
#define TEST_PIX_FMT_RETURN(fmt) case AV_PIX_FMT_##fmt: return #fmt;
|
39 |
+
inline std::string FfmpegFmtToString(const AVPixelFormat fmt)
|
40 |
+
{
|
41 |
+
switch( fmt )
|
42 |
+
{
|
43 |
+
TEST_PIX_FMT_RETURN(YUV420P);
|
44 |
+
TEST_PIX_FMT_RETURN(YUYV422);
|
45 |
+
TEST_PIX_FMT_RETURN(RGB24);
|
46 |
+
TEST_PIX_FMT_RETURN(BGR24);
|
47 |
+
TEST_PIX_FMT_RETURN(YUV422P);
|
48 |
+
TEST_PIX_FMT_RETURN(YUV444P);
|
49 |
+
TEST_PIX_FMT_RETURN(YUV410P);
|
50 |
+
TEST_PIX_FMT_RETURN(YUV411P);
|
51 |
+
TEST_PIX_FMT_RETURN(GRAY8);
|
52 |
+
TEST_PIX_FMT_RETURN(MONOWHITE);
|
53 |
+
TEST_PIX_FMT_RETURN(MONOBLACK);
|
54 |
+
TEST_PIX_FMT_RETURN(PAL8);
|
55 |
+
TEST_PIX_FMT_RETURN(YUVJ420P);
|
56 |
+
TEST_PIX_FMT_RETURN(YUVJ422P);
|
57 |
+
TEST_PIX_FMT_RETURN(YUVJ444P);
|
58 |
+
#ifdef FF_API_XVMC
|
59 |
+
TEST_PIX_FMT_RETURN(XVMC_MPEG2_MC);
|
60 |
+
TEST_PIX_FMT_RETURN(XVMC_MPEG2_IDCT);
|
61 |
+
#endif
|
62 |
+
TEST_PIX_FMT_RETURN(UYVY422);
|
63 |
+
TEST_PIX_FMT_RETURN(UYYVYY411);
|
64 |
+
TEST_PIX_FMT_RETURN(BGR8);
|
65 |
+
TEST_PIX_FMT_RETURN(BGR4);
|
66 |
+
TEST_PIX_FMT_RETURN(BGR4_BYTE);
|
67 |
+
TEST_PIX_FMT_RETURN(RGB8);
|
68 |
+
TEST_PIX_FMT_RETURN(RGB4);
|
69 |
+
TEST_PIX_FMT_RETURN(RGB4_BYTE);
|
70 |
+
TEST_PIX_FMT_RETURN(NV12);
|
71 |
+
TEST_PIX_FMT_RETURN(NV21);
|
72 |
+
TEST_PIX_FMT_RETURN(ARGB);
|
73 |
+
TEST_PIX_FMT_RETURN(RGBA);
|
74 |
+
TEST_PIX_FMT_RETURN(ABGR);
|
75 |
+
TEST_PIX_FMT_RETURN(BGRA);
|
76 |
+
TEST_PIX_FMT_RETURN(GRAY16BE);
|
77 |
+
TEST_PIX_FMT_RETURN(GRAY16LE);
|
78 |
+
TEST_PIX_FMT_RETURN(YUV440P);
|
79 |
+
TEST_PIX_FMT_RETURN(YUVJ440P);
|
80 |
+
TEST_PIX_FMT_RETURN(YUVA420P);
|
81 |
+
#ifdef FF_API_VDPAU
|
82 |
+
TEST_PIX_FMT_RETURN(VDPAU_H264);
|
83 |
+
TEST_PIX_FMT_RETURN(VDPAU_MPEG1);
|
84 |
+
TEST_PIX_FMT_RETURN(VDPAU_MPEG2);
|
85 |
+
TEST_PIX_FMT_RETURN(VDPAU_WMV3);
|
86 |
+
TEST_PIX_FMT_RETURN(VDPAU_VC1);
|
87 |
+
#endif
|
88 |
+
TEST_PIX_FMT_RETURN(RGB48BE );
|
89 |
+
TEST_PIX_FMT_RETURN(RGB48LE );
|
90 |
+
TEST_PIX_FMT_RETURN(RGB565BE);
|
91 |
+
TEST_PIX_FMT_RETURN(RGB565LE);
|
92 |
+
TEST_PIX_FMT_RETURN(RGB555BE);
|
93 |
+
TEST_PIX_FMT_RETURN(RGB555LE);
|
94 |
+
TEST_PIX_FMT_RETURN(BGR565BE);
|
95 |
+
TEST_PIX_FMT_RETURN(BGR565LE);
|
96 |
+
TEST_PIX_FMT_RETURN(BGR555BE);
|
97 |
+
TEST_PIX_FMT_RETURN(BGR555LE);
|
98 |
+
#if LIBAVFORMAT_VERSION_MAJOR >= 59
|
99 |
+
TEST_PIX_FMT_RETURN(VAAPI);
|
100 |
+
#else
|
101 |
+
TEST_PIX_FMT_RETURN(VAAPI_MOCO);
|
102 |
+
TEST_PIX_FMT_RETURN(VAAPI_IDCT);
|
103 |
+
TEST_PIX_FMT_RETURN(VAAPI_VLD);
|
104 |
+
#endif
|
105 |
+
TEST_PIX_FMT_RETURN(YUV420P16LE);
|
106 |
+
TEST_PIX_FMT_RETURN(YUV420P16BE);
|
107 |
+
TEST_PIX_FMT_RETURN(YUV422P16LE);
|
108 |
+
TEST_PIX_FMT_RETURN(YUV422P16BE);
|
109 |
+
TEST_PIX_FMT_RETURN(YUV444P16LE);
|
110 |
+
TEST_PIX_FMT_RETURN(YUV444P16BE);
|
111 |
+
#ifdef FF_API_VDPAU
|
112 |
+
TEST_PIX_FMT_RETURN(VDPAU_MPEG4);
|
113 |
+
#endif
|
114 |
+
TEST_PIX_FMT_RETURN(DXVA2_VLD);
|
115 |
+
TEST_PIX_FMT_RETURN(RGB444BE);
|
116 |
+
TEST_PIX_FMT_RETURN(RGB444LE);
|
117 |
+
TEST_PIX_FMT_RETURN(BGR444BE);
|
118 |
+
TEST_PIX_FMT_RETURN(BGR444LE);
|
119 |
+
TEST_PIX_FMT_RETURN(Y400A );
|
120 |
+
TEST_PIX_FMT_RETURN(NB );
|
121 |
+
default: return "";
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
#undef TEST_PIX_FMT_RETURN
|
126 |
+
|
127 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_convert.h
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/video/drivers/ffmpeg_common.h>
|
32 |
+
|
33 |
+
namespace pangolin {
|
34 |
+
|
35 |
+
enum FfmpegMethod
|
36 |
+
{
|
37 |
+
FFMPEG_FAST_BILINEAR = 1,
|
38 |
+
FFMPEG_BILINEAR = 2,
|
39 |
+
FFMPEG_BICUBIC = 4,
|
40 |
+
FFMPEG_X = 8,
|
41 |
+
FFMPEG_POINT = 0x10,
|
42 |
+
FFMPEG_AREA = 0x20,
|
43 |
+
FFMPEG_BICUBLIN = 0x40,
|
44 |
+
FFMPEG_GAUSS = 0x80,
|
45 |
+
FFMPEG_SINC =0x100,
|
46 |
+
FFMPEG_LANCZOS =0x200,
|
47 |
+
FFMPEG_SPLINE =0x400
|
48 |
+
};
|
49 |
+
|
50 |
+
class PANGOLIN_EXPORT FfmpegConverter : public VideoInterface
|
51 |
+
{
|
52 |
+
public:
|
53 |
+
FfmpegConverter(std::unique_ptr<VideoInterface>& videoin, const std::string pixelfmtout = "RGB24", FfmpegMethod method = FFMPEG_POINT);
|
54 |
+
~FfmpegConverter();
|
55 |
+
|
56 |
+
//! Implement VideoInput::Start()
|
57 |
+
void Start();
|
58 |
+
|
59 |
+
//! Implement VideoInput::Stop()
|
60 |
+
void Stop();
|
61 |
+
|
62 |
+
//! Implement VideoInput::SizeBytes()
|
63 |
+
size_t SizeBytes() const;
|
64 |
+
|
65 |
+
//! Implement VideoInput::Streams()
|
66 |
+
const std::vector<StreamInfo>& Streams() const;
|
67 |
+
|
68 |
+
//! Implement VideoInput::GrabNext()
|
69 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
70 |
+
|
71 |
+
//! Implement VideoInput::GrabNewest()
|
72 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
73 |
+
|
74 |
+
protected:
|
75 |
+
std::vector<StreamInfo> streams;
|
76 |
+
|
77 |
+
struct ConvertContext
|
78 |
+
{
|
79 |
+
SwsContext* img_convert_ctx;
|
80 |
+
AVPixelFormat fmtsrc;
|
81 |
+
AVPixelFormat fmtdst;
|
82 |
+
AVFrame* avsrc;
|
83 |
+
AVFrame* avdst;
|
84 |
+
size_t w,h;
|
85 |
+
size_t src_buffer_offset;
|
86 |
+
size_t dst_buffer_offset;
|
87 |
+
|
88 |
+
void convert(const unsigned char * src, unsigned char* dst);
|
89 |
+
|
90 |
+
};
|
91 |
+
|
92 |
+
std::unique_ptr<VideoInterface> videoin;
|
93 |
+
std::unique_ptr<unsigned char[]> input_buffer;
|
94 |
+
|
95 |
+
std::vector<ConvertContext> converters;
|
96 |
+
//size_t src_buffer_size;
|
97 |
+
size_t dst_buffer_size;
|
98 |
+
};
|
99 |
+
|
100 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/ffmpeg_output.h
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_output_interface.h>
|
31 |
+
#include <pangolin/video/drivers/ffmpeg_common.h>
|
32 |
+
|
33 |
+
namespace pangolin
|
34 |
+
{
|
35 |
+
|
36 |
+
#if (LIBAVFORMAT_VERSION_MAJOR > 55) || ((LIBAVFORMAT_VERSION_MAJOR == 55) && (LIBAVFORMAT_VERSION_MINOR >= 7))
|
37 |
+
typedef AVCodecID CodecID;
|
38 |
+
#endif
|
39 |
+
|
40 |
+
// Forward declaration
|
41 |
+
class FfmpegVideoOutputStream;
|
42 |
+
|
43 |
+
class PANGOLIN_EXPORT FfmpegVideoOutput
|
44 |
+
: public VideoOutputInterface
|
45 |
+
{
|
46 |
+
friend class FfmpegVideoOutputStream;
|
47 |
+
public:
|
48 |
+
FfmpegVideoOutput( const std::string& filename, int base_frame_rate, int bit_rate, bool flip = false);
|
49 |
+
~FfmpegVideoOutput();
|
50 |
+
|
51 |
+
const std::vector<StreamInfo>& Streams() const override;
|
52 |
+
|
53 |
+
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& properties) override;
|
54 |
+
|
55 |
+
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
|
56 |
+
|
57 |
+
bool IsPipe() const override;
|
58 |
+
|
59 |
+
protected:
|
60 |
+
void Initialise(std::string filename);
|
61 |
+
void StartStream();
|
62 |
+
void Close();
|
63 |
+
|
64 |
+
std::string filename;
|
65 |
+
bool started;
|
66 |
+
AVFormatContext *oc;
|
67 |
+
std::vector<FfmpegVideoOutputStream*> streams;
|
68 |
+
std::vector<StreamInfo> strs;
|
69 |
+
|
70 |
+
int frame_count;
|
71 |
+
|
72 |
+
int base_frame_rate;
|
73 |
+
int bit_rate;
|
74 |
+
bool is_pipe;
|
75 |
+
bool flip;
|
76 |
+
};
|
77 |
+
|
78 |
+
class FfmpegVideoOutputStream
|
79 |
+
{
|
80 |
+
public:
|
81 |
+
FfmpegVideoOutputStream(FfmpegVideoOutput& recorder, CodecID codec_id, uint64_t frame_rate, int bit_rate, const StreamInfo& input_info, bool flip );
|
82 |
+
~FfmpegVideoOutputStream();
|
83 |
+
|
84 |
+
const StreamInfo& GetStreamInfo() const;
|
85 |
+
|
86 |
+
void WriteImage(const uint8_t* img, int w, int h);
|
87 |
+
void Flush();
|
88 |
+
|
89 |
+
protected:
|
90 |
+
void WriteAvPacket(AVPacket* pkt);
|
91 |
+
void WriteFrame(AVFrame* frame);
|
92 |
+
double BaseFrameTime();
|
93 |
+
|
94 |
+
FfmpegVideoOutput& recorder;
|
95 |
+
|
96 |
+
StreamInfo input_info;
|
97 |
+
AVPixelFormat input_format;
|
98 |
+
AVPixelFormat output_format;
|
99 |
+
int64_t last_pts;
|
100 |
+
|
101 |
+
// These pointers are owned by class
|
102 |
+
AVStream* stream;
|
103 |
+
SwsContext *sws_ctx;
|
104 |
+
AVFrame* src_frame;
|
105 |
+
AVFrame* frame;
|
106 |
+
AVCodecContext* codec_context;
|
107 |
+
|
108 |
+
bool flip;
|
109 |
+
};
|
110 |
+
|
111 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/firewire.h
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2011 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
|
32 |
+
#include <dc1394/dc1394.h>
|
33 |
+
|
34 |
+
#ifndef _WIN32
|
35 |
+
#include <unistd.h>
|
36 |
+
#endif
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
namespace pangolin
|
41 |
+
{
|
42 |
+
|
43 |
+
PANGOLIN_EXPORT
|
44 |
+
std::string Dc1394ColorCodingToString(dc1394color_coding_t coding);
|
45 |
+
|
46 |
+
PANGOLIN_EXPORT
|
47 |
+
dc1394color_coding_t Dc1394ColorCodingFromString(std::string coding);
|
48 |
+
|
49 |
+
PANGOLIN_EXPORT
|
50 |
+
void Dc1394ModeDetails(dc1394video_mode_t mode, unsigned& w, unsigned& h, std::string& format );
|
51 |
+
|
52 |
+
class PANGOLIN_EXPORT FirewireFrame
|
53 |
+
{
|
54 |
+
friend class FirewireVideo;
|
55 |
+
public:
|
56 |
+
bool isValid() { return frame; }
|
57 |
+
unsigned char* Image() { return frame ? frame->image : 0; }
|
58 |
+
unsigned Width() const { return frame ? frame->size[0] : 0; }
|
59 |
+
unsigned Height() const { return frame ? frame->size[1] : 0; }
|
60 |
+
unsigned ImageBytes() const { return frame ? frame->image_bytes : 0; }
|
61 |
+
int FramesBehind() const { return frame ? frame->frames_behind : -1; }
|
62 |
+
unsigned Timestamp() const { return frame ? frame->timestamp : 0; }
|
63 |
+
int Id() const { return frame ? frame->id : -1; }
|
64 |
+
protected:
|
65 |
+
FirewireFrame(dc1394video_frame_t* frame) : frame(frame) {}
|
66 |
+
dc1394video_frame_t *frame;
|
67 |
+
};
|
68 |
+
|
69 |
+
struct PANGOLIN_EXPORT Guid
|
70 |
+
{
|
71 |
+
Guid(uint64_t guid):guid(guid){}
|
72 |
+
uint64_t guid;
|
73 |
+
};
|
74 |
+
|
75 |
+
class PANGOLIN_EXPORT FirewireVideo : public VideoInterface
|
76 |
+
{
|
77 |
+
public:
|
78 |
+
const static int MAX_FR = -1;
|
79 |
+
const static int EXT_TRIG = -1;
|
80 |
+
const static uint32_t GPIO_CTRL_PIN0 = 0x1110;
|
81 |
+
const static uint32_t GPIO_CTRL_PIN1 = 0x1120;
|
82 |
+
const static uint32_t GPIO_CTRL_PIN2 = 0x1130;
|
83 |
+
const static uint32_t GPIO_CTRL_PIN3 = 0x1140;
|
84 |
+
|
85 |
+
FirewireVideo(
|
86 |
+
unsigned deviceid = 0,
|
87 |
+
dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
|
88 |
+
dc1394framerate_t framerate = DC1394_FRAMERATE_30,
|
89 |
+
dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
|
90 |
+
int dma_buffers = 10
|
91 |
+
);
|
92 |
+
|
93 |
+
FirewireVideo(
|
94 |
+
Guid guid,
|
95 |
+
dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
|
96 |
+
dc1394framerate_t framerate = DC1394_FRAMERATE_30,
|
97 |
+
dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
|
98 |
+
int dma_buffers = 10
|
99 |
+
);
|
100 |
+
|
101 |
+
FirewireVideo(
|
102 |
+
Guid guid,
|
103 |
+
dc1394video_mode_t video_mode,
|
104 |
+
float framerate,
|
105 |
+
uint32_t width, uint32_t height,
|
106 |
+
uint32_t left, uint32_t top,
|
107 |
+
dc1394speed_t iso_speed,
|
108 |
+
int dma_buffers, bool reset_at_boot=false
|
109 |
+
);
|
110 |
+
|
111 |
+
FirewireVideo(
|
112 |
+
unsigned deviceid,
|
113 |
+
dc1394video_mode_t video_mode,
|
114 |
+
float framerate,
|
115 |
+
uint32_t width, uint32_t height,
|
116 |
+
uint32_t left, uint32_t top,
|
117 |
+
dc1394speed_t iso_speed,
|
118 |
+
int dma_buffers, bool reset_at_boot=false
|
119 |
+
);
|
120 |
+
|
121 |
+
~FirewireVideo();
|
122 |
+
|
123 |
+
//! Implement VideoInput::Start()
|
124 |
+
void Start();
|
125 |
+
|
126 |
+
//! Implement VideoInput::Stop()
|
127 |
+
void Stop();
|
128 |
+
|
129 |
+
//! Implement VideoInput::SizeBytes()
|
130 |
+
size_t SizeBytes() const;
|
131 |
+
|
132 |
+
//! Implement VideoInput::Streams()
|
133 |
+
const std::vector<StreamInfo>& Streams() const;
|
134 |
+
|
135 |
+
//! Implement VideoInput::GrabNext()
|
136 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
137 |
+
|
138 |
+
//! Implement VideoInput::GrabNewest()
|
139 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
140 |
+
|
141 |
+
//! (deprecated: use Streams[i].Width())
|
142 |
+
//! Return image width
|
143 |
+
unsigned Width() const { return width; }
|
144 |
+
|
145 |
+
//! (deprecated: use Streams[i].Height())
|
146 |
+
//! Return image height
|
147 |
+
unsigned Height() const { return height; }
|
148 |
+
|
149 |
+
//! Return object containing reference to image data within
|
150 |
+
//! DMA buffer. The FirewireFrame must be returned to
|
151 |
+
//! signal that it can be reused with a corresponding PutFrame()
|
152 |
+
FirewireFrame GetNext(bool wait = true);
|
153 |
+
|
154 |
+
//! Return object containing reference to newest image data within
|
155 |
+
//! DMA buffer discarding old images. The FirewireFrame must be
|
156 |
+
//! returned to signal that it can be reused with a corresponding PutFrame()
|
157 |
+
FirewireFrame GetNewest(bool wait = true);
|
158 |
+
|
159 |
+
//! Return FirewireFrame object. Data held by FirewireFrame is
|
160 |
+
//! invalidated on return.
|
161 |
+
void PutFrame(FirewireFrame& frame);
|
162 |
+
|
163 |
+
//! return absolute shutter value
|
164 |
+
float GetShutterTime() const;
|
165 |
+
|
166 |
+
//! set absolute shutter value
|
167 |
+
void SetShutterTime(float val);
|
168 |
+
|
169 |
+
//! set auto shutter value
|
170 |
+
void SetAutoShutterTime();
|
171 |
+
|
172 |
+
//! return absolute gain value
|
173 |
+
float GetGain() const;
|
174 |
+
|
175 |
+
//! set absolute gain value
|
176 |
+
void SetGain(float val);
|
177 |
+
|
178 |
+
//! set auto gain value
|
179 |
+
void SetAutoGain();
|
180 |
+
|
181 |
+
//! return absolute brightness value
|
182 |
+
float GetBrightness() const;
|
183 |
+
|
184 |
+
//! set absolute brightness value
|
185 |
+
void SetBrightness(float val);
|
186 |
+
|
187 |
+
//! set auto brightness
|
188 |
+
void SetAutoBrightness();
|
189 |
+
|
190 |
+
//! return absolute gamma value
|
191 |
+
float GetGamma() const;
|
192 |
+
|
193 |
+
//! return quantised shutter value
|
194 |
+
void SetShutterTimeQuant(int shutter);
|
195 |
+
|
196 |
+
//! set the trigger to internal, i.e. determined by video mode
|
197 |
+
void SetInternalTrigger();
|
198 |
+
|
199 |
+
//! set the trigger to external
|
200 |
+
void SetExternalTrigger(
|
201 |
+
dc1394trigger_mode_t mode=DC1394_TRIGGER_MODE_0,
|
202 |
+
dc1394trigger_polarity_t polarity=DC1394_TRIGGER_ACTIVE_HIGH,
|
203 |
+
dc1394trigger_source_t source=DC1394_TRIGGER_SOURCE_0
|
204 |
+
);
|
205 |
+
|
206 |
+
//! set a camera register
|
207 |
+
void SetRegister(uint64_t offset, uint32_t value);
|
208 |
+
|
209 |
+
//! read camera register
|
210 |
+
uint32_t GetRegister(uint64_t offset);
|
211 |
+
|
212 |
+
//! set a camera control register
|
213 |
+
void SetControlRegister(uint64_t offset, uint32_t value);
|
214 |
+
|
215 |
+
//! read camera control register
|
216 |
+
uint32_t GetControlRegister(uint64_t offset);
|
217 |
+
|
218 |
+
protected:
|
219 |
+
void init_stream_info();
|
220 |
+
|
221 |
+
void init_camera(
|
222 |
+
uint64_t guid, int dma_frames,
|
223 |
+
dc1394speed_t iso_speed,
|
224 |
+
dc1394video_mode_t video_mode,
|
225 |
+
dc1394framerate_t framerate
|
226 |
+
);
|
227 |
+
|
228 |
+
void init_format7_camera(
|
229 |
+
uint64_t guid, int dma_frames,
|
230 |
+
dc1394speed_t iso_speed,
|
231 |
+
dc1394video_mode_t video_mode,
|
232 |
+
float framerate,
|
233 |
+
uint32_t width, uint32_t height,
|
234 |
+
uint32_t left, uint32_t top, bool reset_at_boot
|
235 |
+
);
|
236 |
+
|
237 |
+
static int nearest_value(int value, int step, int min, int max);
|
238 |
+
static double bus_period_from_iso_speed(dc1394speed_t iso_speed);
|
239 |
+
|
240 |
+
size_t frame_size_bytes;
|
241 |
+
std::vector<StreamInfo> streams;
|
242 |
+
|
243 |
+
bool running;
|
244 |
+
dc1394camera_t *camera;
|
245 |
+
unsigned width, height, top, left;
|
246 |
+
//dc1394featureset_t features;
|
247 |
+
dc1394_t * d;
|
248 |
+
dc1394camera_list_t * list;
|
249 |
+
mutable dc1394error_t err;
|
250 |
+
|
251 |
+
};
|
252 |
+
|
253 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/gamma.h
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/pangolin.h>
|
31 |
+
#include <pangolin/video/video.h>
|
32 |
+
#include <set>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
// Video class that applies gamma to its video input
|
38 |
+
class PANGOLIN_EXPORT GammaVideo :
|
39 |
+
public VideoInterface,
|
40 |
+
public VideoFilterInterface,
|
41 |
+
public BufferAwareVideoInterface
|
42 |
+
{
|
43 |
+
public:
|
44 |
+
GammaVideo(std::unique_ptr<VideoInterface>& videoin, const std::map<size_t, float> &stream_gammas);
|
45 |
+
~GammaVideo();
|
46 |
+
|
47 |
+
//! Implement VideoInput::Start()
|
48 |
+
void Start();
|
49 |
+
|
50 |
+
//! Implement VideoInput::Stop()
|
51 |
+
void Stop();
|
52 |
+
|
53 |
+
//! Implement VideoInput::SizeBytes()
|
54 |
+
size_t SizeBytes() const;
|
55 |
+
|
56 |
+
//! Implement VideoInput::Streams()
|
57 |
+
const std::vector<StreamInfo>& Streams() const;
|
58 |
+
|
59 |
+
//! Implement VideoInput::GrabNext()
|
60 |
+
bool GrabNext( uint8_t* image, bool wait = true );
|
61 |
+
|
62 |
+
//! Implement VideoInput::GrabNewest()
|
63 |
+
bool GrabNewest( uint8_t* image, bool wait = true );
|
64 |
+
|
65 |
+
//! Implement VideoFilterInterface method
|
66 |
+
std::vector<VideoInterface*>& InputStreams();
|
67 |
+
|
68 |
+
uint32_t AvailableFrames() const;
|
69 |
+
|
70 |
+
bool DropNFrames(uint32_t n);
|
71 |
+
|
72 |
+
protected:
|
73 |
+
void Process(uint8_t* image, const uint8_t* buffer);
|
74 |
+
|
75 |
+
std::unique_ptr<VideoInterface> src;
|
76 |
+
std::vector<VideoInterface*> videoin;
|
77 |
+
|
78 |
+
std::vector<StreamInfo> streams;
|
79 |
+
size_t size_bytes;
|
80 |
+
std::unique_ptr<uint8_t[]> buffer;
|
81 |
+
const std::map<size_t, float> stream_gammas;
|
82 |
+
std::set<std::string> formats_supported;
|
83 |
+
};
|
84 |
+
|
85 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/images.h
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2013 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/image/image_io.h>
|
32 |
+
|
33 |
+
#include <deque>
|
34 |
+
#include <vector>
|
35 |
+
|
36 |
+
namespace pangolin
|
37 |
+
{
|
38 |
+
|
39 |
+
// Video class that outputs test video signal.
|
40 |
+
class PANGOLIN_EXPORT ImagesVideo : public VideoInterface, public VideoPlaybackInterface, public VideoPropertiesInterface
|
41 |
+
{
|
42 |
+
public:
|
43 |
+
ImagesVideo(const std::string& wildcard_path);
|
44 |
+
ImagesVideo(const std::string& wildcard_path, const PixelFormat& raw_fmt, size_t raw_width, size_t raw_height, size_t raw_pitch);
|
45 |
+
|
46 |
+
// Explicitly delete copy ctor and assignment operator.
|
47 |
+
// See http://stackoverflow.com/questions/29565299/how-to-use-a-vector-of-unique-pointers-in-a-dll-exported-class-with-visual-studi
|
48 |
+
// >> It appears adding __declspec(dllexport) forces the compiler to define the implicitly-declared copy constructor and copy assignment operator
|
49 |
+
ImagesVideo(const ImagesVideo&) = delete;
|
50 |
+
ImagesVideo& operator=(const ImagesVideo&) = delete;
|
51 |
+
|
52 |
+
~ImagesVideo();
|
53 |
+
|
54 |
+
///////////////////////////////////
|
55 |
+
// Implement VideoInterface
|
56 |
+
|
57 |
+
void Start() override;
|
58 |
+
|
59 |
+
void Stop() override;
|
60 |
+
|
61 |
+
size_t SizeBytes() const override;
|
62 |
+
|
63 |
+
const std::vector<StreamInfo>& Streams() const override;
|
64 |
+
|
65 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
66 |
+
|
67 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
68 |
+
|
69 |
+
///////////////////////////////////
|
70 |
+
// Implement VideoPlaybackInterface
|
71 |
+
|
72 |
+
size_t GetCurrentFrameId() const override;
|
73 |
+
|
74 |
+
size_t GetTotalFrames() const override;
|
75 |
+
|
76 |
+
size_t Seek(size_t frameid) override;
|
77 |
+
|
78 |
+
///////////////////////////////////
|
79 |
+
// Implement VideoPropertiesInterface
|
80 |
+
|
81 |
+
const picojson::value& DeviceProperties() const override;
|
82 |
+
|
83 |
+
const picojson::value& FrameProperties() const override;
|
84 |
+
|
85 |
+
protected:
|
86 |
+
typedef std::vector<TypedImage> Frame;
|
87 |
+
|
88 |
+
const std::string& Filename(size_t frameNum, size_t channelNum) {
|
89 |
+
return filenames[channelNum][frameNum];
|
90 |
+
}
|
91 |
+
|
92 |
+
void PopulateFilenames(const std::string& wildcard_path);
|
93 |
+
|
94 |
+
void PopulateFilenamesFromJson(const std::string& filename);
|
95 |
+
|
96 |
+
bool LoadFrame(size_t i);
|
97 |
+
|
98 |
+
void ConfigureStreamSizes();
|
99 |
+
|
100 |
+
std::vector<StreamInfo> streams;
|
101 |
+
size_t size_bytes;
|
102 |
+
|
103 |
+
size_t num_files;
|
104 |
+
size_t num_channels;
|
105 |
+
size_t next_frame_id;
|
106 |
+
std::vector<std::vector<std::string> > filenames;
|
107 |
+
std::vector<Frame> loaded;
|
108 |
+
|
109 |
+
bool unknowns_are_raw;
|
110 |
+
PixelFormat raw_fmt;
|
111 |
+
size_t raw_width;
|
112 |
+
size_t raw_height;
|
113 |
+
size_t raw_pitch;
|
114 |
+
|
115 |
+
// Load any json properties if they are defined
|
116 |
+
picojson::value device_properties;
|
117 |
+
picojson::value json_frames;
|
118 |
+
picojson::value null_props;
|
119 |
+
};
|
120 |
+
|
121 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/images_out.h
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <fstream>
|
31 |
+
#include <pangolin/video/video_output_interface.h>
|
32 |
+
#include <pangolin/log/packetstream_writer.h>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
class PANGOLIN_EXPORT ImagesVideoOutput : public VideoOutputInterface
|
38 |
+
{
|
39 |
+
public:
|
40 |
+
ImagesVideoOutput(const std::string& image_folder, const std::string& json_file_out, const std::string &image_file_extension);
|
41 |
+
~ImagesVideoOutput();
|
42 |
+
|
43 |
+
const std::vector<StreamInfo>& Streams() const override;
|
44 |
+
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& device_properties) override;
|
45 |
+
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
|
46 |
+
bool IsPipe() const override;
|
47 |
+
|
48 |
+
protected:
|
49 |
+
std::vector<StreamInfo> streams;
|
50 |
+
std::string input_uri;
|
51 |
+
picojson::value device_properties;
|
52 |
+
picojson::value json_frames;
|
53 |
+
|
54 |
+
size_t image_index;
|
55 |
+
std::string image_folder;
|
56 |
+
std::string image_file_extension;
|
57 |
+
std::ofstream file;
|
58 |
+
};
|
59 |
+
|
60 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/join.h
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
|
32 |
+
namespace pangolin
|
33 |
+
{
|
34 |
+
|
35 |
+
class PANGOLIN_EXPORT JoinVideo
|
36 |
+
: public VideoInterface, public VideoFilterInterface
|
37 |
+
{
|
38 |
+
public:
|
39 |
+
JoinVideo(std::vector<std::unique_ptr<VideoInterface>> &src, const bool verbose);
|
40 |
+
|
41 |
+
~JoinVideo();
|
42 |
+
|
43 |
+
// Explicitly delete copy ctor and assignment operator.
|
44 |
+
// See http://stackoverflow.com/questions/29565299/how-to-use-a-vector-of-unique-pointers-in-a-dll-exported-class-with-visual-studi
|
45 |
+
// >> It appears adding __declspec(dllexport) forces the compiler to define the implicitly-declared copy constructor and copy assignment operator
|
46 |
+
JoinVideo(const JoinVideo&) = delete;
|
47 |
+
JoinVideo& operator=(const JoinVideo&) = delete;
|
48 |
+
|
49 |
+
size_t SizeBytes() const;
|
50 |
+
|
51 |
+
const std::vector<StreamInfo>& Streams() const;
|
52 |
+
|
53 |
+
void Start();
|
54 |
+
|
55 |
+
void Stop();
|
56 |
+
|
57 |
+
bool Sync(int64_t tolerance_us, double transfer_bandwidth_gbps = 0);
|
58 |
+
|
59 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
60 |
+
|
61 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
62 |
+
|
63 |
+
std::vector<VideoInterface*>& InputStreams();
|
64 |
+
|
65 |
+
protected:
|
66 |
+
int64_t GetAdjustedCaptureTime(size_t src_index);
|
67 |
+
|
68 |
+
std::vector<std::unique_ptr<VideoInterface>> storage;
|
69 |
+
std::vector<VideoInterface*> src;
|
70 |
+
std::vector<bool> frame_seen;
|
71 |
+
std::vector<StreamInfo> streams;
|
72 |
+
size_t size_bytes;
|
73 |
+
|
74 |
+
int64_t sync_tolerance_us;
|
75 |
+
int64_t transfer_bandwidth_bytes_per_us;
|
76 |
+
bool verbose;
|
77 |
+
};
|
78 |
+
|
79 |
+
|
80 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/merge.h
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2013 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/video/iostream_operators.h>
|
32 |
+
|
33 |
+
namespace pangolin
|
34 |
+
{
|
35 |
+
|
36 |
+
// Take N streams, and place them into one big buffer.
|
37 |
+
class PANGOLIN_EXPORT MergeVideo : public VideoInterface, public VideoFilterInterface
|
38 |
+
{
|
39 |
+
public:
|
40 |
+
MergeVideo(std::unique_ptr<VideoInterface>& src, const std::vector<Point>& stream_pos, size_t w, size_t h);
|
41 |
+
~MergeVideo();
|
42 |
+
|
43 |
+
void Start() override;
|
44 |
+
|
45 |
+
void Stop() override;
|
46 |
+
|
47 |
+
size_t SizeBytes() const override;
|
48 |
+
|
49 |
+
const std::vector<StreamInfo>& Streams() const override;
|
50 |
+
|
51 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
52 |
+
|
53 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
54 |
+
|
55 |
+
std::vector<VideoInterface*>& InputStreams() override;
|
56 |
+
|
57 |
+
protected:
|
58 |
+
void CopyBuffer(unsigned char* dst_bytes, unsigned char* src_bytes);
|
59 |
+
|
60 |
+
std::unique_ptr<VideoInterface> src;
|
61 |
+
std::vector<VideoInterface*> videoin;
|
62 |
+
std::unique_ptr<uint8_t[]> buffer;
|
63 |
+
std::vector<Point> stream_pos;
|
64 |
+
|
65 |
+
std::vector<StreamInfo> streams;
|
66 |
+
size_t size_bytes;
|
67 |
+
};
|
68 |
+
|
69 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/mjpeg.h
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2013 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/image/typed_image.h>
|
32 |
+
#include <fstream>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
// Video class that outputs test video signal.
|
38 |
+
class PANGOLIN_EXPORT MjpegVideo : public VideoInterface, public VideoPlaybackInterface
|
39 |
+
{
|
40 |
+
public:
|
41 |
+
MjpegVideo(const std::string& filename);
|
42 |
+
~MjpegVideo();
|
43 |
+
|
44 |
+
//! Implement VideoInput::Start()
|
45 |
+
void Start() override;
|
46 |
+
|
47 |
+
//! Implement VideoInput::Stop()
|
48 |
+
void Stop() override;
|
49 |
+
|
50 |
+
//! Implement VideoInput::SizeBytes()
|
51 |
+
size_t SizeBytes() const override;
|
52 |
+
|
53 |
+
//! Implement VideoInput::Streams()
|
54 |
+
const std::vector<StreamInfo>& Streams() const override;
|
55 |
+
|
56 |
+
//! Implement VideoInput::GrabNext()
|
57 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
58 |
+
|
59 |
+
//! Implement VideoInput::GrabNewest()
|
60 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
61 |
+
|
62 |
+
size_t GetCurrentFrameId() const override;
|
63 |
+
size_t GetTotalFrames() const override;
|
64 |
+
size_t Seek(size_t frameid) override;
|
65 |
+
|
66 |
+
protected:
|
67 |
+
bool LoadNext();
|
68 |
+
|
69 |
+
std::vector<StreamInfo> streams;
|
70 |
+
size_t size_bytes;
|
71 |
+
std::ifstream bFile;
|
72 |
+
TypedImage next_image;
|
73 |
+
std::vector<std::streampos> offsets;
|
74 |
+
size_t next_frame_id;
|
75 |
+
};
|
76 |
+
|
77 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni.h
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/video/video_interface.h>
|
4 |
+
#include <pangolin/video/drivers/openni_common.h>
|
5 |
+
|
6 |
+
// Workaround poor OpenNI Platform test on Linux before including XnCppWrapper.h
|
7 |
+
// See https://github.com/dennishamester/OpenNI/commit/ca99f6181234c682bba42a6ba
|
8 |
+
#ifdef _LINUX_
|
9 |
+
#define linux 1
|
10 |
+
#endif // _LINUX_
|
11 |
+
|
12 |
+
// OpenNI generates SO MANY warnings, we'll just disable all for this header(!)
|
13 |
+
// GCC and clang will listen to this pramga.
|
14 |
+
#ifdef __GNUC__
|
15 |
+
#pragma GCC system_header
|
16 |
+
#endif
|
17 |
+
#include <XnCppWrapper.h>
|
18 |
+
|
19 |
+
namespace pangolin
|
20 |
+
{
|
21 |
+
|
22 |
+
//! Interface to video capture sources
|
23 |
+
struct PANGOLIN_EXPORT OpenNiVideo : public VideoInterface
|
24 |
+
{
|
25 |
+
public:
|
26 |
+
OpenNiVideo(OpenNiSensorType s1, OpenNiSensorType s2, ImageDim dim = ImageDim(640,480), int fps = 30);
|
27 |
+
~OpenNiVideo();
|
28 |
+
|
29 |
+
//! Implement VideoInput::Start()
|
30 |
+
void Start();
|
31 |
+
|
32 |
+
//! Implement VideoInput::Stop()
|
33 |
+
void Stop();
|
34 |
+
|
35 |
+
//! Implement VideoInput::SizeBytes()
|
36 |
+
size_t SizeBytes() const;
|
37 |
+
|
38 |
+
//! Implement VideoInput::Streams()
|
39 |
+
const std::vector<StreamInfo>& Streams() const;
|
40 |
+
|
41 |
+
//! Implement VideoInput::GrabNext()
|
42 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
43 |
+
|
44 |
+
//! Implement VideoInput::GrabNewest()
|
45 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
46 |
+
|
47 |
+
void SetAutoExposure(bool enabled)
|
48 |
+
{
|
49 |
+
#if XN_MINOR_VERSION > 5 || (XN_MINOR_VERSION == 5 && XN_BUILD_VERSION >= 7)
|
50 |
+
if(imageNode.IsValid()) {
|
51 |
+
imageNode.GetAutoExposureCap().Set(enabled ? 1 : 0);
|
52 |
+
}
|
53 |
+
#else
|
54 |
+
throw pangolin::VideoException("SetAutoExposure Not supported for this version of OpenNI.");
|
55 |
+
#endif
|
56 |
+
}
|
57 |
+
|
58 |
+
protected:
|
59 |
+
std::vector<StreamInfo> streams;
|
60 |
+
OpenNiSensorType sensor_type[2];
|
61 |
+
|
62 |
+
xn::Context context;
|
63 |
+
xn::DepthGenerator depthNode;
|
64 |
+
xn::ImageGenerator imageNode;
|
65 |
+
xn::IRGenerator irNode;
|
66 |
+
|
67 |
+
size_t sizeBytes;
|
68 |
+
};
|
69 |
+
|
70 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni2.h
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Richard Newcombe
|
5 |
+
* 2014 Steven Lovegrove
|
6 |
+
*
|
7 |
+
* Permission is hereby granted, free of charge, to any person
|
8 |
+
* obtaining a copy of this software and associated documentation
|
9 |
+
* files (the "Software"), to deal in the Software without
|
10 |
+
* restriction, including without limitation the rights to use,
|
11 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 |
+
* copies of the Software, and to permit persons to whom the
|
13 |
+
* Software is furnished to do so, subject to the following
|
14 |
+
* conditions:
|
15 |
+
*
|
16 |
+
* The above copyright notice and this permission notice shall be
|
17 |
+
* included in all copies or substantial portions of the Software.
|
18 |
+
*
|
19 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
21 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
23 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
25 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
26 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
27 |
+
*/
|
28 |
+
|
29 |
+
#pragma once
|
30 |
+
|
31 |
+
#include <pangolin/video/video_interface.h>
|
32 |
+
#include <pangolin/video/drivers/openni_common.h>
|
33 |
+
|
34 |
+
#include <OpenNI.h>
|
35 |
+
|
36 |
+
namespace pangolin
|
37 |
+
{
|
38 |
+
const int MAX_OPENNI2_STREAMS = 2 * ONI_MAX_SENSORS;
|
39 |
+
|
40 |
+
//! Interface to video capture sources
|
41 |
+
struct OpenNi2Video : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
|
42 |
+
{
|
43 |
+
public:
|
44 |
+
|
45 |
+
// Open all RGB and Depth streams from all devices
|
46 |
+
OpenNi2Video(ImageDim dim=ImageDim(640,480), ImageRoi roi=ImageRoi(0,0,0,0), int fps=30);
|
47 |
+
|
48 |
+
// Open streams specified
|
49 |
+
OpenNi2Video(std::vector<OpenNiStreamMode>& stream_modes);
|
50 |
+
|
51 |
+
// Open openni file
|
52 |
+
OpenNi2Video(const std::string& filename);
|
53 |
+
|
54 |
+
// Open openni file with certain params
|
55 |
+
OpenNi2Video(const std::string& filename, std::vector<OpenNiStreamMode>& stream_modes);
|
56 |
+
|
57 |
+
void UpdateProperties();
|
58 |
+
|
59 |
+
void SetMirroring(bool enable);
|
60 |
+
void SetAutoExposure(bool enable);
|
61 |
+
void SetAutoWhiteBalance(bool enable);
|
62 |
+
void SetDepthCloseRange(bool enable);
|
63 |
+
void SetDepthHoleFilter(bool enable);
|
64 |
+
void SetDepthColorSyncEnabled(bool enable);
|
65 |
+
void SetFastCrop(bool enable);
|
66 |
+
void SetRegisterDepthToImage(bool enable);
|
67 |
+
void SetPlaybackSpeed(float speed);
|
68 |
+
void SetPlaybackRepeat(bool enabled);
|
69 |
+
|
70 |
+
~OpenNi2Video();
|
71 |
+
|
72 |
+
//! Implement VideoInput::Start()
|
73 |
+
void Start() override;
|
74 |
+
|
75 |
+
//! Implement VideoInput::Stop()
|
76 |
+
void Stop() override;
|
77 |
+
|
78 |
+
//! Implement VideoInput::SizeBytes()
|
79 |
+
size_t SizeBytes() const override;
|
80 |
+
|
81 |
+
//! Implement VideoInput::Streams()
|
82 |
+
const std::vector<StreamInfo>& Streams() const override;
|
83 |
+
|
84 |
+
//! Implement VideoInput::GrabNext()
|
85 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
86 |
+
|
87 |
+
//! Implement VideoInput::GrabNewest()
|
88 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
89 |
+
|
90 |
+
//! Implement VideoPropertiesInterface::Properties()
|
91 |
+
const picojson::value& DeviceProperties() const override{
|
92 |
+
return device_properties;
|
93 |
+
}
|
94 |
+
|
95 |
+
//! Implement VideoPropertiesInterface::Properties()
|
96 |
+
const picojson::value& FrameProperties() const override{
|
97 |
+
return frame_properties;
|
98 |
+
}
|
99 |
+
|
100 |
+
//! Implement VideoPlaybackInterface::GetCurrentFrameId
|
101 |
+
size_t GetCurrentFrameId() const override;
|
102 |
+
|
103 |
+
//! Implement VideoPlaybackInterface::GetTotalFrames
|
104 |
+
size_t GetTotalFrames() const override;
|
105 |
+
|
106 |
+
//! Implement VideoPlaybackInterface::Seek
|
107 |
+
size_t Seek(size_t frameid) override;
|
108 |
+
|
109 |
+
openni::VideoStream* GetVideoStream(int stream);
|
110 |
+
|
111 |
+
protected:
|
112 |
+
void InitialiseOpenNI();
|
113 |
+
int AddDevice(const std::string& device_uri);
|
114 |
+
void AddStream(const OpenNiStreamMode& mode);
|
115 |
+
void SetupStreamModes();
|
116 |
+
void PrintOpenNI2Modes(openni::SensorType sensorType);
|
117 |
+
openni::VideoMode FindOpenNI2Mode(openni::Device &device, openni::SensorType sensorType, int width, int height, int fps, openni::PixelFormat fmt );
|
118 |
+
|
119 |
+
size_t numDevices;
|
120 |
+
size_t numStreams;
|
121 |
+
|
122 |
+
openni::Device devices[ONI_MAX_SENSORS];
|
123 |
+
OpenNiStreamMode sensor_type[ONI_MAX_SENSORS];
|
124 |
+
|
125 |
+
openni::VideoStream video_stream[ONI_MAX_SENSORS];
|
126 |
+
openni::VideoFrameRef video_frame[ONI_MAX_SENSORS];
|
127 |
+
|
128 |
+
std::vector<StreamInfo> streams;
|
129 |
+
size_t sizeBytes;
|
130 |
+
|
131 |
+
picojson::value device_properties;
|
132 |
+
picojson::value frame_properties;
|
133 |
+
picojson::value* streams_properties;
|
134 |
+
|
135 |
+
bool use_depth;
|
136 |
+
bool use_ir;
|
137 |
+
bool use_rgb;
|
138 |
+
bool depth_to_color;
|
139 |
+
bool use_ir_and_rgb;
|
140 |
+
|
141 |
+
size_t current_frame_index;
|
142 |
+
size_t total_frames;
|
143 |
+
};
|
144 |
+
|
145 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/openni_common.h
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
* 2015 Richard Newcombe
|
6 |
+
*
|
7 |
+
* Permission is hereby granted, free of charge, to any person
|
8 |
+
* obtaining a copy of this software and associated documentation
|
9 |
+
* files (the "Software"), to deal in the Software without
|
10 |
+
* restriction, including without limitation the rights to use,
|
11 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 |
+
* copies of the Software, and to permit persons to whom the
|
13 |
+
* Software is furnished to do so, subject to the following
|
14 |
+
* conditions:
|
15 |
+
*
|
16 |
+
* The above copyright notice and this permission notice shall be
|
17 |
+
* included in all copies or substantial portions of the Software.
|
18 |
+
*
|
19 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
21 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
23 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
25 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
26 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
27 |
+
*/
|
28 |
+
|
29 |
+
#pragma once
|
30 |
+
|
31 |
+
#include <pangolin/video/iostream_operators.h>
|
32 |
+
#include <pangolin/utils/type_convert.h>
|
33 |
+
|
34 |
+
namespace pangolin
|
35 |
+
{
|
36 |
+
|
37 |
+
enum OpenNiSensorType
|
38 |
+
{
|
39 |
+
OpenNiUnassigned = -1,
|
40 |
+
OpenNiRgb = 0,
|
41 |
+
OpenNiIr,
|
42 |
+
OpenNiDepth_1mm,
|
43 |
+
OpenNiDepth_1mm_Registered,
|
44 |
+
OpenNiDepth_100um,
|
45 |
+
OpenNiIr8bit,
|
46 |
+
OpenNiIr24bit,
|
47 |
+
OpenNiIrProj,
|
48 |
+
OpenNiIr8bitProj,
|
49 |
+
OpenNiGrey
|
50 |
+
};
|
51 |
+
|
52 |
+
struct PANGOLIN_EXPORT OpenNiStreamMode
|
53 |
+
{
|
54 |
+
OpenNiStreamMode(
|
55 |
+
OpenNiSensorType sensor_type=OpenNiUnassigned,
|
56 |
+
ImageDim dim=ImageDim(640,480), ImageRoi roi=ImageRoi(0,0,0,0), int fps=30, int device=0
|
57 |
+
)
|
58 |
+
: sensor_type(sensor_type), dim(dim), roi(roi), fps(fps), device(device)
|
59 |
+
{
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
OpenNiSensorType sensor_type;
|
64 |
+
ImageDim dim;
|
65 |
+
ImageRoi roi;
|
66 |
+
int fps;
|
67 |
+
int device;
|
68 |
+
};
|
69 |
+
|
70 |
+
inline OpenNiSensorType openni_sensor(const std::string& str)
|
71 |
+
{
|
72 |
+
if( !str.compare("grey") || !str.compare("gray") ) {
|
73 |
+
return OpenNiGrey;
|
74 |
+
}else if( !str.compare("rgb") ) {
|
75 |
+
return OpenNiRgb;
|
76 |
+
}else if( !str.compare("ir") ) {
|
77 |
+
return OpenNiIr;
|
78 |
+
}else if( !str.compare("depth1mm") || !str.compare("depth") ) {
|
79 |
+
return OpenNiDepth_1mm;
|
80 |
+
}else if( !str.compare("depth100um") ) {
|
81 |
+
return OpenNiDepth_100um;
|
82 |
+
}else if( !str.compare("depth_reg") || !str.compare("reg_depth")) {
|
83 |
+
return OpenNiDepth_1mm_Registered;
|
84 |
+
}else if( !str.compare("ir8") ) {
|
85 |
+
return OpenNiIr8bit;
|
86 |
+
}else if( !str.compare("ir24") ) {
|
87 |
+
return OpenNiIr24bit;
|
88 |
+
}else if( !str.compare("ir+") ) {
|
89 |
+
return OpenNiIrProj;
|
90 |
+
}else if( !str.compare("ir8+") ) {
|
91 |
+
return OpenNiIr8bitProj;
|
92 |
+
}else if( str.empty() ) {
|
93 |
+
return OpenNiUnassigned;
|
94 |
+
}else{
|
95 |
+
throw pangolin::VideoException("Unknown OpenNi sensor", str );
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
// Find prefix character key
|
100 |
+
// Given arguments "depth!5:320x240@15", "!:@", would return map
|
101 |
+
// \0->"depth", !->"5", :->"320x240", @->"15"
|
102 |
+
inline std::map<char,std::string> GetTokenSplits(const std::string& str, const std::string& tokens)
|
103 |
+
{
|
104 |
+
std::map<char,std::string> splits;
|
105 |
+
|
106 |
+
char last_token = 0;
|
107 |
+
size_t last_start = 0;
|
108 |
+
for(unsigned int i=0; i<str.size(); ++i) {
|
109 |
+
size_t token_pos = tokens.find(str[i]);
|
110 |
+
if(token_pos != std::string::npos) {
|
111 |
+
splits[last_token] = str.substr(last_start, i-last_start);
|
112 |
+
last_token = tokens[token_pos];
|
113 |
+
last_start = i+1;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
if(last_start < str.size()) {
|
118 |
+
splits[last_token] = str.substr(last_start);
|
119 |
+
}
|
120 |
+
|
121 |
+
return splits;
|
122 |
+
}
|
123 |
+
|
124 |
+
inline std::istream& operator>> (std::istream &is, OpenNiStreamMode& fmt)
|
125 |
+
{
|
126 |
+
std::string str;
|
127 |
+
is >> str;
|
128 |
+
|
129 |
+
std::map<char,std::string> splits = GetTokenSplits(str, "!:@#");
|
130 |
+
|
131 |
+
if(splits.count(0)) {
|
132 |
+
fmt.sensor_type = openni_sensor(splits[0]);
|
133 |
+
}
|
134 |
+
|
135 |
+
if(splits.count('@')) {
|
136 |
+
fmt.fps = pangolin::Convert<int,std::string>::Do(splits['@']);
|
137 |
+
}
|
138 |
+
|
139 |
+
if(splits.count(':')) {
|
140 |
+
fmt.dim = pangolin::Convert<ImageDim,std::string>::Do(splits[':']);
|
141 |
+
}
|
142 |
+
|
143 |
+
if(splits.count('!')) {
|
144 |
+
fmt.device = pangolin::Convert<int,std::string>::Do(splits['!']);
|
145 |
+
}
|
146 |
+
|
147 |
+
if(splits.count('#')) {
|
148 |
+
fmt.roi = pangolin::Convert<ImageRoi,std::string>::Do(splits['#']);
|
149 |
+
}
|
150 |
+
|
151 |
+
return is;
|
152 |
+
}
|
153 |
+
|
154 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pack.h
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
|
32 |
+
namespace pangolin
|
33 |
+
{
|
34 |
+
|
35 |
+
// Video class that packs its video input using the given method.
|
36 |
+
class PANGOLIN_EXPORT PackVideo :
|
37 |
+
public VideoInterface,
|
38 |
+
public VideoFilterInterface,
|
39 |
+
public BufferAwareVideoInterface
|
40 |
+
{
|
41 |
+
public:
|
42 |
+
PackVideo(std::unique_ptr<VideoInterface>& videoin, PixelFormat new_fmt);
|
43 |
+
~PackVideo();
|
44 |
+
|
45 |
+
//! Implement VideoInput::Start()
|
46 |
+
void Start();
|
47 |
+
|
48 |
+
//! Implement VideoInput::Stop()
|
49 |
+
void Stop();
|
50 |
+
|
51 |
+
//! Implement VideoInput::SizeBytes()
|
52 |
+
size_t SizeBytes() const;
|
53 |
+
|
54 |
+
//! Implement VideoInput::Streams()
|
55 |
+
const std::vector<StreamInfo>& Streams() const;
|
56 |
+
|
57 |
+
//! Implement VideoInput::GrabNext()
|
58 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
59 |
+
|
60 |
+
//! Implement VideoInput::GrabNewest()
|
61 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
62 |
+
|
63 |
+
//! Implement VideoFilterInterface method
|
64 |
+
std::vector<VideoInterface*>& InputStreams();
|
65 |
+
|
66 |
+
uint32_t AvailableFrames() const;
|
67 |
+
|
68 |
+
bool DropNFrames(uint32_t n);
|
69 |
+
|
70 |
+
protected:
|
71 |
+
void Process(unsigned char* image, const unsigned char* buffer);
|
72 |
+
|
73 |
+
std::unique_ptr<VideoInterface> src;
|
74 |
+
std::vector<VideoInterface*> videoin;
|
75 |
+
std::vector<StreamInfo> streams;
|
76 |
+
size_t size_bytes;
|
77 |
+
unsigned char* buffer;
|
78 |
+
|
79 |
+
picojson::value device_properties;
|
80 |
+
picojson::value frame_properties;
|
81 |
+
};
|
82 |
+
|
83 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pango.h
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
#include <pangolin/video/stream_encoder_factory.h>
|
32 |
+
#include <pangolin/log/packetstream_reader.h>
|
33 |
+
#include <pangolin/log/playback_session.h>
|
34 |
+
#include <pangolin/utils/signal_slot.h>
|
35 |
+
|
36 |
+
namespace pangolin
|
37 |
+
{
|
38 |
+
|
39 |
+
class PANGOLIN_EXPORT PangoVideo
|
40 |
+
: public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
|
41 |
+
{
|
42 |
+
public:
|
43 |
+
PangoVideo(const std::string& filename, std::shared_ptr<PlaybackSession> playback_session);
|
44 |
+
~PangoVideo();
|
45 |
+
|
46 |
+
// Implement VideoInterface
|
47 |
+
|
48 |
+
size_t SizeBytes() const override;
|
49 |
+
|
50 |
+
const std::vector<StreamInfo>& Streams() const override;
|
51 |
+
|
52 |
+
void Start() override;
|
53 |
+
|
54 |
+
void Stop() override;
|
55 |
+
|
56 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
57 |
+
|
58 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
59 |
+
|
60 |
+
// Implement VideoPropertiesInterface
|
61 |
+
const picojson::value& DeviceProperties() const override {
|
62 |
+
if (-1 == _src_id) throw std::runtime_error("Not initialised");
|
63 |
+
return _device_properties;
|
64 |
+
}
|
65 |
+
|
66 |
+
const picojson::value& FrameProperties() const override {
|
67 |
+
return _frame_properties;
|
68 |
+
}
|
69 |
+
|
70 |
+
// Implement VideoPlaybackInterface
|
71 |
+
|
72 |
+
size_t GetCurrentFrameId() const override;
|
73 |
+
|
74 |
+
size_t GetTotalFrames() const override;
|
75 |
+
|
76 |
+
size_t Seek(size_t frameid) override;
|
77 |
+
|
78 |
+
std::string GetSourceUri();
|
79 |
+
|
80 |
+
private:
|
81 |
+
void HandlePipeClosed();
|
82 |
+
|
83 |
+
protected:
|
84 |
+
int FindPacketStreamSource();
|
85 |
+
void SetupStreams(const PacketStreamSource& src);
|
86 |
+
|
87 |
+
const std::string _filename;
|
88 |
+
std::shared_ptr<PlaybackSession> _playback_session;
|
89 |
+
std::shared_ptr<PacketStreamReader> _reader;
|
90 |
+
SyncTimeEventPromise _event_promise;
|
91 |
+
int _src_id;
|
92 |
+
const PacketStreamSource* _source;
|
93 |
+
|
94 |
+
size_t _size_bytes;
|
95 |
+
bool _fixed_size;
|
96 |
+
std::vector<StreamInfo> _streams;
|
97 |
+
std::vector<ImageDecoderFunc> stream_decoder;
|
98 |
+
picojson::value _device_properties;
|
99 |
+
picojson::value _frame_properties;
|
100 |
+
std::string _source_uri;
|
101 |
+
|
102 |
+
sigslot::scoped_connection session_seek;
|
103 |
+
};
|
104 |
+
|
105 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pango_video_output.h
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2014 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_output_interface.h>
|
31 |
+
#include <pangolin/log/packetstream_writer.h>
|
32 |
+
#include <pangolin/video/stream_encoder_factory.h>
|
33 |
+
|
34 |
+
#include <functional>
|
35 |
+
|
36 |
+
namespace pangolin
|
37 |
+
{
|
38 |
+
|
39 |
+
class PANGOLIN_EXPORT PangoVideoOutput : public VideoOutputInterface
|
40 |
+
{
|
41 |
+
public:
|
42 |
+
PangoVideoOutput(const std::string& filename, size_t buffer_size_bytes, const std::map<size_t, std::string> &stream_encoder_uris);
|
43 |
+
~PangoVideoOutput();
|
44 |
+
|
45 |
+
const std::vector<StreamInfo>& Streams() const override;
|
46 |
+
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& device_properties) override;
|
47 |
+
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
|
48 |
+
bool IsPipe() const override;
|
49 |
+
|
50 |
+
protected:
|
51 |
+
// void WriteHeader();
|
52 |
+
|
53 |
+
std::vector<StreamInfo> streams;
|
54 |
+
std::string input_uri;
|
55 |
+
const std::string filename;
|
56 |
+
picojson::value device_properties;
|
57 |
+
|
58 |
+
PacketStreamWriter packetstream;
|
59 |
+
size_t packetstream_buffer_size_bytes;
|
60 |
+
int packetstreamsrcid;
|
61 |
+
size_t total_frame_size;
|
62 |
+
bool is_pipe;
|
63 |
+
|
64 |
+
bool fixed_size;
|
65 |
+
std::map<size_t, std::string> stream_encoder_uris;
|
66 |
+
std::vector<ImageEncoderFunc> stream_encoders;
|
67 |
+
};
|
68 |
+
|
69 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/pleora.h
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* This file is part of the Pangolin Project.
|
2 |
+
* http://github.com/stevenlovegrove/Pangolin
|
3 |
+
*
|
4 |
+
* Copyright (c) 2015 Steven Lovegrove
|
5 |
+
*
|
6 |
+
* Permission is hereby granted, free of charge, to any person
|
7 |
+
* obtaining a copy of this software and associated documentation
|
8 |
+
* files (the "Software"), to deal in the Software without
|
9 |
+
* restriction, including without limitation the rights to use,
|
10 |
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
+
* copies of the Software, and to permit persons to whom the
|
12 |
+
* Software is furnished to do so, subject to the following
|
13 |
+
* conditions:
|
14 |
+
*
|
15 |
+
* The above copyright notice and this permission notice shall be
|
16 |
+
* included in all copies or substantial portions of the Software.
|
17 |
+
*
|
18 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20 |
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22 |
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23 |
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25 |
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26 |
+
*/
|
27 |
+
|
28 |
+
#pragma once
|
29 |
+
|
30 |
+
#include <pangolin/video/video_interface.h>
|
31 |
+
|
32 |
+
#include <PvDevice.h>
|
33 |
+
#include <PvDeviceGEV.h>
|
34 |
+
#include <PvDeviceU3V.h>
|
35 |
+
#include <PvStream.h>
|
36 |
+
#include <PvStreamGEV.h>
|
37 |
+
#include <PvStreamU3V.h>
|
38 |
+
#include <PvBuffer.h>
|
39 |
+
|
40 |
+
#include <PvSystem.h>
|
41 |
+
|
42 |
+
#include <stdlib.h>
|
43 |
+
#include <list>
|
44 |
+
|
45 |
+
namespace pangolin
|
46 |
+
{
|
47 |
+
|
48 |
+
struct GrabbedBuffer {
|
49 |
+
|
50 |
+
inline GrabbedBuffer(PvBuffer* b,PvResult r,bool v)
|
51 |
+
: buff(b), res(r), valid(v)
|
52 |
+
{
|
53 |
+
}
|
54 |
+
|
55 |
+
PvBuffer* buff;
|
56 |
+
PvResult res;
|
57 |
+
bool valid;
|
58 |
+
|
59 |
+
};
|
60 |
+
|
61 |
+
typedef std::list<GrabbedBuffer> GrabbedBufferList;
|
62 |
+
|
63 |
+
typedef std::list<PvBuffer *> BufferList;
|
64 |
+
|
65 |
+
class PANGOLIN_EXPORT PleoraVideo : public VideoInterface, public VideoPropertiesInterface,
|
66 |
+
public BufferAwareVideoInterface, public GenicamVideoInterface
|
67 |
+
{
|
68 |
+
public:
|
69 |
+
|
70 |
+
static const size_t DEFAULT_BUFFER_COUNT = 30;
|
71 |
+
|
72 |
+
PleoraVideo(const Params& p);
|
73 |
+
|
74 |
+
~PleoraVideo();
|
75 |
+
|
76 |
+
void Start();
|
77 |
+
|
78 |
+
void Stop();
|
79 |
+
|
80 |
+
size_t SizeBytes() const;
|
81 |
+
|
82 |
+
const std::vector<StreamInfo>& Streams() const;
|
83 |
+
|
84 |
+
bool GrabNext( unsigned char* image, bool wait = true );
|
85 |
+
|
86 |
+
bool GrabNewest( unsigned char* image, bool wait = true );
|
87 |
+
|
88 |
+
std::string GetParameter(const std::string& name);
|
89 |
+
|
90 |
+
void SetParameter(const std::string& name, const std::string& value);
|
91 |
+
|
92 |
+
void SetGain(int64_t val);
|
93 |
+
|
94 |
+
int64_t GetGain();
|
95 |
+
|
96 |
+
void SetAnalogBlackLevel(int64_t val);
|
97 |
+
|
98 |
+
int64_t GetAnalogBlackLevel();
|
99 |
+
|
100 |
+
void SetExposure(double val);
|
101 |
+
|
102 |
+
double GetExposure();
|
103 |
+
|
104 |
+
void SetGamma(double val);
|
105 |
+
|
106 |
+
double GetGamma();
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
void SetupTrigger(bool triggerActive, int64_t triggerSource, int64_t acquisitionMode);
|
111 |
+
|
112 |
+
const picojson::value& DeviceProperties() const {
|
113 |
+
return device_properties;
|
114 |
+
}
|
115 |
+
|
116 |
+
const picojson::value& FrameProperties() const {
|
117 |
+
return frame_properties;
|
118 |
+
}
|
119 |
+
|
120 |
+
uint32_t AvailableFrames() const;
|
121 |
+
|
122 |
+
bool DropNFrames(uint32_t n);
|
123 |
+
|
124 |
+
protected:
|
125 |
+
|
126 |
+
void InitDevice(const char *model_name, const char *serial_num, size_t index);
|
127 |
+
|
128 |
+
void DeinitDevice();
|
129 |
+
|
130 |
+
void SetDeviceParams(Params& p);
|
131 |
+
|
132 |
+
void InitStream();
|
133 |
+
|
134 |
+
void DeinitStream();
|
135 |
+
|
136 |
+
void InitPangoStreams();
|
137 |
+
|
138 |
+
void InitPangoDeviceProperties();
|
139 |
+
|
140 |
+
void InitBuffers(size_t buffer_count);
|
141 |
+
|
142 |
+
void DeinitBuffers();
|
143 |
+
|
144 |
+
template<typename T>
|
145 |
+
T DeviceParam(const char* name);
|
146 |
+
|
147 |
+
template<typename T>
|
148 |
+
bool SetDeviceParam(const char* name, T val);
|
149 |
+
|
150 |
+
template<typename T>
|
151 |
+
T StreamParam(const char* name);
|
152 |
+
|
153 |
+
template<typename T>
|
154 |
+
bool SetStreamParam(const char* name, T val);
|
155 |
+
|
156 |
+
bool ParseBuffer(PvBuffer* lBuffer, unsigned char* image);
|
157 |
+
|
158 |
+
void RetriveAllAvailableBuffers(uint32_t timeout);
|
159 |
+
|
160 |
+
std::vector<StreamInfo> streams;
|
161 |
+
picojson::value device_properties;
|
162 |
+
picojson::value frame_properties;
|
163 |
+
|
164 |
+
size_t size_bytes;
|
165 |
+
|
166 |
+
// Pleora handles
|
167 |
+
PvSystem* lPvSystem;
|
168 |
+
const PvDeviceInfo* lDeviceInfo;
|
169 |
+
PvDevice* lDevice;
|
170 |
+
PvStream* lStream;
|
171 |
+
|
172 |
+
// Genicam device parameters
|
173 |
+
PvGenParameterArray* lDeviceParams;
|
174 |
+
PvGenCommand* lStart;
|
175 |
+
PvGenCommand* lStop;
|
176 |
+
|
177 |
+
PvGenInteger* lAnalogGain;
|
178 |
+
PvGenInteger* lAnalogBlackLevel;
|
179 |
+
PvGenFloat* lExposure;
|
180 |
+
PvGenFloat* lGamma;
|
181 |
+
PvGenEnum* lAquisitionMode;
|
182 |
+
PvGenEnum* lTriggerSource;
|
183 |
+
PvGenEnum* lTriggerMode;
|
184 |
+
PvGenFloat* lTemperatureCelcius;
|
185 |
+
bool getTemp;
|
186 |
+
|
187 |
+
// Genicam stream parameters
|
188 |
+
PvGenParameterArray* lStreamParams;
|
189 |
+
|
190 |
+
BufferList lBufferList;
|
191 |
+
GrabbedBufferList lGrabbedBuffList;
|
192 |
+
uint32_t validGrabbedBuffers;
|
193 |
+
};
|
194 |
+
|
195 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/realsense.h
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/video/video_interface.h>
|
4 |
+
#include <pangolin/video/iostream_operators.h>
|
5 |
+
|
6 |
+
namespace rs {
|
7 |
+
class context;
|
8 |
+
class device;
|
9 |
+
}
|
10 |
+
|
11 |
+
namespace pangolin
|
12 |
+
{
|
13 |
+
|
14 |
+
//! Interface to video capture sources
|
15 |
+
struct RealSenseVideo : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
|
16 |
+
{
|
17 |
+
public:
|
18 |
+
|
19 |
+
// Open all RGB and Depth streams from all devices
|
20 |
+
RealSenseVideo(ImageDim dim=ImageDim(640,480), int fps=30);
|
21 |
+
|
22 |
+
~RealSenseVideo();
|
23 |
+
|
24 |
+
//! Implement VideoInput::Start()
|
25 |
+
void Start() override;
|
26 |
+
|
27 |
+
//! Implement VideoInput::Stop()
|
28 |
+
void Stop() override;
|
29 |
+
|
30 |
+
//! Implement VideoInput::SizeBytes()
|
31 |
+
size_t SizeBytes() const override;
|
32 |
+
|
33 |
+
//! Implement VideoInput::Streams()
|
34 |
+
const std::vector<StreamInfo>& Streams() const override;
|
35 |
+
|
36 |
+
//! Implement VideoInput::GrabNext()
|
37 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
38 |
+
|
39 |
+
//! Implement VideoInput::GrabNewest()
|
40 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
41 |
+
|
42 |
+
//! Implement VideoPropertiesInterface::Properties()
|
43 |
+
const picojson::value& DeviceProperties() const override {
|
44 |
+
return device_properties;
|
45 |
+
}
|
46 |
+
|
47 |
+
//! Implement VideoPropertiesInterface::Properties()
|
48 |
+
const picojson::value& FrameProperties() const override {
|
49 |
+
return frame_properties;
|
50 |
+
}
|
51 |
+
|
52 |
+
//! Implement VideoPlaybackInterface::GetCurrentFrameId
|
53 |
+
size_t GetCurrentFrameId() const override;
|
54 |
+
|
55 |
+
//! Implement VideoPlaybackInterface::GetTotalFrames
|
56 |
+
size_t GetTotalFrames() const override;
|
57 |
+
|
58 |
+
//! Implement VideoPlaybackInterface::Seek
|
59 |
+
size_t Seek(size_t frameid) override;
|
60 |
+
|
61 |
+
protected:
|
62 |
+
size_t sizeBytes;
|
63 |
+
|
64 |
+
std::vector<StreamInfo> streams;
|
65 |
+
|
66 |
+
picojson::value device_properties;
|
67 |
+
picojson::value frame_properties;
|
68 |
+
picojson::value* streams_properties;
|
69 |
+
|
70 |
+
size_t current_frame_index;
|
71 |
+
size_t total_frames;
|
72 |
+
|
73 |
+
rs::context* ctx_;
|
74 |
+
std::vector<rs::device*> devs_;
|
75 |
+
|
76 |
+
ImageDim dim_;
|
77 |
+
size_t fps_;
|
78 |
+
};
|
79 |
+
|
80 |
+
}
|
third-party/DPVO/Pangolin/components/pango_video/include/pangolin/video/drivers/realsense2.h
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pragma once
|
2 |
+
|
3 |
+
#include <pangolin/video/video_interface.h>
|
4 |
+
#include <pangolin/video/iostream_operators.h>
|
5 |
+
|
6 |
+
namespace rs2 {
|
7 |
+
class pipeline;
|
8 |
+
class config;
|
9 |
+
}
|
10 |
+
|
11 |
+
namespace pangolin
|
12 |
+
{
|
13 |
+
|
14 |
+
//! Interface to video capture sources
|
15 |
+
struct RealSense2Video : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
|
16 |
+
{
|
17 |
+
public:
|
18 |
+
|
19 |
+
// Open all RGB and Depth streams from all devices
|
20 |
+
RealSense2Video(ImageDim dim=ImageDim(640,480), int fps=30);
|
21 |
+
|
22 |
+
~RealSense2Video();
|
23 |
+
|
24 |
+
//! Implement VideoInput::Start()
|
25 |
+
void Start() override;
|
26 |
+
|
27 |
+
//! Implement VideoInput::Stop()
|
28 |
+
void Stop() override;
|
29 |
+
|
30 |
+
//! Implement VideoInput::SizeBytes()
|
31 |
+
size_t SizeBytes() const override;
|
32 |
+
|
33 |
+
//! Implement VideoInput::Streams()
|
34 |
+
const std::vector<StreamInfo>& Streams() const override;
|
35 |
+
|
36 |
+
//! Implement VideoInput::GrabNext()
|
37 |
+
bool GrabNext( unsigned char* image, bool wait = true ) override;
|
38 |
+
|
39 |
+
//! Implement VideoInput::GrabNewest()
|
40 |
+
bool GrabNewest( unsigned char* image, bool wait = true ) override;
|
41 |
+
|
42 |
+
//! Implement VideoPropertiesInterface::Properties()
|
43 |
+
const picojson::value& DeviceProperties() const override {
|
44 |
+
return device_properties;
|
45 |
+
}
|
46 |
+
|
47 |
+
//! Implement VideoPropertiesInterface::Properties()
|
48 |
+
const picojson::value& FrameProperties() const override {
|
49 |
+
return frame_properties;
|
50 |
+
}
|
51 |
+
|
52 |
+
//! Implement VideoPlaybackInterface::GetCurrentFrameId
|
53 |
+
size_t GetCurrentFrameId() const override;
|
54 |
+
|
55 |
+
//! Implement VideoPlaybackInterface::GetTotalFrames
|
56 |
+
size_t GetTotalFrames() const override;
|
57 |
+
|
58 |
+
//! Implement VideoPlaybackInterface::Seek
|
59 |
+
size_t Seek(size_t frameid) override;
|
60 |
+
|
61 |
+
protected:
|
62 |
+
size_t sizeBytes;
|
63 |
+
|
64 |
+
std::vector<StreamInfo> streams;
|
65 |
+
|
66 |
+
picojson::value device_properties;
|
67 |
+
picojson::value frame_properties;
|
68 |
+
picojson::value* streams_properties;
|
69 |
+
|
70 |
+
size_t current_frame_index;
|
71 |
+
size_t total_frames;
|
72 |
+
|
73 |
+
rs2::pipeline* pipe;
|
74 |
+
rs2::config* cfg;
|
75 |
+
|
76 |
+
ImageDim dim_;
|
77 |
+
size_t fps_;
|
78 |
+
};
|
79 |
+
|
80 |
+
}
|