Commit 57a412e1 authored by Thomas's avatar Thomas
Browse files

qq chgmts pr l'export

parents f1de7f4e e5aa38ee
......@@ -12,11 +12,19 @@ SET(CMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH} ${CGoGN_ROOT_DIR}/cmake_modules/")
find_package(OpenGL)
find_package(GLUT)
# FOR Qt4
FIND_PACKAGE(Qt4 REQUIRED)
SET(QT_USE_QTOPENGL TRUE)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
# qq definition specifiques pour mac
IF(APPLE)
# attention a changer pour chercher la bonne version automatiquement
SET(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.6.sdk")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined -Wl,dynamic_lookup")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMAC_OSX")
SET(CMAKE_OSX_ARCHITECTURES x86_64)
ENDIF(APPLE)
IF(WIN32)
......@@ -41,7 +49,10 @@ ENDIF(WIN32)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar )
SET(COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream openctm assimp)
SET(CGoGN_LIBS_D topologyD algoD containerD utilsD)
SET(CGoGN_LIBS_R topology algo container utils)
SET(NUMERICAL_LIBS numerical lapack blas f2c)
add_subdirectory(Release)
add_subdirectory(Debug)
......
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
SET(CMAKE_BUILD_TYPE Debug)
# FOR Qt4
......@@ -20,27 +18,32 @@ link_directories(
# define includes path
include_directories(
/usr/include/libxml2/
../include
/usr/include/libxml2/
${CGoGN_ROOT_DIR}/include
${CGoGN_ROOT_DIR}/ThirdParty/Numerical
${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/Zinri
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
${CMAKE_CURRENT_BINARY_DIR}
)
#define exec to compile
QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui )
QT4_WRAP_CPP( socialAgents_moc ../include/viewer.h )
add_executable( socialAgentsD
../src/viewer.cpp
../src/env_map.cpp
../src/agent.cpp
../src/simulator.cpp
../src/gl2ps.c
${socialAgents_moc}
${socialAgents_ui}
)
target_link_libraries( socialAgentsD
containerD topologyD utilsD algoD ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} boost_thread-mt)
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} boost_thread-mt)
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
SET(CMAKE_BUILD_TYPE Release)
# FOR Qt4
......@@ -16,27 +14,32 @@ link_directories(
# define includes path
include_directories(
/usr/include/libxml2/
../include
/usr/include/libxml2/
${CGoGN_ROOT_DIR}/include
${CGoGN_ROOT_DIR}/ThirdParty/Numerical
${CGoGN_ROOT_DIR}/ThirdParty/Numerical/UFconfig
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/Zinri
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
${CMAKE_CURRENT_BINARY_DIR}
)
#define exec to compile
QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui )
QT4_WRAP_CPP( socialAgents_moc ../include/viewer.h )
add_executable( socialAgents
../src/viewer.cpp
../src/env_map.cpp
../src/agent.cpp
../src/simulator.cpp
../src/gl2ps.c
${socialAgents_moc}
${socialAgents_ui}
)
target_link_libraries( socialAgents
container topology utils algo ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} boost_thread-mt)
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} boost_thread-mt)
......@@ -49,13 +49,13 @@ public:
std::vector<VEC3> goals_;
unsigned int curGoal_;
size_t maxNeighbors_;
float maxSpeed_;
float neighborDistSq_;
float radius_;
float timeHorizon_;
float timeHorizonObst_;
float rangeSq_;
static size_t maxNeighbors_;
static float maxSpeed_;
static float neighborDistSq_;
static float radius_;
static float timeHorizon_;
static float timeHorizonObst_;
static float rangeSq_;
VEC3 velocity_;
VEC3 newVelocity_;
......
......@@ -40,6 +40,8 @@ struct PFP: public PFP_STANDARD
typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT;
typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
typedef AttributeHandler<OBSTACLEVECT> TAB_OBSTACLEVECT;
typedef NoMathIONameAttribute<std::pair<bool,bool> > BOOLATTRIB;
};
typedef PFP::VEC3 VEC3;
......@@ -70,7 +72,7 @@ public :
void addRefineCandidate(Dart d);
void addCoarsenCandidate(Dart d);
void clearUpdateCandidates();
void updateMap();
void resetAgentInFace(Agent* agent);
......@@ -80,6 +82,8 @@ public :
PFP::TVEC3 position;
PFP::TVEC3 normal;
AttributeHandler<PFP::BOOLATTRIB> subdivisableFace;
PFP::TAB_AGENTVECT agentvect;
PFP::TAB_AGENTVECT neighborAgentvect;
......@@ -88,7 +92,7 @@ public :
CellMarker obstacleMark;
CellMarker buildingMark;
static const unsigned int nbAgentsToSubdivide = 9;
static const unsigned int nbAgentsToSubdivide = 7;
static const unsigned int nbAgentsToSimplify = 7;
std::map<unsigned int, Dart> refineCandidate;
......
......@@ -4,9 +4,7 @@
#include "env_map.h"
#include "agent.h"
#include <GL/glut.h>
void renderDart(EnvMap& m, Dart d)
inline void renderDart(EnvMap& m, Dart d)
{
PFP::VEC3 p1 = m.position[d];
PFP::VEC3 p2 = m.position[m.map.phi1(d)];
......@@ -17,7 +15,7 @@ void renderDart(EnvMap& m, Dart d)
glEnd();
}
void renderFace(EnvMap& m, Dart& d)
inline void renderFace(EnvMap& m, Dart& d)
{
Dart dd=d;
do {
......@@ -26,7 +24,7 @@ void renderFace(EnvMap& m, Dart& d)
}while(dd!=d);
}
void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
{
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,d,m.position);
p[2] -= 1000;
......@@ -45,7 +43,7 @@ void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
static const float cosT[5] = { 1, 0.309017, -0.809017, -0.809017, 0.309017 };
static const float sinT[5] = { 0, 0.951057, 0.587785, -0.587785, -0.951057 };
void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, bool showObstacleDist = false)
inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, bool showObstacleDist = false)
{
VEC3 pos = agent->part_.m_position;
float radius = agent->radius_;
......@@ -105,4 +103,3 @@ void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, bool sh
}
#endif
......@@ -21,7 +21,7 @@ inline float det2D(const VEC3& vector1, const VEC3& vector2)
return vector1[0] * vector2[1] - vector1[1] * vector2[0];
}
inline float distSqPointLineSegment( VEC3 a1, VEC3 b1, const VEC3& c1)
inline float distSqPointLineSegment(VEC3 a1, VEC3 b1, const VEC3& c1)
{
a1[2] = 0;
b1[2] = 0;
......
......@@ -24,41 +24,44 @@
#include <iostream>
#include "Utils/glutwin.h"
#include "Utils/os_spec.h"
#include "Utils/GLSLShader.h"
#include "Utils/qtSimple.h"
#include "ui_socialAgents.h"
#include "Utils/qtui.h"
#include "simulator.h"
#include "env_render.h"
#include "gl2ps.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Export/exportPov.h"
#include "Utils/GLSLShader.h"
#include "Algo/Render/GL1/map_glRender.h"
#include "Algo/Render/GL1/topo_render.h"
using namespace CGoGN ;
typedef PFP::MAP MAP;
class MyGlutWin : public Utils::SimpleGlutWin
class SocialAgents : public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyGlutWin(int* argc, char** argv, int winX, int winY) ;
SocialAgents() ;
void init() ;
void myRedraw();
void animate();
void initGUI() ;
void cb_initGL() ;
void cb_redraw() ;
bool exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std::string& filename, PFP::VEC3 cameraPos, PFP::VEC3 cameraLook, PFP::VEC3 translate, float angle_X, float angle_Y, float angle_Z,const FunctorSelect& good = SelectorTrue());
void myKeyboard(unsigned char keycode, int x, int y);
void cb_keyPress(int keycode) ;
Utils::QT::uiDockInterface dock ;
QTimer* timer;
// to count fps
int frames;
......@@ -69,10 +72,12 @@ public:
Simulator sim;
SelectorTrue allDarts;
bool b_animate;
bool render_anim;
int visu;
int nbGenerated;
float explode;
public slots:
void animate() ;
} ;
#include "agent.h"
#include "simulator.h"
size_t Agent::maxNeighbors_ = 10;
float Agent::maxSpeed_ = 2.0f;
float Agent::neighborDistSq_ = 15.0f * 15.0f;
float Agent::radius_ = 1.5f;
float Agent::timeHorizon_ = 10.0f;
float Agent::timeHorizonObst_ = 10.0f;
float Agent::rangeSq_ = (timeHorizonObst_ * maxSpeed_ + radius_) * (timeHorizonObst_ * maxSpeed_ + radius_);
Agent::Agent(Simulator* sim, const VEC3& position, Dart d) :
part_(sim->envMap_.map, d, position, sim->envMap_.position),
curGoal_(-1),
maxNeighbors_(10),
maxSpeed_(2.0f),
neighborDistSq_(15.0f * 15.0f),
radius_(1.5f),
timeHorizon_(10.0f),
timeHorizonObst_(10.0f),
velocity_(0),
newVelocity_(0),
prefVelocity_(0),
sim_(sim)
{
rangeSq_ = (timeHorizonObst_ * maxSpeed_ + radius_) * (timeHorizonObst_ * maxSpeed_ + radius_);
}
{}
VEC3 Agent::getPosition()
{
......
......@@ -16,6 +16,7 @@ EnvMap::EnvMap() : obstacleMark(map, EDGE_CELL), buildingMark(map, FACE_CELL)
agentvect = map.addAttribute<PFP::AGENTVECT>(FACE_ORBIT, "agents");
neighborAgentvect = map.addAttribute<PFP::AGENTVECT>(FACE_ORBIT, "neighborAgents");
obstvect = map.addAttribute<PFP::OBSTACLEVECT>(FACE_ORBIT, "obstacles");
subdivisableFace = map.addAttribute<PFP::BOOLATTRIB>(FACE_ORBIT, "subdivisableFace");
}
unsigned int EnvMap::mapMemoryCost()
......@@ -47,6 +48,8 @@ void EnvMap::init()
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.init();
registerObstaclesInFaces();
for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
subdivisableFace[i].first = false ;
}
void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
......@@ -224,62 +227,97 @@ void EnvMap::updateMap()
if(agentvect[old].size() > nbAgentsToSubdivide)
{
PFP::AGENTS oldAgents(agentvect[old]);
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
popAgentInCells(*ait, old);
neighborAgentvect[old].clear() ;
map.setCurrentLevel(fLevel) ;
CellMarkerStore newF(map, FACE_CELL);
newF.mark(old);
Algo::IHM::subdivideFace<PFP>(map, old, position) ;
map.setCurrentLevel(map.getMaxLevel()) ;
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
bool subdivisable = true ;
if(subdivisableFace[old].first == true)
{
resetAgentInFace(*ait) ;
pushAgentInCells(*ait, (*ait)->part_.d) ;
subdivisable = subdivisableFace[old].second ;
}
unsigned int degree = 0;
Dart dd = old;
do
else
{
++degree;
Dart d3 = dd;
float maxEdgeSize = Agent::neighborDistSq_ ; // diametre de vision de l'agent au carré
map.setCurrentLevel(fLevel) ;
PFP::VEC3 fCenter = Algo::Geometry::faceCentroid<PFP>(map, old, position) ;
Dart fd = old ;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
while(d4 != d3)
PFP::VEC3 edge = Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
PFP::VEC3 proj = fCenter - (position[fd] + (edge * (fCenter - position[fd]) / edge.norm2()) * edge) ;
if(proj.norm2() < maxEdgeSize)
// if(Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position).norm2() < maxEdgeSize)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
subdivisable = false ;
break ;
}
d3 = map.phi1(d3);
} while(d3 != dd);
fd = map.phi1(fd) ;
} while(fd != old) ;
map.setCurrentLevel(map.getMaxLevel()) ;
subdivisableFace[old].first = true ;
subdivisableFace[old].second = subdivisable ;
}
if(subdivisable)
{
subdivisableFace[old].first = false ;
PFP::AGENTS oldAgents(agentvect[old]);
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
popAgentInCells(*ait, old);
neighborAgentvect[old].clear() ;
map.setCurrentLevel(fLevel) ;
dd = map.phi1(dd);
CellMarkerStore newF(map, FACE_CELL);
newF.mark(old);
Algo::IHM::subdivideFace<PFP>(map, old, position) ;
map.setCurrentLevel(map.getMaxLevel()) ;
} while(dd != old);
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
{
resetAgentInFace(*ait) ;
pushAgentInCells(*ait, (*ait)->part_.d) ;
}
if(degree == 3)
{
Dart centerFace = map.phi2(map.phi1(old));
Dart d3 = centerFace;
unsigned int degree = 0;
Dart dd = old;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
while(d4 != d3)
++degree;
Dart d3 = dd;
do
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
}
d3 = map.phi1(d3);
} while(d3 != centerFace);
Dart d4 = map.alpha1(map.alpha1(d3));
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
}
d3 = map.phi1(d3);
} while(d3 != dd);
map.setCurrentLevel(fLevel) ;
dd = map.phi1(dd);
map.setCurrentLevel(map.getMaxLevel()) ;
} while(dd != old);
if(degree == 3)
{
Dart centerFace = map.phi2(map.phi1(old));
Dart d3 = centerFace;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
}
d3 = map.phi1(d3);
} while(d3 != centerFace);
}
}
}
}
......
#include "simulator.h"
<<<<<<< HEAD
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.1f)
=======
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.25f)
>>>>>>> e5aa38ee0dabd0a950a9aaa810f5f2fa6eb90d29
{
srand(10);
envMap_.init();
std::cout << "setup scenario" << std::endl;
// importAgents("myAgents.pos");
setupScenario();
importAgents("myAgents.pos");
// setupScenario();
// addPathsToAgents();
for(unsigned int i = 0; i < agents_.size(); ++i)
{
......@@ -234,4 +238,3 @@ void Simulator::swapAgentsGoals()
}
}
}
......@@ -25,19 +25,10 @@
#include "viewer.h"
#include <string>
/**********************************************************************************************
* MyGlutWin IMPLEMENTATION *
**********************************************************************************************/
MyGlutWin::MyGlutWin(int* argc, char **argv, int winX, int winY) :
SimpleGlutWin(argc, argv, winX, winY)
{}
void MyGlutWin::init()
SocialAgents::SocialAgents()
{
explode = 0.9f;
b_animate = false;
render_anim = false;
nbGenerated = 0;
......@@ -48,15 +39,32 @@ void MyGlutWin::init()
glEnable( GL_POINT_SMOOTH );
visu = 0;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
}
void MyGlutWin::myRedraw()
void SocialAgents::initGUI()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setDock(&dock) ;
}
if(b_animate)
animate();
void SocialAgents::cb_initGL()
{
Utils::GLSLShader::setCurrentOGLVersion(1) ;
setFocal(5.0f) ;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(sim.envMap_.map, sim.envMap_.position) ;
VEC3 gPosObj = bb.center() ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
setParamObject(gWidthObj, gPosObj.data());
}
void SocialAgents::cb_redraw()
{
glDisable(GL_LIGHTING);
glColor3f(0.5f,0.5f,0.5f);
......@@ -139,39 +147,6 @@ void MyGlutWin::myRedraw()
renderDart(sim.envMap_, d);
}
}
/*
glColor3f(0.0f, 1.0f, 0.0f);
glLineWidth(5.0f);
CellMarker dmb(sim.envMap_.map, FACE_CELL);
for(Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
{
if(!dmb.isMarked(d))
{
dmb.mark(d);
if(sim.envMap_.buildingMark.isMarked(d))
{
VEC3 c = Algo::Geometry::faceCentroid<PFP>(sim.envMap_.map, d, sim.envMap_.position);
glBegin(GL_LINES);
Dart dd = d;
do
{
VEC3 p1 = sim.envMap_.position[dd];
VEC3 p2 = sim.envMap_.position[sim.envMap_.map.phi1(dd)];
VEC3 vec = c - p1;
p1 = p1 + vec*0.25f;
vec = c - p2;
p2 = p2 + vec*0.25f;
glVertex3f(p1[0],p1[1],p1[2]);
glVertex3f(p2[0],p2[1],p2[2]);
dd = sim.envMap_.map.phi1(dd);
} while(dd != d);
glEnd();
}
}
}
*/
glPushMatrix();
glBegin(GL_LINES);
......@@ -203,6 +178,39 @@ void MyGlutWin::myRedraw()
glPopMatrix();
//count fps
// glColor3f(0.0f, 1.0f, 0.0f);
// glLineWidth(5.0f);
// CellMarker dmb(sim.envMap_.map, FACE_CELL);
// for(Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
// {
// if(!dmb.isMarked(d))
// {
// dmb.mark(d);