[vtk-developers] Strange renderering with mixed polydata/volume with QVTKOpenGLWidget

Elvis Stansvik elvis.stansvik at orexplore.com
Mon May 22 05:31:36 EDT 2017


2017-05-18 16:47 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
> 2017-05-18 16:16 GMT+02:00 Utkarsh Ayachit <utkarsh.ayachit at kitware.com>:
>> Okay. In that case, it may be best if you can put together a small example
>> to reproduce the issue so we can debug it here.
>
> Yep, will do.

I've not been able to reproduce exactly the issue I was seeing with a
small test case, and now I've annoyingly enough lost access to the
Windows machine I was testing on (may regain access to it later).

However, the following test case shows an issue (even on my Linux main
dev machine) which I suspect may be related. When running with a
"plain" vtkRenderWindow, the rendering looks normal, but when running
with QVTKOpenGLWidget, I can see through to the window behind the
application.

See the attached screenshot showing what I mean. Run the test case
with just "./TestCase" for "plain" VTK rendering, and with "./TestCase
blah" to use QVTKOpenGLWidget. You'll have to rotate the camera a
little for the problem to appear.

Any idea why this is happening? It looks similar to the issue I was
having on macOS / Windows (nvidia) in that the windows behind the
application become visible, but apart from that, the color of the poly
data is correct (as opposed to the issue I was having on macOS /
Windows (nvidia)).

Elvis

main.cpp:

#include <algorithm>

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkColorTransferFunction.h>
#include <vtkCubeSource.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkNew.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>

#include <QVTKOpenGLWidget.h>

#include <QApplication>

int main(int argc, char *argv[])
{
    auto defaultFormat = QVTKOpenGLWidget::defaultFormat();
    defaultFormat.setSamples(0);
    QSurfaceFormat::setDefaultFormat(defaultFormat);

    QApplication app(argc, argv);

    // Set up volume rendering
    vtkNew<vtkColorTransferFunction> colorFunction;
    colorFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
    colorFunction->AddRGBPoint(1.0, 0.0, 0.0, 0.0);

    vtkNew<vtkPiecewiseFunction> opacityFunction;
    opacityFunction->AddPoint(0.0, 0.0);
    opacityFunction->AddPoint(1.0, 1.0);

    vtkNew<vtkImageData> imageData;
    imageData->SetExtent(0, 200, 0, 200, 0, 200);
    imageData->AllocateScalars(VTK_FLOAT, 1);
    std::fill_n(static_cast<float *>(imageData->GetScalarPointer()),
8000000, 0.01);

    vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
    volumeMapper->SetInputData(imageData.Get());

    vtkNew<vtkVolumeProperty> volumeProperty;
    volumeProperty->SetScalarOpacity(opacityFunction.Get());
    volumeProperty->SetColor(colorFunction.Get());
    volumeProperty->ShadeOff();

    vtkNew<vtkVolume> volume;
    volume->SetMapper(volumeMapper.Get());
    volume->SetProperty(volumeProperty.Get());

    // Set up poly cube rendering
    vtkNew<vtkCubeSource> cubeSource;
    cubeSource->SetBounds(-20, 220, 100, 150, -20, 220);

    vtkNew<vtkPolyDataMapper> cubeMapper;
    cubeMapper->SetInputConnection(cubeSource->GetOutputPort());

    vtkNew<vtkActor> cubeActor;
    cubeActor->SetMapper(cubeMapper.Get());
    cubeActor->GetProperty()->SetColor(0.0, 0.0, 1.0);
    cubeActor->GetProperty()->SetOpacity(0.1);
    cubeActor->GetProperty()->SetAmbient(1.0);
    cubeActor->GetProperty()->SetDiffuse(0.0);
    cubeActor->GetProperty()->SetSpecular(0.0);

    // Set up renderer
    vtkNew<vtkRenderer> renderer;
    renderer->AddActor(cubeActor.Get());
    renderer->AddVolume(volume.Get());
    renderer->SetBackground(1.0, 1.0, 1.0);

    if (argc > 1) {
        // Show with QVTKOpenGLWidget
        vtkNew<vtkGenericOpenGLRenderWindow> window;
        window->AddRenderer(renderer.Get());

        auto widget = new QVTKOpenGLWidget();
        widget->SetRenderWindow(window.Get());
        widget->show();

        return app.exec();
    } else {
        // Show with plain VTK
        vtkNew<vtkRenderWindow> window;
        window->AddRenderer(renderer.Get());

        vtkNew<vtkRenderWindowInteractor> interactor;
        interactor->SetRenderWindow(window.Get());
        interactor->Start();

        return 0;
    }
}


CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)

project(TestCase)

find_package(VTK 7.1 COMPONENTS
    vtkCommonCore
    vtkCommonDataModel
    vtkCommonExecutionModel
    vtkCommonMath
    vtkFiltersSources
    vtkGUISupportQt
    vtkInteractionStyle
    vtkRenderingCore
    vtkRenderingOpenGL2
    vtkRenderingVolume
    vtkRenderingVolumeOpenGL2
    REQUIRED
)

find_package(Qt5Widgets REQUIRED)

add_executable(TestCase main.cpp)

target_link_libraries(TestCase PUBLIC
    vtkCommonCore
    vtkCommonDataModel
    vtkCommonExecutionModel
    vtkCommonMath
    vtkFiltersSources
    vtkGUISupportQt
    vtkInteractionStyle
    vtkRenderingCore
    vtkRenderingOpenGL2
    vtkRenderingVolume
    vtkRenderingVolumeOpenGL2
    Qt5::Widgets
)

target_include_directories(TestCase PUBLIC
    ${VTK_INCLUDE_DIRS}
)

target_compile_definitions(TestCase PUBLIC
    ${VTK_DEFINITIONS}
)

set_target_properties(TestCase PROPERTIES
    CXX_STANDARD 14
    CXX_STANDARD_REQUIRED ON
)


>
> Elvis
>
>>
>> Utkarsh
>>
>> On Thu, May 18, 2017 at 10:14 AM, Elvis Stansvik
>> <elvis.stansvik at orexplore.com> wrote:
>>>
>>> 2017-05-18 15:59 GMT+02:00 Utkarsh Ayachit <utkarsh.ayachit at kitware.com>:
>>> > For now, try doing this:
>>> >   auto surfaceFormat = QVTKOpenGLWidget::defaultFormat()
>>> >   surfaceFormat.setSamples(0);
>>> >   surfaceFormat.setAlphaBufferSIze(0);
>>> >   QSurfaceFormat::setDefaultFormat(surfaceFormat);
>>>
>>> Thanks for the suggestion. I tried it out on the Mac, but it looks
>>> like it made no difference :/
>>>
>>> Elvis
>>>
>>> >
>>> >
>>> > Utkarsh
>>> >
>>> > On Thu, May 18, 2017 at 8:57 AM, Elvis Stansvik
>>> > <elvis.stansvik at orexplore.com> wrote:
>>> >>
>>> >> I'm porting our program to the new QVTKOpenGLWidget.
>>> >>
>>> >> In one place, we're using a semi-transparent polygonal cube to show
>>> >> the selection of an area. We're doing volume rendering using
>>> >> vtkGPUVolumeRayCastMapper in the same renderer, and the polygonal
>>> >> selection marker is enclosing the volume in the X/Y dimensions.
>>> >>
>>> >> See the attached linux_selection_correct.png for how this is supposed
>>> >> to look, and you'll understand what I mean. The light blue area is the
>>> >> selection marker.
>>> >>
>>> >> This has always worked fine, but after porting from QVTKWidget to
>>> >> QVTKOpenGLWidget, the rendering looks strange on Windows (nvidia) and
>>> >> macOS (2013 MBP, intel iris). See the attached
>>> >> windows_nvidia_selection.png and macos_selection.png.
>>> >>
>>> >> The selection is visualized using
>>> >>
>>> >>   vtkCubeSource -> vtkPolyDataMapper
>>> >>
>>> >> and a vtkActor configured like this:
>>> >>
>>> >>     auto selectionColor = palette().color(QPalette::Highlight);
>>> >>
>>> >>     m_selectionMarkerActor->SetMapper(selectionMarkerMapper);
>>> >>
>>> >> m_selectionMarkerActor->GetProperty()->SetColor(selectionColor.redF(),
>>> >>
>>> >> selectionColor.greenF(),
>>> >>
>>> >> selectionColor.blueF());
>>> >>     m_selectionMarkerActor->GetProperty()->SetOpacity(0.1);
>>> >>     m_selectionMarkerActor->GetProperty()->SetAmbient(1.0);
>>> >>     m_selectionMarkerActor->GetProperty()->SetDiffuse(0.0);
>>> >>     m_selectionMarkerActor->GetProperty()->SetSpecular(0.0);
>>> >>
>>> >> Any idea why the rendering looks so strange on Windows/nvidia and
>>> >> macOS/iris, respectively, when using the new widget class?
>>> >>
>>> >> We're using a recent VTK from Git master.
>>> >>
>>> >> We're doing the recommended
>>> >>
>>> >>
>>> >> QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
>>> >>
>>> >> to set the default surface format before QApplication construction.
>>> >>
>>> >> In the particular QVTKOpenGLWidget used here, we modify the format with
>>> >>
>>> >>     auto surfaceFormat = format();
>>> >>     surfaceFormat.setSamples(0);
>>> >>     setFormat(surfaceFormat);
>>> >>
>>> >> to disable multisampling.
>>> >>
>>> >> Very grateful for any advise on how to solve this.
>>> >>
>>> >> Cheers,
>>> >> Elvis
>>> >>
>>> >> _______________________________________________
>>> >> Powered by www.kitware.com
>>> >>
>>> >> Visit other Kitware open-source projects at
>>> >> http://www.kitware.com/opensource/opensource.html
>>> >>
>>> >> Search the list archives at:
>>> >> http://markmail.org/search/?q=vtk-developers
>>> >>
>>> >> Follow this link to subscribe/unsubscribe:
>>> >> http://public.kitware.com/mailman/listinfo/vtk-developers
>>> >>
>>> >>
>>> >
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testcase-plain.png
Type: image/png
Size: 27870 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20170522/dd3d777c/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testcase-qvtkopenglwidget.png
Type: image/png
Size: 28581 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20170522/dd3d777c/attachment-0003.png>


More information about the vtk-developers mailing list