ArticulatedObject.cpp 5.15 KB
Newer Older
pitiot's avatar
up  
pitiot committed
1 2 3 4 5 6 7 8
#include "simulator.h"


/*addGeneralCell
 * adds cell d to general belonging, if it's already present, increases the number of instance of the cell
 */


Etienne Schmitt's avatar
Etienne Schmitt committed
9 10 11 12 13
ArticulatedObject::ArticulatedObject() :
   nbVertices(0u)
  ,nbEdges(0u)
  ,parts_(std::vector<PARTICULE*>())
  ,Segments_(std::vector<Segment *>())
Thomas Pitiot 's avatar
Thomas Pitiot committed
14 15
  ,belonging_cells(std::vector<std::vector<Dart>>())
  ,neighbor_cells(std::vector<std::vector<Dart>>())
Etienne Schmitt's avatar
Etienne Schmitt committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  , 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;
}

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
37
void  ArticulatedObject::addGeneralCell ( Dart d)
pitiot's avatar
up  
pitiot committed
38
{
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
39
    bool added = false;
Etienne Schmitt's avatar
Etienne Schmitt committed
40
    for(std::pair<Dart,int>& pere : general_belonging)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
41
    {
42 43
//        if(sim_->envMap_.map.sameVolume(pere.first,d))
        if(pere.first==d)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
44 45 46 47 48 49 50 51 52 53 54
        {
            pere.second ++;
            added= true;
            break;
        }

    }
    if (!added)
    {
        general_belonging.push_back(std::make_pair(d,1));
    }
pitiot's avatar
up  
pitiot committed
55 56 57 58
}
/*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*
 */
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
59
bool  ArticulatedObject::removeGeneralCell (Dart d)
pitiot's avatar
up  
pitiot committed
60
{
Etienne Schmitt's avatar
Etienne Schmitt committed
61
    for(std::pair<Dart,int>& pere : general_belonging)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
62
    {
63 64
//        if(sim_->envMap_.map.sameVolume(pere.first,d))
        if(pere.first==d)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
65 66 67 68 69 70 71 72 73 74 75 76 77
        {
            pere.second--;
            if(pere.second==0)
            {
                pere=general_belonging.back() ;
                general_belonging.pop_back() ;
            }
            return true;
        }


    };
    return false;
pitiot's avatar
up  
pitiot committed
78 79
}

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
80 81 82
void  ArticulatedObject::addGeneralNeighbor ( Dart d)
{
    bool added = false;
Etienne Schmitt's avatar
Etienne Schmitt committed
83
    for(std::pair<Dart,int>& pere : general_neighbors)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
84
    {
85 86
//        if(sim_->envMap_.map.sameVolume(pere.first,d))
        if(pere.first==d)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
        {
            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)
{
Etienne Schmitt's avatar
Etienne Schmitt committed
104
    for(std::pair<Dart,int>& pere : general_neighbors)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
105
    {
106 107
//        if(sim_->envMap_.map.sameVolume(pere.first,d))
        if(pere.first==d)
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121
        {
            pere.second--;
            if(pere.second==0)
            {
                pere=general_neighbors.back() ;
                general_neighbors.pop_back() ;
            }
            return true;
        }


    };
    return false;
}
pitiot's avatar
up  
pitiot committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195









//-------------------------------------------------------------------------


//////// 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<PFP>::move(Algo::Volume::Geometry::faceCentroid<PFP>(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<PFP>::move(Algo::Volume::Geometry::faceCentroid<PFP>(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 <PFP> (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 <PFP> (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;
//	}
//}

Thomas Pitiot 's avatar
Thomas Pitiot committed
196 197 198 199 200 201 202 203
///// 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;
pitiot's avatar
up  
pitiot committed
204 205


Thomas Pitiot 's avatar
Thomas Pitiot committed
206 207
//        if (nid->parts_[n1]->d == nid->sim_->envMap_.map.phi1(d1))
//            nid->parts_[n1]->d = d1;
pitiot's avatar
up  
pitiot committed
208

Thomas Pitiot 's avatar
Thomas Pitiot committed
209 210
//        if (nid->parts_[n2]->d == nid->sim_->envMap_.map.phi1(d1))
//                    nid->parts_[n2]->d = d1;
pitiot's avatar
up  
pitiot committed
211 212


Thomas Pitiot 's avatar
Thomas Pitiot committed
213 214
//	}
//}
pitiot's avatar
up  
pitiot committed
215 216 217 218 219 220 221 222 223