Commit e3b6c3f3 authored by Etienne Schmitt's avatar Etienne Schmitt

small improvements

Signed-off-by: Etienne Schmitt's avatarÉtienne Schmitt <etienne.schmitt@inria.fr>
parent a1267f46
......@@ -14,20 +14,52 @@ class Simulator;
class ArticulatedObject
{
public :
VEC3 getPositionSegment(int index) ;
ArticulatedObject();
virtual ~ArticulatedObject();
inline const VEC3& getPosition(int index) const
{
return parts_[index]->getPosition();
}
const VEC3& getPositionSegment(int index) const
{
return parts_[(Segments_[index])->indexPart1]->getPosition();
}
const PARTICULE* getParticule(int index) const
{
return parts_[index];
}
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);
VEC3 getPosition(int index);
unsigned int nbVertices;
unsigned int nbEdges;
std::vector<PARTICULE*> parts_ ;
std::vector<Segment *> Segments_;
std::vector<Dart> * belonging_cells;
std::vector<Dart> * neighbor_cells;
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;
......
......@@ -125,10 +125,14 @@ public:
**************************************/
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
template <typename T>
inline void addElementToVector(std::vector<T>& a, T ag)
inline bool addElementToVector(std::vector<T>& a, T ag)
{
assert(std::find(a.begin(), a.end(), ag) == a.end());
a.push_back(ag) ;
if (std::find(a.begin(), a.end(), ag) == a.end())
{
a.push_back(ag) ;
return true;
}
return false;
}
template <typename T>
......@@ -150,13 +154,8 @@ inline bool removeElementFromVector(std::vector<T>& a, T ag)
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
{
CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> * registering_part = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP>(map, d1,pos,position);
std::vector<Dart> result =(registering_part->move(dest));
// d2=registering_part->d;
// CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
return result;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticleCell3DMemo;
return ParticleCell3DMemo(map, d1, pos,position).move(dest);
}
......@@ -197,9 +196,7 @@ inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) == RegisteredNeighborEdges[d].end());
addElementToVector<Segment*>(RegisteredNeighborEdges[d],o);
addElementToVector(RegisteredNeighborEdges[d],o);
}
......@@ -208,9 +205,7 @@ inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) != RegisteredNeighborEdges[d].end());
removeElementFromVector<Segment*>(RegisteredNeighborEdges[d],o);
removeElementFromVector(RegisteredNeighborEdges[d],o);
}
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle* o, Dart d)
......@@ -218,9 +213,7 @@ inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle* o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) == RegisteredNeighborTriangles[d].end());
addElementToVector<Triangle *>(RegisteredNeighborTriangles[d],o);
addElementToVector(RegisteredNeighborTriangles[d],o);
}
......@@ -229,9 +222,7 @@ inline void EnvMap::popTriangleInCellAsNeighbor(Triangle* o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) != RegisteredNeighborTriangles[d].end());
removeElementFromVector<Triangle* >(RegisteredNeighborTriangles[d],o);
removeElementFromVector(RegisteredNeighborTriangles[d],o);
}
......@@ -241,9 +232,7 @@ inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) == RegisteredTriangles[d].end());
addElementToVector<Triangle* >(RegisteredTriangles[d],o);
addElementToVector(RegisteredTriangles[d],o);
}
......@@ -252,9 +241,7 @@ inline void EnvMap::popTriangleInCell(Triangle* o, Dart d)
#ifdef IHMap
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) != RegisteredTriangles[d].end());
removeElementFromVector<Triangle* >(RegisteredTriangles[d],o);
removeElementFromVector(RegisteredTriangles[d],o);
}
......
......@@ -26,7 +26,7 @@ inline float det2D(const VEC3& vector1, const VEC3& vector2)
inline float abs (float x)
{
return (x) >= 0 ? (x) : -(x);
return std::abs<float>(x);
}
......
......@@ -6,10 +6,38 @@
*/
ArticulatedObject::ArticulatedObject() :
nbVertices(0u)
,nbEdges(0u)
,parts_(std::vector<PARTICULE*>())
,Segments_(std::vector<Segment *>())
,belonging_cells(NULL)
,neighbor_cells(NULL)
, width(0.)
, sim_(NULL)
,index_articulated(0u)
,r(0.0f)
,g(0.0f)
,b(0.0f)
,distanceColorationMini(0.0f)
,distanceColorationMaxi(0.0f)
{
}
ArticulatedObject::~ArticulatedObject() {
for (auto p : parts_)
delete p;
for (auto s : Segments_)
delete s;
}
void ArticulatedObject::addGeneralCell ( Dart d)
{
bool added = false;
for(std::pair<Dart,int> pere : general_belonging)
for(std::pair<Dart,int>& pere : general_belonging)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -29,7 +57,7 @@ void ArticulatedObject::addGeneralCell ( Dart d)
*/
bool ArticulatedObject::removeGeneralCell (Dart d)
{
for(std::pair<Dart,int> pere : general_belonging)
for(std::pair<Dart,int>& pere : general_belonging)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -50,7 +78,7 @@ bool ArticulatedObject::removeGeneralCell (Dart d)
void ArticulatedObject::addGeneralNeighbor ( Dart d)
{
bool added = false;
for(std::pair<Dart,int> pere : general_neighbors)
for(std::pair<Dart,int>& pere : general_neighbors)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -70,7 +98,7 @@ void ArticulatedObject::addGeneralNeighbor ( Dart d)
*/
bool ArticulatedObject::removeGeneralNeighbor (Dart d)
{
for(std::pair<Dart,int> pere : general_neighbors)
for(std::pair<Dart,int>& pere : general_neighbors)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -88,15 +116,6 @@ bool ArticulatedObject::removeGeneralNeighbor (Dart d)
return false;
}
VEC3 ArticulatedObject::getPosition(int index)
{
return parts_[index]->getPosition();
}
VEC3 ArticulatedObject::getPositionSegment(int index)
{
return parts_[(Segments_[index])->indexPart1]->getPosition();
}
......
......@@ -284,8 +284,9 @@ void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en
memo = getMemoCross(p1,p2,d1);
if(map.sameVolume(d1,d2))
if(memo.size() == 1u)
{
std::cout << "COUCOU !! " << std::endl;
pushAOneCellSegment(o , d1);
}
else
......@@ -304,7 +305,7 @@ Dart EnvMap::popAndPushSegment(Segment* o)// maj de l'enregistrement
popSegment(o);
FirstRegistrationSegment(o);
return o->nid->parts_[o->indexPart1]->d;;
return o->nid->parts_[o->indexPart1]->d;
}
void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
......@@ -318,7 +319,7 @@ void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
addElementToVector<Segment*>(RegisteredEdges[d],o);
addElementToVector(RegisteredEdges[d],o);
mo->belonging_cells[n].push_back(d);
mo->addGeneralCell (d);
......@@ -358,7 +359,7 @@ void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_c
for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin(); it != mo->belonging_cells[n].end(); ++it)
{
addElementToVector<Segment*>(RegisteredEdges[*it],o);
addElementToVector(RegisteredEdges[*it],o);
mo->addGeneralCell ( (*it));
#ifdef DEBUG_affichage
CGoGNout<<"cellule du belong :"<<(*it)<<CGoGNendl;
......@@ -371,7 +372,7 @@ void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_c
{
if (!map.isBoundaryMarked<3>(*it))
{
addElementToVector<Segment*>(RegisteredNeighborEdges[*it],o);
addElementToVector(RegisteredNeighborEdges[*it],o);
mo->addGeneralNeighbor ( (*it));
}
}
......@@ -398,16 +399,16 @@ void EnvMap::popSegment(Segment* o)
if (mo != NULL)
{
for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin(); it != mo->belonging_cells[n].end(); ++it)
for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin(), end = mo->belonging_cells[n].end() ; it != end ; ++it)
{
removeElementFromVector<Segment*>(RegisteredEdges[*it], o) ;
removeElementFromVector(RegisteredEdges[*it], o) ;
mo->removeGeneralCell (*it);
}
for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it)
for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(), end = mo->neighbor_cells[n].end() ; it != end ; ++it)
{
if (!map.isBoundaryMarked<3>(*it))
{
removeElementFromVector<Segment*>(RegisteredNeighborEdges[*it], o) ;
removeElementFromVector(RegisteredNeighborEdges[*it], o) ;
mo->removeGeneralNeighbor (*it);
}
}
......
......@@ -12,8 +12,8 @@ Knife::Knife(Simulator* sim,std::vector<std::pair<VEC3, Dart>> startingPoints)
nbVertices=startingPoints.size();
nbEdges=nbVertices==0?0:nbVertices-1;
index_articulated=sim->objects.size();
belonging_cells = new std::vector<Dart>[nbEdges];
neighbor_cells = new std::vector<Dart>[nbEdges];
belonging_cells.resize(nbEdges);
neighbor_cells.resize(nbEdges);
for (auto it =startingPoints.begin();it!=startingPoints.end();++it)
......
......@@ -17,8 +17,8 @@ Needle::Needle(Simulator* sim,std::pair<VEC3, Dart> startingPoint)
int maxEdges = 10000;
distanceColorationMaxi=0.25f;
distanceColorationMini=5.0f;
belonging_cells = new std::vector<Dart>[maxEdges];
neighbor_cells = new std::vector<Dart>[maxEdges];
belonging_cells.resize(maxEdges);
neighbor_cells.resize(maxEdges);
index_articulated=sim->objects.size();
......
......@@ -285,7 +285,7 @@ void Surface::changeColor(Triangle *t , float distance)
void Surface::addGeneralCell ( Dart d)
{
bool added = false;
for(std::pair<Dart,int> pere : general_belonging)
for(std::pair<Dart,int>& pere : general_belonging)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -305,7 +305,7 @@ void Surface::addGeneralCell ( Dart d)
*/
bool Surface::removeGeneralCell (Dart d)
{
for(std::pair<Dart,int> pere : general_belonging)
for(std::pair<Dart,int>& pere : general_belonging)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -326,7 +326,7 @@ bool Surface::removeGeneralCell (Dart d)
void Surface::addGeneralNeighbor ( Dart d)
{
bool added = false;
for(std::pair<Dart,int> pere : general_neighbors)
for(std::pair<Dart,int>& pere : general_neighbors)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......@@ -346,7 +346,7 @@ void Surface::addGeneralNeighbor ( Dart d)
*/
bool Surface::removeGeneralNeighbor (Dart d)
{
for(std::pair<Dart,int> pere : general_neighbors)
for(std::pair<Dart,int>& pere : general_neighbors)
{
if(sim_->envMap_.map.sameVolume(pere.first,d))
{
......
......@@ -13,8 +13,8 @@ Tree::Tree(Simulator* sim, std::vector<std::pair<VEC3, Dart>> startingPoints, st
nbEdges=segmentParts.size();
distanceColorationMaxi=0.25f;
distanceColorationMini=5.0f;
belonging_cells = new std::vector<Dart>[nbEdges];
neighbor_cells = new std::vector<Dart>[nbEdges];
belonging_cells.resize(nbEdges);
neighbor_cells.resize(nbEdges);
for (auto it =startingPoints.begin();it!=startingPoints.end();++it)
......
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