Commit 6a8e9fff authored by Pierre Kraemer's avatar Pierre Kraemer

bientot la simplif remarche !

parent fe22bd55
......@@ -90,14 +90,12 @@ public :
CellMarker buildingMark;
static const unsigned int nbAgentsToSubdivide = 7;
static const unsigned int nbAgentsToSimplify = 7;
// std::map<unsigned int, Dart> refineCandidate;
// std::map<unsigned int, Dart> coarsenCandidate;
static const unsigned int nbAgentsToSimplify = 5;
CellMarker refineMark;
std::vector<Dart> refineCandidate;
// std::vector<Dart> coarsenCandidate;
CellMarker coarsenMark;
std::vector<Dart> coarsenCandidate;
};
/**************************************
......@@ -128,10 +126,10 @@ 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());
bool found = false;
PFP::AGENTS& a = agentvect[d];
PFP::AGENTS::iterator end = a.end();
bool found = false;
for(PFP::AGENTS::iterator it = a.begin(); it != end && !found; ++it)
{
if(*it == agent)
......@@ -169,7 +167,7 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::clearUpdateCandidates()
{
refineCandidate.clear();
// coarsenCandidate.clear();
coarsenCandidate.clear();
}
#endif
......@@ -9,7 +9,11 @@
using namespace CGoGN;
EnvMap::EnvMap() : obstacleMark(map, EDGE_CELL), buildingMark(map, FACE_CELL), refineMark(map, FACE_CELL)
EnvMap::EnvMap() :
obstacleMark(map, EDGE_CELL),
buildingMark(map, FACE_CELL),
refineMark(map, FACE_CELL),
coarsenMark(map, FACE_CELL)
{
position = map.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
normal = map.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal");
......@@ -29,10 +33,11 @@ unsigned int EnvMap::mapMemoryCost()
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
CellMarkerStore m(map,FACE_ORBIT);
CellMarkerStore m(map, FACE_ORBIT);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!m.isMarked(d)) {
if(!m.isMarked(d))
{
m.mark(d);
if(!buildingMark.isMarked(d) && Algo::Geometry::isPointInConvexFace2D<PFP>(map, d, position, pos, true))
return d;
......@@ -46,7 +51,7 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 25;
unsigned int nbSquares = 5;
CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
......@@ -108,9 +113,8 @@ void EnvMap::registerObstaclesInFaces()
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(m.isMarked(d) && !buildingMark.isMarked(d)) {
if(m.isMarked(d) && !buildingMark.isMarked(d))
m.unmark(d);
}
}
}
......@@ -218,12 +222,21 @@ void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
Dart newFace = agent->part_.d;
if(!map.isDartValid(oldFace))
std::cout << "agentChangeFace : oldFace INVALID" << std::endl ;
if(!map.isDartValid(newFace))
std::cout << "agentChangeFace : newFace INVALID" << std::endl ;
popAgentInCells(agent, oldFace);
pushAgentInCells(agent, newFace);
// coarsenCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(FACE_ORBIT, oldFace), oldFace));
if(!coarsenMark.isMarked(oldFace) && agentvect[oldFace].size() < nbAgentsToSimplify)
{
coarsenMark.mark(oldFace);
coarsenCandidate.push_back(oldFace);
}
if(!refineMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
if(!refineMark.isMarked(newFace) && !coarsenMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
{
std::pair<bool,bool>& sf = subdivisableFace[newFace];
if(sf.first == false || (sf.first == true && sf.second))
......@@ -241,6 +254,10 @@ void EnvMap::updateMap()
for(std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
{
Dart d = (*it) ;
if(!map.isDartValid(d))
{
std::cout << "refine INVALID" << std::endl ;
}
refineMark.unmark(d);
if(agentvect[d].size() > nbAgentsToSubdivide)
......@@ -267,7 +284,7 @@ void EnvMap::updateMap()
PFP::VEC3 edge = Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
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)
// if(Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position).norm2() < maxEdgeSize)
{
subdivisable = false ;
break ;
......@@ -355,11 +372,16 @@ void EnvMap::updateMap()
}
}
}
/*
for(std::map<unsigned int, Dart>::iterator it = coarsenCandidate.begin(); it != coarsenCandidate.end(); ++it)
for(std::vector<Dart>::iterator it = coarsenCandidate.begin(); it != coarsenCandidate.end(); ++it)
{
unsigned int face = (*it).first ;
Dart d = (*it).second ;
Dart d = (*it) ;
if(!map.isDartValid(d))
{
std::cout << "coarsen INVALID" << std::endl ;
continue ;
}
coarsenMark.unmark(d) ;
unsigned int fLevel = map.faceLevel(d) ;
Dart old = map.faceOldestDart(d) ;
......@@ -395,14 +417,22 @@ void EnvMap::updateMap()
do
{
map.setCurrentLevel(fLevel) ;
unsigned int fEmb = map.getEmbedding(fit, FACE_ORBIT) ;
if(fEmb != face)
coarsenCandidate.erase(fEmb) ;
coarsenMark.unmark(fit) ;
for(std::vector<Dart>::iterator r = it + 1; r != coarsenCandidate.end(); ++r)
{
if(*r == fit)
{
std::vector<Dart>::iterator last = coarsenCandidate.end() ;
--last ;
std::swap(last, r) ;
coarsenCandidate.pop_back() ;
}
}
PFP::AGENTS a(agentvect[fit]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
map.setCurrentLevel(map.getMaxLevel()) ;
for(PFP::AGENTS::iterator it = a.begin(); it != a.end(); ++it)
popAgentInCells(*it, fit);
for(PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
popAgentInCells(*ait, fit);
map.setCurrentLevel(fLevel - 1) ;
Dart nf = map.phi2(fit) ;
if(!map.faceIsSubdivided(nf))
......@@ -411,8 +441,8 @@ void EnvMap::updateMap()
PFP::AGENTS& an = agentvect[nf] ;
for(PFP::AGENTS::iterator ait = an.begin(); ait != an.end(); ++ait)
{
if((*ait)->part_.d == nf)
(*ait)->part_.d = map.phi1(nf) ;
if((*ait)->part_.d == map.phi1(nf))
(*ait)->part_.d = nf ;
}
map.setCurrentLevel(fLevel - 1) ;
}
......@@ -422,20 +452,30 @@ void EnvMap::updateMap()
{
map.setCurrentLevel(fLevel) ;
Dart centerFace = map.phi2(map.phi1(old)) ;
unsigned int fEmb = map.getEmbedding(centerFace, FACE_ORBIT) ;
if(fEmb != face)
coarsenCandidate.erase(fEmb) ;
coarsenMark.unmark(centerFace) ;
for(std::vector<Dart>::iterator r = it + 1; r != coarsenCandidate.end(); ++r)
{
if(*r == centerFace)
{
std::vector<Dart>::iterator last = coarsenCandidate.end() ;
--last ;
std::swap(last, r) ;
coarsenCandidate.pop_back() ;
}
}
PFP::AGENTS a(agentvect[centerFace]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
map.setCurrentLevel(map.getMaxLevel());
for(PFP::AGENTS::iterator it = a.begin(); it != a.end(); ++it)
popAgentInCells(*it, centerFace);
for(PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
popAgentInCells(*ait, centerFace);
map.setCurrentLevel(fLevel - 1) ;
}
Algo::IHM::coarsenFace<PFP>(map, old, position) ;
// gestion des obstacles !!
std::pair<bool,bool>& sf = subdivisableFace[old] ;
sf.first = true;
sf.second = true;
map.setCurrentLevel(map.getMaxLevel());
......@@ -457,12 +497,13 @@ void EnvMap::updateMap()
}
dd = map.phi1(dd);
} while(dd != old);
}
}
map.setCurrentLevel(cur) ;
}
}
*/
map.setCurrentLevel(map.getMaxLevel()) ;
}
......
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