Author: eudoxos
Date: 2009-01-18 13:30:14 +0100 (Sun, 18 Jan 2009)
New Revision: 1627

Modified:
   trunk/extra/Brefcom.cpp
   trunk/gui/qt3/GLSimulationPlayerViewer.cpp
   trunk/gui/qt3/GLSimulationPlayerViewer.hpp
   trunk/gui/qt3/QtGUI-python.cpp
   trunk/gui/qt3/qt.py
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
   trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
Log:
1. fix damage colorizer (removed dynamic_cast causing segfaults on non-spheres)
2. InterpolatingSpiralEngine now takes bool wrap rather than Real period.
3. qt.makePlayerVideo takse startWait argument, which waits for Backspace 
before starting (useful for setting up the view manually); postLoadHook gets 
run afterwards now.



Modified: trunk/extra/Brefcom.cpp
===================================================================
--- trunk/extra/Brefcom.cpp     2009-01-17 22:26:54 UTC (rev 1626)
+++ trunk/extra/Brefcom.cpp     2009-01-18 12:30:14 UTC (rev 1627)
@@ -272,7 +272,8 @@
        FOREACH(shared_ptr<Body> B, *rootBody->bodies){
                body_id_t id=B->getId();
                // add damaged contacts that have already been deleted
-               shared_ptr<BrefcomPhysParams> 
bpp=YADE_PTR_CAST<BrefcomPhysParams>(B->physicalParameters);
+               BrefcomPhysParams* 
bpp=dynamic_cast<BrefcomPhysParams*>(B->physicalParameters.get());
+               if(!bpp) continue;
                //if(bodyDamage[B->getId()].first==0) 
{B->geometricalModel->diffuseColor=Vector3r(0.5,0.5,B->isDynamic?0:1); 
continue; }
                int 
pastOrPresentContacts=bodyDamage[id].first+bpp->numBrokenCohesive;
                if(pastOrPresentContacts>0) 
bpp->normDmg=(bodyDamage[id].second+bpp->numBrokenCohesive)/pastOrPresentContacts;

Modified: trunk/gui/qt3/GLSimulationPlayerViewer.cpp
===================================================================
--- trunk/gui/qt3/GLSimulationPlayerViewer.cpp  2009-01-17 22:26:54 UTC (rev 
1626)
+++ trunk/gui/qt3/GLSimulationPlayerViewer.cpp  2009-01-18 12:30:14 UTC (rev 
1627)
@@ -39,6 +39,7 @@
 
 void GLSimulationPlayerViewer::keyPressEvent(QKeyEvent* e){
        if(e->key()==Qt::Key_H && (e->state() & AltButton)){ 
if(simPlayer->isHidden()) simPlayer->show(); else simPlayer->hide(); }
+       else if(e->key()==Qt::Key_Backspace && !trigger) { trigger=true; }
        else GLViewer::keyPressEvent(e);
 }
 

Modified: trunk/gui/qt3/GLSimulationPlayerViewer.hpp
===================================================================
--- trunk/gui/qt3/GLSimulationPlayerViewer.hpp  2009-01-17 22:26:54 UTC (rev 
1626)
+++ trunk/gui/qt3/GLSimulationPlayerViewer.hpp  2009-01-18 12:30:14 UTC (rev 
1627)
@@ -32,6 +32,7 @@
                Real wallClock, realTime;
                virtual string getRealTimeString();
        public:
+               bool trigger;
                list<string> snapshots;
                QtSimulationPlayer* simPlayer;
                boost::posix_time::ptime lastCheckPointTime;

Modified: trunk/gui/qt3/QtGUI-python.cpp
===================================================================
--- trunk/gui/qt3/QtGUI-python.cpp      2009-01-17 22:26:54 UTC (rev 1626)
+++ trunk/gui/qt3/QtGUI-python.cpp      2009-01-18 12:30:14 UTC (rev 1627)
@@ -75,25 +75,21 @@
  *
  * @returns tuple of (wildcard,[snap0,snap1,snap2,...]), where the list 
contains filename of snapshots.
  */
-python::tuple runPlayerSession(string savedSim,string snapBase="",string 
savedQGLState="",int dispParamsNo=-1,int stride=1,string postLoadHook=""){
+python::tuple runPlayerSession(string savedSim,string snapBase="",string 
savedQGLState="",int dispParamsNo=-1,int stride=1,string postLoadHook="",bool 
startWait=false){
        evtPLAYER();
        shared_ptr<QtSimulationPlayer> player=ensuredMainWindow()->player;
        GLSimulationPlayerViewer* glv=player->glSimulationPlayerViewer;
-       player->hide();
        string snapBase2(snapBase);
        if(snapBase2.empty()){ char tmpnam_str [L_tmpnam]; tmpnam(tmpnam_str); 
snapBase2=tmpnam_str; LOG_INFO("Using "<<snapBase2<<" as temporary basename for 
snapshots."); }
        glv->stride=stride;
        glv->load(savedSim);
-       if(!postLoadHook.empty()){ PyGILState_STATE gstate; LOG_INFO("Running 
postLoadHook "<<postLoadHook); Py_BEGIN_ALLOW_THREADS; gstate = 
PyGILState_Ensure(); PyRun_SimpleString(postLoadHook.c_str()); 
PyGILState_Release(gstate); Py_END_ALLOW_THREADS; }
        glv->saveSnapShots=true;
        glv->snapshotsBase=snapBase2;
-       if(!savedQGLState.empty()){
-               LOG_INFO("Loading view state from "<<savedQGLState);
-               glv->setStateFileName(savedQGLState);
-               glv->restoreStateFromFile();
-               glv->setStateFileName(QString::null);
-       }
+       if(!savedQGLState.empty()){ LOG_INFO("Loading view state from 
"<<savedQGLState); glv->setStateFileName(savedQGLState); 
glv->restoreStateFromFile(); glv->setStateFileName(QString::null); }
        if(dispParamsNo>=0) { LOG_INFO("Loading view state from state 
#"<<dispParamsNo); glv->useDisplayParameters(dispParamsNo);}
+       if(startWait){ LOG_INFO("[[[ Manual view setup, press BACKSPACE to 
start player ]]]"); glv->trigger=false; while(!glv->trigger) 
{usleep(200000);cerr<<"@";} }
+       if(!postLoadHook.empty()){ PyGILState_STATE gstate; LOG_INFO("Running 
postLoadHook "<<postLoadHook); Py_BEGIN_ALLOW_THREADS; gstate = 
PyGILState_Ensure(); PyRun_SimpleString(postLoadHook.c_str()); 
PyGILState_Release(gstate); Py_END_ALLOW_THREADS; }
+       player->hide();
        glv->raise();
        glv->startAnimation();
        Py_BEGIN_ALLOW_THREADS;
@@ -105,7 +101,7 @@
 
 bool qtGuiIsActive(){return (bool)YadeQtMainWindow::self;}
 
-BOOST_PYTHON_FUNCTION_OVERLOADS(runPlayerSession_overloads,runPlayerSession,2,6);
+BOOST_PYTHON_FUNCTION_OVERLOADS(runPlayerSession_overloads,runPlayerSession,2,7);
 
 qglviewer::Vec tuple2vec(python::tuple t){ qglviewer::Vec ret; for(int 
i=0;i<3;i++){python::extract<Real> e(t[i]); if(!e.check()) throw 
invalid_argument("Element #"+lexical_cast<string>(i)+" is not a number"); 
ret[i]=e();} return ret;};
 python::tuple vec2tuple(qglviewer::Vec v){return 
python::make_tuple(v[0],v[1],v[2]);};
@@ -166,7 +162,7 @@
        def("Renderer",ensuredRenderer,"Return wrapped OpenGLRenderingEngine; 
the renderer is constructed if necessary.");
        def("close",Quit);
        def("isActive",qtGuiIsActive,"Whether the Qt GUI is being used.");
-       
def("runPlayerSession",runPlayerSession,runPlayerSession_overloads(args("savedQGLState","dispParamsNo","stride","postLoadHook")));
+       
def("runPlayerSession",runPlayerSession,runPlayerSession_overloads(args("savedQGLState","dispParamsNo","stride","postLoadHook","startWait")));
        def("views",getAllViews);
 
        BASIC_PY_PROXY_WRAPPER(pyOpenGLRenderingEngine,"GLRenderer")

Modified: trunk/gui/qt3/qt.py
===================================================================
--- trunk/gui/qt3/qt.py 2009-01-17 22:26:54 UTC (rev 1626)
+++ trunk/gui/qt3/qt.py 2009-01-18 12:30:14 UTC (rev 1627)
@@ -36,7 +36,7 @@
        o.engines=origEngines
 
 
-def 
makePlayerVideo(playerDb,out,viewerState=None,dispParamsNo=-1,stride=1,fps=24,postLoadHook=None):
+def 
makePlayerVideo(playerDb,out,viewerState=None,dispParamsNo=-1,stride=1,fps=24,postLoadHook=None,startWait=False):
        """Create video by replaying a simulation. Snapshots are taken to 
temporary files,
        encoded to a .ogg stream (theora codec); temps are deleted at the end.
 
@@ -59,7 +59,8 @@
                savedQGLState=(viewerState if viewerState else ''),
                dispParamsNo=dispParamsNo,
                stride=stride,
-               postLoadHook=(postLoadHook if postLoadHook else ''))
+               postLoadHook=(postLoadHook if postLoadHook else ''),
+               startWait=startWait)
        
utils.encodeVideoFromFrames(wildcard,out,renameNotOverwrite=True,fps=fps)
        print "Cleaning snapshot files."
        for f in snaps: os.remove(f)

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp    2009-01-17 
22:26:54 UTC (rev 1626)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.cpp    2009-01-18 
12:30:14 UTC (rev 1627)
@@ -21,7 +21,7 @@
 
 
 void InterpolatingSpiralEngine::applyCondition(MetaBody* rb){
-       Real virtTime=period>0 ? 
Shop::periodicWrap(rb->simulationTime,0,period) : rb->simulationTime;
+       Real virtTime=wrap ? 
Shop::periodicWrap(rb->simulationTime,*times.begin(),*times.rbegin()) : 
rb->simulationTime;
        
angularVelocity=linearInterpolate<Real>(virtTime,times,angularVelocities,pos);
        linearVelocity=angularVelocity*slope;
        SpiralEngine::applyCondition(rb);

Modified: trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp
===================================================================
--- trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp    2009-01-17 
22:26:54 UTC (rev 1626)
+++ trunk/pkg/common/Engine/DeusExMachina/RotationEngine.hpp    2009-01-18 
12:30:14 UTC (rev 1627)
@@ -50,8 +50,8 @@
  * times and velocities and translation by using slope parameter.
  *
  * The interpolation assumes the margin value before the first time point and 
last value
- * after the last time point. If period is specified, time will wrap around, 
but no interpolation
- * between last and first values is done!
+ * after the last time point. If wrap is specified, time will wrap around the 
last times value to the first one (note that no interpolation
+ * between last and first values is done).
  * */
 class InterpolatingSpiralEngine: public SpiralEngine{
        public:
@@ -59,16 +59,16 @@
                vector<Real> times;
                //! list of angular velocities; manadatorily of same length as 
times
                vector<Real> angularVelocities;
-               //! period after which we will wrap time to zero (no wrapping 
if period<=0)
-               Real period;
+               //! wrap t if t>times_n, i.e. t_wrapped=t-N*(times_n-times_0)
+               bool wrap;
                //! axial translation per radian turn (can be negative)
                Real slope;
                //! holder of interpolation state, should not be touched by the 
user.
                size_t pos;
-               InterpolatingSpiralEngine(): period(-1), slope(0), pos(0){}
+               InterpolatingSpiralEngine(): wrap(false), slope(0), pos(0){}
                virtual void applyCondition(MetaBody* rb);
        REGISTER_CLASS_AND_BASE(InterpolatingSpiralEngine,SpiralEngine);
-       
REGISTER_ATTRIBUTES(SpiralEngine,(times)(angularVelocities)(period)(slope)(pos));
+       
REGISTER_ATTRIBUTES(SpiralEngine,(times)(angularVelocities)(wrap)(slope)(pos));
 };
 REGISTER_SERIALIZABLE(InterpolatingSpiralEngine);
 


_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to