Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
OpenGLView Class Reference

The ViewBase class using OpenGL for drawing. More...

#include <OpenGLView.h>

Inheritance diagram for OpenGLView:
Inheritance graph
[legend]
Collaboration diagram for OpenGLView:
Collaboration graph
[legend]

Public Member Functions

virtual void drawColorLines (const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, const std::vector< hippodraw::Color > &colors, float size)
 Draws multiple line segments, each with a different color - that is, a line between x0,y0 and x1,y1, with color[0] =color[1] another between x2,y2 and x3,y3 with color[2]=color[3] and so on.
virtual void drawImage (const std::string &filename, int position=0)
 Draws a image.
virtual void drawLatex (const std::string &eq, int position=0)
 Draws a Latex equation.
virtual void drawLines (const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, const hippodraw::Color &color, float)
 Draws multiple line segments - that is, a line between x0,y0 and x1,y2, another between x2,y2 and x3,y3 and so on.
virtual void drawMag (float x, float y, int mag, float fontsize)
virtual void drawPoints (const std::vector< double > &x, const std::vector< double > &y, hippodraw::Symbol::Type type, float sym_size, const hippodraw::Color &color)
 Draws symbol points.
virtual void drawPoints (const std::vector< double > &x, const std::vector< double > &y, const std::vector< hippodraw::Color > &colors, hippodraw::Symbol::Type type, float sym_size)
 Draws symbol points.
virtual void drawPolygon (const std::vector< double > &xpoints, const std::vector< double > &ypoints, const Color &color, const Color &edge)
 Draws a polygon.
virtual void drawPolyLine (const std::vector< double > &xpoints, const std::vector< double > &ypoints, hippodraw::Line::Style style, const hippodraw::Color &color, float)
 Draws a polyline.
virtual void drawSelf ()
 Draws itself.
virtual void drawSquare (double x1, double y1, double x2, double y2, int red, int green, int blue)
 Draws a colored square.
virtual void drawText (const std::string &s, float x, float y, float fontsize, float angle, char xp, char yp, bool resize=false)
virtual void drawText (const std::string &s, float x, float y, float fontsize, float angle, char xp, char yp, bool resize=false, const hippodraw::FontBase *font=0, const hippodraw::Color *color=0)
 Draws a text string at a point in the view's coordinate system.
virtual void drawViewLines (const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, bool color, float)
 Draws multiple line segments.
virtual void drawViewLines (const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, const hippodraw::Color &color, float)
 Draws multiple line segments.
virtual void drawViewSquare (float x1, float y1, float x2, float y2, int red, int green, int blue)
 Draws a colored square in view space.
virtual double getAspectRatio () const
 Get the aspect ratio.
virtual hippodraw::Rect getDrawRect () const
 Returns the drawing Rectangle in the devices coordinate system.
const RectgetMarginRect () const
 Returns the rectangle area in which data points are drawn.
hippodraw::PlotterBasegetPlotter () const
 Returns the plotter used by this view.
PlotterBasegetPlotter ()
 Returns the plotter used by this view.
const RangegetRange (Axes::Type axis) const
 Returns the range of the data space on specified axis.
const RectgetRawRect () const
 Returns the rectangle before transform.
const RectgetUserRect () const
 Is called by the AxisRepBase object (or one of its derived objects), and returns the rectangle where the drawing is made.
 OpenGLView ()
virtual void setDrawRect (float x, float y, float w, float h)
 Sets the drawing Rectangle in the devices coordinate system.
void setMarginRect (const Rect &)
 Sets the margin rectangle.
void setPlotter (hippodraw::PlotterBase *)
 Sets the PlotterBase object to plotter.
void setRect (double x, double y, double w, double h)
virtual void update (const hippodraw::Observable *)
 Implements the update method of the Observer pattern.
virtual void updateDrawRect ()
 Update the drawing Rectangle in the devices coordinate system.
float userToDrawColor (double c) const
 Converts a coordinate in user space to drawing space along the color (X) axis.
float userToDrawX (double x) const
 Converts a coordinate in user space to drawing space along the X axis.
float userToDrawXAutoInv (double x) const
float userToDrawY (double x) const
 Converts a coordinate in user space to drawing space along the Y axis.
virtual void willDelete (const Observable *plotter)
 Responds to notification that the PlotterBase object is being deleted.
virtual ~OpenGLView ()

Protected Member Functions

virtual double marginToInvertedUserX (double x) const
 Converts from view coordinate to data conordiate, take into account the inversion of x axes.
virtual double marginToInvertedUserY (double y) const
 Converts from inverted view coordinate to data coordinate, without taking into account transforms or scaling.
virtual double marginToUserX (double x) const
 Converts from view coordinate to data coordinate, without taking into account transforms or scaling.
virtual double marginToUserY (double y) const
 Converts from view coordinate to data coordinate, without taking into account transforms or scaling.
void prepareMarginRect ()
 Prepares the margin rectangle.
virtual float userToInvertedMarginX (double x) const
 Converts the user X coordinate into the inverted X coordinate.
virtual float userToInvertedMarginY (double y) const
 Converts the user Y coordinate into the top-left based margin Y coordinate.
virtual float userToMarginColor (double c) const
 Converts the user Z coordinate into the margin color (X) coordinate.
virtual float userToMarginX (double x) const
 Converts the user X coordinate into the margin X coordinate.
virtual float userToMarginY (double y) const
 Converts the user Y coordinate into the margin Y coordinate.

Protected Attributes

Rect m_margin_rect
 The rectangle area in which the projected points are plotted.
PlotterBase * m_plotter
 The plotter object used by this view.

Private Member Functions

void draw_Text (const std::string &s, float x, float y, float fontsize, float angle, char xp, char yp, const hippodraw::FontBase *font=0)
float toCanvasX (double datX) const
float toCanvasY (double datY) const
float toViewX (double datX) const
float toViewY (double datY) const
float toX (double x) const
float toY (double y) const

Private Attributes

hippodraw::Rect m_draw_rect
hippodraw::TextTTFm_TTF

Detailed Description

The ViewBase class using OpenGL for drawing.

Attention
This class was contributed by its author as an experiment to evaluate the core library classes with OpenGL. The author reports: "Now the plotting is very close to what you have with Qt drawing lib." This class and others in this directory require CMT for its build.
Author
Guy Barrand barra.nosp@m.nd@l.nosp@m.al.in.nosp@m.2p3..nosp@m.fr

Definition at line 26 of file OpenGLView.h.

Constructor & Destructor Documentation

Definition at line 36 of file OpenGLView.cxx.

References m_draw_rect, m_TTF, and Rect::setRect().

~OpenGLView ( )
virtual

Definition at line 44 of file OpenGLView.cxx.

References m_TTF.

Member Function Documentation

void draw_Text ( const std::string &  s,
float  x,
float  y,
float  fontsize,
float  angle,
char  xp,
char  yp,
const hippodraw::FontBase font = 0 
)
private
void drawColorLines ( const std::vector< double > &  x,
const std::vector< double > &  y,
hippodraw::Line::Style  style,
const std::vector< hippodraw::Color > &  color,
float  size 
)
virtual

Draws multiple line segments, each with a different color - that is, a line between x0,y0 and x1,y1, with color[0] =color[1] another between x2,y2 and x3,y3 with color[2]=color[3] and so on.

x pairs of coordinates in user space on the X axis for the beginning and the end of the line segment.

y pairs of coordinates in user space on the Y axis for the beginning and the end of the line segment.

style the line style.

color The RGB values for the color of the line.

size The thickness of the line.

Implements ViewBase.

Definition at line 118 of file OpenGLView.cxx.

References hippodraw::Line::Dash, hippodraw::Line::DashDot, hippodraw::Line::Dot, Color::getBlue(), Color::getGreen(), Color::getRed(), hippodraw::Line::Solid, toViewX(), and toViewY().

void drawImage ( const std::string &  filename,
int  position = 0 
)
virtualinherited

Draws a image.

This is called by drawLatex. Meaning of position: 0.Full 1.Top 2.Bottom 3.Left TODO: use enum for position.

Reimplemented in QtViewImp.

Definition at line 112 of file ViewBase.cxx.

void drawLatex ( const std::string &  eq,
int  position = 0 
)
virtualinherited

Draws a Latex equation.

This function will call drawImage. Meaning of position: 0.Full 1.Top 2.Bottom 3.Left

Reimplemented in QtViewImp.

Definition at line 119 of file ViewBase.cxx.

Referenced by BoxTextRep::drawProjectedValues(), AxisRepBase::drawTitle(), AxisRepBase::drawXLabels(), AxisRepBase::drawYLabels(), and AxisRepColor::drawZLabels().

void drawLines ( const std::vector< double > &  x,
const std::vector< double > &  y,
hippodraw::Line::Style  style,
const hippodraw::Color color,
float  size 
)
virtual

Draws multiple line segments - that is, a line between x0,y0 and x1,y2, another between x2,y2 and x3,y3 and so on.

x pairs of coordinates in user space on the X axis for the beginning and the end of the line segment. y pairs of coordinates in user space on the Y axis for the beginning and the end of the line segment. style the line style. color The color size The thickness of the line.

Implements ViewBase.

Definition at line 67 of file OpenGLView.cxx.

References hippodraw::Line::Dash, hippodraw::Line::DashDot, hippodraw::Line::Dot, Color::getBlue(), Color::getGreen(), Color::getRed(), hippodraw::Line::Solid, toViewX(), and toViewY().

void drawMag ( float  x,
float  y,
int  mag,
float  fontsize 
)
virtual

Definition at line 501 of file OpenGLView.cxx.

References draw_Text(), toX(), and toY().

void drawPoints ( const std::vector< double > &  x,
const std::vector< double > &  y,
hippodraw::Symbol::Type  type,
float  sym_size,
const hippodraw::Color color 
)
virtual

Draws symbol points.

x and y are the coordinates, type is the type of symbol, and sym_size is the size. All symbols are draw in the same color.

Implements ViewBase.

Definition at line 312 of file OpenGLView.cxx.

References hippodraw::Symbol::CIRCLE, hippodraw::Symbol::FILLED_CIRCLE, hippodraw::Symbol::FILLED_TRIANGLE, Color::getBlue(), Color::getGreen(), Color::getRed(), hippodraw::Symbol::PLUS, hippodraw::Symbol::SOLIDSQUARE, hippodraw::Symbol::SQUARE, hippodraw::Symbol::TIMES, toViewX(), toViewY(), and hippodraw::Symbol::TRIANGLE.

void drawPoints ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< hippodraw::Color > &  colors,
hippodraw::Symbol::Type  type,
float  sym_size 
)
virtual

Draws symbol points.

x and y are the coordinates, type is the type of symbol, and sym_size is the size. hue is the hue parameters for each point. The saturation and brightness are set to 1.0.

Implements ViewBase.

Definition at line 402 of file OpenGLView.cxx.

void drawPolygon ( const std::vector< double > &  xpoints,
const std::vector< double > &  ypoints,
const Color color,
const Color edge 
)
virtualinherited

Draws a polygon.

xpoints points along the X axis. ypoints points along the Y axis. color The color.

Reimplemented in QtViewImp.

Definition at line 126 of file ViewBase.cxx.

void drawPolyLine ( const std::vector< double > &  xpoints,
const std::vector< double > &  ypoints,
hippodraw::Line::Style  style,
const hippodraw::Color color,
float  size 
)
virtual

Draws a polyline.

xpoints points along the X axis. ypoints points along the Y axis. style the line style. color The color. size The thickness of the line.

Implements ViewBase.

Definition at line 232 of file OpenGLView.cxx.

References hippodraw::Line::Dash, hippodraw::Line::DashDot, hippodraw::Line::Dot, Color::getBlue(), Color::getGreen(), Color::getRed(), hippodraw::Line::Solid, toViewX(), and toViewY().

void drawSelf ( )
virtualinherited
void drawSquare ( double  x1,
double  y1,
double  x2,
double  y2,
int  red,
int  green,
int  blue 
)
virtual

Draws a colored square.

Used for shading on the cuts and the gray plot.

Implements ViewBase.

Definition at line 270 of file OpenGLView.cxx.

References toViewX(), and toViewY().

void drawText ( const std::string &  s,
float  x,
float  y,
float  fontsize,
float  angle,
char  xp,
char  yp,
bool  resize = false 
)
virtual

Definition at line 546 of file OpenGLView.cxx.

References draw_Text(), toX(), and toY().

void drawText ( const std::string &  s,
float  x,
float  y,
float  fontsize,
float  angle,
char  xp,
char  yp,
bool  resize = false,
const hippodraw::FontBase font = 0,
const hippodraw::Color color = 0 
)
virtual

Draws a text string at a point in the view's coordinate system.

Parameters
sThe string to be drawn.
xThe x coordinate in the view's coordinate system.
yThe y coordinate in the view's coordinate system.
fontsizeThe font size. If zero, then taken from the font object.
angleThe angle to draw. 90 degrees is vertical with the beginning of the text towards the bottom.
xpThe horizontal alignment with respect to the coordinate. 'r' means the coordinate is on the right side of the text, 'c' means centered, and 'l' for the left side.
ypThe vertical alignment with respect to the coordinate. 't' means toward the top, 'c' means centered, and 'b' means bottom.
resizeIf true, the bounding rectangle of the view should be re-sized to fit the text string.
fontIf not a null pointer, then the font object to be used, otherwise the default font will be used.
colorIf not given as argument, the default color is that of the default Color constructor which is black.

Implements ViewBase.

Definition at line 556 of file OpenGLView.cxx.

References draw_Text(), toX(), and toY().

void drawViewLines ( const std::vector< double > &  x,
const std::vector< double > &  y,
hippodraw::Line::Style  style,
bool  color,
float  size 
)
virtual

Draws multiple line segments.

x pairs of coordinates in view space on the X axis for the beginning and the end of the line segment. y pairs of coordinates in view space on the Y axis for the beginning and the end of the line segment. style the line style. color if true, use the display's point color; otherwise, use the default color. size The thickness of the line.

Implements ViewBase.

Definition at line 160 of file OpenGLView.cxx.

References hippodraw::Line::Dash, hippodraw::Line::DashDot, hippodraw::Line::Dot, hippodraw::Line::Solid, toX(), and toY().

void drawViewLines ( const std::vector< double > &  x,
const std::vector< double > &  y,
hippodraw::Line::Style  style,
const hippodraw::Color color,
float  size 
)
virtual

Draws multiple line segments.

x pairs of coordinates in view space on the X axis for the beginning and the end of the line segment. y pairs of coordinates in view space on the Y axis for the beginning and the end of the line segment. style the line style. color The color size The thickness of the line.

Implements ViewBase.

Definition at line 196 of file OpenGLView.cxx.

References hippodraw::Line::Dash, hippodraw::Line::DashDot, hippodraw::Line::Dot, Color::getBlue(), Color::getGreen(), Color::getRed(), hippodraw::Line::Solid, toX(), and toY().

void drawViewSquare ( float  x1,
float  y1,
float  x2,
float  y2,
int  red,
int  green,
int  blue 
)
virtual

Draws a colored square in view space.

Used for shading on the cuts and the gray plot.

Implements ViewBase.

Definition at line 291 of file OpenGLView.cxx.

References toX(), and toY().

double getAspectRatio ( ) const
virtualinherited
Rect getDrawRect ( ) const
virtual

Returns the drawing Rectangle in the devices coordinate system.

Must be implemented in derived class.

Implements ViewBase.

Definition at line 594 of file OpenGLView.cxx.

References m_draw_rect.

const Rect & getMarginRect ( ) const
inherited
PlotterBase * getPlotter ( ) const

Returns the plotter used by this view.

Reimplemented from ViewBase.

Definition at line 61 of file OpenGLView.cxx.

PlotterBase * getPlotter ( )
inherited

Returns the plotter used by this view.

Definition at line 55 of file ViewBase.cxx.

References ViewBase::m_plotter.

const Range & getRange ( Axes::Type  axis) const
inherited

Returns the range of the data space on specified axis.

Definition at line 69 of file ViewBase.cxx.

References ViewBase::m_plotter.

Referenced by ContourPointRep::drawContourTicks().

const Rect & getRawRect ( ) const
inherited

Returns the rectangle before transform.

Definition at line 83 of file ViewBase.cxx.

References PlotterBase::getRawRect(), and ViewBase::m_plotter.

const Rect & getUserRect ( ) const
inherited
double marginToInvertedUserX ( double  x) const
protectedvirtualinherited

Converts from view coordinate to data conordiate, take into account the inversion of x axes.

Definition at line 187 of file DataView.cxx.

References ViewBase::getUserRect(), Rect::getWidth(), Rect::getX(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by QtView::fillPickedPoint().

double marginToInvertedUserY ( double  y) const
protectedvirtualinherited

Converts from inverted view coordinate to data coordinate, without taking into account transforms or scaling.

Definition at line 209 of file DataView.cxx.

References Rect::getHeight(), ViewBase::getUserRect(), Rect::getY(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by QtViewWidget::fillPickedPoint(), and QtView::fillPickedPoint().

double marginToUserX ( double  x) const
protectedvirtualinherited

Converts from view coordinate to data coordinate, without taking into account transforms or scaling.

Definition at line 176 of file DataView.cxx.

References ViewBase::getUserRect(), Rect::getWidth(), Rect::getX(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by QtViewWidget::fillPickedPoint(), and QtView::fillPickedPoint().

double marginToUserY ( double  y) const
protectedvirtualinherited

Converts from view coordinate to data coordinate, without taking into account transforms or scaling.

Definition at line 198 of file DataView.cxx.

References Rect::getHeight(), ViewBase::getUserRect(), Rect::getY(), DataView::m_margin_rect, and ViewBase::m_plotter.

void prepareMarginRect ( )
protectedinherited
void setDrawRect ( float  x,
float  y,
float  w,
float  h 
)
virtual

Sets the drawing Rectangle in the devices coordinate system.

Implements ViewBase.

Definition at line 598 of file OpenGLView.cxx.

void setMarginRect ( const Rect rect)
inherited

Sets the margin rectangle.

Sets the rectangular are in which the data points are drawn. The coordinate system is that of the view.

Definition at line 52 of file DataView.cxx.

References DataView::m_margin_rect.

void setPlotter ( hippodraw::PlotterBase plotter)
virtual

Sets the PlotterBase object to plotter.

The ViewBase object does not own the plotter. If the plotter is being changed, it is up to client code to decide to destroy the previous plotter or not.

Reimplemented from ViewBase.

Definition at line 55 of file OpenGLView.cxx.

void setRect ( double  x,
double  y,
double  w,
double  h 
)

Definition at line 49 of file OpenGLView.cxx.

References m_draw_rect, and Rect::setRect().

Referenced by OpenGLWindow::paint().

float toCanvasX ( double  datX) const
private

Definition at line 721 of file OpenGLView.cxx.

float toCanvasY ( double  datY) const
private

Definition at line 726 of file OpenGLView.cxx.

float toViewX ( double  datX) const
private
float toViewY ( double  datY) const
private
float toX ( double  x) const
private

Definition at line 732 of file OpenGLView.cxx.

References Rect::getX(), and m_draw_rect.

Referenced by drawMag(), drawText(), drawViewLines(), and drawViewSquare().

float toY ( double  y) const
private

Definition at line 736 of file OpenGLView.cxx.

References Rect::getHeight(), Rect::getY(), and m_draw_rect.

Referenced by drawMag(), drawText(), drawViewLines(), and drawViewSquare().

void update ( const hippodraw::Observable )
virtual

Implements the update method of the Observer pattern.

Derived classes should send a message to what ever object is the parent of this ViewBase object.

Implements ViewBase.

Definition at line 568 of file OpenGLView.cxx.

void updateDrawRect ( )
virtualinherited

Update the drawing Rectangle in the devices coordinate system.

Reimplemented in QtView.

Definition at line 105 of file ViewBase.cxx.

Referenced by XyPlotter::drawIn().

float userToDrawColor ( double  c) const
virtual

Converts a coordinate in user space to drawing space along the color (X) axis.

Implements ViewBase.

Definition at line 587 of file OpenGLView.cxx.

References DataView::userToMarginColor().

float userToDrawX ( double  x) const
virtual

Converts a coordinate in user space to drawing space along the X axis.

Implements ViewBase.

Definition at line 575 of file OpenGLView.cxx.

References DataView::userToMarginX().

float userToDrawXAutoInv ( double  x) const
virtual

Implements ViewBase.

float userToDrawY ( double  y) const
virtual

Converts a coordinate in user space to drawing space along the Y axis.

Implements ViewBase.

Definition at line 581 of file OpenGLView.cxx.

References DataView::userToInvertedMarginY().

float userToInvertedMarginX ( double  x) const
protectedvirtualinherited

Converts the user X coordinate into the inverted X coordinate.

Definition at line 133 of file DataView.cxx.

References ViewBase::getUserRect(), Rect::getWidth(), Rect::getX(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by QtView::toViewX(), EpsView::userToDrawXAutoInv(), and QtViewImp::userToDrawXAutoInv().

float userToInvertedMarginY ( double  y) const
protectedvirtualinherited

Converts the user Y coordinate into the top-left based margin Y coordinate.

Definition at line 154 of file DataView.cxx.

References Rect::getHeight(), ViewBase::getUserRect(), Rect::getY(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by QtViewWidget::toViewY(), QtView::toViewY(), userToDrawY(), EpsView::userToDrawY(), and QtViewImp::userToDrawY().

float userToMarginColor ( double  c) const
protectedvirtualinherited

Converts the user Z coordinate into the margin color (X) coordinate.

Definition at line 165 of file DataView.cxx.

References Rect::getDepth(), ViewBase::getUserRect(), Rect::getWidth(), Rect::getX(), Rect::getZ(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by userToDrawColor(), EpsView::userToDrawColor(), and QtViewImp::userToDrawColor().

float userToMarginX ( double  x) const
protectedvirtualinherited
float userToMarginY ( double  y) const
protectedvirtualinherited

Converts the user Y coordinate into the margin Y coordinate.

Definition at line 144 of file DataView.cxx.

References Rect::getHeight(), ViewBase::getUserRect(), Rect::getY(), DataView::m_margin_rect, and ViewBase::m_plotter.

Referenced by toViewY(), and EpsView::toViewY().

void willDelete ( const Observable plotter)
virtualinherited

Responds to notification that the PlotterBase object is being deleted.

Reimplemented from Observer.

Definition at line 96 of file ViewBase.cxx.

References ViewBase::m_plotter.

Member Data Documentation

hippodraw::Rect m_draw_rect
private

Definition at line 101 of file OpenGLView.h.

Referenced by getDrawRect(), OpenGLView(), setRect(), toViewX(), toViewY(), toX(), and toY().

Rect m_margin_rect
protectedinherited

The rectangle area in which the projected points are plotted.

The coordinate system is that of the view device. X increase to the right and Y increases downward. Outside of this area are the axis labels, title, etc.

Definition at line 48 of file DataView.h.

Referenced by DataView::getMarginRect(), DataView::marginToInvertedUserX(), DataView::marginToInvertedUserY(), DataView::marginToUserX(), DataView::marginToUserY(), DataView::prepareMarginRect(), QtView::setDrawRect(), DataView::setMarginRect(), DataView::userToInvertedMarginX(), DataView::userToInvertedMarginY(), DataView::userToMarginColor(), DataView::userToMarginX(), and DataView::userToMarginY().

PlotterBase* m_plotter
protectedinherited
hippodraw::TextTTF* m_TTF
private

Definition at line 102 of file OpenGLView.h.

Referenced by draw_Text(), OpenGLView(), and ~OpenGLView().


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

Generated for HippoDraw Class Library by doxygen