~yade-dev/yade/0.90

« back to all changes in this revision

Viewing changes to pkg/dem/SnapshotEngine.cpp

  • Committer: Anton Gladky
  • Date: 2012-11-03 20:46:43 UTC
  • Revision ID: gladky.anton@gmail.com-20121103204643-hprdffm1hulq95f6
0.90.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef YADE_OPENGL
 
2
 
 
3
#include"SnapshotEngine.hpp"
 
4
 
 
5
YADE_PLUGIN((SnapshotEngine));
 
6
CREATE_LOGGER(SnapshotEngine);
 
7
 
 
8
void SnapshotEngine::action(){
 
9
        if(!OpenGLManager::self) throw logic_error("No OpenGLManager instance?!");
 
10
        if(OpenGLManager::self->views.size()==0){
 
11
                int viewNo=OpenGLManager::self->waitForNewView(deadTimeout);
 
12
                if(viewNo<0){
 
13
                        if(!ignoreErrors) throw runtime_error("SnapshotEngine: Timeout waiting for new 3d view.");
 
14
                        else {
 
15
                                LOG_WARN("Making myself Engine::dead, as I can not live without a 3d view (timeout)."); dead=true; return;
 
16
                        }
 
17
                }
 
18
        }
 
19
        const shared_ptr<GLViewer>& glv=OpenGLManager::self->views[0];
 
20
        ostringstream fss; fss<<fileBase<<setw(5)<<setfill('0')<<counter++<<"."<<boost::algorithm::to_lower_copy(format);
 
21
        LOG_DEBUG("GL view → "<<fss.str())
 
22
        glv->setSnapshotFormat(QString(format.c_str()));
 
23
        glv->nextFrameSnapshotFilename=fss.str();
 
24
        // wait for the renderer to save the frame (will happen at next postDraw)
 
25
        timespec t1,t2; t1.tv_sec=0; t1.tv_nsec=10000000; /* 10 ms */
 
26
        long waiting=0;
 
27
        while(!glv->nextFrameSnapshotFilename.empty()){
 
28
                nanosleep(&t1,&t2); waiting++;
 
29
                if(((waiting) % 1000)==0) LOG_WARN("Already waiting "<<waiting/100<<"s for snapshot to be saved. Something went wrong?");
 
30
                if(waiting/100.>deadTimeout){
 
31
                        if(ignoreErrors){ LOG_WARN("Timeout waiting for snapshot to be saved, making byself Engine::dead"); dead=true; return; }
 
32
                        else throw runtime_error("SnapshotEngine: Timeout waiting for snapshot to be saved.");
 
33
                }
 
34
        }
 
35
        snapshots.push_back(fss.str());
 
36
        usleep((long)(msecSleep*1000));
 
37
        //if(!plot.empty()){ pyRunString("import yade.plot; yade.plot.addImgData("+plot+"='"+fss.str()+"')"); }
 
38
}
 
39
 
 
40
 
 
41
#endif /* YADE_OPENGL */