proj home

Files   Classes   Functions   Hierarchy  

pointsgraph Class Reference

Graphics window, so can change viewing window without changing the data. More...

#include <pointsgraph.h>

Inheritance diagram for pointsgraph:
Collaboration diagram for pointsgraph:

List of all members.

Public Member Functions

 pointsgraph ()
 Construct in a bad state.
 pointsgraph (windowscaleD2 const &screen_, windowscaleD2 const &world_, boolc clipwindow_=false)
 Screen projects onto world.
void draw ()
 Draw the object.
template<typename FN >
void samplefunction (FN &fn, uintc N)
 Using the screen space sample N points of a function.
void domain (doublec x0, doublec x1)
 Reset the x-axis domain and update.
void screen_rescaley ()
 Can change domain and need to rescale graph.
void update ()
 Update the windows.

Public Attributes

deque< point2< double > > pts
 Screen space.
windowscaleD2 screen
 Screen window, often changes for what is being displayed.
windowscaleD2 world
 The fixed window.
bool clipwindow
 Do not display points outside the screen.

Static Public Attributes

static bool isinside = true
 Default draw checks conversions are inside world window.


Detailed Description

Graphics window, so can change viewing window without changing the data.

Definition at line 18 of file pointsgraph.h.


Constructor & Destructor Documentation

pointsgraph::pointsgraph (  ) 

Construct in a bad state.

Definition at line 7 of file pointsgraph.cpp.

00007                          : 
00008   screen(0.0,0.0,1.0,1.0), 
00009   world(-1.0,-1.0,1.0,1.0),
00010   clipwindow(false)
00011 {
00012 }

pointsgraph::pointsgraph ( windowscaleD2 const &  screen_,
windowscaleD2 const &  world_,
boolc  clipwindow_ = false 
)

Screen projects onto world.

Definition at line 15 of file pointsgraph.cpp.

00020   : screen(screen_), world(world_), 
00021   clipwindow(clipwindow_)
00022 {
00023 }


Member Function Documentation

void pointsgraph::domain ( doublec  x0,
doublec  x1 
)

Reset the x-axis domain and update.

Definition at line 102 of file pointsgraph.cpp.

References screen, windowscaleD2::update(), windowscaleD2::xmax, and windowscaleD2::xmin.

Referenced by windowscaleD2test::test002().

00103 {
00104   assert( x0<=x1 );
00105   screen.xmin=x0;
00106   screen.xmax=x1;
00107   screen.update();
00108 }

void pointsgraph::draw (  )  [virtual]

Draw the object.

Implements gobj.

Definition at line 26 of file pointsgraph.cpp.

References asserteval, clipwindow, windowscaleD2::convertfrom(), windowscaleD2::isinside(), isinside, pts, screen, SHOW, and world.

00027 {
00028   glBegin(GL_POINTS);
00029 
00030   uint imax=pts.size();
00031 
00032 //assert(clipwindow==false);
00033   if (clipwindow==false)
00034   {
00035     for (uint i=0; i<imax; ++i)
00036     {
00037       double x = pts[i].x;
00038       double y = pts[i].y;
00039 cout << SHOW(x) << " " << SHOW(y) << endl;
00040       if (isinside)
00041         { asserteval(world.convertfrom(x,y,screen)); }  // Coordinates outside window
00042       else
00043         world.convertfrom(x,y,screen); 
00044       glVertex2d(x,y);
00045       //glVertex3d(x,y,0.0);
00046     }
00047   }
00048   else
00049   {
00050     for (uint i=0; i<imax; ++i)
00051     {
00052       double x = pts[i].x;
00053       double y = pts[i].y;
00054       world.convertfrom(x,y,screen);
00055       if (world.isinside(x,y)==false)
00056         continue;
00057 
00058       glVertex2d(x,y);
00059     }
00060   }
00061 
00062   glEnd();
00063 }

template<typename FN >
void pointsgraph::samplefunction ( FN &  fn,
uintc  N 
) [inline]

Using the screen space sample N points of a function.

Endpoints included.

Definition at line 55 of file pointsgraph.h.

References pts, screen, and windowscaleD2::unitscaleInverse_x().

Referenced by windowscaleD2test::test002().

00056   {
00057     double dx = (double)1.0;
00058     dx /= ((double)N-(double)1.0);
00059 
00060     double x;
00061     double y;
00062     for (uint i=0; i<N; ++i)
00063     {
00064       x = dx*i;
00065       screen.unitscaleInverse_x(x);
00066       fn(y,x);
00067     
00068       pts.push_back( point2<double>(x,y) ); 
00069     }
00070   }

void pointsgraph::screen_rescaley (  ) 

Can change domain and need to rescale graph.

Definition at line 65 of file pointsgraph.cpp.

References pts, screen, windowscaleD2::update(), windowscaleD2::xmax, windowscaleD2::xmin, windowscaleD2::ymax, and windowscaleD2::ymin.

Referenced by windowscaleD2test::test002().

00066 {
00067   if (pts.empty())
00068     return;
00069 
00070   double & ymin(screen.ymin);
00071   double & ymax(screen.ymax);
00072   double & xmin(screen.xmin);
00073   double & xmax(screen.xmax);
00074 
00075   ymin = ymax = pts[0].y;
00076 
00077   uint imax=pts.size();
00078   double y;
00079   for (uint i=1; i<imax; ++i)
00080   {
00081     // Only consider points in current domain.
00082     if (pts[i].x<xmin)
00083       continue;
00084     if (pts[i].x>xmax)
00085       continue;
00086 
00087     y = pts[i].y;
00088     if(y<ymin)
00089       ymin=y;
00090     if(y>ymax)
00091       ymax=y;
00092   }  
00093   screen.update();
00094 }

void pointsgraph::update (  ) 

Update the windows.

Reimplemented in pointsgraphtimeD2.

Definition at line 96 of file pointsgraph.cpp.

References screen, windowscaleD2::update(), and world.

Referenced by windowscaleD2test::test002().

00097 {
00098   screen.update();
00099   world.update();
00100 }


Member Data Documentation

Do not display points outside the screen.

Definition at line 45 of file pointsgraph.h.

Referenced by draw(), and windowscaleD2test::test002().

bool pointsgraph::isinside = true [static]

Default draw checks conversions are inside world window.

Definition at line 47 of file pointsgraph.h.

Referenced by draw(), and windowscaleD2test::test002().

deque< point2<double> > pointsgraph::pts

Screen window, often changes for what is being displayed.

Definition at line 38 of file pointsgraph.h.

Referenced by domain(), draw(), samplefunction(), screen_rescaley(), windowscaleD2test::test002(), and update().

The fixed window.

One-one with OpenGL coordinate systmem.

Definition at line 42 of file pointsgraph.h.

Referenced by draw(), windowscaleD2test::test002(), and update().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:10 2011 for Chelton Evans Source by  doxygen 1.5.8