Avogadro
1.1.0
|
Implementation of the Painter class using OpenGL. More...
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 ¢er, 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 |
Implementation of the Painter class using OpenGL.
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.
Avogadro::GLPainter::GLPainter | ( | int | quality = -1 | ) |
Destructor.
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().
void Avogadro::GLPainter::begin | ( | GLWidget * | widget | ) |
void Avogadro::GLPainter::decrementShare | ( | ) | [protected] |
Decrement the number of widgets the Painter is being shared by.
int Avogadro::GLPainter::defaultQuality | ( | ) | [static] |
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.
origin | the center of the circle whose circumference this arc is a portion of. |
direction1 | a vector defining the line the start of the arc will lie on. |
direction2 | a vector defining the line the end of the arc will lie on. |
radius | the radius of the circle whose circumference this arc is a portion of. |
lineWidth | the thickness of the line the arc will be drawn with. |
alternateAngle | whether 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.
corner1 | First corner of the box. |
corner2 | Second corner of the box. |
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
offset | Corner of the box. |
v1 | Edge of box, pointing relative to offset. |
v2 | Edge of box, pointing relative to offset. |
v3 | Edge of box, pointing relative to offset. |
linewidth | The 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
c1 | Corner |
c2 | Corner |
c3 | Corner |
c4 | Corner |
c5 | Corner |
c6 | Corner |
c7 | Corner |
c8 | Corner |
linewidth | The 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.
mesh | the mesh to be drawn. |
mode | the 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.
base | the position of the base of the cone. |
baseRadius | the radius of the base of the cone. |
cap | the position of the tip of the cone. |
capRadius | the radius of the base of the cone. |
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.
end1 | the position of the first end of the cylinder. |
end2 | the position of the second end of the cylinder. |
radius | the 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.
pos | Position of the center of the ellipsoid. |
matrix | Linear transformation matrix for scaling and rotation. |
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.
start | the position of the start of the line. |
end | the position of the end of the line. |
lineWidth | the 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,
points | A list of consecutive points defining the line loop |
lineWidth | the 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.
mesh | the mesh to be drawn. |
mode | the 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.
end1 | the position of the first end of the bond. |
end2 | the position of the second end of the bond. |
radius | the radius, i.e. half-width of each cylinder. |
order | the multiplicity order of the bond, e.g. 2 for a double bond. When this parameter equals 1, this function is equivalent to drawCylinder(). |
shift | how 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.
start | the position of the start of the line. |
end | the position of the end of the line. |
lineWidth | the width of the GL line. |
order | the order of the bond, e.g. 2 for a double bond. |
stipple | The 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.
point1 | the first of the four corners of the quadrilateral. |
point2 | the second of the four corners of the quadrilateral. |
point3 | the third of the four corners of the quadrilateral. |
point4 | the last of the four corners of the quadrilateral. |
lineWidth | the 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.
point1 | the first of the four corners of the quadrilateral. |
point2 | the second of the four corners of the quadrilateral. |
point3 | the third of the four corners of the quadrilateral. |
point4 | the 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.
origin | the center of the circle this sector is a portion of. |
direction1 | a vector defining the line the first point will lie on. |
direction2 | a vector defining the line the second point will lie on. |
radius | the radius of the circle this sector is a portion of. |
alternateAngle | whether 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.
center | the position of the center of the sphere. |
radius | the 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.
pts | QVector containing the points to draw the cubic B-spline along. |
radius | the 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.
x,y | the window coordinates of the top-left corner of the text to render, (0, 0) is the top-left corner of the window. |
string | the 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. |
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.
pos | the window coordinates of the top-left corner of the text to render, (0, 0) is the top-left corner of the window. |
string | the 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. |
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.
pos | the scene coordinates of the top-left corner of the text to render. |
string | The 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. |
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
pos | the scene coordinates of the top-left corner of the text to render. |
string | The 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. |
font | The font to use for rendering |
Reimplemented from Avogadro::Painter.
void Avogadro::GLPainter::drawTorus | ( | const Eigen::Vector3d & | pos, |
double | majorRadius, | ||
double | minorRadius | ||
) | [virtual] |
Placeholder to draw a torus.
pos | Position of the center of the torus. |
majorRadius | Major radius of the torus. |
minorRadius | Minor radius of the torus. |
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.
p1 | first triangle vertex. |
p2 | second triangle vertex. |
p3 | third 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.
p1 | first triangle vertex. |
p2 | second triangle vertex. |
p3 | third triangle vertex. |
n | the normal of the triangle. |
Implements Avogadro::Painter.
void Avogadro::GLPainter::end | ( | ) |
End painting, should be called when all painting is complete.
void Avogadro::GLPainter::incrementShare | ( | ) | [protected] |
Increment the number of widgets the Painter is being shared by.
bool Avogadro::GLPainter::isActive | ( | ) |
bool Avogadro::GLPainter::isShared | ( | ) |
int Avogadro::GLPainter::maxQuality | ( | ) | [static] |
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] |
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.
color | the 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.
color | the 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.
red | component of the color. |
green | component of the color. |
blue | component of the color. |
alpha | component of the color. |
Implements Avogadro::Painter.
void Avogadro::GLPainter::setColor | ( | QString | name | ) | [virtual] |
Set the color to paint elements by its name
name | name of the color to be used |
Implements Avogadro::Painter.
void Avogadro::GLPainter::setDynamicScaling | ( | bool | scaling | ) |
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.
primitive | the 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.
type | the primitive type about to be drawn. |
id | the 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().