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");
170 bool RenderLoop::pollForSmartRenderingThisCycle()
174 bool smart = mSmartRender;
175 int smartInterval = mTimer->interval() * 40;
176 int passed = mLastFullRender.time().msecsTo(QDateTime::currentDateTime().time());
178 if (passed > smartInterval)
181 mLastFullRender = QDateTime::currentDateTime();
185 void RenderLoop::emitFPSIfRequired()
187 if (mCyclicLogger->intervalPassed())
189 emit
fps(mCyclicLogger->getFPS());
190 this->dumpStatistics();
194 mCyclicLogger->reset();
198 void RenderLoop::dumpStatistics()
203 static int counter=0;
208 int RenderLoop::calculateTimeToNextRender()
213 int usage = mLastBeginRender.msecsTo(QDateTime::currentDateTime());
214 int leftover = std::max(0, mTimer->interval() - usage);
215 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)