#include "simulator.h" /*addGeneralCell * adds cell d to general belonging, if it's already present, increases the number of instance of the cell */ ArticulatedObject::ArticulatedObject() : nbVertices(0u) ,nbEdges(0u) ,parts_(std::vector()) ,Segments_(std::vector()) ,belonging_cells(std::vector>()) ,neighbor_cells(std::vector>()) , 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& pere : general_belonging) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second ++; added= true; break; } } if (!added) { general_belonging.push_back(std::make_pair(d,1)); } } /*removeGeneralCell * removes cell d to general belonging decreases the number of instance of the cell, if the number is 0 the celle is removed *forever* */ bool ArticulatedObject::removeGeneralCell (Dart d) { for(std::pair& pere : general_belonging) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second--; if(pere.second==0) { pere=general_belonging.back() ; general_belonging.pop_back() ; } return true; } }; return false; } void ArticulatedObject::addGeneralNeighbor ( Dart d) { bool added = false; for(std::pair& pere : general_neighbors) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second ++; added= true; break; } } if (!added) { general_neighbors.push_back(std::make_pair(d,1)); } } /*removeGeneralCell * removes cell d to general belonging decreases the number of instance of the cell, if the number is 0 the celle is removed *forever* */ bool ArticulatedObject::removeGeneralNeighbor (Dart d) { for(std::pair& pere : general_neighbors) { // if(sim_->envMap_.map.sameVolume(pere.first,d)) if(pere.first==d) { pere.second--; if(pere.second==0) { pere=general_neighbors.back() ; general_neighbors.pop_back() ; } return true; } }; return false; } //------------------------------------------------------------------------- //////// a implémenter //void resetPartSubdiv(Segment* o) //{ // ArticulatedObject * mo = o->mo; // // if (mo != NULL) // { // unsigned int n =o->index; // /// ajout Segments lointains // unsigned int n2; // switch (n-(mo->nbVertices)) // { // case 0 : n2=n+1; break; // case 1 : n2=n-1;break; // default : n2 =(n+1)%(mo->nbVertices); break; // } // //////// // VEC3 pos = mo->parts_[n]->getPosition(); // VEC3 pos2 = mo->parts_[n2]->getPosition(); // mo->parts_[n]->CGoGN::Algo::MovingObjects::ParticleBase::move(Algo::Volume::Geometry::faceCentroid(mo->sim_->envMap_.map, mo->parts_[n]->d, mo->sim_->envMap_.position)) ; // // mo->parts_[n]->setState(VOLUME) ; // mo->parts_[n]->move(pos) ; // // mo->parts_[n2]->CGoGN::Algo::MovingObjects::ParticleBase::move(Algo::Volume::Geometry::faceCentroid(mo->sim_->envMap_.map, mo->parts_[n2]->d, mo->sim_->envMap_.position)) ; // // mo->parts_[n2]->setState(VOLUME) ; // mo->parts_[n2]->move(pos2) ; // // mo->dDir = mo->parts_[0]->d; // } //} // //void resetObstPartInFace(Segment* o, Dart d1) //{ // ArticulatedObject * mo = o->mo; // // if (mo != NULL) // { // unsigned int n =o->index; // /// ajout Segments lointains // unsigned int n2; // switch (n-(mo->nbVertices)) // { // case 0 : n2=n+1; break; // case 1 : n2=n-1;break; // default : n2 =(n+1)%(mo->nbVertices); break; // } // //////// // VEC3 pos1 = mo->parts_[n]->getPosition(); // VEC3 pos2 = mo->parts_[n2]->getPosition(); //// if (Algo::Volume::Geometry::isPointInConvexFace2D (mo->sim_->envMap_.map, d1, mo->sim_->envMap_.position, pos1, true)) // if ( mo->sim_->envMap_.is_insideConvexCell2D(pos1, d1)) // mo->parts_[n]->d = d1; //// if (Algo::Volume::Geometry::isPointInConvexFace2D (mo->sim_->envMap_.map, d1, mo->sim_->envMap_.position, pos2, true)) // if ( mo->sim_->envMap_.is_insideConvexCell2D(pos2, d1)) // mo->parts_[n2]->d = d1; // if(n==0) // mo->dDir = mo->parts_[0]->d; // } //} ///// a implementer 4 cas //void resetPart(Segment * o, Dart d1) //{ // ArticulatedObject * nid = o->nid; // if(nid!=NULL) // { // int n1 = o->indexPart1; // int n2 = o->indexPart2; // if (nid->parts_[n1]->d == nid->sim_->envMap_.map.phi1(d1)) // nid->parts_[n1]->d = d1; // if (nid->parts_[n2]->d == nid->sim_->envMap_.map.phi1(d1)) // nid->parts_[n2]->d = d1; // } //}