Commit 8d135897 authored by Thomas Pitiot 's avatar Thomas Pitiot

ini

parent 701f9b28
cmake_minimum_required(VERSION 2.8)
project(Volusion)
project(SocialAgents3D)
#SET ( CMAKE_VERBOSE_MAKEFILE 1 )
......@@ -41,14 +41,14 @@ file( GLOB
include/*.h
)
qt_wrap_ui( Volusion_ui include/Volusion.ui )
qt_wrap_cpp( Volusion_moc include/viewer.h )
add_executable( Volusion
qt_wrap_ui( SocialAgents3D_ui include/SocialAgents3D.ui )
qt_wrap_cpp( SocialAgents3D_moc include/viewer.h )
add_executable( SocialAgents3D
${includes}
${sources}
${Volusion_moc}
${Volusion_ui}
${SocialAgents3D_moc}
${SocialAgents3D_ui}
)
target_link_libraries( Volusion ${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
qt_use_modules(Volusion Gui OpenGL Xml Svg)
target_link_libraries( SocialAgents3D ${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
qt_use_modules(SocialAgents3D Gui OpenGL Xml Svg)
#ifndef Agent_H
#define Agent_H
#include "env_map.h"
#include "utils.h"
//particules
using namespace CGoGN ;
class Simulator;
class Agent
{
public:
Agent(Simulator* sim,VEC3 startingPoint);
Agent(Simulator* sim, VEC3 startingPoint,Dart d) ;
~Agent();
init(VEC3 startingPoint,Dart d);
void move();
update();
VEC3 getPosition() ;
void updateNeighbors() ;
void computePrefVelocity();
void computeNewVelocity();
// affichage
void initGL();
void draw();
//particule
Particule part_;
// objectif(s)
unsigned int curGoal_ ;
std::vector<VEC3> goals_ ;
//vitesses
VEC3 velocity_ ;
VEC3 newVelocity_ ;
VEC3 prefVelocity_ ;
//voisins retenus pour l'évitement
std::vector<std::pair<float, Agent*> > agentNeighbors_ ;
std::vector<std::pair<float, Segment*> > segmentNeighbors_ ;
std::vector<std::pair<float, Triangle*> > triangleNeighbors_;
//couleur
float r;
float g;
float b;
//lien simulateur
unsigned int agentNo ;
Simulator* sim_;
bool alive;
};
#endif
......@@ -5,6 +5,7 @@
#include "knife.h"
#include "tree.h"
#include "surface.h"
#include "agent.h"
using namespace CGoGN ;
......@@ -17,6 +18,7 @@ public:
void init(int argc, char **argv);
void doStep();
void initAgents();
void initMovingObject();
void initSurfaces();
void initFixedObjects();
......@@ -24,6 +26,7 @@ public:
EnvMap envMap_;
double nbSteps_;
MovingObject * aiguille;
std::vector<Agent *>agents;
std::vector<ArticulatedObject * >objects;
std::vector<Surface * > surfaces;
bool Needle_or_knife;
......
#include "simulator.h"
// initialisation Agent
void Agent::init(VEC3 startingPoint,Dart d)
{
r=0.0f;
g=0.0f;
b=1.0f;
part_= CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, d, startingPoint , sim_->envMap_.position, &(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter));
sim_->agents.push_back(this);
}
Agent::Agent(Simulator* sim,VEC3 startingPoint, Dart d):
sim_(sim)
{
init(startingPoint,d);
}
Agent::Agent(Simulator* sim,VEC3 startingPoint):
sim_(sim)
{
Dart d=sim_->envMap_.getBelongingCell(startingPoint);
init(startingPoint,d);
}
void Agent::color_close()
{
if(nbVertices>0)
{
Dart volume = this->getParticule(0)->getCell();
VEC3 pos=getParticule(0)->getPosition();
float distSq=0;
for (Segment * s : sim_->envMap_.RegisteredEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
s->nid->changeColor(s,distSq);
}
}
for (Segment * s : sim_->envMap_.RegisteredNeighborEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
distSq = distSqPointLineSegment(s->p1,s->p2,pos);
s->nid->changeColor(s,distSq);
}
}
for(Triangle * t : sim_->envMap_.RegisteredTriangles[volume])
{
VEC3 closest = closestPointInTriangle(t->p1,t->p2,t->p3,pos);
t->closest_point=closest;
// CGoGNout<<"pos :"<<pos<<" || closest :"<<closest<<CGoGNendl;
distSq = (pos-closest).norm2();
if(distSq < ((pos-closest_point).norm2()))
closest_point=closest;
t->surf->changeColor(t,distSq);
}
for(Triangle * t : sim_->envMap_.RegisteredNeighborTriangles[volume])
{
VEC3 closest = closestPointInTriangle(t->p1,t->p2,t->p3,pos);
t->closest_point=closest;
// CGoGNout<<"pos :"<<pos<<" || closest :"<<closest<<CGoGNendl;
distSq = (pos-closest).norm2();
if(distSq < ((pos-closest_point).norm2()))
closest_point=closest;
t->surf->changeColor(t,distSq);
}
}
}
void Agent::unColor_close(Dart volume)
{
for (Segment * s : sim_->envMap_.RegisteredEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
s->nid->changeColor(s,-1);
}
}
for (Segment * s : sim_->envMap_.RegisteredNeighborEdges[volume])
{
if(s->nid!=this || s->index!=nbEdges)
{
s->nid->changeColor(s,-1);
}
}
for(Triangle * t : sim_->envMap_.RegisteredTriangles[volume])
{
t->surf->changeColor(t,-1);
}
for(Triangle * t : sim_->envMap_.RegisteredNeighborTriangles[volume])
{
t->surf->changeColor(t,-1);
}
}
void Agent::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,&(sim_->envMap_.facecenter),&(sim_->envMap_.volumecenter)));
partNeedReset.push_back(0);
Segment* o = new Segment(getParticule(index+1)->getPosition(),
getParticule(0)->getPosition(),
this,index+1,0,index,r,g,b);
Segments_.push_back(o);
sim_->envMap_.FirstRegistrationSegment(o);
if(index>0)
{
(Segments_[index-1])->indexPart2=index+1;
}
nbEdges++;
nbVertices++;
}
void Agent::move(VEC3 diff)
{
Dart oldCell = this->getParticule(0)->getCell();
if(diff.norm()>sim_->envMap_.maxCellRay) // on limite la taille du déplacement pour pouvoir vérifier rapidement si l'objectif est dans la carte
{
// CGoGNout<< "déplacement trop grand, on raccourci "<<CGoGNendl;
diff.normalize();
diff*=sim_->envMap_.maxCellRay*0.9;
}
VEC3 pos = getPosition(0)+diff;
if(sim_->envMap_.map.isVolumeIncidentToBoundary(oldCell))
{
if(!sim_->envMap_.checkPointInMap(pos,oldCell))
{
pos=pos-diff;
}
}
this->getParticule(0)->move(pos);
updateRegistration();
this->unColor_close(oldCell);
#ifdef IHMap
if(!getParticule(0)->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS) /// a rajouter si les cellules sont assez petites
{
refine();
}
#endif
this->color_close();
if((getPosition(0)-getPosition(nbEdges)).norm2()>edgeSize)
{
createEdge(nbEdges);
}
}
void Agent::updateRegistration()
{
Segment* o = Segments_[nbEdges-1];
o->p1 = getParticule(o->indexPart1)->getPosition();
o->p2 = getParticule(o->indexPart2)->getPosition();
Dart d1 = this->getParticule(o->indexPart1)->getCell();
Dart d2 = this->getParticule(o->indexPart2)->getCell();
if(!(
(sim_->envMap_.map.sameVolume(d1,d2))
&& (getParticule(o->indexPart1)->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS && getParticule(o->indexPart2)->crossCell==CGoGN::Algo::Volume::MovingObjects::NO_CROSS)))
{
sim_->envMap_.popAndPushSegment(o);
}
/////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;
}
void Agent::refine()
{
#ifdef IHMap
Dart volume = this->getParticule(0)->getCell();
REAL rayon = sim_->envMap_.volumeMaxdistance(volume) ;
if(rayon >2* sim_->envMap_.maxCellRay ) // on subdivise si le rayon est 2 fois le maxCellRay
{
if(sim_->envMap_.subdivideVolume(volume))
{
refine();
}
}
#endif
}
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