OK I changed the linear extrusion filter as follows, and the error still occurs.<div><div><br></div><div>vtkLinearExtrusionFilter extruder = new vtkLinearExtrusionFilter();</div><div>extruder.SetInput(drawnCircle);</div><div>
extruder.SetScaleFactor(1);</div><div>extruder.SetExtrusionTypeToNormalExtrusion();</div><div>extruder.SetVector(0, 0, spacing[2]);</div><div>extruder.Update();</div><br><div class="gmail_quote">On Wed, Feb 23, 2011 at 11:59 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@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've only had a chance to do a quick look through your code, only one<br>
thing looks definitely wrong:<br>
<br>
extruder.SetVector(spacing);<br>
<br>
This extrudes the contour along a diagonal line, which is probably not<br>
what you intended. You want to extrude only in the direction of the<br>
slice normal. Take a look at how the extruder is set up in<br>
VTK/Widgets/Testing/Cxx/TestImageTracerWidget.cxx and also note the<br>
TransformPolyData that is applied to the extruder's output.<br>
<font color="#888888"><br>
- David<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
On Wed, Feb 23, 2011 at 8:49 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>> wrote:<br>
> Here's a copy of a small working program in Java that shows the issues that<br>
> I'm talking about. The program will spit out 2 lines of text. I need them<br>
> both to evaluate to true (that the center and bounds stay the same). In<br>
> addition a render window will open up and clearly show that the two circles<br>
> do not line up with each other (again they should). Please let me know how<br>
> I can fix this problem.<br>
> Thanks!!<br>
> import vtk.*;<br>
> import java.util.Arrays;<br>
> public class PolyDataToImageToPolyDataTest {<br>
> static {<br>
> System.loadLibrary("vtkCommonJava");<br>
> System.loadLibrary("vtkFilteringJava");<br>
> System.loadLibrary("vtkGenericFilteringJava");<br>
> System.loadLibrary("vtkGraphicsJava");<br>
> System.loadLibrary("vtkHybridJava");<br>
> System.loadLibrary("vtkImagingJava");<br>
> System.loadLibrary("vtkIOJava");<br>
> System.loadLibrary("vtkRenderingJava");<br>
> System.loadLibrary("vtkVolumeRenderingJava");<br>
> System.loadLibrary("vtkWidgetsJava");<br>
> }<br>
> public static void main(String[] args) {<br>
> vtkRegularPolygonSource polygonSource = new<br>
> vtkRegularPolygonSource();<br>
> polygonSource.SetNumberOfSides(50);<br>
> polygonSource.SetRadius(50);<br>
> polygonSource.GeneratePolygonOff();<br>
> polygonSource.Update();<br>
> vtkImageData blankImage = new vtkImageData();<br>
> int[] extent = {0, 512, 0, 512, 0, 100};<br>
> double[] origin = {-256, -256, 0};<br>
> double[] spacing = {1, 1, 1};<br>
> blankImage.SetExtent(extent);<br>
> blankImage.SetOrigin(origin);<br>
> blankImage.SetSpacing(spacing);<br>
> blankImage.SetScalarTypeToUnsignedChar();<br>
> blankImage.AllocateScalars();<br>
> vtkPolyData initialCircle = polygonSource.GetOutput();<br>
> vtkPolyData drawnCircle = new vtkPolyData();<br>
> drawnCircle.DeepCopy(initialCircle);<br>
> // I'm choosing 10 here because this problem gets exacerbated after<br>
> each run. By varying this, the problem will get less or more severe.<br>
> for (int i=0; i<10; i++) {<br>
> vtkLinearExtrusionFilter extruder = new<br>
> vtkLinearExtrusionFilter();<br>
> extruder.SetInput(drawnCircle);<br>
> extruder.SetVector(spacing);<br>
> extruder.Update();<br>
> vtkPolyData extruderOutput = extruder.GetOutput();<br>
> vtkPolyDataToImageStencil pol2Stenc = new<br>
> vtkPolyDataToImageStencil();<br>
> pol2Stenc.SetTolerance(0);<br>
> pol2Stenc.SetInput(extruderOutput);<br>
> pol2Stenc.SetInformationInput(blankImage);<br>
> pol2Stenc.Update();<br>
> vtkImageStencilData pol2StencOutput = pol2Stenc.GetOutput();<br>
> vtkImageStencil stencil = new vtkImageStencil();<br>
> stencil.SetInput(blankImage);<br>
> stencil.ReverseStencilOn();<br>
> stencil.SetStencil(pol2StencOutput);<br>
> stencil.Update();<br>
> vtkImageData image = stencil.GetOutput();<br>
><br>
> vtkMarchingSquares marching = new vtkMarchingSquares();<br>
> marching.SetInput(image);<br>
> // For some reason the circle moves in all 3 dimensions, so I<br>
> need to vary the z-coordinate w.r.t the iteration number<br>
> marching.SetImageRange(new int[] {0, 512, 0, 512, i+1, i+1});<br>
> marching.SetValue(0, 1);<br>
> marching.Update();<br>
> vtkPolyData marchingOutput = marching.GetOutput();<br>
> vtkStripper stripper = new vtkStripper();<br>
> stripper.SetInput(marchingOutput);<br>
> stripper.Update();<br>
> drawnCircle = stripper.GetOutput();<br>
> }<br>
> boolean sameCenter = Arrays.equals(drawnCircle.GetCenter(),<br>
> initialCircle.GetCenter());<br>
> boolean sameBounds = Arrays.equals(drawnCircle.GetBounds(),<br>
> initialCircle.GetBounds());<br>
> System.out.println("Same center: " + sameCenter);<br>
> System.out.println("Same bounds: " + sameBounds);<br>
> vtkPolyDataMapper circleMapper = new vtkPolyDataMapper();<br>
> circleMapper.SetInput(initialCircle);<br>
> circleMapper.ScalarVisibilityOff();<br>
> circleMapper.Update();<br>
> vtkActor circleActor = new vtkActor();<br>
> circleActor.SetMapper(circleMapper);<br>
> circleActor.GetProperty().SetRepresentationToSurface();<br>
> circleActor.GetProperty().SetColor(1, 0, 0);<br>
> vtkPolyDataMapper outCircleMapper = new vtkPolyDataMapper();<br>
> outCircleMapper.SetInput(drawnCircle);<br>
> outCircleMapper.ScalarVisibilityOff();<br>
> outCircleMapper.Update();<br>
> vtkActor outCircleActor = new vtkActor();<br>
> outCircleActor.SetMapper(outCircleMapper);<br>
> outCircleActor.GetProperty().SetRepresentationToSurface();<br>
> outCircleActor.GetProperty().SetColor(0, 1, 0);<br>
> vtkRenderer ren = new vtkRenderer();<br>
> ren.AddActor(circleActor);<br>
> ren.AddActor(outCircleActor);<br>
> ren.SetBackground(0.1, 0.2, 0.4);<br>
> vtkRenderWindow renWin = new vtkRenderWindow();<br>
> renWin.AddRenderer(ren);<br>
> vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br>
> renWin.SetInteractor(iren);<br>
> renWin.Render();<br>
> ren.ResetCamera();<br>
> iren.Start();<br>
> }<br>
> }<br>
><br>
><br>
> On Wed, Feb 23, 2011 at 1:31 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>> wrote:<br>
>><br>
>> I tried it but it doesn't work, any other ideas? I really appreciate your<br>
>> help.<br>
>><br>
>> On Wed, Feb 23, 2011 at 1:01 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi Jonathan,<br>
>>><br>
>>> If you convert a contour to a binary image and then back to a contour,<br>
>>> you won't get the exactly the same contour back again. That said, I<br>
>>> think that you can get what you want as long as you apply the correct<br>
>>> tolerances. You can try a contour value of 0.9 for marching squares,<br>
>>> which is fairly tight but not so tight that it will cause the edge<br>
>>> problems that I mentioned in my earlier email. It might work, or it<br>
>>> might not work.<br>
>>><br>
>>> - David<br>
>>><br>
>>><br>
>>> On Wed, Feb 23, 2011 at 1:07 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>><br>
>>> wrote:<br>
>>> > I tried that and now the contour appears to both erode and dilate.<br>
>>> > What I'm<br>
>>> > doing it to take as input some contour data. I then convert it to a<br>
>>> > binary<br>
>>> > image for internal storage using vtkPolyDataToImageStencil. I then<br>
>>> > take a<br>
>>> > slice of the contour and show it to the user using vtkMarchingSquares.<br>
>>> > The<br>
>>> > user can then modify the contour. When the user is done modifying the<br>
>>> > contour I convert it back to binary data for storage using the<br>
>>> > vtkPolyDataToImageStencil, and then again reslice it and use<br>
>>> > vtkMarchingSquares to show the user the contour again. This process is<br>
>>> > very<br>
>>> > quick. What is happening is that the contour appears to be moving on<br>
>>> > the<br>
>>> > screen as this cycle happens even if no edits are done.<br>
>>> > That is the underlying problem I need to fix.<br>
>>> ><br>
>>> > On Wed, Feb 23, 2011 at 11:59 AM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>>> > wrote:<br>
>>> >><br>
>>> >> I've never used marching squares, but I have a guess as<br>
>>> >> to what the problem might be. If your binary image has<br>
>>> >> values "0" and "1" then you should contour it at "0.5".<br>
>>> >><br>
>>> >> - David<br>
>>> >><br>
>>> >><br>
>>> >> On Wed, Feb 23, 2011 at 12:27 PM, Jonathan Morra <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>><br>
>>> >> wrote:<br>
>>> >> > If that's the case, then maybe I could have issues on the other side<br>
>>> >> > (converting binary images to contours, I do both). For this I'm<br>
>>> >> > using<br>
>>> >> > vtkMarchingSquares followed by vtkStripper<br>
>>> >> > int[] extent = binaryOrgan.GetExtent();<br>
>>> >> > switch (orientation) {<br>
>>> >> > case OrthoPanel.ORIENTATION_XY:<br>
>>> >> > extent[4] = slice;<br>
>>> >> > extent[5] = slice;<br>
>>> >> > break;<br>
>>> >> > case OrthoPanel.ORIENTATION_XZ:<br>
>>> >> > extent[2] = slice;<br>
>>> >> > extent[3] = slice;<br>
>>> >> > break;<br>
>>> >> > case OrthoPanel.ORIENTATION_YZ:<br>
>>> >> > extent[0] = slice;<br>
>>> >> > extent[1] = slice;<br>
>>> >> > break;<br>
>>> >> > }<br>
>>> >> > vtkMarchingSquares marching = new vtkMarchingSquares();<br>
>>> >> > marching.SetInput(binaryOrgan);<br>
>>> >> > marching.SetImageRange(extent);<br>
>>> >> > marching.SetValue(0, 1);<br>
>>> >> > marching.Update();<br>
>>> >> > vtkPolyData marchingOutput = marching.GetOutput();<br>
>>> >> > vtkStripper stripper = new vtkStripper();<br>
>>> >> > stripper.SetInput(marchingOutput);<br>
>>> >> > stripper.Update();<br>
>>> >> > Does anything look like it could be causing my issues there?<br>
>>> >> > On Wed, Feb 23, 2011 at 11:18 AM, David Gobbi<br>
>>> >> > <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>>> >> > wrote:<br>
>>> >> >><br>
>>> >> >> The value "1e-6" is a common tolerance because it is larger than<br>
>>> >> >> most roundoff errors that are likely to occur in the calculations,<br>
>>> >> >> but still small enough that it won't appreciably increase size of<br>
>>> >> >> the<br>
>>> >> >> region.<br>
>>> >> >><br>
>>> >> >> Setting the tolerance to zero does exactly what you noted. If the<br>
>>> >> >> pixel is exactly on the edge, then it is considered to be inside if<br>
>>> >> >> the<br>
>>> >> >> edge is a leading edge, or outside if the edge is a trailing edge.<br>
>>> >> >> This is done so that if you have two contours which are adjacent<br>
>>> >> >> (i.e. share an edge), the edge voxels will be considered to be in<br>
>>> >> >> just one of the two contours instead of in both. If the tolerance<br>
>>> >> >> is<br>
>>> >> >> set larger than zero, then the edge pixels would always be<br>
>>> >> >> considered<br>
>>> >> >> to be in both contours.<br>
>>> >> >><br>
>>> >> >> If you are dealing with rectangular contours, then the contour<br>
>>> >> >> lines should be made so that they lie halfway between pixels,<br>
>>> >> >> instead<br>
>>> >> >> of lying directly on top of the pixels. Then there is no<br>
>>> >> >> uncertainty<br>
>>> >> >> about whether a pixel lies inside or outside.<br>
>>> >> >><br>
>>> >> >> - David<br>
>>> >> >><br>
>>> >> >><br>
>>> >> >> On Wed, Feb 23, 2011 at 11:58 AM, Jonathan Morra<br>
>>> >> >> <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>><br>
>>> >> >> wrote:<br>
>>> >> >> > I had the tolerance set to 0, and setting it to 1e-6 didn't fix<br>
>>> >> >> > the<br>
>>> >> >> > problem.<br>
>>> >> >> > How did you come up with that number? What's wrong with setting<br>
>>> >> >> > it<br>
>>> >> >> > to<br>
>>> >> >> > 0?<br>
>>> >> >> > In my case usually the left and top side of the vtkImageData is<br>
>>> >> >> > being<br>
>>> >> >> > eroded, such that if I call the filter many times, the<br>
>>> >> >> > vtkImageData<br>
>>> >> >> > will<br>
>>> >> >> > eventually be blank because it will all be eroded. However,<br>
>>> >> >> > sometimes<br>
>>> >> >> > the<br>
>>> >> >> > bottom and right grow in size, I haven't figured out which<br>
>>> >> >> > situations<br>
>>> >> >> > cause<br>
>>> >> >> > which.<br>
>>> >> >> ><br>
>>> >> >> > On Wed, Feb 23, 2011 at 10:54 AM, David Gobbi<br>
>>> >> >> > <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>>> >> >> > wrote:<br>
>>> >> >> >><br>
>>> >> >> >> Hi Jonathan,<br>
>>> >> >> >><br>
>>> >> >> >> Whether a pixel is set depends on whether the center of the<br>
>>> >> >> >> pixel<br>
>>> >> >> >> is inside or outside the contour, irregardless of what<br>
>>> >> >> >> proportion of<br>
>>> >> >> >> the pixel's volume is inside or outside.<br>
>>> >> >> >><br>
>>> >> >> >> The only adjustment is the Tolerance, which should be set to<br>
>>> >> >> >> around 1e-6 so that pixels right on the edge of the contour<br>
>>> >> >> >> are considered to be inside. The tolerance cannot be negative.<br>
>>> >> >> >><br>
>>> >> >> >> - David<br>
>>> >> >> >><br>
>>> >> >> >><br>
>>> >> >> >> On Wed, Feb 23, 2011 at 11:22 AM, Jonathan Morra<br>
>>> >> >> >> <<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>><br>
>>> >> >> >> wrote:<br>
>>> >> >> >> > I am currently using vtkPolyDataToImageStencil to successfully<br>
>>> >> >> >> > convert<br>
>>> >> >> >> > contours represented as vtkPolyData to binary vtkImageData's.<br>
>>> >> >> >> > However,<br>
>>> >> >> >> > I'm<br>
>>> >> >> >> > noticing a problem with the output sometimes. Sometimes the<br>
>>> >> >> >> > resulting<br>
>>> >> >> >> > binary images are slightly smaller or slightly bigger than the<br>
>>> >> >> >> > poly<br>
>>> >> >> >> > data<br>
>>> >> >> >> > they were made from. I assume this is the result of partial<br>
>>> >> >> >> > volume<br>
>>> >> >> >> > effects.<br>
>>> >> >> >> > I would like to know 2 things<br>
>>> >> >> >> > 1. How does vtkPolyDataToImageStencil handle partial volume.<br>
>>> >> >> >> > 2. Is there a way to tune partial volume in<br>
>>> >> >> >> > vtkPolyDataToImageStencil?<br>
>>> >> >> >> > For<br>
>>> >> >> >> > instance, a parameter which says if the contour includes less<br>
>>> >> >> >> > than<br>
>>> >> >> >> > x<br>
>>> >> >> >> > percentage of the pixel then that pixel is 0.<br>
>>> >> >> >> > Thanks,<br>
>>> >> >> >> > Jon<br>
>>> >> >> >> > PS If my assumption about partial volume effects is wrong,<br>
>>> >> >> >> > please<br>
>>> >> >> >> > let<br>
>>> >> >> >> > me<br>
>>> >> >> >> > know.<br>
>>> >> >> >> > _______________________________________________<br>
>>> >> >> >> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>>> >> >> >> ><br>
>>> >> >> >> > Visit other Kitware open-source projects at<br>
>>> >> >> >> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>>> >> >> >> ><br>
>>> >> >> >> > Please keep messages on-topic and check the VTK FAQ at:<br>
>>> >> >> >> > <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>>> >> >> >> ><br>
>>> >> >> >> > Follow this link to subscribe/unsubscribe:<br>
>>> >> >> >> > <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>>> >> >> >> ><br>
>>> >> >> >> ><br>
>>> >> >> ><br>
>>> >> >> ><br>
>>> >> ><br>
>>> >> ><br>
>>> ><br>
>>> ><br>
>><br>
><br>
><br>
</div></div></blockquote></div><br></div>