Commit e60f0724 authored by pitiot's avatar pitiot

develop

parent beed0290
#ifndef NIDDLE_H
#define NIDDLE_H
#include <iostream>
#include "env_map.h"
#include "Algo/MovingObjects/particle_cell_3D_memo.h"
class Niddle
{
public:
Niddle(Simulator* sim, const VEC3& position, Dart d) ;
VEC3 getPositionSegment(int index) ;
void addGeneralCell ( Dart d);
bool removeGeneralCell (Dart d);
void update();
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1,Dart& d2);
CGoGN::Algo::Volume::MovingObjects::ParticleCell2D<PFP>* * parts_ ;
void updateRegistration();
unsigned int nbVertices;
std::vector<Obstacle *> obstacles_;
std::vector<Dart> * belonging_cells;
std::vector<Dart> * neighbor_cells;
std::vector<std::pair<Dart, int> > general_belonging;
Simulator* sim_;
};
void resetPart(Obstacle * o, Dart d1);
#endif
#ifndef _Segment_H_
#define _Segment_H_
#include "env_map.h"
class Segment
{
public:
Segment(const VEC3 point1, const VEC3 point2,
Niddle * niddle =NULL, unsigned int ind=0) :
p1(point1), p2(point2),
nid(niddle), index(ind)
{
// p1[2] = 0 ;
// p2[2] = 0 ;
// prevP[2] = 0 ;
// nextP[2] = 0 ;
}
VEC3 p1 ;
VEC3 p2 ;
Niddle * nid ;
unsigned int index ;
} ;
#endif
#include "niddle.h"
Niddle::Niddle(Simulator* sim, const VEC3& position, Dart d) :
sim_(sim) // lien vers le simulateur
{
parts_ = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>*[nbVertices];
belonging_cells = new std::vector<Dart>[nbVertices];
neighbor_cells = new std::vector<Dart>[nbvertices];
for (unsigned int i = 0; i < nbVertices; ++i)
{
parts_[i] = new CGoGN::Algo::Volume::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, position, sim_->envMap_.position);
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
Obstacle* o = new Obstacle(parts_[i]->getPosition(),
parts_[(i + 1) % nbVertices]->getPosition(),
this);
obstacles_.push_back(o);
// CGoGNout<<" obstacle :"<< i << " num : "<< o<<CGoGNendl;
sim_->envMap_.pushObstacleInCells(o);
}
}
/*addGeneralCell
* adds cell d to general belonging, if it's already present, increases the number of instance of the cell
*/
void Niddle::addGeneralCell ( Dart d)
{
bool added = false;
std::vector< std::pair<Dart,int> >::iterator it =general_belonging.begin();
while (it != general_belonging.end() )
{
if(sim_->envMap_.map.sameVolume((*it).first,d))
{
(*it).second ++;
added= true;
break;
}
else ++it;
};
if (!added)
{
general_belonging.push_back(std::make_pair(d,1));
}
}
/*removeGeneralCell
* removes cell d to general belonging decreases the number of instance of the cell, if the number is 0 the celle is removed *forever*
*/
bool Niddle::removeGeneralCell (Dart d)
{
std::vector< std::pair<Dart,int> >::iterator it =general_belonging.begin();
while (it != general_belonging.end() )
{
if(sim_->envMap_.map.sameVolume((*it).first,d))
{
if(--((*it).second)==0)
{
*it = general_belonging.back() ;
general_belonging.pop_back() ;
}
return true;
}
else ++it;
};
return false;
}
VEC3 Niddle::getPositionSegment(int index)
{
return parts_[index]->getPosition();
}
void Niddle::updateRegistration()
{
PFP::VEC3 bary(0);
// Dart centerDart =map.phi<11>(groundFace);
for (unsigned int i = 0; i < nbVertices; ++i)
{
VEC3 pos = getNewPosition(i);
parts_[i]->move(pos);
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
// CGoGNout << "avant une etape : Obstacle "<< i << CGoGNendl;
Obstacle* o = obstacles_[i];
o->p1 = parts_[i]->getPosition();
o->p2 = parts_[(i + 1 ) % nbVertices]->getPosition();
Dart d1 = parts_[i]->d;
Dart d2 = parts_[(i+1)%nbVertices]->d;
if(!((sim_->envMap_.map.sameVolume(d1,d2))&& (parts_[i]->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS && parts_[(i+1)%nbVertices]->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS)))
{
sim_->envMap_.popAndPushObstacleInCells(o,i);
}
}
/////affichage du general_belonging
// CGoGNout<< CGoGNendl;
// CGoGNout << "General : ";
// for(std::vector<std::pair<Dart , int> >::iterator ite = general_belonging.begin();ite!=general_belonging.end(); ++ite)
// {
// CGoGNout<<"< "<<(*ite).first.index<<" , "<<(*ite).second<<"> ; ";
// }
// CGoGNout<< CGoGNendl;
}
//-------------------------------------------------------------------------
std::vector<Dart> Niddle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, Dart& d2)
{
CGoGN::Algo::Volume::MovingObjects::ParticleCell2DMemo<PFP> * registering_part = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP>(sim_->envMap_.map, d1,pos,sim_->envMap_.position);
std::vector<Dart> result =(registering_part->move(dest));
d2=registering_part->d;
// CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
return result;
}
//////// a implémenter
//void resetPartSubdiv(Obstacle* o)
//{
// Niddle * mo = o->mo;
//
// if (mo != NULL)
// {
// unsigned int n =o->index;
// /// ajout obstacles lointains
// unsigned int n2;
// switch (n-(mo->nbVertices))
// {
// case 0 : n2=n+1; break;
// case 1 : n2=n-1;break;
// default : n2 =(n+1)%(mo->nbVertices); break;
// }
// ////////
// VEC3 pos = mo->parts_[n]->getPosition();
// VEC3 pos2 = mo->parts_[n2]->getPosition();
// mo->parts_[n]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Volume::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->parts_[n]->d, mo->sim_->envMap_.position)) ;
//
// mo->parts_[n]->setState(VOLUME) ;
// mo->parts_[n]->move(pos) ;
//
// mo->parts_[n2]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Volume::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->parts_[n2]->d, mo->sim_->envMap_.position)) ;
//
// mo->parts_[n2]->setState(VOLUME) ;
// mo->parts_[n2]->move(pos2) ;
//
// mo->dDir = mo->parts_[0]->d;
// }
//}
//
//void resetObstPartInFace(Obstacle* o, Dart d1)
//{
// Niddle * mo = o->mo;
//
// if (mo != NULL)
// {
// unsigned int n =o->index;
// /// ajout obstacles lointains
// unsigned int n2;
// switch (n-(mo->nbVertices))
// {
// case 0 : n2=n+1; break;
// case 1 : n2=n-1;break;
// default : n2 =(n+1)%(mo->nbVertices); break;
// }
// ////////
// VEC3 pos1 = mo->parts_[n]->getPosition();
// VEC3 pos2 = mo->parts_[n2]->getPosition();
//// if (Algo::Volume::Geometry::isPointInConvexFace2D <PFP> (mo->sim_->envMap_.map, d1, mo->sim_->envMap_.position, pos1, true))
// if ( mo->sim_->envMap_.is_insideConvexCell2D(pos1, d1))
// mo->parts_[n]->d = d1;
//// if (Algo::Volume::Geometry::isPointInConvexFace2D <PFP> (mo->sim_->envMap_.map, d1, mo->sim_->envMap_.position, pos2, true))
// if ( mo->sim_->envMap_.is_insideConvexCell2D(pos2, d1))
// mo->parts_[n2]->d = d1;
// if(n==0)
// mo->dDir = mo->parts_[0]->d;
// }
//}
void resetPart(Obstacle * o, Dart d1)
{
Niddle * mo = o->mo;
if(mo!=NULL)
{
int n =o->index;
if (mo->parts_[n]->d == mo->sim_->envMap_.map.phi1(d1))
mo->parts_[n]->d = d1;
if (mo->parts_[n+1]->d == mo->sim_->envMap_.map.phi1(d1))
mo->parts_[n+1]->d = d1;
if(n==0)
mo->dDir = mo->parts_[n]->d;
}
}
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