[vtkusers] Customized Volume Rendering, and Camera Vision

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Tue Mar 22 16:29:41 EST 2005





Hi Jeffery,

Jeffrey Meng <mengjinjie at gmail.com> wrote on 23/03/2005 03:26:24:

> Thanks a lot, David.
>
> As a matter of fact, like what you pointed out, I figured I had to
> override Render function to achieve my goal.
>
> As for putting a light source at the camera spot, that will help to
> give shadows to the far area, and it's really a good trick. However,
> other than that, I will have to change the color of the visited area
> permanently, so that I know I have been to such areas.
>
> As mentioned above, I figured eventually, I have to manipulate the 3D
> data on triangle level. Such that I could give the vertices of the
> triangles different color as needed.  But I haven't found a better way
> to do that.  Basically, I want to achieve my goal based on what VTK
> has to offer, so that I don't have to write thousands of lines
> source-code.  So I built VTK library in Debug mode, trying to trace
> into it and find out the call stack of rendering process, hoping it
> would eventually lead me to the triangle rendering spot. But I failed,
> when I clicked F11 in Visual Studio, it just jumped over the current
> instruction and got the next one, never got inside the VTK function
> calls. :(

The rendering code is complicated, lots of cases for different types of
data and rendering modes... Tracing in would follow just the path relevant
to your dataset/rendering mode, but it would still be a bit scary I think!
I dont think there is any way to solve this with existing code? You might
get some hints from the volume rendering stuff, I have never worked with
this.

The need to mark points that have been seen is sounding like a ray tracing
problem, because you must correctly determine points occluded from each
view position. This would be a bit slow just for one view position, and
quite a big problem for a moving camera (many view points).

vtkPicker and more specifically vtkCellPicker 'shoot' a ray from the camera
to the focal point in the scene and determine what was intersected. A quick
peek at the code shows this is done brute force: each cell is tested with
IntersectWithLine, and the closest intersection is remembered.

Assuming you could specify the camera path and orientation at a set of
discrete steps (more steps = more accurate and slower) you could write a
class to do this as follows:
1  Initialise scalars to 0s
2  for each camera position
3    for each point in dataset
4      if point p1 inside camera view frustrum
5        for each cell in dataset (watch out for own cell)
6          if line from p1 to camera position 'intersects' cell
7            break out of cell loop, this point is occluded
8          if point was not occluded
9            set its scalar to 1, it was visible

At 4 you could avoid processing points where scalar is already 1
At 9 you could set scalar to integer representing camera position in
sequence, giving points that were seen and at which step.

This simplistic approach sounds quite easy to do, (vtkCell has
IntersectWithLine for the critical test) but it would certainly not be
fast. If you wanted this to happen interactivly you would not pre-specify
camera path but find a way to get render events and process the dataset at
each render. Take a look at how vtkFollower knows the camera has moved, or
look at AddObserver stuff?
Note the end result would be accurate only to the resolution of points in
the dataset, ie the exact boundary of visible/not on cell faces is not
determined. More points (see vtkLinearSubdivisionFilter...) would give more
accuracy, (and slower speed).

A vtkLookupTable with opacity 0 (or < 1) for scalar=0 could be one useful
way to view the result, pieces not seen would disappear (or be lighter).

   Dave P.

>
> Thanks again, and I hope you guys could help me out with this.
>
> Sincerely,
> Jeffrey Meng
>
>
>
> On Tue, 22 Mar 2005 09:38:25 +1200, David.Pont at forestresearch.co.nz
> <David.Pont at forestresearch.co.nz> wrote:
> >
> >
> > Hi Jeffery,
> >
> > vtkusers-bounces at vtk.org wrote on 18/03/2005 09:23:25:
> >
> > > Hi all,
> > >
> > > I am brand new to VTK, and I find it really extremely valuable as it
> > > encapsulate many useful tools and concepts into a bunch of C++
> > > classes.
> > >
> > > I am working on a research project for my course, and I have some
> > > questions that have been bothering me, I wish any of you guys could
> > > give me a hand here. Thanks in advance.
> > >
> > > The scenario is, put it a simple way, I am sending a camera into a
> > > colon volume (Built by vtkVolume16Reader), I want to color the area
> > > within camera's vision. Which requires me to:
> > >
> > > 1. Determine what the camera can see.  (Raycast with all the
> > > triangles? and how?)
> > > 2. Change the color of the area that the camera can see. (Change the
> > > color of the triangle votices? and how?)
> > >
> > > I am not sure if VTK has provided an easy way to do that. If it does,
> > > I will be more than joyful. If , unfortunately, it's not supported by
> > > VTK at present, please give me a hint of how to get it done based on
> > > what VTK has to offer right now.
> >
> > Just a couple of crazy ideas...
> >
> > There is info and source code on rendering shadows in OpenGL at:
> >
> > http://www.opengl.org/resources/code/rendering/mjktips/rts/index.html
> >
> > You could adapt these ideas so the area beyond the camera view is
> > 'shadowed' thus emphasising the parts visible to the camera.
> > This uses some advanced tricks in OpenGL. It is possible to mix OpenGL
> > calls with vtk code... but it will probably  be difficult to get the
> > desired effect... I think you would have to get inside the vtkRenderer
> > code, it would do extra renders for light sources (other than the
standard
> > vtk headlight at the camera) using stencil buffer magic to compose the
> > final scene.
> > In your application you would place a directional light source with a
> > 'field of view' equating to your camera ?
> >
> > As a quick hack in vtk you could try a directional light source at the
> > camera position (and opacity < 1 for the triangles ?) but I dont expect
> > this will give a good result?
> >
> >   Dave P
> >
> >
> > >
> > > Thanks a bunch,
> > >
> > > Best,
> > > Jeffrey
> > > _______________________________________________
> > > This is the private VTK discussion list.
> > > Please keep messages on-topic. Check the FAQ at: http://www.vtk.
> > > org/Wiki/VTK_FAQ
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.
> org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list