Plot 2D curves example.
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpMath.h>
#include <visp3/gui/vpPlot.h>
int main()
{
#if defined(VISP_HAVE_DISPLAY)
#ifdef ENABLE_VISP_NAMESPACE
#endif
try {
vpPlot plot(2, 700, 700, 100, 200,
"Curves...");
plot.initGraph(0, 1);
plot.initGraph(1, 1);
char title[40];
strncpy(title, "cos function", 40);
plot.setTitle(0, title);
strncpy(title, "sin function", 40);
plot.setTitle(1, title);
char legend[40];
strncpy(legend, "cos x", 40);
plot.setLegend(0, 0, legend);
strncpy(legend, "sin x", 40);
plot.setLegend(1, 0, legend);
char unit[40];
strncpy(unit, "x", 40);
plot.setUnitX(0, unit);
strncpy(unit, "x", 40);
plot.setUnitX(1, unit);
strncpy(unit, "y", 40);
plot.setUnitY(0, unit);
strncpy(unit, "y", 40);
plot.setUnitY(1, unit);
double i = 0;
while (i <= 20 * 2 * M_PI) {
double co = cos(i);
double si = sin(i);
plot.plot(0, 0, i, co);
plot.plot(1, 0, i, si);
i += 0.1;
}
plot.saveData(0, "dataCos.txt", "# ");
plot.saveData(1, "dataSin.txt", "# ");
return EXIT_SUCCESS;
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
#else
std::cout << "Plot functionalities are not avalaible since no display is "
"available."
<< std::endl;
return EXIT_SUCCESS;
#endif
}
static const vpColor green
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emitted by ViSP classes.
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...