本文整理汇总了C++中GeometryNode::addDrawable方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryNode::addDrawable方法的具体用法?C++ GeometryNode::addDrawable怎么用?C++ GeometryNode::addDrawable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryNode
的用法示例。
在下文中一共展示了GeometryNode::addDrawable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void BallAndStick::process(const Molecule &molecule,
Rendering::GroupNode &node)
{
// Add a sphere node to contain all of the spheres.
GeometryNode *geometry = new GeometryNode;
node.addChild(geometry);
SphereGeometry *spheres = new SphereGeometry;
spheres->identifier().molecule = &molecule;
spheres->identifier().type = Rendering::AtomType;
geometry->addDrawable(spheres);
for (Index i = 0; i < molecule.atomCount(); ++i) {
Core::Atom atom = molecule.atom(i);
unsigned char atomicNumber = atom.atomicNumber();
const unsigned char *c = Elements::color(atomicNumber);
Vector3ub color(c[0], c[1], c[2]);
spheres->addSphere(atom.position3d().cast<float>(), color,
static_cast<float>(Elements::radiusVDW(atomicNumber))
* 0.3f);
}
float bondRadius = 0.1f;
CylinderGeometry *cylinders = new CylinderGeometry;
cylinders->identifier().molecule = &molecule;
cylinders->identifier().type = Rendering::BondType;
geometry->addDrawable(cylinders);
for (Index i = 0; i < molecule.bondCount(); ++i) {
Core::Bond bond = molecule.bond(i);
Vector3f pos1 = bond.atom1().position3d().cast<float>();
Vector3f pos2 = bond.atom2().position3d().cast<float>();
Vector3ub color1(Elements::color(bond.atom1().atomicNumber()));
Vector3ub color2(Elements::color(bond.atom2().atomicNumber()));
Vector3f bondVector = pos2 - pos1;
float bondLength = bondVector.norm();
bondVector /= bondLength;
switch (bond.order()) {
case 3: {
Vector3f delta = bondVector.unitOrthogonal() * (2.0f * bondRadius);
cylinders->addCylinder(pos1 + delta, bondVector, bondLength, bondRadius,
color1, color2, i);
cylinders->addCylinder(pos1 - delta, bondVector, bondLength, bondRadius,
color1, color2, i);
}
default:
case 1:
cylinders->addCylinder(pos1, bondVector, bondLength, bondRadius,
color1, color2, i);
break;
case 2: {
Vector3f delta = bondVector.unitOrthogonal() * bondRadius;
cylinders->addCylinder(pos1 + delta, bondVector, bondLength, bondRadius,
color1, color2, i);
cylinders->addCylinder(pos1 - delta, bondVector, bondLength, bondRadius,
color1, color2, i);
}
}
}
}
示例2: process
void VanDerWaals::process(const Core::Molecule &molecule,
Rendering::GroupNode &node)
{
// Add a sphere node to contain all of the VdW spheres.
GeometryNode *geometry = new GeometryNode;
node.addChild(geometry);
SphereGeometry *spheres = new SphereGeometry;
spheres->identifier().molecule = &molecule;
spheres->identifier().type = Rendering::AtomType;
geometry->addDrawable(spheres);
for (size_t i = 0; i < molecule.atomCount(); ++i) {
Core::Atom atom = molecule.atom(i);
unsigned char atomicNumber = atom.atomicNumber();
const unsigned char *c = Elements::color(atomicNumber);
Vector3ub color(c[0], c[1], c[2]);
spheres->addSphere(atom.position3d().cast<float>(), color,
static_cast<float>(Elements::radiusVDW(atomicNumber)));
}
}
示例3: glwidgettest
int glwidgettest(int argc, char* argv[])
{
// Set up the default format for our GL contexts.
QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat();
defaultFormat.setSamples(4);
QSurfaceFormat::setDefaultFormat(defaultFormat);
QApplication app(argc, argv);
GLWidget widget;
widget.setGeometry(10, 10, 250, 250);
widget.show();
GeometryNode* geometry = new GeometryNode;
SphereGeometry* spheres = new SphereGeometry;
geometry->addDrawable(spheres);
spheres->addSphere(Vector3f(0, 0, 0), Vector3ub(255, 0, 0), 0.5);
spheres->addSphere(Vector3f(2, 0, 0), Vector3ub(0, 255, 0), 1.5);
spheres->addSphere(Vector3f(0, 2, 1), Vector3ub(0, 0, 255), 1.0);
widget.renderer().scene().rootNode().addChild(geometry);
// Make sure the widget renders the scene, and store it in a QImage.
widget.raise();
widget.repaint();
// Run the application for a while, and then quit so we can save an image.
QTimer timer;
timer.setSingleShot(true);
app.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
timer.start(200);
app.exec();
// Grab the frame buffer of the GLWidget and save it to a QImage.
QImage image = widget.grabFramebuffer();
// Set up the image regression test.
ImageRegressionTest test(argc, argv);
// Do the image threshold test, printing output to the std::cout for ctest.
return test.imageThresholdTest(image, std::cout);
}
示例4: process
void QTAIMEngine::process(const Core::Molecule &coreMolecule,
Rendering::GroupNode &node)
{
const QtGui::Molecule *molecule =
dynamic_cast<const QtGui::Molecule*>(&coreMolecule);
if (!molecule)
return;
// Create sphere/cylinder nodes.
GeometryNode *geometry = new GeometryNode;
node.addChild(geometry);
SphereGeometry *spheres = new SphereGeometry;
geometry->addDrawable(spheres);
CylinderGeometry *cylinders = new CylinderGeometry;
geometry->addDrawable(cylinders);
// Render the bond paths
if(
molecule->property("QTAIMFirstNCPIndexVariantList").isValid() &&
molecule->property("QTAIMSecondNCPIndexVariantList").isValid() &&
molecule->property("QTAIMLaplacianAtBondCriticalPoints").isValid() &&
molecule->property("QTAIMEllipticityAtBondCriticalPoints").isValid() &&
molecule->property("QTAIMBondPathSegmentStartIndex").isValid() &&
molecule->property("QTAIMBondPathSegmentEndIndex").isValid() &&
molecule->property("QTAIMXBondPaths").isValid() &&
molecule->property("QTAIMYBondPaths").isValid() &&
molecule->property("QTAIMZBondPaths").isValid()
)
{
QVariant firstNCPIndexVariant=molecule->property("QTAIMFirstNCPIndexVariantList");
QVariant secondNCPIndexVariant=molecule->property("QTAIMSecondNCPIndexVariantList");
QVariant laplacianAtBondCriticalPointsVariant=molecule->property("QTAIMLaplacianAtBondCriticalPoints");
QVariant ellipticityAtBondCriticalPointsVariant=molecule->property("QTAIMEllipticityAtBondCriticalPoints");
QVariant bondPathSegmentStartIndexVariant=molecule->property("QTAIMBondPathSegmentStartIndex");
QVariant bondPathSegmentEndIndexVariant=molecule->property("QTAIMBondPathSegmentEndIndex");
QVariant xBondPathsVariant=molecule->property("QTAIMXBondPaths");
QVariant yBondPathsVariant=molecule->property("QTAIMYBondPaths");
QVariant zBondPathsVariant=molecule->property("QTAIMZBondPaths");
QVariantList firstNCPIndexVariantList=firstNCPIndexVariant.toList();
QVariantList secondNCPIndexVariantList=secondNCPIndexVariant.toList();
QVariantList laplacianAtBondCriticalPointsVariantList=laplacianAtBondCriticalPointsVariant.toList();
QVariantList ellipticityAtBondCriticalPointsVariantList=ellipticityAtBondCriticalPointsVariant.toList();
QVariantList bondPathSegmentStartIndexVariantList=bondPathSegmentStartIndexVariant.toList();
QVariantList bondPathSegmentEndIndexVariantList=bondPathSegmentEndIndexVariant.toList();
QVariantList xBondPathsVariantList=xBondPathsVariant.toList();
QVariantList yBondPathsVariantList=yBondPathsVariant.toList();
QVariantList zBondPathsVariantList=zBondPathsVariant.toList();
for( qint64 i=0 ; i < firstNCPIndexVariantList.length() ; ++i )
{
qint64 start=bondPathSegmentStartIndexVariantList.at(i).toLongLong();
qint64 end=bondPathSegmentEndIndexVariantList.at(i).toLongLong();
if( laplacianAtBondCriticalPointsVariantList.at(i).toReal() > 0.0 )
{
const qint64 step=4;
Vector3f xyz;
Vector3ub color(255, 255, 255);
for( qint64 j=start ; j < end-1 ; j=j+step )
{
xyz << xBondPathsVariantList.at(j).toFloat(),
yBondPathsVariantList.at(j).toFloat(),
zBondPathsVariantList.at(j).toFloat();
spheres->addSphere(xyz, color, 0.025f);
}
}
else
{
const qint64 step=1;
Vector3ub color(255, 255, 255);
double radius=0.025;
Vector3f v1;
Vector3f v2;
Vector3f direction;
for( qint64 j=start ; j < end-1 ; j=j+step )
{
v1 << xBondPathsVariantList.at(j).toFloat(),
yBondPathsVariantList.at(j).toFloat(),
zBondPathsVariantList.at(j).toFloat();
v2 << xBondPathsVariantList.at(j+1).toFloat(),
yBondPathsVariantList.at(j+1).toFloat(),
zBondPathsVariantList.at(j+1).toFloat();
direction = v2 - v1;
float length = direction.norm();
direction /= length;
cylinders->addCylinder(v1, direction, length, radius, color);
}
}
} // bond path
}
//.........这里部分代码省略.........
示例5: qttextlabeltest
int qttextlabeltest(int argc, char *argv[])
{
// Set up the default format for our GL contexts.
QGLFormat defaultFormat = QGLFormat::defaultFormat();
defaultFormat.setSampleBuffers(true);
QGLFormat::setDefaultFormat(defaultFormat);
// Create and show widget
QApplication app(argc, argv);
GLWidget widget;
widget.setGeometry(10, 10, 500, 500);
widget.show();
// Create scene
GeometryNode *geometry = new GeometryNode;
widget.renderer().scene().rootNode().addChild(geometry);
// Add a small sphere at the origin for reference:
SphereGeometry *spheres = new SphereGeometry;
spheres->addSphere(Vector3f::Zero(), Vector3ub(128, 128, 128), 0.1f);
geometry->addDrawable(spheres);
// Default text property:
TextProperties tprop;
// Test alignment:
TextLabel3D *l3 = NULL;
TextLabel2D *l2 = NULL;
// 3D:
tprop.setColorRgb(255, 0, 0);
tprop.setAlign(TextProperties::HLeft, TextProperties::VTop);
l3 = new TextLabel3D;
l3->setText("Upper Left Anchor");
l3->setAnchor(Vector3f::Zero());
l3->setTextProperties(tprop);
geometry->addDrawable(l3);
tprop.setColorRgb(0, 255, 0);
tprop.setAlign(TextProperties::HLeft, TextProperties::VBottom);
l3 = new TextLabel3D;
l3->setText("Bottom Left Anchor");
l3->setAnchor(Vector3f::Zero());
l3->setTextProperties(tprop);
geometry->addDrawable(l3);
tprop.setColorRgb(0, 0, 255);
tprop.setAlign(TextProperties::HRight, TextProperties::VTop);
l3 = new TextLabel3D;
l3->setText("Upper Right Anchor");
l3->setAnchor(Vector3f::Zero());
l3->setTextProperties(tprop);
geometry->addDrawable(l3);
tprop.setColorRgb(255, 255, 0);
tprop.setAlign(TextProperties::HRight, TextProperties::VBottom);
l3 = new TextLabel3D;
l3->setText("Bottom Right Anchor");
l3->setAnchor(Vector3f::Zero());
l3->setTextProperties(tprop);
geometry->addDrawable(l3);
tprop.setColorRgba(255, 255, 255, 220);
tprop.setRotationDegreesCW(90.f);
tprop.setAlign(TextProperties::HCenter, TextProperties::VCenter);
l3 = new TextLabel3D;
l3->setText("Centered Anchor (3D)");
l3->setAnchor(Vector3f::Zero());
l3->setTextProperties(tprop);
l3->setRenderPass(Avogadro::Rendering::TranslucentPass);
geometry->addDrawable(l3);
tprop.setRotationDegreesCW(0.f);
tprop.setAlpha(255);
// 2D:
tprop.setColorRgb(255, 0, 0);
tprop.setAlign(TextProperties::HLeft, TextProperties::VTop);
l2 = new TextLabel2D;
l2->setText("Upper Left Corner");
l2->setAnchor(Vector2i(0, widget.height()));
l2->setTextProperties(tprop);
geometry->addDrawable(l2);
tprop.setColorRgb(0, 255, 0);
tprop.setAlign(TextProperties::HLeft, TextProperties::VBottom);
l2 = new TextLabel2D;
l2->setText("Bottom Left Corner");
l2->setAnchor(Vector2i(0, 0));
l2->setTextProperties(tprop);
geometry->addDrawable(l2);
tprop.setColorRgb(0, 0, 255);
tprop.setAlign(TextProperties::HRight, TextProperties::VTop);
l2 = new TextLabel2D;
l2->setText("Upper Right Corner");
l2->setAnchor(Vector2i(widget.width(), widget.height()));
l2->setTextProperties(tprop);
geometry->addDrawable(l2);
tprop.setColorRgb(255, 255, 0);
//.........这里部分代码省略.........