37 #include "vtkRenderWindow.h" 51 mBaseRenderInterval(40)
53 mLastFullRender = QDateTime::currentDateTime();
56 mTimer =
new QTimer(
this);
57 connect(mTimer, SIGNAL(timeout()),
this, SLOT(timeoutSlot()));
59 this->sendRenderIntervalToTimer(mBaseRenderInterval);
75 return mTimer->isActive();
80 mBaseRenderInterval = interval;
81 this->sendRenderIntervalToTimer(mBaseRenderInterval);
94 void RenderLoop::sendRenderIntervalToTimer(
int interval)
96 if (interval==mTimer->interval())
104 mTimer->setInterval(interval);
111 mLayoutWidgets.push_back(layout);
117 mLayoutWidgets.clear();
120 void RenderLoop::timeoutSlot()
122 mCyclicLogger->begin();
123 mLastBeginRender = QDateTime::currentDateTime();
124 this->sendRenderIntervalToTimer(mBaseRenderInterval);
130 this->emitFPSIfRequired();
132 int timeToNext = this->calculateTimeToNextRender();
133 this->sendRenderIntervalToTimer(timeToNext);
136 void RenderLoop::renderViews()
138 bool smart = this->pollForSmartRenderingThisCycle();
140 for (
unsigned i=0; i<mLayoutWidgets.size(); ++i)
142 if (mLayoutWidgets[i])
145 mLayoutWidgets[i]->setModified();
146 mLayoutWidgets[i]->render();
150 mCyclicLogger->time(
"render");
154 bool RenderLoop::pollForSmartRenderingThisCycle()
158 bool smart = mSmartRender;
159 int smartInterval = mTimer->interval() * 40;
160 int passed = mLastFullRender.time().msecsTo(QDateTime::currentDateTime().time());
162 if (passed > smartInterval)
165 mLastFullRender = QDateTime::currentDateTime();
169 void RenderLoop::emitFPSIfRequired()
171 if (mCyclicLogger->intervalPassed())
173 emit
fps(mCyclicLogger->getFPS());
174 this->dumpStatistics();
178 mCyclicLogger->reset();
182 void RenderLoop::dumpStatistics()
187 static int counter=0;
192 int RenderLoop::calculateTimeToNextRender()
197 int usage = mLastBeginRender.msecsTo(QDateTime::currentDateTime());
198 int leftover = std::max(0, mTimer->interval() - usage);
199 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 reportDebug(QString msg)
Namespace for all CustusX production code.