[vtkusers] contour widget with live wire interpolation not working
Jonathan Morra
jonmorra at gmail.com
Wed Oct 27 20:29:50 EDT 2010
I actually just figured this out, I had to set the OutputSpacing and
OutputOriging of reslice.
On Wed, Oct 27, 2010 at 3:32 PM, Jonathan Morra <jonmorra at gmail.com> wrote:
> I have a vtkContourWidget and I wish to use a Live Wire method for drawing
> the lines. When I make a contour widget without the live wire stuff
> everything looks fine. However, when I add in the live wire stuff the line
> that is connecting two control points is not being shown. Below is a
> snippet of my code that deals with the live wire part (I'm writing in Java).
> Does anyone know why this is happening?
>
> Thanks
>
> vtkImageAnisotropicDiffusion3D diffusion = new
> vtkImageAnisotropicDiffusion3D();
> diffusion.SetInput(imageData);
>
> // Gradient magnitude for edges
> vtkImageGradientMagnitude grad = new vtkImageGradientMagnitude();
> grad.SetDimensionality(3);
> grad.HandleBoundariesOn();
> grad.SetInputConnection(diffusion.GetOutputPort());
> grad.Update();
>
> double[] range = grad.GetOutput().GetScalarRange();
>
> // Invert the gradient magnitude so that low costs are
> // associated with strong edges and scale from 0 to 1
> vtkImageShiftScale gradInvert = new vtkImageShiftScale();
> gradInvert.SetShift(-1.0*range[1]);
> gradInvert.SetScale(1.0 / (range[0] - range[1]));
> gradInvert.SetOutputScalarTypeToFloat();
> gradInvert.SetInputConnection(grad.GetOutputPort());
> gradInvert.Update();
> gradInverseData = gradInvert.GetOutput();
>
> vtkContourWidget contourWidget = new vtkContourWidget();
> contourWidget.FollowCursorOn();
>
> vtkOrientedGlyphContourRepresentation rep = new
> vtkOrientedGlyphContourRepresentation();
> rep.GetLinesProperty().SetLineWidth(5);
> rep.GetProperty().SetPointSize(6);
> rep.SetWorldTolerance(0.000005);
>
> // The contour rep requires a suitable point placer
> vtkImageActorPointPlacer placer = new vtkImageActorPointPlacer();
> placer.SetImageActor(imageViewer.GetImageActor());
>
> rep.SetPointPlacer(placer);
> // Reslice the data because the gradient only works in 2D
> int[] dims = imageViewer.GetImageActor().GetDisplayExtent();
> vtkImageReslice reslice = new vtkImageReslice();
> reslice.SetInput(gradDataInverse);
> reslice.SetOutputExtent(dims);
> reslice.Update();
>
> // The line interpolator defines how intermediate points are
> // generated between the representations nodes. This
> // interpolator uses Dijkstra's shortest path algorithm.
> vtkDijkstraImageContourLineInterpolator interpolator = new
> vtkDijkstraImageContourLineInterpolator();
> interpolator.SetCostImage(reslice.GetOutput());
>
> interpolator.GetDijkstraImageGeodesicPath().StopWhenEndReachedOn();
> // prevent contour segments from overlapping
>
> interpolator.GetDijkstraImageGeodesicPath().RepelPathFromVerticesOn();
>
> // weights are scaled from 0 to 1 as are associated cost
> // components
>
> interpolator.GetDijkstraImageGeodesicPath().SetCurvatureWeight(0.15);
>
> interpolator.GetDijkstraImageGeodesicPath().SetEdgeLengthWeight(0.8);
> interpolator.GetDijkstraImageGeodesicPath().SetImageWeight(1.0);
>
> rep.SetLineInterpolator(interpolator);
> contourWidget.SetRepresentation(rep);
> contourWidget.SetInteractor(panel.getRenWin().getIren());
> contourWidget.On();
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101027/7cbd53d1/attachment.htm>
More information about the vtkusers
mailing list