← Back to team overview

yade-dev team mailing list archive

Re: acces to sphere/wall information

 

Maybe I mystified you with the "Wall". In the normal TriaxialTest, the
"walls" are instances of Box (Walls are infine planes, which are only
experimental now). Try with Box instead, and let us know. It should be
OK. Cheers, Václav


> Hi, I'm trying to use the two ways
> 
> >> 1. dynamic_cast and 2. class indices
> 
> and i have these results:
> 
> //first possibility (dynamic_cast)
> 
> /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;
> 
> }
> else if (dynamic_cast<Wall*>(b->shape.get()))
> {
> Wall* w = YADE_CAST<Wall*> ( b->shape.get() );
> const body_id_t& id = b->getId();
> cout << "is it a wall?? id == " << id << endl;
> }
> }/
> 
> This test seems to work only for spheres, not for walls, i never get the 
> second cout message.
> On the contrary, if I do:
> 
> /if (dynamic_cast<Sphere*>(b->shape.get()))
> {************}
> else
> {is it a wall? etc.etc.}/
> 
> it works, I get the message..
> 
> /is it a wall?? id == 0
> is it a wall?? id == 1
> etc. etc.
> /
> I have something similar with the second possibility.
> 
> //second possibility (class_index)
> 
> / shared_ptr<Sphere> sph(new Sphere);
> shared_ptr<Wall> wll(new Wall);
> 
> / / 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;
> 
> }
> else if ( b->shape->getClassIndex() == wll->getClassIndex() )
> {
> Wall* w = YADE_CAST<Wall*> ( b->shape.get() );
> const body_id_t& id = b->getId();
> cout << "is it a wall?? id == " << id << endl;
> }/
> 
> I never get the wall_id message. I get it only by commenting the /else 
> if /condition "/else /*if ( b->shape->getClassIndex() == 
> wll->getClassIndex() )*//"
> 
> Why?
> 
> Thanks. Emanuele.
> 
> 
> 
> Václav Šmilauer a écrit :
> >> I usually use classIndexes, but it needs a bit more than one line. Do we 
> >> have a simpler way now (checking class names takes too much time)?
> >>     
> > You should try 1. dynamic_cast and 2. class indices. I am not sure which
> > one will be the winner:
> >
> > FOREACH(const shared_ptr<Body>& b, *scene->bodies){
> > 	if(!b) continue; // deleted bodies
> >
> > 	// first possibility
> > 	// (not tested, but I think static indices should work just fine)
> > 	if(b->shape->getClassIndexStatic()==Sphere::getClassIndexStatic()){ /* ... */ }
> > 	else if(b->shape->getClassIndexStatic()==Wall::getClassIndexState()) { /* ... */ }
> >
> > 	// second possibility
> > 	if(dynamic_cast<Sphere>(b->shape->get())){ /* ... */ }
> > 	else if(dynamic_cast<Wall>(b->shape->get())){ /* ... */ }
> > }
> >
> > v
> >
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~yade-dev
> > Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~yade-dev
> > More help   : https://help.launchpad.net/ListHelp
> >
> >   
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-dev
> More help   : https://help.launchpad.net/ListHelp
> 





Follow ups

References