void GeometryComponent::GotMessage(Object * sender, const std::string & message) { Component::GotMessage(sender, message); if (this->getOwner() == sender) { if (Object::isComponentAddedMessage(message)) { // TODO:: check GeometryComponent supports only one mesh per object auto holdedMesh = this->meshComponent.lock(); auto foundMesh = this->getOwner()->FindComponent<MeshComponent>(); if (holdedMesh != foundMesh) { this->releaseBuffers(); if (foundMesh) { this->setVertices(foundMesh->getVertices()); this->setIndices(foundMesh->getIndices()); indexCount = foundMesh->getIndices().size(); } this->meshComponent = foundMesh; } } } }
void CoeffsBase::setupBasisFunctionsInfo() { plumed_massert(indices_shape_.size()>0,"indices must be initialized before running this function"); if(coeffs_type_==LinearBasisSet) { for(unsigned int i=0; i<numberOfCoeffs(); i++) { std::vector<unsigned int> indices=getIndices(i); std::string desc; desc=basisf_[0]->getBasisFunctionLabel(indices[0]); for(unsigned int k=1; k<numberOfDimensions(); k++) { desc+="*"+basisf_[k]->getBasisFunctionLabel(indices[k]); } setCoeffDescription(i,desc); } } else if(coeffs_type_==MultiCoeffs_LinearBasisSet) { for(unsigned int i=0; i<numberOfCoeffs(); i++) { std::vector<unsigned int> indices=getIndices(i); unsigned int mc_id = indices[ndimensions_-1]; std::string mc_idstr; Tools::convert(mc_id,mc_idstr); // std::string mc_label = getDimensionLabel(ndimensions_-1); std::string postfix = ":" + mc_idstr; std::string desc =""; desc+=multicoeffs_basisf_[mc_id][0]->getBasisFunctionLabel(indices[0]); for(unsigned int k=1; k<(numberOfDimensions()-1); k++) { desc+="*"+multicoeffs_basisf_[mc_id][k]->getBasisFunctionLabel(indices[k]); } desc+=postfix; setCoeffDescription(i,desc); } } }
std::tuple<DenseColumnSubset, DenseColumnSubset> splitMatrix(DenseMatrix& matrix, const std::vector<std::string>& reference, const std::vector<std::string>& test) { return std::make_tuple( DenseColumnSubset( &matrix, getIndices(matrix, reference, "reference")), DenseColumnSubset( &matrix, getIndices(matrix, test, "test"))); }
bool CoinPackedVectorBase::operator==(const CoinPackedVectorBase &rhs) const { if (getNumElements() == 0 || rhs.getNumElements() == 0) { if (getNumElements() == 0 && rhs.getNumElements() == 0) return (true); else return (false); } else { return (getNumElements() == rhs.getNumElements() && std::equal(getIndices(), getIndices() + getNumElements(), rhs.getIndices()) && std::equal(getElements(), getElements() + getNumElements(), rhs.getElements())); } }
void LargeVoxelSphere::mesh() { PolyVox::Region region(PolyVox::Vector3DInt32(-120,-120,-120), PolyVox::Vector3DInt32(120, 120, 120)); auto encodedMesh = extractCubicMesh(mVolumeData, region); auto mesh = decodeMesh(encodedMesh); auto vertexOffset = static_cast<PolyVox::Vector3DFloat>(mesh.getOffset()); delete mVolumeData; mVolumeData = nullptr; // clear(); begin("BaseWhite", Ogre::RenderOperation::OT_TRIANGLE_LIST); { auto& vertices = mesh.getVertices(); auto& indices = mesh.getIndices(); for (auto index : indices) { auto& vertex = vertices[index]; auto vertexPos = vertex.position + vertexOffset; position(vertexPos.getX(), vertexPos.getY(), vertexPos.getZ()); // uint8_t mat = vertex.getMaterial() + 0.5; // uint8_t red = mat & 0xF0; // uint8_t green = mat & 0x03; // uint8_t blue = mat & 0x0C; // colour(red*2, green*4, blue*4); colour(1, 0, 0, 0.5); } } end(); }
void CoinPackedVectorBase::findMaxMinIndices() const { if (getNumElements() == 0) return; // if indexSet exists then grab begin and rend to get min & max indices else if (indexSetPtr_ != NULL) { maxIndex_ = *indexSetPtr_->rbegin(); minIndex_ = *indexSetPtr_->begin(); } else { // Have to scan through vector to find min and max. maxIndex_ = *(std::max_element(getIndices(), getIndices() + getNumElements())); minIndex_ = *(std::min_element(getIndices(), getIndices() + getNumElements())); } }
void BCP_lp_relax::pack(BCP_buffer& buf) const { const int major = getMajorDim(); const int minor = getMinorDim(); buf.pack(colOrdered_) .pack(extraGap_) .pack(extraMajor_) .pack(major) .pack(minor) .pack(size_) .pack(maxMajorDim_) .pack(maxSize_); const int * length = getVectorLengths(); const int * start = getVectorStarts(); const int * ind = getIndices(); const double * elem = getElements(); if (major > 0) { buf.pack(length, major); buf.pack(start, major+1); for (int i = 0; i < major; ++i) buf.pack(ind + start[i], length[i]); for (int i = 0; i < major; ++i) buf.pack(elem + start[i], length[i]); } buf.pack(_Objective).pack(_ColLowerBound).pack(_ColUpperBound) .pack(_RowLowerBound).pack(_RowUpperBound); }
hkResult HavokDisplayManager::addGeometry(const hkArrayBase<hkDisplayGeometry*>& geometries, const hkTransform& transform, hkUlong id, int tag, hkUlong shapeIdHint, hkGeometry::GeometryType createDyanamicGeometry /*= hkGeometry::GEOMETRY_STATIC*/) { auto& a = m_geometries[id]; vec3 newTranslation(DO_NOT_INITIALIZE); Quaternion newRotation(DO_NOT_INITIALIZE); gep::conversion::hk::fromHkTransform(transform, newTranslation, newRotation); mat4 newTransform = mat4::translationMatrix(newTranslation) * newRotation.toMat4() ; m_transformations[id] = newTransform; for (auto geom : geometries) { geom->buildGeometry(); auto pGeom = geom->getGeometry(); auto pDataHolder = GEP_NEW(g_stdAllocator, HavokDataHolder)(geom, pGeom->m_triangles); auto vertices = ArrayPtr<vec4>((vec4*)&pGeom->m_vertices[0], pGeom->m_vertices.getSize()); auto indices = pDataHolder->getIndices(); auto pModel = g_globalManager.getRenderer()->loadModel(pDataHolder, vertices, indices); a.append(pModel); } return HK_SUCCESS; }
void TriangleMeshData::getDataProperty(int property, void **_pvData) { if (property == NUM_VERTICES) { ((int *)*_pvData)[0] = getNumVertices(); } else if (property == NUM_INDICES) { ((int *)*_pvData)[0] = getNumIndices(); } else if (property == COORDINATES) { *_pvData = getVertices(); } else if (property == INDICES) { *_pvData = getIndices(); } else if (property == VALUES) { *_pvData = getValues(); } else { Data3D::getDataProperty(property, _pvData); } }
std::set<int> * CoinPackedVectorBase::indexSet(const char* methodName, const char * className) const { testedDuplicateIndex_ = true; if ( indexSetPtr_ == NULL ) { // create a set of the indices indexSetPtr_ = new std::set<int>; const int s = getNumElements(); const int * inds = getIndices(); for (int j=0; j < s; ++j) { if (!indexSetPtr_->insert(inds[j]).second) { testedDuplicateIndex_ = false; delete indexSetPtr_; indexSetPtr_ = NULL; if (methodName != NULL) { throw CoinError("Duplicate index found", methodName, className); } else { throw CoinError("Duplicate index found", "indexSet", "CoinPackedVectorBase"); } } } } return indexSetPtr_; }
void VirtualFont::incrementSequence(QuadBatch *batch) { if (sequenceUseColor) { batch->addColor(color); } if (batch->size() == properties.slotCapacity) { if (sequence) { batchMap->pack(); sequence->addMap(move(batchMap)); } else { begin(sequenceUseColor); batchMap->flush(getIndices(), sequenceUseColor, anisotropy); end(sequenceUseColor); } if (!batchMap) { batchMap = unique_ptr<QuadBatchMap<FontTexture>>(new QuadBatchMap<FontTexture>); } else { batchMap->clear(); } } }
//------------------------------------------------------------------------- unsigned int Volume::getIndex( const gmtl::Vec3f &i_point )const { gmtl::Vec3i indices= getIndices(i_point[0],i_point[1],i_point[2]); return indices[0] + indices[1]*m_noOfVoxelsX + indices[2]*m_noOfVoxelsX*m_noOfVoxelsY; }
int CoinPackedVectorBase::findIndex(int i) const { const int * inds = getIndices(); int retVal = static_cast<int>(std::find(inds, inds + getNumElements(), i) - inds); if (retVal == getNumElements() ) retVal = -1; return retVal; }
//-------------------------------------------------------------- vector<ofIndexType> ofBoxPrimitive::getSideIndices( int sideIndex ) const { if(sideIndex < 0 || sideIndex >= SIDES_TOTAL) { ofLogWarning("ofBoxPrimitive") << "getSideIndices(): faceIndex out of bounds, returning SIDE_FRONT"; sideIndex = SIDE_FRONT; } return getIndices(strides[sideIndex][0], strides[sideIndex][0]+strides[sideIndex][1]); }
double CoinPackedVectorBase::dotProduct(const double* dense) const { const double * elems = getElements(); const int * inds = getIndices(); double dp = 0.0; for (int i = getNumElements() - 1; i >= 0; --i) dp += elems[i] * dense[inds[i]]; return dp; }
Shadow::Shadow(World *world) : Ghost(world) { CL_Sizef fieldSize = world->getLevel()->getFieldSize(); //Startposition ist die rechte, obere Ecke position = CL_Pointf(26 * fieldSize.width + fieldSize.width / 2, 1 * fieldSize.height + fieldSize.height / 2); currentField = getIndices(position); setBody("Shadow"); onFieldCenter(); }
IndexRange getSurroundingIndices(const ArrayType& center, const ArrayType& distance) const { ArrayType zero; ArrayType range; for (size_t i(0); i < NDim; ++i) { zero[i] = (center[i] + _dimensions[i] - distance[i]) % _dimensions[i]; range[i] = 2 * distance[i] + 1; } return getIndices(zero, range); }
/** * estimateNormals */ void ZAdaptiveNormals::estimateNormals(const v4r::DataMatrix2D<Eigen::Vector3f> &cloud, const std::vector<int> &normals_indices, std::vector<Eigen::Vector3f> &normals) { EIGEN_ALIGN16 Eigen::Matrix3f eigen_vectors; std::vector< int > indices; #pragma omp parallel for private(eigen_vectors,indices) for (unsigned i=0; i<normals_indices.size(); i++) { indices.clear(); int idx = normals_indices[i]; int u = idx%width; int v = idx/width; const Eigen::Vector3f &pt = cloud.data[idx]; Eigen::Vector3f &n = normals[i]; if(!std::isnan(pt[0]) && !std::isnan(pt[1]) && !std::isnan(pt[2])) { if(param.adaptive) { int dist = (int) (pt[2]*2); // *2 => every 0.5 meter another kernel radius getIndices(cloud, u,v, param.kernel_radius[dist], indices); } else getIndices(cloud, u,v, param.kernel, indices); } if (indices.size()<4) { n[0] = NaN; continue; } /* curvature= */ computeNormal(cloud, indices, eigen_vectors); n[0] = eigen_vectors (0,0); n[1] = eigen_vectors (1,0); n[2] = eigen_vectors (2,0); if (n.dot(pt) > 0) { n *= -1; //n.getNormalVector4fMap()[3] = 0; //n.getNormalVector4fMap()[3] = -1 * n.getNormalVector4fMap().dot(pt.getVector4fMap()); } } }
void CoeffsBase::setAllCoeffsDescriptions(const std::string& description_prefix) { for(size_t i=0; i<numberOfCoeffs(); i++) { std::vector<unsigned int> indices=getIndices(i); std::string is; Tools::convert(indices[0],is); std::string desc=description_prefix+"("+is; for(unsigned int k=1; k<numberOfDimensions(); k++) { Tools::convert(indices[k],is); desc+=","+is; } desc+=")"; coeffs_descriptions_[i]=desc; } }
int CoinPackedVectorBase::compare(const CoinPackedVectorBase &rhs) const { const int size = getNumElements(); int itmp = size - rhs.getNumElements(); if (itmp != 0) { return itmp; } itmp = memcmp(getIndices(), rhs.getIndices(), size * sizeof(int)); if (itmp != 0) { return itmp; } return memcmp(getElements(), rhs.getElements(), size * sizeof(double)); }
STDMETHODIMP CVisComplexObj::get_indices(VARIANT *pVal) { double *data = getIndices(); double *newdata = CopyDoubleArrayStruct(data); if (newdata) { int len = GetLength(data); for (int i=0; i<len; ++i) newdata[i] = ((unsigned int *)data)[i]; } VariantFromDoubleArray(newdata, pVal); FreeDoubleArray(newdata); return S_OK; }
// NOTE Can i make this process faster? // NOTE Why should i have a seperate class for dynamic and static models StaticModel::StaticModel(const Model3D* const model, const glm::mat4& world) : m_model(model), m_world(world), m_sampler(std::make_unique<Sampler>()) { if(model == nullptr) { throw GenericException("Null param passed to StaticModel constructor"); } m_meshCount = m_model->getMeshCount(); for(unsigned int i = 0; i < m_meshCount; i++) { auto mesh = m_model->getMesh(i); GLuint vbo, vao, ibo; glGenVertexArrays(1, &vao); glBindVertexArray(vao); m_VAO.push_back(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(Model3D::Vertex) * mesh->getVertices().size(), mesh->getVertices().data(), GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), (GLvoid*)sizeof(glm::vec3)); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Model3D::Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec3))); m_VBO.push_back(vbo); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glGenBuffers(1, &ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * mesh->getIndices().size(), mesh->getIndices().data(), GL_STATIC_DRAW); m_indexCount.push_back(mesh->getIndices().size()); m_IBO.push_back(ibo); } }
bool Character::update(float elapsed) { float distance = speed * elapsed; //Distanz zum nächsten Feld berechnen CL_Point nextField = getNextField(moveDirection); CL_Pointf nextFieldCoordinates = getCoordinates(nextField); float distanceToField = abs(position.x - nextFieldCoordinates.x) + abs(position.y - nextFieldCoordinates.y); //Ist die zurückzulegende Distanz größer als die Distanz zum nächsten Feldmittelpunkt //und ist das Feld frei, so muss eine eventuelle Richtungsänderung geprüft werden while (distance > distanceToField && world->getLevel()->isFreeField(nextField)) { //Zum Feldmittelpunkt bewegen move(distanceToField); distance -= distanceToField; currentField = getIndices(nextFieldCoordinates); //wird für erbende Klassen aufgerufen, um Aktionen auf dem Feldmittelpunkt ausführen zu können onFieldCenter(); //Ist eine Richtungsänderung möglich, dann Richtung ändern if(world->getLevel()->isFreeField(getNextField(newDirection))) moveDirection = newDirection; //Distanz zum nächsten Feld berechnen nextField = getNextField(moveDirection); nextFieldCoordinates = getCoordinates(nextField); distanceToField = abs(position.x - nextFieldCoordinates.x) + abs(position.y - nextFieldCoordinates.y); } //Spielfigur weiterbewegen bzw. Richtung ändern if(world->getLevel()->isFreeField(nextField)) move(distance); else if(world->getLevel()->isFreeField(getNextField(newDirection))) moveDirection = newDirection; animationPos += elapsed * animationSpeed; while (animationPos >= animationLength) animationPos -= animationLength; body.set_frame(getAnimationPos()); return true; }
/* Select every 'interval' points */ vector<vector<FragmentInfo>> TriangulationPointsFixedInterval(const vector<ContourEQW>& contours, int interval) { vector<vector<FragmentInfo>> placements(contours.size()); //contour points selected for triangulation //first select all contour end-points. for(int i=0; i<contours.size(); ++i) { vector<int> range = getIndices(0, contours[i].size()-1, interval); for(int j=0; j<range.size(); ++j) { placements[i].push_back(FragmentInfo(i, range[j])); } } return placements; }
double * CoinPackedVectorBase::denseVector(int denseSize) const { if (getMaxIndex() >= denseSize) throw CoinError("Dense vector size is less than max index", "denseVector", "CoinPackedVectorBase"); double * dv = new double[denseSize]; CoinFillN(dv, denseSize, 0.0); const int s = getNumElements(); const int * inds = getIndices(); const double * elems = getElements(); for (int i = 0; i < s; ++i) dv[inds[i]] = elems[i]; return dv; }
void VectorPortBit::getConnectedNets(std::vector<NetSharedPtr>& outNets, bool inSkipChildConnections) const throw (Error) { //First get connections exclusive to me Port::getConnectedNets(outNets); //Append cousins from nets that have been connected to my //parent if(!inSkipChildConnections) { VectorBit<Net>::List parentConnections; Composite<Port>::Pointer parent = getParentCollection(); if(!parent) { Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__); e.saveContextData("Pointer to parent collection does not exist", parent); throw e; } if(eCompositionTypeVector != parent->getCompositionType()) { Error e(eMessageIdErrorCompositionTypeMismatch, __FUNCTION__, __FILE__, __LINE__); e.saveContextData("Composition type mismatch", parent->getCompositionType()); throw e; } parent->getConnectedNets(parentConnections, true); VectorBit<Net>::List::iterator connNet = parentConnections.begin(); VectorBit<Net>::List::iterator connNetEnd = parentConnections.end(); const std::vector<VectorBit<Net>::SizeType>& myIndex = getIndices(); for(; connNet != connNetEnd; ++connNet) { Composite<Net>::Pointer cousin; if(eCompositionTypeVector == (*connNet)->getCompositionType()) { cousin = (*connNet)->get(myIndex); //We don't want to mess up preservervation //by calling getChildren() } else //Must be a bundle { VectorBit<Net>::List bChildren; (*connNet)->getChildren(bChildren); cousin = bChildren[getAbsoluteIndex()]; //We assume list is a vector } if(!cousin) { Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__); e.saveContextData("Pointer to item does not exist", cousin); throw e; } outNets.push_back(cousin); } } return; }
ofxMesh &ofxMesh::addMesh(ofMesh b) { int numVertices = getNumVertices(); int numIndices = getNumIndices(); //add b addVertices(b.getVertices()); addNormals(b.getNormals()); addIndices(b.getIndices()); //shift indices for b for (int i=0; i<b.getNumIndices(); i++) { getIndices()[numIndices+i] += numVertices; } return *this; }
void ofxMesh::fromMesh(const ofMesh & mesh){ if (mesh.hasVertices()) { getVertices()=mesh.getVertices(); } if (mesh.hasColors()) { getColors()=mesh.getColors(); } if (mesh.hasNormals()) { getNormals()=mesh.getNormals(); } if (mesh.hasTexCoords()) { getTexCoords()=mesh.getTexCoords(); } if (mesh.hasIndices()) { getIndices()=mesh.getIndices(); } }
void ofxMesh::toMesh(ofMesh & mesh){ mesh.clear(); if (hasVertices()) { mesh.getVertices()=getVertices(); } if (hasColors()) { mesh.getColors()=getColors(); } if (hasNormals()) { mesh.getNormals()=getNormals(); } if (hasTexCoords()) { mesh.getTexCoords()=getTexCoords(); } if (hasIndices()) { mesh.getIndices()=getIndices(); } }
void Init() { PROFILE_SCOPED() frac = 1.0 / double(edgeLen-1); // also want vtx indices for tris not touching edge of patch indices.reset(new unsigned short[IDX_VBO_COUNT_ALL_IDX()]); unsigned short *idx = indices.get(); for (int x=0; x<edgeLen-1; x++) { for (int y=0; y<edgeLen-1; y++) { idx[0] = x + edgeLen*y; idx[1] = x+1 + edgeLen*y; idx[2] = x + edgeLen*(y+1); idx+=3; idx[0] = x+1 + edgeLen*y; idx[1] = x+1 + edgeLen*(y+1); idx[2] = x + edgeLen*(y+1); idx+=3; } } // these will hold the optimised indices std::vector<unsigned short> pl_short; // populate the N indices lists from the arrays built during InitTerrainIndices() // iterate over each index list and optimize it unsigned int tri_count = getIndices(pl_short); VertexCacheOptimizerUShort vco; VertexCacheOptimizerUShort::Result res = vco.Optimize(&pl_short[0], tri_count); assert(0 == res); //create buffer & copy indexBuffer.Reset(Pi::renderer->CreateIndexBuffer(pl_short.size(), Graphics::BUFFER_USAGE_STATIC)); Uint16* idxPtr = indexBuffer->Map(Graphics::BUFFER_MAP_WRITE); for (Uint32 j = 0; j < pl_short.size(); j++) { idxPtr[j] = pl_short[j]; } indexBuffer->Unmap(); if (indices) { indices.reset(); } }