Gl Graph
Gl Graph Source of lines2d.cpp
#include "lines2d.h" #include "pthread.h" Lines2D::Lines2D() : DrawableDataReader() { } Lines2D::Lines2D(std::string * filename, std::string * format, int maxline,std::unordered_map<std::string, std::string> * args) : DrawableDataReader(filename,format,maxline,args) { gllinedata=GlLineStripData(args); } void Lines2D::updateMinMax(Vec3f &pts) { if (ptsdata.size()==0) { vmin = pts; vmax = pts; } else { vmin.setMin(vmin,pts); vmax.setMax(vmax,pts); } } void Lines2D::addData(float x, float y) { setChanged(); Vec3f pts(x,y,0); gllinedata.addLineVertexData(pts); ptsdata.push_back(pts); updateMinMax(pts); } void Lines2D::addData(float y) { addData(ptsdata.size(), y); } int Lines2D::getElementNb() const { lock(); int nb=ptsdata.size(); unlock(); return nb; } void Lines2D::init() { gllinedata.init(this->glVersion); } void Lines2D::draw() { lock(); glColor3fv(color); gllinedata.draw(); unlock(); } void Lines2D::print() { int size = ptsdata.size(); for (int i = 0; i < size; i++) { std::cout << "x [" << i << "]=" << ptsdata[i].getX() << std::endl; std::cout << "y [" << i << "]=" << ptsdata[i].getY() << std::endl; } } void Lines2D::onFileOpen() { } bool Lines2D::onLineRead(std::string line) { bool ret= true; float x, y, z; const int nbargs = sscanf(line.c_str(), getFormat()->c_str(), &x, &y, &z); lock(); if (nbargs == 1) addData(x); else if (nbargs == 2) addData(x, y); else ret= false; unlock(); return ret; } void Lines2D::onFileClose() { setChanged(); }