Commit b8f34fe9 authored by Pierre Kraemer's avatar Pierre Kraemer

bla bli blu

parents
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
# a decommenter si on veut voir ce qui se passe a la compilation
#set( CMAKE_VERBOSE_MAKEFILE 1 )
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../../CGoGN)
SET(CMAKE_MODULE_PATH " ${CMAKE_MODULE_PATH} ${CGoGN_ROOT_DIR}/cmake_modules/")
find_package(OpenGL)
find_package(GLUT)
# 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")
ENDIF(APPLE)
IF(WIN32)
SET(GLEW_LIBRARY glew32)
SET(DEVIL_LIBRARIES DevIL ILU ILUT)
SET(ZLIB_LIBRARIES zlib)
SET(LIBXML2_LIBRARIES xml2)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/dependencies/include/)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/dependencies/lib/)
ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
find_package(DevIL)
find_package(ZLIB)
find_package(LibXml2)
SET(GLEW_LIBRARY GLEW)
IF (IL_LIBRARIES)
SET(DEVIL_LIBRARIES ${IL_LIBRARIES} ${ILU_LIBRARIES} ${ILUT_LIBRARIES})
ELSE(IL_LIBRARIES)
SET(DEVIL_LIBRARIES ${IL_LIBRARY} ${ILU_LIBRARY} ${ILUT_LIBRARY})
ENDIF(IL_LIBRARIES)
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 )
add_subdirectory(Release)
add_subdirectory(Debug)
cmake_minimum_required(VERSION 2.6)
project(SocialAgents)
SET(CMAKE_BUILD_TYPE Debug)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
link_directories(
${CGoGN_ROOT_DIR}/lib/Debug/
${CGoGN_ROOT_DIR}/lib/Release/
)
# define includes path
include_directories(
/usr/include/libxml2/
../include
${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
)
#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} boost_thread-mt)
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/
../include
${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
)
#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} boost_thread-mt)
#ifndef M_AGENT_H
#define M_AGENT_H
#include <iostream>
#include "utils.h"
#include "env_map.h"
#include "Algo/MovingObjects/particle_cell_2D.h"
class Simulator;
class Agent
{
public:
Agent(Simulator* sim, const VEC3& position, Dart d);
void insertAgentNeighbor(Agent* other);
void insertAgentNeighbor(Agent* other, float distSq);
void removeAgentNeighbor(Agent* other);
void updateAgentNeighbors();
void clearAgentNeighbors();
void insertObstacleNeighbor(Dart d);
void removeObstacleNeighbor(Dart d);
void updateObstacleNeighbors();
void clearObstacleNeighbors();
void update();
void computePrefVelocity();
void computeNewVelocity();
bool linearProgram1(
const std::vector<Line>& lines, unsigned int lineNo,
float radius, const VEC3& optVelocity,
bool directionOpt, VEC3& result
);
bool linearProgram2(
const std::vector<Line>& lines, unsigned int num, float radius,
const VEC3& optVelocity, bool directionOpt,
VEC3& result
);
void linearProgram3(
const std::vector<Line>& lines, unsigned int numObstLines,
float radius, VEC3& result
);
std::multimap<float, Agent*> agentNeighbors_;
std::multimap<float, Agent*> newAgentNeighbors_;
// std::map<const Agent*, std::multimap<float, Agent*>::iterator> neighborsIt_;
std::multimap<float, Dart> obstacleNeighbors_;
std::multimap<float, Dart> newObstacleNeighbors_;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_;
std::vector<VEC3> goals_;
unsigned int curGoal_;
size_t maxNeighbors_;
float maxSpeed_;
float neighborDistSq_;
float radius_;
float timeHorizon_;
float timeHorizonObst_;
float rangeSq_;
VEC3 velocity_;
VEC3 newVelocity_;
VEC3 prefVelocity_;
Simulator* sim_;
bool treated;
};
#endif
#ifndef ENV_GENERATOR
#define ENV_GENERATOR
#include "Container/fakeAttribute.h"
namespace CGoGN
{
namespace CityGenerator
{
template <typename PFP>
bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker& buildingMark);
template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateGrid(typename PFP::MAP& map, typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength, CellMarker& obstacleMark, CellMarker& buildingMark);
template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& buildingMark, float height);
template <typename PFP>
void generateBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, float height, unsigned int buildingType, CellMarker& obstacleMark, CellMarker& buildingMark);
template <typename PFP>
void generateCity(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize, unsigned int nbSquares);
template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position);
template <typename PFP>
bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area);
template <typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& obstacleMark);
template <typename PFP>
void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark);
}
}
#include "env_generator.hpp"
#endif
#include "Algo/Modelisation/subdivision.h"
#include "Geometry/inclusion.h"
namespace CGoGN
{
namespace CityGenerator
{
template <typename PFP>
bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker& buildingMark)
{
Dart dd = d;
do
{
if(buildingMark.isMarked(map.alpha1(map.alpha1(dd))))
return false;
dd = map.phi1(dd);
} while(dd != d);
return true;
}
template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateGrid(typename PFP::MAP& map, typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength, CellMarker& obstacleMark, CellMarker& buildingMark)
{
Algo::Modelisation::Polyhedron<PFP> prim(map, position);
prim.grid_topo(cX, cY);
Dart boundary;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(map.phi2(d) == d)
{
obstacleMark.mark(d);
boundary = d;
}
}
map.closeHole(boundary);
buildingMark.mark(map.phi2(boundary));
prim.embedGrid(sideLength * cX, sideLength * cY);
return prim;
}
template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& buildingMark, float height)
{
Dart dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, d, height);
buildingMark.mark(dRoof);
Dart dd = dRoof;
do
{
buildingMark.mark(map.phi2(dd));
dd = map.phi1(dd);
} while(dd != dRoof);
return dRoof;
}
template <typename PFP>
void generateBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, float height, unsigned int buildingType, CellMarker& obstacleMark, CellMarker& buildingMark)
{
// mark the face as obstacle before extrusion
Dart dd = d;
do
{
obstacleMark.mark(dd);
dd = map.phi1(dd);
} while(dd != d);
Dart dRoof;
dRoof = extrudeFaceAndMark<PFP>(map, position, d, buildingMark, height);
switch(buildingType)
{
case 0 : {
break;
}
case 1 : {
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height/3);
Dart dNext = map.phi1(dRoof);
Dart dPrev = map.phi2(map.phi_1(dRoof));
map.collapseEdge(dNext);
map.collapseEdge(dPrev);
break;
}
case 2 : {
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height/3);
Dart dNext = map.phi1(dRoof);
Dart dPrev = map.phi2(map.phi_1(dRoof));
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f;
map.collapseEdge(dNext);
map.collapseEdge(dPrev);
position[dRoof] = mid2;
position[map.phi1(dRoof)] = mid1;
break;
}
case 3 : {
unsigned int nbStairs = rand() % 5;
for(unsigned int i = 0; i < nbStairs; ++i)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position);
Dart dRoofSmall = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, 0.0f);
Dart dd = dRoofSmall;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f;
dd = map.phi1(dd);
} while (dd != dRoofSmall);
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoofSmall, buildingMark, height / 2.0f);
}/*
bool spike= rand() % 2;
if(spike)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position);
c[2] += height / 1.5f;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof);
position[dRoof] = c;
}*/
break;
}
}
}
template <typename PFP>
void generateCity(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize, unsigned int nbSquares)
{
unsigned int nbBuilding = 1000;
float height = sideSize / 2.0f;
generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
Dart dEnd = map.end();
for(Dart d = map.begin(); d != dEnd && nbBuilding > 0; map.next(d))
{
if(!buildingMark.isMarked(d) && (rand() % 20 == 0) && notDiagonalAdjacentToAnObstacle<PFP>(map, d, buildingMark))
{
generateBuilding<PFP>(map, position, d, (1+(rand()%3)) * height / 2.0f, rand() % 4, obstacleMark, buildingMark);
--nbBuilding;
}
}
}
template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark)
{
typedef typename PFP::VEC3 VEC3;
typedef std::multimap<float, Dart> VEC_D_A;
AutoAttributeHandler<float> tableArea(map, FACE_ORBIT);
AutoAttributeHandler<CGoGN::NoMathIONameAttribute<VEC_D_A::iterator> > tableIt(map, EDGE_ORBIT);
VEC_D_A orderedD;
// compute all heuristic and construct multimap
Algo::Geometry::computeAreaFaces<PFP>(map, position, tableArea);
CellMarker eM(map, EDGE_CELL);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!eM.isMarked(d) && !obstacleMark.isMarked(d) && !buildingMark.isMarked(d))
{
eM.mark(d);
tableIt[d] = orderedD.insert(std::make_pair(tableArea[d] + tableArea[map.phi2(d)], d));
}
}
eM.unmarkAll();
bool stillSimplif = true;
VEC_D_A::iterator it = orderedD.begin();
if(it == orderedD.end())
stillSimplif = false;
while(stillSimplif)
{
Dart d = it->second;
if(!map.sameFace(d, map.phi2(d)))
{
// remove selected edge
float sumArea = it->first;
orderedD.erase(it);
Dart dd = map.phi1(d);
map.mergeFaces(d);
tableArea[dd] = sumArea;
// erase all edges of new face from multimap
Dart ddd = dd ;
do
{
if(!eM.isMarked(ddd) && !obstacleMark.isMarked(ddd))
{
eM.mark(ddd);
orderedD.erase(tableIt[ddd]);
}
ddd = map.phi1(ddd);
} while(ddd != dd);
// collapse edges in faces if possible
ddd = dd;
do
{
Dart dN = map.phi1(ddd);
// remove pending edges
if(map.phi2(dN) == map.phi1(dN))
{
if(dN == dd || map.phi1(dN) == dd)
dd = map.phi1(map.phi1(dN));
// VEC3 p = position[dN];
map.collapseEdge(dN);
dN = map.phi1(ddd);
// position[dN] = p;
}
// simplify vertices of valence 2 -> check if no intersection is created
if(map.alpha1(map.alpha1(dN)) == dN && !obstacleMark.isMarked(dN))
{
if(dN == dd || dN == map.phi2(dd))
dd = map.phi1(dd);
VEC3 p = position[map.phi1(dN)];
bool intersect = false;
Dart dI = map.phi1(map.phi1(dN));
VEC3 pA = position[map.phi_1(dN)];
VEC3 pB = position[map.phi1(dN)];
do
{
VEC3 p1 = position[dI];
VEC3 p2 = position[map.phi1(dI)];
if( Geom::testOrientation2D(p1, pA, pB) != Geom::testOrientation2D(p2, pA, pB) &&
Geom::testOrientation2D(pA, p1, p2) != Geom::testOrientation2D(pB, p1, p2)
)
{
if( !Geom::arePointsEquals(p1, pA) && !Geom::arePointsEquals(p1, pB) &&
!Geom::arePointsEquals(p2, pA) && !Geom::arePointsEquals(p2, pB)
)
intersect = true;
}
dI = map.phi1(dI);
} while(dI != map.phi_1(dN));
if(!intersect)
{
dN = map.phi2(dN);
Dart dI = map.phi1(map.phi1(dN));
do
{
VEC3 v;
VEC3 p1 = position[dI];
VEC3 p2 = position[map.phi1(dI)];
if( Geom::testOrientation2D(p1, pA, pB)!= Geom::testOrientation2D(p2, pA, pB) &&
Geom::testOrientation2D(pA, p1, p2)!= Geom::testOrientation2D(pB, p1, p2)
)
{
if( !Geom::arePointsEquals(p1, pA) && !Geom::arePointsEquals(p1, pB) &&
!Geom::arePointsEquals(p2, pA) && !Geom::arePointsEquals(p2, pB)
)
intersect = true;
}
dI = map.phi1(dI);
}while(dI != map.phi_1(dN));
}
if(!intersect)
{
map.collapseEdge(dN);
position[map.phi1(ddd)] = p;
}
}
ddd = map.phi1(ddd);
} while(ddd != dd);
ddd = dd;
do
{
if(eM.isMarked(ddd))
{
eM.unmark(ddd);
tableIt[ddd] = orderedD.insert(std::make_pair(tableArea[ddd] + tableArea[map.phi2(ddd)], ddd));
}
ddd = map.phi1(ddd);
} while(ddd != dd);
it = orderedD.begin();
}
else
{
++it;
}
if(it == orderedD.end())
stillSimplif = false;
}
convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.check();
}
template <typename PFP>
bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area)
{
typedef typename PFP::VEC3 VEC3;
bool check = false;
if(Geom::testOrientation2D(position[dd], position[map.phi_1(dd)], position[map.phi1(dd)]) == Geom::RIGHT)
{
VEC3 p = position[dd];
VEC3 p1 = position[map.phi1(dd)];
VEC3 p_1 = position[map.phi_1(dd)];
Dart ddd = map.phi1(map.phi1(dd));
check = true;
do
{
unsigned int incl = isPointInTriangle(position[ddd], p_1, p, p1);
if((incl == Geom::FACE_INCLUSION) || (incl == Geom::EDGE_INCLUSION))
check = false;
ddd = map.phi1(ddd);
} while(check && ddd != map.phi_1(dd));
if(check)
{
VEC3 v1(p1 - p);
VEC3 v2(p - p_1);
VEC3 v3(p_1 - p1);
area = 1.0f / std::min(std::min(Geom::angle(v1, -1.0f*v2), Geom::angle(-1.0f*v1, v3)), Geom::angle(v2, -1.0f*v3));
// area = 1.0f / Geom::triangleArea(p_1, p, p1);
}
}
return check;
}
template <typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& obstacleMark)
{
typedef typename PFP::VEC3 VEC3;
if(!obstacleMark.isMarked(d) && position[d][2] == 0.0f)
{
Dart d2 = map.phi2(d);
VEC3 p1 = position[map.phi_1(d)];
VEC3 p2 = position[d];
VEC3 p3 = position[d2];
VEC3 p4 = position[map.phi_1(d2)];
VEC3 p5 = position[map.phi1(map.phi1(d))];
VEC3 p6 = position[map.phi1(map.phi1(d2))];
if( (p1[0] != p6[0] || p1[1] != p6[1] || p1[2] != p6[2]) &&