yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #00962
[svn] r1667 - in trunk: gui/py pkg/common pkg/common/DataClass pkg/common/DataClass/Widgets pkg/common/Engine/FilterEngine pkg/common/RenderingEngine pkg/common/RenderingEngine/GLDrawWidgets
Author: sega
Date: 2009-02-16 20:42:09 +0100 (Mon, 16 Feb 2009)
New Revision: 1667
Added:
trunk/pkg/common/DataClass/Widgets/
trunk/pkg/common/DataClass/Widgets/ColorScale.cpp
trunk/pkg/common/DataClass/Widgets/ColorScale.hpp
trunk/pkg/common/RenderingEngine/GLDrawWidgets/
trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.cpp
trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.hpp
Modified:
trunk/gui/py/utils.py
trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.cpp
trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.hpp
trunk/pkg/common/SConscript
Log:
1. The experimental widget for drawing a color scale for colorized velocity filter.
2. Convenient python function utils.ColorizedVelocityFilter.
Modified: trunk/gui/py/utils.py
===================================================================
--- trunk/gui/py/utils.py 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/gui/py/utils.py 2009-02-16 19:42:09 UTC (rev 1667)
@@ -396,3 +396,7 @@
+def ColorizedVelocityFilter(isFilterActivated=True,autoScale=True,minValue=0,maxValue=0,posX=0,posY=0.2,width=0.05,height=0.5,title='Velocity, m/s'):
+ f = DeusExMachina('ColorizedVelocityFilter',{'isFilterActivated':isFilterActivated,'autoScale':autoScale,'minValue':minValue,'maxValue':maxValue,'posX':posX,'posY':posY,'width':width,'height':height,'title':title})
+ O.engines+=[f]
+ return f
Added: trunk/pkg/common/DataClass/Widgets/ColorScale.cpp
===================================================================
--- trunk/pkg/common/DataClass/Widgets/ColorScale.cpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/DataClass/Widgets/ColorScale.cpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -0,0 +1,39 @@
+/*************************************************************************
+* Copyright (C) 2009 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. *
+*************************************************************************/
+
+#include "ColorScale.hpp"
+#include<yade/lib-opengl/OpenGLWrapper.hpp>
+
+ColorScale::ColorScale () : GeometricalModel()
+{
+ createIndex();
+ posX=0;
+ posY=0.2;
+ width=0.05;
+ height=0.5;
+ title="";
+}
+
+
+ColorScale::~ColorScale ()
+{
+}
+
+
+void ColorScale::registerAttributes()
+{
+ GeometricalModel::registerAttributes();
+ REGISTER_ATTRIBUTE(posX);
+ REGISTER_ATTRIBUTE(posY);
+ REGISTER_ATTRIBUTE(width);
+ REGISTER_ATTRIBUTE(height);
+ REGISTER_ATTRIBUTE(title);
+}
+
+
+YADE_PLUGIN();
Added: trunk/pkg/common/DataClass/Widgets/ColorScale.hpp
===================================================================
--- trunk/pkg/common/DataClass/Widgets/ColorScale.hpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/DataClass/Widgets/ColorScale.hpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -0,0 +1,34 @@
+/*************************************************************************
+* Copyright (C) 2009 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. *
+*************************************************************************/
+
+#pragma once
+
+#include<yade/core/GeometricalModel.hpp>
+
+class ColorScale : public GeometricalModel {
+ public :
+ Real posX,posY;
+ Real width,height;
+ string title;
+
+ vector<Vector3r> colors;
+ vector<string> labels;
+
+ ColorScale ();
+ virtual ~ColorScale ();
+
+ protected :
+ void registerAttributes();
+ REGISTER_CLASS_NAME(ColorScale);
+ REGISTER_BASE_CLASS_NAME(GeometricalModel);
+ REGISTER_CLASS_INDEX(ColorScale,GeometricalModel);
+};
+
+REGISTER_SERIALIZABLE(ColorScale);
+
+
Modified: trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.cpp
===================================================================
--- trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.cpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.cpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -7,6 +7,7 @@
*************************************************************************/
#include"ColorizedVelocityFilter.hpp"
+#include <yade/pkg-common/ColorScale.hpp>
CREATE_LOGGER(ColorizedVelocityFilter);
@@ -21,6 +22,12 @@
prevIteration=0;
dt=0;
subscrBodies.clear();
+
+ posX=0;
+ posY=0.2;
+ width=0.05;
+ height=0.5;
+ title="Velocity, m/s";
}
@@ -40,6 +47,12 @@
REGISTER_ATTRIBUTE(onlyDynamic);
REGISTER_ATTRIBUTE(minValue);
REGISTER_ATTRIBUTE(maxValue);
+
+ REGISTER_ATTRIBUTE(posX);
+ REGISTER_ATTRIBUTE(posY);
+ REGISTER_ATTRIBUTE(width);
+ REGISTER_ATTRIBUTE(height);
+ REGISTER_ATTRIBUTE(title);
}
void ColorizedVelocityFilter::applyCondition(MetaBody* ncb)
@@ -57,7 +70,8 @@
prevPositions[i] = currPos;
}
prevIteration = currIteration;
- if (autoScale) makeScale();
+ makeScale();
+ updateColorScale();
for (int i=0,e=subscrBodies.size(); i<e; ++i)
{
shared_ptr<Body> b =(*bodies)[subscrBodies[i]];
@@ -65,6 +79,46 @@
}
}
+void ColorizedVelocityFilter::updateColorScale()
+{
+ legend->posX = posX;
+ legend->posY = posY;
+ legend->width = width;
+ legend->height = height;
+
+ if (cur_minValue==minValue && cur_maxValue==maxValue) return;
+
+ cur_minValue=minValue;
+ cur_maxValue=maxValue;
+ legend->colors.resize(3);
+ Real h = (maxValue-minValue)/(legend->colors.size()-1);
+ for(unsigned int i=0; i<legend->colors.size(); ++i)
+ legend->colors[i] = getColor4Value(minValue+h*i);
+
+ legend->labels.resize(5);
+ h = (maxValue-minValue)/(legend->labels.size()-1);
+ for(unsigned int i=0; i<legend->labels.size(); ++i)
+ {
+ char tmp[64];
+ sprintf(tmp, "%6.3f", minValue+h*i);
+ legend->labels[i]=string(tmp);
+ }
+}
+
+void ColorizedVelocityFilter::makeScale()
+{
+ if (autoScale)
+ {
+ minValue=maxValue=values[0];
+ for(int i=0,e=values.size(); i<e; ++i)
+ {
+ if (values[i]<minValue) minValue = values[i];
+ if (values[i]>maxValue) maxValue = values[i];
+ }
+ LOG_INFO("minValue:" << minValue << '\t' << "maxValue:" << maxValue);
+ }
+}
+
Vector3r ColorizedVelocityFilter::getColor4Value(Real v)
{
Vector3r color;
@@ -84,22 +138,18 @@
return color;
}
-
-void ColorizedVelocityFilter::makeScale()
-{
- minValue=maxValue=values[0];
- for(int i=0,e=values.size(); i<e; ++i)
- {
- if (values[i]<minValue) minValue = values[i];
- if (values[i]>maxValue) maxValue = values[i];
- }
- LOG_INFO("minValue:" << minValue << '\t' << "maxValue:" << maxValue);
-}
-
void ColorizedVelocityFilter::initialize(MetaBody* ncb)
{
first=false;
+ widget = shared_ptr<Body>(new Body);
+ legend = shared_ptr<ColorScale>(new ColorScale);
+ widget->geometricalModel = legend;
+ legend->title = title;
+ widget->physicalParameters = shared_ptr<PhysicalParameters>(new PhysicalParameters);
+ widget->isDynamic=false;
+ ncb->bodies->insert(widget);
+
if (onlyDynamic)
{
FOREACH(shared_ptr<Body> b, *ncb->bodies) { if(b->isDynamic) subscrBodies.push_back(b->getId()); }
Modified: trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.hpp
===================================================================
--- trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.hpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/Engine/FilterEngine/ColorizedVelocityFilter.hpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -11,6 +11,8 @@
#include<yade/pkg-common/FilterEngine.hpp>
#include<yade/core/MetaBody.hpp>
+class ColorScale;
+
class ColorizedVelocityFilter : public FilterEngine {
protected:
vector<Vector3r> prevPositions;
@@ -21,13 +23,22 @@
bool first;
void initialize(MetaBody*);
void makeScale();
+ void updateColorScale();
Vector3r getColor4Value(Real v);
+ shared_ptr<Body> widget;
+ shared_ptr<ColorScale> legend;
+ Real cur_minValue;
+ Real cur_maxValue;
public :
bool autoScale;
bool onlyDynamic;
Real minValue;
Real maxValue;
+ Real posX,posY;
+ Real width,height;
+ string title;
+
ColorizedVelocityFilter();
virtual ~ColorizedVelocityFilter();
Added: trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.cpp
===================================================================
--- trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.cpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.cpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -0,0 +1,67 @@
+/*************************************************************************
+* 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. *
+*************************************************************************/
+
+#include "GLDrawColorScale.hpp"
+#include <GL/glut.h>
+#include <yade/pkg-common/ColorScale.hpp>
+#include<yade/lib-opengl/OpenGLWrapper.hpp>
+
+void GLDrawColorScale::go(const shared_ptr<GeometricalModel>& gm, const shared_ptr<PhysicalParameters>& ph,bool wire)
+{
+ ColorScale* cs = static_cast<ColorScale*>(gm.get());
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ //int WinH = glutGet(GLUT_WINDOW_HEIGHT);
+ //int WinW = glutGet(GLUT_WINDOW_WIDTH);
+ //gluOrtho2D(0,WinW, 0,WinH);
+ gluOrtho2D(0.,1.,0.,1.);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glDisable(GL_LIGHTING);
+
+ const Real oX = cs->posX;
+ const Real oY = cs->posY;
+ const Real w = cs->width;
+ const vector<Vector3r>& colors = cs->colors;
+ const Real nbSteps = colors.size();
+ const Real hStep = cs->height/(nbSteps-1);
+ glBegin(GL_QUAD_STRIP);
+ for (int i=0; i<nbSteps; ++i)
+ {
+ glColor3f(colors[i][0],colors[i][1],colors[i][2]);
+ glVertex2f(oX, oY+i*hStep);
+ glVertex2f(oX+w,oY+i*hStep);
+ }
+ glEnd();
+
+ const vector<string>& labels = cs->labels;
+ const int nbLabels = labels.size();
+ const Real lStep = cs->height/(nbLabels-1);
+ for (int i=0; i<nbLabels; ++i)
+ {
+ glColor3f(1.,1.,1.);
+ glRasterPos2f(oX+w,oY+i*lStep);
+ for(unsigned int j=0;j<labels[i].length();j++)
+ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, labels[i][j]);
+ }
+
+ glColor3f(1.,1.,1.);
+ glRasterPos2f(oX,oY+(nbSteps-1)*hStep+0.05);
+ for(unsigned int i=0;i<cs->title.length();i++)
+ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, cs->title[i]);
+
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+
+}
+YADE_PLUGIN();
Added: trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.hpp
===================================================================
--- trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.hpp 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/RenderingEngine/GLDrawWidgets/GLDrawColorScale.hpp 2009-02-16 19:42:09 UTC (rev 1667)
@@ -0,0 +1,26 @@
+/*************************************************************************
+* 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. *
+*************************************************************************/
+
+#pragma once
+
+#include<yade/pkg-common/GLDrawFunctors.hpp>
+
+class GLDrawColorScale : public GLDrawGeometricalModelFunctor
+{
+
+ public :
+ virtual void go(const shared_ptr<GeometricalModel>&, const shared_ptr<PhysicalParameters>&,bool);
+
+ RENDERS(ColorScale);
+ REGISTER_CLASS_NAME(GLDrawColorScale);
+ REGISTER_BASE_CLASS_NAME(GLDrawGeometricalModelFunctor);
+};
+
+REGISTER_SERIALIZABLE(GLDrawColorScale);
+
+
Modified: trunk/pkg/common/SConscript
===================================================================
--- trunk/pkg/common/SConscript 2009-02-16 09:28:32 UTC (rev 1666)
+++ trunk/pkg/common/SConscript 2009-02-16 19:42:09 UTC (rev 1667)
@@ -47,6 +47,7 @@
env.SharedLibrary('Tetrahedron',['DataClass/GeometricalModel/Tetrahedron.cpp']),
env.SharedLibrary('Quadrilateral',['DataClass/GeometricalModel/Quadrilateral.cpp']),
env.SharedLibrary('Facet',['DataClass/GeometricalModel/Facet.cpp']),
+ env.SharedLibrary('ColorScale',['DataClass/Widgets/ColorScale.cpp']),
env.SharedLibrary('MomentEngine',['Engine/DeusExMachina/MomentEngine.cpp'],
LIBS=env['LIBS']+['Momentum','ParticleParameters']),
env.SharedLibrary('ForceEngine',['Engine/DeusExMachina/ForceEngine.cpp'],
@@ -110,7 +111,7 @@
env.SharedLibrary('ColorizedLayerFilter',['Engine/FilterEngine/ColorizedLayerFilter.cpp'],
LIBS=env['LIBS']+['FilterEngine']),
env.SharedLibrary('ColorizedVelocityFilter',['Engine/FilterEngine/ColorizedVelocityFilter.cpp'],
- LIBS=env['LIBS']+['FilterEngine']),
+ LIBS=env['LIBS']+['FilterEngine','ColorScale']),
env.SharedLibrary('BoundingVolumeMetaEngine',['Engine/MetaEngine/BoundingVolumeMetaEngine.cpp']),
env.SharedLibrary('GeometricalModelMetaEngine',['Engine/MetaEngine/GeometricalModelMetaEngine.cpp']),
env.SharedLibrary('InteractingGeometryMetaEngine',['Engine/MetaEngine/InteractingGeometryMetaEngine.cpp']),
@@ -196,6 +197,8 @@
env.SharedLibrary('GLDrawNormalInteraction',['RenderingEngine/GLDrawInteractionPhysics/GLDrawNormalInteraction.cpp'],LIBS=env['LIBS']+['yade-opengl','NormalShearInteractions']),
env.SharedLibrary('GLDrawParticleState',['RenderingEngine/GLDrawState/GLDrawParticleState.cpp'],
LIBS=env['LIBS']+['yade-base','ParticleParameters','yade-opengl']),
+ env.SharedLibrary('GLDrawColorScale',['RenderingEngine/GLDrawWidgets/GLDrawColorScale.cpp'],
+ LIBS=env['LIBS']+['yade-base','ColorScale','yade-opengl']),
env.SharedLibrary('GLDrawRigidBodyState',['RenderingEngine/GLDrawState/GLDrawRigidBodyState.cpp'],
LIBS=env['LIBS']+['ParticleParameters','RigidBodyParameters','GLDrawParticleState','yade-opengl']),
env.SharedLibrary('OpenGLRenderingEngine',['RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp'],
Follow ups