[vtkusers] Problem with displaying data (vtkSmartVolumeMapper and Qt4)
Sebastian Klein
sebimail at ymail.com
Fri Dec 14 11:55:08 EST 2012
Hello,
I'm writing a MIP-Viewer (I use vtkSmartVolumeMapper). The result of it should be displayed in a qt window. I use Qt 4.8.0 and VTK 5.10.
There are three classes:
- MIP-Viewer (VTK only)
- QVTKMIPViewer (widget that displays the MIP content)
- MainWindow (small application to illustrate my problem)
The MIP viewer is initialized with a placeholder object for the vtkSmartVolumeMapper. After clicking on a button (buttonLoadDicom) a dicom data set should be displayed instead of the placeholder. This does not work and I don't know why. I wrote three small classes listed below to illustrate the problem in my application. Calling SetInput(...) inside of the MainWindow constructor works but not outside of it.
Any idea why the dicom content is not displayed after clicking on the button?
CODE:
----- MainWindow -----
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
{
m_pDicomData = vtkDICOMImageReader::New();
this->resize(800,600);
m_pQVTKMIPViewer = new QVTKMIPViewer(this);
m_pDicomData->SetDirectoryName("C:/dicom");
m_pDicomData->Update();
SetupUi();
//m_pQVTKMIPViewer->SetInput(m_pDicomData->GetOutput()); <- THIS WORKS: DICOM CONTENT IS DISPLAYED
}
////////////////////////////////////////////////////////////////////////////////////
void MainWindow::SetupUi()
{
buttonLoadDicom = new QPushButton("load DICOM", this);
connect(buttonLoadDicom, SIGNAL(clicked()), this, SLOT(OnLoadDicom()));
//layout
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QHBoxLayout *hLayout = new QHBoxLayout(this);
hLayout->addWidget(buttonLoadDicom);
mainLayout->addWidget(m_pQVTKMIPViewer);
mainLayout->addLayout(hLayout);
this->setLayout(mainLayout);
}
////////////////////////////////////////////////////////////////////////////////////
void MainWindow::OnLoadDicom() //slot
{
m_pQVTKMIPViewer->SetInput(m_pDicomData->GetOutput()); // <- THIS DOES NOT WORK: DICOM CONTENT IS NOT DISPLAYED (command is executed after clicking...)
}
////////////////////////////////////////////////////////////////////////////////////
----- QVTKMIPViewer -----
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
QVTKMIPViewer::QVTKMIPViewer(QWidget *parent) : QWidget(parent),
m_pMIPViewer(NULL),
m_pInteractor(NULL),
m_pQVTKWidget(NULL),
m_pRenderer(NULL),
m_pRenderWindow(NULL),
m_pImageData(NULL)
{
m_pMIPViewer = MIPViewer::New();
m_pQVTKWidget = new QVTKWidget(this);
m_pQVTKWidget->setMinimumSize(300,300);
m_pQVTKWidget->SetRenderWindow(m_pMIPViewer->GetRenderWindow());
}
////////////////////////////////////////////////////////////////////////////////////
void QVTKMIPViewer::SetInput(vtkImageData* pImageData)
{
m_pMIPViewer->SetInput(pImageData);
}
////////////////////////////////////////////////////////////////////////////////////
----- MIPVIEWER -----
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
MIPViewer::MIPViewer():vtkObject(),
m_dInitialLevel(2048),
m_dInitialWindow(4096)
{
this->m_pColorFunc = vtkColorTransferFunction::New();
this->m_pOpacityFunc = vtkPiecewiseFunction::New();
this->m_pVolumeMapper = vtkSmartVolumeMapper::New();
this->m_pVolume = vtkVolume::New();
this->m_pVolumeProperty = vtkVolumeProperty::New();
this->m_pRenderer = NULL;
this->m_pRenderWindow = NULL;
this->m_pImageData = NULL;
vtkRenderWindow *renWin = vtkRenderWindow::New();
this->SetRenderWindow(renWin);
renWin->Delete();
vtkRenderer *ren = vtkRenderer::New();
this->SetRenderer(ren);
ren->Delete();
//set dummy data
m_pDummyImage = vtkImageData::New();
m_pDummyImage->SetDimensions(2,2,2);
m_pDummyImage->SetScalarTypeToUnsignedShort();
m_pDummyImage->AllocateScalars(); // allocate storage for image data
unsigned short * VolPtr = (unsigned short *) m_pDummyImage->GetScalarPointer();
for(int i=0; i<2*2*2; i++ )
{
*VolPtr= 900;
*VolPtr++;
}
m_pDummyImage->Update();
m_pColorFunc->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );
m_pOpacityFunc->AddSegment( m_dInitialLevel - 0.5 * m_dInitialWindow, 0.0, m_dInitialLevel + 0.5 * m_dInitialWindow, 1.0 );
m_pVolumeProperty->SetColor( m_pColorFunc );
m_pVolumeProperty->SetScalarOpacity( m_pOpacityFunc );
m_pVolume->SetProperty( m_pVolumeProperty );
m_pVolumeMapper->SetBlendModeToMaximumIntensity();
this->SetInput(m_pDummyImage);
this->m_pVolume->SetMapper(this->m_pVolumeMapper);
}
////////////////////////////////////////////////////////////////////////////////////
void MIPViewer::SetRenderWindow(vtkRenderWindow *renWin)
{
if (this->m_pRenderWindow == renWin)
{
return;
}
if (this->m_pRenderWindow)
{
this->m_pRenderWindow->UnRegister(this);
}
this->m_pRenderWindow = renWin;
if (this->m_pRenderWindow)
{
this->m_pRenderWindow->Register(this);
}
}
////////////////////////////////////////////////////////////////////////////////////
void MIPViewer::SetRenderer(vtkRenderer *ren)
{
if (this->m_pRenderer == ren)
{
return;
}
if(m_pRenderWindow && m_pRenderer)
{
this->m_pRenderWindow->RemoveRenderer(this->m_pRenderer);
}
if (this->m_pRenderer)
{
this->m_pRenderer->UnRegister(this);
}
this->m_pRenderer = ren;
if (this->m_pRenderer)
{
this->m_pRenderer->Register(this);
}
this->m_pRenderWindow->AddRenderer(this->m_pRenderer);
this->m_pRenderer->AddViewProp(this->m_pVolume);
}
////////////////////////////////////////////////////////////////////////////////////
void MIPViewer::SetInput(vtkImageData *pImageData)
{
m_pImageData = pImageData;
if(pImageData)
{
if(m_pVolumeMapper->GetInput())
{
m_pVolumeMapper->RemoveAllInputs();
}
m_pVolumeMapper->SetInput(m_pImageData);
}
}
////////////////////////////////////////////////////////////////////////////////////
vtkImageData* MIPViewer::GetInput()
{
return m_pVolumeMapper->GetInput();
}
////////////////////////////////////////////////////////////////////////////////////
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121214/21e6ded0/attachment.htm>
More information about the vtkusers
mailing list