当前位置: 首页>>代码示例>>C++>>正文


C++ Molecule::atomById方法代码示例

本文整理汇总了C++中Molecule::atomById方法的典型用法代码示例。如果您正苦于以下问题:C++ Molecule::atomById方法的具体用法?C++ Molecule::atomById怎么用?C++ Molecule::atomById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Molecule的用法示例。


在下文中一共展示了Molecule::atomById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initOneTwo

  void NeighborList::initOneTwo()
  {
    unsigned int numAtoms = m_atoms.size();
    if (!numAtoms)
      return;

    m_oneTwo.resize(m_atoms.size());
    m_oneThree.resize(m_atoms.size());

    if (m_atoms.isEmpty())
      return;

    Molecule *molecule = m_atoms.first()->molecule();
    if (!molecule) {
      qDebug() << "Error, null molecule returned in NeighborList::initOneTwo()";
      return;
    }

    foreach (Atom *atom, m_atoms) {
      foreach (unsigned long id1, atom->neighbors()) {
        Atom *nbr1 = molecule->atomById(id1);
        m_oneTwo[atom->index()].push_back(nbr1->index());
        m_oneTwo[nbr1->index()].push_back(atom->index());

        foreach (unsigned long id2, nbr1->neighbors()) {
          Atom *nbr2 = molecule->atomById(id2);
          if (atom->index() == nbr2->index())
            continue;

          m_oneThree[atom->index()].push_back(nbr2->index());
          m_oneThree[nbr2->index()].push_back(atom->index());
        }
      }
    }
开发者ID:Algerien1970,项目名称:avogadro,代码行数:34,代码来源:neighborlist.cpp

示例2: renderRing

  bool RingEngine::renderRing(const QList<unsigned long> &ring, PainterDevice *pd)
  {
    // We need to get rid of the constness in order to get the atoms
    Molecule *mol = const_cast<Molecule *>(pd->molecule());

    // Calculate an appropriate normal and use it for all the triangles in the
    // ring - this will give consistent lighting.
    Eigen::Vector3d v1, v2, norm;
    v1 = *mol->atomById(ring[1])->pos() - *mol->atomById(ring[0])->pos();
    v2 = *mol->atomById(ring[2])->pos() - *mol->atomById(ring[1])->pos();
    norm = v1.cross(v2);
    if (norm.dot(pd->camera()->backTransformedZAxis()) > 0) norm *= -1;

    // Disable face culling for ring structures.
    glDisable(GL_CULL_FACE);

    // Optimize for smaller ring structures
    switch (ring.size()) {
      case 3:
        // Single triangle - easy
        pd->painter()->setColor(ringColors[0][0], ringColors[0][1],
                                ringColors[0][2], m_alpha);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[1])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    norm);
        break;
      case 4:
        // Two triangles
        pd->painter()->setColor(ringColors[1][0], ringColors[1][1],
                                ringColors[1][2], m_alpha);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[1])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    *mol->atomById(ring[3])->pos(),
                                    norm);
        break;
      case 5:
        // Three triangles
        pd->painter()->setColor(ringColors[2][0], ringColors[2][1],
                                ringColors[2][2], m_alpha);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[1])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    *mol->atomById(ring[3])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[3])->pos(),
                                    *mol->atomById(ring[4])->pos(),
                                    norm);
        break;
      case 6:
        // Four triangles
        pd->painter()->setColor(ringColors[3][0], ringColors[3][1],
                                ringColors[3][2], m_alpha);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[1])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[2])->pos(),
                                    *mol->atomById(ring[3])->pos(),
                                    *mol->atomById(ring[4])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[4])->pos(),
                                    *mol->atomById(ring[5])->pos(),
                                    *mol->atomById(ring[0])->pos(),
                                    norm);
        pd->painter()->drawTriangle(*mol->atomById(ring[0])->pos(),
                                    *mol->atomById(ring[2])->pos(),
                                    *mol->atomById(ring[4])->pos(),
                                    norm);
        break;
      default:
        // The generic case - find the centre of the ring and draw a triangle fan
        pd->painter()->setColor(ringColors[4][0], ringColors[4][1],
                                ringColors[4][2], m_alpha);
        Vector3d center;
        for (int i = 0; i < ring.size(); i++)
          center += *mol->atomById(ring[i])->pos();
        center /= ring.size();
        for (int i = 0; i < ring.size()-1; i++)
          pd->painter()->drawTriangle(center,
                                      *mol->atomById(ring[i])->pos(),
                                      *mol->atomById(ring[i+1])->pos(),
                                      norm);
        pd->painter()->drawTriangle(center,
                                    *mol->atomById(ring[ring.size()-1])->pos(),
                                    *mol->atomById(ring[0])->pos(),
                                    norm);

    }
    return true;
  }
开发者ID:Algerien1970,项目名称:avogadro,代码行数:99,代码来源:ringengine.cpp


注:本文中的Molecule::atomById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。