[vtkusers] Question about contour widget

Jonathan Morra jonmorra at gmail.com
Wed Oct 13 22:56:54 EDT 2010


Thanks a lot for all the advice, I went with Dean and John's solution, and
it works perfectly.  Internally I keep the following data structure (in
java)
HashSet<vtkContourWidget>[]
where the array is the same length as the number of planes, and I can store
multiple contours per plane.  There's only one thing left for me to make
this complete.  After I draw the contour, I use the vtkAppendPolyData to
create one vtkPolyData.  I want to display that vtkPolyData on top of the
vtkImageViewer2 in the same fashion as I do with the contours.  In order to
accomplish this, I tried to use the following code, but it's not working yet

        vtkPolyDataMapper mapper = new vtkPolyDataMapper();
        mapper.SetInput(polyData);

        vtkActor actor = new vtkActor();
        actor.SetMapper(mapper);

        imageViewer.GetRenderer().AddActor(actor);

        double[] bounds = imageViewer.GetImageActor().GetBounds();

        vtkPlane topPlane = new vtkPlane();
        topPlane.SetOrigin(bounds[0], bounds[2], bounds[4]);
        normals[getPerpendicularSlice()] = 1;
        topPlane.SetNormal(0, 0, 1);

        vtkPlane bottomPlane = new vtkPlane();
        bottomPlane.SetOrigin(bounds[1], bounds[3], bounds[5]);
        bottomPlane.SetNormal(0, 0, -1);

        actor.GetMapper().RemoveAllClippingPlanes();
        actor.GetMapper().AddClippingPlane(topPlane);
        actor.GetMapper().AddClippingPlane(bottomPlane);

Am I on the right track with this?

Thanks

On Wed, Oct 13, 2010 at 7:23 PM, Dean Inglis <dean.inglis at camris.ca> wrote:

> Hi John,
>
> you are doing everything right as far as I can tell from your code.  The
> solution
> we implemented was to create a slice viewer based on vtkImageViewer2 that
> broadcasted SliceChanged events whenever its ivar vtkImageActor changed
> slices / display extents.  We created a vtkContour class inherited from
> vtkProp that displays itself
> in response to those events as well as stores and  maintains its history of
> edits,
> calculates its perimeter and area metrics, if closed displays the area as a
> translucent image overlay
> etc etc.  The contour "knows" which slice extents it belongs to and
> switches its visibility accordingly.
> One could for example define a contour on a current vtkImageActor slice as
> done
> in your code and then send the vtkPolyData via the widget's rep method
> GetContourRepresentationAsPolyData to initialize an isntance of the
> vtkContour class.
> We also subclassed a picker that adds vtkContour to the possible type of
> props it can pick
> so that one can mouse hover and cause it to automagically highlight itself
> or pick
> and cause it to remain highlighted in a selected state.   A selected
> contour is unselected
> whenever the slice viewer changes slices.  Editing of contours is
> accomplished by passing its vtkPolyData ivar back to the vtkContourWidget
> via
> its Initialize method. There is a lot more interaction logic embedded in
> this approach
> but maybe you have some ideas to go on...
>
> regards,
> Dean
>
>
>
> I have a vtkImageViewer2 and wish to use vtkContourWidget to draw a contour
> on the image.  The data I'm loading is a 3D DICOM CT volume.  I have found
> the following question
>
> http://vtk.1045678.n5.nabble.com/vtkContourWidget-with-vtkImageViewer2-td1236295.html
> and
> created the following code as a result (in Java)
>
>       vtkContourWidget contourWidget = new vtkContourWidget();
>       contourWidget.SetInteractor(panel.getRenWin().getIren());
>       contourWidget.FollowCursorOn();
>
>       vtkOrientedGlyphContourRepresentation rep = new
> vtkOrientedGlyphContourRepresentation();
>       contourWidget.SetRepresentation(rep);
>
>       vtkImageActorPointPlacer placer = new vtkImageActorPointPlacer();
>       placer.SetImageActor(panel.getImageViewer().GetImageActor());
>       rep.SetPointPlacer(placer);
>
>       contourWidget.EnabledOn();
>       contourWidget.ProcessEventsOn();
>
> When I do this and draw a contour and then scroll through the image planes
> the same contour appears on every plane.  Ideally I'd like a different
> contour on every plane.  If I don't use the vtkImageActorPointPlacer then
> the contour only appears on one plane but it's the same plane regardless of
> which plane is being viewed, which is also wrong.
>
> Any suggestions about how to do this correctly would be greatly
> appreciated.
>
> Thanks
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101013/d36b25f9/attachment.htm>


More information about the vtkusers mailing list