Пример #1
0
void HexMap::placeSites(mt19937& urng)
{
	array<sf::Color, 13> tColors = { sf::Color::Blue, sf::Color::Cyan, sf::Color::Black, sf::Color::Green, sf::Color::Magenta,
	sf::Color::Red, sf::Color::White, sf::Color::Yellow, lerp::brown, lerp::limeGreen, lerp::orange, lerp::purple, lerp::turquoise};
	static function<bool(HexTile&)> condition = [](HexTile& hex){ return hex.hts->FLAGS[HexTileS::WALKABLE] && !hex.FLAGS[HexTile::MOUNTAINS]; };
	clearEntities();
	auto* fac = addFaction();
	std::uniform_int_distribution<int> landChance(0, land.size() - 1);
	std::vector<sf::Vector2i> territories;
	for (int a = 0; a < 20; a++) {
		sf::Vector2i aPos = (sf::Vector2i)offsetToAxial(land[landChance(urng)]);
		territories.push_back(aPos);
	}
	std::vector<VectorSet> fill;
	fill.resize(territories.size());
	floodSelectParallel(fill, territories, 91, condition);
	int index = 0;
	std::vector<sf::Vector2i> output;
	for (auto& f : fill) {
		if (f.empty()) {
			index++;
			continue;
		}
		//for (auto& h : f) {
		//	sf::Vector2i oPos = axialToOffset(h);
		//	pushTileColor(oPos, tColors[index%tColors.size()]);
		//	setTile(oPos, HexTileS::get(HexTileS::TUNDRA_SNOW), urng);
		//}
		auto t = f.find(territories[index]);
		if (t == f.end()) {
			index++;
			continue;
		}
		f.erase(t);
		int size = (int)(0.1 * f.size());
		for (int a = 0; a < size; a++) {
			std::uniform_int_distribution<int> range(0, f.size() - 1);
			auto it = f.begin();
			std::advance(it, range(urng));
			output.push_back(*it);
			f.erase(it);
		}
		auto* c = addSite(&SiteS::get(SiteS::CITY), fac);
		c->setAnimationType(MapEntityS::anim::IDLE);
		c->initMapPos(territories[index]);
		for (auto& o : output) {
			auto* s = addSite(&SiteS::get(rng::boolean(urng) ? SiteS::TOWN : SiteS::VILLAGE), fac);
			s->setAnimationType(MapEntityS::anim::IDLE);
			s->initMapPos(o);
		}
		output.clear();
		index++;
	}
}
Пример #2
0
	void Voronoi::addSites( const std::vector< Point* >& points,
			const std::vector< unsigned >* colors )
	{
		if( !_sites )
			_sites = new SiteList();

		unsigned length = points.size( );
		for( unsigned i = 0; i < length; ++i ){
			addSite( points[i], colors ? colors->at( i ) : 0, i );
		}
	}
Пример #3
0
void NewRecordUser::addMessage()
{
	int saveMsgBox = QMessageBox::information(this,
	Scale::coded("Создать новую запись?"), Scale::coded("Новая запись будет создана в базе"),
	Scale::coded("Создать"), Scale::coded("Отмена"));
	if (saveMsgBox == 0)
	{
	addSite();
	}

}
IfcSchema::IfcBuilding* IfcHierarchyHelper::addBuilding(IfcSchema::IfcSite* site, IfcSchema::IfcOwnerHistory* owner_hist) {
	if (! owner_hist) {
		owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
	}
	if (! owner_hist) {
		owner_hist = addOwnerHistory();
	}
	if (! site) {
		site = getSingle<IfcSchema::IfcSite>();
	}
	if (! site) {
		site = addSite(0, owner_hist);
	}
	IfcSchema::IfcBuilding* building = new IfcSchema::IfcBuilding(IfcParse::IfcGlobalId(), owner_hist, boost::none, boost::none, boost::none, 
		addLocalPlacement(), 0, boost::none, IfcSchema::IfcElementCompositionEnum::IfcElementComposition_ELEMENT, 
		boost::none, boost::none, 0);

	addEntity(building);
	addRelatedObject<IfcSchema::IfcRelAggregates>(site, building);
	relatePlacements(site, building);

	return building;
}
Пример #5
0
void VoronoiSegment::
generate()
{
    const double sqrt3 = 1.7320508075688772935274463415059;

    std::cout << "Generating" << std::endl;

    std::list< Vertex* >::iterator vxIt;
    for( vxIt = allVertices.begin(); vxIt != allVertices.end(); ++vxIt )
    {
        VSVertex *vtx = static_cast<VSVertex *>(*vxIt);
        if( vtx->isDeleted() ) continue;

        if( vtx->isExternal() )
        {
            for( int i = 0; i < 3; ++i )
            {
                VSVertex *vs = static_cast<VSVertex *>( vtx->vertices[i] );
                if( vs == (VSVertex *) 0 ) continue;

                if( !vs->isExternal() && vs->isWaiting() )
                {
                    vs->makeActive();
                    actives.insert( vs );
                }
            }
        }
        else
        {
            double ref = bg->interpolate( vtx->vx, vtx->vy ) / sqrt3;
            if( vtx->rightSize( ref ) )
            {
                if( vtx->isActive() ) actives.remove( vtx );
                vtx->makeAccepted();
                for( int i = 0; i < 3; ++i )
                {
                    VSVertex *vs = static_cast<VSVertex *>( vtx->vertices[i] );
                    if( !vs->isExternal() && vs->isWaiting() )
                    {
                        vs->makeActive();
                        actives.insert( vs );
                    }
                }
            }
        }
    }

    while( actives.size() > 0 )
    {
        VSVertex *vtx = static_cast<VSVertex *>( actives.first() );

        if( !vtx->borderTest( ) )
        {
            double nx, ny;
            if( vtx->computeNewCoordinates( *bg, nx, ny ) > 0 )
            {
                MeshNode *nd = new MeshNode( nx, ny );

                if( addSite( vtx, nd, false, true ) == true )
                {
                    if( deleted.size() == 1 )
                    {
                        // This is a terrible hack and we get a lot of it wrong!
                        vtx->unDelete();
                        vtx->makeAccepted();
                        vtx->radiate( actives );
                        deleted.erase( deleted.begin(), deleted.end() );
                    }
                    else
                    {
                        actives.removeRelevants( deleted );

                        int len = newVertices.size(), i;
                        for( i = 0; i < len; ++i )
                        {
                            VSVertex *vs = static_cast<VSVertex *>( newVertices[i] );
                            vs->setBody( tag );
                        }

                        for( i = 0; i < len; ++i )
                        {
                            VSVertex *vs = static_cast<VSVertex *>( newVertices[i] );
                            double ref = bg->interpolate( vs->vx, vs->vy ) / sqrt3;
                            if( vs->rightSize( ref ) )
                            {
                                vs->makeAccepted();
                            }
                            else
                            {
                                if( !vs->testIfActive( actives ) )
                                {
                                    vs->makeWaiting();
                                }
                            }
                        }

                        for( i = 0; i < len; ++i )
                        {
                            VSVertex *vs = static_cast<VSVertex *>( newVertices[i] );
                            if( vs->isWaiting() )
                            {
                                vs->testIfActive( actives );
                            }
                            else if( vs->isAccepted() )
                            {
                                vs->radiate( actives );
                            }
                        }
                    }
                }
                // 		else std::cout << "Bad node" << std::endl;

                recycle();
            }
        }
    }
}
Пример #6
0
void Connect::
triangulate()
{
	int i;
	int len;
	
	bounds->collectNodesAndPairs( border, links );
	
	makeWorld();
	
	for (i = 0; i < fixedGeometryNodes.size(); i++)
	{
		MeshNode *nd = static_cast< MeshNode* >( fixedGeometryNodes[i] );
		Vertex *vtx = root->firstAcceptableFound( nd->x, nd->y);
		addSite( vtx, nd, true );
		nd->fix();
		recycle();
	}
	
	len = border.size();
	int *indirect = new int[len];
	for( i = 0; i < len; ++i)
	{
		indirect[i] = i;
	}
	std::random_shuffle(indirect, indirect + len);
	
//	std::cout << "Inserting border" << std::endl;
	for( i = 0; i < len; ++i)
	{
		int ind = indirect[i];
		Vertex *vtx = root->firstAcceptableFound( border[ind]->x, border[ind]->y);
		addSite( vtx, border[ind], true );
		MeshNode *nd = static_cast< MeshNode* >( border[ind] );
		nd->fix();
		recycle();
	}
	
	delete [] indirect;
	
	// Verify borders (no recovery!)
//	std::cout << "Verifying borders" << std::endl;
	
	len = border.size();
	
	Vertex *verify = root;
	for(i = 0; i < len; ++i)
	{
		int t1 = border[i]->tag, t2 = border[(i + 1) % len]->tag;
		if( links.find( std::make_pair( std::min(t1, t2), std::max(t1, t2) ) ) != 
			links.end() )
		{ 
			verify = verify->vertexOwning( border[i], border[(i + 1) % len] );
			if(!verify)
			{
				blm_error("Initial triangulation is incomplete!",
					"Please readjust your mesh parameters.");
			}
		}
	} 
//	std::cout << "Verifying borders completed" << std::endl;
	
	//
	Vertex *vtx = root->vertexWith( border[0], border[1] );
	
	vtx->labelBodies( tag, links );
}
Пример #7
0
void Connect::
removeBoundaryConnectors()
{
	const double sqrt3 = 1.7320508075688772935274463415059;
	
	pq actives;

	double ref;
	std::list< Vertex* >::iterator vxIt;
	for( vxIt = allVertices.begin(); vxIt != allVertices.end(); ++vxIt )
	{
		Vertex *vtx = (*vxIt);
		if( !(vtx->isDeleted() || vtx->isExternal() ))
		{
			if( vtx->isBoundaryConnector(links) )
			{
				vtx->rightSize( 1.0 );
				actives.insert( vtx );
			}
		}
	}
	
	while( actives.size() > 0 )
	{
		Vertex *vtx = actives.first();

		if (!vtx->isBoundaryConnector(links))
			continue;
		
		int i;
		double x, y;

		for (i = 0; i < 3; i++)
		{
			int t0 = vtx->nodeAt(i)->tag, t1 = vtx->nodeAt((i+1)%3)->tag;
			if (links.find(std::make_pair(std::min(t0, t1), std::max(t0, t1))) == links.end())
			{
				double dx0 = vtx->nodeAt(i)->x - vtx->nodeAt((i+2)%3)->x;
				double dy0 = vtx->nodeAt(i)->y - vtx->nodeAt((i+2)%3)->y;
				double dx1 = vtx->nodeAt((i+1)%3)->x - vtx->nodeAt((i+2)%3)->x;
				double dy1 = vtx->nodeAt((i+1)%3)->y - vtx->nodeAt((i+2)%3)->y;

				// r1 = sqrt(dx0*dx0+dy0*dy0)
				// r2 = sqrt(dx1*dx1+dy1*dy1)
				// theta1 = atan(dy0/dx0)
				// theta2 = atan(dy1/dx1)
				// (x + iy) = sqrt(r1*r2)*e^(i*(theta1+theta2)/2)

				double x2y2 = dx0 * dx1 - dy0 * dy1; // x*x-y*y
				double xy = dx0 * dy1 + dx1 * dy0; // 2*x*y

				y = sqrt(0.5 * (sqrt(x2y2 * x2y2 + xy * xy) - x2y2));
				x = 0.5 * xy / y;

				if (dx0 * x + dy0 * y < 0.0)
				{
					x = -x;
					y = -y;
				}

				x = vtx->nodeAt((i+2)%3)->x + x;
				y = vtx->nodeAt((i+2)%3)->y + y;

				break;
			}
		}

		MeshNode *nd = new MeshNode( x, y ); //vtx->vx, vtx->vy );
		
		if( addSite( vtx, nd, false, true, false) == true )
		{
			actives.removeRelevants( deleted );
			
			int len = newVertices.size();
			for( int i = 0; i < len; ++i )
			{
				newVertices[i]->setBody( 1 );
				if( newVertices[i]->isBoundaryConnector(links) )
				{
					newVertices[i]->rightSize( 1.0 );
					actives.insert( newVertices[i] );
				}
			}
		}
		
		recycle();
	}

	return;
}