Commit 2a8274e6 authored by Thomas Pitiot 's avatar Thomas Pitiot

ajouts optim pour particules

parent d69e3ee7
......@@ -2,7 +2,7 @@
#define ENV_MAP_H
#define DEBUG_affichage
//#define DEBUG_affichage
//#define DEBUG
#include <iostream>
......@@ -73,13 +73,14 @@ public:
VertexAttribute<VEC3, MAP> position ;
FaceAttribute<VEC3, MAP> facecenter;
VolumeAttribute<VEC3, MAP> color ;
VolumeAttribute<VEC3, MAP> volumecenter;
VolumeAttribute<ARETES, MAP> RegisteredEdges ;
VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
VolumeAttribute<TRIANGLES, MAP> RegisteredTriangles ;
VolumeAttribute<TRIANGLES, MAP> RegisteredNeighborTriangles ;
Geom::BoundingBox<PFP::VEC3> bb;
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, unsigned int state);
void FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
......@@ -94,7 +95,7 @@ public:
void pushSegmentInCellAsNeighbor(Segment* o, Dart d);
void popSegmentInCellAsNeighbor(Segment* o, Dart d);
void resetPartSubdiv(Segment* o);
void resetPartSubdiv(Segment* o, int vLevelOld);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Enregistrement Surfaces
......@@ -107,7 +108,7 @@ public:
void popTriangleInCell(Triangle* o, Dart d);
void pushTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void popTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void resetPartSubdiv(Triangle* cell);
void resetPartSubdiv(Triangle* cell, int vLevelOld);
} ;
......@@ -152,10 +153,12 @@ inline bool removeElementFromVector(std::vector<T>& a, T ag)
/////////////////////////////////////////////////////////////////////REGISTRATIONS
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1 , unsigned int state)
{
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticleCell3DMemo;
return ParticleCell3DMemo(map, d1, pos,position).move(dest);
ParticleCell3DMemo part(map, d1, pos,position,&facecenter,&volumecenter);
part.setState(state);
return part.move(dest);
}
......
......@@ -37,12 +37,22 @@ public:
{
return parts_[index];
}
inline Particule* getParticule(int index)
{
return parts_[index];
}
inline const int& getNeedForSubd(int index) const
{
return partNeedReset[index];
}
inline const int& getNeedForSubd(int index)
{
return partNeedReset[index];
}
inline void setNeedForSubd(int index, int b)
{
partNeedReset[index]=b;
}
inline int getIndexOfParticuleAtVertex(Dart d) const
{
return indexParticule[d];
......@@ -86,7 +96,7 @@ public:
REAL faceMaxdistance(Face face); //calcul du rayon max d'une face
bool subdiveMap(); //subdivision de la map
void initOperators(SubdivisionType st); // fonction de sélection du type de subdivision pour l'ihm2
void needResetTriangle(Triangle * o);
void addGeneralCell ( Dart d);
bool removeGeneralCell (Dart d);
......@@ -120,6 +130,7 @@ private:
unsigned int nbTriangles;
std::vector<Particule*> parts_ ;
std::vector<int>partNeedReset;
std::vector<Triangle *> triangles_;
Algo::Render::GL2::MapRender* m_render_map; // render de l'objet
......
......@@ -48,6 +48,7 @@ void EnvMap::init(int argc, char **argv)
///// initialisation attributs
position = map.addAttribute<VEC3, VERTEX, MAP>("position");
facecenter = map.addAttribute<VEC3, FACE, MAP>("facecenter");
volumecenter=map.addAttribute<VEC3, VOLUME, MAP>("volumecenter");
color = map.addAttribute<VEC3, VOLUME, MAP>("color");
RegisteredEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredEdges");
RegisteredNeighborEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredNeighborEdges");
......@@ -85,6 +86,7 @@ void EnvMap::init(int argc, char **argv)
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{
color[d] = position[d]/10 + VEC3(0.5,0.5,0.5);
volumecenter[d]=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3, MAP>>(map,d,position);
}
......@@ -282,7 +284,7 @@ void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en
std::vector<Dart> memo;
memo = getMemoCross(p1,p2,d1);
memo = getMemoCross(p1,p2,d1,mo->getParticule(n1)->getState());
if(memo.size() == 1u)
{
......@@ -427,7 +429,7 @@ void EnvMap::FirstRegistrationTriangle(Triangle * o)// réenregistre l'Triangle
if (mo != NULL)
{
#ifdef DEBUG_affichage
CGoGNout<<"First Registration Triangle "<<o->cell<<CGoGNendl;
CGoGNout<<"First Registration Triangle "<<o->indexTri<<CGoGNendl;
#endif
CellMarkerMemo<MAP, VOLUME> inside(map);
CellMarkerMemo<MAP, VOLUME> neighbor(map);
......@@ -442,8 +444,12 @@ void EnvMap::FirstRegistrationTriangle(Triangle * o)// réenregistre l'Triangle
const Particule * p1 = mo->getParticule(mo->getIndexOfParticuleAtVertex(cell));
Dart d1=p1->getCell(); // darts de la carte 3D contenant les particules
memo = getMemoCross(p1->getPosition(),mo->getSurfacePosition(cell2),d1);
#ifdef DEBUG_affichage
CGoGNout<<"Calcul memo_cross pour l'edge (p1,p2,d1,state) "<<p1->getPosition()<<" || "<<mo->getSurfacePosition(cell2)<<" || "<<d1<<" || "<<p1->getState()<<CGoGNendl;
#endif
memo = getMemoCross(p1->getPosition(),mo->getSurfacePosition(cell2),d1,p1->getState());
for (Dart d : memo)
inside.mark(d);
......@@ -632,6 +638,7 @@ bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
for (Triangle * o : oldTrian)
{
this->popTriangle(o) ;
o->surf->needResetTriangle(o);
}
TRIANGLES oldTrianNeighbor(RegisteredNeighborTriangles[old]) ;
......@@ -703,7 +710,8 @@ bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
facecenter[f]=Algo::Surface::Geometry::faceCentroid<PFP, VertexAttribute<VEC3, MAP>>(map,f,position);
}
VEC3 center=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d,position);
volumecenter[d]=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d,position);
VEC3 center=volumecenter[d];
color[d] = VEC3((center[0]-mapMinX)/(mapMaxX-mapMinX),(center[1]-mapMinY)/(mapMaxY-mapMinY),(center[2]-mapMinZ)/(mapMaxZ-mapMinZ));
......@@ -737,35 +745,23 @@ bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
// //same for adjacent triangles // optimiser
// for (Triangle * o : oldTrianNeighbor)
// {
//// this->FirstRegistrationTriangle(o) ; // old version
// }
//same for triangles // optimiser
//same for triangles //
for (Triangle * o : oldTrian)
{
resetPartSubdiv(o);
resetPartSubdiv(o,vLevel);
this->FirstRegistrationTriangle(o) ;
}
const std::chrono::time_point<std::chrono::system_clock> endPushTriangle = std::chrono::system_clock::now();
// //same for adjacent obstacles // optimiser
// for (Segment * o : oldNeighborObst)
// {
//// FirstRegistrationSegment(o) ; // old version
// }
const std::chrono::time_point<std::chrono::system_clock> endPushSegmentNeighbors = std::chrono::system_clock::now();
//same for obstacles contained
for (Segment * o : oldobst)
{
resetPartSubdiv(o);
resetPartSubdiv(o,vLevel);
FirstRegistrationSegment(o);
}
......@@ -784,7 +780,7 @@ bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
}
void EnvMap::resetPartSubdiv(Segment* o)
void EnvMap::resetPartSubdiv(Segment* o, int vLevelOld)
{
ArticulatedObject * mo = o->nid;
......@@ -803,45 +799,52 @@ void EnvMap::resetPartSubdiv(Segment* o)
#endif
mo->getParticule(o->indexPart1)->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
mo->getParticule(o->indexPart1)->reset_positionFace();
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved to centroid ,d : "<< mo->getParticule(o->indexPart1)->getPosition()<<" || "<<mo->parts_[o->indexPart1]->getCell()<<CGoGNendl;
mo->getParticule(o->indexPart1)->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
mo->getParticule(o->indexPart1)->reset_positionFace();
mo->getParticule(o->indexPart1)->reset_positionVolume();
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved to centroid ,d : "<< mo->getParticule(o->indexPart1)->getPosition()<<" || "<<mo->parts_[o->indexPart1]->getCell()<<CGoGNendl;
#endif
mo->getParticule(o->indexPart1)->setState(VOLUME) ;
mo->getParticule(o->indexPart1)->move(pos) ;
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved in the end (destination, arrivée,d) : "<<pos<<" || "<< mo->getParticule(o->indexPart1)->getPosition()<<" || "<<mo->parts_[o->indexPart1]->getCell()<<CGoGNendl;
#endif
mo->getParticule(o->indexPart1)->setState(VOLUME) ;
mo->getParticule(o->indexPart1)->move(pos) ;
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved in the end (destination, arrivée,d,state) : "<<pos<<" || "<< mo->getParticule(o->indexPart1)->getPosition()<<" || "<<mo->parts_[o->indexPart1]->getCell()<<" || "<<mo->parts_[o->indexPart1]->getState()<<CGoGNendl;
#endif
mo->getParticule(o->indexPart2)->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
mo->getParticule(o->indexPart2)->reset_positionFace();
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved to centroid ,d : "<< mo->getParticule(o->indexPart2)->getPosition()<<" || "<<mo->parts_[o->indexPart2]->getCell()<<CGoGNendl;
#endif
#endif
mo->getParticule(o->indexPart2)->setState(VOLUME) ;
mo->getParticule(o->indexPart2)->move(pos2) ;
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved in the end (destination, arrivée,d) : "<<pos2<<" || "<< mo->getParticule(o->indexPart2)->getPosition()<<" || "<<mo->parts_[o->indexPart2]->getCell()<<CGoGNendl;
mo->getParticule(o->indexPart2)->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
mo->getParticule(o->indexPart2)->reset_positionFace();
mo->getParticule(o->indexPart2)->reset_positionVolume();
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved to centroid ,d : "<< mo->getParticule(o->indexPart2)->getPosition()<<" || "<<mo->parts_[o->indexPart2]->getCell()<<CGoGNendl;
#endif
mo->getParticule(o->indexPart2)->setState(VOLUME) ;
mo->getParticule(o->indexPart2)->move(pos2) ;
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved in the end (destination, arrivée,d,state) : "<<pos2<<" || "<< mo->getParticule(o->indexPart2)->getPosition()<<" || "<<mo->parts_[o->indexPart2]->getCell()<<" || "<<mo->parts_[o->indexPart2]->getState()<<CGoGNendl;
#endif
#endif
}
}
void EnvMap::resetPartSubdiv(Triangle * o)
void EnvMap::resetPartSubdiv(Triangle * o, int vLevelOld)
{
Surface * mo = o->surf;
Dart cell =o->cell;
Dart cell2 = mo->getSurfaceMap().phi1(cell);
Dart cell3 = mo->getSurfaceMap().phi1(cell2);
Particule * p = mo->getParticule(mo->getIndexOfParticuleAtVertex(cell));
Particule * p2 = mo->getParticule(mo->getIndexOfParticuleAtVertex(cell2));
Particule * p3 = mo->getParticule(mo->getIndexOfParticuleAtVertex(cell3));
int indPart=mo->getIndexOfParticuleAtVertex(cell);
int indPart2=mo->getIndexOfParticuleAtVertex(cell2);
int indPart3=mo->getIndexOfParticuleAtVertex(cell3);
Particule * p = mo->getParticule(indPart);
Particule * p2 = mo->getParticule(indPart2);
Particule * p3 = mo->getParticule(indPart3);
if (mo != NULL)
{
......@@ -858,9 +861,11 @@ void EnvMap::resetPartSubdiv(Triangle * o)
CGoGNout<<"Faces centroids : "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d3,position)<<CGoGNendl;
#endif
if(mo->getNeedForSubd(indPart))
{
p->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
p->reset_positionFace(); // attention avec les particules 3D on doit mettre a jour la position_face !!!
p->reset_positionVolume();
#ifdef DEBUG_affichage
CGoGNout<<"on a reset face part1 moved to centroid ,d : "<< p->getPosition()<<" || "<<p->getCell()<<CGoGNendl;
......@@ -868,11 +873,16 @@ void EnvMap::resetPartSubdiv(Triangle * o)
p->setState(VOLUME) ;
p->move(pos) ;
#ifdef DEBUG_affichage
CGoGNout<<"part1 moved in the end (destination, arrivée,d) : "<<pos<<" || "<< p->getPosition()<<" || "<<p->getCell()<<CGoGNendl;
CGoGNout<<"part1 moved in the end (destination, arrivée,d,state) : "<<pos<<" || "<< p->getPosition()<<" || "<<p->getCell()<<" || "<<p->getState()<<CGoGNendl;
#endif
mo->setNeedForSubd(indPart,0);
}
if(mo->getNeedForSubd(indPart2))
{
p2->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
p2->reset_positionFace();
p2->reset_positionVolume();
#ifdef DEBUG_affichage
CGoGNout<<"on a reset face part2 moved to centroid ,d : "<< p2->getPosition()<<" || "<<p2->getCell()<<CGoGNendl;
......@@ -880,12 +890,16 @@ void EnvMap::resetPartSubdiv(Triangle * o)
p2->setState(VOLUME) ;
p2->move(pos2) ;
#ifdef DEBUG_affichage
CGoGNout<<"part2 moved in the end (destination, arrivée,d) : "<<pos2<<" || "<< p2->getPosition()<<" || "<<p2->getCell()<<CGoGNendl;
CGoGNout<<"part2 moved in the end (destination, arrivée,d,state) : "<<pos2<<" || "<< p2->getPosition()<<" || "<<p2->getCell()<<" || "<<p2->getState()<<CGoGNendl;
#endif
mo->setNeedForSubd(indPart2,0);
}
if(mo->getNeedForSubd(indPart3))
{
p3->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d3,position)) ;
p3->reset_positionFace();
p3->reset_positionVolume();
#ifdef DEBUG_affichage
CGoGNout<<"on a reset face part3 moved to centroid ,d : "<< p3->getPosition()<<" || "<<p3->getCell()<<CGoGNendl;
......@@ -893,9 +907,11 @@ void EnvMap::resetPartSubdiv(Triangle * o)
p3->setState(VOLUME) ;
p3->move(pos3) ;
#ifdef DEBUG_affichage
CGoGNout<<"part3 moved in the end (destination, arrivée,d) : "<<pos3<<" || "<< p3->getPosition()<<" || "<<p3->getCell()<<CGoGNendl;
CGoGNout<<"part3 moved in the end (destination, arrivée,d,state) : "<<pos3<<" || "<< p3->getPosition()<<" || "<<p3->getCell()<<" || "<<p3->getState()<<CGoGNendl;
#endif
mo->setNeedForSubd(indPart3,0);
}
}
......
......@@ -19,7 +19,7 @@ Knife::Knife(Simulator* sim,std::vector<std::pair<VEC3, Dart>> startingPoints)
for (auto it =startingPoints.begin();it!=startingPoints.end();++it)
{
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, (*it).second, (*it).first , sim_->envMap_.position));
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, (*it).second, (*it).first , sim_->envMap_.position, &(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
}
......
......@@ -22,7 +22,7 @@ Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
index_articulated=sim->objects.size();
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, startingPoint.second, startingPoint.first , sim_->envMap_.position));
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, startingPoint.second, startingPoint.first , sim_->envMap_.position, &(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
this->color_close();
......@@ -110,7 +110,7 @@ void Needle::unColor_close(Dart volume)
void Needle::createEdge(int index)
{
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, this->getParticule(0)->getCell(), getParticule(0)->getPosition() , sim_->envMap_.position));
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, this->getParticule(0)->getCell(), getParticule(0)->getPosition() , sim_->envMap_.position,&(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
Segment* o = new Segment(getParticule(index+1)->getPosition(),
getParticule(0)->getPosition(),
......@@ -141,6 +141,7 @@ void Needle::move(VEC3 diff)
{
if(!sim_->envMap_.checkPointInMap(pos,this->getParticule(0)->getCell()))
{
CGoGNout<<"pos not in map :"<<pos<< " || d: "<<this->getParticule(0)->getCell()<<CGoGNendl;
pos=pos-diff;
}
}
......@@ -205,7 +206,7 @@ void Needle::refine()
{
if(sim_->envMap_.subdivideVolume(volume))
{
// refine();
refine();
}
}
......
......@@ -42,7 +42,7 @@ void Simulator::doStep()
void Simulator::initSurfaces()
{
Surface * obj = new Surface(this,VEC3(-1.0f,-1.5f,0.0f));
Surface * obj = new Surface(this,VEC3(-2.0f,0.0f,0.0f));
CGoGNout<<"surface initialisée : "<<obj->index_surface<<CGoGNendl;
}
......
......@@ -35,8 +35,9 @@ Surface::Surface(Simulator* sim,VEC3 offset):
{
positionSurface[d]+=offset;
indexParticule[d]=nbVertices;
parts_.push_back(new Particule(sim_->envMap_.map, sim_->envMap_.getBelongingCell(positionSurface[d]), positionSurface[d] , sim_->envMap_.position));
parts_.push_back(new Particule(sim_->envMap_.map, sim_->envMap_.getBelongingCell(positionSurface[d]), positionSurface[d] , sim_->envMap_.position,&(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
nbVertices ++;
partNeedReset.push_back(0);
}
// initialisation tableaux de vecteurs qui vont stocker les belonging cells
TraversorE<SurfaceMap> tF2(surfaceMap);
......@@ -375,5 +376,13 @@ bool Surface::removeGeneralNeighbor (Dart d)
return false;
}
void Surface::needResetTriangle(Triangle * o)
{
Dart d =o->cell;
for(int i=0;i<3;i++)
{
partNeedReset[indexParticule[d]]=1;
d=surfaceMap.phi1(d);
}
}
......@@ -20,7 +20,7 @@ Tree::Tree(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints, st
for (auto it =startingPoints.begin();it!=startingPoints.end();++it)
{
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, (*it).second, (*it).first , sim_->envMap_.position));
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, (*it).second, (*it).first , sim_->envMap_.position, &(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
}
......
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