void CGraph::getNodes(size_t start_node, size_t num_nodes, Mat& pots) const { if (!num_nodes) num_nodes = getNumNodes() - start_node; // Assertions DGM_ASSERT_MSG(start_node + num_nodes <= getNumNodes(), "The given ranges exceed the number of nodes(%zu)", getNumNodes()); if (pots.empty() || pots.cols != m_nStates || pots.rows != num_nodes) pots = Mat(static_cast<int>(num_nodes), m_nStates, CV_32FC1); transpose(pots, pots); #ifdef ENABLE_PPL int size = pots.cols; int rangeSize = size / (concurrency::GetProcessorCount() * 10); rangeSize = MAX(1, rangeSize); //printf("Processors: %d\n", concurrency::GetProcessorCount()); concurrency::parallel_for(0, size, rangeSize, [start_node, size, rangeSize, &pots, this](int i) { Mat pot; for (int j = 0; (j < rangeSize) && (i + j < size); j++) getNode(start_node + i + j, lvalue_cast(pots.col(i + j))); }); #else for (int n = 0; n < pots.cols; n++) getNode(start_node + n, lvalue_cast(pots.col(n))); #endif transpose(pots, pots); }
//-------------------------------------------------------------- ofVec3f ofxBulletSoftBody::getPosition() const { ofVec3f avgpos; for ( int i = 0; i < getNumNodes(); i++ ) { avgpos += getNodePos(i); } avgpos /= (float)getNumNodes(); return avgpos; }
bool ProcessorGraph::enableProcessors() { updateConnections(getEditorViewport()->requestSignalChain()); std::cout << "Enabling processors..." << std::endl; bool allClear; if (getNumNodes() < 5) { getUIComponent()->disableCallbacks(); return false; } for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = (GenericProcessor*) node->getProcessor(); allClear = p->isReady(); if (!allClear) { std::cout << p->getName() << " said it's not OK." << std::endl; // sendActionMessage("Could not initialize acquisition."); getUIComponent()->disableCallbacks(); return false; } } } for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = (GenericProcessor*) node->getProcessor(); p->enableEditor(); p->enable(); } } getEditorViewport()->signalChainCanBeEdited(false); // sendActionMessage("Acquisition started."); return true; }
GraphFlow *getResidualNetwork(GraphFlow *g) { GraphFlow *newGraph = newGraphFlow( getNumNodes(g), getSource(g), getSink(g) ); int i = 0, j = 0; int capacity = 0; for(i=0; i < getNumNodes(newGraph); i++) { for(j=0; i < getNumNodes(newGraph); i++) { capacity = getResidualCapacity(g,i,j); if(capacity > 0) { addEdge(newGraph,i,j); setCapacity(newGraph,i,j,capacity); } } } }
void TR_LocalAnalysis::initializeLocalAnalysis(bool isSparse, bool lock) { _info = (TR_LocalAnalysisInfo::LAInfo*) trMemory()->allocateStackMemory(_lainfo._numBlocks*sizeof(TR_LocalAnalysisInfo::LAInfo)); memset(_info, 0, _lainfo._numBlocks*sizeof(TR_LocalAnalysisInfo::LAInfo)); TR::BitVector blocksSeen(comp()->allocator()); initializeBlocks(toBlock(comp()->getFlowGraph()->getStart()), blocksSeen); int32_t i; for (i = 0; i < _lainfo._numBlocks; i++) { _info[i]._analysisInfo = allocateContainer(getNumNodes()); _info[i]._downwardExposedAnalysisInfo = allocateContainer(getNumNodes()); _info[i]._downwardExposedStoreAnalysisInfo = allocateContainer(getNumNodes()); } }
Array<GenericProcessor*> ProcessorGraph::getListOfProcessors() { Array<GenericProcessor*> a; for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); int nodeId = node->nodeId; if (nodeId != OUTPUT_NODE_ID && nodeId != AUDIO_NODE_ID && nodeId != RECORD_NODE_ID && nodeId != RESAMPLING_NODE_ID && nodeId != MESSAGE_CENTER_ID) { GenericProcessor* p =(GenericProcessor*) node->getProcessor(); a.add(p); } } return a; }
void ProcessorGraph::clearConnections() { for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); int nodeId = node->nodeId; if (nodeId != OUTPUT_NODE_ID) { if (nodeId != RECORD_NODE_ID && nodeId != AUDIO_NODE_ID) { disconnectNode(node->nodeId); } GenericProcessor* p = (GenericProcessor*) node->getProcessor(); p->resetConnections(); } } // connect audio subnetwork for (int n = 0; n < 2; n++) { addConnection(AUDIO_NODE_ID, n, OUTPUT_NODE_ID, n); } addConnection(MESSAGE_CENTER_ID, midiChannelIndex, RECORD_NODE_ID, midiChannelIndex); }
int runLRSBaked(string fName, int numSamples) { srand((unsigned(time(NULL)))); cout << "numSamples: " << numSamples << endl; cout << "Getting gammas..." << endl; int best = INT_MAX; vector<LPEdge> hkSoln = getHKSolutionsBaked(fName, false); vector<ModEdge> graph = xToZ(lpToMod(hkSoln)); vector<double> lambda = getLambdaBaked(fName, graph); weightGraph(graph, lambda); int numNodes = getNumNodes(graph); Graph g = Graph(fName, false); cout << "Done getting gammas" << endl; int numErrs = 0; for (int i = 0; i < numSamples; i++) { int n = numNodes; int cur = getLRSTourFast(graph, lambda, g, n); best = min(cur, best); if (cur == INT_MAX) numErrs++; } cout << "Number of errors: " << numErrs << " out of " << numSamples << " samples" << endl; return best; }
// ---------------------------------------------------------------------------- void ArenaGraph::setNearbyNodesOfAllNodes() { // Only save the nearby 8 nodes const unsigned int try_count = 8; for (unsigned int i = 0; i < getNumNodes(); i++) { // Get the distance to all nodes at i ArenaNode* cur_node = getNode(i); std::vector<int> nearby_nodes; std::vector<float> dist = m_distance_matrix[i]; // Skip the same node dist[i] = 999999.0f; for (unsigned int j = 0; j < try_count; j++) { std::vector<float>::iterator it = std::min_element(dist.begin(), dist.end()); const int pos = int(it - dist.begin()); nearby_nodes.push_back(pos); dist[pos] = 999999.0f; } cur_node->setNearbyNodes(nearby_nodes); } } // setNearbyNodesOfAllNodes
/** This function defines the "path-to-nodes" for each graph node that has * more than one successor. The path-to-nodes indicates which successor to * use to reach a certain node. This is e.g. used for the rubber ball to * determine which path it is going to use to reach its target (this allows * the ball to hit a target that is on a shortcut). The algorithm for the * path computation favours the use of successor 0, i.e. it will if possible * only use main driveline paths, not a shortcut (even though a shortcut * could result in a faster way to the target) - but since shotcuts can * potentially be hidden they should not be used (unless necessary). * Only graph nodes with more than one successor have this data structure * (since on other graph nodes only one path can be used anyway, this * saves some memory). */ void QuadGraph::setupPaths() { for(unsigned int i=0; i<getNumNodes(); i++) { m_all_nodes[i]->setupPathsToNode(); } } // setupPaths
// 1 void test_getNumNodes_Vine_has_1_Nodes_should_return_1(void){ setNode(&node1, NULL, NULL, 'b'); Node *vine = &node1; int num = getNumNodes(vine); TEST_ASSERT_EQUAL(1,num); }
void ProcessorGraph::clearSignalChain() { int n = 0; while (getNumNodes() > 4) { Node* node = getNode(n); int nodeId = node->nodeId; if (nodeId != OUTPUT_NODE_ID && nodeId != AUDIO_NODE_ID && nodeId != RECORD_NODE_ID && nodeId != RESAMPLING_NODE_ID) { GenericProcessor* p =(GenericProcessor*) node->getProcessor(); removeProcessor(p); } else { n++; } } }
/** This function defines the "path-to-nodes" for each graph node that has * more than one successor. The path-to-nodes indicates which successor to * use to reach a certain node. This is e.g. used for the rubber ball to * determine which path it is going to use to reach its target (this allows * the ball to hit a target that is on a shortcut). The algorithm for the * path computation favours the use of successor 0, i.e. it will if possible * only use main driveline paths, not a shortcut (even though a shortcut * could result in a faster way to the target) - but since shotcuts can * potentially be hidden they should not be used (unless necessary). * Only graph nodes with more than one successor have this data structure * (since on other graph nodes only one path can be used anyway, this * saves some memory). */ void DriveGraph::setupPaths() { for(unsigned int i=0; i<getNumNodes(); i++) { getNode(i)->setupPathsToNode(); } } // setupPaths
void ProcessorGraph::clearConnections() { for (int i = 0; i < getNumConnections(); i++) { const Connection* connection = getConnection(i); if (connection->destNodeId == RESAMPLING_NODE_ID || connection->destNodeId == OUTPUT_NODE_ID) { ; // leave it } else { removeConnection(i); } } for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p =(GenericProcessor*) node->getProcessor(); p->resetConnections(); } } }
// ---------------------------------------------------------------------------- void ArenaGraph::buildGraph() { const unsigned int n_nodes = getNumNodes(); m_distance_matrix = std::vector<std::vector<float>> (n_nodes, std::vector<float>(n_nodes, 9999.9f)); for (unsigned int i = 0; i < n_nodes; i++) { ArenaNode* cur_node = getNode(i); for (const int& adjacent : cur_node->getAdjacentNodes()) { Vec3 diff = getNode(adjacent)->getCenter() - cur_node->getCenter(); float distance = diff.length(); m_distance_matrix[i][adjacent] = distance; } m_distance_matrix[i][i] = 0.0f; } // Allocate and initialise the previous node data structure: m_parent_node = std::vector<std::vector<int16_t>> (n_nodes, std::vector<int16_t>(n_nodes, Graph::UNKNOWN_SECTOR)); for (unsigned int i = 0; i < n_nodes; i++) { for (unsigned int j = 0; j < n_nodes; j++) { if (i == j || m_distance_matrix[i][j] >= 9899.9f) m_parent_node[i][j] = -1; else m_parent_node[i][j] = i; } // for j } // for i } // buildGraph
void ProcessorGraph::setRecordState(bool isRecording) { // actually start recording if (isRecording) { getRecordNode()->setParameter(1,10.0f); } else { getRecordNode()->setParameter(0,10.0f); } for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = (GenericProcessor*) node->getProcessor(); p->setRecording(isRecording); } } }
//-------------------------------------------------------------- void ofxBulletSoftTriMesh::updateMesh( ofMesh& aMesh ) { int totalNodes = getNumNodes(); auto& tverts = aMesh.getVertices(); if( _cachedMesh.getMode() == OF_PRIMITIVE_TRIANGLES ) { if( tverts.size() != totalNodes ) { tverts.resize( totalNodes ); } auto& tnormals = aMesh.getNormals(); if( aMesh.getNumNormals() != totalNodes ) { tnormals.resize( totalNodes ); } for( int i = 0; i < totalNodes; i++ ) { tverts[i].x = _softBody->m_nodes[i].m_x.x(); tverts[i].y = _softBody->m_nodes[i].m_x.y(); tverts[i].z = _softBody->m_nodes[i].m_x.z(); tnormals[i].x = _softBody->m_nodes[i].m_n.x(); tnormals[i].y = _softBody->m_nodes[i].m_n.y(); tnormals[i].z = _softBody->m_nodes[i].m_n.z(); } } _lastMeshUpdateFrame = ofGetFrameNum(); }
bool ProcessorGraph::disableProcessors() { std::cout << "Disabling processors..." << std::endl; bool allClear; for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = (GenericProcessor*) node->getProcessor(); std::cout << "Disabling " << p->getName() << std::endl; p->disableEditor(); allClear = p->disable(); if (!allClear) { // sendActionMessage("Could not stop acquisition."); return false; } } } getEditorViewport()->signalChainCanBeEdited(true); // sendActionMessage("Acquisition ended."); return true; }
void ProcessorGraph::setRecordState(bool isRecording) { // const MessageManagerLock mmLock; // lock the message manager to prevent rendering crashes // inform other processors that recording will begin // actually start recording if (isRecording) { getRecordNode()->setParameter(1,10.0f); } else { getRecordNode()->setParameter(0,10.0f); } for (int i = 0; i < getNumNodes(); i++) { Node* node = getNode(i); if (node->nodeId != OUTPUT_NODE_ID) { GenericProcessor* p = (GenericProcessor*) node->getProcessor(); if (isRecording) p->startRecording(); else p->stopRecording(); } } }
bool PViewData::writeTXT(const std::string &fileName) { FILE *fp = Fopen(fileName.c_str(), "w"); if(!fp){ Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } for(int step = 0; step < getNumTimeSteps(); step++){ for(int ent = 0; ent < getNumEntities(step); ent++){ for(int ele = 0; ele < getNumElements(step, ent); ele++){ if(skipElement(step, ent, ele)) continue; for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ double x, y, z; getNode(step, ent, ele, nod, x, y, z); fprintf(fp, "%d %.16g %d %d %.16g %.16g %.16g ", step, getTime(step), ent, ele, x, y, z); for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){ double val; getValue(step, ent, ele, nod, comp, val); fprintf(fp, "%.16g ", val); } } fprintf(fp, "\n"); } } } fclose(fp); return true; }
/** Increases the distance from start for all nodes that are directly or * indirectly a successor of the given node. This code is used when two * branches merge together, but since the latest 'fork' indicates a longer * distance from start. * \param indx Index of the node for which to increase the distance. * \param delta Amount by which to increase the distance. * \param recursive_count Counts how often this function was called * recursively in order to catch incorrect graphs that contain loops. */ void QuadGraph::updateDistancesForAllSuccessors(unsigned int indx, float delta, unsigned int recursive_count) { if(recursive_count>getNumNodes()) { Log::error("QuadGraph", "Quad graph contains a loop (without start node)."); Log::fatal("QuadGraph", "Fix graph, check for directions of all shortcuts etc."); } recursive_count++; GraphNode &g=getNode(indx); g.setDistanceFromStart(g.getDistanceFromStart()+delta); for(unsigned int i=0; i<g.getNumberOfSuccessors(); i++) { GraphNode &g_next = getNode(g.getSuccessor(i)); // Stop when we reach the start node, i.e. the only node with a // distance of 0 if(g_next.getDistanceFromStart()==0) continue; // Only increase the distance from start of a successor node, if // this successor has a distance from start that is smaller then // the increased amount. if(g.getDistanceFromStart()+g.getDistanceToSuccessor(i) > g_next.getDistanceFromStart()) { updateDistancesForAllSuccessors(g.getSuccessor(i), delta, recursive_count); } } } // updateDistancesForAllSuccessors
bool PViewData::writeSTL(const std::string &fileName) { FILE *fp = Fopen(fileName.c_str(), "w"); if(!fp){ Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } if(!getNumTriangles() && !getNumQuadrangles()){ Msg::Error("No surface elements to save"); fclose(fp); return false; } int step = getFirstNonEmptyTimeStep(); fprintf(fp, "solid Created by Gmsh\n"); for(int ent = 0; ent < getNumEntities(step); ent++){ for(int ele = 0; ele < getNumElements(step, ent); ele++){ if(getDimension(step, ent, ele) != 2) continue; if(skipElement(step, ent, ele)) continue; int N = getNumNodes(step, ent, ele); if(N != 3 && N != 4) continue; double x[4], y[4], z[4], n[3]; for(int i = 0; i < N; i++) getNode(step, ent, ele, i, x[i], y[i], z[i]); normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n); if(N == 3){ fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); fprintf(fp, " vertex %g %g %g\n", x[0], y[0], z[0]); fprintf(fp, " vertex %g %g %g\n", x[1], y[1], z[1]); fprintf(fp, " vertex %g %g %g\n", x[2], y[2], z[2]); fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); } else{ fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); fprintf(fp, " vertex %g %g %g\n", x[0], y[0], z[0]); fprintf(fp, " vertex %g %g %g\n", x[1], y[1], z[1]); fprintf(fp, " vertex %g %g %g\n", x[2], y[2], z[2]); fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); fprintf(fp, " vertex %g %g %g\n", x[0], y[0], z[0]); fprintf(fp, " vertex %g %g %g\n", x[2], y[2], z[2]); fprintf(fp, " vertex %g %g %g\n", x[3], y[3], z[3]); fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); } } } fprintf(fp, "endsolid Created by Gmsh\n"); fclose(fp); return true; }
void ModelComponent::animate() { if (_animated) { return; } _animation->animate(_hier, getNumNodes()); _animated = true; }
int flowConservative2(GraphFlow *g) { int i = 0; int j = 0; int balance = 0; for( i=0; i < getNumNodes(g); i++) { if( i != getSource(g) && i != getSink(g) ) { for(j=0, balance =0; j < getNumNodes(g); j++) { balance += getFlow(g,i,j); } if(balance != 0) return FALSE; } } return TRUE; }
void TransferPhysicsToGraphicsMeshBehavior::update(double dt) { auto state = m_source->getFinalState(); for (size_t nodeId = 0; nodeId < state->getNumNodes(); ++nodeId) { m_target->getMesh()->setVertexPosition(nodeId, state->getPosition(nodeId)); } }
/* private */ void cleanFlow(GraphFlow *g) { int numNodes = getNumNodes(g); int a = 0, b = 0; for(a = 0; a < numNodes; a++) { for(b = 0; b < numNodes; b++) { g->f[a][b] = 0; } } }
// 1-2-3 void test_getNumNodes_Vine_has_3_Nodes_should_return_3(void){ setNode(&node1, NULL, &node2, 'b'); setNode(&node2, NULL, &node3, 'b'); setNode(&node3, NULL, NULL, 'b'); Node *vine = &node1; int num = getNumNodes(vine); TEST_ASSERT_EQUAL(3,num); }
Relation* RelationList::findRelation(Node* node0, Node* node1){ for (int i=0; i<getNumNodes(); i++) { Relation* relation = (Relation*)getNodeAt(i); if ( (relation->getNode0()==node0 && relation->getNode1()==node1) || (relation->getNode0()==node1 && relation->getNode1()==node0) ) { return relation; } } return NULL; }
void Skeleton::setPose(const VectorXd& state, bool bCalcTrans, bool bCalcDeriv) { mCurrPose = state; for (int i = 0; i < getNumDofs(); i++) { mDofs.at(i)->setValue(state[i]); } if (bCalcTrans) { for (int i = 0; i < getNumNodes(); i++) { mNodes.at(i)->updateTransform(); } } if (bCalcDeriv) { for (int i = 0; i < getNumNodes(); i++) { mNodes.at(i)->updateFirstDerivatives(); } } }
void Skeleton::setConfig(std::vector<int> _id, Eigen::VectorXd _vals, bool _calcTrans, bool _calcDeriv) { for( unsigned int i = 0; i < _id.size(); i++ ) { mCurrPose[_id[i]] = _vals(i); mDofs[_id[i]]->setValue(_vals(i)); } // TODO: Only do the necessary updates if (_calcTrans) { for (int i = 0; i < getNumNodes(); i++) { mNodes.at(i)->updateTransform(); } } if (_calcDeriv) { for (int i = 0; i < getNumNodes(); i++) { mNodes.at(i)->updateFirstDerivatives(); } } }