Commit 5fbd799d authored by pitiot's avatar pitiot

résolu 2D

parent ed23a69b
......@@ -34,7 +34,7 @@ class ArticulatedObstacle;
//#define EXPORTING3
//#define TWO_AND_HALF_DIM
#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
......
......@@ -7,11 +7,16 @@
#include "env_map.h"
#include <set>
// #define SECURED
#ifdef TWO_AND_HALF_DIM
#include "Algo/MovingObjects/particle_cell_2DandHalf_memo.h"
#else
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
#else
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#endif
#endif
#define EXPORTING_BOXES
......@@ -147,7 +152,7 @@ public:
bool rigid_;
bool spinning;
ArticulatedObstacle * parent;
float hight;
float height;
MovingMesh* mm_;
Agent* ag_;
int index_parent;
......
......@@ -146,25 +146,18 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
if(dInside==NIL)
dInside = sim_->envMap_.getBelongingCell(pos[0]);
unsigned int nbParticles = nbVertices;
if(!rigid);
nbParticles +=1; //a center particle for the mass-spring
#ifdef TWO_AND_HALF_DIM
if(!rigid_)
{
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>*[nbVertices+1];
}
else
{
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>*[nbVertices];
}
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>*[nbParticles];
#else
if(!rigid_)
{
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>*[nbVertices+1];
}
else
{
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>*[nbVertices];
}
#ifdef SECURED
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DSecured<PFP>*[nbParticles];
#else
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>*[nbParticles];
#endif
#endif
obstacles_ = new Obstacle*[nbVertices];
......@@ -186,46 +179,47 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
for (unsigned int i = 0; i < nbVertices; ++i)
{
#ifdef TWO_AND_HALF_DIM
Dart d = dInside;/*sim_->envMap_.getBelongingCellOnSurface(pos[i]); TO CHECK*/
// CGoGNout<<" d trouvée :"<< d <<CGoGNendl;
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
Dart d = dInside;
parts_[i] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
#else
Dart d = sim_->envMap_.getBelongingCell(pos[i]);
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
#ifdef SECURED
parts_[i] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DSecured<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
#else
parts_[i] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
#endif
#endif
parts_[i] = part;
center += pos[i];
if(i==0)
dDir = d;
}
center /= nbVertices;
front=(pos[0] + pos[1]) / 2;
center /= nbVertices;
front=(pos[0] + pos[1]) / 2;
if(!rigid_)
{
#ifdef TWO_AND_HALF_DIM
if(!rigid_)
{
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>(sim_->envMap_.map, dInside, center, sim_->envMap_.position);
parts_[nbVertices]=part;
}
parts_[nbVertices] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>(sim_->envMap_.map, dInside, center, sim_->envMap_.position);
#else
if(!rigid_)
{
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, dInside, center, sim_->envMap_.position);
parts_[nbVertices]=part;
}
#ifdef SECURED
parts_[nbVertices] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DSecured<PFP>(sim_->envMap_.map, dInside, center, sim_->envMap_.position);
#else
parts_[nbVertices] = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, dInside, center, sim_->envMap_.position);
#endif
#endif
}
// M appartient à l'ellipse ssi MF1 + MF2 = sum_dist_foci est une constante
// où F1 et F2 sont les deux foyers.
// length = (pos[0]-pos[1]).norm();
// width = (pos[1]-pos[2]).norm();
// sum_dist_foci_rest = 2*(length + width*(sqrt(2)-0.5));
if ( parent==NULL) //départ face à la cible en cas d'obstacles pouvant effectuer des rotations
{
if ( parent==NULL) //départ face à la cible en cas d'obstacles pouvant effectuer des rotations
{
// VEC3 axeZ=VEC3 (0,0,1);
//#ifdef TWO_AND_HALF_DIM
//
......@@ -260,7 +254,7 @@ if(!rigid_)
// }
// angle=0;
// front=(pos[0] + pos[1]) / 2;
}
}
groundFace = map.newFace(nbVertices);
......@@ -280,24 +274,16 @@ if(!rigid_)
velocity[d] = VEC3(0);
forces[d] = VEC3(0);
}
}
//extrude face to build a cage
// compute edgeLength for mass-spring
hight=rigid_ ? 10.0f : -10.0f;
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, hight) ;
// Dart dT = map.phi1(map.phi1(map.phi2(Dart(0))));
// std::cout << __FUNCTION__ << " val " << dT << std::endl;
// position[dT]= VEC3(0);
// std::cout << __FUNCTION__ << " pos " << position[dT] << std::endl;
// Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, 0.0f) ;
height=rigid_ ? 10.0f : 10.0f;
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, height) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
if(!rigid_)
{
Dart d = Algo::Surface::Modelisation::trianguleFace<PFP>(map,groundFace);
......@@ -891,9 +877,6 @@ void MovingObstacle::updateForces()
Dart d;
velocity_ = newVelocity_* velocity_factor;
// velocity_[0] = 0.0;
// velocity_[1] = 0.0;
// MAJ des particules
float abs_angle= angle > 0 ? 1 : -1;
......@@ -916,7 +899,6 @@ void MovingObstacle::updateForces()
Dart e = map.phi1(d);
//initialisation of forces with viscosity
forces[e] += -0.9f*velocity[e];
// forces[dd] = VEC3(0.0);
VEC3 p1Next = position[map.phi1(e)]+(velocity[map.phi1(e)] * sim_->timeStep_); // ressorts sur le bord
VEC3 p2Next = position[e]+(velocity[e] * sim_->timeStep_);
// p1Next et p2Next sont la position des extremites de l'arete.
......@@ -1178,96 +1160,74 @@ void MovingObstacle::applyForces()
velocity[e] += forces[e] * sim_->timeStep_;
position[e] += (velocity[e] * sim_->timeStep_);
d=map.phi<21>(d);
}
velocity[centerDart] +=forces[centerDart] * sim_->timeStep_;
position[centerDart] += (velocity[centerDart] * sim_->timeStep_);
// MAJ des obstacles
}
}
void MovingObstacle::updateRegistration()
{
PFP::VEC3 bary(0);
Dart centerDart =map.phi<11>(groundFace);
Dart centerDart =map.phi<11>(groundFace);
if(!rigid_)
if(!rigid_)
{
Dart d = centerDart;
for (unsigned int i = 0; i < nbVertices; ++i)
{
Dart d = centerDart;
for (unsigned int i = 0; i < nbVertices; ++i)
{
Dart e = map.phi_1(d);
Dart e = map.phi_1(d);
parts_[i]->move(position[e]);
#ifdef TWO_AND_HALF_DIM
parts_[i]->move(position[e]);
position[e] = parts_[i]->getPosition(); //recalage de l'obstacle sur ses particules (qui elles ont bien suivi la carte au sol)
#ifdef TWO_AND_HALF_DIM
PFP::VEC3 normal = CGoGN::Algo::Surface::Geometry::faceNormal<PFP>(sim_->envMap_.map, parts_[i]->d, sim_->envMap_.position);
normal *= hight;
// std::cout << " phi11 d : " << map.phi<112>(d) <<" || d : "<<d<< std::endl;
position[map.phi_1(map.phi<12>(d))] = position[e]+normal;
position[e] = parts_[i]->getPosition(); //recalage de l'obstacle sur ses particules (qui elles ont bien suivi la carte au sol)
#endif
PFP::VEC3 normal = CGoGN::Algo::Surface::Geometry::faceNormal<PFP>(sim_->envMap_.map, parts_[i]->d, sim_->envMap_.position);
normal *= height;
position[map.phi_1(map.phi<12>(d))] = position[e]+normal;
#endif
bary += position[e];
d=map.phi<21>(d);
}
bary += position[e];
d=map.phi<21>(d);
}
center = bary / nbVertices;
parts_[nbVertices]->move(position[centerDart]);
center = bary / nbVertices;
parts_[nbVertices]->move(position[centerDart]);
#ifdef TWO_AND_HALF_DIM
position[centerDart] = parts_[nbVertices]->getPosition(); //recalage de l'obstacle sur ses particules (qui elles ont bien suivi la carte au sol)
#endif
// MAJ des obstacles
}
}
else
{
for (unsigned int i = 0; i < nbVertices; ++i)
{
for (unsigned int i = 0; i < nbVertices; ++i)
{
VEC3 pos = getDilatedPosition(i);
parts_[i]->move(pos);
#ifdef TWO_AND_HALF_DIM
VEC3 pos = getDilatedPosition(i);
parts_[i]->move(pos);
Dart d(i);
#ifdef TWO_AND_HALF_DIM
position[d] = parts_[i]->getPosition(); //recalage de l'obstacle sur ses particules (qui elles ont bien suivi la carte au sol)
#endif
PFP::VEC3 normal = CGoGN::Algo::Surface::Geometry::faceNormal<PFP>(sim_->envMap_.map, parts_[i]->d, sim_->envMap_.position);
normal *= height;
position[map.phi_1(d)] = position[d]+normal;
Dart d(i);
position[d] = parts_[i]->getPosition(); //recalage de l'obstacle sur ses particules (qui elles ont bien suivi la carte au sol)
PFP::VEC3 normal = CGoGN::Algo::Surface::Geometry::faceNormal<PFP>(sim_->envMap_.map, parts_[i]->d, sim_->envMap_.position);
normal *= hight;
// std::cout << " phi11 d : " << map.phi<112>(d) <<" || d : "<<d<< std::endl;
position[map.phi_1(d)] = position[d]+normal;
#endif
}
}
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
// CGoGNout << "avant une etape : Obstacle "<< i << CGoGNendl;
{
// CGoGNout << "avant une etape : Obstacle "<< i << CGoGNendl;
Obstacle* o = obstacles_[i];
o->p1 = getDilatedPosition(i);
o->p2 = getDilatedPosition((i+1) % nbVertices);
......@@ -1285,7 +1245,7 @@ void MovingObstacle::updateRegistration()
sim_->envMap_.popAndPushObstacleInCells(o,i);
}
/////affichage des belonging cells
/////affichage des belonging cells
// CGoGNout<< CGoGNendl;
// CGoGNout << "Obstacle "<< i << ": ";
// for(std::vector<Dart>::iterator ite = belonging_cells[i].begin();ite!=belonging_cells[i].end(); ++ite)
......@@ -1293,8 +1253,9 @@ void MovingObstacle::updateRegistration()
// CGoGNout<<(*ite).index<<" ; ";
// }
// CGoGNout<< CGoGNendl;
// CGoGNout << "Apres une etape : Obstacle "<< i << CGoGNendl;
// CGoGNout << "Apres une etape : Obstacle "<< i << CGoGNendl;
}
/////affichage du general_belonging
// CGoGNout<< CGoGNendl;
// CGoGNout << "General : ";
......
......@@ -19,7 +19,7 @@ Simulator::Simulator(unsigned int config, unsigned int minS, unsigned int nbAgen
#ifdef TWO_AND_HALF_DIM
timeStep_(0.01f),
#else
timeStep_(0.25f),
timeStep_(config > 2 ? 0.01f : 0.25f),
#endif
// timeStep_(0.2f),
globalTime_(0.0f),
......
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