37 #include "vtkRenderWindow.h"
49 mPreRenderSignalRequested(false),
52 mBaseRenderInterval(40)
54 mLastFullRender = QDateTime::currentDateTime();
57 mTimer =
new QTimer(
this);
58 connect(mTimer, SIGNAL(timeout()),
this, SLOT(timeoutSlot()));
60 this->sendRenderIntervalToTimer(mBaseRenderInterval);
76 return mTimer->isActive();
81 mPreRenderSignalRequested =
true;
86 mBaseRenderInterval = interval;
87 this->sendRenderIntervalToTimer(mBaseRenderInterval);
100 void RenderLoop::sendRenderIntervalToTimer(
int interval)
102 if (interval==mTimer->interval())
110 mTimer->setInterval(interval);
117 mLayoutWidgets.push_back(layout);
123 mLayoutWidgets.clear();
126 void RenderLoop::timeoutSlot()
128 mCyclicLogger->begin();
129 mLastBeginRender = QDateTime::currentDateTime();
130 this->sendRenderIntervalToTimer(mBaseRenderInterval);
132 this->emitPreRenderIfRequested();
136 this->emitFPSIfRequired();
138 int timeToNext = this->calculateTimeToNextRender();
139 this->sendRenderIntervalToTimer(timeToNext);
142 void RenderLoop::emitPreRenderIfRequested()
144 if(mPreRenderSignalRequested)
147 mPreRenderSignalRequested =
false;
152 void RenderLoop::renderViews()
154 bool smart = this->pollForSmartRenderingThisCycle();
156 for (
unsigned i=0; i<mLayoutWidgets.size(); ++i)
158 if (mLayoutWidgets[i])
161 mLayoutWidgets[i]->setModified();
162 mLayoutWidgets[i]->render();
166 mCyclicLogger->time(
"render");
169 bool RenderLoop::pollForSmartRenderingThisCycle()
173 bool smart = mSmartRender;
174 int smartInterval = mTimer->interval() * 40;
175 int passed = mLastFullRender.time().msecsTo(QDateTime::currentDateTime().time());
177 if (passed > smartInterval)
180 mLastFullRender = QDateTime::currentDateTime();
184 void RenderLoop::emitFPSIfRequired()
186 if (mCyclicLogger->intervalPassed())
188 emit
fps(mCyclicLogger->getFPS());
189 this->dumpStatistics();
193 mCyclicLogger->reset();
197 void RenderLoop::dumpStatistics()
202 static int counter=0;
207 int RenderLoop::calculateTimeToNextRender()
212 int usage = mLastBeginRender.msecsTo(QDateTime::currentDateTime());
213 int leftover = std::max(0, mTimer->interval() - usage);
214 int timeToNext = std::max(1, leftover);
void setRenderingInterval(int interval)
void fps(int number)
Emits number of frames per second.
void addLayout(ViewCollectionWidget *layout)
void setSmartRender(bool val)
If set: Render only views with modified props using the given interval, render nonmodified at a slowe...
void requestPreRenderSignal()
void reportDebug(QString msg)