Commit 94af8198 authored by Thomas Pitiot 's avatar Thomas Pitiot

up

parent 6ea92056
#ifndef ArticulatedObject_H
#define ArticulatedObject_H
#include <iostream>
#include "glm/glm.hpp"
#include "env_map.h"
#include "utils.h"
//particules
using namespace CGoGN ;
class Simulator;
class ArticulatedObject
{
public :
ArticulatedObject();
virtual ~ArticulatedObject();
inline const VEC3& getPosition(int index) const
{
return getParticule(index)->getPosition();
}
const VEC3& getPositionSegment(int index) const
{
return getParticule((Segments_[index])->indexPart1)->getPosition();
}
const Particule* getParticule(int index) const
{
return parts_[index];
}
Particule* getParticule(int index)
{
return parts_[index];
}
inline const int& getNeedForSubd(int index) const
{
return partNeedReset[index];
}
inline const int& getNeedForSubd(int index)
{
return partNeedReset[index];
}
inline void setNeedForSubd(int index, int b)
{
partNeedReset[index]=b;
}
inline const int& getNeedForSimplif(int index) const
{
return partNeedResetSimplif[index];
}
inline const int& getNeedForSimplif(int index)
{
return partNeedResetSimplif[index];
}
inline void setNeedForSimplif(int index, int b)
{
partNeedResetSimplif[index]=b;
}
const Segment* getSegment(int index) const
{
return Segments_[index];
}
inline void setSimulator(Simulator* sim)
{
sim_ = sim;
}
void addGeneralCell ( Dart d);
bool removeGeneralCell (Dart d);
void addGeneralNeighbor ( Dart d);
bool removeGeneralNeighbor (Dart d);
void needResetSegment(Segment * o);
void needResetSimplifSegment(Segment * o);
unsigned int nbVertices;
unsigned int nbEdges;
std::vector<Particule*> parts_ ;
std::vector<int>partNeedReset;
std::vector<int>partNeedResetSimplif;
std::vector<Segment *> Segments_;
std::vector< std::vector<Dart> > belonging_cells;
std::vector< std::vector<Dart> > neighbor_cells;
std::vector<std::pair<Dart, int> > general_belonging;
std::vector<std::pair<Dart, int> > general_neighbors;
double width;
Simulator* sim_;
unsigned int index_articulated;
virtual void changeColor(Segment * s, float distance)=0;
float r;
float g;
float b;
float distanceColorationMini;
float distanceColorationMaxi;
};
#endif
#ifndef MovingObject_H
#define MovingObject_H
#include "ArticulatedObject.h"
//particules
using namespace CGoGN ;
class Simulator;
class MovingObject : public ArticulatedObject
{
public :
virtual void move(VEC3 diff)=0;
virtual void updateRegistration()=0;
virtual void color_close()=0;
virtual void unColor_close(Dart oldCell)=0;
virtual Dart refine()=0;
void changeColor(Segment * s, float distance);
bool Needle_or_knife;
VEC3 closest_point; //temp
};
#endif
#ifndef Agent_H
#define Agent_H
#include "env_map.h"
#include "utils.h"
#include "Algo/MovingObjects/MovingObject.h"
#include "Algo/MovingObjects/ParticleAgent.h"
//particules
typedef CGoGN::Algo::Volume::MovingObjects::MovingObject MovingObject;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleAgent ParticleAgent;
typedef CGoGN::Algo::Volume::MovingObjects::mapOperators mapOperators;
using namespace CGoGN ;
class Simulator;
class Agent
class Agent : public ParticleAgent, public MovingObject
{
public:
Agent(Simulator* sim,VEC3 startingPoint,std::vector<VEC3> goals);
Agent(Simulator* sim, VEC3 startingPoint,std::vector<VEC3> goals,Dart d) ;
~Agent();
void init(Simulator * sim ,VEC3 startingPoint,std::vector<VEC3> goals,Dart d);
Agent(mapOperators * operators, int numAgent, VEC3 startingPoint, std::vector<VEC3> goals, float timeStep_);
void init(mapOperators * operators , int numAgent, VEC3 startingPoint,std::vector<VEC3> goals, float timeStep_);
VEC3 getPosition();
void updatePosition();
void updatePosition( );
void updateNeighbors() ;
void computeNewVelocity();
//particule
Particule * part_;
void computeNewVelocity( );
static float radius; // taille de l'agent
static float averageVelocity; // vitesse moyenne d'un agent
......@@ -36,7 +28,7 @@ public:
std::vector<VEC3> goals_ ;
//vitesses
VEC3 newVelocity_ ;
VEC3 forces;
double ag_stiffness; // agent-agent interaction stiffness
double ag_damping ; // agent-agent interaction damping
......@@ -44,33 +36,32 @@ public:
float maxVelocity_;
void move(VEC3 diff);
void updateRegistration();
void color_close();
void unColor_close(Dart oldCell);
//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_;
std::vector<std::pair<float, ParticleAgent*> > agentNeighbors_ ;
// std::vector<std::pair<float, Segment*> > segmentNeighbors_ ;
// std::vector<std::pair<float, Triangle*> > triangleNeighbors_;
//avec les distances de détection
float neighborAgDistSq_;
float neighborSegDistSq_;
float neighborTriDistSq_;
// float neighborSegDistSq_;
// float neighborTriDistSq_;
//calcul des répulsions
void goalAttraction();
void avoidanceAgents();
void avoidanceSegments();
void avoidanceTriangles();
void avoidanceAgents( );
// void avoidanceSegments();
// void avoidanceTriangles();
// nb de voisins considérés par l'évitement
// int maxNeighbors_ ;
//couleur
float r;
float g;
float b;
//lien simulateur
unsigned int agentNo ;
Simulator* sim_;
bool alive;
float timeStep_;
};
......
......@@ -2,9 +2,10 @@
#define ENV_MAP_H
//#define DEBUG_affichage
#define DEBUG_affichage
//#define DEBUG
#include <iostream>
#include <algorithm>
#include <chrono>
......@@ -27,285 +28,31 @@
#include "Algo/Geometry/volume.h"
#include "Algo/Geometry/area.h"
/////////////////particules
#include "Algo/MovingObjects/particle_cell_3D_memo.h"
#include "Algo/MovingObjects/mapOperators.h"
using namespace CGoGN ;
#include "pfp.h"
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP> Particule;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticuleMemo;
#include "segment.h"
#include "triangle.h"
#include "agent.h"
typedef CGoGN::Algo::Volume::MovingObjects::mapOperators mapOperators;
class EnvMap
{
public:
std::chrono::duration<double> duration_pop, duration_subdiv, duration_push;
// std::chrono::duration<double> duration_pop, duration_subdiv, duration_push;
EnvMap() ;
void init(int argc, char **argv) ;
bool checkPointInMap(VEC3 pos,Dart neighborhood);
bool checkPointInCube(VEC3 pos);
bool checkFaces(); // vérifie que tous les points des faces sont bien coplanaires si ce n'eest pas le cas renvoie true
bool insideVolume(VEC3 pos, Dart d);
REAL volumeMaxdistance(Vol volume);
VEC3 normaleFromVolume(Dart volume,Dart face);
void open_file(std::string filename);
VolumeAttribute<VEC3, MAP> color ;
float mapMinX;
float mapMaxX;
float mapMinY;
float mapMaxY;
float mapMinZ;
float mapMaxZ;
float maxCellRay;
void resetPartNeighborsFace(Dart neighbor, unsigned int vLevel);
void simplifyNeedle(Dart celltoSimplify, Dart needleCell);
bool simplifyCellAgents(Dart volume);
bool simplifyVolume (Dart d , CellMarkerMemo<MAP,VOLUME>& smallCells );
bool subdivideVolume(Dart d );
void subdivideToMaxLevel();
bool subdivideMap();
bool simplifyMap();
Dart getBelongingCell(const PFP::VEC3& pos);
unsigned int nbAgentsToSubdivide;
unsigned int nbAgentsToSimplify;
void init(int argc, char **argv) ;
PFP::MAP map ;
CellMarkerMemo<MAP,VOLUME> refineMark;
CellMarkerMemo<MAP,VOLUME> simplifyMark;
VertexAttribute<VEC3, MAP> position ;
FaceAttribute<VEC3, MAP> facecenter;
VolumeAttribute<VEC3, MAP> color ;
VolumeAttribute<VEC3, MAP> volumecenter;
VolumeAttribute<AGENTS,MAP> RegisteredAgents;
VolumeAttribute<AGENTS,MAP> RegisteredNeighborAgents;
VolumeAttribute<ARETES, MAP> RegisteredEdges ;
VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
VolumeAttribute<TRIANGLES, MAP> RegisteredTriangles ;
VolumeAttribute<TRIANGLES, MAP> RegisteredNeighborTriangles ;
VolumeAttribute<Dart, MAP> OldestDart;
VolumeAttribute<bool,MAP> CellOnMaxLevel; // remplacer par marker ?
Geom::BoundingBox<PFP::VEC3> bb;
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, unsigned int state);
void FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Dart popAndPushSegment(Segment* o);
void FirstRegistrationSegment(Segment * mo);
void pushAOneCellSegment(Segment * o, Dart d);
void pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_cross);
void popSegment(Segment* o);
void pushSegmentInCellAsNeighbor(Segment* o, Dart d);
void popSegmentInCellAsNeighbor(Segment* o, Dart d);
void resetPartSubdiv(Segment* o);
void resetPartSimplif(Segment* cell, Dart d);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Enregistrement Surfaces
void popAndPushTriangle(Triangle* o); // pop et push d'une Triangle
void FirstRegistrationTriangle (Triangle* o); // premier enregistrement d'une Triangle
void markNeighbors(CellMarkerMemo<MAP,VOLUME> * memo_mark, CellMarkerMemo<MAP,VOLUME> * OneRingMark, const std::vector<Dart>& memo_cross); // marker les cellules voisines d'un ensemble de cellules retenu dans memo_cross
void popTriangle(Triangle* o);
void pushTriangleInCell(Triangle* o, Dart d);
void popTriangleInCell(Triangle* o, Dart d);
void pushTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void popTriangleInCellAsNeighbor(Triangle* cell, Dart d);
void resetPartSubdiv(Triangle* cell);
void resetPartSimplif(Triangle* cell, Dart d);
/// enregistrement des agents
void agentChangeFace(Agent * ag , Dart oldCell);
void popAgent(Agent * agent,Dart oldCell) ;
void pushAgent(Agent * agent,Dart newVolume) ;
void pushAgentInCell(Agent* o, Dart d);
void popAgentInCell(Agent* o, Dart d);
void pushAgentInCellAsNeighbor(Agent* cell, Dart d);
void popAgentInCellAsNeighbor(Agent* cell, Dart d);
#ifndef IHMap
Dart volumeLowestIndex(Dart v);
#endif
mapOperators* operators;
bool intersect_SegmentTriangle( VEC3 s0, VEC3 s1,VEC3 t1, VEC3 t2, VEC3 t3, VEC3& I );
} ;
/**************************************
* INLINE FUNCTIONS *
**************************************/
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
template <typename T>
inline bool addElementToVector(std::vector<T>& a, T ag)
{
if (std::find(a.begin(), a.end(), ag) == a.end())
{
a.push_back(ag) ;
return true;
}
return false;
}
template <typename T>
inline bool removeElementFromVector(std::vector<T>& a, T ag)
{
typedef typename std::vector<T>::iterator iterator;
iterator it = std::find(a.begin(), a.end(), ag);
if (it == a.end())
{
return false;
} else {
*it = a.back();
a.pop_back();
}
return true;
}
/////////////////////////////////////////////////////////////////////REGISTRATIONS
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1 , unsigned int state)
{
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticleCell3DMemo;
ParticleCell3DMemo part(map, d1, pos,position,&facecenter,&volumecenter);
part.setState(state);
return part.move(dest);
}
inline void EnvMap::pushAgentInCell(Agent* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector(RegisteredAgents[d],o);
}
inline void EnvMap::popAgentInCell(Agent* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
removeElementFromVector(RegisteredAgents[d],o);
}
inline void EnvMap::pushAgentInCellAsNeighbor(Agent* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector(RegisteredNeighborAgents[d],o);
}
inline void EnvMap::popAgentInCellAsNeighbor(Agent* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
removeElementFromVector(RegisteredNeighborAgents[d],o);
}
inline void EnvMap::FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(!belonging_cells.empty());
neighbor_cells->clear();
CellMarkerMemo<MAP,VOLUME> memo_mark(map); //marqueur des cellules "présentes"
CellMarkerMemo<MAP,VOLUME> OneRingMark(map); // marquer des cellules voisines
for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
memo_mark.mark(*it);
for( Dart dd : belonging_cells)
{
for (Vol d : volumesAdjacentByVertex3(map,dd))
{
if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
{
OneRingMark.mark(d);
#ifdef IHMap
(*neighbor_cells).push_back(OldestDart[d]);
#else
(*neighbor_cells).push_back(volumeLowestIndex(d));
#endif
}
}
}
}
inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector(RegisteredNeighborEdges[d],o);
}
inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
removeElementFromVector(RegisteredNeighborEdges[d],o);
}
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector(RegisteredNeighborTriangles[d],o);
}
inline void EnvMap::popTriangleInCellAsNeighbor(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
removeElementFromVector(RegisteredNeighborTriangles[d],o);
}
inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector(RegisteredTriangles[d],o);
}
inline void EnvMap::popTriangleInCell(Triangle* o, Dart d)
{
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
removeElementFromVector(RegisteredTriangles[d],o);
}
#endif
#ifndef Knife_H
#define Knife_H
#include "MovingObject.h"
//particules
using namespace CGoGN ;
class Simulator;
class Knife : public MovingObject
{
public:
Knife(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints) ;
void updateRegistration();
void move(VEC3 diff);
void color_close();
void unColor_close(Dart oldCell);
Dart refine();
};
#endif
#ifndef Needle_H
#define Needle_H
#include "MovingObject.h"
//particules
using namespace CGoGN ;
class Simulator;
class Needle : public MovingObject
{
public:
Needle(Simulator* sim, std::pair<VEC3, Dart> startingPoint) ;
void move(VEC3 diff);
void updateRegistration();
void createEdge(int index);
// Fonctions sur la coloration
void color_close();
void unColor_close(Dart oldCell);
float edgeSize;
Dart oldCell;
Dart refine();
};
#endif
#ifndef PFP_H_
#define PFP_H_
// carte
#define IHMap
#ifndef IHMap
#include "Topology/map/embeddedMap3.h"
#include "Algo/Modelisation/tetrahedralization.h"
#else
#include "Algo/ImplicitHierarchicalMesh/ihm3.h"
#include "Algo/ImplicitHierarchicalMesh/subdivision3.h"
#endif
#include "Topology/ihmap/ihm2.h"
#include "Algo/Multiresolution/IHM2/ihm2_PrimalAdapt.h"
#include "Algo/Multiresolution/Map2MR/Masks/loop.h"
#include "Algo/Multiresolution/Map2MR/Masks/lerp.h"
#include "Algo/Multiresolution/Map2MR/Masks/catmullClark.h"
#include "Algo/Multiresolution/Map2MR/Masks/sqrt3.h"
#include "Topology/generic/parameters.h"
class Segment;
class Triangle;
class Agent;
typedef enum
{
LOOP = 0,
LERP,
CATC,
SQRT3
} SubdivisionType;
struct PFP : public PFP_STANDARD
{
// definition de la carte
// typedef Algo::Volume::IHM::ImplicitHierarchicalMap3 MAP ;
#ifndef IHMap
typedef EmbeddedMap3 MAP;
#else
typedef CGoGN::Algo::Volume::IHM::ImplicitHierarchicalMap3 MAP;
#endif
// definition des listes d'arêtes
typedef std::vector<Segment*> ARETE ;
typedef NoTypeNameAttribute<ARETE> ARETES ;
typedef std::vector<Agent*> AGENT ;
typedef NoTypeNameAttribute<AGENT> AGENTS ;
typedef std::vector<Triangle*> TRIANGLE ;
typedef NoTypeNameAttribute<TRIANGLE> TRIANGLES ;
//
// typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
struct PFPSurface : public PFP_STANDARD
{
// definition de la carte
typedef CGoGN::ImplicitHierarchicalMap2 MAP;
} ;
typedef PFPSurface::MAP SurfaceMap;
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
typedef PFP::AGENTS AGENTS;
typedef PFP::ARETES ARETES;
typedef PFP::TRIANGLES TRIANGLES;
#endif /* PFP_H_ */
#ifndef _Segment_H_
#define _Segment_H_
class ArticulatedObject;
class Segment
{
public:
Segment(const VEC3 point1, const VEC3 point2,
ArticulatedObject * Needle =NULL,unsigned int indexP1=0,unsigned int indexP2=0, unsigned int ind=0,float rouge=0,float green =0, float blue=1.0f) :
p1(point1), p2(point2),
nid(Needle),indexPart1(indexP1),indexPart2(indexP2), index(ind),r(rouge),g(green),b(blue)
{
}
VEC3 p1 ;
VEC3 p2 ;
// colors
ArticulatedObject * nid ;
unsigned int indexPart1;
unsigned int indexPart2;
unsigned int index ;
float r;
float g;
float b;
} ;
#endif
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include "needle.h"
#include "knife.h"
#include "tree.h"
#include "surface.h"
#include "agent.h"
#include "env_map.h"
#include <iostream>
#include <string>
#include <fstream>
......@@ -21,10 +18,6 @@ public:
void init(int argc, char **argv);
void doStep();
void initAgents(int nbAgents);
void initMovingObject();
void initSurfaces();