[vtkusers] 3 speed questions
Jonathan Morra
jonmorra at gmail.com
Fri Nov 5 21:24:56 EDT 2010
I have been wrestling with these problems for a few days now, and have some
more information to add. I found that after generating meshes with
vtkMarchingCubes, and cutting the data with vtkCutter, the data points seem
to be out of order. I've posted a related question here
http://comments.gmane.org/gmane.comp.lib.vtk.user/52679
Below I've reproduced my code for generating meshes from a
vtkPolyDataAppender (app). I was wondering if the ordering issue could be
causing the slowdown in my rendering, and if anyone knows how to fix it
(even if that's not the cause of this issue, I need to fix it for my other
issue). I've also tried vtkContourFilter and vtkDiscreteMarchingCubes, and
they do not seem to be working any better.
vtkImageData image = ENV.getInstance().getDataLoader().getImage();
double[] spacing = image.GetSpacing();
vtkLinearExtrusionFilter extruder = new vtkLinearExtrusionFilter();
extruder.SetInputConnection(app.GetOutputPort());
switch (orientation) {
case OrthoPanel.ORIENTATION_XY:
extruder.SetVector(0, 0, spacing[2]);
break;
case OrthoPanel.ORIENTATION_XZ:
extruder.SetVector(0, spacing[1], 0);
break;
case OrthoPanel.ORIENTATION_YZ:
extruder.SetVector(spacing[0], 0, 0);
}
extruder.CappingOn();
vtkImageData inputImage = new vtkImageData();
inputImage.SetOrigin(image.GetOrigin());
inputImage.SetSpacing(spacing);
inputImage.SetDimensions(image.GetDimensions());
inputImage.SetExtent(image.GetWholeExtent());
inputImage.SetScalarTypeToUnsignedChar();
inputImage.AllocateScalars();
vtkPolyDataToImageStencil pol2Stenc = new vtkPolyDataToImageStencil();
pol2Stenc.SetTolerance(0);
pol2Stenc.SetInputConnection(extruder.GetOutputPort());
pol2Stenc.SetInformationInput(inputImage);
vtkImageStencil stencil = new vtkImageStencil();
stencil.SetInput(inputImage);
stencil.SetStencil(pol2Stenc.GetOutput());
vtkMarchingCubes marching = new vtkMarchingCubes();
marching.SetInputConnection(stencil.GetOutputPort());
marching.ComputeGradientsOff();
marching.ComputeNormalsOff();
marching.ComputeScalarsOff();
marching.SetValue(0, 1);
marching.Update();
/*
// This appears to be the slowest of the pipeline, so
// for now we're going to eliminate it
vtkDecimatePro decimate = new vtkDecimatePro();
decimate.SetInputConnection(marching.GetOutputPort());
decimate.SetTargetReduction(0.9);
decimate.Update();
*/
wholeMesh = filter.GetOutput();
On Mon, Nov 1, 2010 at 6:01 PM, Jonathan Morra <jonmorra at gmail.com> wrote:
> I have three questions regarding speed in VTK with Java
> 1. I have three vtkImageViewer2's showing three different cuts through a
> 3D volume. I wish to display cuts through a vtkPolyData over 2 of them and
> have those cuts update as the user moves through the data. When the
> vtkPolyData is a stack of 2D contours, the speed is totally fine. However,
> when I take that stack of 2D contours and create a 3D mesh out of it by
> using a LinearExtruder then ImageStencil then MarchingCubes then Decimation
> (I do this only once, not on every update). The render time is much slower.
> Here is a snippet of code showing how I go from a 3D mesh to the
> appropriate 2D cut for display.
>
> double[] center = imageViewer.GetImageActor().GetCenter();
> vtkPolyData organData =
> ENV.getInstance().getDataManager().getOrganMesh(organ);
> if (organData == null)
> continue;
>
> vtkPlane cutPlane = new vtkPlane();
> cutPlane.SetOrigin(center);
> switch (orientation) {
> case ORIENTATION_XY:
> cutPlane.SetNormal(0, 0, 1);
> break;
> case ORIENTATION_XZ:
> cutPlane.SetNormal(0, 1, 0);
> break;
> case ORIENTATION_YZ:
> cutPlane.SetNormal(1, 0, 0);
> break;
> }
>
> vtkCutter cutter = new vtkCutter();
> cutter.SetCutFunction(cutPlane);
> cutter.SetInput(organData);
>
> vtkPolyDataMapper mapper = new vtkPolyDataMapper();
> mapper.SetInputConnection(cutter.GetOutputPort());
> mapper.ScalarVisibilityOff();
> mapper.Update();
>
> vtkActor actor = new vtkActor();
> actor.SetMapper(mapper);
>
> actor.GetProperty().SetColor(ENV.getInstance().getDataManager().getLineColor(organ));
> actor.GetProperty().SetRepresentationToWireframe();
>
> imageViewer.GetRenderer().AddActor(actor);
>
> From my analysis, the slowdown does not occur here, but rather in the line
> imageViewer.SetSlice(value);
> After some more digging, it turns out that the Render method is actually
> the method taking the most time to execute.
>
> 2. I have 3 vtkImagePlaneWidget's with and I want to show a vtkPolyData
> with them in the same window. This question is similar to the first in that
> if I show a vtkPolyData that is a series of 2D contours then the speed is
> fine, however the render speed is extremely slow if I show a 3D surface. I
> noticed that the amount of decimation that I do to the surface with
> vtkDecimatePro does not seem to affect the render speed.
>
> 3. An unrelated question. I have a vtkContourWidget that I wish to use
> live wire with. I have followed the tutorial
> on vtkDijkstraImageContourLineInterpolator and am able to successfully
> create the contour widget with live wire interpolation. However, when I
> first initialize the contour with the following code it is very slow
>
> // For now, we're just initializing the data with
> // the point that was clicked
>
> vtkPoints points = new vtkPoints();
>
> // The initial data MUST be at least a "line"
> // by giving the same point twice we are effictively creating a zero
> // length line
> points.InsertNextPoint(lastContourControlPoint);
> points.InsertNextPoint(lastContourControlPoint);
> vtkPolyData initialData = new vtkPolyData();
> initialData.SetPoints(points);
> contourWidget.Initialize(initialData, 0);
> The line that is slow is the last line. The weird part is that if I do not
> use live wire, and just use the default Bezier curve interpolation the
> initialization is instant.
>
> In summary, I've been working on these three issues for a few days and
> can't seem to make any progress in any of them. Does anyone have any
> suggestions on how to speed things up?
>
> Thanks
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101105/94d8ad34/attachment.htm>
More information about the vtkusers
mailing list