예제 #1
0
TEST(RWMoleculeTest, setAtomPositions3d)
{
  Molecule m;
  RWMolecule mol(m);
  mol.addAtom(1);
  mol.addAtom(2);
  mol.addAtom(3);
  mol.addAtom(4);
  mol.addAtom(5);
  mol.undoStack().clear();

  Array<Vector3> pos;
  Real gen = 1;
  pos.push_back(Vector3(gen, gen, gen)); gen++;
  pos.push_back(Vector3(gen, gen, gen)); gen++;
  pos.push_back(Vector3(gen, gen, gen)); gen++;
  pos.push_back(Vector3(gen, gen, gen)); gen++;
  pos.push_back(Vector3(gen, gen, gen)); gen++;

  mol.setAtomPositions3d(pos);
  EXPECT_TRUE(std::equal(mol.atomPositions3d().begin(),
                         mol.atomPositions3d().end(), pos.begin()));
  mol.undoStack().undo();
  EXPECT_TRUE(mol.atomPositions3d().empty());
  mol.undoStack().redo();
  EXPECT_TRUE(std::equal(mol.atomPositions3d().begin(),
                         mol.atomPositions3d().end(), pos.begin()));
  mol.undoStack().undo();

  // Test merging for interactive edits:
  mol.setInteractive(true);
  mol.setAtomPositions3d(pos);
  for (Array<Vector3>::iterator it = pos.begin(), itEnd = pos.end();
       it != itEnd; ++it) {
    it->x() += static_cast<Real>(pos.size());
    it->y() += static_cast<Real>(pos.size());
    it->z() += static_cast<Real>(pos.size());
  }
  mol.setAtomPositions3d(pos);
  mol.setInteractive(false);

  EXPECT_TRUE(std::equal(mol.atomPositions3d().begin(),
                         mol.atomPositions3d().end(), pos.begin()));
  EXPECT_EQ(1, mol.undoStack().count());
  mol.undoStack().undo();
  EXPECT_TRUE(mol.atomPositions3d().empty());
  mol.undoStack().redo();
  EXPECT_TRUE(std::equal(mol.atomPositions3d().begin(),
                         mol.atomPositions3d().end(), pos.begin()));
}
TEST(CoordinateSetTest, Store)
{
  CoordinateSet<Vector3> data;
  data.resize(5);
  data[0] = Vector3(0.0, 1.0, 2.0);
  EXPECT_EQ(data[0].x(), 0.0);
  EXPECT_EQ(data[0].y(), 1.0);
  EXPECT_EQ(data[0].z(), 2.0);
}
예제 #3
0
TEST_F(MoleculeTest, perceiveBondsSimple)
{
  Molecule molecule;
  Atom o1 = molecule.addAtom(8);
  Atom h2 = molecule.addAtom(1);
  Atom h3 = molecule.addAtom(1);

  o1.setPosition3d(Vector3(0, 0, 0));
  h2.setPosition3d(Vector3(0.6, -0.5, 0));
  h3.setPosition3d(Vector3(-0.6, -0.5, 0));
  EXPECT_EQ(molecule.bondCount(), 0);

  molecule.perceiveBondsSimple();
  EXPECT_EQ(molecule.bondCount(), 2);
  EXPECT_TRUE(molecule.bond(o1, h2).isValid());
  EXPECT_TRUE(molecule.bond(o1, h3).isValid());
  EXPECT_FALSE(molecule.bond(h2, h3).isValid());
}
TEST(CoordinateSetTest, StoreTypeRetrieve)
{
  CoordinateSet<Vector3> data;
  data.resize(5);
  data[0] = Vector3(0.0, 1.0, 2.0);

  ArraySet *array = &data;
  CoordinateSet<Vector3> &ref = *reinterpret_cast< CoordinateSet<Vector3> *>(array);
  EXPECT_EQ(ref[0].x(), 0.0);
  EXPECT_EQ(ref[0].y(), 1.0);
  EXPECT_EQ(ref[0].z(), 2.0);
}
TEST(CoordinateSetTest, StoreType)
{
  ArraySet *array = new CoordinateSet<Vector3>;

  EXPECT_TRUE(array->isType(Vector3()));

  delete array;
  array = 0;

  array = new CoordinateSet<float>;
  EXPECT_TRUE(array->isType(float()));
  delete array;
  array = 0;
}
예제 #6
0
TEST(RWMoleculeTest, MoleculeToRWMolecule)
{
  Molecule mol;
  typedef Molecule::AtomType Atom;
  typedef Molecule::BondType Bond;
  Atom a0 = mol.addAtom(1);
  Atom a1 = mol.addAtom(6);
  Atom a2 = mol.addAtom(9);
  Bond b0 = mol.addBond(a0, a2);
  a1.setPosition3d(Vector3(0, 6, 9));
  b0.setOrder(3);

  RWMolecule rwmol(mol, 0);
  EXPECT_EQ(rwmol.atomCount(), mol.atomCount());
  EXPECT_EQ(rwmol.bondCount(), mol.bondCount());
  EXPECT_EQ(rwmol.atom(2).atomicNumber(), mol.atom(2).atomicNumber());
  EXPECT_EQ(rwmol.bond(0).order(), mol.bond(0).order());
}
예제 #7
0
MoleculeTest::MoleculeTest()
{
  Atom o1 = m_testMolecule.addAtom(8);
  Atom h2 = m_testMolecule.addAtom(1);
  Atom h3 = m_testMolecule.addAtom(1);

  o1.setPosition3d(Vector3(0, 0, 0));
  h2.setPosition3d(Vector3(0.6, -0.5, 0));
  h3.setPosition3d(Vector3(-0.6, -0.5, 0));

  o1.setPosition2d(Vector2(0, 0));
  h2.setPosition2d(Vector2(0.6, -0.5));
  h3.setPosition2d(Vector2(-0.6, -0.5));

  // Add some data
  VariantMap data;
  data.setValue("test", Variant("test"));
  m_testMolecule.setDataMap(data);

  // Add some bonds
  m_testMolecule.perceiveBondsSimple();

  Mesh *mesh = m_testMolecule.addMesh();

  Array<Vector3f> vertices;
  Array<Vector3f> normals;
  Array<Color3f> colors;

  Color3f color = Color3f(23, 23, 23);
  colors.push_back(color);

  Vector3f vec(1.2f, 1.3f, 1.4f);

  vertices.push_back(vec);
  normals.push_back(vec);

  mesh->setColors(colors);
  mesh->setNormals(normals);
  mesh->setVertices(vertices);
  mesh->setIsoValue(1.2f);
  mesh->setName("testmesh");
  mesh->setOtherMesh(1);
  mesh->setStable(false);
}
예제 #8
0
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);
}
예제 #9
0
TEST(RWMoleculeTest, AtomType)
{
  Molecule m;
  RWMolecule mol(m);
  typedef RWMolecule::AtomType Atom;
  Atom a0 = mol.addAtom(1);
  Atom a1 = mol.addAtom(2);

  EXPECT_TRUE(a0.isValid());
  EXPECT_FALSE(Atom().isValid());
  EXPECT_FALSE(Atom(&mol, 2).isValid());

  EXPECT_EQ(&mol, a0.molecule());
  EXPECT_EQ(0, a0.index());

  EXPECT_EQ(1, a0.atomicNumber());
  EXPECT_EQ(1, mol.atomicNumber(0));
  EXPECT_EQ(2, a1.atomicNumber());
  EXPECT_EQ(2, mol.atomicNumber(1));

  a0.setPosition3d(Vector3(Real(3), Real(4), Real(5)));
  a1.setPosition3d(Vector3(Real(6), Real(7), Real(8)));

  EXPECT_EQ(Vector3(Real(3), Real(4), Real(5)), a0.position3d());
  EXPECT_EQ(Vector3(Real(3), Real(4), Real(5)), mol.atomPosition3d(0));
  EXPECT_EQ(Vector3(Real(6), Real(7), Real(8)), a1.position3d());
  EXPECT_EQ(Vector3(Real(6), Real(7), Real(8)), mol.atomPosition3d(1));

  Atom other(&mol, 0);
  EXPECT_EQ(a0, other);
  EXPECT_NE(a1, other);
}
예제 #10
0
TEST(RWMoleculeTest, setAtomPosition3d)
{
  Molecule m;
  RWMolecule mol(m);
  mol.addAtom(1);
  mol.addAtom(2);
  mol.addAtom(3);
  mol.addAtom(4);
  mol.addAtom(5);
  mol.undoStack().clear();

  EXPECT_TRUE(mol.atomPositions3d().empty());
  mol.setAtomPosition3d(0, Vector3(Real(1), Real(2), Real(3)));
  EXPECT_EQ(mol.atomicNumbers().size(), mol.atomPositions3d().size());
  EXPECT_EQ(Real(1), mol.atomPosition3d(0).x());
  EXPECT_EQ(Real(2), mol.atomPosition3d(0).y());
  EXPECT_EQ(Real(3), mol.atomPosition3d(0).z());
  for (Index i = 1; i < 5; ++i)
    EXPECT_EQ(Vector3::Zero(), mol.atomPosition3d(i));

  mol.undoStack().undo();
  for (Index i = 0; i < 5; ++i)
    EXPECT_EQ(Vector3::Zero(), mol.atomPosition3d(i));

  mol.undoStack().redo();
  EXPECT_EQ(Real(1), mol.atomPosition3d(0).x());
  EXPECT_EQ(Real(2), mol.atomPosition3d(0).y());
  EXPECT_EQ(Real(3), mol.atomPosition3d(0).z());
  for (Index i = 1; i < 5; ++i)
    EXPECT_EQ(Vector3::Zero(), mol.atomPosition3d(i));

  mol.undoStack().undo();
  mol.undoStack().clear();

  // Test command merging for interactive editing:
  mol.setInteractive(true);
  mol.setAtomPosition3d(0, Vector3(Real(1), Real(2), Real(3)));
  mol.setAtomPosition3d(3, Vector3(Real(4), Real(5), Real(6)));
  mol.setAtomPosition3d(0, Vector3(Real(7), Real(8), Real(9)));
  mol.setAtomPosition3d(1, Vector3(Real(6), Real(4), Real(2)));
  mol.setInteractive(false);

  Array<Vector3> pos(mol.atomPositions3d());
  EXPECT_EQ(Vector3(Real(7), Real(8), Real(9)), pos[0]);
  EXPECT_EQ(Vector3(Real(6), Real(4), Real(2)), pos[1]);
  EXPECT_EQ(Vector3::Zero(), pos[2]);
  EXPECT_EQ(Vector3(Real(4), Real(5), Real(6)), pos[3]);
  EXPECT_EQ(Vector3::Zero(), pos[4]);

  EXPECT_EQ(1, mol.undoStack().count());
  mol.undoStack().undo();
  for (Index i = 1; i < 5; ++i)
    EXPECT_EQ(Vector3::Zero(), mol.atomPosition3d(i));
  mol.undoStack().redo();
  EXPECT_TRUE(std::equal(pos.begin(), pos.end(),
                         mol.atomPositions3d().begin()));
}
예제 #11
0
TEST(RWMoleculeTest, clearAtoms)
{
  Molecule m;
  RWMolecule mol(m);
  typedef RWMolecule::AtomType Atom;

  Atom a0 = mol.addAtom(1); // H
  Atom a1 = mol.addAtom(2); // He
  Atom a2 = mol.addAtom(3); // Li
  Atom a3 = mol.addAtom(4); // Be
  Atom a4 = mol.addAtom(5); // B

  const Vector3 pos(Real(1), Real(2), Real(3));
  mol.setAtomPosition3d(0, pos);

  ASSERT_EQ(5, mol.atomCount());
  ASSERT_EQ(std::string("HHeLiBeB"), formula(mol));

  // Add some bonds to ensure that they are properly added/removed when a bonded
  // atom is removed.
  ASSERT_TRUE(mol.addBond(a0, a1, 0).isValid());
  ASSERT_TRUE(mol.addBond(a1, a2, 1).isValid());
  ASSERT_TRUE(mol.addBond(a2, a3, 2).isValid());
  ASSERT_TRUE(mol.addBond(a3, a4, 3).isValid());
  ASSERT_TRUE(mol.addBond(a0, a2, 4).isValid());
  ASSERT_TRUE(mol.addBond(a1, a3, 5).isValid());
  ASSERT_TRUE(mol.addBond(a2, a4, 6).isValid());
  ASSERT_TRUE(mol.addBond(a0, a3, 7).isValid());
  ASSERT_TRUE(mol.addBond(a1, a4, 8).isValid());
  ASSERT_TRUE(mol.addBond(a0, a4, 9).isValid());

  ASSERT_EQ(10, mol.bondCount());

  mol.clearAtoms();

  EXPECT_EQ(0, mol.atomCount());
  EXPECT_EQ(0, mol.bondCount());

  mol.undoStack().undo();

  ASSERT_EQ(5, mol.atomCount());
  ASSERT_EQ(10, mol.bondCount());
  ASSERT_EQ(std::string("HHeLiBeB"), formula(mol));

  for (Index i = 0; i < mol.atomCount(); ++i) {
    EXPECT_EQ(static_cast<unsigned char>(i + 1), mol.atomicNumber(i));
    EXPECT_EQ(i, mol.atomUniqueId(i));
  }

#define VALIDATE_BOND(ind, atom1, atom2, order, uid) \
  EXPECT_EQ(std::make_pair(Index(atom1), Index(atom2)), mol.bondPair(ind)); \
  EXPECT_EQ(static_cast<unsigned char>(order), mol.bondOrder(ind)); \
  EXPECT_EQ(uid, mol.bondUniqueId(ind))

  VALIDATE_BOND(0, 0, 1, 0, 0);
  VALIDATE_BOND(1, 1, 2, 1, 1);
  VALIDATE_BOND(2, 2, 3, 2, 2);
  VALIDATE_BOND(3, 3, 4, 3, 3);
  VALIDATE_BOND(4, 0, 2, 4, 4);
  VALIDATE_BOND(5, 1, 3, 5, 5);
  VALIDATE_BOND(6, 2, 4, 6, 6);
  VALIDATE_BOND(7, 0, 3, 7, 7);
  VALIDATE_BOND(8, 1, 4, 8, 8);
  VALIDATE_BOND(9, 0, 4, 9, 9);
#undef VALIDATE_BOND
}
예제 #12
0
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);
  tprop.setAlign(TextProperties::HRight, TextProperties::VBottom);
  l2 = new TextLabel2D;
  l2->setText("Bottom Right Corner");
  l2->setAnchor(Vector2i(widget.width(), 0));
  l2->setTextProperties(tprop);
  geometry->addDrawable(l2);

  tprop.setColorRgba(255, 255, 255, 220);
  tprop.setAlign(TextProperties::HCenter, TextProperties::VCenter);
  l2 = new TextLabel2D;
  l2->setText("Centered Anchor (2D)");
  l2->setAnchor(Vector2i(widget.width() / 2, widget.height() / 2));
  l2->setTextProperties(tprop);
  geometry->addDrawable(l2);

  // Test the TextLabel3D's radius feature:
  spheres->addSphere(Vector3f(0.f, 6.f, 0.f), Vector3ub(255, 255, 255), 1.f);

  tprop.setColorRgba(255, 128, 64, 255);
  tprop.setRotationDegreesCW(90.f);
  l3 = new TextLabel3D;
  l3->setText("Clipped");
  l3->setAnchor(Vector3f(0.f, 6.f, 0.f));
  l3->setTextProperties(tprop);
  geometry->addDrawable(l3);

  tprop.setColorRgba(64, 128, 255, 255);
  tprop.setRotationDegreesCW(45.f);
  l3 = new TextLabel3D;
  l3->setText("Projected");
  l3->setAnchor(Vector3f(0.f, 6.f, 0.f));
  l3->setTextProperties(tprop);
  l3->setRadius(1.f);
  geometry->addDrawable(l3);

  // 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(false);

  // 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);
}