35 #include <visp3/core/vpConfig.h>
37 #if defined(VISP_HAVE_DISPLAY)
41 #include <visp3/core/vpMath.h>
42 #include <visp3/core/vpMeterPixelConversion.h>
43 #include <visp3/core/vpPixelMeterConversion.h>
44 #include <visp3/gui/vpDisplayD3D.h>
45 #include <visp3/gui/vpDisplayGDI.h>
46 #include <visp3/gui/vpDisplayGTK.h>
47 #include <visp3/gui/vpDisplayOpenCV.h>
48 #include <visp3/gui/vpDisplayX.h>
49 #include <visp3/gui/vpPlot.h>
59 vpPlot::vpPlot() : I(), display(nullptr), graphNbr(1), graphList(nullptr), margei(30), margej(40), factori(1.f), factorj(1.)
78 vpPlot::vpPlot(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
const std::string &title)
79 : I(), display(nullptr), graphNbr(1), graphList(nullptr), margei(30), margej(40), factori(1.f), factorj(1.)
81 init(graph_nbr, height, width, x, y, title);
96 void vpPlot::init(
unsigned int graph_nbr,
unsigned int height,
unsigned int width,
int x,
int y,
97 const std::string &title)
99 I.
init(height, width, 255);
101 #if defined(VISP_HAVE_X11)
102 display =
new vpDisplayX;
103 #elif defined(VISP_HAVE_GDI)
105 #elif defined(HAVE_OPENCV_HIGHGUI)
107 #elif defined(VISP_HAVE_GTK)
109 #elif defined(VISP_HAVE_D3D9)
113 display->init(
I, x, y, title);
117 factori = height / 700.0f;
118 factorj = width / 700.0f;
120 initNbGraph(graph_nbr);
128 if (graphList !=
nullptr) {
132 if (display !=
nullptr) {
147 void vpPlot::initNbGraph(
unsigned int nbGraph)
152 graphList =
new vpPlotGraph[nbGraph];
157 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(700 * factori), margei,
161 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(350 * factori), margei,
163 graphList[1].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
164 (
unsigned int)(350 * factori), margei, margej);
167 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
169 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
170 (
unsigned int)(350 * factori), margei, margej);
171 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
172 (
unsigned int)(350 * factori), margei, margej);
175 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
177 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
178 (
unsigned int)(350 * factori), margei, margej);
179 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(350 * factorj),
180 (
unsigned int)(350 * factori), margei, margej);
181 graphList[3].initSize(
vpImagePoint((
unsigned int)(350 * factori), (
unsigned int)(350 * factorj)),
182 (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei, margej);
186 for (
unsigned int i = 0; i < graphNbr; ++i) {
187 graphList[i].title.clear();
188 graphList[i].unitx.clear();
189 graphList[i].unity.clear();
190 graphList[i].unitz.clear();
215 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax)
217 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10,
true,
true);
232 void vpPlot::initRange(
unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax,
double zmin,
235 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10, zmin, zmax, 10,
true,
true);
248 (graphList + graphNum)->setCurveColor(curveNum, color);
254 void vpPlot::displayGrid()
256 for (
unsigned int i = 0; i < graphNbr; ++i)
257 graphList[i].displayGrid(
I);
270 void vpPlot::plot(
unsigned int graphNum,
unsigned int curveNum,
double x,
double y)
272 (graphList + graphNum)->
plot(
I, curveNum, x, y);
288 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
289 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
290 this->
plot(graphNum, i, x, v_y[i]);
310 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
311 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
312 this->
plot(graphNum, i, x, v_y[i]);
334 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
335 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
336 this->
plot(graphNum, i, x, v_y[i]);
357 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
358 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
359 this->
plot(graphNum, i, x, v_y[i]);
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]);
410 return (graphList + graphNum)->plot(
I, curveNum, x, y, z);
432 if ((graphList + graphNum)->curveNbr == v_y.
getRows() && (graphList + graphNum)->curveNbr == v_z.
getRows()) {
433 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
434 button = this->
plot(graphNum, i, x, v_y[i], v_z[i]);
453 bool blocked =
false;
454 unsigned int iblocked = 0;
460 for (
unsigned int i = 0; i < graphNbr; ++i) {
466 if ((graphList + iblocked)->move(
I, b)) {
467 (graphList + iblocked)->replot3D(
I);
469 blocked = (graphList + iblocked)->blocked;
472 if ((graphList + iblocked)->move(
I, b)) {
473 (graphList + iblocked)->replot3D(
I);
475 blocked = (graphList + iblocked)->blocked;
496 for (
unsigned int i = 0; i < graphNbr; ++i) {
554 (graphList + graphNum)->
setLegend(curveNum, legend);
567 for (
unsigned int i = 0; i < (graphList + graphNum)->curveNbr; ++i)
568 (graphList + graphNum)->resetPointList(i);
582 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
595 for (
unsigned int curveNum = 0; curveNum < (graphList + graphNum)->curveNbr; ++curveNum)
596 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
655 void vpPlot::saveData(
unsigned int graphNum,
const std::string &dataFile,
const std::string &title_prefix)
657 std::ofstream fichier;
658 fichier.open(dataFile.c_str());
661 double *p =
new double[3];
664 std::vector<std::list<double>::const_iterator> vec_iter_pointListx((graphList + graphNum)->curveNbr);
665 std::vector<std::list<double>::const_iterator> vec_iter_pointListy((graphList + graphNum)->curveNbr);
666 std::vector<std::list<double>::const_iterator> vec_iter_pointListz((graphList + graphNum)->curveNbr);
668 fichier << title_prefix << (graphList + graphNum)->title << std::endl;
670 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ++ind) {
671 vec_iter_pointListx[ind] = (graphList + graphNum)->curveList[ind].pointListx.begin();
672 vec_iter_pointListy[ind] = (graphList + graphNum)->curveList[ind].pointListy.begin();
673 vec_iter_pointListz[ind] = (graphList + graphNum)->curveList[ind].pointListz.begin();
679 while (end ==
false) {
681 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ++ind) {
687 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
688 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
689 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end())) {
690 p[0] = *vec_iter_pointListx[ind];
691 p[1] = *vec_iter_pointListy[ind];
692 p[2] = *vec_iter_pointListz[ind];
700 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
701 ++vec_iter_pointListx[ind];
702 ++vec_iter_pointListy[ind];
703 ++vec_iter_pointListz[ind];
712 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
713 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
714 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end()))
724 p[0] = (graphList + graphNum)->curveList[ind].pointListx.back();
725 p[1] = (graphList + graphNum)->curveList[ind].pointListy.back();
726 p[2] = (graphList + graphNum)->curveList[ind].pointListz.back();
727 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
730 fichier << std::endl;
739 #elif !defined(VISP_BUILD_SHARED_LIBS)
741 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...
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)