• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
camke(6)配置pangolin 2线程和立方体交互

 

 

 

 

 

 

 

 

 

 

 

plotTrajectory.cpp

#include <pangolin/pangolin.h>
#include <thread>

//https://blog.csdn.net/weixin_43991178/article/details/105119610
static const std::string window_name = "HelloPangolinThreads";

void setup() {
    // create a window and bind its context to the main thread
    pangolin::CreateWindowAndBind(window_name, 640, 480);

    // enable depth
    glEnable(GL_DEPTH_TEST);

    // unset the current context from the main thread
    //但这个视窗实在主线程中创建的,因此在主线程调用玩后,需要使用GetBoundWindow()->RemoveCurrent()将其解绑。
    pangolin::GetBoundWindow()->RemoveCurrent();
}

void run() {
    // fetch the context and bind it to this thread
    //首先使用BindToContext()函数将之前解绑的视窗绑定到当前线程
    pangolin::BindToContext(window_name);

    // we manually need to restore the properties of the context
    glEnable(GL_DEPTH_TEST);

    // Define Projection and initial ModelView matrix
    // 创建相机观察
    pangolin::OpenGlRenderState s_cam(
        pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),//相机矩阵
        pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)      //窗口初始看向位置
    );

    // Create Interactive View in window
    // 创建交互窗口 //交互式视图(view)用于显示上一步摄像机所“拍摄”到的内容
    pangolin::Handler3D handler(s_cam); //交互相机视图句柄
    pangolin::View& d_cam = pangolin::CreateDisplay()
    //setBounds()函数前四个参数依次表示视图在视窗中的范围(下、上、左、右),可以采用相对坐标(0~1)以及绝对坐标(使用Attach对象)。
            .SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)  
            .SetHandler(&handler);

    while( !pangolin::ShouldQuit() )
    {
        // Clear screen and activate view to render into 清楚上一张颜色和深度缓存  不重影子
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        d_cam.Activate(s_cam);

        // Render OpenGL Cube 创建立方体
        pangolin::glDrawColouredCube();

        // Swap frames and Process Events    // 运行帧循环以推进窗口事件
        pangolin::FinishFrame();
    }

    // unset the current context from the main thread
    //在线程结束时,我们需要解绑视窗。
    pangolin::GetBoundWindow()->RemoveCurrent();
}

int main( int /*argc*/, char** /*argv*/ )
{
    // create window and context in the main thread
    setup();

    // use the context in a separate rendering thread
    std::thread render_loop;
    render_loop = std::thread(run);
    render_loop.join();

    return 0;
}

CMakeLists.txt

# cmake needs this line
cmake_minimum_required(VERSION 3.1)

# Define project name
project(Pangolin_project)

#添加Pangolin画图依赖库
find_package(Pangolin REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})

#编译可执行文件
add_executable(plotTrajectory plotTrajectory.cpp)
#连接Pangolin库
target_link_libraries(plotTrajectory ${Pangolin_LIBRARIES})

 

执行

# 创建编译文件夹(在Pangolin文件夹下)
mkdir build && cd build
# 配置编译选项
cmake ..
# 开始编译代码
cmake --build .
# 安装
sudo make install

  

 

 

 

 

 

 

 

  

 

posted on 2021-06-06 17:02  MKT-porter  阅读(258)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3