After many additional experiments, I think I have narrowed down our problem somewhat; it seems to be related to volume rendering,
I can at least provide a minimal example which works with VTK 9.1 but doesn’t properly with VTK 9.2:
OpenVRVol.cxx:
#include <vtkActor.h>
#include <vtkColorSeries.h>
#include <vtkColorTransferFunction.h>
#include <vtkConeSource.h>
#include <vtkImageData.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOpenVRRenderWindow.h>
#include <vtkOpenVRRenderWindowInteractor.h>
#include <vtkOpenVRRenderer.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkVolumeProperty.h>
int main(int, char* [])
{
int dim[3] = { 10, 10, 10 };
double spc[3] = { 0.05, 0.05, 0.05 };
vtkNew<vtkImageData> img;
img->SetDimensions(dim);
img->AllocateScalars(VTK_INT, 1);
img->SetSpacing(spc);
for (int x=0; x<dim[0]; ++x)
for (int y=0; y<dim[1]; ++y)
for (int z=0; z<dim[2]; ++z)
{
img->SetScalarComponentFromDouble(x, y, z, 0, x);
}
vtkNew<vtkColorSeries> colors;
colors->SetColorScheme(vtkColorSeries::BREWER_QUALITATIVE_SET3);
vtkNew<vtkColorTransferFunction> ctf;
for (int x = 0; x < dim[0]; ++x)
{
auto c = colors->GetColor(x);
ctf->AddRGBPoint(x, c.GetRed() / 255.0, c.GetGreen() / 255.0, c.GetBlue() / 255.0);
}
ctf->AddRGBPoint(dim[0], 1.0, 1.0, 1.0);
ctf->Build();
vtkNew<vtkSmartVolumeMapper> volMapper;
vtkNew<vtkVolume> volume;
vtkNew<vtkVolumeProperty> volProp;
volMapper->SetBlendModeToComposite();
volume->SetMapper(volMapper);
volume->SetProperty(volProp);
volume->SetVisibility(true);
volMapper->SetInputData(img);
volProp->SetColor(0, ctf);
vtkNew<vtkPiecewiseFunction> otf;
otf->AddPoint(0.0, 1.0);
otf->AddPoint(dim[0], 1.0);
volProp->SetScalarOpacity(0, otf);
volProp->Modified();
vtkNew<vtkConeSource> coneSource;
coneSource->Update();
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(coneSource->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkNew<vtkOpenVRRenderWindow> renderWindow;
renderWindow->Initialize();
vtkNew<vtkOpenVRRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRRenderer> renderer;
renderWindow->AddRenderer(renderer);
vtkNew<vtkNamedColors> namedColors;
renderer->SetBackground(namedColors->GetColor3d("ForestGreen").GetData());
renderer->AddActor(actor);
renderer->AddVolume(volume);
volume->SetPosition(0, 1, 0);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(OpenVRVol)
find_package(VTK COMPONENTS
CommonCore
CommonColor
CommonDataModel
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
RenderingOpenVR
RenderingVolumeOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "OpenVRVol: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(OpenVRVol MACOSX_BUNDLE OpenVRVol.cxx )
target_link_libraries(OpenVRVol PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS OpenVRVol
MODULES ${VTK_LIBRARIES}
)
With VTK 9.1, the demo volume is nicely rendered above the cone:
With VTK 9.2, I only see bits and pieces of the volume if I move around; it looks as though I’m “slicing”(maybe with the near plane) through the volume, but I never see the full one, not even if I try to move further away or if I look at it from below or the other direction. A screenshot cannot really catch the full “experience”, but you get an idea:
Is my code doing something wrong here?
Was there a change in how volume rendering works with OpenVR?