void testCopy() { NodeRef orig = DeviceInterface::create ( "orig" ); orig->add_child(Terminal::create("child1")); orig->add_child(Terminal::create("child2")); NodeRef copy(orig); CPPUNIT_ASSERT ( copy->has_children() ); CPPUNIT_ASSERT ( std::string("child1") == copy->get_child("child1")->get_name() ); CPPUNIT_ASSERT ( std::string("child2") == copy->get_child("child2")->get_name() ); CPPUNIT_ASSERT_THROW ( copy->get_child("child3") , Exception ); NodeRef orig2 = DeviceInterface::create("orig"); orig2->add_child(Terminal::create("child3")); orig2->add_child(Terminal::create("child4")); CPPUNIT_ASSERT_THROW ( orig2->add_child(Terminal::create("child3")), Exception ); copy = orig2; CPPUNIT_ASSERT ( copy->has_children() ); CPPUNIT_ASSERT_THROW ( copy->get_child("child1"), Exception ); CPPUNIT_ASSERT_EQUAL ( std::string("child3") , copy->get_child("child3")->get_name() ); int children=0; for (DITreeIter i = copy->child_begin(); i != copy->child_end(); ++i ) { children += 1; } CPPUNIT_ASSERT ( children == 2 ); };
void Path::moveLeft(unsigned Level) { assert(Level != 0 && "Cannot move the root node"); // Go up the tree until we can go left. unsigned l = 0; if (valid()) { l = Level - 1; while (path[l].offset == 0) { assert(l != 0 && "Cannot move beyond begin()"); --l; } } else if (height() < Level) // end() may have created a height=0 path. path.resize(Level + 1, Entry(nullptr, 0, 0)); // NR is the subtree containing our left sibling. --path[l].offset; NodeRef NR = subtree(l); // Get the rightmost node in the subtree. for (++l; l != Level; ++l) { path[l] = Entry(NR, NR.size() - 1); NR = NR.subtree(NR.size() - 1); } path[l] = Entry(NR, NR.size() - 1); }
__m256 BVH2Intersector8Chunk<TriangleIntersector>::occluded(const BVH2Intersector8Chunk* This, Ray8& ray, const __m256 valid_i) { avxb valid = valid_i; avxb terminated = !valid; const BVH2* bvh = This->bvh; STAT3(shadow.travs,1,popcnt(valid),8); NodeRef stack[1+BVH2::maxDepth]; //!< stack of nodes that still need to get traversed NodeRef* stackPtr = stack; //!< current stack pointer NodeRef cur = bvh->root; //!< in cur we track the ID of the current node /* let inactive rays miss all boxes */ const avx3f rdir = rcp_safe(ray.dir); avxf rayFar = select(terminated,avxf(neg_inf),ray.tfar); while (true) { /*! downtraversal loop */ while (likely(cur.isNode())) { STAT3(normal.trav_nodes,1,popcnt(valid),8); /* intersect packet with box of both children */ const Node* node = cur.node(); const size_t hit0 = intersectBox(ray.org,rdir,ray.tnear,rayFar,node,0); const size_t hit1 = intersectBox(ray.org,rdir,ray.tnear,rayFar,node,1); /*! if two children are hit push both onto stack */ if (likely(hit0 != 0 && hit1 != 0)) { *stackPtr = node->child(0); stackPtr++; cur = node->child(1); } /*! if one child hit, continue with that child */ else { if (likely(hit0 != 0)) cur = node->child(0); else if (likely(hit1 != 0)) cur = node->child(1); else goto pop_node; } } /*! leaf node, intersect all triangles */ { STAT3(shadow.trav_leaves,1,popcnt(valid),8); size_t num; Triangle* tri = (Triangle*) cur.leaf(NULL,num); for (size_t i=0; i<num; i++) { terminated |= TriangleIntersector::occluded(valid,ray,tri[i],bvh->vertices); if (all(terminated)) return terminated; } /* let terminated rays miss all boxes */ rayFar = select(terminated,avxf(neg_inf),rayFar); } /*! pop next node from stack */ pop_node: if (unlikely(stackPtr == stack)) break; cur = *(--stackPtr); } return terminated; }
int Dijkstra(NodeRef start, int want, color color){ //to find distance, create node.prev which contains the prev node.you can go backwards and add up all nodes. priority_queue<NodeRef, vector<NodeRef>, Compare> openSet; vector<NodeRef> closedSet; openSet.push(start); //add initial node to open set while(openSet.size()!=0){ NodeRef current = openSet.top(); //node with least cost closedSet.push_back(current); current -> visited = true; if(current->GetId() == want){ //if wanted node is found return CalculateCost(edgeList.at(want)); } openSet.pop(); //remove current node from open set if(current->GetCost()==INT_MAX){ //current node has no connections cout<<"No connections found, break"<<endl; break; } for(int link=0; link<(current)->links.size(); link++){ if((!current->links.at(link)->visited) && current->links.at(link)->color == color){ //if unvisited and correct color current->links.at(link)->Visited(true); current->links.at(link)->prev = current; int alt = CalculateCost(current) + (CalculateCost(current->links.at(link)) - CalculateCost(current)); //relaxing the edge if(alt<CalculateCost(current)){ //if found a faster way (current->links.at(link))->cost = alt; } openSet.push(current->links.at(link)); } } } return INT_MAX; //failed to find node }
void ModelTargetSkinnedVboMesh::loadBoneWeights( const std::vector<BoneWeights>& boneWeights ) { std::vector<ci::Vec4f> boneWeightsBuffer; std::vector<ci::Vec4f> boneIndicesBuffer; for( const auto& boneWeight : boneWeights ) { ci::Vec4f vWeights = ci::Vec4f::zero(); ci::Vec4f vIndices = ci::Vec4i::zero(); for( unsigned int b =0; b < boneWeight.mActiveNbWeights; ++b ) { NodeRef bone = boneWeight.getBone( b ); vWeights[b] = boneWeight.getWeight(b); //FIXME: Maybe use ints on the desktop? vIndices[b] = bone->getBoneIndex(); } boneWeightsBuffer.push_back( vWeights ); boneIndicesBuffer.push_back( vIndices ); } size_t dataSize = sizeof(GLfloat) * ci::Vec4f::DIM * boneWeightsBuffer.size(); bufferSubData< std::vector<ci::Vec4f> >( boneWeightsBuffer, dataSize ); setCustomAttribute( mAttribLocation, "boneWeights" ); incrementOffsets( dataSize ); bufferSubData< std::vector<ci::Vec4f> >( boneIndicesBuffer, dataSize); setCustomAttribute( mAttribLocation, "boneIndices" ); incrementOffsets( dataSize ); mSkinnedVboMesh->getActiveSection()->boneMatrices = &mSkinnedVboMesh->mBoneMatrices; mSkinnedVboMesh->getActiveSection()->invTransposeMatrices = &mSkinnedVboMesh->mInvTransposeMatrices; }
/** * Update all nodes in a way with the ID of the given NodeRef with the * location of the given NodeRef. */ void update_node_location(const NodeRef& new_node_ref) { for (auto& node_ref : nodes()) { if (node_ref.ref() == new_node_ref.ref()) { node_ref.location(new_node_ref.location()); } } }
int main() { AudioGraphRef graph = new AudioGraph(); /*------------------------------------------------------------------------ * Create a simple envelope-modulated triangle wave. *-----------------------------------------------------------------------*/ NodeRef triangle = new Triangle(1000); NodeRef envelope = new ASR(0.01, 0.0, 0.1); NodeRef output = triangle * envelope; /*------------------------------------------------------------------------ * Pan the output across the stereo field. *-----------------------------------------------------------------------*/ NodeRef panned = new Pan(2, output); graph->add_output(panned); graph->start(); while (true) { /*------------------------------------------------------------------------ * Periodically, retrigger the envelope, panned to a random location. *-----------------------------------------------------------------------*/ usleep(random_integer(1e4, 1e6)); panned->set_input("pan", random_uniform(-1, 1)); envelope->trigger(); } }
void Synth::set_input(std::string name, float value) { NodeRef current = this->inputs[name]; signal_assert(this->inputs[name] != nullptr, "Synth has no such parameter: %s", name.c_str()); NodeRef input = this->inputs[name]; Constant *constant = (Constant *) input.get(); constant->value = value; }
void ForwarderRank::_generateDelegatesFor(const DataObjectRef &dObj, const NodeRef &target, const NodeRefList *other_targets) { List<Pair<NodeRef, bubble_metric_t> > sorted_delegate_list; // Figure out which node to look for: bubble_node_id_t target_id = id_from_string(target->getIdStr()); LABEL_T targetLabel = rib[target_id].first; //RANK_T targetRank = rib[target_id].second; HAGGLE_DBG("HAGGLE_DBG:_generateDelegatesFor node %d string %s label %s\n", target_id, target->getIdStr(), targetLabel.c_str()); for (bubble_rib_t::iterator it = rib.begin();it != rib.end(); it++) { if (it->first != this_node_id && it->first != target_id) { NodeRef delegate = kernel->getNodeStore()->retrieve(id_number_to_nodeid[it->first], true); if (delegate && !isTarget(delegate, other_targets)) { LABEL_T &neighborLabel = it->second.first; RANK_T &neighborRank = it->second.second; HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor neighborLabel=%s, targetLabel=%s\n", neighborLabel.c_str(), targetLabel.c_str()); if (neighborLabel.compare(targetLabel)==0) { //NodeRef delegate = Node::create_with_id(Node::TYPE_PEER, id_number_to_nodeid[it->first].c_str(), "Label delegate node"); sortedNodeListInsert(sorted_delegate_list, delegate, it->second); HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor Label same: Node '%s' is a good delegate for target '%s' [label=%s, rank=%ld]\n", delegate->getName().c_str(), target->getName().c_str(), neighborLabel.c_str(), neighborRank); } } } } // Add up to max_generated_delegates delegates to the result in order of decreasing metric if (!sorted_delegate_list.empty()) { NodeRefList delegates; unsigned long num_delegates = max_generated_delegates; while (num_delegates && sorted_delegate_list.size()) { NodeRef delegate = sorted_delegate_list.front().first; sorted_delegate_list.pop_front(); delegates.push_back(delegate); num_delegates--; } kernel->addEvent(new Event(EVENT_TYPE_DELEGATE_NODES, dObj, target, delegates)); HAGGLE_DBG("HAGGLE_DBG: Forward Generated %lu delegates for target %s\n", delegates.size(), target->getName().c_str()); } else { HAGGLE_DBG("No delegates found for target %s\n", target->getName().c_str()); } }
bool NodeStore::update(NodeRef &node, NodeRefList *nl) { Mutex::AutoLocker l(mutex); bool found = false; if (!node) return false; // There may be undefined nodes in the node store that should // be removed/merged with a 'defined' node that we create from a // node description. We loop through all nodes in the store and // compare their interface lists with the one in the 'defined' node. // If any interfaces match, we remove the matching nodes in the store // and eventually replace them with the new one. for (NodeStore::iterator it = begin(); it != end();) { NodeRecord *nr = *it; bool found_now = false; nr->node.lock(); const InterfaceRefList *ifaces = nr->node->getInterfaces(); for (InterfaceRefList::const_iterator it2 = ifaces->begin(); it2 != ifaces->end(); it2++) { InterfaceRef iface = *it2; if (node->hasInterface(iface)) { // Transfer all the "up" interface states to the updated node if (iface->isUp()) node->setInterfaceUp(iface); found_now = true; } } nr->node.unlock(); if (found_now) { if (nl) nl->push_back(nr->node); nr->node->setStored(false); node->setExchangedNodeDescription(nr->node->hasExchangedNodeDescription()); it = erase(it); delete nr; found = true; } else { it++; } } if (found) { node->setStored(true); push_back(new NodeRecord(node)); } return found; }
virtual void decode(NodeRef& node) { string rd; in >> rd; if (rd == "@") { node.reset(); } else { node.set(NodeId(rd)); } }
void Node::insertChildAt( NodeRef child, size_t index ) { Node *former_parent = child->getParent(); if( former_parent ) // remove child from parent (but skip notifying child) { vector_remove( &former_parent->mChildren, child ); } child->setParent( this ); mChildren.insert( mChildren.begin() + index, child ); childAdded( child ); }
void testRefs() { NodeRef orig = DeviceInterface::create("top"); orig->add_child(Terminal::create("child1")); NodeRef child2 = Register::create("child2"); CPPUNIT_ASSERT_NO_THROW(orig->get_child ( "child1")->add_child(child2)); child2->set_attr("test", "hello" ); CPPUNIT_ASSERT_NO_THROW(orig->get_child ( "child1")->get_child("child2")->get_attr("test")); CPPUNIT_ASSERT_EQUAL ( std::string("hello"), (std::string)orig->get_child("child1")->get_child("child2")->get_attr("test")); }
ci::vec2 Event::getScenePos() { NodeRef source = getSource(); if (source) { return source->windowToScene(getWindowPos()); } return getWindowPos(); }
ci::vec2 Event::getLocalPos() { NodeRef source = getSource(); if (source) { return source->windowToLocal(getWindowPos()); } return getWindowPos(); }
void cloneTraversal( const NodeRef& origin, NodeRef& copy ) { for( const auto& originChild : origin->getChildren() ) { NodeRef copyChild = originChild->clone(); copyChild->setParent( copy ); copy->addChild( copyChild ); cloneTraversal( originChild, copyChild ); } }
void BVHN<N>::clearBarrier(NodeRef& node) { if (node.isBarrier()) node.clearBarrier(); else if (!node.isLeaf()) { Node* n = node.node(); for (size_t c=0; c<N; c++) clearBarrier(n->child(c)); } }
void testErase() { NodeRef node = Node::create("Test"); NodeRef child1 = Node::create("child1"); NodeRef child2 = Node::create("child2"); node->add_child(child1); node->add_child(child2); CPPUNIT_ASSERT_NO_THROW( node->del_child("child2") ); CPPUNIT_ASSERT_EQUAL ( 1, (int) node->num_children() ); CPPUNIT_ASSERT_THROW ( node->del_child ( "child2" ), Exception ); }
void BVHN<N>::clearBarrier(NodeRef& node) { if (node.isBarrier()) node.clearBarrier(); else if (!node.isLeaf()) { BaseNode* n = node.baseNode(BVH_FLAG_ALIGNED_NODE); // FIXME: flags should be stored in BVH for (size_t c=0; c<N; c++) clearBarrier(n->child(c)); } }
void Context::uninitRecursive( const NodeRef &node, set<NodeRef> &traversedNodes ) { if( ! node || traversedNodes.count( node ) ) return; traversedNodes.insert( node ); for( auto &input : node->getInputs() ) uninitRecursive( input, traversedNodes ); node->uninitializeImpl(); }
void Context::initRecursisve( const NodeRef &node, set<NodeRef> &traversedNodes ) { if( ! node || traversedNodes.count( node ) ) return; traversedNodes.insert( node ); for( auto &input : node->getInputs() ) initRecursisve( input, traversedNodes ); node->configureConnections(); }
void Context::disconnectRecursive( const NodeRef &node, set<NodeRef> &traversedNodes ) { if( ! node || traversedNodes.count( node ) ) return; traversedNodes.insert( node ); for( auto &input : node->getInputs() ) disconnectRecursive( input, traversedNodes ); node->disconnectAllInputs(); }
NodeRef Skeleton::findNode( const std::string& name, const NodeRef& node ) const { if( node->getName() == name ) { return node; } for( const NodeRef& child : node->getChildren() ) { NodeRef foundNode = findNode( name, child ); if (foundNode != nullptr) { return foundNode; } } return nullptr; }
void ForwarderRank::_endNeighbor(const NodeRef &neighbor) { // We don't handle routing to anything but other haggle nodes: if (neighbor->getType() != Node::TYPE_PEER) return; // Update our private metric regarding this node: bubble_node_id_t neighbor_id = id_from_string(neighbor->getIdStr()); HAGGLE_DBG("HAGGLE_DBG: _endNeighbor node left: node %ld %s \n", neighbor_id, neighbor->getIdStr()); rib_timestamp = Timeval::now(); }
__INLINE ElementRef::ElementRef (NodeRef& nodeRef) : NodeRef(nodeRef.getDocument()) { Log_Element ( "New ElementRef=%p document=%p from noderef=%p\n", this, &document, &nodeRef ); if (nodeRef.isElement()) { setElementPtr(nodeRef.toElement().getElementPtr()); } else { setElementPtr(nodeRef.toAttribute().getParentElementPtr()); } }
template< typename Tnode> void dumpPart( ElementRef< Tnode>& elref, boolean indent) { NodeRef< Tnode>* fstrefp = new ElementRef< Tnode>( elref, elref.getFirstChild()); NodeRef< Tnode>* sndrefp = new ElementRef< Tnode>( (*fstrefp), fstrefp->getFirstChild()); if (indent) fputs(" ", stdout); puts((char *) sndrefp->getNodeValue()); delete sndrefp; delete fstrefp; }
bool NodeStore::stored(const NodeRef& node, bool mustBeNeighbor) { Mutex::AutoLocker l(mutex); bool ret; if (!node) return false; node.lock(); ret = _stored(node, mustBeNeighbor); node.unlock(); return ret; }
void Node::disconnect( const NodeRef &output ) { if( ! output ) return; for( auto weakOutIt = mOutputs.begin(); weakOutIt != mOutputs.end(); ++weakOutIt ) { if( weakOutIt->lock() == output ) { mOutputs.erase( weakOutIt ); break; } } output->disconnectInput( shared_from_this() ); output->notifyConnectionsDidChange(); }
bool Node::checkCycle( const NodeRef &sourceNode, const NodeRef &destNode ) const { if( sourceNode == destNode ) return true; if( sourceNode->supportsCycles() || destNode->supportsCycles() ) return false; for( const auto &input : sourceNode->getInputs() ) { if( checkCycle( input, destNode ) ) return true; } return false; }
void Skeleton::traverseNodes( const NodeRef& node, std::function<void(NodeRef)> visit ) const { visit( node ); for( NodeRef child : node->getChildren() ) { traverseNodes(child, visit); } }