Пример #1
0
void MeshGeometry::addTriangles(const Core::Array<unsigned int>& indiceArray)
{
  m_indices.reserve(m_indices.size() + indiceArray.size());
  std::copy(indiceArray.begin(), indiceArray.end(),
            std::back_inserter(m_indices));
  m_dirty = true;
}
Пример #2
0
void Spectra::setMode(int mode)
{
  if (mode >= 0
      && mode < static_cast<int>(m_molecule->vibrationFrequencies().size())) {
    m_mode = mode;

    // Now calculate the frames and set them on the molecule.
    m_molecule->setCoordinate3d(0);
    Core::Array<Vector3> atomPositions = m_molecule->atomPositions3d();
    Core::Array<Vector3> atomDisplacements = m_molecule->vibrationLx(mode);

    int frames = 5;
    int frameCounter = 0;
    m_molecule->setCoordinate3d(atomPositions, frameCounter++);

    double factor = 0.01 * m_amplitude;

    // Current coords + displacement.
    for (int i = 1; i <= frames; ++i) {
      Core::Array<Vector3> framePositions;
      for (Index atom = 0; atom < m_molecule->atomCount(); ++atom) {
        framePositions.push_back(atomPositions[atom] + atomDisplacements[atom]
                                 * factor * (double(i) / frames));
      }
      m_molecule->setCoordinate3d(framePositions, frameCounter++);
    }
    // + displacement back to original.
    for (int i = frames - 1; i >=0; --i) {
      Core::Array<Vector3> framePositions;
      for (Index atom = 0; atom < m_molecule->atomCount(); ++atom) {
        framePositions.push_back(atomPositions[atom] + atomDisplacements[atom]
                                 * factor *(double(i) / frames));
      }
      m_molecule->setCoordinate3d(framePositions, frameCounter++);
    }
    // Current coords - displacement.
    for (int i = 1; i <= frames; ++i) {
      Core::Array<Vector3> framePositions;
      for (Index atom = 0; atom < m_molecule->atomCount(); ++atom) {
        framePositions.push_back(atomPositions[atom] - atomDisplacements[atom]
                                 * factor *(double(i) / frames));
      }
      m_molecule->setCoordinate3d(framePositions, frameCounter++);
    }
    // - displacement back to original.
    for (int i = frames - 1; i >=0; --i) {
      Core::Array<Vector3> framePositions;
      for (Index atom = 0; atom < m_molecule->atomCount(); ++atom) {
        framePositions.push_back(atomPositions[atom] - atomDisplacements[atom]
                                 * factor *(double(i) / frames));
      }
      m_molecule->setCoordinate3d(framePositions, frameCounter++);
    }
  }
}
size_t LineStripGeometry::addLineStrip(const Core::Array<Vector3f> &vertices,
                                       const Core::Array<Vector3ub> &rgb,
                                       float lineWidth)
{
  if (vertices.empty() || vertices.size() != rgb.size())
    return InvalidIndex;

  size_t result = m_lineStarts.size();
  m_lineStarts.push_back(static_cast<unsigned int>(m_vertices.size()));
  m_lineWidths.push_back(lineWidth);

  Array<Vector3ub>::const_iterator colorIter(rgb.begin());
  Array<Vector3f>::const_iterator vertIter(vertices.begin());
  Array<Vector3f>::const_iterator vertEnd(vertices.end());

  m_vertices.reserve(m_vertices.size() + vertices.size());
  Vector4ub tmpColor(0, 0, 0, m_opacity);
  while (vertIter != vertEnd) {
    tmpColor.head<3>() = *(colorIter++);
    m_vertices.push_back(PackedVertex(*(vertIter++), tmpColor));
  }

  m_dirty = true;
  return result;
}
Пример #4
0
         //
         // Info::putChunk
         //
         void Info::putChunk(char const *name, Core::Array<Core::String> const &strs, bool junk)
         {
            std::size_t base;
            std::size_t off;

            // Calculate base offset.
            base = strs.size() * 4 + 4;
            if(junk) base += 8;

            // Calculate size of chunk.
            off = base;
            for(auto const &s : strs)
               off += lenString(s);

            // Write chunk header.
            putData(name, 4);
            putWord(off);

            // Write string count.
            if(junk) putWord(0);
            putWord(strs.size());
            if(junk) putWord(0);

            // Write string offsets.
            off = base;
            for(auto const &s : strs)
            {
               putWord(off);
               off += lenString(s);
            }

            // Write strings.
            if(junk && UseChunkSTRE)
            {
               off = base;
               for(auto const &s : strs)
               {
                  putString(s, off * 157135);
                  off += lenString(s);
               }
            }
            else for(auto const &s : strs)
               putString(s);
         }
Пример #5
0
unsigned int MeshGeometry::addVertices(const Core::Array<Vector3f>& v,
                                       const Core::Array<Vector3f>& n)
{
  if (v.size() != n.size())
    return InvalidIndex;

  size_t result = m_vertices.size();

  Core::Array<Vector3f>::const_iterator vIter = v.begin();
  Core::Array<Vector3f>::const_iterator vEnd = v.end();
  Core::Array<Vector3f>::const_iterator nIter = n.begin();

  const Vector4ub tmpColor(m_color[0], m_color[1], m_color[2], m_opacity);
  while (vIter != vEnd)
    m_vertices.push_back(PackedVertex(tmpColor, *(nIter++), *(vIter++)));

  m_dirty = true;

  return static_cast<unsigned int>(result);
}
Пример #6
0
bool Molecule::removeAtom(Index index)
{
  if (index >= atomCount())
    return false;
  Index uniqueId = findAtomUniqueId(index);
  if (uniqueId == MaxIndex)
    return false;

  // Unique ID of an atom that was removed:
  m_atomUniqueIds[uniqueId] = MaxIndex;

  // Before removing the atom we must first remove any bonds to it.
  Core::Array<BondType> atomBonds = Core::Molecule::bonds(atom(index));
  while (atomBonds.size()) {
    removeBond(atomBonds.back());
    atomBonds = Core::Molecule::bonds(atom(index));
  }

  Index newSize = static_cast<Index>(m_atomicNumbers.size() - 1);
  if (index != newSize) {
    // We need to move the last atom to this position, and update its unique ID.
    m_atomicNumbers[index] = m_atomicNumbers.back();
    if (m_positions2d.size() == m_atomicNumbers.size())
      m_positions2d[index] = m_positions2d.back();
    if (m_positions3d.size() == m_atomicNumbers.size())
      m_positions3d[index] = m_positions3d.back();

    // Find any bonds to the moved atom and update their index.
    atomBonds = Core::Molecule::bonds(atom(newSize));
    foreach (const BondType& currentBond, atomBonds) {
      std::pair<Index, Index> pair = m_bondPairs[currentBond.index()];
      if (pair.first == newSize)
        pair.first = index;
      else if (pair.second == newSize)
        pair.second = index;
      m_bondPairs[currentBond.index()] = pair;
    }
Пример #7
0
unsigned int MeshGeometry::addVertices(const Core::Array<Vector3f>& v,
                                       const Core::Array<Vector3f>& n,
                                       const Core::Array<Vector4ub>& c)
{
  if (v.size() != n.size() || n.size() != c.size())
    return InvalidIndex;

  size_t result = m_vertices.size();

  Core::Array<Vector3f>::const_iterator vIter = v.begin();
  Core::Array<Vector3f>::const_iterator vEnd = v.end();
  Core::Array<Vector3f>::const_iterator nIter = n.begin();
  Core::Array<Vector4ub>::const_iterator cIter = c.begin();

  while (vIter != vEnd)
    m_vertices.push_back(PackedVertex(*(cIter++), *(nIter++), *(vIter++)));

  m_dirty = true;

  return static_cast<unsigned int>(result);
}
Пример #8
0
    Bool FileSystem::Find( const Char * searchStr, Core::Array< PathString >& fileNames, Bool absolute )
    {
        WIN32_FIND_DATA ffd;
        HANDLE hFind;

        hFind = FindFirstFile( searchStr, &ffd );
        if ( hFind == INVALID_HANDLE_VALUE ) 
        {
            return false;
        }

        Char dir[ 256 ];
        Char * fileStart = dir;

        if ( absolute )
        {
            if ( GetFullPathName( searchStr, 256, dir, &fileStart ) == 0 )
            {
                return false;
            }
        }

        do
        {
            if ( ! ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
            {
                PathString f( dir, fileStart - dir );
                f += ffd.cFileName;
                fileNames.PushBack( f );
            }
        }
        while ( FindNextFile( hFind, &ffd ) != 0 );

        FindClose( hFind );

        return true;
    }