Commit af76ccee authored by Pierre Kraemer's avatar Pierre Kraemer

correction GROS BUG !!

parent 42b91bf6
......@@ -3,6 +3,7 @@
#include "env_map.h"
#include "agent.h"
#include "Utils/colorMaps.h"
inline void renderDart(EnvMap& m, Dart d)
{
......@@ -48,13 +49,15 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
VEC3 pos = agent->part_.m_position;
float radius = agent->radius_;
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
pos[2] -= 1000;
Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos);
// Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
// pos[2] -= 1000;
// Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos);
glLineWidth(1.0f);
glColor3f(1.0f,0.0f,0.0f);
// VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
// glColor3fv(col.data());
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
for(unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
......
......@@ -171,7 +171,7 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 5;
unsigned int nbSquares = 14;
// float sideSize = 420.0f;
// unsigned int nbSquares = 4;
......@@ -509,6 +509,8 @@ void EnvMap::updateMap()
if(map.faceIsSubdividedOnce(old))
{
// on compte le nombre d'agents dans les sous-faces
// on en profite pour compter le degré de la face grossière
unsigned int degree = 0 ;
unsigned int nbAgents = 0 ;
Dart fit = old ;
......@@ -516,6 +518,21 @@ void EnvMap::updateMap()
{
nbAgents += agentvect[fit].size() ;
++degree ;
coarsenMark.unmark(fit) ;
unsigned int start = it + 1;
unsigned int fEmb = map.getEmbedding(FACE, fit) ;
while(start < coarsenCandidate.size())
{
if(map.getEmbedding(FACE, coarsenCandidate[start]) == fEmb)
{
coarsenCandidate[start] = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
fit = map.phi1(fit) ;
} while(fit != old) ;
if(degree == 3)
......@@ -523,6 +540,19 @@ void EnvMap::updateMap()
map.setCurrentLevel(fLevel) ;
Dart centerFace = map.phi2(map.phi1(old)) ;
nbAgents += agentvect[centerFace].size() ;
coarsenMark.unmark(centerFace) ;
unsigned int start = it + 1;
unsigned int fEmb = map.getEmbedding(FACE, centerFace) ;
while(start < coarsenCandidate.size())
{
if(map.getEmbedding(FACE, coarsenCandidate[start]) == fEmb)
{
coarsenCandidate[start] = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
map.setCurrentLevel(fLevel - 1) ;
}
......@@ -532,25 +562,11 @@ void EnvMap::updateMap()
Dart fit = old ;
do
{
map.setCurrentLevel(fLevel) ;
coarsenMark.unmark(fit) ;
unsigned int start = it + 1;
unsigned int fEmb = map.getEmbedding(FACE, fit) ;
while(start < coarsenCandidate.size())
{
if(map.getEmbedding(FACE, coarsenCandidate[start]) == fEmb)
{
coarsenCandidate[start] = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
PFP::AGENTS a(agentvect[fit]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
map.setCurrentLevel(map.getMaxLevel()) ;
for(PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
popAgentInCells(*ait, fit);
popAgentInCells(*ait, fit) ;
map.setCurrentLevel(fLevel - 1) ;
Dart nf = map.phi2(fit) ;
if(!map.faceIsSubdivided(nf))
......@@ -566,24 +582,10 @@ void EnvMap::updateMap()
}
fit = map.phi1(fit) ;
} while(fit != old) ;
if(degree == 3)
{
map.setCurrentLevel(fLevel) ;
Dart centerFace = map.phi2(map.phi1(old)) ;
coarsenMark.unmark(centerFace) ;
unsigned int start = it + 1;
unsigned int fEmb = map.getEmbedding(FACE, centerFace) ;
while(start < coarsenCandidate.size())
{
if(map.getEmbedding(FACE, coarsenCandidate[start]) == fEmb)
{
coarsenCandidate[start] = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
PFP::AGENTS a(agentvect[centerFace]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
map.setCurrentLevel(map.getMaxLevel());
......@@ -591,6 +593,7 @@ void EnvMap::updateMap()
popAgentInCells(*ait, centerFace);
map.setCurrentLevel(fLevel - 1) ;
}
neighborAgentvect[old].clear();
Algo::IHM::coarsenFace<PFP>(map, old, position) ;
......@@ -600,7 +603,6 @@ void EnvMap::updateMap()
map.setCurrentLevel(map.getMaxLevel());
agentvect[old].clear();
for(PFP::AGENTS::iterator itA = agents.begin(); itA != agents.end(); ++itA)
{
(*itA)->part_.d = old ;
......@@ -628,8 +630,6 @@ void EnvMap::updateMap()
}
}
map.setCurrentLevel(cur) ;
}
}
......
#include "simulator.h"
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.25f)
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.2f)
{
srand(10);
envMap_.init();
std::cout << "setup scenario" << std::endl;
// importAgents("myAgents.pos");
setupScenario(10);
setupScenario(700);
// setupCircleScenario(1000);
// setupCityScenario(-1.0f*(24*(70/2.0f)-10),-1.0f*(24*(70.0f/2.0f)-10),167,5);
// addPathsToAgents();
......@@ -97,11 +97,11 @@ void Simulator::doStep()
globalTime_ += timeStep_;
// if(int(globalTime_ / timeStep_) % 2000 == 0)
// {
// std::cout << "swap goals (globalTime -> " << globalTime_ << ")" << std::endl ;
// swapAgentsGoals();
// }
if(int(globalTime_ / timeStep_) % 2000 == 0)
{
std::cout << "swap goals (globalTime -> " << globalTime_ << ")" << std::endl ;
swapAgentsGoals();
}
}
bool Simulator::reachedGoal()
......@@ -169,8 +169,8 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
Dart d = envMap_.map.begin();
CellMarker filled(envMap_.map,FACE);
unsigned int nbx = 2;
unsigned int nby = 2;
unsigned int nbx = 10;
unsigned int nby = 10;
unsigned int bMax = nbMaxAgent / (nbx*nby);
......
......@@ -114,6 +114,60 @@ void SocialAgents::cb_redraw()
// renderDart(sim.envMap_, obst->second);
// }
}
// CellMarker m(sim.envMap_.map, FACE);
// for(Dart d = sim.envMap_.map.begin() ; d != sim.envMap_.map.end() ; sim.envMap_.map.next(d))
// {
// if(!m.isMarked(d) && !sim.envMap_.buildingMark.isMarked(d))
// {
// m.mark(d);
//
// Dart dd = d;
// VEC3 cornerLeftBottom = sim.envMap_.position[d];
// do
// {
// VEC3 p = sim.envMap_.position[dd];
// if(cornerLeftBottom[0] > p[0])
// cornerLeftBottom[0] = p[0];
// if(cornerLeftBottom[1] > p[1])
// cornerLeftBottom[1] = p[1];
// if(cornerLeftBottom[2] > p[2])
// cornerLeftBottom[2] = p[2];
// dd = sim.envMap_.map.phi1(dd);
// } while (dd != d);
//
// //draw vectors
// //contains
// for(unsigned int i = 0 ; i < sim.envMap_.agentvect[d].size() ; ++i)
// {
// Agent* ag = sim.envMap_.agentvect[d][i];
//
// VEC3 col = Utils::color_map_BCGYR(float(ag->agentNo)/float(sim.agents_.size()));
// glColor3fv(col.data());
// glBegin(GL_POINTS);
// if(i < 5)
// glVertex3f(cornerLeftBottom[0]+5+1+i*2, cornerLeftBottom[1]+7+1.5, cornerLeftBottom[2]+2);
// else
// glVertex3f(cornerLeftBottom[0]+5+1+(i-5)*2, cornerLeftBottom[1]+7+1.5+3, cornerLeftBottom[2]+2);
// glEnd();
// }
//
// //neighbours
// for(unsigned int i = 0 ; i < sim.envMap_.neighborAgentvect[d].size() ; ++i)
// {
// Agent* ag = sim.envMap_.neighborAgentvect[d][i];
//
// VEC3 col = Utils::color_map_BCGYR(float(ag->agentNo)/float(sim.agents_.size()));
// glColor3fv(col.data());
// glBegin(GL_POINTS);
// if(i < 8)
// glVertex3f(12+cornerLeftBottom[0]+5+1+i*2, cornerLeftBottom[1]+7+1.5, cornerLeftBottom[2]+2);
// else
// glVertex3f(12+cornerLeftBottom[0]+5+1+(i-8)*2, cornerLeftBottom[1]+7+1.5+3, cornerLeftBottom[2]+2);
// glEnd();
// }
// }
// }
}
if(drawAgentsPredictionTri)
......@@ -279,23 +333,23 @@ void SocialAgents::cb_redraw()
void SocialAgents::animate()
{
if(sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 10 == 0)
if(sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1000 == 0)
std::cout << sim.globalTime_ << " " << sim.envMap_.mapMemoryCost() << std::endl;
// std::cout << "t : " << sim.globalTime_ << std::endl;
timeval startTime;
gettimeofday(&startTime, NULL);
timeval endTime;
long seconds, nseconds;
// timeval startTime;
// gettimeofday(&startTime, NULL);
// timeval endTime;
// long seconds, nseconds;
sim.doStep();
gettimeofday(&endTime, NULL);
seconds = endTime.tv_sec - startTime.tv_sec;
nseconds = endTime.tv_usec - startTime.tv_usec;
elapsedTime += (seconds + nseconds/1000000.0) ;
// gettimeofday(&endTime, NULL);
// seconds = endTime.tv_sec - startTime.tv_sec;
// nseconds = endTime.tv_usec - startTime.tv_usec;
//
// elapsedTime += (seconds + nseconds/1000000.0) ;
// if(sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0)
// {
......@@ -723,7 +777,6 @@ bool SocialAgents::exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std
if(infoFaces)
{
CellMarker m(sim.envMap_.map,FACE);
// m.unmarkAll();
for(Dart d = sim.envMap_.map.begin() ; d != sim.envMap_.map.end() ; sim.envMap_.map.next(d))
{
if(!m.isMarked(d))
......
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