Commit 658baf8f authored by Pierre Kraemer's avatar Pierre Kraemer

suppression SocialAgents

correction unsewFaces + edgeCollapse dans embeddedMap2
ajout simplif faces IHM
parent ea07242a
......@@ -9,8 +9,6 @@ ELSE(WIN32)
add_subdirectory(Examples/Release)
add_subdirectory(Examples/Debug)
add_subdirectory(Examples/Tests)
add_subdirectory(Examples/SocialAgents/Release)
add_subdirectory(Examples/SocialAgents/Debug)
add_subdirectory(Tuto)
ENDIF(WIN32)
......
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
SET(CMAKE_BUILD_TYPE Debug)
link_directories(
${CGoGN_ROOT_DIR}/lib/Debug/
${CGoGN_ROOT_DIR}/lib/Release/
)
# define includes path
include_directories(
/usr/include/libxml2/
${CGoGN_ROOT_DIR}/Apps/Examples/SocialAgents/include
${CGoGN_ROOT_DIR}/include
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/Numerical
${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/Zinri
)
#define exec to compile
add_executable(socialAgentsD ../src/viewer.cpp ../src/env_map.cpp ../src/agent.cpp ../src/simulator.cpp )
target_link_libraries( socialAgentsD containerD topologyD utilsD algoD ${COMMON_LIBS} )
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
SET(CMAKE_BUILD_TYPE Release)
link_directories(
${CGoGN_ROOT_DIR}/lib/Release/
)
# define includes path
include_directories(
/usr/include/libxml2/
${CGoGN_ROOT_DIR}/Apps/Examples/SocialAgents/include
${CGoGN_ROOT_DIR}/include
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/Numerical
${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/Zinri
)
#define exec to compile
add_executable(socialAgents ../src/viewer.cpp ../src/env_map.cpp ../src/agent.cpp ../src/simulator.cpp )
target_link_libraries( socialAgents container topology utils algo ${COMMON_LIBS} )
#ifndef M_AGENT_H
#define M_AGENT_H
// #include "Definitions.h"
#include <iostream>
#include "utils.h"
#include "env_map.h"
#include "Algo/MovingObjects/particle_cell_2D.h"
class Simulator;
class Agent
{
public:
// typedef RVO::Vector2 VEC_A;
typedef VEC3 VEC_A;
explicit Agent(Simulator* sim, size_t agentNo);
Agent(Simulator* sim, const VEC_A& position, size_t agentNo);
Agent(Simulator* sim, const VEC_A& position, size_t agentNo, Dart d);
Agent(Simulator* sim, const VEC_A& position, float neighborDist,
size_t maxNeighbors, float timeHorizon, float timeHorizonObst,
float radius, const VEC_A& velocity, float maxSpeed, size_t agentNo);
~Agent();
void setGoalNo(size_t goal);
void computeNewVelocity();
void insertAgentNeighbor(size_t agentNo, float& rangeSq);
// void insertObstacleNeighbor(size_t obstacleNo, float rangeSq);
void insertObstacleNeighbor(Dart d);
void update();
std::vector<std::pair<float, size_t> > agentNeighbors_;
size_t maxNeighbors_;
float maxSpeed_;
float neighborDist_;
// RVO::Vector2 newVelocity_;
VEC_A newVelocity_;
// std::vector<std::pair<float, size_t> > obstacleNeighbors_;
std::vector<std::pair<float, Dart> > obstacleNeighbors_;
std::vector<Line> orcaLines_;
// RVO::Vector2 position_;
// RVO::Vector2 prefVelocity_;
VEC_A position_;
VEC_A prefVelocity_;
float radius_;
Simulator* sim_;
float timeHorizon_;
float timeHorizonObst_;
// RVO::Vector2 velocity_;
VEC_A velocity_;
size_t agentNo_;
size_t goalNo_;
// Dart nearestDart;
// std::vector<Dart> includingFaces;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> * part;
float rangeSq;
bool treated;
};
bool linearProgram1(const std::vector<Line>& lines, size_t lineNo,
float radius, const Agent::VEC_A& optVelocity,
bool directionOpt, Agent::VEC_A& result);
bool linearProgram2(const std::vector<Line>& lines, size_t num, float radius,
const Agent::VEC_A& optVelocity, bool directionOpt,
Agent::VEC_A& result);
void linearProgram3(const std::vector<Line>& lines, size_t numObstLines,
float radius, Agent::VEC_A& result);
#endif
#ifndef ENV_GENERATOR
#define ENV_GENERATOR
namespace CGoGN
{
namespace CityGenerator
{
template <typename PFP>
void generateAbsolutSpiralOfDeath(typename PFP::MAP& map,typename PFP::TVEC3& position, DartMarker& closeMark, unsigned int side, float rMin, float rMax,float nbTurns);
template <typename PFP>
void generateToboggan(typename PFP::MAP& map,typename PFP::TVEC3& position, DartMarker& closeMark, unsigned int side, float rMin, float rMax,float nbTurns);
template <typename PFP, typename EMBV>
void generateSmallCity(typename PFP::MAP& map, EMBV& position, DartMarker& closeMark, float sideSize);
template <typename PFP, typename EMBV>
void generateCity(typename PFP::MAP& map, EMBV& position, DartMarker& closeMark, float sideSize);
template <typename PFP, typename EMBV, typename EMBAGENT>
void animateCity(typename PFP::MAP& map, EMBV& position, EMBAGENT& agents, DartMarker& closeMark, std::vector<Dart>& newBuilding);
template <typename PFP, typename EMBV>
bool notEightAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, DartMarker& closeMark);
template <typename PFP, typename EMBV>
void generateGrid(typename PFP::MAP& map, EMBV& position, unsigned int cX,unsigned int cY,float sideLength, DartMarker& closeMark);
template <typename PFP, typename EMBV>
void markObstacleSteepFaces(typename PFP::MAP& map, EMBV& position, float steepness, DartMarker& closeMark);
template <typename PFP, typename EMBV>
void generatePathToUpperStair(typename PFP::MAP& map, EMBV& position, Dart dLower, Dart dUpper, DartMarker& closeMark);
template <typename PFP, typename EMBV>
void generateBuilding(typename PFP::MAP& map, EMBV& position, Dart d,DartMarkerStore& build, float height, float side, unsigned int buildingType, DartMarker& closeMark);
template <typename PFP, typename EMBV>
static void generateBridge(typename PFP::MAP& map, EMBV& position, Dart dStart, Dart dStop,float bridgeHeight, DartMarker& closeMark);
template <typename PFP, typename EMBV>
void generateBridge(typename PFP::MAP& map, EMBV& position, unsigned int cX, unsigned int cY,float sideLength, DartMarker& closeMark);
}
}
#include "env_generator.hpp"
#endif
\ No newline at end of file
This diff is collapsed.
#ifndef ENVMap_H
#define ENVMap_H
#include <iostream>
// #include "Definitions.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Algo/ImplicitHierarchicalMesh/ihm.h"
#include "Algo/ImplicitHierarchicalMesh/subdivision.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/extrusion.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/centroid.h"
#include "Container/fakeAttribute.h"
#include "env_generator.h"
using namespace CGoGN;
class Agent;
struct PFP: public PFP_STANDARD
{
// definition de la carte
// typedef EmbeddedMap2<Map2> MAP;
typedef Algo::IHM::ImplicitHierarchicalMap MAP;
// definition des listes d'agent
// typedef std::vector<Agent *> AGENTS;
typedef std::vector<Agent * > AGENTS;
typedef NoMathIONameAttribute<AGENTS > AGENTVECT;
typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
};
typedef PFP::VEC3 VEC3 ;
class EnvMap
{
public :
PFP::MAP map;
//SelectorTrue<PFP::MAP::Dart> allDarts;
//identifier for the position attribute
// unsigned int idPos;
PFP::TVEC3 position;
//identifier for the normal attribute
// unsigned int idNorm;
PFP::TVEC3 normal;
// unsigned int idAgent;
PFP::TAB_AGENTVECT agentvect;
float sideSize;
// PFP::POSITION tablePosition;
// PFP::TAB_AGENTVECT tableAgent;
DartMarker closeMark;
// DartMarker subdivMarker;
std::vector<Dart> newBuildings;
// std::vector<Dart> subdividedDarts;
Dart dSimplify;
Dart dSubdivide;
EnvMap();
bool simplifiable(Dart d);
bool simplifiableDart(Dart d);
bool collapsableEdge(Dart& d,Dart& dStop);
bool simplifyVertex(Dart& d);
bool simplifyEdge(Dart& d);
void simplify();
VEC3 faceCenter(Dart d);
// const PFP::VEC3& getPosition(const Dart& d);
// RVO::Vector2 getPosition2(Dart d);
unsigned int getNbFaces();
Dart getDart(unsigned int i);
Dart getBelongingCell(const PFP::VEC3& pos);
bool noAgentSurroundingVertex(Dart d);
void findAgentContactInFace(Dart d, PFP::VEC3 pos, float radius, std::vector<Dart>& l_contact_Dart,DartMarker& m);
// void insertObstacleOfFace(Agent * agent, const Dart d);
void insertObstacleOfFace(PFP::AGENTS agents,const Dart d);
// void getAllFacesOfAgent(Agent * agent, Dart d, PFP::VEC3 pos, float radius);
void getAllFacesOfAgents(Dart d);
void linkAgentWithCells(Agent* agent);
void addObstacle(std::vector<VEC3> points);
bool subdivideSquare(Dart d);
bool subdivideFace(Dart d);
void resetAgentInFace(Agent * agent);
bool checkForSubdivision(Dart d);
void updateMap();
void subdivideFaces();
void simplifyFaces();
void pushAgentInCell(Agent * agent, Dart d);
void popAgentInCell(Agent * agent, Dart d);
// void addNeighborAgents(size_t agentno, Agent * agent);
void addNeighborAgents(PFP::AGENTS agentsFrom,PFP::AGENTS agentsTo);
};
#endif
#ifndef ENVMAP_RENDER
#define ENVMAP_RENDER
#include "env_map.h"
#include <GL/glut.h>
//static void renderPoint(EnvMap& m, Dart& d)
//{
// PFP::VEC3 p = m.position[d];
// glBegin(GL_POINTS);
// glVertex3f(p[0],p[1],p[2]);
// glEnd();
//}
static void renderDart(EnvMap& m, Dart d)
{
PFP::VEC3 p1 = m.position[d];
PFP::VEC3 p2 = m.position[m.map.phi1(d)];
glBegin(GL_LINES);
glVertex3f(p1[0],p1[1],p1[2]);
glVertex3f(p2[0],p2[1],p2[2]);
glEnd();
}
static void renderFace(EnvMap& m, Dart& d)
{
Dart dd=d;
do {
renderDart(m,dd);
dd = m.map.phi1(dd);
}while(dd!=d);
}
//static void renderCellOfDim(EnvMap& m,Dart d, unsigned int dim)
//{
// switch(dim) {
// case 0 : renderPoint(m,d); break;
// case 1 : renderDart(m,d); break;
// case 2 : renderFace(m,d); break;
// }
//}
//
//static void renderAllPoints(EnvMap& m)
//{
// glBegin(GL_POINTS);
// for(Dart d=m.map.begin();d!=m.map.end();m.map.next(d)) {
// PFP::VEC3 p = m.position[d];
// glVertex3f(p[0],p[1],p[2]);
// }
// glEnd();
//}
static void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
{
glBegin(GL_LINE_LOOP);
glVertex3fv(&p[0]);
glVertex3fv(& m.position[d][0]);
glVertex3fv(& m.position[m.map.phi1(d)][0]);
glEnd();
}
#endif
/****************************************************************************
** Form interface generated from reading ui file 'mainwindow.ui'
**
** Created: Thu Sep 30 11:00:52 2010
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef PATH_FINDER
#define PATH_FINDER
namespace CGoGN
{
namespace PathFinder
{
template <typename PFP>
float pathCostSqr(typename PFP::MAP& map,const typename PFP::TVEC3& position, Dart startPos, Dart stopPos);
template <typename PFP>
std::vector<Dart> pathFindAStar(typename PFP::MAP& map,const typename PFP::TVEC3& position, Dart startPos, Dart stopPos, FunctorSelect& bad = FunctorType());
}
}
#include "path_finder.hpp"
#endif
\ No newline at end of file
#include "Algo/Geometry/centroid.h"
#include <limits>
#include <iostream>
namespace CGoGN
{
namespace PathFinder
{
template <typename PFP>
float pathCostSqr(typename PFP::MAP& map,const typename PFP::TVEC3& position, Dart startPos, Dart stopPos)
{
return VEC3(Algo::Geometry::faceCentroid<PFP>(map,stopPos,position)-Algo::Geometry::faceCentroid<PFP>(map,startPos,position)).norm2();
}
template <typename PFP>
std::vector<Dart> pathFindAStar(typename PFP::MAP& map,const typename PFP::TVEC3& position, Dart startPos, Dart stopPos, FunctorType& bad)
{
std::vector<Dart> path;
AutoAttributeHandler< Dart > tablePred(map,FACE_ORBIT);
std::vector<std::pair<float,Dart> > vToDev;
Dart toDev = stopPos;
vToDev.push_back(std::make_pair(0, toDev));
tablePred[toDev] = toDev;
do {
//dev cell
//get all vertex-adjacent cells
Dart dd = toDev;
do {
Dart ddd = map.alpha1(dd);
do {
ddd = map.alpha1(ddd);
if(ddd!=dd) {
if(!map.foreach_dart_of_face(ddd,bad) && tablePred[ddd]==EMBNULL) {
//evaluate their cost and push them in the vector to dev
if(tablePred[ddd]==EMBNULL)
tablePred[ddd]=toDev;
std::vector<std::pair<float,Dart> >::iterator it=vToDev.begin();
float costDDD=pathCostSqr<PFP>(map,position,startPos,ddd)+(vToDev.begin())->first;
while(it!=vToDev.end() && (*it).first<costDDD)
++it;
vToDev.insert(it, std::make_pair(costDDD, ddd));
}
}
} while(ddd!=dd);
dd = map.phi1(dd);
} while(dd!=toDev);
//remove developped cell and get new cell to dev
if(vToDev.size()>0) {
toDev = (vToDev.begin())->second;
vToDev.erase(vToDev.begin());
}
} while(vToDev.size()>0 && !map.sameOrientedFace(startPos,toDev));
//if path found : from start to stop -> push all predecessors
if(map.sameOrientedFace(startPos,toDev))
{
std::cout << "found" << std::endl;
Dart toPush=startPos;
std::cout << tablePred[startPos] << std::endl;
do {
path.push_back(toPush);
toPush = tablePred[toPush];
} while(!map.sameOrientedFace(toPush,stopPos));
}
return path;
}
//namespace
}
}
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include <limits>
#include <vector>
#include "utils.h"
#include "env_map.h"
#include "env_generator.h"
#include "agent.h"
#include "path_finder.h"
class Simulator
{
public:
Simulator();
Simulator(float timeStep, float neighborDist, size_t maxNeighbors,
float timeHorizon, float timeHorizonObst, float radius,
float maxSpeed, const VEC3& velocity = VEC3(0,0,0));
~Simulator();
size_t addAgent(VEC3 position);
size_t addAgent(VEC3 position, Dart d);
size_t addAgent(VEC3 position, float neighborDist,
size_t maxNeighbors, float timeHorizon,
float timeHorizonObst, float radius, float maxSpeed,
const VEC3& velocity = VEC3());
void doStep();
VEC3 getAgentPrefVelocity(size_t agentNo) const;
float getGlobalTime() const;
void setAgentDefaults(float neighborDist, size_t maxNeighbors,
float timeHorizon, float timeHorizonObst,
float radius, float maxSpeed,
const VEC3& velocity = VEC3());
void setAgentPrefVelocity(size_t agentNo, const VEC3& prefVelocity);
void setTimeStep(float timeStep);
std::vector<Agent*> agents_;
Agent* defaultAgent_;
float globalTime_;
EnvMap envMap;
float timeStep_;
std::vector<PFP::VEC3 > socialAgents;
void setPreferredNextCellVelocities();
// std::vector<Dart> path;
/** Added function */
std::vector<PFP::VEC3> getAgentsPosition();
//just one goal
std::vector<PFP::VEC3> goals;
void setPreferredVelocities(PFP::VEC3 posToReach);
//for a path of goals
std::vector<std::pair<int,int> > pathPointer;
std::vector<std::vector<PFP::VEC3> * > pathToFollow;
void setPreferredPathVelocities();
//scenarii
void setupScenario();
void setupTobogganScenario(float rMax,float rMin);
void setupHelicoidScenario(float rMax,float rMin);
};
#endif
#ifndef UTILS_H
#define UTILS_H
#include <cmath>
#include <limits>
#include <vector>
// #include "Vector2.h"
#include "Geometry/vector_gen.h"
typedef CGoGN::Geom::Vec3f VEC3;
static const float RVO_EPSILON = 0.00001f;
static const size_t RVO_ERROR = std::numeric_limits<size_t>::max();
typedef VEC3 VEC_A;
struct Line {
VEC_A point;
VEC_A direction;
};
inline float abs(const VEC3& vector)
{
return std::sqrt(vector * vector);
}
inline float absSq(const VEC3& vector)
{
return vector[0] * vector[0] + vector[1] * vector[1];
// return vector * vector;
}
inline float det2D(const VEC_A& vector1, const VEC_A& vector2)