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(
const unsigned int graph_nbr,
const unsigned int height,
const unsigned int width,
const int x,
82 const int y,
const std::string &title)
83 :
I(),
display(NULL), graphNbr(1), graphList(NULL), margei(30), margej(40), factori(1.f), factorj(1.)
85 init(graph_nbr, height, width, x, y, title);
100 void vpPlot::init(
const unsigned int graph_nbr,
const unsigned int height,
const unsigned int width,
const int x,
101 const int y,
const std::string &title)
103 I.
init(height, width, 255);
105 #if defined VISP_HAVE_X11 107 #elif defined VISP_HAVE_GDI 109 #elif defined VISP_HAVE_OPENCV 111 #elif defined VISP_HAVE_GTK 113 #elif defined VISP_HAVE_D3D9 117 display->init(
I, x, y, title.c_str());
121 factori = height / 700.0f;
122 factorj = width / 700.0f;
124 initNbGraph(graph_nbr);
132 if (graphList != NULL) {
151 void vpPlot::initNbGraph(
unsigned int nbGraph)
156 graphList =
new vpPlotGraph[nbGraph];
161 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(700 * factori), margei,
165 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(700 * factorj), (
unsigned int)(350 * factori), margei,
167 graphList[1].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
168 (
unsigned int)(350 * factori), margei, margej);
171 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
173 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
174 (
unsigned int)(350 * factori), margei, margej);
175 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(700 * factorj),
176 (
unsigned int)(350 * factori), margei, margej);
179 graphList[0].initSize(
vpImagePoint(0, 0), (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei,
181 graphList[1].initSize(
vpImagePoint(0, (
unsigned int)(350 * factorj)), (
unsigned int)(350 * factorj),
182 (
unsigned int)(350 * factori), margei, margej);
183 graphList[2].initSize(
vpImagePoint((
unsigned int)(350 * factori), 0), (
unsigned int)(350 * factorj),
184 (
unsigned int)(350 * factori), margei, margej);
185 graphList[3].initSize(
vpImagePoint((
unsigned int)(350 * factori), (
unsigned int)(350 * factorj)),
186 (
unsigned int)(350 * factorj), (
unsigned int)(350 * factori), margei, margej);
190 for (
unsigned int i = 0; i < graphNbr; i++) {
191 graphList[i].title.clear();
192 graphList[i].unitx.clear();
193 graphList[i].unity.clear();
194 graphList[i].unitz.clear();
228 void vpPlot::initRange(
const unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax)
230 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10,
true,
true);
247 void vpPlot::initRange(
const unsigned int graphNum,
double xmin,
double xmax,
double ymin,
double ymax,
double zmin,
250 (graphList + graphNum)->initScale(
I, xmin, xmax, 10, ymin, ymax, 10, zmin, zmax, 10,
true,
true);
263 (graphList + graphNum)->setCurveColor(curveNum, color);
269 void vpPlot::displayGrid()
271 for (
unsigned int i = 0; i < graphNbr; i++)
272 graphList[i].displayGrid(
I);
286 void vpPlot::plot(
const unsigned int graphNum,
const unsigned int curveNum,
const double x,
const double y)
288 (graphList + graphNum)->
plot(
I, curveNum, x, y);
304 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
305 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
306 this->
plot(graphNum, i, x, v_y[i]);
308 vpTRACE(
"error in plot vector : not the right dimension");
323 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
324 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
325 this->
plot(graphNum, i, x, v_y[i]);
327 vpTRACE(
"error in plot vector : not the right dimension");
343 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
344 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
345 this->
plot(graphNum, i, x, v_y[i]);
347 vpTRACE(
"error in plot vector : not the right dimension");
362 if ((graphList + graphNum)->curveNbr == v_y.
getRows()) {
363 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
364 this->
plot(graphNum, i, x, v_y[i]);
366 vpTRACE(
"error in plot vector : not the right dimension");
382 if ((graphList + graphNum)->curveNbr == v_y.
size()) {
383 for (
unsigned int i = 0; i < v_y.
size(); ++i)
384 this->
plot(graphNum, i, x, v_y[i]);
386 vpTRACE(
"error in plot vector : not the right dimension");
403 const double y,
const double z)
405 return (graphList + graphNum)->plot(
I, curveNum, x, y, z);
424 if ((graphList + graphNum)->curveNbr == v_y.
getRows() && (graphList + graphNum)->curveNbr == v_z.
getRows()) {
425 for (
unsigned int i = 0; i < v_y.
getRows(); ++i)
426 button = this->
plot(graphNum, i, x, v_y[i], v_z[i]);
428 vpTRACE(
"error in plot vector : not the right dimension");
443 bool blocked =
false;
444 unsigned int iblocked = 0;
450 for (
unsigned int i = 0; i < graphNbr; i++) {
456 if ((graphList + iblocked)->move(
I, b)) {
457 (graphList + iblocked)->replot3D(
I);
459 blocked = (graphList + iblocked)->blocked;
461 if ((graphList + iblocked)->move(
I, b)) {
462 (graphList + iblocked)->replot3D(
I);
464 blocked = (graphList + iblocked)->blocked;
485 for (
unsigned int i = 0; i < graphNbr; i++) {
500 (graphList + graphNum)->
setTitle(title);
512 (graphList + graphNum)->
setUnitX(unitx);
524 (graphList + graphNum)->
setUnitY(unity);
536 (graphList + graphNum)->
setUnitZ(unitz);
547 void vpPlot::setLegend(
const unsigned int graphNum,
const unsigned int curveNum,
const std::string &legend)
549 (graphList + graphNum)->
setLegend(curveNum, legend);
562 for (
unsigned int i = 0; i < (graphList + graphNum)->curveNbr; i++)
563 (graphList + graphNum)->resetPointList(i);
574 void vpPlot::setThickness(
const unsigned int graphNum,
const unsigned int curveNum,
const unsigned int thickness)
576 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
589 for (
unsigned int curveNum = 0; curveNum < (graphList + graphNum)->curveNbr; curveNum++)
590 (graphList + graphNum)->setCurveThickness(curveNum, thickness);
646 void vpPlot::saveData(
const unsigned int graphNum,
const std::string &dataFile,
const std::string &title_prefix)
648 std::ofstream fichier;
649 fichier.open(dataFile.c_str());
652 double *p =
new double[3];
655 std::vector<std::list<double>::const_iterator> vec_iter_pointListx((graphList + graphNum)->curveNbr);
656 std::vector<std::list<double>::const_iterator> vec_iter_pointListy((graphList + graphNum)->curveNbr);
657 std::vector<std::list<double>::const_iterator> vec_iter_pointListz((graphList + graphNum)->curveNbr);
659 fichier << title_prefix << (graphList + graphNum)->title << std::endl;
661 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
662 vec_iter_pointListx[ind] = (graphList + graphNum)->curveList[ind].pointListx.begin();
663 vec_iter_pointListy[ind] = (graphList + graphNum)->curveList[ind].pointListy.begin();
664 vec_iter_pointListz[ind] = (graphList + graphNum)->curveList[ind].pointListz.begin();
670 while (end ==
false) {
672 for (ind = 0; ind < (graphList + graphNum)->curveNbr; ind++) {
678 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
679 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
680 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end())) {
681 p[0] = *vec_iter_pointListx[ind];
682 p[1] = *vec_iter_pointListy[ind];
683 p[2] = *vec_iter_pointListz[ind];
691 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
692 ++vec_iter_pointListx[ind];
693 ++vec_iter_pointListy[ind];
694 ++vec_iter_pointListz[ind];
703 if ((vec_iter_pointListx[ind] != (graphList + graphNum)->curveList[ind].pointListx.end()) &&
704 (vec_iter_pointListy[ind] != (graphList + graphNum)->curveList[ind].pointListy.end()) &&
705 (vec_iter_pointListz[ind] != (graphList + graphNum)->curveList[ind].pointListz.end()))
714 p[0] = (graphList + graphNum)->curveList[ind].pointListx.back();
715 p[1] = (graphList + graphNum)->curveList[ind].pointListy.back();
716 p[2] = (graphList + graphNum)->curveList[ind].pointListz.back();
717 fichier << p[0] <<
"\t" << p[1] <<
"\t" << p[2] <<
"\t";
720 fichier << std::endl;
727 #elif !defined(VISP_BUILD_SHARED_LIBS) 729 void dummy_vpPlot(){};
Implementation of a generic rotation vector.
void initRange(const unsigned int graphNum, double xmin, double xmax, double ymin, double ymax)
void setColor(const unsigned int graphNum, const unsigned int curveNum, vpColor color)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
vpImage< unsigned char > I
void init(unsigned int height, unsigned int width)
Set the size of the image.
Implementation of row vector and the associated operations.
Class to define colors available for display functionnalities.
vpDisplayGDI()
Basic constructor.
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void setUnitX(const unsigned int graphNum, const std::string &unitx)
error that can be emited by ViSP classes.
unsigned int getRows() const
bool inRectangle(const vpRect &rect) const
void saveData(const unsigned int graphNum, const std::string &dataFile, const std::string &title_prefix="")
unsigned int size() const
Return the number of elements of the 2D array.
void plot(const unsigned int graphNum, const unsigned int curveNum, const double x, const double y)
void setUnitY(const unsigned int graphNum, const std::string &unity)
void setTitle(const unsigned int graphNum, const std::string &title)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
void setGridThickness(const unsigned int graphNum, const unsigned int thickness)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
VISP_EXPORT void sleepMs(double t)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void init(const unsigned int nbGraph, const unsigned int height=700, const unsigned int width=700, const int x=-1, const int y=-1, const std::string &title="")
void getPixelValue(const bool block)
void setLegend(const unsigned int graphNum, const unsigned int curveNum, const std::string &legend)
void initGraph(unsigned int graphNum, unsigned int curveNbr)
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
void resetPointList(const unsigned int graphNum)
void setGraphThickness(const unsigned int graphNum, const unsigned int thickness)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setThickness(const unsigned int graphNum, const unsigned int curveNum, const unsigned int thickness)
Class that consider the case of a translation vector.
void setUnitZ(const unsigned int graphNum, const std::string &unitz)