16 #include "vtkRenderWindow.h" 30 mBaseRenderInterval(40)
32 mLastFullRender = QDateTime::currentDateTime();
35 mTimer =
new QTimer(
this);
36 connect(mTimer, SIGNAL(timeout()),
this, SLOT(timeoutSlot()));
38 this->sendRenderIntervalToTimer(mBaseRenderInterval);
54 return mTimer->isActive();
59 mBaseRenderInterval = interval;
60 this->sendRenderIntervalToTimer(mBaseRenderInterval);
73 void RenderLoop::sendRenderIntervalToTimer(
int interval)
75 if (interval==mTimer->interval())
83 mTimer->setInterval(interval);
90 mLayoutWidgets.push_back(layout);
96 mLayoutWidgets.clear();
99 void RenderLoop::timeoutSlot()
101 mCyclicLogger->begin();
102 mLastBeginRender = QDateTime::currentDateTime();
103 this->sendRenderIntervalToTimer(mBaseRenderInterval);
109 this->emitFPSIfRequired();
111 int timeToNext = this->calculateTimeToNextRender();
112 this->sendRenderIntervalToTimer(timeToNext);
115 void RenderLoop::renderViews()
117 bool smart = this->pollForSmartRenderingThisCycle();
119 for (
unsigned i=0; i<mLayoutWidgets.size(); ++i)
121 if (mLayoutWidgets[i])
124 mLayoutWidgets[i]->setModified();
125 mLayoutWidgets[i]->render();
129 mCyclicLogger->time(
"render");
133 bool RenderLoop::pollForSmartRenderingThisCycle()
137 bool smart = mSmartRender;
138 int smartInterval = mTimer->interval() * 40;
139 int passed = mLastFullRender.time().msecsTo(QDateTime::currentDateTime().time());
141 if (passed > smartInterval)
144 mLastFullRender = QDateTime::currentDateTime();
148 void RenderLoop::emitFPSIfRequired()
150 if (mCyclicLogger->intervalPassed())
152 emit
fps(mCyclicLogger->getFPS());
153 this->dumpStatistics();
157 mCyclicLogger->reset();
161 void RenderLoop::dumpStatistics()
166 static int counter=0;
171 int RenderLoop::calculateTimeToNextRender()
176 int usage = mLastBeginRender.msecsTo(QDateTime::currentDateTime());
177 int leftover = std::max(0, mTimer->interval() - usage);
178 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.