<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">Hello,<br><br>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.<br>There are three classes:<br>- MIP-Viewer (VTK only)<br>- QVTKMIPViewer (widget that displays the MIP content)<br>- MainWindow (small application to illustrate my problem)<br><br>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.<br><br>Any idea why the dicom content is not displayed after clicking on the button? <br><br><br>CODE:<br>----- MainWindow -----<br>////////////////////////////////////////////////////////////////////////////////////<br>////////////////////////////////////////////////////////////////////////////////////<br>MainWindow::MainWindow(QWidget *parent) : QWidget(parent)<br>{<br> m_pDicomData = vtkDICOMImageReader::New();<br> this->resize(800,600);<br> m_pQVTKMIPViewer = new QVTKMIPViewer(this);<br> m_pDicomData->SetDirectoryName("C:/dicom");<br> m_pDicomData->Update();<br> SetupUi();<br> <br> //m_pQVTKMIPViewer->SetInput(m_pDicomData->GetOutput()); <- THIS WORKS: DICOM CONTENT IS
DISPLAYED<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void MainWindow::SetupUi()<br>{<br> buttonLoadDicom = new QPushButton("load DICOM", this);<br> connect(buttonLoadDicom, SIGNAL(clicked()), this, SLOT(OnLoadDicom()));<br><br> //layout<br> QVBoxLayout *mainLayout = new QVBoxLayout(this);<br> QHBoxLayout *hLayout = new QHBoxLayout(this);<br> hLayout->addWidget(buttonLoadDicom);<br> mainLayout->addWidget(m_pQVTKMIPViewer);<br> mainLayout->addLayout(hLayout);<br> this->setLayout(mainLayout);<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void MainWindow::OnLoadDicom() //slot<br>{<br> m_pQVTKMIPViewer->SetInput(m_pDicomData->GetOutput()); // <- THIS DOES NOT
WORK: DICOM CONTENT IS NOT DISPLAYED (command is executed after clicking...)<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br><br><br>----- QVTKMIPViewer -----<br>////////////////////////////////////////////////////////////////////////////////////<br>////////////////////////////////////////////////////////////////////////////////////<br>QVTKMIPViewer::QVTKMIPViewer(QWidget *parent) : QWidget(parent),<br>m_pMIPViewer(NULL),<br>m_pInteractor(NULL),<br>m_pQVTKWidget(NULL),<br>m_pRenderer(NULL),<br>m_pRenderWindow(NULL),<br>m_pImageData(NULL)<br>{<br> m_pMIPViewer = MIPViewer::New();<br> m_pQVTKWidget = new QVTKWidget(this);<br> m_pQVTKWidget->setMinimumSize(300,300);<br>
m_pQVTKWidget->SetRenderWindow(m_pMIPViewer->GetRenderWindow());<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void QVTKMIPViewer::SetInput(vtkImageData* pImageData)<br>{<br> m_pMIPViewer->SetInput(pImageData);<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br><br><br>----- MIPVIEWER -----<br>////////////////////////////////////////////////////////////////////////////////////<br>////////////////////////////////////////////////////////////////////////////////////<br>MIPViewer::MIPViewer():vtkObject(),<br>m_dInitialLevel(2048),<br>m_dInitialWindow(4096)<br>{<br> this->m_pColorFunc = vtkColorTransferFunction::New();<br> this->m_pOpacityFunc = vtkPiecewiseFunction::New();<br> this->m_pVolumeMapper = vtkSmartVolumeMapper::New();<br> this->m_pVolume =
vtkVolume::New();<br> this->m_pVolumeProperty = vtkVolumeProperty::New();<br> this->m_pRenderer = NULL;<br> this->m_pRenderWindow = NULL;<br> this->m_pImageData = NULL;<br><br> vtkRenderWindow *renWin = vtkRenderWindow::New();<br> this->SetRenderWindow(renWin);<br> renWin->Delete();<br><br> vtkRenderer *ren = vtkRenderer::New();<br> this->SetRenderer(ren);<br> ren->Delete(); <br><br> //set dummy data<br> m_pDummyImage = vtkImageData::New();<br> m_pDummyImage->SetDimensions(2,2,2);<br> m_pDummyImage->SetScalarTypeToUnsignedShort();<br> m_pDummyImage->AllocateScalars(); // allocate storage for image
data<br> unsigned short * VolPtr = (unsigned short *) m_pDummyImage->GetScalarPointer();<br> for(int i=0; i<2*2*2; i++ )<br> {<br> *VolPtr= 900;<br> *VolPtr++;<br> }<br> m_pDummyImage->Update();<br><br> m_pColorFunc->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );<br> m_pOpacityFunc->AddSegment( m_dInitialLevel - 0.5 * m_dInitialWindow, 0.0, m_dInitialLevel + 0.5 * m_dInitialWindow, 1.0 );<br> m_pVolumeProperty->SetColor( m_pColorFunc );<br> m_pVolumeProperty->SetScalarOpacity( m_pOpacityFunc );<br> m_pVolume->SetProperty( m_pVolumeProperty );<br> m_pVolumeMapper->SetBlendModeToMaximumIntensity();<br><br>
this->SetInput(m_pDummyImage);<br> this->m_pVolume->SetMapper(this->m_pVolumeMapper);<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void MIPViewer::SetRenderWindow(vtkRenderWindow *renWin)<br>{<br> if (this->m_pRenderWindow == renWin)<br> {<br> return;<br> }<br><br> if (this->m_pRenderWindow)<br> {<br> this->m_pRenderWindow->UnRegister(this);<br> }<br><br> this->m_pRenderWindow = renWin;<br><br> if (this->m_pRenderWindow)<br> {<br> this->m_pRenderWindow->Register(this);<br>
}<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void MIPViewer::SetRenderer(vtkRenderer *ren)<br>{<br> if (this->m_pRenderer == ren)<br> {<br> return;<br> }<br><br> if(m_pRenderWindow && m_pRenderer)<br> {<br> this->m_pRenderWindow->RemoveRenderer(this->m_pRenderer);<br> }<br><br> if (this->m_pRenderer)<br> {<br> this->m_pRenderer->UnRegister(this);<br> }<br><br> this->m_pRenderer = ren;<br><br> if (this->m_pRenderer)<br> {<br> this->m_pRenderer->Register(this);<br>
}<br><br> this->m_pRenderWindow->AddRenderer(this->m_pRenderer);<br> this->m_pRenderer->AddViewProp(this->m_pVolume);<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>void MIPViewer::SetInput(vtkImageData *pImageData)<br>{<br> m_pImageData = pImageData;<br> if(pImageData)<br> {<br> if(m_pVolumeMapper->GetInput())<br> {<br> m_pVolumeMapper->RemoveAllInputs();<br> }<br> m_pVolumeMapper->SetInput(m_pImageData);<br> }<br>}<br>////////////////////////////////////////////////////////////////////////////////////<br>vtkImageData*
MIPViewer::GetInput()<br>{<br> return m_pVolumeMapper->GetInput();<br>}<br>////////////////////////////////////////////////////////////////////////////////////</div></div></body></html>