# How to use VTK to realize volume rendering in the application based on OpenSceneGraph

**URL:** https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327
**Category:** Support
**Created:** [December 21, 2019, 9:11am UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327 "2019-12-21T09:11:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [December 21, 2019, 9:11am UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/1 "2019-12-21T09:11:17Z")

</div>

I’m a beginner of VTK. My 3D application is based on OpenSceneGraph(OSG). Now I want to add volume rendering into the application so that it can convert CT/MRI images to 3D scene. But the volume rendering of OSG is too simple with poor efficiency. I want to use VTK to realize volume rendering. But it’s impossible to change the whole rendering engine from OSG to VTK. So what I’m asking really if anybody has any advice, for example, changing volume rendering data of VTK to my OSG scene so that volume data and triangle mesh data can be rendered in the same scene(window), or other suggestion. It would be really appreciated, thanks!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 22, 2019, 1:19pm UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/2 "2019-12-22T13:19:55Z")

</div>

Hello, it’ll be quite tricky. The first challenge to overcome is to make VTK render to an OSG viewport. A starting point is to google `vtkActorToOSG`. There are a few source code repositories out there using that bridging class that someone wrote years ago.

Alternativelly, assuming the backend is OpenGL, you can avoid the trouble of converting `vtkActor`s to OSG objects if you manage to pass OSG’s OpenGL context to VTK so it can render there. I’d take a look at the [`vtkExternalOpenGLRenderWindow`](https://vtk.org/doc/nightly/html/classvtkExternalOpenGLRenderWindow.html) class, which is designed so VTK doesn’t create a new OpenGL context.

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [January 19, 2020, 8:53am UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/3 "2020-01-19T08:53:49Z")

</div>

Thanks! I have decided to use VTK for rendering engine instead of OSG. Maybe it will take a long time. But I think it will be worthing!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 19, 2020, 11:55am UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/4 "2020-01-19T11:55:57Z")

</div>

Well, welcome to the VTK community. I suggest you to read the VTK primer, which is available [on-line](https://vtk.org/vtk-textbook/) (not pirate! 😉 ). Also, there is an overwhelming ammount of code examples, posts and open source repositories out there. I also suggest you to try the basic examples to get the hang of it. The community has recently made a decent work making a [new hub for learning VTK](https://lorensen.github.io/VTKExamples/site/).

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [April 6, 2020, 9:13am UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/5 "2020-04-06T09:13:32Z")

</div>

I’m so grateful to choose VTK and the development of the application is going well. I have refactored the code of rendering with VTK. Though VTK is hard to handle well for me, but it is worthing. The on-line primer, examples and the community you suggest is very useful. Thank you! 😀

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 6, 2020, 12:05pm UTC](https://discourse.vtk.org/t/how-to-use-vtk-to-realize-volume-rendering-in-the-application-based-on-openscenegraph/2327/6 "2020-04-06T12:05:11Z")

</div>

You’re welcome, Harrison. 🙂 VTK is a pipeline-oriented API, which has a learning curve longer than scene graph-oriented ones. But it really pays in the long run, as doing things in parallel and scaling things up is easier with pipelines.
