Creating a new CMakeLists.txt for building and using vtkOSPRay* with c++

I successfully built OSPRay and VTK 9/8 with it and the Rendering vtkExamples and Tests/Testing are working. I am having difficulty updating my own CMakeLists.txt file for c++ to “make” the includes and libraries known but I have been building VTK programs until now. I looked at the CMakeLists.txt files in the example/test directories but I don’t yet understand how to make the OSPray parts work because they are dependent on CMake files higher in the VTK build directory structure (when I cut and pasted subparts). I did browse this forum for solutions, but most pertain to how incorporate OSPRay in the build itself, not the usage. Please advise. Thanks

Hi @Spacetracker

find_package(VTK) should be enough. Do you intend to use ospray directly in your project of just VTKRaytracing classes ?


Not unless necessary; I just want to tell the renderer to use the ray tracer in place of OpenGL sometimes. I will go to the classes more directly only if I need to. I am using ImplicitFunctions and am sampling them, but would like to have clouds of gridded pressures in a volume eventually. I am looking for a good example of switching the renderer to ray tracing for volume rendering (instead of surface rendering now). Can you point me to some?

I typically look at the example CMake files to determine what packages I needed and assumed I would need the same here. The OSPRay CMakes themselves are more complicated. I first tried adding some OSPRay-specific classes to find_packages put ran into trouble. Without them, I have added three vtkOSPRay* includes to my source without complaint, so they must be under another package I have already loaded.

Oh, and I am software rendering on a headless server.


Then this sound like you have OSPRay questions, not VTK questions. VTK do not provide OSPRay feature, it provides raytracing features through OSPRay.

If you want to use OSPRay directly, you need to do just that.

Then this sound like you have OSPRay questions, not VTK questions. VTK do not provide OSPRay feature, it provides raytracing features through OSPRay.

I am sorry I was not clear. I certainly don’t want to program OSPRay calls from that API at all, or control many or any of the variables. My question is totally about how to use VTK for ray tracing that was built with OSRPray. Inside of VTK, there are vtkOSPRay calls directly, and another level inside the renderers that may not call for doing even that. I am getting confused from the old and new examples of how to do that properly.

Thanks again.

Did you try using the OSPRay examples testing ?

I should have asked, “How to switch between OpenGL and ray tracing rendering?” But I was getting stuck on problems and finding a good example.

Yes, I have been going through those examples. That is where I am now. I just thought I saw a simpler example before. I will work on that today. Thanks.

BTW. I am already looking at the Testing examples. I am also looking for “usage” examples. There is one old Ray Casting example, but no OSPRay usage examples yet.

“Hundreds of tests are distributed with the toolkit source. The tests reside in ‘‘Kit’’/Testing directories (for example, Filters/Points/Testing) in the source distribution. However, these tests are meant to exercise the toolkit rather than illustrate how to use it. For the most part, the tests are not good educational resources.”

but are better than nothing, as there is not ospray examples available.

VTK examples is (also) an open source project, open for anyone to create new ones, sadly no OSPRay examples were ever submited.

OK. I am back to the original question. How to include the ospray package in my CMake file.

I built all of Testing and ran all of the RayTracing ones interactively. Those will help me with the source code. But I am still stuck on getting ospray properly loaded in the CMakeLists.txt file.

Even though I added the ospray libraries to my path I still get vtk OSPRAY errors:

Undefined symbols for architecture x86_64:
  "vtkOSPRayPass::New()", referenced from:
      _main in AlveoliMPIVolumeRay.cxx.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [AlveoliMPIVolumeRay] Error 1
make[1]: *** [CMakeFiles/AlveoliMPIVolumeRay.dir/all] Error 2
make: *** [all] Error 2

I have looked at all three levels of CMake files under RayTracing. When I cut and paste the part I think I need, I get this error:

CMake Error at []vtkINSTALL/lib/cmake/vtk-9.1/vtkObjectFactory.cmake:93 (message):
  The `vtk_object_factory_configure` function needs to be run within a module
Call Stack (most recent call first):
  CMakeLists.txt:41 (vtk_object_factory_configure)

This is what I copied over. How LITTLE do I need? I don’t want the RTX or denoiser, etc anyway.

#to add OSPRay renderer
  BASE vtkOSPRayVolumeInterface
  OVERRIDE vtkOSPRayVolumeMapper)

  SOURCE_FILE vtk_object_factory_source
  HEADER_FILE vtk_object_factory_header

option(VTK_ENABLE_OSPRAY "Enable OSPRay RayTracing backend" ON)
  "build OSPRay Renderer using OpenImageDenoise" OFF

option(VTK_ENABLE_VISRTX "Enable VisRTX RayTracing backend" OFF)
  list(APPEND sources RTWrapper/VisRTX/VisRTXBackend.cxx)
endif ()

  CLASSES ${classes}
  SOURCES ${vtk_object_factory_source} ${sources}
  NOWRAP_CLASSES  ${nowrap_classes}
  NOWRAP_HEADERS  ${nowrap_headers}
  PRIVATE_HEADERS ${vtk_object_factory_header})

    PACKAGE ospray
    VERSION 2.1)

      PACKAGE OpenImageDenoise
  endif ()

  # TODO: FindOSPRay should do this.
  # OSPRay_Core uses MMTime which is in it's own special library.
  if (WIN32)
  endif ()
endif ()

# VisRTX
endif ()

So let me ask the same question, do you want to use OSPray directly or do you want to use VTK raytracing classes ?

Using the VTK ray tracing classes has really been my only goal. I do not want to write any OSPRay code. I built VTK with it and ran the OSPray tests. It seems to be as simple as this:

vtkSmartPointer ospray = vtkSmartPointer::New();
vtkNew renderer;

My question has always been this. I am already building a VTK program. What do I need to add to my CmakeList.txt file to get past the first link error? I attempted to add items from the Testing CMakeList.txt file to do that, but got the other error.

Never mind. It was easier than I thought. But I still learned from this. Thanks.