Commit 2092aca0 authored by Thomas's avatar Thomas
Browse files

debut fusion 2.5 et switch

parent a60a9c43
......@@ -30,6 +30,13 @@ void generateMall(typename PFP::MAP& map,typename PFP::TVEC3& position, CellMark
template <typename PFP>
void generatePathToUpperStair(typename PFP::MAP& map,typename PFP::TVEC3& position, Dart dLower,Dart dUpper);
/*******************************************************************************/
template <typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float radius, unsigned int nbSquares);
/*******************************************************************************/
template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position);
......
......@@ -273,6 +273,15 @@ void generatePathToUpperStair(typename PFP::MAP& map,typename PFP::TVEC3& positi
} while(dd!=dInBetweenDown);
}
template <typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float radius, unsigned int nbSquares)
{
Algo::Modelisation::Polyhedron<PFP> prim(map, position);
prim.cylinder_topo(nbSquares, nbSquares, true, true);
prim.embedSphere(radius);
}
template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark)
{
......
......@@ -60,7 +60,7 @@ public :
void subdivideAllToMaxLevel();
void subdivideToProperLevel();
void init();
void init(unsigned int config);
void foreach_neighborFace(Dart d, FunctorType& f);
......
......@@ -84,6 +84,8 @@ public:
~Simulator();
void init(unsigned int config, float dimension, bool enablePathFinding=false);
void doStep();
bool reachedGoal();
......@@ -92,6 +94,7 @@ public:
void setupCityScenario(float startX, float startY, int nbLines , int nbRank);
void setupScenario(unsigned int nbMaxAgent);
void addPathsToAgents();
void addPathsToAgents_height();
bool importAgents(std::string filename);
bool exportAgents(std::string filename);
......
......@@ -27,21 +27,6 @@ EnvMap::EnvMap() :
refineCandidate.reserve(100);
coarsenCandidate.reserve(100);
// std::string filename = "/home/jund/Desktop/drawingQuads.svg";
// std::string filename = "/home/jund/Desktop/drawingTest.svg";
// std::string filename = "/home/jund/Desktop/drawingSimple.svg";
// std::string filename = "/home/jund/Desktop/drawingLines.svg";
// std::string filename = "/home/jund/Desktop/mapKrutSimple.svg";
// std::string filename = "/home/jund/Desktop/mapKrut.svg";
// Algo::Import::importSVG<PFP>(map,filename,position, obstacleMark, buildingMark);
// scale(3.2808399f);
// Algo::BooleanOperator::mergeVertices<PFP>(map,position);
// DartMarker amelk(map);
// map.closeMap(amelk);
// Algo::Modelisation::CatmullClarkSubdivision<PFP>(map,position);
// Algo::Modelisation::computeDual<PFP>(map);
}
unsigned int EnvMap::mapMemoryCost()
......@@ -169,18 +154,45 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
return map.begin();
}
void EnvMap::init()
void EnvMap::init(unsigned int config)
{
float sideSize = 70.0f;
unsigned int nbSquares = 24;
CityGenerator::generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
// CityGenerator::generateCorridor<PFP>(map, position, obstacleMark, buildingMark, 50, nbSquares);
// CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
switch(config)
{
case 0 : CityGenerator::generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
break;
case 1 : CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
break;
case 2 : CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
break;
case 3 :
{
// std::string filename = "/home/jund/Desktop/drawingQuads.svg";
// std::string filename = "/home/jund/Desktop/drawingTest.svg";
// std::string filename = "/home/jund/Desktop/drawingSimple.svg";
// std::string filename = "/home/jund/Desktop/drawingLines.svg";
// std::string filename = "/home/jund/Desktop/mapKrutSimple.svg";
std::string filename = "/home/jund/Desktop/mapKrut.svg";
Algo::Import::importSVG<PFP>(map,filename,position, obstacleMark, buildingMark);
scale(3.2808399f);
Algo::BooleanOperator::mergeVertices<PFP>(map,position);
DartMarker amelk(map);
map.closeMap(amelk);
Algo::Modelisation::CatmullClarkSubdivision<PFP>(map,position);
Algo::Modelisation::computeDual<PFP>(map);
}
break;
case 4 : CityGenerator::generatePlanet<PFP>(map, position, obstacleMark, buildingMark, 200.0f, nbSquares);
break;
}
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::installGuardRail<PFP>(map, position, obstacleMark, buildingMark, 5.0f);
map.init();
registerObstaclesInFaces();
......
......@@ -5,19 +5,45 @@ Simulator::Simulator() : timeStep_(0.2f), globalTime_(0.0f), nbSteps_(0)
srand(10);
nbStepsPerUnit_ = 1 / timeStep_;
envMap_.init();
init(0,2.0f);
}
Simulator::~Simulator()
{
for (unsigned int i = 0; i < agents_.size(); ++i)
delete agents_[i];
}
void Simulator::init(unsigned int config, float dimension, bool enablePathFinding)
{
envMap_.init(config);
std::cout << "setup scenario" << std::endl;
// importAgents("myAgents.pos");
// setupScenario(700);
setupCircleScenario(1000);
// setupCityScenario(
// -1.0f * (12 * (70.0f / 2.0f) - 10),
// -1.0f * (12 * (70.0f / 2.0f) - 10),
// 20,
// 20
// );
// addPathsToAgents();
switch(config)
{
case 0 : setupCircleScenario(1000);
break;
case 1 : importAgents("myAgents.pos");
break;
case 2 : setupScenario(700);
break;
case 3 : setupCityScenario(
-1.0f * (12 * (70.0f / 2.0f) - 10),
-1.0f * (12 * (70.0f / 2.0f) - 10),
20,
20
);
break;
}
if(enablePathFinding)
{
if(dimension==2.0f)
addPathsToAgents();
else if(dimension==2.5f)
addPathsToAgents_height();
}
unsigned nbAgents = agents_.size();
......@@ -35,12 +61,6 @@ Simulator::Simulator() : timeStep_(0.2f), globalTime_(0.0f), nbSteps_(0)
envMap_.subdivideToProperLevel();
}
Simulator::~Simulator()
{
for (unsigned int i = 0; i < agents_.size(); ++i)
delete agents_[i];
}
void Simulator::doStep()
{
envMap_.clearUpdateCandidates();
......@@ -274,6 +294,57 @@ void Simulator::addPathsToAgents()
}
}
void Simulator::addPathsToAgents_height()
{
//city
unsigned int dartDistForPath = 50;
for(unsigned int i = 0; i < agents_.size(); ++i)
{
agents_[i]->goals_.clear();
Dart dStart = agents_[i]->part_.d;
Dart dStop = dStart;
for(unsigned int j = 0; envMap_.buildingMark.isMarked(dStop) || j < dartDistForPath+rand()*20 || envMap_.map.sameFace(dStop,dStart); ++j)
{
envMap_.map.next(dStop);
if(dStop == envMap_.map.end())
dStop = envMap_.map.begin();
}
std::vector<Dart> path = CGoGN::PathFinder::pathFindAStar<PFP>(envMap_.map, envMap_.position, dStart, dStop, envMap_.buildingMark);
for(std::vector<Dart>::iterator it = path.begin(); it != path.end(); ++it)
{
VEC3 dest = Algo::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position);
agents_[i]->goals_.push_back(dest);
}
Dart dStop2 = dStop;
for(unsigned int j = 0; envMap_.buildingMark.isMarked(dStop2) || j < dartDistForPath+rand()*20 || envMap_.map.sameFace(dStop,dStop2) || envMap_.map.sameFace(dStop2,dStart); ++j)
{
envMap_.map.next(dStop2);
if(dStop2 == envMap_.map.end())
dStop2 = envMap_.map.begin();
}
path = CGoGN::PathFinder::pathFindAStar<PFP>(envMap_.map, envMap_.position, dStop, dStop2, envMap_.buildingMark);
for(std::vector<Dart>::iterator it = path.begin(); it!=path.end();++it)
{
VEC3 dest = Algo::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position);
agents_[i]->goals_.push_back(dest);
}
path = CGoGN::PathFinder::pathFindAStar<PFP>(envMap_.map, envMap_.position, dStop2, dStart, envMap_.buildingMark);
for(std::vector<Dart>::iterator it = path.begin(); it!=path.end();++it)
{
VEC3 dest = Algo::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position);
agents_[i]->goals_.push_back(dest);
}
}
}
bool Simulator::importAgents(std::string filename)
{
std::ifstream myfile(filename.c_str(), std::ios::in);
......
......@@ -177,7 +177,7 @@ void SocialAgents::cb_redraw()
{
glColor3f((*it)->part_.state / 3.0f, (*it)->part_.state % 2, 0.0f);
glLineWidth(5.0f);
renderPredictionTriangle(sim.envMap_, (*it)->part_.d, (*it)->part_.m_position);
renderPredictionTriangle(sim.envMap_, (*it)->part_.d, (*it)->getPosition());
}
}
......@@ -482,23 +482,6 @@ void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
}
}
// if(j==0) {
// out << "object {" << " Sheriff_animated_ " << std::endl;
// out << "scale 0.165745856" << std::endl;
// }
// else if(j%7==0) {
// out << "object {" << " Cowbow_animated_ " << std::endl;
// out << "scale 0.170454545" << std::endl;
// }
// else if(j%7<5) {
// out << "object {" << " sombrero2_highres_ " << std::endl;
// out << "scale 0.127659574" << std::endl;
// }
// else {
// out << "object {" << " sombrero3_highres_ " << std::endl;
// out << "scale 0.132743363" << std::endl;
// }
out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl;
out << "scale 0.5" << std::endl;
......@@ -553,24 +536,6 @@ void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
}
}
// if(j==0) {
// out << "object {" << " Sheriff_animated_ " << std::endl;
// out << "scale 0.165745856" << std::endl;
// }
// else if(j%7==0) {
// out << "object {" << " Cowbow_animated_ " << std::endl;
// out << "scale 0.170454545" << std::endl;
// }
// else if(j%7<5) {
// out << "object {" << " sombrero2_highres_ " << std::endl;
// out << "scale 0.127659574" << std::endl;
// }
// else {
// out << "object {" << " sombrero3_highres_ " << std::endl;
// out << "scale 0.132743363" << std::endl;
//
// }
out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl;
out << "scale 0.5" << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment