Avogadro  1.1.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Avogadro::GLPainter Class Reference

Implementation of the Painter class using OpenGL. More...

Inheritance diagram for Avogadro::GLPainter:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 GLPainter (int quality=-1)
 ~GLPainter ()
void setQuality (int quality)
int quality () const
void setName (const Primitive *primitive)
void setName (Primitive::Type type, int id)
void setColor (const Color *color)
void setColor (const QColor *color)
void setColor (float red, float green, float blue, float alpha=1.0)
void setColor (QString name)
void drawSphere (const Eigen::Vector3d &center, double radius)
void drawCylinder (const Eigen::Vector3d &end1, const Eigen::Vector3d &end2, double radius)
void drawMultiCylinder (const Eigen::Vector3d &end1, const Eigen::Vector3d &end2, double radius, int order, double shift)
void drawCone (const Eigen::Vector3d &base, const Eigen::Vector3d &cap, double baseRadius, double capRadius=0.0)
void drawLine (const Eigen::Vector3d &start, const Eigen::Vector3d &end, double lineWidth)
void drawMultiLine (const Eigen::Vector3d &start, const Eigen::Vector3d &end, double lineWidth, int order, short stipple)
void drawTriangle (const Eigen::Vector3d &p1, const Eigen::Vector3d &p2, const Eigen::Vector3d &p3)
void drawTriangle (const Eigen::Vector3d &p1, const Eigen::Vector3d &p2, const Eigen::Vector3d &p3, const Eigen::Vector3d &n)
void drawSpline (const QVector< Eigen::Vector3d > &pts, double radius)
void drawShadedSector (const Eigen::Vector3d &origin, const Eigen::Vector3d &direction1, const Eigen::Vector3d &direction2, double radius, bool alternateAngle=false)
void drawArc (const Eigen::Vector3d &origin, const Eigen::Vector3d &direction1, const Eigen::Vector3d &direction2, double radius, double lineWidth, bool alternateAngle=false)
void drawShadedQuadrilateral (const Eigen::Vector3d &point1, const Eigen::Vector3d &point2, const Eigen::Vector3d &point3, const Eigen::Vector3d &point4)
void drawQuadrilateral (const Eigen::Vector3d &point1, const Eigen::Vector3d &point2, const Eigen::Vector3d &point3, const Eigen::Vector3d &point4, double lineWidth)
void drawLineLoop (const QList< Eigen::Vector3d > &points, const double lineWidth)
void drawMesh (const Mesh &mesh, int mode=0)
void drawColorMesh (const Mesh &mesh, int mode=0)
int drawText (int x, int y, const QString &string)
int drawText (const QPoint &pos, const QString &string)
int drawText (const Eigen::Vector3d &pos, const QString &string)
int drawText (const Eigen::Vector3d &pos, const QString &string, const QFont &font)
void drawBox (const Eigen::Vector3d &corner1, const Eigen::Vector3d &corner2)
void drawBoxEdges (const Eigen::Vector3d &offset, const Eigen::Vector3d &v1, const Eigen::Vector3d &v2, const Eigen::Vector3d &v3, const double linewidth)
void drawBoxEdges (const Eigen::Vector3d &c1, const Eigen::Vector3d &c2, const Eigen::Vector3d &c3, const Eigen::Vector3d &c4, const Eigen::Vector3d &c5, const Eigen::Vector3d &c6, const Eigen::Vector3d &c7, const Eigen::Vector3d &c8, const double linewidth)
void drawTorus (const Eigen::Vector3d &pos, double majorRadius, double minorRadius)
void drawEllipsoid (const Eigen::Vector3d &position, const Eigen::Matrix3d &matrix)
void begin (GLWidget *widget)
void end ()
bool isActive ()
bool isShared ()
void setDynamicScaling (bool scaling)

Static Public Member Functions

static int defaultQuality ()
static int maxQuality ()

Protected Member Functions

void incrementShare ()
void decrementShare ()
void pushName ()
void popName ()
void resetName ()
void apply (const Color3f &color)
void applyAsMaterials (const Color3f &color, float alpha=1.0)

Protected Attributes

GLPainterPrivate *const d
bool m_dynamicScaling

Detailed Description

Implementation of the Painter class using OpenGL.

Author:
Marcus D. Hanwell

This class implements the base Painter class using OpenGL. It is intended to be used with the GLWidget to render molecules and other constructs to an OpenGL context.

See also:
Painter

Constructor & Destructor Documentation

Avogadro::GLPainter::GLPainter ( int  quality = -1)

Constructor.

Parameters:
qualitydefaults to -1, valid range from 0 to 4.

References quality().

Destructor.


Member Function Documentation

void Avogadro::GLPainter::apply ( const Color3f color) [inline, protected]

Sets this color to be the one used by OpenGL for rendering when lighting is disabled.

References Avogadro::Color3f::data().

void Avogadro::GLPainter::applyAsMaterials ( const Color3f color,
float  alpha = 1.0 
) [inline, protected]

Applies nice OpenGL materials using this color as the diffuse color while using different shades for the ambient and specular colors. This is only useful if lighting is enabled.

References Avogadro::Color3f::blue(), Avogadro::Color3f::green(), and Avogadro::Color3f::red().

Referenced by drawColorMesh().

Set the Painter up for painting onto a GLWidget, should be called before any painting.

Decrement the number of widgets the Painter is being shared by.

Returns:
the default quality level of the Painter.
void Avogadro::GLPainter::drawArc ( const Eigen::Vector3d &  origin,
const Eigen::Vector3d &  direction1,
const Eigen::Vector3d &  direction2,
double  radius,
double  lineWidth,
bool  alternateAngle = false 
) [virtual]

Draws an arc. The arc is defined by three vectors, the center of the circle, and two vectors that define the lines going out from the center of the circle to the circumference of the circle. The actual points on the circumference are found using these two vectors and the radius of the circle.

Parameters:
originthe center of the circle whose circumference this arc is a portion of.
direction1a vector defining the line the start of the arc will lie on.
direction2a vector defining the line the end of the arc will lie on.
radiusthe radius of the circle whose circumference this arc is a portion of.
lineWidththe thickness of the line the arc will be drawn with.
alternateAnglewhether to draw the obtuse angle made by the two vectors instead of the acute angle between them.

Implements Avogadro::Painter.

References A.

void Avogadro::GLPainter::drawBox ( const Eigen::Vector3d &  corner1,
const Eigen::Vector3d &  corner2 
) [virtual]

Placeholder to draw a box.

Parameters:
corner1First corner of the box.
corner2Second corner of the box.
Todo:
Implement this primitive.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawBoxEdges ( const Eigen::Vector3d &  offset,
const Eigen::Vector3d &  v1,
const Eigen::Vector3d &  v2,
const Eigen::Vector3d &  v3,
const double  linewidth 
) [virtual]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws the outline of a parallelpiped at offset with three vectors v1, v2, and v3 defining the edges.

       6------8  c1 = origin
      /:     /|  c2 = origin + v1
     / :    / |  c3 = origin + v2
    /  4---/--7  c4 = origin + v3
   /  /   /  /   c5 = origin + v1 + v2
  3------5  /    c6 = origin + v2 + v3
  | /    | /     c7 = origin + v1 + v3
  |/     |/      c8 = origin + v1 + v2 + v3
  1------2
Parameters:
offsetCorner of the box.
v1Edge of box, pointing relative to offset.
v2Edge of box, pointing relative to offset.
v3Edge of box, pointing relative to offset.
linewidthThe width of the line.

Reimplemented from Avogadro::Painter.

void Avogadro::GLPainter::drawBoxEdges ( const Eigen::Vector3d &  c1,
const Eigen::Vector3d &  c2,
const Eigen::Vector3d &  c3,
const Eigen::Vector3d &  c4,
const Eigen::Vector3d &  c5,
const Eigen::Vector3d &  c6,
const Eigen::Vector3d &  c7,
const Eigen::Vector3d &  c8,
const double  linewidth 
) [virtual]

Draws the outline of a box with the given corners.

       6------8
      /:     /|
     / :    / |
    /  4---/--7
   /  /   /  /
  3------5  /
  | /    | /
  |/     |/
  1------2
Warning:
The default implementaion of this function simply calls drawLine repeatedly to draw the specified shape. This may be very inefficent on certain paint devices and should be reimplemented in such cases.
Parameters:
c1Corner
c2Corner
c3Corner
c4Corner
c5Corner
c6Corner
c7Corner
c8Corner
linewidthThe width of the line.

Reimplemented from Avogadro::Painter.

void Avogadro::GLPainter::drawColorMesh ( const Mesh mesh,
int  mode = 0 
) [virtual]

Draws a continuous mesh of triangles and respects the colors stored.

Parameters:
meshthe mesh to be drawn.
modethe mode to use. 0 = filled, 1 = lines and 2 = points.

Implements Avogadro::Painter.

References applyAsMaterials(), Avogadro::Mesh::colors(), Avogadro::Mesh::normals(), and Avogadro::Mesh::vertices().

void Avogadro::GLPainter::drawCone ( const Eigen::Vector3d &  base,
const Eigen::Vector3d &  cap,
double  baseRadius,
double  capRadius = 0.0 
) [virtual]

Draws a cone between the tip and the base with the base radius given.

Parameters:
basethe position of the base of the cone.
baseRadiusthe radius of the base of the cone.
capthe position of the tip of the cone.
capRadiusthe radius of the base of the cone.
Note:
The capRadius is currently ignored

Implements Avogadro::Painter.

References cross().

void Avogadro::GLPainter::drawCylinder ( const Eigen::Vector3d &  end1,
const Eigen::Vector3d &  end2,
double  radius 
) [virtual]

Draws a cylinder, leaving the Painter choose the appropriate detail level based on the apparent radius (ratio of radius over distance) and the global quality setting.

Parameters:
end1the position of the first end of the cylinder.
end2the position of the second end of the cylinder.
radiusthe radius, i.e. half-width of the cylinder.

Implements Avogadro::Painter.

References popName(), and pushName().

void Avogadro::GLPainter::drawEllipsoid ( const Eigen::Vector3d &  position,
const Eigen::Matrix3d &  matrix 
) [virtual]

Placeholder to draw an ellipsoid.

Parameters:
posPosition of the center of the ellipsoid.
matrixLinear transformation matrix for scaling and rotation.
Todo:
Implement this primitive.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawLine ( const Eigen::Vector3d &  start,
const Eigen::Vector3d &  end,
double  lineWidth 
) [virtual]

Draws a GL line between the given points of the given width.

Parameters:
startthe position of the start of the line.
endthe position of the end of the line.
lineWidththe width of the GL line.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawLineLoop ( const QList< Eigen::Vector3d > &  points,
const double  lineWidth 
) [virtual]

Draws a closed line loop connecting each of the points in points,

Parameters:
pointsA list of consecutive points defining the line loop
lineWidththe thickness of the line the pentagon will be drawn with.

Reimplemented from Avogadro::Painter.

References QList::constBegin(), and QList::constEnd().

void Avogadro::GLPainter::drawMesh ( const Mesh mesh,
int  mode = 0 
) [virtual]

Draws a continuous mesh of triangles.

Parameters:
meshthe mesh to be drawn.
modethe mode to use. 0 = filled, 1 = lines and 2 = points.

Implements Avogadro::Painter.

References Avogadro::Mesh::normals(), and Avogadro::Mesh::vertices().

void Avogadro::GLPainter::drawMultiCylinder ( const Eigen::Vector3d &  end1,
const Eigen::Vector3d &  end2,
double  radius,
int  order,
double  shift 
) [virtual]

Draws a multiple cylinder (see below), leaving the Painter choose the appropriate detail level based on the apparent radius (ratio of radius over distance) and the global quality setting.

What is a "multiple cylinder"? Think bond of order two or more between two atoms. This function is here to allow drawing multiple bonds in a single call.

This function takes care of rendering multiple bonds in such a way that the individual bonds avoid hiding each other, at least in the defaut viewpoint of a molecule. To achieves that, it asks the GLWidget for the the normal vector of the molecule's best-fitting plane.

Parameters:
end1the position of the first end of the bond.
end2the position of the second end of the bond.
radiusthe radius, i.e. half-width of each cylinder.
orderthe multiplicity order of the bond, e.g. 2 for a double bond. When this parameter equals 1, this function is equivalent to drawCylinder().
shifthow far away from the central axis the cylinders are shifted. In other words this influences the total width of multiple bonds.

Implements Avogadro::Painter.

References popName(), and pushName().

void Avogadro::GLPainter::drawMultiLine ( const Eigen::Vector3d &  start,
const Eigen::Vector3d &  end,
double  lineWidth,
int  order,
short  stipple 
) [virtual]

Draws a multiple GL line between the given points. This function is the GL line equivalent to the drawMultiCylinder function and performs the same basic operations using simpler and quicker GL lines.

Parameters:
startthe position of the start of the line.
endthe position of the end of the line.
lineWidththe width of the GL line.
orderthe order of the bond, e.g. 2 for a double bond.
stippleThe GL stipple parameter for the bond, can be used to draw aromatic bonds etc. sa drawMultiCylinder

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawQuadrilateral ( const Eigen::Vector3d &  point1,
const Eigen::Vector3d &  point2,
const Eigen::Vector3d &  point3,
const Eigen::Vector3d &  point4,
double  lineWidth 
) [virtual]

Draws the outline of a two dimensional quadrilateral in three dimensional space.

Parameters:
point1the first of the four corners of the quadrilateral.
point2the second of the four corners of the quadrilateral.
point3the third of the four corners of the quadrilateral.
point4the last of the four corners of the quadrilateral.
lineWidththe thickness of the line the quadrilateral will be drawn with.

Reimplemented from Avogadro::Painter.

void Avogadro::GLPainter::drawShadedQuadrilateral ( const Eigen::Vector3d &  point1,
const Eigen::Vector3d &  point2,
const Eigen::Vector3d &  point3,
const Eigen::Vector3d &  point4 
) [virtual]

Draws a solid two dimensional quadrilateral in three dimensional space.

Parameters:
point1the first of the four corners of the quadrilateral.
point2the second of the four corners of the quadrilateral.
point3the third of the four corners of the quadrilateral.
point4the last of the four corners of the quadrilateral.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawShadedSector ( const Eigen::Vector3d &  origin,
const Eigen::Vector3d &  direction1,
const Eigen::Vector3d &  direction2,
double  radius,
bool  alternateAngle = false 
) [virtual]

Draws a shaded sector of a circle. The sector is defined by three vectors, the center of the circle, and two vectors that define the lines going out from the centre of the circle to the circumference of the circle. The actual points on the circumference are found using these two vectors and the radius of the circle.

Parameters:
originthe center of the circle this sector is a portion of.
direction1a vector defining the line the first point will lie on.
direction2a vector defining the line the second point will lie on.
radiusthe radius of the circle this sector is a portion of.
alternateAnglewhether to draw the obtuse angle made by the two vectors instead of the acute angle between them.

Implements Avogadro::Painter.

References A.

void Avogadro::GLPainter::drawSphere ( const Eigen::Vector3d &  center,
double  radius 
) [virtual]

Draws a sphere, leaving the Painter choose the appropriate detail level based on the apparent radius (ratio of radius over distance) and the global quality setting.

Parameters:
centerthe position of the center of the sphere.
radiusthe radius of the sphere.

Implements Avogadro::Painter.

References popName(), and pushName().

void Avogadro::GLPainter::drawSpline ( const QVector< Eigen::Vector3d > &  pts,
double  radius 
) [virtual]

Draw a cubic B-spline between the given points using GL NURBS.

Parameters:
ptsQVector containing the points to draw the cubic B-spline along.
radiusthe radius of the cubic B-spline.

Implements Avogadro::Painter.

References QVector::size().

int Avogadro::GLPainter::drawText ( int  x,
int  y,
const QString string 
) [virtual]

Draws text at a given window position, on top of the scene.

Note:
Calls to drawText methods must be enclosed between begin() and end().
Text is rendered as a transparent object, and should therefore be rendered after the opaque objects.
Parameters:
x,ythe window coordinates of the top-left corner of the text to render, (0, 0) is the top-left corner of the window.
stringthe string to render. All character encodings are allowed but superposed characters are not supported yet. For accented letters, use a character giving the whole accented letter, not a separate character for the accent.
See also:
begin(), drawText(const Eigen::Vector3d &, const QString &), drawText(const QPoint &, const QString &)

Implements Avogadro::Painter.

int Avogadro::GLPainter::drawText ( const QPoint pos,
const QString string 
) [virtual]

Draws text at a given window position, on top of the scene.

Note:
Calls to drawText methods must be enclosed between begin() and endText().
Text is rendered as a transparent object, and should therefore be rendered after the opaque objects.
Parameters:
posthe window coordinates of the top-left corner of the text to render, (0, 0) is the top-left corner of the window.
stringthe string to render. All character encodings are allowed but superposed characters are not supported yet. For accented letters, use a character giving the whole accented letter, not a separate character for the accent.
See also:
begin(), drawText(const Eigen::Vector3d &, const QString &), drawText(int, int, const QString &) const

Implements Avogadro::Painter.

References QPoint::x(), and QPoint::y().

int Avogadro::GLPainter::drawText ( const Eigen::Vector3d &  pos,
const QString string 
) [virtual]

Draws text at a given scene position, inside the scene.

Note:
Calls to drawText methods must be enclosed between begin() and endText().
Text is rendered as a transparent object, and should therefore be rendered after the opaque objects.
Parameters:
posthe scene coordinates of the top-left corner of the text to render.
stringThe string to render. All character encodings are allowed but superposed characters are not supported yet. For accented letters, use a character giving the whole accented letter, not a separate character for the accent.
See also:
begin(), drawText(const QPoint&, const QString &), drawText(int, int, const QString &)

Implements Avogadro::Painter.

int Avogadro::GLPainter::drawText ( const Eigen::Vector3d &  ,
const QString ,
const QFont  
) [virtual]

Draws text at a given scene position, inside the scene, using given font

Parameters:
posthe scene coordinates of the top-left corner of the text to render.
stringThe string to render. All character encodings are allowed but superposed characters are not supported yet. For accented letters, use a character giving the whole accented letter, not a separate character for the accent.
fontThe font to use for rendering
Todo:
make it pure virtual in 2.0
See also:
begin(), drawText(const QPoint&, const QString &) const, drawText(int, int, const QString &) const

Reimplemented from Avogadro::Painter.

void Avogadro::GLPainter::drawTorus ( const Eigen::Vector3d &  pos,
double  majorRadius,
double  minorRadius 
) [virtual]

Placeholder to draw a torus.

Parameters:
posPosition of the center of the torus.
majorRadiusMajor radius of the torus.
minorRadiusMinor radius of the torus.
Todo:
Implement this primitive.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawTriangle ( const Eigen::Vector3d &  p1,
const Eigen::Vector3d &  p2,
const Eigen::Vector3d &  p3 
) [virtual]

Draws a triangle with vertives on the three given points. This function calculates the normal of the triangle and corrects the winding order to ensure the front face is facing the camera.

Parameters:
p1first triangle vertex.
p2second triangle vertex.
p3third triangle vertex.

Implements Avogadro::Painter.

void Avogadro::GLPainter::drawTriangle ( const Eigen::Vector3d &  p1,
const Eigen::Vector3d &  p2,
const Eigen::Vector3d &  p3,
const Eigen::Vector3d &  n 
) [virtual]

Draws a triangle with vertives on the three given points using the given normal. This function corrects the triangle's winding order.

Parameters:
p1first triangle vertex.
p2second triangle vertex.
p3third triangle vertex.
nthe normal of the triangle.

Implements Avogadro::Painter.

End painting, should be called when all painting is complete.

Increment the number of widgets the Painter is being shared by.

Returns:
true if the Painter is active.
Returns:
true if the Painter is being shared between multiple GLWidgets.
Returns:
the maximum quality level of the Painter.
void Avogadro::GLPainter::popName ( ) [protected]

Pop the GL name and type, called internally after GL objects are painted on the GLWidget.

References resetName().

Referenced by drawCylinder(), drawMultiCylinder(), and drawSphere().

void Avogadro::GLPainter::pushName ( ) [protected]

Push the GL name and type, called internally before GL objects are painted on the GLWidget.

Referenced by drawCylinder(), drawMultiCylinder(), and drawSphere().

int Avogadro::GLPainter::quality ( ) const [virtual]
Returns:
the current global quality setting.

Implements Avogadro::Painter.

Referenced by GLPainter(), and setQuality().

void Avogadro::GLPainter::resetName ( ) [protected]

Reset the GL name and type, called internally in popName() and also whenever frustum culling determines that a GL object must not be painted.

References Avogadro::Primitive::OtherType.

Referenced by popName().

void Avogadro::GLPainter::setColor ( const Color color) [virtual]

Set the color to paint the OpenGL primitives with.

Parameters:
colorthe color to be used for painting.

Implements Avogadro::Painter.

References Avogadro::Color::alpha(), Avogadro::Color::blue(), Avogadro::Color::green(), and Avogadro::Color::red().

void Avogadro::GLPainter::setColor ( const QColor color) [virtual]

Set the color to paint the OpenGL primitives with.

Parameters:
colorthe color to be used for painting.

Implements Avogadro::Painter.

References QColor::alphaF(), QColor::blueF(), QColor::greenF(), and QColor::redF().

void Avogadro::GLPainter::setColor ( float  red,
float  green,
float  blue,
float  alpha = 1.0 
) [virtual]

Set the color to paint elements with where 0.0 is the minimum and 1.0 is the maximum.

Parameters:
redcomponent of the color.
greencomponent of the color.
bluecomponent of the color.
alphacomponent of the color.

Implements Avogadro::Painter.

void Avogadro::GLPainter::setColor ( QString  name) [virtual]

Set the color to paint elements by its name

Parameters:
namename of the color to be used

Implements Avogadro::Painter.

Set to true to turn dynamic object scaling on, false for off.

void Avogadro::GLPainter::setName ( const Primitive primitive) [virtual]

Uses the primitive to set the type and name if the Paint Device supports it.

Parameters:
primitivethe primitive about to be drawn.

Implements Avogadro::Painter.

References Avogadro::Primitive::AtomType, and Avogadro::Primitive::BondType.

void Avogadro::GLPainter::setName ( Primitive::Type  type,
int  id 
) [virtual]

Sets the primitive type and id.

Parameters:
typethe primitive type about to be drawn.
idthe primitive id.

Implements Avogadro::Painter.

void Avogadro::GLPainter::setQuality ( int  quality)

Sets the global quality setting. This influences the detail level of the geometric objects (spheres and cylinders). Values range from 0 to PAINTER_GLOBAL_QUALITY_SETTINGS-1.

References quality().


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