Commit 796d8ff2 authored by Thomas's avatar Thomas
Browse files

Merge branch 'master' of cgogn:~kraemer/CGoGN_Apps/SocialAgents2

parents dbb974dc 1bc93ad5
......@@ -128,14 +128,15 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
PFP::AGENTS& a = agentvect[d];
PFP::AGENTS::iterator end = a.end();
bool found = false;
PFP::AGENTS::iterator end = agentvect[d].end();
for(PFP::AGENTS::iterator it = agentvect[d].begin(); it != end && !found; ++it)
for(PFP::AGENTS::iterator it = a.begin(); it != end && !found; ++it)
{
if(*it == agent)
{
*it = agentvect[d].back();
agentvect[d].pop_back();
*it = a.back();
a.pop_back();
found = true;
}
}
......@@ -147,13 +148,14 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
while(ddd != dd)
{
bool found = false;
PFP::AGENTS::iterator end = neighborAgentvect[ddd].end();
for(PFP::AGENTS::iterator it = neighborAgentvect[ddd].begin(); it != end && !found; ++it)
PFP::AGENTS& na = neighborAgentvect[ddd];
PFP::AGENTS::iterator end = na.end();
for(PFP::AGENTS::iterator it = na.begin(); it != end && !found; ++it)
{
if(*it == agent)
{
*it = neighborAgentvect[ddd].back();
neighborAgentvect[ddd].pop_back();
*it = na.back();
na.pop_back();
found = true;
}
}
......@@ -165,7 +167,12 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::addRefineCandidate(Dart d)
{
refineCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(d, FACE_ORBIT), d)) ;
if(agentvect[d].size() > nbAgentsToSubdivide)
{
std::pair<bool,bool>& sf = subdivisableFace[d] ;
if(sf.first == false || (sf.first == true && sf.second))
refineCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(d, FACE_ORBIT), d)) ;
}
}
inline void EnvMap::addCoarsenCandidate(Dart d)
......@@ -176,7 +183,7 @@ inline void EnvMap::addCoarsenCandidate(Dart d)
inline void EnvMap::clearUpdateCandidates()
{
refineCandidate.clear();
coarsenCandidate.clear();
// coarsenCandidate.clear();
}
#endif
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>188</width>
<height>472</height>
<width>208</width>
<height>457</height>
</rect>
</property>
<property name="windowTitle">
......@@ -16,12 +16,81 @@
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QCheckBox" name="check_timer">
<property name="text">
<string>Animate</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawEnvLines">
<property name="text">
<string>draw env lines</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawEnvFaces">
<property name="text">
<string>draw env faces</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawEnvTopo">
<property name="text">
<string>draw env topo</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawObstacles">
<property name="text">
<string>draw obstacles</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawAgents">
<property name="text">
<string>draw agents</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawAgentsPredictionTri">
<property name="text">
<string>draw agents prediction tri</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawAgentsNeighborDist">
<property name="text">
<string>draw agents neighbor dist</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawAgentsObstacleDist">
<property name="text">
<string>draw agents obstacle dist</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -76,8 +76,25 @@ public:
int visu;
int nbGenerated;
float explode;
bool drawEnvLines ;
bool drawEnvFaces ;
bool drawEnvTopo ;
bool drawObstacles ;
bool drawAgents ;
bool drawAgentsNeighborDist ;
bool drawAgentsObstacleDist ;
bool drawAgentsPredictionTri ;
public slots:
void animate() ;
void slot_timer(bool b) { b ? timer->start() : timer->stop() ; }
void slot_drawEnvLines(bool b) { drawEnvLines = b ; updateGL() ; }
void slot_drawEnvFaces(bool b) { drawEnvFaces = b ; updateGL() ; }
void slot_drawEnvTopo(bool b) { drawEnvTopo = b ; updateGL() ; }
void slot_drawObstacles(bool b) { drawObstacles = b ; updateGL() ; }
void slot_drawAgents(bool b) { drawAgents = b ; updateGL() ; }
void slot_drawAgentsPredictionTri(bool b) { drawAgentsPredictionTri = b ; updateGL() ; }
void slot_drawAgentsNeighborDist(bool b) { drawAgentsNeighborDist = b ; updateGL() ; }
void slot_drawAgentsObstacleDist(bool b) { drawAgentsObstacleDist = b ; updateGL() ; }
} ;
......@@ -42,9 +42,9 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 40;
// CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
unsigned int nbSquares = 20;
CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.init();
registerObstaclesInFaces();
......@@ -211,7 +211,10 @@ void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbo
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
popAgentInCells(agent, oldFace);
// addCoarsenCandidate(oldFace);
pushAgentInCells(agent, agent->part_.d);
addRefineCandidate(agent->part_.d);
}
void EnvMap::updateMap()
......@@ -222,27 +225,29 @@ void EnvMap::updateMap()
{
Dart d = (*it).second ;
unsigned int fLevel = map.faceLevel(d) ;
Dart old = map.faceOldestDart(d) ;
if(agentvect[old].size() > nbAgentsToSubdivide)
if(agentvect[d].size() > nbAgentsToSubdivide)
{
unsigned int fLevel = -1 ;
Dart old = map.faceOldestDart(d) ;
bool subdivisable = true ;
if(subdivisableFace[old].first == true)
{
subdivisable = subdivisableFace[old].second ;
}
std::pair<bool,bool>& sf = subdivisableFace[d] ;
if(sf.first == true)
subdivisable = sf.second ;
else
{
float maxEdgeSize = Agent::neighborDistSq_ ; // diametre de vision de l'agent au carré
fLevel = map.faceLevel(d) ;
map.setCurrentLevel(fLevel) ;
PFP::VEC3 fCenter = Algo::Geometry::faceCentroid<PFP>(map, old, position) ;
Dart fd = old ;
do
{
PFP::VEC3& p = position[fd] ;
PFP::VEC3 edge = Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
PFP::VEC3 proj = fCenter - (position[fd] + (edge * (fCenter - position[fd]) / edge.norm2()) * edge) ;
PFP::VEC3 proj = fCenter - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
if(proj.norm2() < maxEdgeSize)
// if(Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position).norm2() < maxEdgeSize)
{
......@@ -253,13 +258,16 @@ void EnvMap::updateMap()
} while(fd != old) ;
map.setCurrentLevel(map.getMaxLevel()) ;
subdivisableFace[old].first = true ;
subdivisableFace[old].second = subdivisable ;
sf.first = true ;
sf.second = subdivisable ;
}
if(subdivisable)
{
subdivisableFace[old].first = false ;
if(fLevel == -1)
fLevel = map.faceLevel(d) ;
sf.first = false ;
PFP::AGENTS oldAgents(agentvect[old]);
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
......@@ -279,44 +287,52 @@ void EnvMap::updateMap()
pushAgentInCells(*ait, (*ait)->part_.d) ;
}
unsigned int degree = 0;
Dart dd = old;
unsigned int degree = 0 ;
Dart dd = old ;
do
{
++degree;
Dart d3 = dd;
++degree ;
Dart d3 = dd ;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
Dart d4 = map.alpha1(map.alpha1(d3)) ;
PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
{
PFP::AGENTS& ad4 = agentvect[d4] ;
nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
}
d4 = map.alpha1(d4) ;
}
d3 = map.phi1(d3);
} while(d3 != dd);
d3 = map.phi1(d3) ;
} while(d3 != dd) ;
map.setCurrentLevel(fLevel) ;
dd = map.phi1(dd);
dd = map.phi1(dd) ;
map.setCurrentLevel(map.getMaxLevel()) ;
} while(dd != old);
if(degree == 3)
{
Dart centerFace = map.phi2(map.phi1(old));
Dart d3 = centerFace;
Dart centerFace = map.phi2(map.phi1(old)) ;
Dart d3 = centerFace ;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
Dart d4 = map.alpha1(map.alpha1(d3)) ;
PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
{
PFP::AGENTS& ad4 = agentvect[d4] ;
nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
}
d4 = map.alpha1(d4) ;
}
d3 = map.phi1(d3);
} while(d3 != centerFace);
d3 = map.phi1(d3) ;
} while(d3 != centerFace) ;
}
}
}
......
......@@ -7,7 +7,7 @@ Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.1f)
std::cout << "setup scenario" << std::endl;
// importAgents("myAgents.pos");
setupScenario(15000);
addPathsToAgents();
// addPathsToAgents();
for(unsigned int i = 0; i < agents_.size(); ++i)
{
agents_[i]->updateObstacleNeighbors();
......@@ -48,8 +48,6 @@ void Simulator::doStep()
// break;
// case CGoGN::Algo::MovingObjects::CROSS_OTHER :
envMap_.agentChangeFace(agents_[i], oldFace);
envMap_.addCoarsenCandidate(oldFace);
envMap_.addRefineCandidate(agents_[i]->part_.d);
// break;
}
......@@ -63,6 +61,11 @@ void Simulator::doStep()
envMap_.updateMap();
globalTime_ += timeStep_;
if(globalTime_ - int(globalTime_) == 0.0f && int(globalTime_) % 500 == 0)
{
swapAgentsGoals();
}
}
void Simulator::setupScenario(unsigned int nbMaxAgent)
......@@ -77,7 +80,7 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
unsigned int nbx = 3;
unsigned int nby = 3;
unsigned int bMax = nbMaxAgent/(nbx*nby);
unsigned int bMax = nbMaxAgent / (nbx*nby);
for (unsigned int i = 0; i < bMax && d != envMap_.map.end(); ++i)
{
......@@ -141,7 +144,7 @@ void Simulator::addPathsToAgents()
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)
for(std::vector<Dart>::iterator it = path.begin(); it != path.end(); ++it)
agents_[i]->goals_.push_back(Algo::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position));
Dart dStop2 = dStop;
......@@ -231,7 +234,8 @@ void Simulator::swapAgentsGoals()
{
unsigned int r = rand() % nbAgents;
if(agents_[i]->goals_[1][0]!=agents_[r]->goals_[1][0] || agents_[i]->goals_[1][1]!=agents_[r]->goals_[1][1]) {
if(agents_[i]->goals_[1][0] != agents_[r]->goals_[1][0] || agents_[i]->goals_[1][1] != agents_[r]->goals_[1][1])
{
VEC3 g = agents_[i]->goals_[1];
agents_[i]->goals_[1] = agents_[r]->goals_[1];
agents_[r]->goals_[1] = g;
......
......@@ -25,21 +25,24 @@
#include "viewer.h"
#include <string>
SocialAgents::SocialAgents()
SocialAgents::SocialAgents() :
drawEnvLines(true),
drawEnvFaces(false),
drawEnvTopo(false),
drawAgents(true),
drawAgentsNeighborDist(false),
drawAgentsObstacleDist(false),
drawAgentsPredictionTri(false)
{
explode = 0.9f;
render_anim = false;
nbGenerated = 0;
displayFps = false;
displayFps = true;
nextUpdate = clock() + 1 * CLOCKS_PER_SEC;
fps = 0;
glEnable( GL_POINT_SMOOTH );
visu = 0;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
}
......@@ -47,6 +50,19 @@ SocialAgents::SocialAgents()
void SocialAgents::initGUI()
{
setDock(&dock) ;
dock.check_drawEnvLines->setChecked(true) ;
dock.check_drawAgents->setChecked(true) ;
setCallBack( dock.check_timer, SIGNAL(toggled(bool)), SLOT(slot_timer(bool)) ) ;
setCallBack( dock.check_drawEnvLines, SIGNAL(toggled(bool)), SLOT(slot_drawEnvLines(bool)) ) ;
setCallBack( dock.check_drawEnvFaces, SIGNAL(toggled(bool)), SLOT(slot_drawEnvFaces(bool)) ) ;
setCallBack( dock.check_drawEnvTopo, SIGNAL(toggled(bool)), SLOT(slot_drawEnvTopo(bool)) ) ;
setCallBack( dock.check_drawObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawObstacles(bool)) ) ;
setCallBack( dock.check_drawAgents, SIGNAL(toggled(bool)), SLOT(slot_drawAgents(bool)) ) ;
setCallBack( dock.check_drawAgentsPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPredictionTri(bool)) ) ;
setCallBack( dock.check_drawAgentsNeighborDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsNeighborDist(bool)) ) ;
setCallBack( dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool)) ) ;
}
void SocialAgents::cb_initGL()
......@@ -79,105 +95,106 @@ void SocialAgents::cb_redraw()
glVertex3f(0.,0.,1.);
glEnd();
for(std::vector<Agent*>::iterator it = sim.agents_.begin(); it != sim.agents_.end(); ++ it)
{
renderAgent(sim.envMap_,*it);
if(drawAgents)
{
for(std::vector<Agent*>::iterator it = sim.agents_.begin(); it != sim.agents_.end(); ++ it)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
renderAgent(sim.envMap_, *it, drawAgentsNeighborDist, drawAgentsObstacleDist);
// for(std::vector<std::pair<float, Dart> >::iterator obst = (*it)->obstacleNeighbors_.begin();
// obst != (*it)->obstacleNeighbors_.end() && obst->first < (*it)->rangeSq_;
// ++obst)
// {
// glColor3f(0.0f, 1.0f, 1.0f);
// glLineWidth(10.0f);
// renderDart(sim.envMap_, obst->second);
// }
// for(std::vector<std::pair<float, Dart> >::iterator obst = (*it)->obstacleNeighbors_.begin();
// obst != (*it)->obstacleNeighbors_.end() && obst->first < (*it)->rangeSq_;
// ++obst)
// {
// glColor3f(0.0f, 1.0f, 1.0f);
// glLineWidth(10.0f);
// renderDart(sim.envMap_, obst->second);
// }
}
}
if(visu == 1)
if(drawAgentsPredictionTri)
{
for(std::vector<Agent*>::iterator it = sim.agents_.begin(); it != sim.agents_.end(); ++ it)
{
// draw prediction triangle
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);
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);
}
}
//draw the environment
if(visu == 0)
if(drawEnvLines)
{
// glEnable(GL_LIGHTING);
// glColor3f(1.0f ,1.0f ,1.0f);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.map, Algo::Render::GL1::FLAT, 1.0, sim.envMap_.position, sim.envMap_.normal);
// glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glDisable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.map, Algo::Render::GL1::LINE, 1.0, sim.envMap_.position, sim.envMap_.normal);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}
else if(visu == 1)
if(drawEnvFaces)
{
glDisable(GL_LIGHTING);
glEnable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL) ;
glPolygonOffset(1.0f, 1.0f) ;
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.map, Algo::Render::GL1::LINE, 1.0, sim.envMap_.position, sim.envMap_.normal);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}
else if(visu == 2)
if(drawEnvTopo)
{
glDisable(GL_LIGHTING);
glLineWidth(1.0f);
Algo::Render::GL1::renderTopoMD2<PFP>(sim.envMap_.map, sim.envMap_.position, true, true, 0.9f, 0.9f);
}
else if(visu == 3)
{}
glColor3f(1.0f, 0.0f, 0.0f);
glLineWidth(5.0f);
CellMarker dmo(sim.envMap_.map, EDGE_CELL);
for(Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
if(drawObstacles)
{
if(!dmo.isMarked(d))
glColor3f(1.0f, 0.0f, 0.0f);
glLineWidth(5.0f);
CellMarker dmo(sim.envMap_.map, EDGE_CELL);
for(Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
{
dmo.mark(d);
if(sim.envMap_.obstacleMark.isMarked(d))
renderDart(sim.envMap_, d);
if(!dmo.isMarked(d))
{
dmo.mark(d);
if(sim.envMap_.obstacleMark.isMarked(d))
renderDart(sim.envMap_, d);
}
}
}
glPushMatrix();
glBegin(GL_LINES);
unsigned int iter = 100;
for(int i=0;i<700;i=i+iter)
{
VEC3 camPos(-800,-800,10);
camPos = camPos + VEC3(-10-0.3*i,400.0f*log(1.0f+i/700.0f),30+0.3*i);
glVertex3fv(&camPos[0]);
camPos = VEC3(-800,-800,10);
camPos = camPos + VEC3(-10-0.3*(i+iter),400.0f*log(1.0f+(i+iter)/700.0f),30+0.3*(i+iter));
glVertex3fv(&camPos[0]);
}
glEnd();
glPopMatrix();
glPushMatrix();
glBegin(GL_LINES);
for(int i=0;i<700;i=i+iter)
{
VEC3 camLook(0,0,0);
camLook = camLook + VEC3(-10-0.1*i,400.0f*log(1.0f+i/700.0f),30+0.1*i);
glVertex3fv(&camLook[0]);
camLook = VEC3(0,0,0);
camLook = camLook + VEC3(-10-0.1*(i+iter),400.0f*log(1.0f+(i+iter)/700.0f),30+0.1*(i+iter));
glVertex3fv(&camLook[0]);
}
glEnd();
glPopMatrix();
// glPushMatrix();
// glBegin(GL_LINES);
// unsigned int iter = 100;
// for(int i=0;i<700;i=i+iter)
// {
// VEC3 camPos(-800,-800,10);
// camPos = camPos + VEC3(-10-0.3*i,400.0f*log(1.0f+i/700.0f),30+0.3*i);
// glVertex3fv(&camPos[0]);
// camPos = VEC3(-800,-800,10);
// camPos = camPos + VEC3(-10-0.3*(i+iter),400.0f*log(1.0f+(i+iter)/700.0f),30+0.3*(i+iter));
// glVertex3fv(&camPos[0]);
// }
// glEnd();
// glPopMatrix();
//
// glPushMatrix();
// glBegin(GL_LINES);
// for(int i=0;i<700;i=i+iter)
// {
// VEC3 camLook(0,0,0);
// camLook = camLook + VEC3(-10-0.1*i,400.0f*log(1.0f+i/700.0f),30+0.1*i);
// glVertex3fv(&camLook[0]);
// camLook = VEC3(0,0,0);
// camLook = camLook + VEC3(-10-0.1*(i+iter),400.0f*log(1.0f+(i+iter)/700.0f),30+0.1*(i+iter));
// glVertex3fv(&camLook[0]);
// }
// glEnd();