pangolin-task4

Task4

pangolin 的plot功能。

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

int main(/*int argc, char* argv[]*/)
{
  // Create OpenGL window in single line
  pangolin::CreateWindowAndBind("Main",640,480);

  // Data logger object
  pangolin::DataLog log;

  // Optionally add named labels
  std::vector<std::string> labels;
  labels.push_back(std::string("sin(t)"));
  labels.push_back(std::string("cos(t)"));
  labels.push_back(std::string("sin(t)+cos(t)"));
  log.SetLabels(labels);

  const float tinc = 0.01f;

  // OpenGL 'view' of data. We might have many views of the same data.
  pangolin::Plotter plotter(&log,0.0f,4.0f*(float)M_PI/tinc,-4.0f,4.0f,(float)M_PI/(4.0f*tinc),0.5f);
  plotter.SetBounds(0.0, 1.0, 0.0, 1.0);
  // plotter.Track("$i");//坐标轴自动滚动

  // Add some sample annotations to the plot(为区域着色)
  // plotter.AddMarker(pangolin::Marker::Vertical,   50*M_PI, pangolin::Marker::LessThan, pangolin::Colour::Blue().WithAlpha(0.2f) );
  plotter.AddMarker(pangolin::Marker::Horizontal,   3, pangolin::Marker::GreaterThan, pangolin::Colour::Red().WithAlpha(0.2f) );
  plotter.AddMarker(pangolin::Marker::Horizontal,    3, pangolin::Marker::Equal, pangolin::Colour::Green().WithAlpha(0.2f) );

  pangolin::DisplayBase().AddDisplay(plotter);

  float t = 0;

  // Default hooks for exiting (Esc) and fullscreen (tab).
  while( !pangolin::ShouldQuit() )
  {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    log.Log(sin(t),cos(t),sin(t)+cos(t));
    // log.Log(1,2,3);
    t += tinc;

    // Render graph, Swap frames and Process Events
    pangolin::FinishFrame();
  }

  return 0;
}

逐行解析

pangolin::DataLog log;

任意尺寸浮点数的容器。
在这里插入图片描述

/*
Plotter(
	DataLog* default_log,
	float left=0, float right=600, float bottom=-1, float top=1,
	float tickx=30, float ticky=0.5,
	Plotter* linked_plotter_x = 0,
	Plotter* linked_plotter_y = 0
);
*/
pangolin::Plotter plotter(&log,0.0f,4.0f*(float)M_PI/tinc,-4.0f,4.0f,(float)M_PI/(4.0f*tinc),0.5f);

Plotter 参数解释

  • default_log,数据存储器指针
  • left,right,是x轴范围
  • bottom,top,是y轴范围
  • tickx,ticky,是x 和 y 轴的刻度间隔
plotter.SetBounds(0.0, 1.0, 0.0, 1.0);

占满窗体。

plotter.AddMarker(pangolin::Marker::Vertical,   50*M_PI, pangolin::Marker::LessThan, pangolin::Colour::Blue().WithAlpha(0.2f) );
plotter.AddMarker(pangolin::Marker::Horizontal,   3, pangolin::Marker::GreaterThan, pangolin::Colour::Red().WithAlpha(0.2f) );
plotter.AddMarker(pangolin::Marker::Horizontal,    3, pangolin::Marker::Equal, pangolin::Colour::Green().WithAlpha(0.2f) );

AddMarker 用来在图中添加标记区域,用于标识临界点或有效区域。pangolin提供了两个重载函数,这里仅展示了其中一个。

这里的AddMarker可以绘制区域和线,如下图所示。

在这里插入图片描述

参数解释

  • pangolin::Marker::Horizontal,画水平区域
  • 3,y轴上的刻度
  • pangolin::Marker::GreaterThan,区域比指定的刻度大
  • pangolin::Colour::Red().WithAlpha(0.2f),颜色,0.2的透明
  • pangolin::Marker::Equal,区域宽度等于设定值(3),那么就形成线。
pangolin::DisplayBase().AddDisplay(plotter);

DisplayBase ,会始终渲染它关联的窗口,也就是不用在循环中激活窗口。

log.Log(sin(t),cos(t),sin(t)+cos(t));
t += tinc;

每次循环向数据容器中添加数据,plot会绘制这些数据。

总结

Plotter 继承了 View 和 Handler 。可以用鼠标与plot进行交互。

AddMarker的另一个重载函数可以用来绘制任意的某段区域,使用如下两个函数:

Marker(const XYRangef& range, const Colour& c = Colour() );
Marker& AddMarker( const Marker& marker );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值