yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #12013
[Branch ~yade-pkg/yade/git-trunk] Rev 3651: New viewer feature : display tori instead of spheres for 2D simulations.
------------------------------------------------------------
revno: 3651
committer: Francois Kneib <francois.kneib@xxxxxxxxx>
timestamp: Tue 2015-05-05 14:55:44 +0200
message:
New viewer feature : display tori instead of spheres for 2D simulations.
So if the viewer looks toward the right axis, on can see circles instead of disks.
Modifications in pkg/common/Gl1_Primitives.*pp
3 new parameters in Gl1_Sphere : circleView, circleRelThickness, circleAllowedRotationAxis.
A new condition to enable circleView. The code is based on initGlutGlList() method for spheres.
modified:
pkg/common/Gl1_Primitives.cpp
pkg/common/Gl1_Primitives.hpp
--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'pkg/common/Gl1_Primitives.cpp'
--- pkg/common/Gl1_Primitives.cpp 2014-10-15 06:44:01 +0000
+++ pkg/common/Gl1_Primitives.cpp 2015-05-05 12:55:44 +0000
@@ -101,10 +101,15 @@
int Gl1_Sphere::glutStacks;
Real Gl1_Sphere::quality;
bool Gl1_Sphere::localSpecView;
+bool Gl1_Sphere::circleView;
+Real Gl1_Sphere::circleRelThickness;
vector<Vector3r> Gl1_Sphere::vertices, Gl1_Sphere::faces;
int Gl1_Sphere::glStripedSphereList=-1;
int Gl1_Sphere::glGlutSphereList=-1;
Real Gl1_Sphere::prevQuality=0;
+string Gl1_Sphere::prevDisplayMode="";
+char Gl1_Sphere::circleAllowedRotationAxis;
+char Gl1_Sphere::prevCircleAllowedRotationAxis='z';
void Gl1_Sphere::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& ,bool wire2, const GLViewInfo&)
{
@@ -113,11 +118,32 @@
Real r=(static_cast<Sphere*>(cm.get()))->radius;
glColor3v(cm->color);
- if (wire || wire2) glutWireSphere(r,quality*glutSlices,quality*glutStacks);
+ if (circleView) {
+ bool somethingChanged = (std::abs(quality-prevQuality)>0.001 || prevDisplayMode!="torus" || prevCircleAllowedRotationAxis!=circleAllowedRotationAxis);
+ if (somethingChanged) {
+ prevCircleAllowedRotationAxis=circleAllowedRotationAxis;
+ prevDisplayMode="torus";
+ glDeleteLists(glGlutSphereList,1);
+ glGlutSphereList = glGenLists(1);
+ glNewList(glGlutSphereList,GL_COMPILE);
+ glEnable(GL_LIGHTING);
+ glShadeModel(GL_SMOOTH);
+ switch (tolower(circleAllowedRotationAxis)) { //rotate the torus according to the axis from which we want to look at it.
+ case 'z':break; //Initial torus axis is z, nothing to do
+ case 'x':glRotatef(90,0,1,0);break;
+ case 'y':glRotatef(90,1,0,0);break;
+ default:cerr<<"Error in Gl1_Sphere::go, circleAllowedRotationAxis should be \"x\", \"y\" or \"z\"."<<endl;
+ }
+ glutSolidTorus(0.5*circleRelThickness*r,r*(1.0-circleRelThickness/2.),quality*glutStacks,quality*glutSlices); //generate torus
+ glEndList();
+ }
+ glCallList(glGlutSphereList);
+ }
+ else if (wire || wire2) glutWireSphere(r,quality*glutSlices,quality*glutStacks);
else {
//Check if quality has been modified or if previous lists are invalidated (e.g. by creating a new qt view), then regenerate lists
- bool somethingChanged = (std::abs(quality-prevQuality)>0.001 || glIsList(glStripedSphereList)!=GL_TRUE);
- if (somethingChanged) {initStripedGlList(); initGlutGlList(); prevQuality=quality;}
+ bool somethingChanged = (std::abs(quality-prevQuality)>0.001 || glIsList(glStripedSphereList)!=GL_TRUE || prevDisplayMode!="sphere");
+ if (somethingChanged) {initStripedGlList(); initGlutGlList(); prevQuality=quality;prevDisplayMode="sphere";}
glScalef(r,r,r);
if(stripes) glCallList(glStripedSphereList);
else glCallList(glGlutSphereList);
=== modified file 'pkg/common/Gl1_Primitives.hpp'
--- pkg/common/Gl1_Primitives.hpp 2014-10-15 06:44:01 +0000
+++ pkg/common/Gl1_Primitives.hpp 2015-05-05 12:55:44 +0000
@@ -63,8 +63,12 @@
void initGlutGlList();
//Generate GlList for sliced spheres
void initStripedGlList();
- //for regenerating glutSphere list if needed
+ //for regenerating glutSphere or glutTorus list if needed
static Real prevQuality;
+ //for regenerating glutSphere or glutTorus list if needed
+ static string prevDisplayMode;
+ //for regenerating glutTorus list if needed
+ static char prevCircleAllowedRotationAxis;
public:
virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&);
YADE_CLASS_BASE_DOC_STATICATTRS(Gl1_Sphere,GlShapeFunctor,"Renders :yref:`Sphere` object",
@@ -74,6 +78,9 @@
((bool,localSpecView,true,,"Compute specular light in local eye coordinate system."))
((int,glutSlices,12,(Attr::noSave | Attr::readonly),"Base number of sphere slices, multiplied by :yref:`Gl1_Sphere::quality` before use); not used with ``stripes`` (see `glut{Solid,Wire}Sphere reference <http://www.opengl.org/documentation/specs/glut/spec3/node81.html>`_)"))
((int,glutStacks,6,(Attr::noSave | Attr::readonly),"Base number of sphere stacks, multiplied by :yref:`Gl1_Sphere::quality` before use; not used with ``stripes`` (see `glut{Solid,Wire}Sphere reference <http://www.opengl.org/documentation/specs/glut/spec3/node81.html>`_)"))
+ ((bool,circleView,false,,"For 2D simulations : display tori instead of spheres, so they will appear like circles if the viewer is looking in the right direction. In this case, remember to disable perspective by pressing \"t\"-key in the viewer."))
+ ((Real,circleRelThickness,0.2,,"If :yref:`Gl1_Sphere::circleView` is enabled, this is the torus diameter relative to the sphere radius (i.e. the circle relative thickness)."))
+ ((char,circleAllowedRotationAxis,'z',,"If :yref:`Gl1_Sphere::circleView` is enabled, this is the only axis ('x', 'y' or 'z') along which rotation is allowed for the 2D simulation. It allows right orientation of the tori to appear like circles in the viewer. For example, if circleAllowedRotationAxis='x' is set, blockedDOFs=\"YZ\" should also be set for all your particles."))
);
RENDERS(Sphere);
};