void Histogram::display(Gnuplot & g ) const { vector<float> tmp = get_bin_edges(); tmp.pop_back(); vector<float> tmp2 = vector<float>(0); tmp2.reserve(hist_array_.size()); for(vectori::const_iterator it = hist_array_.begin(); it<hist_array_.end(); ++it) tmp2.push_back(*it); try { g.plot_xy(tmp,tmp2); g.set_style("histograms"); g.set_grid(); g.replot(); wait_for_key(); } catch(GnuplotException & e) { cout<<e.what()<<endl; } }
void print_deceleration_curve_with_gnuplot(Gnuplot & plot ,const parabola_curve &curve, std::string label, bool svg) { try{ std::ostringstream function; std::vector<double> points_begin; std::vector<double> points_speed; points_begin.reserve(curve.arcs.size()); points_speed.reserve(curve.arcs.size()); for (auto i : curve.arcs) { function << "((x>=" << i.second.begin << ")&&(x<" << i.second.end << "))? "; function << "(2*("<< -i.second.slope << ")*(x-" << i.second.begin << ")+" << i.second.value << "**(2))**(1.0/2.0)"; function << ":"; points_begin.push_back(i.first); points_speed.push_back(i.second.value); } function << "1/0" ; if(svg) { plot << "set terminal svg fname 'Verdana' fsize 10 "; plot << "set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind"; plot << "set object 1 rect fc rgb \"white\" fillstyle solid 1.0"; std::string output("set output '"); output += label; output += ".svg'"; plot << output; } else { plot << "set term wxt"; } plot.set_style("lines"); plot.set_yautoscale(); plot.set_xlabel("Position [m]"); plot.set_ylabel("Permitted Speed to brake for target [m/s]"); plot.plot_equation(function.str(),label); if(svg) plot.set_style("points lc -1 pt 7"); else plot.set_style("points lc 7 pt 7"); plot.plot_xy(points_begin,points_speed,"Begin of Arcs"); } catch (const GnuplotException & e) { std::cout << "Error while plotting with Gnuplot (" << e.what() <<")" << std::endl; } }
void GNUPlotOut::out(const std::string& name) { Gnuplot plot; plot.set_title(name.c_str()); plot.set_style("lines"); plot.cmd("set terminal png size 1024,768"); plot.cmd("set output \"" + name + ".png\""); plot.plot_xy(_y, _x); //std::cin.get(); }
void rysuj() { Gnuplot mainPlot; mainPlot.set_style("lines"); //styl rysowania wykresu mainPlot.set_grid(); //siatka poprawiająca czytelnosc mainPlot.set_xrange(rangeStart, rangeEnd); //zakres osi x wg. zadanych wartoœci mainPlot.plot_xy(functionX, functionY, "Funkcja aproksymowana"); mainPlot.set_style("lines"); //styl rysowania wykresu mainPlot.set_grid(); //siatka poprawiająca czytelnoœæ mainPlot.set_xrange(rangeStart, rangeEnd); //zakres osi x wg. zadanych wartoœci mainPlot.plot_xy(functionX, approximationY, "Funkcja aproksymujaca"); getchar(); system("PAUSE"); }
int main(int argc, const char** argv) { // don't forget to set LD_LIBRARY_PATH to directory where libOiVibrations.so libary resides // LD_LIBRARY_PATH=/home/john/sharedlibs // export LD_LIBRARY_PATH cout << "\n"; if (argc < 2) { cout << "\n"; cout << "Requires one or more command arguments.\n"; cout << " Universal file name : FileName.uff \n"; exit(1); } Oi::Proxy proxy; bool bSucceess = proxy.init(argc, argv); if (bSucceess) cout << "Initialization succeeded!\n"; else { cout << "Initialization failed!\n"; exit(1); } cout << "\n"; int i(0); int nrows(0), ncols(0); const double* pnodes = proxy.getNodes(nrows, ncols); vector<Point> nodesCollection; nodesCollection.reserve(nrows); Point pt1, pt2, pt3; if (pnodes != NULL && ncols == 3) { for (i = 0; i < nrows; ++i) { Point pt; pt.x = pnodes[0*nrows + i]; pt.y = pnodes[1*nrows + i]; pt.z = pnodes[2*nrows + i]; nodesCollection.push_back(pt); } } const unsigned int* plines = proxy.getLines(nrows, ncols); vector<Line> linesCollection; linesCollection.reserve(nrows); if (plines != NULL && ncols == 2 && !nodesCollection.empty()) { unsigned int idx1(0), idx2(0); for (i = 0; i < nrows; ++i) { Line line; idx1 = plines[0*nrows + i]; idx2 = plines[1*nrows + i]; // number of node (point) starts from 1, where the indexes of vector<Point> // starts from 0. line.point1 = nodesCollection[idx1-1]; line.point2 = nodesCollection[idx2-1]; linesCollection.push_back(line); } } const unsigned int* psurfaces = proxy.getSurfaces(nrows, ncols); vector<Surface> surfacesCollection; surfacesCollection.reserve(nrows); if (psurfaces != NULL && ncols == 3) { unsigned int idx1(0), idx2(0), idx3(0); for (i = 0; i < nrows; ++i) { Surface surface; idx1 = psurfaces[0*nrows + i]; idx2 = psurfaces[1*nrows + i]; idx3 = psurfaces[2*nrows + i]; surface.point1 = nodesCollection[idx1-1]; surface.point2 = nodesCollection[idx2-1]; surface.point3 = nodesCollection[idx3-1]; surfacesCollection.push_back(surface); } } /* * std::cout << "------ Nodes ---------\n"; * std::ostream_iterator<Point> os_pit( std::cout, "\n" ); * std::copy(nodesCollection.begin(), nodesCollection.end(), os_pit); * std::cout << std::endl; * * std::cout << "------- Lines --------\n"; * std::ostream_iterator<Line> os_it( std::cout, "\n" ); * std::copy(linesCollection.begin(), linesCollection.end(), os_it); * std::cout << std::endl; */ vector<double> singularValues; int length(0); int numberOfMeasurements = proxy.getNumberOfMeasurements(); vector<const double*> pvalues(numberOfMeasurements); vector<const double*> pfreq(numberOfMeasurements); vector<Gnuplot*> plots; for (i = 0; i < numberOfMeasurements; ++i) { //pvalues[i] = proxy.getSingularValues(i, nrows, ncols); pvalues[i] = proxy.getSpectralDensity(i, nrows, ncols); pfreq[i] = proxy.getFrequencies(length); if (pvalues[i] != 0) { try { std::stringstream ss; ss << "Measurement: " << (i+1); Gnuplot* gplot = new Gnuplot(ss.str()); gplot->set_title(ss.str()); ss.str(""); ss.clear(); gplot->set_grid(); gplot->set_ylogscale(); gplot->set_style("steps"); for (int j = 0; j < ncols; ++j) { ss << "singular values " << j; gplot->plot_xy(pfreq[i], pfreq[i]+length, pvalues[i]+j*nrows, pvalues[i]+(j+1)*nrows, ss.str() ); ss.str(""); ss.clear(); } plots.push_back(gplot); } catch(GnuplotException& e) { std::cout << e.what() << "\n"; std::for_each(plots.begin(), plots.end(), delete_plot); } } } wait_for_key(); std::for_each(plots.begin(), plots.end(), delete_plot); /* *double natFreq = 33.8; *int nchannels(0), nsvd(0); *const complex<double>* pmodes = proxy.getModes(natFreq, 0, nchannels, nsvd); * *vector< complex<double> > modesList(nchannels*nsvd); *std::copy(pmodes, pmodes+nchannels*nsvd, &modesList[0]); */ return 0; }