[vtkusers] Plane polydata intersection

Cory Quammen cquammen at cs.unc.edu
Mon Jun 24 11:42:52 EDT 2013


Laurent,

By shaders, I mean GLSL shaders [1]. You can write custom vertex and
fragment shaders than enable very careful control of how various
elements of your scene are rendered. You can do things like modify the
position of vertices, apply custom lighting, calculate the distance of
each rendered pixels position to a plane, etc.

In this case, you could simply have a fragment program that renders
your polydata. For each fragment, you can get the coordinates of the
fragment. With those coordinates, you can compute the distance to your
plane. If the distance is outside some threshold, you can discard the
fragment, which means it won't wind up in the final image. In the end,
you should wind up with a thin strip of your original geometry
representing the intersection of the geometry with the plane.

In VTK, shaders are set through properties of vtkActors [2].
Unfortunately, there isn't much documentation nor many examples for
shaders available (that I know of), so I can't give you any quick
pointers on how to use them.

[1] http://en.wikipedia.org/wiki/GLSL

[2] http://www.vtk.org/doc/nightly/html/classvtkProperty.html#a399829856851c282d776eb138fca97d7

Cory

On Mon, Jun 24, 2013 at 11:05 AM, Laurent Chauvin
<lchauvin at bwh.harvard.edu> wrote:
> Hi Cory.
>
> Indeed the plane I will use can change position and direction.
>
> Please, could you explain what is custom shaders and how to use them to
> compute distance ?
>
> Thank you.
> -Laurent
>
>
>
> On Jun 24, 2013, at 10:46 AM, Cory Quammen <cquammen at cs.unc.edu> wrote:
>
> Laurent,
>
> If your plane doesn't change orientation, then you should be able to
> change your isolevel value as you move the plane along its normal,
> thereby avoiding the distance computation, e.g., compute the distance
> one time relative to the current plane, then add 5 to the isolevel if
> your plane moves 5 units along the plane normal, etc.
>
> For a non-geometry based approach, you might use custom shaders to
> compute the distance of each vertex to your plane and discard
> fragments that aren't within some distance to the plane. This would be
> fast but may suffer from giving you a more-than-one-pixel-thick
> representation of the intersection in parts of the scene closest to
> the camera and perhaps missing some pixels in parts of the scene
> furthest from the camera.
>
> Hope that helps,
> Cory
>
>
>
> On Mon, Jun 24, 2013 at 10:20 AM, Laurent Chauvin
> <lchauvin at bwh.harvard.edu> wrote:
>
> Hi Cory,
>
> Thank you for your reply.
>
> However, you said I have to compute distance from each point to my plane,
> then use vtkContourFilter.
> But I think it would be really heavy computation to compute distance from
> each point to the plane every time I move the plane, isn't it ?
>
> I would like to be able to display the intersection while the plane is
> moving. If I have a polydata like a bone or a skull or something like that,
> it would be really long to compute this distance, isn't it ?
>
> Thank you.
> -Laurent
>
>
>
> On Jun 24, 2013, at 10:04 AM, Cory Quammen <cquammen at cs.unc.edu> wrote:
>
> On Sun, Jun 23, 2013 at 12:41 PM, Laurent Chauvin
> <lchauvin at bwh.harvard.edu> wrote:
>
> Hi Cory,
>
> Thank you very much for your reply.
> However, I'm not sure to understand what you mean.
> Should I create a new polydata with all points at the same z coordinates ?
>
>
> Laurent,
>
> You don't need to create a new polydata. Instead, you can add a new
> vtkDataArray (likely a vtkFloatArray or vtkDataArray in this case) to
> the point data of whatever polydata you already have by using
> vtkPolyData::GetPointData()->AddArray(...).
>
> For axis-aligned planes, this new array could simply contain the x, y,
> or z coordinate of each of the points in your vtkPolyData. If you want
> an intersection of your poly data with a plane spanning x and y, you
> would add a point data array storing all the z values. You can then
> use the vtkContourFilter to get the polydata consisting of line
> segments that represents the intersection of your polydata with the
> plane at a given z value by specifying that z value as the isolevel
> for the contour filter. You have to make sure you tell the
> vtkContourFilter to use your new coordinate array.
>
> For an quick example of this concept, I've attached a simple ParaView
> statefile showing how you can do this for a cylinder polydata. In this
> example, I've specified my plane as spanning the x and y coordinates
> with z value 0.2. In ParaView, I've used the Calculator to compute the
> array consisting of the z coordinates of each point in the cylinder.
> Forgive me if you don't have ParaView installed, we use it all the
> time when prototyping visualizations.
>
> Does this work with some oblique planes ( not parallel to x,y, or z axis ) ?
>
>
> For the general case of an arbitrary plane, you would want to compute
> the distance from each point your desired plan instead of creating a
> new array containing the x, y, or z coordinates of each point. Then
> you would set the vtkContourFilter isolevel to 0. The point plane
> calculation is pretty simple:
> http://mathworld.wolfram.com/Point-PlaneDistance.html
>
> Does that make sense?
>
> Thank you.
> -Laurent
>
>
> On Sun, Jun 23, 2013 at 12:31 PM, Cory Quammen <cquammen at cs.unc.edu> wrote:
>
>
> Laurent,
>
> For this special case of computing the intersection between a polydata
> and a plane, you can use a little trick. First, you can compute a new
> point data set for your polydata with,say, the z coordinates of each
> point in the polydata. Then, to get the intersection with an xy plane,
> you then use the vtkContourFilter operating on this coordinate point
> data and specify the z value that corresponds to your plane. The
> result should be equivalent to the intersection of the polydata with
> that plane.
>
> It should be relatively fast to compute the contour, so you can
> probably do this interactively.
>
> Hope that helps,
> Cory
>
> On Sat, Jun 22, 2013 at 2:46 PM, Laurent Chauvin
> <lchauvin at bwh.harvard.edu> wrote:
>
> Hello,
>
> I'm working on Slicer, and I was trying to find a nice way to display
> intersection between polydata and a plane.
> I read we could use a vtkCutter, but the thing is, I would like to do
> this
> interactively. I want to be able to move the plane, and update the
> intersection while moving the plane.
> I'm not sure using vtkCutter for this purpose would work. I think
> vtkCutter
> will take some times to execute, then moving the plane will be slow.
>
> I know this question has been asked before, but I would like if there
> were
> some update since then. New widgets or object that I could use for that
> ?
>
> I was thinking using vtkImageReslice, get polydata of the plane and
> compute
> the intersection between the 2 polydata, but I think it would also be to
> computing intensive to be able to do it smoothly with an interactive
> plane.
>
> Thank you.
> -Laurent
>
>
>
>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>
>
> --
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
>
>
>
>
>
> --
> Laurent Chauvin, MS
> Surgical Navigation and Robotics Laboratory, Radiology
> Brigham And Women's Hospital, Harvard Medical School
> http://wiki.ncigt.org/index.php/User:Lchauvin
>
>
>
>
> --
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
> <PlaneIntersectionExample.pvsm>
>
>
>
>
>
> --
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
>
>



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill



More information about the vtkusers mailing list