Example #1
0
int Combining_Tree::getAndIncrement(int thread_id){
  std::list <Node*> nodes_stack;
  Node * myLeaf      = this->leaf_[thread_id / 2];
  Node * node        = myLeaf;
  
  // determine first or second node reach to a point
  while(node->pre_combine()){
    node             = node->getParent();    // climb to the parent node
  }
  Node * stop        = node;            // set the highest point the climb reached
  node               = myLeaf;          // set node to original point
  
  int combined       = 1;               // make an increase on here.
  
  while (node != stop){                 // do combining until reach the stop point.
    combined         = node->combine(combined);  // combine each point along with climbing.
    nodes_stack.push_back(node);                 // trace the node reached.
    node             = node->getParent();        // climb up 
  }

  int prior = stop->op(combined);        // set the final increased value to the stop point

  while(!nodes_stack.empty()) {          // iterater all the element in the stack
    node             = nodes_stack.back();  
    nodes_stack.pop_back();              
    node->distribute(prior);             // call distribute function to all waiting thread
  }

  return prior;
}
Example #2
0
Node * Tree::getMRCATraverse(Node * curn1,Node * curn2){
	Node * mrca = NULL;
	//get path to root for first node
	vector<Node *> path1;
	Node * parent = curn1;
	path1.push_back(parent);
	while (parent != NULL) {
		path1.push_back(parent);
		if (parent->getParent() != NULL)
			parent = parent->getParent();
		else
			break;
	}
	//find first match between this node and the first one
	parent = curn2;
	bool x = true;
	while (x == true) {
		for (unsigned int i = 0; i < path1.size(); i++) {
			if (parent == path1.at(i)) {
				mrca = parent;
				x = false;
				break;
			}
		}
		parent = parent->getParent();
	}
	return mrca;
}
Example #3
0
	void Model::getNodeList(Model::AnimationNodeMap &nodelist)
	{
		std::queue<Node*> currentnodes;
		currentnodes.push(rootnode);
		while (currentnodes.size() > 0)
		{
			Node *node = currentnodes.front();
			currentnodes.pop();
			AnimationNode *newnode = new AnimationNode;
			newnode->name = node->getName();
			if (node->getParent())
				newnode->parent = nodelist[node->getParent()->getName()];
			else
				newnode->parent = 0;
			newnode->transformation = node->getTransformation();
			newnode->transinverse = node->getInvTrans();
			newnode->dirty = true;
			nodelist.insert(std::make_pair(newnode->name, newnode));
			// Child nodes
			const std::vector<Node*> &children = node->getChildren();
			for (unsigned int i = 0; i < children.size(); i++)
			{
				currentnodes.push(children[i]);
			}
		}
	}
Example #4
0
/*
@K key
@P pointer
@return error information
	KEY_EXIST: -1
@throw 
	key length does not match
*/
int Index::insertKey(Key K, int P){	
	if (K.getLength() != keyLen)
		throw std::runtime_error("key length does not match");
	Node* L;
	if (root == NULL) {
		if (debug&&0)
			std::cout <<"---------new Root!? -----------" << std::endl;
		root = newNode();
		L = root;
	} else {		
		std::pair<Node*, int> p = find(K);		
		if (p.second != -1)
			return KEY_EXIST;
		L = p.first;
		if (debug&&0)
			std::cout <<"---------find Key -----------" << L->getAddr() << std::endl;
	}	
	if (L->getKeyNum() < maxKeyNum - 1){
		L->insertInLeaf(K, P);
	} else {
		if (debug&&0) {
			std::cout <<"---------insert Key -----------" << L->getParent() << std::endl;
			if (L->getParent()!=-1) getNode(L->getParent())->print();
		}
		L->add(P, K);
		Node* L1 = L->split();
		L->insertInParent(L1->getKey(0), L1);
	}
	return INSERT_SUCCESS;
}
Node *
ColladaVisualScene::createInstance(ColladaInstanceElement *colInstElem)
{
    OSG_COLLADA_LOG(("ColladaVisualScene::createInstance\n"));

    ColladaInstanceVisualSceneRefPtr colInstVisScene =
        dynamic_cast<ColladaInstanceVisualScene *>(colInstElem);

    domVisual_sceneRef   visScene = getDOMElementAs<domVisual_scene>();
    const domNode_Array &nodes    = visScene->getNode_array         ();

    for(UInt32 i = 0; i < nodes.getCount(); ++i)
    {
        ColladaNodeRefPtr colNode = getUserDataAs<ColladaNode>(nodes[i]);

        if(colNode == NULL)
        {
            colNode = dynamic_pointer_cast<ColladaNode>(
                ColladaElementFactory::the()->create(nodes[i], getGlobal()));

            colNode->setVisualScene(this);
            colNode->read();
        }

        if(nodes.getCount() > 1)
        {
            if(_RootN == NULL)
            {
                GroupUnrecPtr group = Group::create();
                _RootN = makeNodeFor(group);
            }

            Node *childN = colNode->getTopNode();

            if(childN->getParent() != NULL)
            {
                SWARNING << "ColladaVisualScene::createInstance: <node> [" << i
                         << "] already has a parent." << std::endl;
            }

            _RootN->addChild(childN);
        }
        else
        {
            Node *childN = colNode->getTopNode();

            if(childN->getParent() != NULL)
            {
                SWARNING << "ColladaVisualScene::createInstance: <node> [" << i
                         << "] already has a parent." << std::endl;
            }

            _RootN = childN;
        }
    }

    editInstStore().push_back(_RootN);

    return _RootN;
}
Example #6
0
void MeshSkin::setRootJoint(Joint* joint)
{
    if (_rootJoint)
    {
        if (_rootJoint->getParent())
        {
            _rootJoint->getParent()->removeListener(this);
        }
    }

    _rootJoint = joint;

    // If the root joint has a parent node, register for its transformChanged event
    if (_rootJoint && _rootJoint->getParent())
    {
        _rootJoint->getParent()->addListener(this, 1);
    }

    Node* newRootNode = _rootJoint;
    if (newRootNode)
    {
        // Find the top level parent node of the root joint
        for (Node* node = newRootNode->getParent(); node != NULL; node = node->getParent())
        {
            if (node->getParent() == NULL)
            {
                newRootNode = node;
                break;
            }
        }
    }
    setRootNode(newRootNode);
}
Example #7
0
 Node* Node::getRootNode() const
 {
     Node* n = const_cast<Node*>(this);
     while( !n->getParent().expired() )
     {
         n = n->getParent().lock().get();
     }
     return n;
 }
Example #8
0
Vec2 ParallaxNode::absolutePosition()
{
    Vec2 ret = _position;
    Node *cn = this;
    while (cn->getParent() != nullptr)
    {
        cn = cn->getParent();
        ret = ret + cn->getPosition();
    }
    return ret;
}
Example #9
0
//指定のノードから親を辿り、第2指定のノードの直の子に打ち当たったら、そのノードを返す
Node* getChildOfTargetNodeUpstreamFrom(Node* from, Node* target) {
    Node* current = from;
    while (1) {
        if (current->getParent() == target) {
            return current;
        }
        else{
            current = current->getParent();
        }
    }
    return nullptr;
}
Example #10
0
/*
 * only makes sense for ultrametric trees
 */
void Tree::setHeightFromTipToNodes(){
	for (int i = 0; i < externalNodeCount; i++) {
		double curh = 0.0;
		Node * cur = this->getExternalNode(i);
		cur->setHeight(curh);
		while (cur->getParent() != NULL) {
			curh += cur->getBL();
			cur = cur->getParent();
			if(cur->getHeight()<curh)
				cur->setHeight(curh);
		}
	}
}
Example #11
0
//红黑树取前驱元素操作
Node& RBTree::TreePredecessor(int key)
{
	Node* x = &TreeSearch(key);
	if (x->getLeft() != NIL)
		return TreeMaximum(x->getLeft(), 0);
	Node* y = x->getParent();
	while (y != NIL && x == y->getLeft())
	{
		x = y;
		y = y->getParent();
	}
	if (y == NIL)
		throw 1;
	return *y;
}
Example #12
0
bool Menu::onTouchBegan(Touch* touch, Event* event)
{
    auto camera = Camera::getVisitingCamera();
    if (_state != Menu::State::WAITING || ! _visible || !_enabled || !camera)
    {
        return false;
    }
    
    for (Node *c = this->_parent; c != nullptr; c = c->getParent())
    {
        if (c->isVisible() == false)
        {
            return false;
        }
    }
    _selectedItem = this->getItemForTouch(touch, camera);

    if (_selectedItem)
    {
        _state = Menu::State::TRACKING_TOUCH;
        _selectedWithCamera = camera;
        _selectedItem->selected();
        
        return true;
    }
    
    return false;
}
Example #13
0
bool PerfectMenu::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event)
{
    if (isTouched||_state != Menu::State::WAITING || ! _visible || !_enabled)
    {
        return false;
    }
    
    for (Node *c = this->_parent; c != nullptr; c = c->getParent())
    {
        if (c->isVisible() == false)
        {
            return false;
        }
    }
    
    _selectedItem = this->getItemForTouch(touch);
    if (_selectedItem)
    {
        _state = Menu::State::TRACKING_TOUCH;
        _selectedItem->selected();
        isTouched = true;
        return true;
    }
    
    return false;
}
Example #14
0
void PhysicsVehicle::initialize()
{
    GP_ASSERT(getNode());

    // Safe default values
    setSteeringGain(0.5f);
    setBrakingForce(350.0f);
    setDrivingForce(2000.0f);
    setSteerdown(0, 1);
    setBrakedown(1000, 0);
    setDrivedown(1000, 0);
    setBoost(0, 1);
    setDownforce(0);

    // Create the vehicle and add it to world
    btRigidBody* body = static_cast<btRigidBody*>(_rigidBody->getCollisionObject());
    btDynamicsWorld* dynamicsWorld = Game::getInstance()->getPhysicsController()->_world;
    _vehicleRaycaster = new VehicleNotMeRaycaster(dynamicsWorld, body);
    _vehicle = bullet_new<btRaycastVehicle>(_vehicleTuning, body, _vehicleRaycaster);
    body->setActivationState(DISABLE_DEACTIVATION);
    dynamicsWorld->addVehicle(_vehicle);
    _vehicle->setCoordinateSystem(0, 1, 2);

    // Advertise self among ancestor nodes so that wheels can bind to self.
    // See PhysicsVehicleWheel and Node for more details.
    for (Node* n = getNode()->getParent(); n; n = n->getParent())
    {
        n->addAdvertisedDescendant(getNode());
    }
}
Example #15
0
TEST_F(NodeTest, testAddChild)
{
    Node* nodeChild = new Node(2);
    _node->addChild(nodeChild);
    ASSERT_EQ(1, _node->getNodeList().size());
    ASSERT_EQ(_node, nodeChild->getParent());
}
Example #16
0
Rect ScrollView::getViewRect()
{
    Vec2 screenPos = this->convertToWorldSpace(Vec2::ZERO);
    
    float scaleX = this->getScaleX();
    float scaleY = this->getScaleY();
    
    for (Node *p = _parent; p != nullptr; p = p->getParent()) {
        scaleX *= p->getScaleX();
        scaleY *= p->getScaleY();
    }

    // Support negative scaling. Not doing so causes intersectsRect calls
    // (eg: to check if the touch was within the bounds) to return false.
    // Note, Node::getScale will assert if X and Y scales are different.
    if(scaleX<0.f) {
        screenPos.x += _viewSize.width*scaleX;
        scaleX = -scaleX;
    }
    if(scaleY<0.f) {
        screenPos.y += _viewSize.height*scaleY;
        scaleY = -scaleY;
    }

    return Rect(screenPos.x, screenPos.y, _viewSize.width*scaleX, _viewSize.height*scaleY);
}
Example #17
0
bool ark_SwallowButton::onTouchBegan(Touch *touch, Event *event) {
	if (!ark_engine::instance()->checkIsVisible(this))
	{
		return false;
	}
	dragging = false;
	if (m_isDirty == true)
	{
		for (Node *i = this->getParent();i != NULL;i=i->getParent())
		{
			ScrollView *t = dynamic_cast<ScrollView*>(i);
			if (t)
			{
				this->m_scrollView = t;
				break;
			}
		}
		m_isDirty = false;
	}
	if (this->m_scrollView &&m_scrollView->isTouchEnabled())
	{
		Rect rect = ark_engine::instance()->getViewRect(m_scrollView);
		if (rect.containsPoint(touch->getLocation()))
		{
			return ControlButton::onTouchBegan(touch, event);
		}else
		{
			return false;
		}
	}
	return ControlButton::onTouchBegan(touch, event);
}
Example #18
0
bool ButtonControlLayer::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
{
    auto camera = cocos2d::Camera::getVisitingCamera();
    if (_selectedItem != nullptr || !_visible || !camera)
    {
        return false;
    }
    
    for (Node *c = this->_parent; c != nullptr; c = c->getParent())
    {
        if (c->isVisible() == false)
        {
            return false;
        }
    }
    
    _selectedItem = this->getItemForTouch(touch, camera);
    if (_selectedItem)
    {
        _selectedWithCamera = camera;
        _selectedItem->selected();
        onButtonPressed(_selectedItem->getTag());
        return true;
    }
    
    return false;
}
Example #19
0
void	QuadTree::move(TreeElement &elem)
{
	Node *node = elem.getNode();
	if (node)
	{
		if (node == this->_mainNode)
		{
			this->_mainNode->getElements().erase(&elem);
			this->push(elem);
		}
		else
		{
			if (node->getElements().size() > 1)
				node->getElements().erase(&elem);
			else
			{
				int nbChilds = node->getNbChilds();
				if (nbChilds < 2)
				{
					Node *parent = node->getParent();
					node = this->eraseNode(node, elem.getNodeNb());
					if (parent)
					{
						if (parent->getElements().empty() && parent->getNbChilds() == 1)
							node = this->eraseNode(parent, elem.getNodeNb());
					}
				}
				else
					node->getElements().erase(&elem);
			}
			int nodeNb = this->findNodeNb(elem);

			if (this->isInMiddle(elem))
			{
				this->_mainNode->getElements().insert(&elem);
				elem.setNode(this->_mainNode);
			}
			else if (elem.getNodeNb() != nodeNb)
				this->push(elem);
			else
			{
				elem.setXElementAbs();
				elem.setYElementAbs();
				if (!node)
					this->_mainNode->getChilds()[nodeNb] = this->createNode(elem);
				else if (this->isInSquare(elem, node->getX(), node->getY(), node->getSize()))
				{
					Node *tmp = node;
					Node *prev = node;
					while ((tmp = this->findChild(tmp, elem)) != 0)
						prev = tmp;
					tmp = prev;
					this->insertChild(tmp, elem);
				}
				else
					this->insertOnTop(node, elem, nodeNb);
			}
		}
	}
}
Example #20
0
void	QuadTree::pop(TreeElement &elem)
{
	int nodeNb = this->findNodeNb(elem);
	Node *node = elem.getNode();
	if (node)
	{
		if (node == this->_mainNode)
			this->_mainNode->getElements().erase(&elem);
		else
		{
			if (node->getElements().size() > 1)
				node->getElements().erase(&elem);
			else
			{
				int nbChilds = node->getNbChilds();
				if (nbChilds < 2)
				{
					Node *parent = node->getParent();
					this->eraseNode(node, nodeNb);
					if (parent)
					{
						if (parent->getElements().empty() && parent->getNbChilds() == 1)
							this->eraseNode(parent, nodeNb);
					}
				}
				else
					node->getElements().erase(&elem);
			}
		}
	}
}
Example #21
0
bool ScrollMenu::onTouchBegan(Touch* touch, Event* event)
{
	if (_state != Menu::State::WAITING || !_visible || !_enabled)
	{
		return false;
	}

	for (Node *c = this->_parent; c != nullptr; c = c->getParent())
	{
		if (c->isVisible() == false)
		{
			return false;
		}
	}

	m_iStartPos = touch->getLocation();
	if (m_iEffectiveRange.containsPoint(m_iStartPos))
	{
		m_bTouchMoved = false;
		_selectedItem = this->getItemForTouch(touch);
		if (_selectedItem)
		{
			_state = Menu::State::TRACKING_TOUCH;
			_selectedItem->selected();

			return true;
		}
	}


	return false;
}
Example #22
0
void BidirectionalRRTPlanner::CreatePath(MilestonePath& p) const
{
  Assert(milestones[0]->connectedComponent == milestones[1]->connectedComponent);
  Assert(connectedComponents[0] == milestones[0]);
  list<Node*> path;
  Node* n = milestones[1];
  while(n != milestones[0]) {
    path.push_front(n);
    n = n->getParent();
    Assert(n != NULL);
  }
  p.edges.resize(0);
  p.edges.reserve(path.size());
  for(list<Node*>::const_iterator i=path.begin();i!=path.end();i++) {
    Node* n = *i;
    SmartPointer<EdgePlanner> e=n->edgeFromParent();
    if(e->Start() == n->x) {
      p.edges.push_back(e->ReverseCopy());
    }
    else if(e->Goal() == n->x) {
      p.edges.push_back(e);
    }
    else {
      cerr<<"Hmm... edge doesn't have node as its start or its goal!"<<endl;
      Abort();
    }
  }
}
Example #23
0
void PhysicsBody::update(float delta)
{
    if (_node != nullptr)
    {
        for (auto shape : _shapes)
        {
            shape->update(delta);
        }
        
        Node* parent = _node->getParent();
        Node* scene = &_world->getScene();
        
        Vec2 position = parent != scene ? parent->convertToNodeSpace(scene->convertToWorldSpace(getPosition())) : getPosition();
        float rotation = getRotation();
        for (; parent != scene; parent = parent->getParent())
        {
			rotation -= parent->getRotation();
        }
        
        _positionResetTag = true;
        _rotationResetTag = true;
        _node->setPosition(position);
        _node->setRotation(rotation);
        _positionResetTag = false;
        _rotationResetTag = false;
        
        // damping compute
        if (_isDamping && _dynamic && !isResting())
        {
            _info->getBody()->v.x *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
            _info->getBody()->v.y *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
            _info->getBody()->w *= cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f);
        }
    }
}
Example #24
0
Rect HpView::getViewRect()
{
    Point screenPos = this->convertToWorldSpace(Point::ZERO);
    
    float scaleX = this->getScaleX();
    float scaleY = this->getScaleY();
    
    for (Node *p = getParent(); p != NULL; p = p->getParent()) {
        scaleX *= p->getScaleX();
        scaleY *= p->getScaleY();
    }
    
    // Support negative scaling. Not doing so causes intersectsRect calls
    // (eg: to check if the touch was within the bounds) to return false.
    // Note, Node::getScale will assert if X and Y scales are different.
    if(scaleX<0.f) {
        screenPos.x += getContentSize().width*scaleX;
        scaleX = -scaleX;
    }
    if(scaleY<0.f) {
        screenPos.y += getContentSize().height*scaleY;
        scaleY = -scaleY;
    }
    
    return Rect(screenPos.x, screenPos.y, getContentSize().width*scaleX, getContentSize().height*scaleY);
}
void LHJointsProtocol::findConnectedNodes()
{
    if(_nodeAUUID.length() == 0 || _nodeBUUID.length() == 0)
        return;
    
    
    Node* node = dynamic_cast<Node*>(this);
    if(!node)return;
    
    LHScene* scene = (LHScene*)node->getScene();
    
    LHNodeProtocol* parentProtocol = dynamic_cast<LHNodeProtocol*>(node->getParent());
    if(parentProtocol)
    {
        _nodeA = parentProtocol->getChildNodeWithUUID(_nodeAUUID);
        _nodeB = parentProtocol->getChildNodeWithUUID(_nodeBUUID);
    }
    if(!_nodeA){
        _nodeA = scene->getChildNodeWithUUID(_nodeAUUID);
        
    }
    if(!_nodeB){
        _nodeB = scene->getChildNodeWithUUID(_nodeBUUID);
    }
}
Example #26
0
bool CMD_scene_tree(
		u32		n_args,
		char	**args
	)
{
	u32 n_nodes, i;
	Node **node_list;

	n_nodes = SceneGraph::getNodeCount();

	node_list = (Node **) malloc(sizeof(Node *) * n_nodes);

	SceneGraph::getNodes(node_list);

	for (i = 0; i < n_nodes; i++) {
		Node *node = node_list[i];

		if (!node->getParent()) {
			p_scene_tree_traverse(node, 0);
		}

	}

	free(node_list);

	return true;
}
Example #27
0
Node* Scene::getNext()
{
    if (_nextReset)
    {
        _nextItr = findNextVisibleSibling(getFirstNode());
        _nextReset = false;
    }
    else if (_nextItr)
    {
        Node* node = findNextVisibleSibling(_nextItr->getFirstChild());
        if (node == NULL)
        {
            node = findNextVisibleSibling(_nextItr->getNextSibling());
            if (node == NULL)
            {
                // Find first parent with a sibling
                node = _nextItr->getParent();
                while (node && (!findNextVisibleSibling(node->getNextSibling())))
                {
                    node = node->getParent();
                }
                if (node)
                {
                    node = findNextVisibleSibling(node->getNextSibling());
                }
            }
        }
        _nextItr = node;
    }
    return _nextItr;
}
Example #28
0
void
pcl::recognition::ORROctree::deleteBranch (Node* node)
{
  node->deleteChildren ();
  node->deleteData ();

  Node *parent = node->getParent ();

  // Go up until you reach a node which has other non-empty children (i.e., children with other children or with data)
  while ( parent )
  {
    Node *children = parent->getChildren ();
    // Check the children
    int i;
    for ( i = 0 ; i < 8 ; ++i )
    {
      if ( children[i].hasData () || children[i].hasChildren () )
        break;
    }

    // There are no children with other children or with data -> delete them all!
    if ( i == 8 )
    {
      parent->deleteChildren ();
      parent->deleteData ();
      // Go one level up
      parent = parent->getParent ();
    }
    else
      // Terminate the deleting process
      break;
  }
}
Example #29
0
bool TouchController::isParentAllVisible(TouchControllerEvent* lsTe) {
	bool bRef = true;
	// 向父类转型,以便获取地址比较对象,TouchControllerEvent 的对象必须同时直接或者简介继承 CCNode
	Node* nLsTe = dynamic_cast<Node*>(lsTe);

	Node* parent = getParent();
	do {
		// 如果遍历完毕,说明 TouchController 不再 TouchControllerEvent 之内
		if (!parent) {
			bRef = false;
			break;
		}
		// 如果 TouchController 在 TouchControllerEvent 之内,返回 true
		// 注意:如果想让TouchControllerEvent 处理 不在其 CCNode 结构之内的元素,则取消此处判断
		if (nLsTe == parent) {
			break;
		}
		if (!parent->isVisible()) {
			bRef = false;
			break;
		}
		parent = parent->getParent();
	} while (1);
	return bRef;
}
Example #30
0
HTTP2PriorityQueue::Handle
HTTP2PriorityQueue::updatePriority(HTTP2PriorityQueue::Handle handle,
                                   http2::PriorityUpdate pri) {
  Node* node = handle;
  pendingWeightChange_ = true;
  VLOG(4) << "Updating id=" << node->getID() << " with parent=" <<
    pri.streamDependency << " and weight=" << ((uint16_t)pri.weight + 1);
  node->updateWeight(pri.weight);
  CHECK_NE(pri.streamDependency, node->getID()) <<
    "Tried to create a loop in the tree";;
  if (pri.streamDependency == node->parentID() && !pri.exclusive) {
    // no move
    return handle;
  }

  Node* newParent = find(pri.streamDependency);
  if (!newParent) {
    newParent = &root_;
    VLOG(4) << "updatePriority missing parent, assigning root for txn="
            << node->getID();

  }

  if (newParent->isDescendantOf(node)) {
    newParent = newParent->reparent(node->getParent(), false);
  }
  return node->reparent(newParent, pri.exclusive);
}