<div><div><div>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</div>
<div><a href="http://comments.gmane.org/gmane.comp.lib.vtk.user/52679">http://comments.gmane.org/gmane.comp.lib.vtk.user/52679</a></div><div>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.</div>
<div><br></div><div> vtkImageData image = ENV.getInstance().getDataLoader().getImage();</div><div> double[] spacing = image.GetSpacing();</div><div> vtkLinearExtrusionFilter extruder = new vtkLinearExtrusionFilter();</div>
<div> extruder.SetInputConnection(app.GetOutputPort());</div><div> switch (orientation) {</div><div> case OrthoPanel.ORIENTATION_XY:</div><div> extruder.SetVector(0, 0, spacing[2]);</div><div> break;</div>
<div> case OrthoPanel.ORIENTATION_XZ:</div><div> extruder.SetVector(0, spacing[1], 0);</div><div> break;</div><div> case OrthoPanel.ORIENTATION_YZ:</div><div> extruder.SetVector(spacing[0], 0, 0);</div>
<div> }</div><div> extruder.CappingOn();</div><div> </div><div> vtkImageData inputImage = new vtkImageData();</div><div> inputImage.SetOrigin(image.GetOrigin());</div><div> inputImage.SetSpacing(spacing);</div>
<div> inputImage.SetDimensions(image.GetDimensions());</div><div> inputImage.SetExtent(image.GetWholeExtent());</div><div> inputImage.SetScalarTypeToUnsignedChar();</div><div> inputImage.AllocateScalars();</div>
<div><br></div><div> vtkPolyDataToImageStencil pol2Stenc = new vtkPolyDataToImageStencil();</div><div> pol2Stenc.SetTolerance(0);</div><div> pol2Stenc.SetInputConnection(extruder.GetOutputPort());</div><div> pol2Stenc.SetInformationInput(inputImage);</div>
<div><br></div><div> vtkImageStencil stencil = new vtkImageStencil();</div><div> stencil.SetInput(inputImage);</div><div> stencil.SetStencil(pol2Stenc.GetOutput());</div><div><br></div><div> vtkMarchingCubes marching = new vtkMarchingCubes();</div>
<div> marching.SetInputConnection(stencil.GetOutputPort());</div><div> marching.ComputeGradientsOff();</div><div> marching.ComputeNormalsOff();</div><div> marching.ComputeScalarsOff();</div><div> marching.SetValue(0, 1);</div>
<div> marching.Update();</div><div><br></div><div>/*</div><div> // This appears to be the slowest of the pipeline, so</div><div> // for now we're going to eliminate it</div><div> vtkDecimatePro decimate = new vtkDecimatePro();</div>
<div> decimate.SetInputConnection(marching.GetOutputPort());</div><div> decimate.SetTargetReduction(0.9);</div><div> decimate.Update();</div><div>*/</div><div> wholeMesh = filter.GetOutput();</div></div>
</div><div><br><div class="gmail_quote">On Mon, Nov 1, 2010 at 6:01 PM, Jonathan Morra <span dir="ltr"><<a href="mailto:jonmorra@gmail.com" target="_blank">jonmorra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have three questions regarding speed in VTK with Java<div>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.</div>
<div><br></div><div> double[] center = imageViewer.GetImageActor().GetCenter();</div><div> vtkPolyData organData = ENV.getInstance().getDataManager().getOrganMesh(organ);</div><div><div> if (organData == null)</div>
<div> continue;</div><div><br></div><div> vtkPlane cutPlane = new vtkPlane();</div><div> cutPlane.SetOrigin(center);</div><div> switch (orientation) {</div><div> case ORIENTATION_XY:</div><div> cutPlane.SetNormal(0, 0, 1);</div>
<div> break;</div><div> case ORIENTATION_XZ:</div><div> cutPlane.SetNormal(0, 1, 0);</div><div> break;</div><div> case ORIENTATION_YZ:</div><div> cutPlane.SetNormal(1, 0, 0);</div>
<div> break;</div><div> }</div><div><br></div><div> vtkCutter cutter = new vtkCutter();</div><div> cutter.SetCutFunction(cutPlane);</div><div> cutter.SetInput(organData);</div><div><br></div><div> vtkPolyDataMapper mapper = new vtkPolyDataMapper();</div>
<div> mapper.SetInputConnection(cutter.GetOutputPort());</div><div> mapper.ScalarVisibilityOff();</div><div> mapper.Update();</div><div><br></div><div> vtkActor actor = new vtkActor();</div><div> actor.SetMapper(mapper);</div>
<div> actor.GetProperty().SetColor(ENV.getInstance().getDataManager().getLineColor(organ));</div><div> actor.GetProperty().SetRepresentationToWireframe();</div><div><br></div><div> imageViewer.GetRenderer().AddActor(actor);</div>
</div><div><br></div><div>From my analysis, the slowdown does not occur here, but rather in the line </div><div>imageViewer.SetSlice(value);</div><div>After some more digging, it turns out that the Render method is actually the method taking the most time to execute.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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</div>
<div><br></div><div><div> // For now, we're just initializing the data with</div><div> // the point that was clicked</div><div><br></div><div> vtkPoints points = new vtkPoints();</div><div> </div><div>
// The initial data MUST be at least a "line"</div><div> // by giving the same point twice we are effictively creating a zero</div><div> // length line</div><div> points.InsertNextPoint(lastContourControlPoint);</div>
<div> points.InsertNextPoint(lastContourControlPoint);</div><div> vtkPolyData initialData = new vtkPolyData();</div><div> initialData.SetPoints(points);</div><div> contourWidget.Initialize(initialData, 0);</div>
</div><div>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.</div><div><br></div><div>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?</div>
<div><br></div><div>Thanks</div>
</blockquote></div><br>
</div>