fshake3d  0.0.1
FreeformDensity3DSurfaceEditor
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
scene_Plot1D.cpp
Go to the documentation of this file.
00001 #include "scene_Plot1D.hpp"
00002 #include "opengl.hpp"
00003 
00004 Plot1D::Plot1D()
00005 : mEnabled(true)
00006 , mPosition( Point3d(0,0,0) )
00007 , mColor( Vec4d(1.0,1.0,1.0,1.0) )
00008 , mSteps(100)
00009 , mXLimits( Vec2d(-1,1) )
00010 , mXAxis(0)
00011 , mYAxis(1)
00012 , mFunc1D(0)
00013 , mYScale(0)
00014 {
00015 }
00016 
00017 void Plot1D::setEnabled(bool e)
00018 {
00019   mEnabled = e;
00020 }
00021 void Plot1D::setPosition(const Point3d& p)
00022 {
00023   mPosition = p;
00024 }
00025 void Plot1D::setColor(const Vec4d& c)
00026 {
00027   mColor = c;
00028 }
00029 void Plot1D::setSteps(int steps)
00030 {
00031   mSteps = steps;
00032 }
00033 void Plot1D::setXLimits(const Vec2d& xlimits)
00034 {
00035   mXLimits = xlimits;
00036 }
00037 void Plot1D::setXAxis(int xaxis)
00038 {
00039   mXAxis = xaxis;
00040 }
00041 void Plot1D::setYAxis(int yaxis)
00042 {
00043   mYAxis = yaxis;
00044 }
00045 void Plot1D::setFunction(const boost::function1<double,double>& f1d)
00046 {
00047   mFunc1D = f1d;
00048 }
00049 void Plot1D::setYScale(double yscale)
00050 {
00051   mYScale = yscale;
00052 }
00053 
00054 void Plot1D::display()
00055 {
00056   if (mEnabled)
00057   {
00058     if (mFunc1D)
00059     {
00060       glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT);
00061 
00062       if (mColor[3] != 1.0)
00063         glEnable(GL_BLEND);
00064 
00065       gl_set_color(mColor);
00066       glLineWidth(3.0);
00067 
00068       glBegin(GL_LINE_STRIP);
00069       double unit = ( (mXLimits[1]-mXLimits[0]) / (mSteps-1) );
00070       for (int ix=0; ix < mSteps ; ++ix)
00071       {
00072         double x = mXLimits[0] + unit * ix;    
00073         double y = mFunc1D(x);
00074 
00075         Point3d p = mPosition;
00076         p[mXAxis] = x;
00077         p[mYAxis] = y * mYScale;
00078         glVertex3d(p[0],p[1],p[2]);
00079       }
00080       glEnd();
00081 
00082       glPopAttrib();
00083     }
00084   }
00085 }