Thread: [Thplot-cvs] CVS: thplot/src/Draw Symbol.cpp,NONE,1.1 Symbol.h,NONE,1.1 Curve.cpp,1.3,1.4 Curve.h,1.
Status: Pre-Alpha
Brought to you by:
apeden
From: Tony P. <ap...@us...> - 2002-07-06 14:49:43
|
Update of /cvsroot/thplot/thplot/src/Draw In directory usw-pr-cvs1:/tmp/cvs-serv19951 Modified Files: Curve.cpp Curve.h Makefile.am Added Files: Symbol.cpp Symbol.h Log Message: Support for mulitple symbol types. --- NEW FILE --- /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Header: Symbol.cpp Author: Tony Peden Date started: 7/6/02 ------------- Copyright (C) 2002 Tony Peden (ap...@ea...) ----------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Further information about the GNU General Public License can also be found on the world wide web at http://www.gnu.org. */ #include <iostream> #include <FL/gl.h> #include <GL/gl.h> #include <Main/Globals.h> #include <Draw/Symbol.h> Symbol::Symbol(SymbolType type, bool fill) { stype=type; filled=fill; regen=true; listid=0; radius=1.5; } Symbol::~Symbol(void) { if(listid) glDeleteLists(listid,1); } void Symbol::DrawGL(float x, float y) { if(regen) { if(listid) glDeleteLists(listid,1); listid=0; listid=glGenLists(1); genList(); } glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(x,y,0); glCallList(listid); glPopMatrix(); } void Symbol::genList(void) { glNewList(listid, GL_COMPILE); glColor3f(0,0,0); glLineWidth(1); glPointSize(1); glBegin(GL_POINTS); glVertex2f(0,0); glEnd(); switch(stype) { case circle: case triangle: case square: case pentagon: int sides; float x,y; if( stype == circle ) { sides=10; } else sides = int(stype); glBegin(GL_LINE_LOOP); for(float i=0;i<sides;i++) { x=radius*cos(i/sides*2*TH_PI); y=radius*sin(i/sides*2*TH_PI); glVertex2f(x,y); } glEnd(); break; case plussign: glBegin(GL_LINES); glVertex2f(-radius,0); glVertex2f(radius,0); glEnd(); glBegin(GL_LINES); glVertex2f(0,-radius); glVertex2f(0,radius); glEnd(); break; case diamond: glBegin(GL_LINE_LOOP); glVertex2f(0,radius); glVertex2f(0.75*radius,0); glVertex2f(0,-radius); glVertex2f(-0.75*radius,0); glEnd(); break; } glEndList(); } --- NEW FILE --- /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Header: Symbol.h Author: Tony Peden Date started: 7/6/02 ------------- Copyright (C) 2002 Tony Peden (ap...@ea...) ----------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Further information about the GNU General Public License can also be found on the world wide web at http://www.gnu.org. */ #ifndef SYMBOL_H #define SYMBOL_H #include <FL/gl.h> #include <GL/gl.h> typedef enum { circle=0, plussign, diamond, triangle, square, pentagon } SymbolType; const int NSymbolTypes=6; class Symbol { public: Symbol(SymbolType type, bool fill); ~Symbol(void); void setType(SymbolType type) { stype=type; regen=true; } SymbolType getType(void) { return stype; } void setFilled(bool fill) { filled=fill; regen=true; } bool getFilled(void) { return filled; } void setRadius(float r) { radius=r; regen=true; } float getRadius(void) { return radius; } void DrawGL(float x, float y); private: SymbolType stype; bool filled; bool regen; float radius; GLuint listid; void genList(void); }; #endif Index: Curve.cpp =================================================================== RCS file: /cvsroot/thplot/thplot/src/Draw/Curve.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** Curve.cpp 4 Jul 2002 15:53:26 -0000 1.3 --- Curve.cpp 6 Jul 2002 14:49:40 -0000 1.4 *************** *** 26,30 **** --- 26,32 ---- #include <Draw/Curve.h> + #include <Draw/Symbol.h> #include <Data/csvData.h> + Curve::Curve(Globals *g, Grid *p, int idx){ *************** *** 32,41 **** parent=p; index=idx; ! lines=true; ! symbols=false; ! lstyle=linestyles(index % Nstyles); }; ! Curve::~Curve(void) {} --- 34,46 ---- parent=p; index=idx; ! lines_on=true; ! symbols_on=true; ! lstyle=solid; ! //lstyle=linestyles(index % Nstyles); ! symbols = new Symbol(SymbolType(index % NSymbolTypes),false); ! xthreshold=2;ythreshold=5; }; ! Curve::~Curve(void) { delete symbols; } *************** *** 48,66 **** iIndep = d->getParameterIdx( parent->getIndepName() ); ! if( symbols ) { ! glPointSize(4); ! // Makes points round rather than boxes ! glEnable(GL_POINT_SMOOTH); ! glColor3f(0,0,0); ! glBegin(GL_POINTS); for(int i=0;i<d->getNumPoints(iIndep);i++) { x = parent->convertIndepCoord( d->getValue(iIndep,i) ); y = parent->convertDepCoord( d->getValue(iDep,i) ); ! glVertex2f(x,y); } - glEnd(); } ! if(lines) { if(lstyle == solid) { glDisable(GL_LINE_STIPPLE); --- 53,71 ---- iIndep = d->getParameterIdx( parent->getIndepName() ); ! if( symbols_on ) { ! float lastx, lasty,dx,dy; ! lastx=lasty=0; for(int i=0;i<d->getNumPoints(iIndep);i++) { x = parent->convertIndepCoord( d->getValue(iIndep,i) ); y = parent->convertDepCoord( d->getValue(iDep,i) ); ! dx = x - lastx; dy = y - lasty; ! if( i==0 || dx > xthreshold || dy > ythreshold) { ! symbols->DrawGL(x,y); ! lastx=x;lasty=y; ! } } } ! if(lines_on) { if(lstyle == solid) { glDisable(GL_LINE_STIPPLE); Index: Curve.h =================================================================== RCS file: /cvsroot/thplot/thplot/src/Draw/Curve.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** Curve.h 4 Jul 2002 15:53:26 -0000 1.3 --- Curve.h 6 Jul 2002 14:49:40 -0000 1.4 *************** *** 31,34 **** --- 31,35 ---- #include <Data/csvData.h> #include <Main/Globals.h> + #include <Draw/Symbol.h> #include <Draw/Grid.h> *************** *** 43,48 **** ~Curve(void); ! void LinesOn(bool tt) { lines = tt; } ! void SymbolsOn(bool tt) { symbols = tt; } bool DrawGL(void); --- 44,55 ---- ~Curve(void); ! void LinesOn(bool tt) { lines_on = tt; } ! void SymbolsOn(bool tt) { symbols_on = tt; } ! ! void setSymbolDrawXThreshold( float xt ) { xthreshold=xt; } ! float getSymbolDrawXThreshold( void ) { return xthreshold; } ! ! void setSymbolDrawYThreshold( float yt ) { ythreshold=yt; } ! float getSymbolDrawYThreshold( void ) { return ythreshold; } bool DrawGL(void); *************** *** 51,59 **** Globals *global; Grid *parent; csvData *data; int index; string ind_pname, dep_pname; ! bool lines, symbols; linestyles lstyle; }; --- 58,68 ---- Globals *global; Grid *parent; + Symbol *symbols; csvData *data; int index; string ind_pname, dep_pname; ! bool lines_on, symbols_on; linestyles lstyle; + float xthreshold,ythreshold; }; Index: Makefile.am =================================================================== RCS file: /cvsroot/thplot/thplot/src/Draw/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** Makefile.am 22 Jun 2002 11:57:09 -0000 1.1.1.1 --- Makefile.am 6 Jul 2002 14:49:40 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- Plot.cpp Plot.h \ Curve.cpp Curve.h \ + Symbol.cpp Symbol.h \ drawObject.cpp drawObject.h |