[vtkusers] Strange rendering with 2-voxel thick volume
Elvis Stansvik
elvis.stansvik at orexplore.com
Wed Oct 4 10:09:36 EDT 2017
Hi Aashish,
2017-10-04 15:47 GMT+02:00 Aashish Chaudhary <aashish.chaudhary at kitware.com>:
> Please make sure that your sampling distance is less than < 2. You can set
> the sampling distance manually in the API.
Hm. I don't think it's related to sampling distance. In the test case
I'm not setting sampling distance at all, so I think it should default
to 1, and then be automatically adjusted during interaction.
In any case, even if I amend the test case with e.g.:
volumeMapper->AutoAdjustSampleDistancesOff();
volumeMapper->SetSampleDistance(0.2);
...
volumeMapper2->AutoAdjustSampleDistancesOff();
volumeMapper2->SetSampleDistance(0.2);
The result is the same.
Elvis
>
> On Wed, Oct 4, 2017 at 8:23 AM Elvis Stansvik <elvis.stansvik at orexplore.com>
> wrote:
>>
>> 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
>> )
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list