Thread Previous • Date Previous • Date Next • Thread Next |
I think this will give segfaults in optimized builds, where YADE_CAST is static_cast, right? If I remember correctly, dynamic_casts are very slow, so I would go for the second option./FOREACH ( const shared_ptr<Body>& b, *ncb->bodies ) { if ( !b ) continue; if (dynamic_cast<Sphere*>(b->shape.get())) { Sphere* s=YADE_CAST<Sphere*> ( b->shape.get() ); const body_id_t& id = b->getId(); cout << "is it a sphere?? id == " << id << endl; }
I saw something like a "getStaticIndex" in one of the previous message on this topic, could it be better?/ / FOREACH ( const shared_ptr<Body>& b, *ncb->bodies ) { if ( !b ) continue; if ( b->shape->getClassIndex() == sph->getClassIndex() ) { Sphere* s=YADE_CAST<Sphere*> ( b->shape.get() ); const body_id_t& id = b->getId(); cout << "is it a sphere?? id == " << id << endl; }
Also, perhaps consider defining outside the loop : int SIndex = sph->getClassIndex(); Bruno -- _______________ Chareyre Bruno Maître de Conférences Grenoble INP Laboratoire 3SR - bureau E145 BP 53 - 38041, Grenoble cedex 9 - France Tél : 33 4 56 52 86 21 Fax : 33 4 76 82 70 43 ________________
Thread Previous • Date Previous • Date Next • Thread Next |