← Back to team overview

yade-dev team mailing list archive

Re: "Yade does not render custom shape after integration step"

 

Hi Burak, and welcome in yade-dev.
I see no obvious mistake in your code, it should work.
I guess you already checked that the coordinates of the vertices are not
just junk numbers after one step? This could be one problem.
If you execute engine per engine (substepping in GUI) inside the first
step, when does it start to disappear?
I' m not sure to understand the images. Why particles have different
positions and different colors after only one step?

Bruno


On 17/09/13 12:36, Burak Er wrote:
> Dear Yade Developers, 
>
> I am trying to create an element interface for yade(finite element). In this interface, 
> The nodes and the triangles are held within the structure. The structures that I created as follows, 
>
> DeformableElement-> derived from Shape 
> Gl1_DeformableElement->derived from GlShapeFunctor 
>
> Every time in a step drawing of the element is not realized after NewtonIntegrator step. 
> Initially all faces of the element is drawn in ::go function of the Gl1_DeformableElement 
> but after one step it is not drawn. What is the reason for this behaviour? Here is the screenshots, 
>
> before integration 
> <a href="http://tinypic.com?ref=2eauds1"; target="_blank"><img src="http://i42.tinypic.com/2eauds1.png"; border="0" alt="Image and video hosting by TinyPic"></a> 
>
> after integration 
> <a href="http://tinypic.com?ref=280qckp"; target="_blank"><img src="http://i44.tinypic.com/280qckp.png"; border="0" alt="Image and video hosting by TinyPic"></a> 
>
> The classes are as follows 
>
> ******************************Gl1_DeformableElement.hpp**************************************** 
> #pragma once 
>
> #include<yade/pkg/common/GLDrawFunctors.hpp> 
> #include<yade/pkg/dem/deformablecohesive/DeformableElement.hpp> 
>
> class Gl1_DeformableElement : public GlShapeFunctor 
> { 
> public: 
> virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&); 
> YADE_CLASS_BASE_DOC(Gl1_DeformableElement,GlShapeFunctor,"Renders :yref:`Node` object" 
> ); 
> RENDERS(DeformableElement); 
> }; 
>
> REGISTER_SERIALIZABLE(Gl1_DeformableElement); 
>
> ***********************************************Gl1_DeformableElement.cpp**************************************** 
>
> /************************************************************************* 
> * Copyright (C) 2008 by Sergei Dorofeenko * 
> * sega@xxxxxxxxxxxxxxxx * 
> * * 
> * This program is free software; it is licensed under the terms of the * 
> * GNU General Public License v2 or later. See file LICENSE for details. * 
> *************************************************************************/ 
>
> #ifdef YADE_OPENGL 
>
> #include<yade/pkg/dem/deformablecohesive/Gl1_DeformableElement.hpp> 
> #include<yade/pkg/dem/deformablecohesive/DeformableElement.hpp> 
> #include<yade/lib/opengl/OpenGLWrapper.hpp> 
>
> typedef DeformableElement::NodeMap NodeMap; 
> void Gl1_DeformableElement::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& ,bool wire,const GLViewInfo&) 
> { 
>
>
> DeformableElement* element = static_cast<DeformableElement*>(cm.get()); 
> std::vector<Vector3r> triangles = element->faces; 
> Vector3r elempos=element->frame_get().position; 
>
> Scene* scene(Omega::instance().getScene().get()); // get scene 
>
>
> // if(!normals) return; 
> // // DeformableElement's normal 
> // glBegin(GL_LINES); 
> // glColor3(0.0,0.0,1.0); 
> // glVertex3(0.0,0.0,0.0); 
> // glVertex3v(DeformableElement->normal); 
> // glEnd(); 
> // // normal of edges 
> // glColor3(0.0,0.0,1.0); 
> // glBegin(GL_LINES); 
> // glVertex3(0.0,0.0,0.0); glVertex3v(Vector3r(icr*ne[0])); 
> // glVertex3(0.0,0.0,0.0); glVertex3v(Vector3r(icr*ne[1])); 
> // glVertex3(0.0,0.0,0.0); glVertex3v(Vector3r(icr*ne[2])); 
> // glEnd(); 
>
> if(!(cm->wire || wire)){ 
> glDisable(GL_CULL_FACE); 
> //Vector3r normal=(facet->vertices[1]-facet->vertices[0]).cross(facet->vertices[2]-facet->vertices[1]); normal.normalize(); 
> glColor3v(cm->color); 
> glBegin(GL_TRIANGLES); 
>
> FOREACH(Vector3r vertices,triangles){ 
> NodeMap::iterator i1(element->localmap.begin()); 
> NodeMap::iterator i2(i1); 
> NodeMap::iterator i3(i1); 
>
> std::advance(i1,vertices[0]); 
> std::advance(i2,vertices[1]); 
> std::advance(i3,vertices[2]); 
>
> const shared_ptr<Body>& member1=Body::byId(i1->first,scene); 
> const shared_ptr<Body>& member2=Body::byId(i2->first,scene); 
> const shared_ptr<Body>& member3=Body::byId(i3->first,scene); 
>
> Vector3r pos1=member1->state->pos; 
> Vector3r pos2=member2->state->pos; 
> Vector3r pos3=member3->state->pos; 
>
> cout<<"Pos1"<<pos1<<"\n"; 
> cout<<"Pos2"<<pos2<<"\n"; 
> cout<<"Pos3"<<pos3<<"\n"; 
>
>
> glVertex3v(pos1); 
> glVertex3v(pos2); 
> glVertex3v(pos3); 
>
> } 
> } 
> glEnd(); 
>
> glBegin(GL_LINE_LOOP); 
> glColor3v(Vector3r(0,0,0)); 
> FOREACH(Vector3r vertices,triangles){ 
> NodeMap::iterator i1(element->localmap.begin()); 
> NodeMap::iterator i2(i1); 
> NodeMap::iterator i3(i1); 
>
> std::advance(i1,vertices[0]); 
> std::advance(i2,vertices[1]); 
> std::advance(i3,vertices[2]); 
>
> const shared_ptr<Body>& member1=Body::byId(i1->first,scene); 
> const shared_ptr<Body>& member2=Body::byId(i2->first,scene); 
> const shared_ptr<Body>& member3=Body::byId(i3->first,scene); 
>
> Vector3r pos1=member1->state->pos; 
> Vector3r pos2=member2->state->pos; 
> Vector3r pos3=member3->state->pos; 
>
> glVertex3v(pos1); 
> glVertex3v(pos2); 
> glVertex3v(pos3); 
> } 
>
> glEnd(); 
>
> } 
>
> YADE_PLUGIN((Gl1_DeformableElement)); 
>
> #endif /* YADE_OPENGL */ 
>
> AND 
>
>
> *****************************************************DeformableElement.hpp*************************************** 
> /************************************************************************* 
> * Copyright (C) 2013 by Burak ER * 
> * * 
> * * 
> * This program is free software; it is licensed under the terms of the * 
> * GNU General Public License v2 or later. See file LICENSE for details. * 
> *************************************************************************/ 
>
> #pragma once 
>
> #include<vector> 
> #include<map> 
> #include<stdexcept> 
> #include<yade/core/Body.hpp> 
> #include<yade/lib/base/Logging.hpp> 
> #include<yade/lib/base/Math.hpp> 
> #include<yade/core/PartialEngine.hpp> 
>
> //#include<yade/trunk/pkg/dem/deformablecohesive/Node.hpp> //Node shape 
>
> /* Before starting the implementation of the deformable element, I am really dissappointed that deformableelement's algorithm relies on its shape. 
> Shape means "shape" and I think it should not contain any other physical meaning or anything else. Therefore, DeformableElement like 
> deformable element structure is not used. 
>
> With respect to this view; The deformable element class is derived from the body and knows the information of 
> its members that are node shaped bodies. 
>
> */ 
>
> class NewtonIntegrator; 
>
> namespace yade{ 
>
> class DeformableElement: public Shape { 
> public: 
>
> typedef std::map<Body::id_t,Se3r> NodeMap; 
> typedef std::vector<Vector3r> Triangles; // Used for drawing the element 
>
> virtual ~DeformableElement (); 
> void addNode(const shared_ptr<Body>& subBody); 
> void delNode(const shared_ptr<Body>& subBody); 
>
> void addFace(Vector3r&); 
> void removeLastFace(void); 
> //! Recalculate physical properties of DeformableElement. 
>
> Se3r frame_get(); 
> void frame_set(Se3r); 
>
> //! update member positions after deformableelement being moved by mouse (in case simulation is paused and engines will not do that). 
> //void userForcedDisplacementRedrawHook(){ throw runtime_error("DeformableElement::userForcedDisplacementRedrawHook not yet implemented (with DeformableElement as subclass of Shape).");} 
>
> python::dict localmap_get(); 
>
> YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(DeformableElement,Shape,"Deformable aggregate of nodes", 
> ((NodeMap,localmap,,,"Ids and relative positions+orientations of members of the deformable element (should not be accessed directly)")) 
> ((Se3r,elementframe,,,"Position and orientation of the element frame")) 
> ((Triangles,faces,,,"Faces of the element for drawing")), 
> , 
> createIndex(); /*ctor*/ 
> , 
> /*py*/ 
> YADE_PY_TOPINDEXABLE(DeformableElement) 
> .add_property("elementframe",&DeformableElement::frame_get) 
> .def("addNode",&DeformableElement::addNode,"Add a node shared_pt<:yref:'Body'>& as into the element") 
> .def("delNode",&DeformableElement::delNode,"Remove a node shared_pt<:yref:'Body'>& from the element") 
> .def("addFace",&DeformableElement::addFace,"Add a face into the element") 
> .def("removeLastFace",&DeformableElement::removeLastFace,"Remove a face from the element") 
>
> ); 
> DECLARE_LOGGER; 
>
> REGISTER_CLASS_INDEX(DeformableElement,Shape); 
>
> }; 
> } 
> // necessary 
> using namespace yade; 
> REGISTER_SERIALIZABLE(DeformableElement); 
>
>
>
>
> *****************************************************DeformableElement.cpp*************************************** 
>
>
> // (c) 2007-2010 Vaclav Smilauer <eudoxos@xxxxxxxx> 
>
> #include<yade/pkg/dem/deformablecohesive/DeformableElement.hpp> 
> #include<algorithm> 
> #include<yade/core/Scene.hpp> 
> #include<yade/core/BodyContainer.hpp> 
> #include<yade/core/State.hpp> 
> #include<yade/pkg/common/Sphere.hpp> 
> #include<yade/pkg/dem/deformablecohesive/Node.hpp> 
>
>
> YADE_PLUGIN((DeformableElement)); 
> CREATE_LOGGER(DeformableElement); 
>
> python::dict DeformableElement::localmap_get(){ 
> python::dict ret; 
> FOREACH(NodeMap::value_type& b, localmap){ 
> ret[b.first]=python::make_tuple(b.second.position,b.second.orientation); 
> } 
> return ret; 
> } 
> void DeformableElement::addFace(Vector3r& indexes){ 
>
> faces.push_back(indexes); 
>
> } 
>
> DeformableElement::~DeformableElement(){ 
>
> } 
>
> void DeformableElement::removeLastFace(void){ 
>
> faces.pop_back(); 
>
> } 
>
> void DeformableElement::addNode(const shared_ptr<Body>& nodeBody){ 
>
> const shared_ptr<Node> node=YADE_PTR_CAST<Node>(nodeBody->shape);//Should be checked dynamically otherwise it will always cast: every shape is castable to Node shape 
>
> Body::id_t subId=nodeBody->getId(); 
>
> if(node){} else{ throw std::invalid_argument(("The body that is given #"+lexical_cast<string>(subId)+" is not a Node therefore cannot be added to the deformable element "));} 
>
> if(subId<0){throw std::invalid_argument(("The Node that is given is not a member of the scene therefore it has no state, not adding exiting"));} 
>
> if(this->localmap.count(subId)!=0) throw std::invalid_argument(("Node that has Body id #"+lexical_cast<string>(subId)+" is already part of this deformable element")); 
>
> // Add body to localmap 
> this->localmap[subId]=Se3r();// meaningful values will be put in by DeformableElement::updateProperties 
>
> // Get first node 
> Scene* scene(Omega::instance().getScene().get()); // get scene 
> const shared_ptr<Body>& member=Body::byId(localmap.begin()->first,scene); 
>
> //Substract from the current node, therefore find the local value, 
> localmap[subId].position=nodeBody->state->pos-member->state->pos; 
> //localmap[subId].orientation=nodeBody->state->ori; 
>
> //this->setBounded(false); // disallow collisions with the element itself 
>
> //If we have more than three nodes define a local triad that is clumped on the first node and initially parallel to the global frame 
> if(this->localmap.size()>=3) 
> { 
> //define a local triad if needed 
> } 
>
> return; 
> } 
>
> void DeformableElement::delNode(const shared_ptr<Body>& subBody){ 
> // erase the subBody; removing body that is not part of the element throws 
> if(this->localmap.erase(subBody->id)!=1) throw std::invalid_argument(("Node #"+lexical_cast<string>(subBody->id)+" not a part of the deformable element, not removing...").c_str()); 
> LOG_DEBUG("Removed node #"<<subBody->id); 
> } 
>
> Se3r DeformableElement::frame_get() const 
> { 
> Scene* scene(Omega::instance().getScene().get()); // get scene 
> const shared_ptr<Body>& member=Body::byId(localmap.begin()->first,scene); 
> return member->state->se3; 
> } 
>
> void DeformableElement::frame_set(Se3r) const 
> { 
> // Scene* scene(Omega::instance().getScene().get()); // get scene 
> // NodeMap::iterator i=localmap.begin(); 
> // const shared_ptr<Body>& member=Body::byId(i->first,scene); 
> return; 
> } 
>
>
>
> _______________________________________________
> 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
>
>
>


-- 
_______________
Bruno Chareyre
Associate Professor
ENSE³ - Grenoble INP
Lab. 3SR
BP 53
38041 Grenoble cedex 9
Tél : +33 4 56 52 86 21
Fax : +33 4 76 82 70 43
________________



References