//-------------------------------------------------------------------------------------
int NavTileHandle::findRandomPointAroundCircle(int layer, const Position3D& centerPos,
	std::vector<Position3D>& points, uint32 max_points, float maxRadius)
{
	setMapLayer(layer);
	pCurrNavTileHandle = this;

	if(pCurrNavTileHandle->pTilemap->GetNumLayers() < layer + 1)
	{
		ERROR_MSG(fmt::format("NavTileHandle::findRandomPointAroundCircle: not found layer({})\n", layer));
		return NAV_ERROR;
	}
	
	Position3D currpos;
	
	for (uint32 i = 0; i < max_points; i++)
	{
		float rnd = frand();
		float a = maxRadius * rnd;						// 半径在maxRadius米内
		float b = 360.0f * rnd;							// 随机一个角度
		currpos.x = a * cos(b); 						// 半径 * 正余玄
		currpos.z = a * sin(b);
		points.push_back(currpos);
	}

	return (int)points.size();
}
示例#2
0
void CDTUndoWidget::setLayer(CDTBaseLayer *layer)
{
    onDockClear();
    if (qobject_cast<CDTSegmentationLayer*>(layer) ||
        qobject_cast<CDTExtractionLayer*>(layer) ||
        qobject_cast<CDTClassificationLayer*>(layer) )
    {
        setMapCanvas(layer->canvas());
        setMapLayer(layer->canvasLayer());
        this->setEnabled(true);
        this->setVisible(true);
        this->raise();
        this->adjustSize();
    }
}
示例#3
0
//-------------------------------------------------------------------------------------
int NavTileHandle::raycast(int layer, const Vector3& start, const Vector3& end, std::vector<Vector3>& hitPointVec)
{
	setMapLayer(layer);
	pCurrNavTileHandle = this;

	if(pCurrNavTileHandle->pTilemap->GetNumLayers() < layer + 1)
	{
		printf("NavTileHandle::raycast: not found layer(%d)\n",  layer);
		return NAV_ERROR;
	}

	// Create a start state
	MapSearchNode nodeStart;
	nodeStart.x = int(start.x / pTilemap->GetTileWidth());
	nodeStart.y = int(start.z / pTilemap->GetTileHeight()); 

	// Define the goal state
	MapSearchNode nodeEnd;
	nodeEnd.x = int(end.x / pTilemap->GetTileWidth());				
	nodeEnd.y = int(end.z / pTilemap->GetTileHeight()); 

	std::vector<MapSearchNode> vec;
	bresenhamLine(nodeStart, nodeEnd, vec);
	
	if(vec.size() > 0)
	{
		vec.erase(vec.begin());
	}

	std::vector<MapSearchNode>::iterator iter = vec.begin();
	int pos = 0;
	for(; iter != vec.end(); iter++)
	{
		if(getMap((*iter).x, (*iter).y) == TILE_STATE_CLOSED)
			break;

		hitPointVec.push_back(Vector3(float((*iter).x * pTilemap->GetTileWidth()), start.y, float((*iter).y * pTilemap->GetTileWidth())));
		pos++;
	}

	return pos;
}
void QgsHtmlAnnotation::readXml( const QDomElement &itemElem, const QgsReadWriteContext &context )
{
  mHtmlFile = itemElem.attribute( QStringLiteral( "htmlfile" ), QString() );
  QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral( "AnnotationItem" ) );
  if ( !annotationElem.isNull() )
  {
    _readXml( annotationElem, context );
  }

  // upgrade old layer
  if ( !mapLayer() && itemElem.hasAttribute( QStringLiteral( "vectorLayer" ) ) )
  {
    setMapLayer( QgsProject::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ) ) ) );
  }

  if ( mWebPage )
  {
    setSourceFile( mHtmlFile );
  }
}
示例#5
0
void QgsFormAnnotation::readXml( const QDomElement &itemElem, const QgsReadWriteContext &context )
{
  mDesignerForm = itemElem.attribute( QStringLiteral( "designerForm" ), QString() );
  QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral( "AnnotationItem" ) );
  if ( !annotationElem.isNull() )
  {
    _readXml( annotationElem, context );
  }
  // upgrade old layer
  if ( !mapLayer() && itemElem.hasAttribute( QStringLiteral( "vectorLayer" ) ) )
  {
    setMapLayer( QgsProject::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ) ) ) );
  }

  mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
  if ( mDesignerWidget && fillSymbol() )
  {
    QgsFillSymbol *newFill = fillSymbol()->clone();
    newFill->setColor( mDesignerWidget->palette().color( QPalette::Window ) );
    setFillSymbol( newFill );
  }
}
示例#6
0
//-------------------------------------------------------------------------------------
int NavTileHandle::findStraightPath(int layer, const Vector3& start, const Vector3& end, std::vector<Vector3>& paths)
{
	setMapLayer(layer);
	pCurrNavTileHandle = this;

	if(pCurrNavTileHandle->pTilemap->GetNumLayers() < layer + 1)
	{
		printf("NavTileHandle::findStraightPath: not found layer(%d)\n", layer);
		return NAV_ERROR;
	}

	// Create a start state
	nodeStart.x = int(start.x / pTilemap->GetTileWidth());
	nodeStart.y = int(start.z / pTilemap->GetTileHeight()); 

	// Define the goal state
	nodeGoal.x = int(end.x / pTilemap->GetTileWidth());				
	nodeGoal.y = int(end.z / pTilemap->GetTileHeight()); 

	//printf("NavTileHandle::findStraightPath: start({}, {}), end({}, {})\n", 
	//	nodeStart.x, nodeStart.y, nodeGoal.x, nodeGoal.y));

	// Set Start and goal states
	astarsearch.SetStartAndGoalStates(nodeStart, nodeGoal);

	unsigned int SearchState;
	unsigned int SearchSteps = 0;

	int steps = 0;

	do
	{
		SearchState = astarsearch.SearchStep();

		SearchSteps++;

#if DEBUG_LISTS

		printf("NavTileHandle::findStraightPath: Steps: %d\n", SearchSteps);

		int len = 0;

		printf("NavTileHandle::findStraightPath: Open:\n");
		MapSearchNode *p = astarsearch.GetOpenListStart();
		while( p )
		{
			len++;
#if !DEBUG_LIST_LENGTHS_ONLY			
			((MapSearchNode *)p)->printNodeInfo();
#endif
			p = astarsearch.GetOpenListNext();
			
		}
		
		printf("NavTileHandle::findStraightPath: Open list has %d nodes\n", len);

		len = 0;

		printf("NavTileHandle::findStraightPath: Closed:\n");
		p = astarsearch.GetClosedListStart();
		while( p )
		{
			len++;
#if !DEBUG_LIST_LENGTHS_ONLY			
			p->printNodeInfo();
#endif			
			p = astarsearch.GetClosedListNext();
		}

		printf("NavTileHandle::findStraightPath: Closed list has %d nodes\n", len);
#endif

	}

	while( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING );

	if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED )
	{
		//DEBUG_MSG("NavTileHandle::findStraightPath: Search found goal state\n");
		MapSearchNode *node = astarsearch.GetSolutionStart();

		

		//node->PrintNodeInfo();
		for( ;; )
		{
			node = astarsearch.GetSolutionNext();

			if( !node )
			{
				break;
			}

			//node->PrintNodeInfo();
			steps ++;
			paths.push_back(Vector3((float)node->x * pTilemap->GetTileWidth(), 0, (float)node->y * pTilemap->GetTileWidth()));
		};

		// printf("NavTileHandle::findStraightPath: Solution steps {}\n", steps));
		// Once you're done with the solution you can free the nodes up
		astarsearch.FreeSolutionNodes();
	}
	else if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED ) 
	{
		printf("NavTileHandle::findStraightPath: Search terminated. Did not find goal state\n");
	}

	// Display the number of loops the search went through
	// printf("NavTileHandle::findStraightPath: SearchSteps: {}\n", SearchSteps));
	astarsearch.EnsureMemoryFreed();

	return steps;
}