Ejemplo n.º 1
0
Archivo: SVG.cpp Proyecto: dillonl/CBD
void DrawSVGIntPath(string SVGfname, vector<IntPairVector> PS, char* strokeColor, double strokeWidth, char* StrokeType, char* fill, bool smooth, Matrix<double> lon, Matrix<double> lat, double xmin, double ymin){
    if(PS.size()<=1)
        return;

    //cout << "****got here" << endl;

    ofstream data;
    data.open(SVGfname.c_str(), std::ofstream::out | std::ofstream::app);

    if(!data.is_open()){
        cerr << "Bad SVG Filename: " << SVGfname << endl;
        exit(-1);
    }

    /*
    vector<IntPairVector> Pset;

    //TODO: optimize
    if(smooth)
        Pset = SmoothPath(PS);
    else{
        for(int i=0; i<PS.size(); i++)
        Pset.push_back(PS[i]);
    }
    */
    vector<DoublePairVect> Pset;
    //cout << "about to draw path:" << xmin << ", " << ymin << endl;

    for(int i=0; i<PS.size(); i++)
        Pset.push_back(make_pair(lon(PS[i].first, PS[i].second), lat(PS[i].first, PS[i].second)));

    if(smooth)
        Pset = SmoothPath(Pset);

    //Pset = getMapProjSphere(Pset);

    //cout << "here" << xmin << ", " << ymin << endl;

    printf("\n%s,%d\n", StrokeType, strcmp(StrokeType, "dash"));
    if(strcmp(StrokeType, "dash") == 0)
        data << "<path stroke-dasharray=\"2,2\" fill = \"" << fill <<
                "\" d=\"M" << Pset[0].first-xmin << "," << Pset[0].second-ymin;// << "\"" << endl;
    else
        data << "<path  fill = \"" << fill <<
                "\" d=\"M" << Pset[0].first-xmin << "," << Pset[0].second-ymin;// << endl;

        for(int i=1; i<Pset.size(); i++)
            data << endl << "            L" << Pset[i].first-xmin << ", " << Pset[i].second-ymin;// << endl;

        //data << endl << "            L" << Pset[0].first-xmin << ", " << Pset[0].second-ymin;// << endl;

    //make it conncet to the first point
    data << endl << "            L" << Pset.back().first-xmin << ", " << Pset.back().second-ymin << "\"" << endl;

    data << "            stroke = \"" << strokeColor << "\" stroke-width = \"" <<
            strokeWidth << "\" stroke-linejoin=\"round\"/>" << endl;
    data.close();
}
Ejemplo n.º 2
0
void QTPFS::PathSearch::Finalize(IPath* path) {
	TracePath(path);

	#ifdef QTPFS_SMOOTH_PATHS
	SmoothPath(path);
	#endif

	path->SetBoundingBox();

	// path remains in live-cache until DeletePath is called
	pathCache->AddLivePath(path);
}
Ejemplo n.º 3
0
Archivo: SVG.cpp Proyecto: dillonl/CBD
void FillPolygon(string SVGfname, vector<IntPairVector> PS, char* fillColor, char* StrokeColor, double StrokeWidth, double opacity, Matrix<double> lon, Matrix<double> lat, double xmin, double ymin, bool smooth){
    if( PS.size()<=2 )
        return;

    /*
    //TODO: optimize
    vector<IntPairVector> Pset;
    if(smooth)
        Pset = SmoothPath(PS);
    else{
        for(int i=0; i<PS.size(); i++)
        Pset.push_back(PS[i]);
    }
    */

    vector<DoublePairVect> Pset;
    //cout << "about to draw path:" << xmin << ", " << ymin << endl;

    for(int i=0; i<PS.size(); i++)
        Pset.push_back(make_pair(lon(PS[i].first, PS[i].second), lat(PS[i].first, PS[i].second)));

    if(smooth)
        Pset = SmoothPath(Pset);

    //for(int i=0; i<Pset.size(); i++){
    //    cout << Pset[i].first << ", " << Pset[i].second << ": " << PS[i].first << ", " << PS[i].second << endl;
    //}

    //Pset = getMapProjSphere(Pset);

    //for(int i=0; i<Pset.size(); i++)
    //    cout << Pset[i].first << ", " << Pset[i].second << ": " << lon(PS[i].first, PS[i].second) << ", " << lat(PS[i].first, PS[i].second) << ":: " << PS[i].first << ", " << PS[i].second << endl;

    //cout << "here" << xmin << ", " << ymin << endl;

    ofstream data;
    data.open(SVGfname.c_str(), std::ofstream::out | std::ofstream::app);

    if(!data.is_open()){
        cerr << "Bad SVG Filename: " << SVGfname << endl;
        exit(-1);
    }

    data << endl << "<polygon fill=\"" << fillColor << "\" stroke=\"" << StrokeColor << "\" stroke-width=\"" << StrokeWidth
         << "\" stroke-linejoin=\"round\" stroke-opacity=\"" << opacity << "\" fill-opacity=\"" << opacity << "\""
         << endl;
    data << "    points=\"" << Pset[0].first-xmin << "," << Pset[0].second-ymin << endl;
    for(int i=1; i<Pset.size(); i++)
        data << "     " << Pset[i].first-xmin << "," << Pset[i].second-ymin << endl;

    data << "      " << Pset.back().first-xmin << "," << Pset.back().second-ymin << "\"/>" << endl;
    data.close();
}
Ejemplo n.º 4
0
void DoSnipeFire (CObject *objP, tAILocalInfo *ailP)
{
if (ailP->nextActionTime < 0) {
	tAIStaticInfo	*aiP = &objP->cType.aiInfo;
	CreateNSegmentPath (objP, 10 + d_rand () / 2048, OBJSEG (TARGETOBJ));
	aiP->nPathLength = (aiP->nHideIndex < 0) ? 0 : SmoothPath (objP, &gameData.ai.routeSegs [aiP->nHideIndex], aiP->nPathLength);
	if (d_rand () < 8192)
		ailP->mode = AIM_SNIPE_RETREAT_BACKWARDS;
	else
		ailP->mode = AIM_SNIPE_RETREAT;
	ailP->nextActionTime = SNIPE_RETREAT_TIME;
	}
}
Ejemplo n.º 5
0
SmoothPath SmoothPathEngine::endSmoothPath()
{
    m_creationCompleted = false;

    double width = 1;
    if ( m_annotElement.hasAttribute( "width" ) )
        width = m_annotElement.attribute( "width" ).toDouble();

    QColor color( m_annotElement.hasAttribute( "color" ) ?
        m_annotElement.attribute( "color" ) : m_engineColor );

    return SmoothPath( points, QPen(color, width) );
}
cost AnyAngleAlgorithm::FindPath(xyLoc from, xyLoc to)
{
#ifdef ANY_ANGLE_STATISTICS
    StartStatistics(from, to);
#endif

    cost c;
    if (!UsingXYLocCont()) {
        xyloc_path_.clear();
        c = FindCornerLocPath(from, to, xyloc_path_);
#ifdef ANY_ANGLE_STATISTICS
        ReportStatistics(xyloc_path_, statistics_);
#endif

        if (ShouldSmoothPaths()) {
            c = SmoothPath(xyloc_path_, smoothed_xyloc_path_);
#ifdef ANY_ANGLE_STATISTICS
            ReportStatistics(smoothed_xyloc_path_, statistics_with_smoothing_);
#endif
        }
    }
    else {
        xyloc_cont_path_.clear();
        c = FindXYLocContPath(from, to, xyloc_cont_path_);
#ifdef ANY_ANGLE_STATISTICS
        ReportStatistics(xyloc_cont_path_, statistics_);
#endif
        if (ShouldSmoothPaths()) {
            c = SmoothPath(xyloc_cont_path_, smoothed_xyloc_cont_path_);
#ifdef ANY_ANGLE_STATISTICS
            ReportStatistics(smoothed_xyloc_cont_path_, statistics_with_smoothing_);
#endif
        }
    }

    return c;
}
Ejemplo n.º 7
0
/*****************************************************************
* GeneratePath()		Uses A* PathFinding to generate a path from
*						the start position to the goal position
*
* Ins:					int
*						int
*
* Outs:					None
*
* Returns:				vector<CNode*>
*
* Mod. Date:		    08/16/2015
* Mod. Initials:	    NS
*****************************************************************/
vector<XMFLOAT3> CPathFinding::GeneratePath(int _start, int _goal, bool smoothed)
{
	GetReadyForNewSearch();

	// Create the first PathNode
	CPathNode* curPathNode = new CPathNode(m_pGraph->GetNodes()[_start]);
	m_pqNodeQue.push(curPathNode);
	m_umVisitedNodes[_start] = curPathNode;

	// Create all local variables here for attempt at optimization
	CPathNode* theNode = nullptr;
	CPathNode* visitedNode = nullptr;
	CPathNode* nextPathNode = nullptr;
	CNode* curNode;
	CNode* adjNode;
	CEdge* curEdge;
	float newFinalCost;
	float newCost;
	float oldCost;
	float curCost;
	float newHeuristic;
	int adjNodeIndex;
	int curNodeIndex;
	vector<XMFLOAT3> path;

	// Loop while there are edges to explore
	while (!m_pqNodeQue.empty())
	{
		// Get the next node.
		curPathNode = m_pqNodeQue.front();
		m_pqNodeQue.pop();

		// Access the node and it's index for future use
		curNode = curPathNode->GetNode();
		curNodeIndex = curNode->GetIndex();

		// If the destination is found
		if (curNodeIndex == _goal)
		{
			// Clear the old path
			m_lPath.clear();

			// Build the path
			theNode = m_umVisitedNodes[curNode->GetIndex()];

			// Untill we trace back to the _start node
			while (theNode != nullptr)
			{
				// Add the node to the path
				m_lPath.push_back(theNode->GetNode());

				// Advance to the next connected node
				theNode = theNode->m_cpParent;
			}
			if (smoothed)
				path = SmoothPath(m_lPath);
			else
			{
				for (size_t currNode = 0; currNode < m_lPath.size(); currNode++)
					path.push_back(m_lPath[currNode]->GetPosition());
			}

			
			

			
			
				/*m_umVisitedNodes.clear();
				^^^^^^^^^^^^^^^^^^^^^^^^^^
				This stupid line of code caused us so many headaches that I can't bring
				 myself to actually delete it. Forever it shall live in the belly of our 
				 pathfinding code*/

			return path;
		}

		// For each edge the node has
		for (size_t edge = 0; edge < curNode->GetEdges().size(); edge++)
		{
			// Get the current Edge and the node attatched to it
			curEdge = curNode->GetEdges()[edge];
			adjNodeIndex = curEdge->GetAdjNode();
			adjNode = m_pGraph->GetNodes()[adjNodeIndex];

			// Calculate the cost to the adj Node from _start Node (Total cost so far)
			curCost = curNode->GetCost() + curEdge->GetEdgeCost();

			// If the node has been visited
			if (m_umVisitedNodes[adjNodeIndex] != nullptr)
			{
				visitedNode = m_umVisitedNodes[adjNodeIndex];

				// The cost it took previously to get to the node
				oldCost = visitedNode->GetNode()->GetCost();

				// If the new cost is less the the old one
				if (curCost < oldCost)
				{
					m_pqNodeQue.remove(visitedNode);
					visitedNode->GetNode()->SetCost(curCost);

					newFinalCost = visitedNode->GetNode()->GetCost() + visitedNode->GetNode()->GetHeuristic() * m_fHeuristicWeight;
					visitedNode->GetNode()->SetFinalCost(newFinalCost);

					visitedNode->m_cpParent = curPathNode;
					m_pqNodeQue.push(visitedNode);
				}

			}
			else // If it has not been visited
			{
				// Set the cost adj notes cost (Total of what it takes to get here)
				newCost = curNode->GetCost() + curEdge->GetEdgeCost();
				adjNode->SetCost(newCost);

				// Set the HeuristicCost
				newHeuristic = CalculateCost(m_pGraph->GetNodes()[_goal]->GetPosition(), adjNode->GetPosition());
				adjNode->SetHeuristic(newHeuristic);

				// Set the new FinalCost // ?? 
				newFinalCost = newCost + newHeuristic * m_fHeuristicWeight;
				adjNode->SetFinalCost(newFinalCost);

				// Create a PathNode for the adj node (Note adj to the one I'm on)
				nextPathNode = new CPathNode(adjNode);

				// Set it's parent to the one I'm on (Coming from)
				nextPathNode->m_cpParent = curPathNode;

				// Add it to the que to be checked.
				m_pqNodeQue.push(nextPathNode);

				// Mark it as visited
				m_umVisitedNodes[adjNodeIndex] = nextPathNode;
			}
		}
	}
	return path;
}