Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 6ec46172 authored by Thomas's avatar Thomas
Browse files

socialagents : un peu de nettoyage

parent 4d7589e3
......@@ -2,7 +2,6 @@
#define ENVMap_H
#include <iostream>
// #include "Definitions.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
......@@ -32,19 +31,12 @@ struct PFP {
// definition du type de vecteur (point) utilise
typedef Geom::Vec3f VEC3;
// definition des listes d'agent
// typedef std::vector<Agent *> AGENTS;
typedef std::vector<Agent * > AGENTS;
typedef NoMathIONameAttribute<AGENTS > AGENTVECT;
typedef AttributeHandler<VEC3> TVEC3;
typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
// definition des cellules abstraites
// typedef MAP::EVertex EVERTEX;
// typedef MAP::EEdge EEDGE;
// typedef MAP::EFace EFACE;
// typedef MAP::EVolume EVOLUME;
};
typedef PFP::VEC3 VEC3 ;
......@@ -53,33 +45,26 @@ class EnvMap
{
public :
PFP::MAP map;
//SelectorTrue<PFP::MAP::Dart> allDarts;
//identifier for the position attribute
// unsigned int idPos;
PFP::TVEC3 position;
//identifier for the normal attribute
// unsigned int idNorm;
PFP::TVEC3 normal;
// unsigned int idAgent;
PFP::TAB_AGENTVECT agentvect;
float sideSize;
// PFP::POSITION tablePosition;
// PFP::TAB_AGENTVECT tableAgent;
DartMarker closeMark;
// DartMarker subdivMarker;
std::vector<Dart> newBuildings;
// std::vector<Dart> subdividedDarts;
Dart dSimplify;
Dart dSubdivide;
std::list<Dart> filledFaces;
static const unsigned int maxNbAgentInFace=3;
EnvMap();
bool simplifiable(Dart d);
......@@ -89,11 +74,6 @@ class EnvMap
bool simplifyEdge(Dart& d);
void simplify();
VEC3 faceCenter(Dart d);
// const PFP::VEC3& getPosition(const Dart& d);
// RVO::Vector2 getPosition2(Dart d);
unsigned int getNbFaces();
Dart getDart(unsigned int i);
......@@ -104,33 +84,23 @@ class EnvMap
void findAgentContactInFace(Dart d, PFP::VEC3 pos, float radius, std::vector<Dart>& l_contact_Dart,DartMarker& m);
// void insertObstacleOfFace(Agent * agent, const Dart d);
void insertObstacleOfFace(PFP::AGENTS agents,Dart d);
// void getAllFacesOfAgent(Agent * agent, Dart d, PFP::VEC3 pos, float radius);
void getAllFacesOfAgents(Dart d);
void linkAgentWithCells(Agent* agent);
void addObstacle(std::vector<VEC3> points);
bool subdivideSquare(Dart d);
bool subdivideFace(Dart d);
void resetAgentInFace(Agent * agent);
bool checkForSubdivision(Dart d);
void updateMap();
void subdivideFaces();
void simplifyFaces();
void pushFaceToSubdivide(Dart d);
void pushFaceToSubdivide(const Dart& d);
std::list<Dart>::iterator popFaceToSubdivide(Dart d);
void popFaceToSubdivide(const Dart& d);
void pushAgentInCell(Agent * agent, Dart d);
......
......@@ -161,16 +161,12 @@ bool EnvMap::simplifyEdge(Dart& d)
void EnvMap::simplify()
{
// for(unsigned int i=0;i<10;++i) {
bool nomodif;
do {
// map.check();
nomodif=true;
for(Dart d= map.begin() ; d!= map.end(); map.next(d)) {
// std::cout << "dart " << d << std::endl;
// simplifyVertex(d);
nomodif = !simplifyVertex(d) && nomodif;
}
......@@ -180,38 +176,28 @@ void EnvMap::simplify()
} while(!nomodif);
map.check();
// for(Dart d= map.begin() ; d!= map.end(); map.next(d)) {
// if(simplifiable(d)) {
// map.mergeFaces(d);
// }
// }
// std::cout << "i" << i << std::endl;
// }
}
Dart EnvMap::getDart(unsigned int i)
{
Dart d;
for(d=map.begin(); d !=map.end() ; map.next(d)) {
for(Dart d=map.begin(); d != map.end(); map.next(d)) {
if(d==i)
return d;
}
std::cout << "Dart not found" << std::endl;
return d;
return map.end();
}
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
Dart d;
for(d=map.begin(); d!=map.end() ; map.next(d)) {
for(Dart d=map.begin(); d!=map.end() ; map.next(d)) {
if(!closeMark.isMarked(d) && Algo::Geometry::isPointInConvexFace2D<PFP>(map,d,position,pos,true)) {
return d;
}
}
std::cout << "pos not in map" << std::endl;
std::cout << "ERROR : pos not in map" << std::endl;
return map.begin();
}
......@@ -249,81 +235,35 @@ void EnvMap::getAllFacesOfAgents(Dart d)
do {
ddd = map.alpha1(ddd);
if(ddd!=dd) {
// if(!closeMark.isMarked(dd))
insertObstacleOfFace(agentvect[d],ddd);
insertObstacleOfFace(agentvect[d],ddd);
addNeighborAgents(agentvect[d],agentvect[ddd]);
}
} while(ddd!=dd);
dd = map.phi1(dd);
}while(dd!=d);
// pushAgentInCell(agent,d);
// l_contact_Dart.push_back(d);
// cm.mark(d);
// insertObstacleOfFace(agent,d);
//
// Dart dd = d;
// do {
// Dart ddd = map.alpha1(dd);
// do {
// ddd = map.alpha1(ddd);
// if(ddd!=dd) {
// // pushAgentInCell(agent,ddd);
// // l_contact_Dart.push_back(d);
// // cm.mark(ddd);
// insertObstacleOfFace(agent,ddd);
// }
// } while(ddd!=dd);
//
// dd = map.phi1(dd);
// }while(dd!=d);
// pushAgentInCell(agent,d,l_contact_Dart);
//
// insertObstacleOfFace(agent,d);
//
// Dart dd = d;
// do {
// Dart ddd = map.alpha1(dd);
// do {
// ddd = map.alpha1(ddd);
// if(ddd!=dd) {
// pushAgentInCell(agent,ddd,l_contact_Dart);
// insertObstacleOfFace(agent,ddd);
// }
// } while(ddd!=dd);
//
// dd = map.phi1(dd);
// }while(dd!=d);
}
void EnvMap::pushFaceToSubdivide(Dart d)
void EnvMap::pushFaceToSubdivide(const Dart& d)
{
// for(std::list<Dart>::iterator it = filledFaces.begin(); it != filledFaces.end() ; ++it) {
// if(map.sameFace(d,*it))
// return;
// }
for(std::list<Dart>::iterator it = filledFaces.begin(); it != filledFaces.end() ; ++it) {
if(agentvect[d]==agentvect[*it])
return;
}
filledFaces.push_back(d);
}
std::list<Dart>::iterator EnvMap::popFaceToSubdivide(Dart d)
void EnvMap::popFaceToSubdivide(const Dart& d)
{
for(std::list<Dart>::iterator it = filledFaces.begin(); it != filledFaces.end() ; ++it)
if(map.sameFace(d,*it)) {
return filledFaces.erase(it);
}
std::cout << "ERROR : cannot pop face to subdivide " << std::endl;
if(agentvect[d]==agentvect[*it])
filledFaces.erase(it);
}
void EnvMap::pushAgentInCell(Agent * agent, Dart d)
{
agentvect[d].push_back(agent);
if(agentvect[d].size()==1) {
if(agentvect[d].size()>maxNbAgentInFace) {
pushFaceToSubdivide(d);
}
}
......@@ -333,8 +273,6 @@ void EnvMap::popAgentInCell(Agent * agent, Dart d)
for(PFP::AGENTVECT::iterator it = agentvect[d].begin(); it != agentvect[d].end() ; ++it)
if(*it==agent) {
agentvect[d].erase(it);
if(agentvect[d].size()==0)
popFaceToSubdivide(d);
return;
}
......@@ -372,16 +310,16 @@ void EnvMap::subdivideFaces()
for(std::list<Dart>::iterator itF = filledFaces.begin(); itF != filledFaces.end(); ++itF)
{
Dart d = *itF;
if(!closeMark.isMarked(d) && agentvect[d].size() > 3)
if(agentvect[d].size() > maxNbAgentInFace)
{
if(!map.faceIsSubdivided(d))
{
itF = filledFaces.erase(itF);
d = map.faceOldestDart(d) ;
std::vector<Agent*> agents ;
agents.swap(agentvect[d]) ;
itF = filledFaces.erase(itF);
unsigned int fLevel = map.faceLevel(d) ;
map.setCurrentLevel(fLevel) ;
......@@ -408,246 +346,9 @@ void EnvMap::subdivideFaces()
}
}
}
// else if(agentvect[d].size()==0)
// itF = filledFaces.erase(itF);
}
// for(unsigned int i=0;i<8;++i) {
// if(/*!fm.isMarked(d) && */!closeMark.isMarked(dSubdivide) && !closeMark.isMarked(map.phi2(dSubdivide))) {
// VEC3 n = Algo::Geometry::triangleNormal<PFP>(map,dSubdivide,position);
// if(n[2]==1.0f) {
// if(checkForSubdivision(dSubdivide)) {
// map.next(dSubdivide);
// if(dSubdivide==map.end()) {
// dSubdivide = map.begin();
// }
// return;
// }
// }
// }
// map.next(dSubdivide);
//
// if(dSubdivide==map.end()) {
// dSubdivide = map.begin();
// }
// }
}
void EnvMap::simplifyFaces()
{
// map.check();
// for(Dart d = map.begin(); d!= map.end() ; map.next(d)) {
for(unsigned int i=0;i<2;++i) {
// std::cout << "subdividedDarts size " << subdividedDarts.size() << std::endl;
// for(std::vector<Dart>::iterator it = subdividedDarts.begin(); it != subdividedDarts.end() ; ++it) {
// Dart d=*it;
// if(map.phi1(d)!=map.phi_1(d))
// do {
// Dart dNext = dSimplify;
// map.next(dNext);
if(!closeMark.isMarked(dSimplify) && !closeMark.isMarked(map.phi2(dSimplify)) && agentvect[dSimplify].size()==0) {
// if(noAgentSurroundingVertex(dSimplify) && simplifyVertex(dSimplify)) {
// std::cout << "erase some darts 1" << std::endl;
// // subdividedDarts.erase(it);
// map.next(dSimplify);
// return;
// }
// else {
if(agentvect[map.phi2(dSimplify)].size()==0) {
if(simplifyEdge(dSimplify)) {
std::cout << "erase some darts 2" << std::endl;
// subdividedDarts.erase(it);
// dSimplify = dNext;
map.next(dSimplify);
return;
}
else if(simplifiable(dSimplify)) {
std::cout << "erase some darts 3" << std::endl;
map.mergeFaces(dSimplify);
// subdividedDarts.erase(it);
// dSimplify = dNext;
map.next(dSimplify);
return;
}
}
// }
}
// d=map.phi1(d);
// }while(d!=*it);
map.next(dSimplify);
// dSimplify = dNext;
if(dSimplify==map.end()) {
dSimplify = map.begin();
}
}
// std::cout << "say what ?" << std::endl;
}
bool EnvMap::checkForSubdivision(Dart d)
{
if(agentvect[d].size() > 10) {
// if(map.phi<1111>(d)==d) {
// if(!closeMark.isMarked(d) && subdivideSquare(d)) {
// // map.check();
// // std::cout << "subdivided square" << std::endl;
// for(PFP::AGENTS::iterator it = agentvect[d].begin() ;it != agentvect[d].end() ; ++it ) {
// resetAgentInFace(*it,d);
// Dart dd = map.phi2(map.phi1(d));
// Dart ddd=dd;
// do {
// // std::cout << "push 4 times" << std::endl;
// pushAgentInCell(*it,ddd,(*it)->includingFaces);
// ddd = map.alpha1(ddd);
// } while(dd!=map.alpha1(ddd));
// }
// // std::cout << "ok" << std::endl;
// return true;
// }
// }
// else
// {
Dart dd=d;
bool found=false;
do {
if(Geom::testOrientation2D<PFP::VEC3>(position[map.phi_1(dd)],position[dd],position[map.phi1(dd)])==Geom::ALIGNED && (position[map.phi1(dd)][0]!= position[dd][0] || position[map.phi1(dd)][1]!= position[dd][1]))
found = true;
else
dd = map.phi1(dd);
} while(!found && dd!=d);
if(found && subdivideFace(dd)) {
// map.check();
// if(found && !map.faceIsSubdivided(d)) {
// Algo::IHM::subdivideFace<PFP>(map,d,position);
// std::cout << "replace agents : " << agentvect[dd].size() << std::endl;
for(PFP::AGENTS::iterator it = agentvect[dd].begin() ;it != agentvect[dd].end() ; ++it ) {
// std::cout << "agent " << (*it)->agentNo_ << std::endl;
resetAgentInFace(*it);
pushAgentInCell(*it,map.alpha1(dd));
}
return true;
}
// }
}
return false;
}
bool EnvMap::subdivideSquare(Dart d)
{
std::cout << "subdivide square" << std::endl;
VEC3 c;
Dart dd=d;
do {
VEC3 mid(position[dd]+position[map.phi1(dd)]);
mid *= 0.5f;
map.cutEdge(dd);
if(closeMark.isMarked(map.phi2(dd)))
closeMark.mark(map.phi2(map.phi1(dd)));
position[map.phi1(dd)] = mid;
c +=mid;
dd = map.phi1(map.phi1(dd));
} while(dd!=d);
c *= 0.25f;
position[Algo::Modelisation::quadranguleFace<PFP>(map,dd)] = c;
return true;
}
bool EnvMap::subdivideFace(Dart d)
{
int coordChg = 0;
int phiCount=0;
// std::cout << "start " << std::endl;
VEC3 posD = position[d];
if(posD[1]!=position[map.phi1(d)][1])
coordChg = 1;
if(fabs(position[map.phi1(d)][coordChg]-posD[coordChg])<sideSize)
return false;
Dart dd=d;
do {
dd=map.phi1(dd);
phiCount++;
// std::cout << " -pos dd " << position[dd] << std::endl;
} while(position[map.phi1(dd)][coordChg]!=position[dd][coordChg]);
coordChg = (coordChg+1)%2;
while(position[map.phi1(dd)][coordChg]!=position[dd][coordChg]) {
dd=map.phi1(dd);
// std::cout << " +pos dd " << position[dd] << std::endl;
}
coordChg = (coordChg+1)%2;
do {
dd=map.phi1(dd);
// std::cout << " *pos dd " << position[dd] << std::endl;
} while(dd!=d && posD[coordChg]!=position[dd][coordChg]);
// std::cout << "phiCount " << phiCount << std::endl;
coordChg = (coordChg+1)%2;
if(d!=dd && Geom::testOrientation2D<PFP::VEC3>(position[map.phi_1(dd)],position[dd],position[map.phi1(dd)])==Geom::ALIGNED) {
// std::cout << " pos d " << position[d] << " dd " << position[dd] << std::endl;
// std::cout << " d " << d << " dd " << dd << std::endl;
// std::cout << " coord " << coordChg << std::endl;
map.splitFace(d,dd);
int nbCut = (position[d][coordChg]-position[dd][coordChg])/sideSize;
if(nbCut>0)
nbCut--;
else
nbCut++;
while(abs(nbCut)>0) {
map.cutEdge(map.phi_1(d));
position[map.phi_1(d)] = position[d];
position[map.phi_1(d)][coordChg] -= nbCut*this->sideSize;
// std::cout << " cutEdge : " << position[map.phi_1(d)] << std::endl;
if(nbCut>0)
nbCut--;
else
nbCut++;
}
return true;
else
itF = filledFaces.erase(itF);
}
return false;
}
VEC3 EnvMap::faceCenter(Dart d)
{
VEC3 center(0,0,0);
unsigned int count = 0 ;
Dart it = d ;
do
{
center += position[it];
++count ;
// while(map.phi1(it)!=d && Geom::testOrientation2D<PFP::VEC3>(position[map.phi1(d)],position[d],position[map.phi1(map.phi1(d))])==Geom::ALIGNED)
// it=map.phi1(it);
it = map.phi1(it) ;
} while(it != d) ;
// if(count<4) {
// std::cout << "??????" << count << std::endl;
// }
center /= double(count);
return center ;
}
void EnvMap::resetAgentInFace(Agent * agent)
......@@ -659,7 +360,6 @@ void EnvMap::resetAgentInFace(Agent * agent)
agent->part->m_position = Algo::Geometry::faceCentroid<PFP>(map,agent->part->d,position);
agent->part->state = FACE_ORBIT;
agent->part->move(agent->position_) ;
// agent->part->d = d;
}
void EnvMap::addObstacle(std::vector<VEC3> points)
......@@ -667,7 +367,6 @@ void EnvMap::addObstacle(std::vector<VEC3> points)
std::cout << "test" << std::endl;
std::vector<VEC3>::iterator it = points.begin();
VEC3 p1 = *it;
// std::cout << "p1 " << p1 << std::endl;
it++;
VEC3 p2;
Dart d = getBelongingCell(p1);
......
......@@ -287,7 +287,7 @@ void Simulator::setupScenario()
while(!found && d != envMap.map.end()) {
VEC3 n = Algo::Geometry::triangleNormal<PFP>(envMap.map,d,envMap.position);
if(!envMap.closeMark.isMarked(d) && !filled.isMarked(d) && envMap.position[d][2]==0.0f && n[2]==1.0f) {
pos = envMap.faceCenter(d);
pos = Algo::Geometry::faceCentroid<PFP>(envMap.map,d,envMap.position);
dCell=d;
found = true;
filled.markOrbit(FACE_ORBIT,d);
......@@ -353,7 +353,7 @@ void Simulator::setupHelicoidScenario(float rMax,float rMin)
Dart dCell;
while(!found && d != envMap.map.end()) {
if(!envMap.closeMark.isMarked(d) && !filled.isMarked(d)) {
pos = envMap.faceCenter(d);
pos = Algo::Geometry::faceCentroid<PFP>(envMap.map,d,envMap.position);
if(i==nbPack/2)
std::cout << "pos " << pos << std::endl;
pos[2]=0.0f;
......
......@@ -112,7 +112,6 @@ void ParticleCell2D<PFP>::vertexState(const VEC3& current)
//displacement step
// if(!obstacle.isMarked(d)) {
if(getOrientationEdge(current,d)==Geom::ALIGNED && Algo::Geometry::isPointOnHalfEdge<PFP>(m,d,m_positions,current)) {
std::cout << m.vertexDegree(d) << std::endl;
edgeState(current);
}
else {
......
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