36 #include <visp3/core/vpConfig.h>
38 #if defined(VISP_HAVE_DISPLAY)
42 #include <visp3/core/vpMath.h>
43 #include <visp3/core/vpMeterPixelConversion.h>
44 #include <visp3/core/vpPixelMeterConversion.h>
45 #include <visp3/gui/vpDisplayD3D.h>
46 #include <visp3/gui/vpDisplayGDI.h>
47 #include <visp3/gui/vpDisplayGTK.h>
48 #include <visp3/gui/vpDisplayOpenCV.h>
49 #include <visp3/gui/vpDisplayX.h>
50 #include <visp3/gui/vpPlot.h>
58 vpPlot::vpPlot() : I(), display(nullptr), graphNbr(1), graphList(nullptr), margei(30), margej(40), factori(1.f), factorj(1.)
77 vpPlot::vpPlot(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
const std::string &title)
78 : I(), display(nullptr), graphNbr(1), graphList(nullptr), margei(30), margej(40), factori(1.f), factorj(1.)
80 init(graph_nbr, height, width, x, y, title);
95 void vpPlot::init(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
96 const std::string &title)
98 I.
init(height, width, 255);
100 #if defined(VISP_HAVE_X11)
102 #elif defined(VISP_HAVE_GDI)
104 #elif defined(HAVE_OPENCV_HIGHGUI)
106 #elif defined(VISP_HAVE_GTK)
108 #elif defined(VISP_HAVE_D3D9)
112 display->init(
I, x, y, title);
116 factori = height / 700.0f;
117 factorj = width / 700.0f;
119 initNbGraph(graph_nbr);
127 if (graphList !=
nullptr) {
131 if (display !=
nullptr) {
146 void vpPlot::initNbGraph(
unsigned int nbGraph)
151 graphList =
new vpPlotGraph[nbGraph];
156 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(700 * factori), margei,
160 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(350 * factori), margei,
162 graphList[1].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
163 (
unsigned int)(350 * factori), margei, margej);
166 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
168 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
169 (
unsigned int)(350 * factori), margei, margej);
170 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
171 (
unsigned int)(350 * factori), margei, margej);
174 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
176 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
177 (
unsigned int)(350 * factori), margei, margej);
178 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(350 * factorj),
179 (
unsigned int)(350 * factori), margei, margej);
180 graphList[3].initSize(
vpImagePoint((
unsigned int)(350 * factori), (
unsigned int)(350 * factorj)),
181 (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei, margej);
185 for (
unsigned int i = 0; i < graphNbr; i++) {
186 graphList[i].title.clear();
187 graphList[i].unitx.clear();
188 graphList[i].unity.clear();
189 graphList[i].unitz.clear();
214 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax)
216 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10,
true,
true);
231 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax,
double zmin,
234 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10, zmin, zmax, 10,
true,
true);
247 (graphList + graphNum)->setCurveColor(curveNum, color);
253 void vpPlot::displayGrid()
255 for (
unsigned int i = 0; i < graphNbr; i++)
256 graphList[i].displayGrid(
I);
269 void vpPlot::plot(
unsigned int graphNum,
unsigned int curveNum,
double x,
double y)
271 (graphList + graphNum)->
plot(
I, curveNum, x, y);
287 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
288 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
289 this->
plot(graphNum, i, x, v_y[i]);
292 vpTRACE(
"error in plot vector : not the right dimension");
308 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
309 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
310 this->
plot(graphNum, i, x, v_y[i]);
313 vpTRACE(
"error in plot vector : not the right dimension");
331 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
332 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
333 this->
plot(graphNum, i, x, v_y[i]);
336 vpTRACE(
"error in plot vector : not the right dimension");
353 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
354 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
355 this->
plot(graphNum, i, x, v_y[i]);
358 vpTRACE(
"error in plot vector : not the right dimension");
376 if ((graphList + graphNum)->curveNbr == v_y.
size()) {
377 for (
unsigned int i = 0; i < v_y.
size(); ++i)
378 this->
plot(graphNum, i, x, v_y[i]);
381 vpTRACE(
"error in plot vector : not the right dimension");
404 return (graphList + graphNum)->plot(
I, curveNum, x, y, z);
426 if ((graphList + graphNum)->curveNbr == v_y.
getRows() && (graphList + graphNum)->curveNbr == v_z.
getRows()) {
427 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
428 button = this->
plot(graphNum, i, x, v_y[i], v_z[i]);
431 vpTRACE(
"error in plot vector : not the right dimension");
446 bool blocked =
false;
447 unsigned int iblocked = 0;
453 for (
unsigned int i = 0; i < graphNbr; i++) {
459 if ((graphList + iblocked)->move(
I, b)) {
460 (graphList + iblocked)->replot3D(
I);
462 blocked = (graphList + iblocked)->blocked;
465 if ((graphList + iblocked)->move(
I, b)) {
466 (graphList + iblocked)->replot3D(
I);
468 blocked = (graphList + iblocked)->blocked;
489 for (
unsigned int i = 0; i < graphNbr; i++) {
547 (graphList + graphNum)->
setLegend(curveNum, legend);
560 for (
unsigned int i = 0; i < (graphList + graphNum)->curveNbr; i++)
561 (graphList + graphNum)->resetPointList(i);
575 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
588 for (
unsigned int curveNum = 0; curveNum < (graphList + graphNum)->curveNbr; curveNum++)
589 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
648 void vpPlot::saveData(
unsigned int graphNum,
const std::string &dataFile,
const std::string &title_prefix)
650 std::ofstream fichier;
651 fichier.open(dataFile.c_str());
654 double *p =
new double[3];
657 std::vector<std::list<double>::const_iterator> vec_iter_pointListx((graphList + graphNum)->curveNbr);
658 std::vector<std::list<double>::const_iterator> vec_iter_pointListy((graphList + graphNum)->curveNbr);
659 std::vector<std::list<double>::const_iterator> vec_iter_pointListz((graphList + graphNum)->curveNbr);
661 fichier << title_prefix << (graphList + graphNum)->title << std::endl;
663 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
664 vec_iter_pointListx[ind] = (graphList + graphNum)->curveList[ind].pointListx.begin();
665 vec_iter_pointListy[ind] = (graphList + graphNum)->curveList[ind].pointListy.begin();
666 vec_iter_pointListz[ind] = (graphList + graphNum)->curveList[ind].pointListz.begin();
672 while (end ==
false) {
674 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
680 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
681 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
682 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end())) {
683 p[0] = *vec_iter_pointListx[ind];
684 p[1] = *vec_iter_pointListy[ind];
685 p[2] = *vec_iter_pointListz[ind];
693 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
694 ++vec_iter_pointListx[ind];
695 ++vec_iter_pointListy[ind];
696 ++vec_iter_pointListz[ind];
705 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
706 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
707 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end()))
717 p[0] = (graphList + graphNum)->curveList[ind].pointListx.back();
718 p[1] = (graphList + graphNum)->curveList[ind].pointListy.back();
719 p[2] = (graphList + graphNum)->curveList[ind].pointListz.back();
720 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
723 fichier << std::endl;
730 #elif !defined(VISP_BUILD_SHARED_LIBS)
732 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 functionalities.
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 emitted 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)