[vtkusers] Volume rendering with png slice images

Joseph D. Wieber Jr. jdwieber at gmail.com
Wed Aug 3 20:59:58 EDT 2011


I apologize, I figured it out.  It was the single line in generateVolume 
that reads: spVolumeProperty->IndependentComponentsOff(); When I comment 
out this line, and uncomment the lines for linear interpolation and 
shading it looks very nice.  However, it's terribly slow.  I suspect 
that this version is software rendered.  Is there a similar hardware 
accelerated  method?

Thanks

On 08/03/2011 07:18 PM, Joseph D. Wieber Jr. wrote:
>
> Hi all,
>
> I'm trying to do some volume rendering using the below code, but 
> nothing is showing in the render window.  When I run the code I see 
> the window and the background color that I set, but no data.  The code 
> cranks for about 5 seconds before I see the default render window 
> replaced (the default render window is white, and the volume render 
> window is gray-ish).  I don't see error messages in the console either.
>
> I'm using Qt with QVTKWidget to create the GUI.  I'm obviously doing 
> something wrong, but I don't see what it is.  Does anyone see what I'm 
> missing?  Thanks.
>
> Regards,
>
> Joseph
>
> void MainWindow::on_actionOpenDirectory_triggered()
> {
>     QString dirname = QFileDialog::getExistingDirectory( this,
>                                                         tr("Select a 
> Directory"),
>                                                         
> QDir::currentPath() );
>     if( !dirname.isNull() )
>     {
>         string pattern( dirname.toStdString () );
>         pattern += "/%03d.png";
>         cerr << "using pattern:<" << pattern << ">\n";
>
>         vtkSmartPointer< vtkVolume > spVolume = generateVolume ( 
> pattern );
>
>         vtkSmartPointer<vtkRenderWindow> spRenWin =
>                 vtkSmartPointer<vtkRenderWindow>::New();
>
>         vtkSmartPointer< vtkRenderer> spRen =
>                 vtkSmartPointer< vtkRenderer >::New();
>         spRen->AddViewProp ( spVolume );
>
>         spRenWin->AddRenderer( spRen );
>         m_pUi->qvtkWidget->SetRenderWindow ( spRenWin );
>         vtkSmartPointer< vtkRenderWindowInteractor > spIren =
>                 m_pUi->qvtkWidget->GetInteractor ();
>         spIren->SetRenderWindow( spRenWin );
>         spRen->SetBackground( 0.2, 0.3, 0.4 );
>         spRen->ResetCamera ();
>
>         //I tried this in place of ResetCamera, but id didn't work either
>         //        vtkSmartPointer< vtkCamera > spCamera = 
> spRen->GetActiveCamera();
>         //        double* c = spVolume->GetCenter();
>         //        spCamera->SetFocalPoint( c[ 0 ], c[ 1 ], c[ 2 ] );
>         //        spCamera->SetPosition( c[ 0 ] + 400, c[ 1 ], c[ 2 ] );
>         //        spCamera->SetViewUp( 0, 0, -1 );
>
>
>         spRenWin->Render();
>         m_pUi->qvtkWidget->setCursor ( Qt::ArrowCursor );
>     }
>     else
>     {
>         //TODO: do something intelligent here!
>     }
> }
>
>
> //--------------------------------------------------------------------------------------------------------------------------- 
>
> vtkSmartPointer< vtkVolume > MainWindow::generateVolume( const 
> std::string& pattern )
> {
>     //m_spReader is a vtkSmartPointer< vtkPNGReader >
>     m_spReader->SetFilePattern ( pattern.c_str () );
>     m_spReader->SetFileNameSliceOffset ( 1 );//images start at 001.png
>     //TODO: derive these from input
>     m_spReader->SetDataExtent( 0, 511, 0, 511, 1, 370 );//images go 
> from 1 to 370
>     m_spReader->SetDataSpacing( 1.0, 1.0, 1.0 ); // mm
>     m_spReader->SetDataOrigin( 0, 0, 0 );
>     m_spReader->SetDataScalarTypeToUnsignedChar();
>     //m_spReader->Update();
>
>     vtkSmartPointer< vtkPiecewiseFunction > spOpacityTransferFunction =
>             vtkSmartPointer< vtkPiecewiseFunction >::New();
>     spOpacityTransferFunction->AddPoint( 0, 0.0 );
>     spOpacityTransferFunction->AddPoint( 255, 1.0 );
>
>     vtkSmartPointer< vtkVolumeProperty > spVolumeProperty =
>             vtkSmartPointer< vtkVolumeProperty >::New();
>     spVolumeProperty->SetScalarOpacity( 0, spOpacityTransferFunction );
>     spVolumeProperty->SetScalarOpacity( 1, spOpacityTransferFunction );
>     spVolumeProperty->SetScalarOpacity( 2, spOpacityTransferFunction );
>     spVolumeProperty->IndependentComponentsOff();
>     spVolumeProperty->SetInterpolationTypeToLinear();
>     //spVolumeProperty->ShadeOn();
>     //spVolumeProperty->SetAmbient( 0.4 );
>     //spVolumeProperty->SetDiffuse( 0.6 );
>     //spVolumeProperty->SetSpecular( 0.2 );
>
>     vtkSmartPointer< vtkFixedPointVolumeRayCastMapper > spVolumeMapper =
>             vtkSmartPointer< vtkFixedPointVolumeRayCastMapper >::New();
>
>     spVolumeMapper->SetInputConnection( m_spReader->GetOutputPort() );
>
>     vtkSmartPointer< vtkVolume > spVolume =
>             vtkSmartPointer< vtkVolume >::New();
>     spVolume->SetMapper( spVolumeMapper );
>     spVolume->SetProperty( spVolumeProperty );
>
>     return spVolume;
> }
>



More information about the vtkusers mailing list