Example #1
0
double Marker::calculater(const Node &sp, const Node &cp) {
	double x = cp.getX() - sp.getX();
	double y = cp.getY()- sp.getY();

	double l = sqrt(x*x+y*y);
	return l;
}
Example #2
0
void DrawTreeCairo::DrawSpeciesEdgesWithContour()
{
    Color& cfill = config->species_edge_color;
    Color& cline = config->species_edge_contour_color;

    cairo_set_line_width(cr, s_contour_width);
    cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);

    const double midnode = leafWidth;
    Node *root = species->getRootNode();

    cairo_move_to(cr, 0, root->getY()+midnode);
    cairo_rel_line_to(cr, root->getX(), 0);
    cairo_rel_line_to(cr,0, -(midnode * 2) );
    cairo_rel_line_to(cr, -(root->getX()), 0);
    cairo_close_path(cr);

    cairo_set_source_rgba(cr, cline.red, cline.green, cline.blue, 1);
    cairo_stroke_preserve(cr);
    cairo_set_source_rgba(cr, cfill.red, cfill.green, cfill.blue, 1);
    cairo_fill(cr);
    
    for ( Node *n = species->preorder_begin(); n != 0; n = species->preorder_next(n) )
    {
        const double x = n->getX();
        const double y = n->getY();

        if (!n->isLeaf())
        { 
            double pmidx;
            double pmidy;
            intersection(x, y - midnode,
                    n->getLeftChild()->getX(), n->getLeftChild()->getY()-midnode,		      
                    x, y + midnode,
                    n->getRightChild()->getX(), n->getRightChild()->getY()+midnode,
                    pmidx, pmidy);

            cairo_move_to(cr, x, y + midnode);
            cairo_rel_line_to(cr,n->getLeftChild()->getX()-x,n->getLeftChild()->getY()-y);
            cairo_rel_line_to(cr, 0, -(midnode * 2) );
            cairo_line_to(cr, pmidx, pmidy);
            cairo_line_to(cr,n->getRightChild()->getX(),n->getRightChild()->getY()+midnode);
            cairo_rel_line_to(cr, 0, - (midnode * 2) );
            cairo_line_to(cr, x, y - midnode);
            cairo_close_path(cr);
            cairo_set_source_rgba(cr, cline.red, cline.green, cline.blue, 1);
            cairo_stroke_preserve(cr);
            cairo_set_source_rgba(cr, cfill.red, cfill.green, cfill.blue, 1);
            cairo_fill(cr);
        }
    }
}
void LSPositionFindingAStar::calculateHeuristics(Node& targetNode)
{	  	  
	for(int x=0; x< _GRID_RESOLUTION_X_AXIS; x++)
	{
		for(int y=0; y< _GRID_RESOLUTION_Y_AXIS; y++)
		{
			int x_temp = abs(m_map[x][y].getX() - targetNode.getX());
			int y_temp = abs(m_map[x][y].getY() - targetNode.getY());

			m_map[x][y].setH((x_temp+y_temp)*10);
			m_map[x][y].setParentNode(nullptr);
			
			m_map[x][y].setG(0);
			if(m_map[x][y].getNodeStatus() !=LOCKED)
			{
				m_map[x][y].setNodeStatus(NONE);
			}
			else
			{std::cout<< "LOCKED";}
	/*		x = m_X;
		y = m_Y;
		H = 0;
		G = 0;
		parentNode = nullptr;
		nodeType= NODE_WALKABLE;
		nodeStatus = NONE;*/
		}
	}		

}
Example #4
0
void
DrawTreeCairo::GeneTreeMarkers()
{
    cairo_set_source_rgba(cr,config->gene_edge_color.red,config->gene_edge_color.green,config->gene_edge_color.blue,1);

    if(parameters->isMarkerColor) 
    {
        cairo_set_source_rgba(cr,config->umColor.red,config->umColor.green,config->umColor.blue,0.80);
    }

    cairo_select_font_face (cr, parameters->gene_font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr,fontsize * parameters->markerscale);
    cairo_text_extents (cr, "i", &extents);

    const double offset = extents.width / 2;

    for(vector<double>::const_iterator i = parameters->uMarker.begin(); 
        i != parameters->uMarker.end(); i++)
    {
        if (*i < gene->getNumberOfNodes())
        {
            Node *n = gene->getNode(*i);
            ostringstream os;
            os << *i;
            const string st = os.str();
            cairo_move_to(cr,n->getX() + parameters->ux_offset + offset,n->getY() + parameters->uy_offset + offset);
            cairo_show_text(cr,st.c_str()); 
        }
    }
}
/**
* Find the leaf node which directly contains this chunk.
*
* @param aChunk the chunk to be located.  If non null, the parameters ax and az are ignored.
* @param ax the chunkspace coordinate of the chunk to be located.  Only used if param aChunk is null
* @param az the chunkspace coordinate of the chunk to be located.  Only used if param aChunk is null
*/
TerrainQuadTree::Node * TerrainQuadTree::Node::findChunkNode (const ProceduralTerrainAppearance::Chunk * const chunk, int x, int z, int size)
{
	Node * node = this;

	if (chunk)
	{
		x = chunk->getChunkX ();
		z = chunk->getChunkZ ();
		size = static_cast <int> (chunk->getChunkWidthInMeters () / m_minChunkWidthInMeters);
	}

	if (!node->nodeEncloses (x, z))
		return 0;

	while (node)
	{
		if (node->getSize() == size && node->getX() == x && node->getZ() == z)
			return node;
		
		const int which = node->getQuadrant (x, z);
		node = node->m_subNodes [which];
	}

	return 0;
}
Example #6
0
void DrawTreeCairo::DrawTimeEdges()
{
    cairo_set_line_width (cr, linewidth);
    const double midnode = leafWidth;
    cairo_set_font_size (cr, fontsize);
    cairo_set_source_rgba (cr,parameters->allFontColor.red,parameters->allFontColor.green,parameters->allFontColor.blue, 1);
    cairo_move_to(cr, 0, pageheight);
    cairo_line_to(cr, pagewidth, pageheight);
    cairo_line_to(cr, pagewidth, 0);
    cairo_set_line_width(cr, 1);
    cairo_set_dash(cr, dashed1, len1, 0);

    for(unsigned u = 0; u < species->getNumberOfNodes(); u++)
    {
        Node* n = species->getNode(u);
        if (!n->isLeaf())
        {		    
            cairo_move_to(cr, n->getX(), pageheight);    
            cairo_line_to(cr, n->getX(), n->getY() + midnode);
        }
    }

    cairo_stroke(cr);
    cairo_set_dash(cr, dashed3, 0, 0);
}
void RoadNetwork::run() {

    city = this->getData("City");
    param.RoadNetworkRa = this->getRasterData("City",vRoadNetworkRa);
    param.RoadNetworkRa->setSize(param.Width, param.Height, param.CellSize, param.CellSize,0,0);
    param.RoadNetworkRa->clear();
    param.roadDistanceToRiver =  param.roadDistanceToRiver_in / param.CellSize;
    param.roadBasisLength = param.roadBasisLength_in / param.CellSize;
    param.dAlpha = param.dAlpha_in / 0.01745329;
    param.roadConnectivity = param.dAlpha_in / param.CellSize;


    Node StartPoint;
    StartPoint.x = 0;
    StartPoint.y = this->findPointNearRiver(StartPoint.x, param.roadDistanceToRiver,  param.topoStatus);

    param.RoadNetworkRa->setCell(StartPoint.x, StartPoint.y, 1);

    Node EndPoint;
    EndPoint.x = param.Width -1;
    EndPoint.y = this->findPointNearRiver(EndPoint.x, param.roadDistanceToRiver,  param.topoStatus);


    param.RoadNetworkRa->setCell(EndPoint.x, EndPoint.y, 1);

    std::vector<Node> vP ;

    std::vector<std::string> centers = city->getUUIDsOfComponentsInView(vCityCenters);
    foreach(std::string c , centers) {
        Node * p = this->city->getNode(c);
        vP.push_back(Node(p->getX()/param.CellSize, p->getY()/param.CellSize, p->getZ()));
    }
Example #8
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 #9
0
void	QuadTree::collide(QuadTree const &quadTree, QuadTree::callInfo call) const
{
	Node *node;
	Node *node2;

	if (call == QuadTree::ALL)
	{
		for (Elements::const_iterator it = this->_mainNode->getElements().begin();
			it != this->_mainNode->getElements().end(); ++it)
			quadTree.collideBranches(**it, QuadTree::ALL);
	}
	else
	{
		for (Elements::const_iterator it = this->_mainNode->getElements().begin();
			it != this->_mainNode->getElements().end(); ++it)
			quadTree.collide(**it, static_cast<QuadTree::callInfo>(QuadTree::ALL & (~call)));
	}
	for (Elements::const_iterator it = quadTree._mainNode->getElements().begin();
		it != quadTree._mainNode->getElements().end(); ++it)
		this->collide(**it, call);
	for (int i = 0; i < 4; ++i)
	{
		node = this->_mainNode->getChilds()[i];
		node2 = quadTree._mainNode->getChilds()[i];
		if (node && node2 && this->collideRect(node->getX(), node->getY(), node->getSize(), node->getSize(),
			node2->getX(), node2->getY(), node2->getSize(), node2->getSize()))
			this->collideNodes(node, node2, call);
	}
}
Example #10
0
void	QuadTree::push(TreeElement &elem)
{
	if (this->isInMiddle(elem))
	{
		this->_mainNode->getElements().insert(&elem);
		elem.setNode(this->_mainNode);
		return ;
	}
	elem.setXElementAbs();
	elem.setYElementAbs();
	int nodeNb = this->findNodeNb(elem);
	elem.setNodeNb(nodeNb);
	if (!this->_mainNode->getChilds()[nodeNb])
		this->_mainNode->getChilds()[nodeNb] = this->createNode(elem);
	else
	{
		Node *node = this->_mainNode->getChilds()[nodeNb];
		if (this->isInSquare(elem, node->getX(), node->getY(), node->getSize()))
		{
			Node *prev = node;
			while ((node = this->findChild(node, elem)) != 0)
				prev = node;
			node = prev;
			this->insertChild(node, elem);
		}
		else
			this->insertParent(elem, nodeNb);
	}
}
void WaterFaker::postStepProc(FEMUtil &femUtil, NodeHandler &nodeHandler,
		TimeHandler &timeHandler) {
	for (int i = 0; i < nodeHandler.getNodeNum(); i++) {
		Node* current = nodeHandler.getNode(i);
		float dt = timeHandler.getDeltaTime() / current->getData(MASSI);

		current->move(current->getData(MXI) * dt,
				current->getData(MYI) * dt,
				0);
//				current->getData(MZI) * dt);
		float x = current->getX();
		float y = current->getY();
		if (isnan(x) || isnan(y)) {
			printf("NANTIME!!\n");
			exit(1);
		}
		if (x < WALL_MINX) {
			current->setData(MXI, -current->getData(MXI) * .9f);
			current->setX(WALL_MINX);
		} else if (x > WALL_MAXX) {
			current->setData(MXI, -current->getData(MXI) * .9f);
			current->setX(WALL_MAXX);
		}
		if (y < WALL_MINY) {
			current->setData(MYI, 0);
			current->setY(WALL_MINY);
		} else if (y > WALL_MAXY) {
			current->setData(MYI, 0);
			current->setY(WALL_MAXY);
		}
	}
}
Example #12
0
void
DrawTreeCairo::TimeLabelsOnEdges()
{
    cairo_set_source_rgba (cr, 0, 0, 0, 1);

    for(unsigned u = 0; u < species->getNumberOfNodes(); u++)
    {
        Node* n = species->getNode(u);
        const string timelabel = double2charp(n->getTime());
        double xpos = n->getX();
        double ypos = n->getY();
        if (!n->isLeaf())
        {
            cairo_text_extents (cr, timelabel.c_str(), &extents);
            xpos = xpos - (extents.width + extents.x_advance);
            ypos =  ypos - leafWidth;
            cairo_move_to(cr,xpos,ypos);
            cairo_save(cr);
            if(parameters->horiz)
            {
                cairo_rotate(cr,-(pi/4));
            }
            cairo_show_text(cr,timelabel.c_str()); 
            cairo_restore(cr);
        }
    }
}
Example #13
0
Node	*QuadTree::findChild(Node *node, TreeElement &elem) const
{
	Node *child = node->getChild(elem);

	if (child && this->isInSquare(elem, child->getX(), child->getY(), child->getSize()))
		return (child);
	return (0);
}
Example #14
0
void NodeTable::addNode ( const Node& node )
{
    int row = node.getNumber() - 1;
    insertRow( row );
    setCoord( row, 0, node.getX() );
    setCoord( row, 1, node.getY() );
    setFixationItem( row, node.getFixation() );
}
void WaterFaker::solveStep(FEMUtil &femUtil, NodeHandler &nodeHandler,
		TimeHandler &timeHandler) {
	for (int i = 0; i < nodeHandler.getNodeNum(); i++) {
		Node* current = nodeHandler.getNode(i);
		Node* other;
		float fx = rand() * RAND_AMOUNT / RAND_MAX;
		float fy = -GRAVITY + frand() * RAND_AMOUNT;
//		float fz = 0;
		float adx, dx;
		float ady, dy;
		float dist;
		float force;
		float dt = timeHandler.getDeltaTime();

		for (int j = 0; j < nodeHandler.getNodeNum(); j++) {
			if (j != i) {
				other = nodeHandler.getNode(j);
				dx = current->getX() - other->getX();
				adx = fabs(dx);
				if (adx < MAX_RAD) {
					dy = current->getY() - other->getY();
					ady = fabs(dy);
					if (ady < MAX_RAD) {
						dist = sqrt(dx*dx+dy*dy);
						if (dist < MAX_RAD) {
							force = MAX_FORCE * ((MAX_RAD - dist) / (MAX_RAD - MIN_RAD));
//							printf("Collision %f\n", force);
							if (dist > ARB_SMALL) {
								fx += dx * force / dist;
								fy += dy * force / dist;
							} else {
								other->move(frand() * 2 * MAX_RAD, frand() * 2 * MAX_RAD, 0);
								printf("Too Small\n");
							}
						}
					}
				}
			}
		}
		current->setData(MXI, current->getData(MXI) + fx * dt);
		current->setData(MYI, current->getData(MYI) + fy * dt);
//		current->setData(MZI, current->getData(MZI) + fz * dt);
//		printf("Force %f %f %f - Momentum %f %f %f\n", fx, fy, fz, current->getData(MXI), current->getData(MYI), current->getData(MZI));
	}
}
Example #16
0
void PNP::addInterrupt(Place *pi, string condition, Place *po) {
    Node *pe = next(next(pi)); // exec place
    string ae=pe->getName();
    std::size_t pos = ae.find(".");      // position of "." in str
    std::string a = ae.substr(0,pos);
    Transition *ts = addTransition(a+".interrupt ["+condition+"]");
    ts->setY(pe->getY()-1); ts->setX(pe->getX()); // upper line wrt pe
    connect(pe,ts); connect(ts,po);
}
Example #17
0
void DrawTreeCairo::DrawSpeciesEdges()
{

    cairo_set_source_rgba(cr,config->species_edge_color.red,config->species_edge_color.green,config->species_edge_color.blue,1);
    cairo_set_line_width(cr, 1);

    const double midnode = leafWidth;
    Node *root = species->getRootNode();

    cairo_move_to(cr, 0, (root->getY() + midnode) );
    cairo_rel_line_to(cr,root->getX(),0);
    cairo_rel_line_to(cr, 0, -(midnode * 2) );
    cairo_rel_line_to(cr, -(root->getX()) , 0);
    cairo_close_path(cr);
    cairo_stroke_preserve(cr);
    cairo_fill(cr);
    
    for ( Node *n = species->preorder_begin(); n != 0; n = species->preorder_next(n) )
    {
        const double x = n->getX();
        const double y = n->getY();

        cairo_set_source_rgba(cr,config->species_edge_color.red,config->species_edge_color.green,config->species_edge_color.blue,1);
        if (!n->isLeaf())
        {
            cairo_move_to(cr,x,y + midnode);
            cairo_rel_line_to(cr,n->getLeftChild()->getX()-x,n->getLeftChild()->getY()-y);
            cairo_rel_line_to(cr,0,-midnode*2);
            cairo_rel_line_to(cr,x-n->getLeftChild()->getX(),(y) - (n->getLeftChild()->getY()));
            cairo_close_path(cr);
            cairo_stroke_preserve(cr);
            cairo_fill(cr);

            cairo_move_to(cr,x,y - midnode);
            cairo_rel_line_to(cr,n->getRightChild()->getX()-x,n->getRightChild()->getY()-y);
            cairo_rel_line_to(cr,0,midnode*2);
            cairo_rel_line_to(cr,x-n->getRightChild()->getX(),y - n->getRightChild()->getY());
            cairo_close_path(cr);
            cairo_stroke_preserve(cr);
            cairo_fill(cr);
        }
        cairo_stroke(cr);
    }
}
Example #18
0
vector<Node> Graph::getNeighbors(Node n) {
    vector<Node> nbrs;
    if( n.neighborEmpty() ) {
        for( int x = n.getX()-proximity; x <= n.getX()+proximity; x += proximity )
            for( int y = n.getY()-proximity; y <= n.getY()+proximity; y += proximity )
                if( ! ( x == n.getX() && y == n.getY() ) )
                    if ( isWithinBorders(x, y) &&  !isPathObstructed(n.getX(), n.getY(), x, y) ) {
                        vector<Node> nd = getNode(x,y) ;
                        vector<Node>::iterator iter;
                        for( iter = nd.begin(); iter != nd.end(); iter++ ) {
                            nbrs.push_back(*iter);
                            n.addNeighbor(*iter);
                        }
                    }
    }
    else
        nbrs = n.getNeighbors();
    return nbrs;
}
Example #19
0
void Crowd::binsort()
{
	int i,j,k,l;
	double ndiv,factx,facty,factz;
	deque<int> ibin;
	Node* nd;
	int num;

	/*////
	   double stx,sty,stz;
	   stx = stdpt.getX()/stdrate;
	   sty = stdpt.getY()/stdrate;
	   stz = stdpt.getZ()/stdrate;
	 */                                                                                                                    /////

	///binlist.clear();
	num = getSize();
	///for(i=0;i<num;i++) binlist.push_back(i);

	ndiv = (int)pow((double)num,0.1);
	factx = ndiv / ((getXWidth()) * 1.01 / getMaxWidth());
	facty = ndiv / ((getYWidth()) * 1.01 / getMaxWidth());
	factz = ndiv / ((getZWidth()) * 1.01 / getMaxWidth());

	for(l = 0; l < num; l++)
	{
		nd = getNode(l);
		i = (int)((nd->getX()) * factx);
		j = (int)((nd->getY()) * factz);
		k = (int)((nd->getZ()) * facty);
		//////
		//i = (int)((nd->getX()-stx)*factx);
		//j = (int)((nd->getY()-sty)*factz);
		//k = (int)((nd->getZ()-stz)*facty);
		///////////
		if((k % 2) == 0)
		{
			if((j % 2) == 0)
				ibin.push_back((int)(k * ndiv * ndiv + j * ndiv + i + 1));
			else
				ibin.push_back((int)(k * ndiv * ndiv + (j + 1) * ndiv - i));
		}
		else
		{
			if((j % 2) == 0)
				ibin.push_back((int)(k * ndiv * ndiv + (ndiv - j) * ndiv - i));
			else
				ibin.push_back((int)(k * ndiv * ndiv +
				                     (ndiv - j - 1) * ndiv + i + 1));
		}
	}

	dtm::quickSort(0,num - 1,binlist,ibin);
}
Example #20
0
void	QuadTree::collideNodes(Node *node, Node *node2, QuadTree::callInfo call) const
{
	Node *checkpoint;
	int nbChilds = 0;

	if (!node->getElements().empty())
	{
		for (Node *tmp = node2; tmp; tmp = tmp->getParent())
			this->collideElements(node->getElements(), tmp->getElements(), call);
	}
	for (int i = 0; i < 4; ++i)
	{
		Node *child = node2->getChilds()[i];
		if (child && this->collideRect(node->getX(), node->getY(), node->getSize(), node->getSize(),
			child->getX(), child->getY(), child->getSize(), child->getSize()))
		{
			++nbChilds;
			checkpoint = this->collideNode(node, child, call);
		}
	}
	if (nbChilds == 1)
	{
		for (int i = 0; i < 4; ++i)
		{
			if (node->getChilds()[i])
				this->collideNodes(node->getChilds()[i], checkpoint, call);
		}
	}
	else
	{
		for (int i = 0; i < 4; ++i)
		{
			Node *child = node->getChilds()[i];
			if (child && this->collideRect(node2->getX(), node2->getY(), node2->getSize(), node2->getSize(),
			child->getX(), child->getY(), child->getSize(), child->getSize()))
				this->collideNodes(child, node2, call);
		}
	}
}
Example #21
0
void DrawTreeCairo::DrawGeneEdges()
{
    Color& regular = config->gene_edge_color;
    cairo_set_source_rgba(cr, regular.red, regular.green, regular.blue,1);
    cairo_set_line_width(cr, linewidth / 2);
    
    for (unsigned i = 0; i < gene->getNumberOfNodes(); i++)
    {
        Node *n = gene->getNode(i);
        if (!n->isRoot())
        {
            if(n->getReconcilation() == Node::LateralTransfer)
            {
                LGT.insert(std::make_pair(n,0));
            }
            else
            {
                newDrawPath(n);
            }
        }
        else if ((*lambda)[n]->isRoot())
        {
            cairo_move_to(cr,n->getX(),n->getY());
            cairo_line_to(cr,0,n->getY());
        }
        else 
        {    
            //TODO can the root be further away than 1 node?
            cairo_move_to(cr,n->getX(),n->getY());
            cairo_line_to(cr,species->getRootNode()->getX(),species->getRootNode()->getY());
            cairo_line_to(cr,0,species->getRootNode()->getY());
        }
    }

    DrawLGT();
    cairo_stroke(cr);
}
Example #22
0
// add node to open or visited list
void AStar::addNode(int x, int y, float newCost,
	Node* parent, Node* newNode) {
	if (!newNode->getPass()) {
		return;
	}

	// I had to use the x, y to compair nodes due to pointer issue (and out of time)
	Node* addNode = newNode;
	for (unsigned int i = 0; i < m_visitedList.size(); i++) { 
		if (addNode->getX() == m_visitedList[i]->getX()
			&& addNode->getY() == m_visitedList[i]->getY()) {
			return;
		}
	}

	// create temp node and establish it for the open list
	Node* newChild = new Node(x, y, parent, true);
	newChild->setG(newCost);
	newChild->setH(parent->manhattenDist(m_goal));
	for (unsigned int i = 0; i < m_openList.size(); i++) {
		if (addNode->getX() == m_openList[i]->getX() &&
			addNode->getY() == m_openList[i]->getY()) {
			float newF = newChild->getG() + newCost + m_openList[i]->getH();

			if (m_openList[i]->getF() > newF) {
				m_openList[i]->setG(newChild->getG() + newCost);
				m_openList[i]->setParent(newChild);
			}
			else {
				delete newChild;
				return;
			}
		}
	}
	m_openList.push_back(newChild);
}
Example #23
0
void NetworkVisualiser::process()
{
    const int NODE_WIDTH = 80;
    const int NODE_HEIGHT = 40;
    Canvas c = NodeCore::Canvas(300, 300);
    Network* net = (Network*)asData("network");
    NodeList nodes = net->getNodes();
    for (NodeIterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
        Node* node = (*iter);
        NodeCore::BezierPath p = NodeCore::BezierPath();
        p.rect(node->getX(), node->getY(), NODE_WIDTH, NODE_HEIGHT);
        c.append(p);
    }
    _setOutput(c);
}
	void StrategicPositioningSystem::FindNewPostionForLS() // 1:Set Action to Moving 2:Find new Move Location 3:Find Path to new move
	{
		//1. Find the New cube to move which has Line of sight.
		ds::Node* pathNodes = strategicPositionFinding.getClosestPosition(*m_pOwner->m_pCurrent_location,  *m_pOwner->m_pCurrent_target);
		Node node = *pathNodes;
		
		//2. Find the convinient path to the new move location.
		ds::CubeGeomerty* next_move_cube = new ds::CubeGeomerty((*pathNodes).getCubeCoordinates().location);
		pathNodes = pathfindingAStar.A_Star(*m_pOwner->m_pCurrent_location, *next_move_cube);
		
		//3. Set the Agent action to MOve as the agent wil be moving to the new cube for next few frames.		
		m_pOwner->m_Agent_Action = MOVING;

		if(m_pOwner->m_pCurrent_Move_target !=nullptr){
			m_map[static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.x)][static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.y)].setNodeStatus(OPEN);
		}
		m_pOwner->m_pCurrent_Move_target = new ds::CubeGeomerty((*pathNodes).getCubeCoordinates().location);

		m_map[static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.x)][static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.y)].setNodeStatus(LOCKED);

		// MultiAgent Changes, set the next move target as NODE_COLLISION so that other agents wont select it as target.
		//m_map[static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.x)][static_cast<int>((*m_pOwner->m_pCurrent_Move_target).location.y)].setNodeType(NODE_COLLISION);
		//4. Create a vector of nodes to move through to get to the new cube;
		std::cout <<"\n**************************";
		m_pOwner->m_Move_path_nodes.clear();
			while(true)
		{
			if(nullptr != pathNodes){	
		
				Node node = *pathNodes; // Dereference the object for the parent node
				// Add here
						

				m_pOwner->m_Move_path_nodes.push_back(new ds::CubeGeomerty(node.getCubeCoordinates().location));
						
				std::cout << "\nAI:(" << node.getX() << "," << node.getY() << ")";

				pathNodes = node.getParentNode();
				//node.setNodeStatus(PATH);
						
			}
			else
			{
				break;
			}
		}
	
	}
Example #25
0
void DrawTreeCairo::DrawSpeciesNodeLabels()
{
    cairo_select_font_face (cr, parameters->species_font.c_str(), CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_source_rgba (cr, parameters->speciesFontColor.red, 
                parameters->speciesFontColor.green, parameters->speciesFontColor.blue, 1);
    cairo_set_font_size (cr, speciesfontsize);

    for(unsigned u = 0; u < species->getNumberOfNodes(); u++)
    {
        Node* n = species->getNode(u);
        ostringstream st;
        if(parameters->do_not_draw_species_tree == false)
        {
            if (parameters->ids_on_inner_nodes) 
            {
                st << n->getNumber();
            }
            st << " " + n->getName();
        }

        const string ns = st.str();
        const double xpos = n->getX();
        const double ypos = n->getY();

        cairo_text_extents (cr, ns.c_str(), &extents);
        if(n->isLeaf())
        {
            cairo_move_to(cr, xpos + (extents.height / 2) , ypos + leafWidth);
        }
        else
        {
            cairo_move_to(cr, xpos - (0.25 * extents.width) , ypos + leafWidth);
        }

        cairo_save(cr);
        if(parameters->horiz)
        {
            cairo_rotate(cr,-(pi/4));
        }

        cairo_show_text(cr,ns.c_str());
        cairo_restore(cr);
    }
    cairo_stroke(cr);
}
Example #26
0
void	QuadTree::insertOnTop(Node *node, TreeElement &elem, int nodeNb)
{
	Node *parent;

	while ((parent = node->getParent()) && !this->isInSquare(elem, parent->getX(), parent->getY(), parent->getSize()))
		node = parent;
	if (parent)
	{
		Node *prev = parent;
		while ((parent = this->findChild(parent, elem)) != 0)
			prev = parent;
		parent = prev;
		this->insertChild(parent, elem);
	}
	else
	{
		this->insertParent(elem, nodeNb);
	}
}
Example #27
0
void	QuadTree::collide(TreeElement &elem, int x, int y, int width, int height, Node *currentNode, QuadTree::callInfo call) const
{
	for (Elements::const_iterator it = currentNode->getElements().begin(); it != currentNode->getElements().end(); ++it)
	{
		if (this->collideRect(x, y, width, height, (*it)->getXElementAbs(), (*it)->getYElementAbs(), (*it)->getWidthElement(), (*it)->getHeightElement()))
		{
			if (call & QuadTree::RIGHT)
				elem.collide(**it);
			if (call & QuadTree::LEFT)
				(*it)->collide(elem);
		}
	}
	for (int i = 0; i < 4; ++i)
	{
		Node *node = currentNode->getChilds()[i];
		if (node && this->collideRect(x, y, width, height, node->getX(), node->getY(), node->getSize(), node->getSize()))
			this->collide(elem, x, y, width, height, node, call);
	}
}
Example #28
0
Node	*QuadTree::collideNode(Node *node, Node *node2, QuadTree::callInfo call) const
{
	int nbChilds = 0;
	Node *checkpoint;

	this->collideElements(node->getElements(), node2->getElements(), call);
	for (int i = 0; i < 4; ++i)
	{
		Node *child = node2->getChilds()[i];
		if (child && this->collideRect(node->getX(), node->getY(), node->getSize(), node->getSize(),
			child->getX(), child->getY(), child->getSize(), child->getSize()))
		{
			++nbChilds;
			checkpoint = this->collideNode(node, child, call);
		}
	}
	if (nbChilds == 1)
		return (checkpoint);
	return (node2);
}
Example #29
0
void DrawTreeCairo::DrawGeneNodes()
{
    Color& duplCol = config->gene_dupl_color;
    Color& specCol = config->gene_spec_color;
    
    cairo_set_line_width(cr,2);
        
    for ( Node *n = gene->preorder_begin(); n != 0; n = gene->preorder_next(n) )
    {
        const double x = n->getX();
        const double y = n->getY();
        
        if(n->getReconcilation() == Node::Leaf || n->getReconcilation() == Node::Speciation) //speciation or leaf
        {
            cairo_set_source_rgba(cr, specCol.red, specCol.green, specCol.blue, 1);
            cairo_arc(cr,x, y, (leafWidth / 10), 0.0, 2*pi);
            cairo_fill(cr);
        }
        else if (n->getReconcilation() == Node::Duplication) //duplication
        {
            nDupl++;
            cairo_set_source_rgba(cr, duplCol.red, duplCol.green, duplCol.blue, 1);
            cairo_rectangle(cr,x - ( (leafWidth / 5) / 2 ),y - ( (leafWidth / 5) / 2),
                            leafWidth / 5, leafWidth / 5);
            cairo_fill(cr);

        }
        else if (n->getReconcilation() == Node::LateralTransfer) //duplication
        {
            nTrans++;
            cairo_set_source_rgba(cr, duplCol.red, duplCol.green, duplCol.blue, 1);
            cairo_rectangle(cr,x - ( (leafWidth / 5) / 2 ),y - ( (leafWidth / 5) / 2),
                            leafWidth / 5, leafWidth / 5);
            cairo_fill(cr);
        }
    }
    
    cairo_stroke(cr);

}
Example #30
0
void DrawTreeCairo::DrawSpeciesNodes()
{
    Color& cfill = config->species_node_color;
    Color& cline = config->species_node_contour_color;
    
    for ( Node *n = species->preorder_begin(); n != 0; n = species->preorder_next(n) )
    {
        if (!n->isLeaf())
        {
            cairo_save(cr);
            cairo_translate (cr,n->getX(), n->getY());
            cairo_scale(cr, 0.3, 1);
            cairo_arc (cr, 0.0, 0.0,leafWidth, 0.0, 2 * pi);
            cairo_set_source_rgba(cr, cfill.red, cfill.green, cfill.blue, 1);
            cairo_fill_preserve(cr);
            cairo_set_line_width(cr, s_contour_width);
            cairo_set_source_rgba(cr, cline.red, cline.green, cline.blue, 1);
            cairo_stroke(cr);
            cairo_restore(cr);
        }
    }
    
}