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