[vtkusers] Replace Volume in render window

Dženan Zukić dzenanz at gmail.com
Mon Oct 10 03:56:19 EDT 2011


This is what I use:

void MainWindow::updateVisualization()
{
    typedef itk::ImageToVTKImageFilter<VisualizingImageType>
itkVtkConverter;
    itkVtkConverter::Pointer conv=itkVtkConverter::New();
    conv->SetInput(itkVolume);

    vtkGPUVolumeRayCastMapper *mapper = vtkGPUVolumeRayCastMapper::New();
    mapper->SetInput(conv->GetOutput());

    if (volume) //if not the first volume delete the old one
        volume->Delete();
    volume=vtkVolume::New();
constructTF();
    volume->SetMapper( mapper );

    vtkRenderer *renderer =
vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
    renderer->RemoveAllViewProps();
    renderer->AddVolume( volume );
    vis->GetRenderWindow()->Render();
    renderer->ResetCamera();

QApplication::processEvents();
}

On Fri, Oct 7, 2011 at 13:49, Xavius <xavierelf at gmail.com> wrote:

> Hi all!
> I have a trouble with VTK. I can't understand what is necessary to do to
> replace current volume.
> I've tried many things but without success. There's no troubles with a
> single volume, but when I try to load another volume I face problems...
>
> Below I post code, I think should work, but it doesn't...
> Please help me to understand VTK!
>
> // This method called when thread, that load DICOM image series finished
> void MainWindow::onThreadFinished(void) {
>        if (m_reader)
>                m_reader->Delete();
>        m_reader = m_itkLoadThread->getReader();
>
>        render();
> }
>
> // Volume constructing
> void MainWindow::render(void) {
>        ExportFilterType::Pointer
> itkExporter     = ExportFilterType::New();
>        vtkSmartPointer<vtkImageImport>                         vtkImporter
>     = vtkImageImport::New();
>        vtkSmartPointer<vtkVolume>
>  volume          = vtkVolume::New();
>        vtkSmartPointer<vtkVolumeTextureMapper3D>       mapper          =
> vtkVolumeTextureMapper3D::New();
>
>        itkExporter->SetInput(m_reader->GetOutput());
>        itkExporter->Update();
>        ConnectPipelines(itkExporter, vtkImporter);
>        vtkImporter->Update();
>
>        mapper->SetBlendModeToComposite();
>        mapper->SetInput(vtkImporter->GetOutput());
>        volume->SetProperty(m_volumeProperty);
>        volume->SetMapper(mapper);
>
>        changeVolume(volume);
>        if (!m_eventLoopStarted) {
>                m_iren->Start();
>                m_eventLoopStarted = !m_eventLoopStarted;
>        }
> }
>
> // Replacing an old volume for a new one
> void MainWindow::changeVolume(vtkProp *aProp) {
>        m_renderer->RemoveAllViewProps();
>        m_renderer->AddVolume(aProp);
>        vtkWidget->GetRenderWindow()->Render();
> }
>
> // Method called from constructor. Setting up render window.
> void MainWindow::prepareRenderWindow(void) {
>        vtkSmartPointer<vtkRenderWindow>
>    renWin          =
> vtkWidget->GetRenderWindow();
>        vtkSmartPointer<vtkInteractorStyleTrackballCamera>      irenStyle
>     =
> vtkInteractorStyleTrackballCamera::New();
>        m_iren          = vtkRenderWindowInteractor::New();
>        m_renderer      = vtkRenderer::New();
>
>        // Prepare Render Window
>        renWin->AddRenderer(m_renderer);
>        renWin->SetInteractor(m_iren);
>
>        // Prepare Render Window Interactor
>        m_iren->SetInteractorStyle(irenStyle);
>        irenStyle->SetDefaultRenderer(m_renderer);
>        m_iren->SetRenderWindow(renWin);
>
>        // Prepare Renderer
>        m_renderer->SetBackground(0.5, 0.5, 0.5);
>        m_renderer->ResetCamera();
>
>        renWin->Render();
> }
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Replace-Volume-in-render-window-tp4879789p4879789.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111010/abfbebc5/attachment.htm>


More information about the vtkusers mailing list