pcl_plotter_demo.cpp
Go to the documentation of this file.
00001 /* \author Kripasindhu Sarkar */
00002 
00003 #include<pcl/visualization/pcl_plotter.h>
00004 
00005 #include<iostream>
00006 #include<vector>
00007 #include<utility>
00008 #include<math.h>  //for abs()
00009 
00010 using namespace std;
00011 using namespace pcl::visualization;
00012 
00013 void
00014 generateData (double *ax, double *acos, double *asin, int numPoints)
00015 {
00016   double inc = 7.5 / (numPoints - 1);
00017   for (int i = 0; i < numPoints; ++i)
00018   {
00019     ax[i] = i*inc;
00020     acos[i] = cos (i * inc);
00021     asin[i] = sin (i * inc);
00022   }
00023 }
00024 
00025 //.....................callback functions defining Y= f(X)....................
00026 double
00027 step (double val)
00028 {
00029   if (val > 0)
00030     return (double) (int) val;
00031   else
00032     return (double) ((int) val - 1);
00033 }
00034 
00035 double
00036 identity (double val)
00037 {
00038   return val;
00039 }
00040 //............................................................................
00041 
00042 int
00043 main (int argc, char * argv [])
00044 {
00045   //defining a plotter
00046   PCLPlotter *plotter = new PCLPlotter ("My Plotter");
00047 
00048   //setting some properties
00049   plotter->setShowLegend (true);
00050 
00051   //generating point correspondances
00052   int numPoints = 69;
00053   double ax[100], acos[100], asin[100];
00054   generateData (ax, acos, asin, numPoints);
00055 
00056   //adding plot data
00057   plotter->addPlotData (ax, acos, numPoints, "cos");
00058   plotter->addPlotData (ax, asin, numPoints, "sin");
00059 
00060   //display for 2 seconds
00061   plotter->spinOnce (3000);
00062   plotter->clearPlots ();
00063   
00064   
00065   //...................plotting implicit functions and custom callbacks....................
00066 
00067   //make a fixed axis
00068   plotter->setYRange (-10, 10);
00069 
00070   //defining polynomials
00071   vector<double> func1 (1, 0);
00072   func1[0] = 1; //y = 1
00073   vector<double> func2 (3, 0);
00074   func2[2] = 1; //y = x^2
00075 
00076   plotter->addPlotData (std::make_pair (func1, func2), -10, 10, "y = 1/x^2", 100, vtkChart::POINTS);
00077   plotter->spinOnce (2000);
00078 
00079   plotter->addPlotData (func2, -10, 10, "y = x^2");
00080   plotter->spinOnce (2000);
00081 
00082   //callbacks
00083   plotter->addPlotData (identity, -10, 10, "identity");
00084   plotter->spinOnce (2000);
00085 
00086   plotter->addPlotData (abs, -10, 10, "abs");
00087   plotter->spinOnce (2000);
00088 
00089   plotter->addPlotData (step, -10, 10, "step", 100, vtkChart::POINTS);
00090   plotter->spinOnce (2000);
00091 
00092   plotter->clearPlots ();
00093 
00094   //........................A simple animation..............................
00095   vector<double> fsq (3, 0);
00096   fsq[2] = -100; //y = x^2
00097   while (!plotter->wasStopped ())
00098   {
00099     if (fsq[2] == 100) fsq[2] = -100;
00100     fsq[2]++;
00101     char str[50];
00102     sprintf (str, "y = %dx^2", (int) fsq[2]);
00103     plotter->addPlotData (fsq, -10, 10, str);
00104 
00105     plotter->spinOnce (100);
00106     plotter->clearPlots ();
00107   }
00108 
00109   return 1;
00110 }
00111 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:28:09