Files Classes Functions Hierarchy
00001 00002 #include <pointsgraph.h> 00003 #include <zero.h> 00004 00005 bool pointsgraph::isinside=true; 00006 00007 pointsgraph::pointsgraph() : 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 } 00013 00014 pointsgraph::pointsgraph 00015 ( 00016 windowscaleD2 const & screen_, 00017 windowscaleD2 const & world_, 00018 boolc clipwindow_ 00019 ) 00020 : screen(screen_), world(world_), 00021 clipwindow(clipwindow_) 00022 { 00023 } 00024 00025 00026 void pointsgraph::draw() 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 } 00064 00065 void pointsgraph::screen_rescaley() 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 } 00095 00096 void pointsgraph::update() 00097 { 00098 screen.update(); 00099 world.update(); 00100 } 00101 00102 void pointsgraph::domain(doublec x0, doublec x1) 00103 { 00104 assert( x0<=x1 ); 00105 screen.xmin=x0; 00106 screen.xmax=x1; 00107 screen.update(); 00108 } 00109 00110 pointsgraph_axes_circle::pointsgraph_axes_circle() 00111 { 00112 quadric.radius = 0.02; 00113 quadric.slices=20; 00114 quadric.loops=6; 00115 00116 disablelighting=true; 00117 00118 xaxiscolor = gobjglColor3d(0.0,.62,.33); 00119 yaxiscolor = gobjglColor3d(0.05,.12,.83); 00120 00121 graphics = new gobjContainer(); 00122 } 00123 00124 pointsgraph_axes_circle::~pointsgraph_axes_circle() 00125 { 00126 delete graphics; 00127 graphics=0; 00128 } 00129 00130 void pointsgraph_axes_circle::update() 00131 { 00132 assert(graphics); 00133 00134 graphics->nuke(); 00135 00136 push(new gobjglPushAttrib(GL_CURRENT_BIT)); 00137 push(new gobjglPushAttrib(GL_LIGHTING_BIT)); 00138 if (disablelighting) 00139 push(new gobjglDisable(GL_LIGHTING)); 00140 00141 push(new gobjglColor3d(xaxiscolor)); 00142 for (uint i=0; i<xaxis.size(); ++i) 00143 { 00144 push(new 00145 gobjMySphereDraw(point3<double>(origin.x+xaxis[i],origin.y,origin.z),&quadric)); 00146 } 00147 00148 push(new gobjglColor3d(yaxiscolor)); 00149 for (uint i=0; i<yaxis.size(); ++i) 00150 { 00151 push(new 00152 gobjMySphereDraw(point3<double>(origin.x,origin.y+yaxis[i],origin.z),&quadric)); 00153 } 00154 00155 push(new gobjglPopAttrib()); 00156 push(new gobjglPopAttrib()); 00157 } 00158 00159 void pointsgraph_axes_circle::draw() 00160 { 00161 assert(graphics); 00162 graphics->draw(); 00163 } 00164 00165 void pointsgraph_axes_circle::push(gobj* g) 00166 { 00167 assert(graphics); 00168 graphics->push(g); 00169 } 00170 00171 pointsgraphtime::pointsgraphtime(uintc N_) 00172 { 00173 N = N_; 00174 00175 assert(N!=1); 00176 assert(N!=0); 00177 00178 dx = (double)1.0/(N-1); 00179 } 00180 00181 void pointsgraphtime::push_front(double yval) 00182 { 00183 assert(false); // TODO write this function. 00184 for (uint i=0; i<N; ++i) 00185 { pts[i].x += dx; } 00186 00187 pts.push_front( point2<double>(0,yval) ); 00188 00189 if (pts.size()==N) 00190 { 00191 pts.pop_back(); 00192 return; 00193 } 00194 00195 assert(pts.size()<N); 00196 } 00197 00198 void pointsgraphtime::push_back(double yval) 00199 { 00200 uint imax=pts.size(); 00201 for (uint i=0; i<imax; ++i) 00202 { pts[i].x -= dx; } 00203 00204 if (imax==N) 00205 pts.pop_front(); 00206 00207 pts.push_back( point2<double>(1.0,yval) ); 00208 00209 assert(pts.size()<=N); 00210 } 00211 00212 00213 00214
1.5.8