yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #05283
[Branch ~yade-dev/yade/trunk] Rev 2351: - Implement the distinction between node orientation (integrated in Newton) and beam orientation ...
------------------------------------------------------------
revno: 2351
committer: bchareyre <bchareyre@dt-rv020>
branch nick: trunk
timestamp: Mon 2010-07-12 16:06:55 +0200
message:
- Implement the distinction between node orientation (integrated in Newton) and beam orientation (always oriented as line between adjacent node). It fixes the starcases appearing in display for large stretch.
modified:
pkg/common/DataClass/Shape/Cylinder.cpp
pkg/common/DataClass/Shape/Cylinder.hpp
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'pkg/common/DataClass/Shape/Cylinder.cpp'
--- pkg/common/DataClass/Shape/Cylinder.cpp 2010-07-12 08:50:35 +0000
+++ pkg/common/DataClass/Shape/Cylinder.cpp 2010-07-12 14:06:55 +0000
@@ -9,7 +9,7 @@
CylScGeom::~CylScGeom(){}
-YADE_PLUGIN((Cylinder)(ChainedCylinder)(ChainedState)(CylScGeom)(Ig2_Sphere_ChainedCylinder_CylScGeom)(Ig2_ChainedCylinder_ChainedCylinder_ScGeom)(Gl1_Cylinder)(Bo1_Cylinder_Aabb)/*(Bo1_ChainedCylinder_Aabb)*/);
+YADE_PLUGIN((Cylinder)(ChainedCylinder)(ChainedState)(CylScGeom)(Ig2_Sphere_ChainedCylinder_CylScGeom)(Ig2_ChainedCylinder_ChainedCylinder_ScGeom)(Gl1_Cylinder)/*(Gl1_ChainedCylinder)*/(Bo1_Cylinder_Aabb)/*(Bo1_ChainedCylinder_Aabb)*/);
YADE_REQUIRE_FEATURE(OPENGL)
vector<vector<int> > ChainedState::chains;
@@ -17,6 +17,8 @@
//!################## IG FUNCTORS #####################
+
+//!Sphere-cylinder or cylinder-cylinder not implemented yet, see Ig2_ChainedCylinder_ChainedCylinder_ScGeom and test/chained-cylinder-spring.py
#ifdef YADE_DEVIRT_FUNCTORS
bool Ig2_Sphere_ChainedCylinder_CylScGeom::go(const shared_ptr<Shape>& cm1, const shared_ptr<Shape>& cm2, const State& state1, const State& state2, const Vector3r& shift2, const bool& force, const shared_ptr<Interaction>& c){ throw runtime_error("Do not call Ig2_Sphere_ChainedCylinder_CylScGeom::go, use getStaticFunctorPtr and call that function instead."); }
bool Ig2_Sphere_ChainedCylinder_CylScGeom::goStatic(InteractionGeometryFunctor* _self, const shared_ptr<Shape>& cm1, const shared_ptr<Shape>& cm2, const State& state1, const State& state2, const Vector3r& shift2, const bool& force, const shared_ptr<Interaction>& c){
@@ -105,8 +107,13 @@
bool isNew = !c->interactionGeometry;
if(!isNew) scm=YADE_PTR_CAST<ScGeom>(c->interactionGeometry);
else { scm=shared_ptr<ScGeom>(new ScGeom()); c->interactionGeometry=scm; }
- Real length=abs((pChain->ori*Vector3r::UnitZ()).dot(chain2.pos-chain1.pos));
- Vector3r segment =pChain->ori*Vector3r::UnitZ()*length;
+// Real length=abs((pChain->ori*Vector3r::UnitZ()).dot(chain2.pos-chain1.pos));
+ Real length=(chain2.pos-chain1.pos).norm();
+// Vector3r segment =pChain->ori*Vector3r::UnitZ()*length;
+ Vector3r segment =chain2.pos-chain1.pos;
+ if (revert) segment = -segment;
+ s->chainedOrientation.setFromTwoVectors(Vector3r::UnitZ(),pChain->ori.conjugate()*segment);
+// s->chainedOrientation=pChain->ori.conjugate()*s->chainedOrientation;
if (revert) segment = -segment;
if(isNew) {scm->normal=scm->prevNormal=segment/length;s->initLength=length;}
@@ -118,7 +125,7 @@
else {
scm->radius1=0;
scm->radius2=s->initLength;}
-
+ //length only used for display
s->length=length;
scm->penetrationDepth=s->initLength-length;
scm->contactPoint=pChain->pos+pChain->ori*Vector3r::UnitZ()*length;
@@ -158,6 +165,18 @@
int Gl1_Cylinder::glutStacks;
int Gl1_Cylinder::glCylinderList=-1;
+// bool Gl1_ChainedCylinder::wire;
+// bool Gl1_ChainedCylinder::glutNormalize;
+// int Gl1_ChainedCylinder::glutSlices;
+// int Gl1_ChainedCylinder::glutStacks;
+// int Gl1_ChainedCylinder::glCylinderList=-1;
+
+void out ( Quaternionr q )
+{
+ AngleAxisr aa(q);
+ std::cout << " axis: " << aa.axis()[0] << " " << aa.axis()[1] << " " << aa.axis()[2] << ", angle: " << aa.angle() << " | ";
+}
+
void Gl1_Cylinder::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& ,bool wire2, const GLViewInfo&)
{
Real r=(static_cast<Cylinder*>(cm.get()))->radius;
@@ -166,15 +185,32 @@
glColor3v(cm->color);
if(glutNormalize) glPushAttrib(GL_NORMALIZE); // as per http://lists.apple.com/archives/Mac-opengl/2002/Jul/msg00085.html
// glPushMatrix();
- if (wire || wire2) drawCylinder(true, r,length);
- else drawCylinder(false, r,length);
+ Quaternionr shift = (static_cast<ChainedCylinder*>(cm.get()))->chainedOrientation;
+ if (wire || wire2) drawCylinder(true, r,length,shift);
+ else drawCylinder(false, r,length,shift);
if(glutNormalize) glPopAttrib();
// glPopMatrix();
return;
}
+// void Gl1_ChainedCylinder::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& ,bool wire2, const GLViewInfo&)
+// {
+// Real r=(static_cast<ChainedCylinder*>(cm.get()))->radius;
+// Real length=(static_cast<ChainedCylinder*>(cm.get()))->length;
+// Quaternionr shift = (static_cast<ChainedCylinder*>(cm.get()))->chainedOrientation;
+// //glMaterialv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Vector3f(cm->color[0],cm->color[1],cm->color[2]));
+// glColor3v(cm->color);
+// if(glutNormalize) glPushAttrib(GL_NORMALIZE); // as per http://lists.apple.com/archives/Mac-opengl/2002/Jul/msg00085.html
+// // glPushMatrix();
+// out(shift);
+// if (wire || wire2) drawCylinder(true, r,length,shift);
+// else drawCylinder(false, r,length,shift);
+// if(glutNormalize) glPopAttrib();
+// // glPopMatrix();
+// return;
+// }
-void Gl1_Cylinder::drawCylinder(bool wire, Real radius, Real length) const
+void Gl1_Cylinder::drawCylinder(bool wire, Real radius, Real length, const Quaternionr& shift) const
{
// GLERROR;
/* if (glCylinderList<0) {
@@ -188,24 +224,58 @@
// glTranslatef(0.0,0.0,-length*0.5);
//scaling needs to adapt spheres or they will be elipsoids. They actually seem to disappear when commented glList code is uncommented, the cylinders are displayed correclty.
// glScalef(1,length,1);
+ AngleAxisr aa(shift);
+ glRotatef(aa.angle()*180.0/Mathr::PI,aa.axis()[0],aa.axis()[1],aa.axis()[2]);
gluCylinder(quadObj, radius, radius, length, glutSlices,glutStacks);
gluQuadricOrientation(quadObj, (GLenum) GLU_INSIDE);
glutSolidSphere(radius,glutSlices,glutStacks);
glTranslatef(0.0,0.0,length);
-// glRotatef(180,0.0,1.0,0.0);
+
glutSolidSphere(radius,glutSlices,glutStacks);
// gluDisk(quadObj,0.0,radius,glutSlices,_loops);
gluDeleteQuadric(quadObj);
glPopMatrix();
// GLERROR;
-
+
// glEndList();}
// glCallList(glCylinderList);
}
+// void Gl1_Cylinder::drawCylinder(bool wire, Real radius, Real length, const Quaternionr& shift) const
+// {
+// // GLERROR;
+// /* if (glCylinderList<0) {
+// glCylinderList = glGenLists(1);
+// glNewList(glCylinderList,GL_COMPILE);*/
+// glPushMatrix();
+// GLUquadricObj *quadObj = gluNewQuadric();
+// gluQuadricDrawStyle(quadObj, (GLenum) (wire ? GLU_SILHOUETTE : GLU_FILL));
+// gluQuadricNormals(quadObj, (GLenum) GLU_SMOOTH);
+// gluQuadricOrientation(quadObj, (GLenum) GLU_OUTSIDE);
+// // glTranslatef(0.0,0.0,-length*0.5);
+// //scaling needs to adapt spheres or they will be elipsoids. They actually seem to disappear when commented glList code is uncommented, the cylinders are displayed correclty.
+// // glScalef(1,length,1);
+// gluCylinder(quadObj, radius, radius, length, glutSlices,glutStacks);
+// gluQuadricOrientation(quadObj, (GLenum) GLU_INSIDE);
+// glutSolidSphere(radius,glutSlices,glutStacks);
+// glTranslatef(0.0,0.0,length);
+// AngleAxisr aa(shift);
+// glRotatef(aa.angle(),aa.axis()[0],aa.axis()[1],aa.axis()[2]);
+// glutSolidSphere(radius,glutSlices,glutStacks);
+// // gluDisk(quadObj,0.0,radius,glutSlices,_loops);
+// gluDeleteQuadric(quadObj);
+// glPopMatrix();
+// // GLERROR;
+//
+// // glEndList();}
+// // glCallList(glCylinderList);
+//
+// }
+
//!################## BOUNDS FUNCTOR #####################
+
void Bo1_Cylinder_Aabb::go(const shared_ptr<Shape>& cm, shared_ptr<Bound>& bv, const Se3r& se3, const Body* b){
Cylinder* cylinder = static_cast<Cylinder*>(cm.get());
Aabb* aabb = static_cast<Aabb*>(bv.get());
=== modified file 'pkg/common/DataClass/Shape/Cylinder.hpp'
--- pkg/common/DataClass/Shape/Cylinder.hpp 2010-07-12 08:50:35 +0000
+++ pkg/common/DataClass/Shape/Cylinder.hpp 2010-07-12 14:06:55 +0000
@@ -26,12 +26,14 @@
public:
ChainedCylinder(Real _radius, Real _length): Cylinder(_radius,_length){}
virtual ~ChainedCylinder ();
+
//Keep pointers or copies of connected states?
// ChainedState st1, st2;
YADE_CLASS_BASE_DOC_ATTRS_CTOR(ChainedCylinder,Cylinder,"Geometry of a deformable chained cylinder, using geometry :yref:`MinkCylinder`.",
((Real,initLength,0,"tensile-free length, used as reference for tensile strain"))
+ ((Quaternionr,chainedOrientation,Quaternionr::Identity(),"Orientation of node-to-node vector"))
,createIndex();/*ctor*/
// state=shared_ptr<ChainedState>(new ChainedState);
@@ -119,7 +121,7 @@
private:
static int glCylinderList;
void subdivideTriangle(Vector3r& v1,Vector3r& v2,Vector3r& v3, int depth);
- void drawCylinder(bool wire, Real radius, Real length) const;
+ void drawCylinder(bool wire, Real radius, Real length, const Quaternionr& shift=Quaternionr::Identity()) const;
void initGlLists(void);
public:
virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&);
@@ -130,8 +132,38 @@
((int,glutStacks,4,"Number of sphere stacks."))
);
RENDERS(Cylinder);
+ friend class Gl1_ChainedCylinder;
};
+//!This doesn't work : the 1D dispatcher will pick Gl1_Cylinder to display ChainedCylinders, workaround : add shift to cylinders (should be a variable of chained cylinders only).
+// class Gl1_ChainedCylinder : public Gl1_Cylinder{
+// public:
+// virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&);
+// YADE_CLASS_BASE_DOC(Gl1_ChainedCylinder,Gl1_Cylinder,"Renders :yref:`ChainedCylinder` object including a shift for compensating flexion."
+// );
+// RENDERS(ChainedCylinder);
+// };
+
+
+/*
+class Gl1_ChainedCylinder : public GlShapeFunctor{
+ private:
+ static int glCylinderList;
+ void subdivideTriangle(Vector3r& v1,Vector3r& v2,Vector3r& v3, int depth);
+ void drawCylinder(bool wire, Real radius, Real length, const Quaternionr& shift=Quaternionr::Identity()) const;
+ void initGlLists(void);
+ public:
+ virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&);
+ YADE_CLASS_BASE_DOC_STATICATTRS(Gl1_ChainedCylinder,GlShapeFunctor,"Renders :yref:`ChainedCylinder` object including a shift for compensating flexion.",
+ ((bool,wire,false,"Only show wireframe (controlled by ``glutSlices`` and ``glutStacks``."))
+ ((bool,glutNormalize,true,"Fix normals for non-wire rendering"))
+ ((int,glutSlices,8,"Number of sphere slices."))
+ ((int,glutStacks,4,"Number of sphere stacks."))
+ );
+ RENDERS(ChainedCylinder);
+};*/
+
+
class Bo1_Cylinder_Aabb : public BoundFunctor
{
public :
@@ -159,6 +191,7 @@
REGISTER_SERIALIZABLE(Bo1_Cylinder_Aabb);
// REGISTER_SERIALIZABLE(Bo1_ChainedCylinder_Aabb);
REGISTER_SERIALIZABLE(Gl1_Cylinder);
+// REGISTER_SERIALIZABLE(Gl1_ChainedCylinder);
REGISTER_SERIALIZABLE(Cylinder);
REGISTER_SERIALIZABLE(ChainedCylinder);
REGISTER_SERIALIZABLE(ChainedState);