Commit 0f7416b4 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Cleaned up image caching code making it easier to override in subclass.

Change-Id: I550224136e5270a29b4e30eeaffc3cc2de681f93
parent 009705a6
......@@ -315,14 +315,14 @@ void QVTKWidget::saveImageToCache()
int w = this->width();
int h = this->height();
this->mCachedImage->SetWholeExtent(0, w-1, 0, h-1, 0, 0);
this->mCachedImage->SetNumberOfScalarComponents(3);
this->mCachedImage->SetExtent(this->mCachedImage->GetWholeExtent());
this->mCachedImage->SetExtent(0, w-1, 0, h-1, 0, 0);
this->mCachedImage->AllocateScalars();
vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast(
this->mCachedImage->GetPointData()->GetScalars());
this->mRenWin->GetPixelData(0, 0, this->width()-1, this->height()-1, 1,
array);
// We use back-buffer if
this->mRenWin->GetPixelData(0, 0, this->width()-1, this->height()-1,
this->mRenWin->GetDoubleBuffer()? 0 /*back*/ : 1 /*front*/, array);
this->cachedImageCleanFlag = true;
emit cachedImageClean();
}
......@@ -465,19 +465,10 @@ void QVTKWidget::paintEvent(QPaintEvent* )
{
return;
}
// if we have a saved image, use it
if (this->cachedImageCleanFlag)
if (this->paintCachedImage())
{
vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast(
this->mCachedImage->GetPointData()->GetScalars());
// put cached image into back buffer if we can
this->mRenWin->SetPixelData(0, 0, this->width()-1, this->height()-1,
array, !this->mRenWin->GetDoubleBuffer());
// swap buffers, if double buffering
this->mRenWin->Frame();
// or should we just put it on the front buffer?
return;
}
......@@ -841,6 +832,26 @@ OSStatus QVTKWidget::DirtyRegionProcessor(EventHandlerCallRef, EventRef event, v
#endif
//-----------------------------------------------------------------------------
bool QVTKWidget::paintCachedImage()
{
// if we have a saved image, use it
if (this->cachedImageCleanFlag)
{
vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast(
this->mCachedImage->GetPointData()->GetScalars());
// put cached image into back buffer if we can
this->mRenWin->SetPixelData(0, 0, this->width()-1, this->height()-1,
array, !this->mRenWin->GetDoubleBuffer());
// swap buffers, if double buffering
this->mRenWin->Frame();
// or should we just put it on the front buffer?
return true;
}
return false;
}
//-----------------------------------------------------------------------------
static void dirty_cache(vtkObject *caller, unsigned long,
void *clientdata, void *)
{
......
......@@ -232,6 +232,11 @@ protected:
// overload drop event
virtual void dropEvent(QDropEvent*);
// method called in paintEvent() to render the image cache on to the device.
// return false, if cache couldn;t be used for painting. In that case, the
// paintEvent() method will continue with the default painting code.
virtual bool paintCachedImage();
// the vtk render window
vtkRenderWindow* mRenWin;
bool UseTDx;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment