pangolinDynamicPly.md

0 结果展示

https://cdn.jsdelivr.net/gh/xychen5/blogImgs@main/imgs/dynamicPly.4903brhv6b00.gif

1 下载编译pangolin的库

https://github.com/stevenlovegrove/Pangolin.git
该库中本身含有libpng, libjpg, libzip

2 当需要调用该库时:

调用时依赖如下:(本项目并未上传所有依赖,部分依赖需要单独下载然后放到thirdparty目录里)

1
2
3
4
5
# include
F:\prjs\ORB_SLAM3_Fix\ORB_SLAM3\Thirdparty\Pangolin\include;F:\prjs\ORB_SLAM3_Fix\ORB_SLAM3\Thirdparty\Pangolin\build\src\include;F:\prjs\ORB_SLAM3_Fix\ORB_SLAM3\Thirdparty\Pangolin\build\external\glew\include;F:\BASE_ENV\forOpenMVS\eigen;%(AdditionalIncludeDirectories)

# lib
..\..\..\lib\Release\pangolin.lib;opengl32.lib;glu32.lib;..\..\external\glew\lib\glew.lib;..\..\external\libpng\lib\libpng16_static.lib;..\..\external\zlib\lib\zlibstatic.lib;..\..\external\libjpeg\lib\jpeg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib

3 动态展示点云的示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
void viewThread(pangolin::OpenGlMatrix &Twc) {
pangolin::CreateWindowAndBind("Main", 1024, 768);
glEnable(GL_DEPTH_TEST);
// Issue specific OpenGl we might need
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(1024, 768, 500, 500, 512, 389, 0.1, 1000),
pangolin::ModelViewLookAt(50, 50, 50, 0, 0, 0, pangolin::AxisY)
);

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

// Add named OpenGL viewport to window and provide 3D Handler
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(175), 1.0, -1024.0f / 768.0f)
.SetHandler(new pangolin::Handler3D(s_cam));

size_t frame = 0;
while( !pangolin::ShouldQuit() ) {
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f,1.0f,1.0f,1.0f);
//! Activate Displays and set State Matrices
d_cam.Activate(s_cam);
// draw camera
const float w = 2;
const float h = w*0.75;
const float z = w*0.6;
glPushMatrix();
glMultMatrixd(Twc.m);
glLineWidth(1);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(0,0,0);
glVertex3f(w,h,z);
glVertex3f(0,0,0);
glVertex3f(w,-h,z);
glVertex3f(0,0,0);
glVertex3f(-w,-h,z);
glVertex3f(0,0,0);
glVertex3f(-w,h,z);

glVertex3f(w,h,z);
glVertex3f(w,-h,z);

glVertex3f(-w,h,z);
glVertex3f(-w,-h,z);

glVertex3f(-w,h,z);
glVertex3f(w,h,z);

glVertex3f(-w,-h,z);
glVertex3f(w,-h,z);
glEnd();

glPopMatrix();

// draw points
glPointSize(2);
glBegin(GL_POINTS);
glColor3f(0.0, 0.0, 0.0);

// get all points to m_pos.m_ppatches
updatePointsMutex.lock();
for (size_t p = 0; p < (size_t)allPPatchesRender.size(); ++p)
{
auto patch = *allPPatchesRender[p];
glVertex3f(
patch.m_coord[0],
patch.m_coord[1],
patch.m_coord[2]
);
}
updatePointsMutex.unlock();
glEnd();

// Swap frames and Process Events
pangolin::FinishFrame();

std::this_thread::sleep_for(std::chrono::milliseconds(100)); // ms
// std::cout << "frame��" << ++frame << std::endl;
// std::cout << "point nums are: " << findMatch->m_pos.m_ppatches.size() << std::endl;
}
}


int main(int argc, char* argv[])
{
pangolin::OpenGlMatrix Twc, Twr;
Twc.SetIdentity();
std::thread viewThd(viewThread, Twc);

while(1) {
...<省略>
// update render points
updatePointsMutex.lock();
allPPatchesRender = findMatch->m_pos.m_ppatches; // to get the newest points
updatePointsMutex.unlock();
...<省略>
}


viewThd.join();

//writePointCloundPly(prefix);
releasePMVS();
return 0;
}