39 #include <visp3/core/vpConfig.h>
41 #if defined(VISP_HAVE_DISPLAY)
45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpMeterPixelConversion.h>
47 #include <visp3/core/vpPixelMeterConversion.h>
48 #include <visp3/gui/vpDisplayD3D.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/gui/vpDisplayOpenCV.h>
52 #include <visp3/gui/vpDisplayX.h>
53 #include <visp3/gui/vpPlot.h>
61 vpPlot::vpPlot() : I(), display(NULL), graphNbr(1), graphList(NULL), margei(30), margej(40), factori(1.f), factorj(1.)
81 vpPlot::vpPlot(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
const std::string &title)
82 : I(), display(NULL), graphNbr(1), graphList(NULL), margei(30), margej(40), factori(1.f), factorj(1.)
84 init(graph_nbr, height, width, x, y, title);
99 void vpPlot::init(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
100 const std::string &title)
102 I.
init(height, width, 255);
104 #if defined VISP_HAVE_X11
106 #elif defined VISP_HAVE_GDI
108 #elif defined VISP_HAVE_OPENCV
110 #elif defined VISP_HAVE_GTK
112 #elif defined VISP_HAVE_D3D9
116 display->init(
I, x, y, title.c_str());
120 factori = height / 700.0f;
121 factorj = width / 700.0f;
123 initNbGraph(graph_nbr);
131 if (graphList != NULL) {
135 if (display != NULL) {
150 void vpPlot::initNbGraph(
unsigned int nbGraph)
155 graphList =
new vpPlotGraph[nbGraph];
160 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(700 * factori), margei,
164 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(350 * factori), margei,
166 graphList[1].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
167 (
unsigned int)(350 * factori), margei, margej);
170 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
172 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
173 (
unsigned int)(350 * factori), margei, margej);
174 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
175 (
unsigned int)(350 * factori), margei, margej);
178 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
180 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
181 (
unsigned int)(350 * factori), margei, margej);
182 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(350 * factorj),
183 (
unsigned int)(350 * factori), margei, margej);
184 graphList[3].initSize(
vpImagePoint((
unsigned int)(350 * factori), (
unsigned int)(350 * factorj)),
185 (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei, margej);
189 for (
unsigned int i = 0; i < graphNbr; i++) {
190 graphList[i].title.clear();
191 graphList[i].unitx.clear();
192 graphList[i].unity.clear();
193 graphList[i].unitz.clear();
227 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax)
229 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10,
true,
true);
246 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax,
double zmin,
249 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10, zmin, zmax, 10,
true,
true);
262 (graphList + graphNum)->setCurveColor(curveNum, color);
268 void vpPlot::displayGrid()
270 for (
unsigned int i = 0; i < graphNbr; i++)
271 graphList[i].displayGrid(
I);
285 void vpPlot::plot(
unsigned int graphNum,
unsigned int curveNum,
double x,
double y)
287 (graphList + graphNum)->
plot(
I, curveNum, x, y);
303 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
304 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
305 this->
plot(graphNum, i, x, v_y[i]);
307 vpTRACE(
"error in plot vector : not the right dimension");
322 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
323 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
324 this->
plot(graphNum, i, x, v_y[i]);
326 vpTRACE(
"error in plot vector : not the right dimension");
342 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
343 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
344 this->
plot(graphNum, i, x, v_y[i]);
346 vpTRACE(
"error in plot vector : not the right dimension");
361 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
362 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
363 this->
plot(graphNum, i, x, v_y[i]);
365 vpTRACE(
"error in plot vector : not the right dimension");
381 if ((graphList + graphNum)->curveNbr == v_y.
size()) {
382 for (
unsigned int i = 0; i < v_y.
size(); ++i)
383 this->
plot(graphNum, i, x, v_y[i]);
385 vpTRACE(
"error in plot vector : not the right dimension");
404 return (graphList + graphNum)->plot(
I, curveNum, x, y, z);
423 if ((graphList + graphNum)->curveNbr == v_y.
getRows() && (graphList + graphNum)->curveNbr == v_z.
getRows()) {
424 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
425 button = this->
plot(graphNum, i, x, v_y[i], v_z[i]);
427 vpTRACE(
"error in plot vector : not the right dimension");
442 bool blocked =
false;
443 unsigned int iblocked = 0;
449 for (
unsigned int i = 0; i < graphNbr; i++) {
455 if ((graphList + iblocked)->move(
I, b)) {
456 (graphList + iblocked)->replot3D(
I);
458 blocked = (graphList + iblocked)->blocked;
460 if ((graphList + iblocked)->move(
I, b)) {
461 (graphList + iblocked)->replot3D(
I);
463 blocked = (graphList + iblocked)->blocked;
484 for (
unsigned int i = 0; i < graphNbr; i++) {
536 (graphList + graphNum)->
setLegend(curveNum, legend);
549 for (
unsigned int i = 0; i < (graphList + graphNum)->curveNbr; i++)
550 (graphList + graphNum)->resetPointList(i);
563 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
576 for (
unsigned int curveNum = 0; curveNum < (graphList + graphNum)->curveNbr; curveNum++)
577 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
633 void vpPlot::saveData(
unsigned int graphNum,
const std::string &dataFile,
const std::string &title_prefix)
635 std::ofstream fichier;
636 fichier.open(dataFile.c_str());
639 double *p =
new double[3];
642 std::vector<std::list<double>::const_iterator> vec_iter_pointListx((graphList + graphNum)->curveNbr);
643 std::vector<std::list<double>::const_iterator> vec_iter_pointListy((graphList + graphNum)->curveNbr);
644 std::vector<std::list<double>::const_iterator> vec_iter_pointListz((graphList + graphNum)->curveNbr);
646 fichier << title_prefix << (graphList + graphNum)->title << std::endl;
648 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
649 vec_iter_pointListx[ind] = (graphList + graphNum)->curveList[ind].pointListx.begin();
650 vec_iter_pointListy[ind] = (graphList + graphNum)->curveList[ind].pointListy.begin();
651 vec_iter_pointListz[ind] = (graphList + graphNum)->curveList[ind].pointListz.begin();
657 while (end ==
false) {
659 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
665 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
666 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
667 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end())) {
668 p[0] = *vec_iter_pointListx[ind];
669 p[1] = *vec_iter_pointListy[ind];
670 p[2] = *vec_iter_pointListz[ind];
678 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
679 ++vec_iter_pointListx[ind];
680 ++vec_iter_pointListy[ind];
681 ++vec_iter_pointListz[ind];
690 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
691 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
692 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end()))
701 p[0] = (graphList + graphNum)->curveList[ind].pointListx.back();
702 p[1] = (graphList + graphNum)->curveList[ind].pointListy.back();
703 p[2] = (graphList + graphNum)->curveList[ind].pointListz.back();
704 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
707 fichier << std::endl;
714 #elif !defined(VISP_BUILD_SHARED_LIBS)
716 void dummy_vpPlot(){};
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionnalities.
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
error that can be emited by ViSP classes.
@ dimensionError
Bad dimension.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
bool inRectangle(const vpRect &rect) const
void init(unsigned int height, unsigned int width)
Set the size of the image.
void initGraph(unsigned int graphNum, unsigned int curveNbr)
vpImage< unsigned char > I
void setUnitY(unsigned int graphNum, const std::string &unity)
void init(unsigned int nbGraph, unsigned int height=700, unsigned int width=700, int x=-1, int y=-1, const std::string &title="")
void initRange(unsigned int graphNum, double xmin, double xmax, double ymin, double ymax)
void setGridThickness(unsigned int graphNum, unsigned int thickness)
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
void setUnitX(unsigned int graphNum, const std::string &unitx)
void setColor(unsigned int graphNum, unsigned int curveNum, vpColor color)
void setThickness(unsigned int graphNum, unsigned int curveNum, unsigned int thickness)
void setGraphThickness(unsigned int graphNum, unsigned int thickness)
void setUnitZ(unsigned int graphNum, const std::string &unitz)
void setTitle(unsigned int graphNum, const std::string &title)
void saveData(unsigned int graphNum, const std::string &dataFile, const std::string &title_prefix="")
void resetPointList(unsigned int graphNum)
void getPixelValue(bool block)
Implementation of a pose vector and operations on poses.
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Class that consider the case of a translation vector.
VISP_EXPORT void sleepMs(double t)