[vtkusers] Strange rendering with 2-voxel thick volume

Elvis Stansvik elvis.stansvik at orexplore.com
Wed Oct 4 08:22:58 EDT 2017


Hi all,

In the test case below, I render one 200x200x2 volume and one
200x200x3 volume, both with the same settings.

The 200x200x3 volume looks as expected (the light gray one in the
attached screenshot), while the 200x200x2 one looks strange (too dark,
and with some kind of gradient artifact).

Is there some limitation on rendering a volume that is only 2 thick in
one of the dimensions? I can understand why a volume of thickness 1
can't be rendered properly, since VTK must have values to interpolate
between, but 2 should be OK right?

Thanks for any help.

Elvis


main.cpp:

#include <algorithm>

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

int main(int argc, char *argv[])
{
    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);

    // A 200x200x2 volume
    vtkNew<vtkImageData> imageData;
    imageData->SetExtent(0, 199, 0, 199, 0, 1);
    imageData->AllocateScalars(VTK_FLOAT, 1);
    std::fill_n(static_cast<float *>(imageData->GetScalarPointer()),
200 * 200 * 2, 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());
    volume->SetPosition(120, 0, 0);

    // A 200x200x3 volume
    vtkNew<vtkImageData> imageData2;
    imageData2->SetExtent(0, 199, 0, 199, 0, 2);
    imageData2->AllocateScalars(VTK_FLOAT, 1);
    std::fill_n(static_cast<float *>(imageData2->GetScalarPointer()),
200 * 200 * 3, 0.01);

    vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper2;
    volumeMapper2->SetInputData(imageData2.Get());

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

    vtkNew<vtkVolume> volume2;
    volume2->SetMapper(volumeMapper2.Get());
    volume2->SetProperty(volumeProperty2.Get());
    volume2->SetPosition(-120, 0, 0);

    vtkNew<vtkRenderer> renderer;
    renderer->AddVolume(volume.Get());
    renderer->AddVolume(volume2.Get());
    renderer->SetBackground(1.0, 1.0, 1.0);

    // Render with "plain" render window / interactor
    vtkNew<vtkRenderWindow> window;
    window->SetMultiSamples(0);
    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 8.0 COMPONENTS
    vtkCommonCore
    vtkCommonDataModel
    vtkCommonExecutionModel
    vtkCommonMath
    vtkFiltersSources
    vtkGUISupportQt
    vtkInteractionStyle
    vtkRenderingCore
    vtkRenderingOpenGL2
    vtkRenderingVolume
    vtkRenderingVolumeOpenGL2
    REQUIRED
)

add_executable(TestCase main.cpp)

target_link_libraries(TestCase PUBLIC
    vtkCommonCore
    vtkCommonDataModel
    vtkCommonExecutionModel
    vtkCommonMath
    vtkFiltersSources
    vtkInteractionStyle
    vtkRenderingCore
    vtkRenderingOpenGL2
    vtkRenderingVolume
    vtkRenderingVolumeOpenGL2
)

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
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.png
Type: image/png
Size: 25837 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171004/e65687e9/attachment.png>


More information about the vtkusers mailing list