<div dir="ltr"><div>The fact that the box was open completely slipped my notice :)</div><div><br></div><div>It was because of the ordering of the points for the faces, the normals were facing inwards instead of outwards.  Therefore the algorithm considered the inside of the box to be the "outside" of the surface.</div><div><br></div><div>Reverse the faces, and the result is a closed half-box:</div><div><br></div><div>  4, 3,2,1,0,</div><div>  4, 2,6,5,1,</div><div>  4, 6,7,4,5,</div><div>  4, 7,3,0,4,</div><div>  4, 4,5,1,0,</div><div>  4, 7,6,2,3</div><div><br></div><div> - David</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 25, 2015 at 9:02 PM, kent myers via vtkusers <span dir="ltr"><<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:12px"><div><span>HI David,</span></div><div><span></span><br></div><div dir="ltr"><span>The order of calling SetNumberOfComponents did not make any difference.  I am using vtkIdTypeArray and filling it with a vtkIntArray.</span></div><div dir="ltr"><span></span><br></div><div dir="ltr"><span>The documentation at <a href="http://www.vtk.org/Wiki/VTK/Closed_Surface_Clipping" rel="nofollow" link="external" target="_blank">http://www.vtk.org/Wiki/VTK/Closed_Surface_Clipping</a> says that the vtkClipClosedSurface filter "When given a closed surface as input, it will produce a closed surface as output."</span></div><div dir="ltr"><span></span><br></div><div dir="ltr"><span>Do you have any idea why it did not give me a close rectangular box after the clip?</span></div><div dir="ltr"><span></span><br></div><div dir="ltr"><span>Thanks again for you help.  I will keep looking for an efficient way to pass point and sequence data from Java.</span></div><div dir="ltr"><span></span><br></div><div dir="ltr"><span>Kent</span></div><div dir="ltr"><span></span><br></div><div dir="ltr"><span></span><br></div>  <br><div><br><br></div><div style="display:block"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:12px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><span class=""> <div dir="ltr"> <font face="Arial" size="2"> On Monday, May 25, 2015 7:40 PM, David Gobbi [via VTK] <<a href="http:///user/SendEmail.jtp?type=node&node=5732003&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>> wrote:<br> </font> </div>  <br><br> </span><div><div><div><div dir="ltr"><span class=""><div>Unfortunately, I don't know much about the Java wrappers... I didn't realize the SetJavaArray() method existed until I saw the code you posted.  The crash could be due to something as simple as calling d.SetNumberOfComponents(3) after SetJavaArray(), instead of before.  Or using a vtkIntArray instead of a vtkIdTypeArray.</div><div><br clear="none"></div><div> - David</div><div><br clear="none"></div></span><div><div class="h5"><div><br clear="none"><div>On Mon, May 25, 2015 at 7:55 PM, kent myers via vtkusers <span dir="ltr"><<a rel="nofollow" shape="rect" link="external">[hidden email]</a>></span> wrote:<br clear="none"><blockquote style="border-left:2px solid #cccccc;padding:0 1em"><div style="color:rgb(0,0,0);font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:12px;background-color:rgb(255,255,255)"><div><span>Hi David,</span></div><div><span></span><br clear="none"></div><div><span>Changing to your technique of filling the point and cells did solve the problem.  One reason I did not do it that way is because in my actual application, I have 10's of thousands of points and I do not want to make a Java API call to store every point and every cell connection.  I am afraid the efficiency hit would be very high.  I found the technique of copying the entire point and cell data arrays in one call in an article that you wrote:</span></div><div><span></span><br clear="none"></div><div dir="ltr"><span><a href="http://public.kitware.com/pipermail/vtkusers/2010-January/056525.html" rel="nofollow" shape="rect" link="external" target="_blank">http://public.kitware.com/pipermail/vtkusers/2010-January/056525.html</a></span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>Of course it was C++, but since the methods are in the Java API, I assumed it was a safe method to use.  Do you know of a better way to pass the java points and cell definitions more efficiently than one by one?</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>Thanks,</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>Kent</span></div>  <br clear="none"><div><br clear="none"><br clear="none"></div><div style="display:block"> <div style="font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:12px"> <div style="font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:16px"><span> </span><div dir="ltr"> <font face="Arial" size="2"> On Monday, May 25, 2015 5:33 PM, David Gobbi [via VTK] <<a rel="nofollow" shape="rect" link="external">[hidden email]</a>> wrote:<br clear="none"> </font> </div>  <br clear="none"><br clear="none"> <div><div><div><div dir="ltr">Hi Kent,<div><br clear="none"></div><span></span><div>Yes, it displayed half a box (see attached screenshot).</div><div><br clear="none"></div><div>Let's just say that code like "<span style="color:rgb(0,0,0);white-space:pre-wrap">vtkPoints vtkPoints = new vtkPoints();"</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">doesn't fill me with confidence.  Can you try building the polydata</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">as per my python example and see if that works?</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br clear="none"></span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> - David</span></div><div><div><div><br clear="none"><div><br clear="none"><div>On Mon, May 25, 2015 at 6:23 PM, kent myers via vtkusers <span dir="ltr"><<a rel="nofollow" shape="rect" link="external">[hidden email]</a>></span> wrote:<br clear="none"><blockquote style="border-left:2px solid #cccccc;padding:0 1em"><div style="color:rgb(0,0,0);font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:12px;background-color:rgb(255,255,255)"><div><span>Hi David,</span></div><div><span></span><br clear="none"></div><div dir="ltr"><span>I did display the box successfully.  This method was extracted from a complete demo  application that I submitted to the bug tracker as issue 0015487.  I have attached it here if you want to look at it.  This would not be the first time that the Java API crashes using methods that work in other languages.</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>You said it ran without errors.  Did you get a properly clipped box as a result?  It started out as a cube and I put the clipping plane half the height of the cube.</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>Thanks for taking a look.</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span>Kent</span></div><div dir="ltr"><span></span><br clear="none"></div><div dir="ltr"><span></span><br clear="none"></div>  <br clear="none"><div><br clear="none"><br clear="none"></div><div style="display:block"> <div style="font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:12px"> <div style="font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:16px"><div><div> <div dir="ltr"> <font face="Arial" size="2"> On Monday, May 25, 2015 5:09 PM, David Gobbi [via VTK] <<a rel="nofollow" shape="rect" link="external">[hidden email]</a>> wrote:<br clear="none"> </font> </div>  <br clear="none"><br clear="none"> </div></div><div><div><div><div dir="ltr"><div><div><div>Hi Kent,</div><div><br clear="none"></div><div>Your code for building the polydata looks suspicious.  If you put your box polydata directly into the mapper (i.e. without vtkClipClosedSurface) does it display properly? </div><div><br clear="none"></div><div>I translated your code into python (I'm not much of a Java programmer), and it ran without any errors:</div><div><br clear="none"></div><div><br clear="none"></div><div>from vtk import *</div><div><br clear="none"></div><div>points = [</div><div>  0.0, 0.0, 0.0,</div><div>  1.0, 0.0, 0.0,</div><div>  1.0, 1.0, 0.0,</div><div>  0.0, 1.0, 0.0,</div><div>  0.0, 0.0, 1.0,</div><div>  1.0, 0.0, 1.0,</div><div>  1.0, 1.0, 1.0,</div><div>  0.0, 1.0, 1.0,</div><div>]</div><div><br clear="none"></div><div>seq = [</div><div>  4, 0,1,2,3,</div><div>  4, 1,5,6,2,</div><div>  4, 5,4,7,6,</div><div>  4, 4,0,3,7,</div><div>  4, 0,1,5,4,</div><div>  4, 3,2,6,7</div><div>]</div><div><br clear="none"></div><div># create a plane for clipping</div><div>plane = vtkPlane();</div><div>plane.SetOrigin(0.0, 0.0, 0.5);</div><div>plane.SetNormal(0, 0, 1);</div><div><br clear="none"></div><div># create the box from points and sequence</div><div>polyData = vtkPolyData();</div><div>pts = vtkPoints();</div><div>for i in range(8):</div><div>    pts.InsertNextPoint(points[i*3:(i+1)*3])</div><div>polyData.SetPoints(pts);</div><div>cells = vtkCellArray();</div><div>for i in range(6):</div><div>    cells.InsertNextCell(4)</div><div>    for j in range(1,5):</div><div>        cells.InsertCellPoint(seq[5*i + j])</div><div>polyData.SetPolys(cells);</div><div><br clear="none"></div><div>clipClosedSurface = vtkClipClosedSurface();</div><div>planes = vtkPlaneCollection();</div><div>planes.AddItem(plane);</div><div>clipClosedSurface.SetClippingPlanes(planes);</div><div>clipClosedSurface.AddInputData(polyData);</div><div>clipClosedSurface.Update();   # THIS CRASHES</div><div><br clear="none"></div><div>clipMapper = vtkDataSetMapper();</div><div>clipMapper.SetInputConnection(clipClosedSurface.GetOutputPort());</div><div><br clear="none"></div><div>boxActor = vtkActor();</div><div>boxActor.SetMapper(clipMapper);</div><div>boxActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);</div><div><br clear="none"></div><div>ren = vtkRenderer()</div><div>ren.AddActor(boxActor)</div><div><br clear="none"></div><div>win = vtkRenderWindow()</div><div>win.AddRenderer(ren)</div><div><br clear="none"></div><div>iren = vtkRenderWindowInteractor()</div><div>win.SetInteractor(iren)</div><div><br clear="none"></div><div>iren.Initialize()</div><div>iren.Start()</div></div></div><div><div><div><br clear="none"><div><div>On Mon, May 25, 2015 at 5:18 PM, kent myers via vtkusers <span dir="ltr"><<a rel="nofollow" shape="rect" link="external">[hidden email]</a>></span> wrote:<br clear="none"><blockquote style="border-left:2px solid #cccccc;padding:0 1em">I am trying to clip a box constructed as a polydata mesh.  I have tried the<br clear="none">
vtkClipPolyData class based on the quadric surface example in the following<br clear="none">
link, but have not succeeded.<br clear="none">
<br clear="none">
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/SolidClip" rel="nofollow" shape="rect" link="external" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/SolidClip</a><br clear="none">
<br clear="none">
I found the vtkClipClosedSurface class and it seems like exactly what I am<br clear="none">
looking for, but I could not find any examples of how to use it.  The code<br clear="none">
below shows my attempt.  It crashes when calling the Update() method.<br clear="none">
Without that call, I get no visible result.<br clear="none">
<br clear="none">
Any help would be appreciated!<br clear="none">
<br clear="none">
Kent<br clear="none">
<br clear="none">
        private static void createBox() {<br clear="none">
                float[] points = {<br clear="none">
                                0.0f, 0.0f, 0.0f,<br clear="none">
                                1.0f, 0.0f, 0.0f,<br clear="none">
                                1.0f, 1.0f, 0.0f,<br clear="none">
                                0.0f, 1.0f, 0.0f,<br clear="none">
                                0.0f, 0.0f, 1.0f,<br clear="none">
                                1.0f, 0.0f, 1.0f,<br clear="none">
                                1.0f, 1.0f, 1.0f,<br clear="none">
                                0.0f, 1.0f, 1.0f,<br clear="none">
                                };<br clear="none">
                int[] seq = {<br clear="none">
                                4, 0, 1, 2, 3,<br clear="none">
                                4, 1,5,6,2,<br clear="none">
                                4, 5,4,7,6,<br clear="none">
                                4, 4,0,3,7,<br clear="none">
                                4, 0,1,5,4,<br clear="none">
                                4, 3,2,6,7};<br clear="none">
<br clear="none">
<br clear="none">
                // create a plane for clipping<br clear="none">
                vtkPlane plane = new vtkPlane();<br clear="none">
                plane.SetOrigin(0.0, 0.0, 0.5);<br clear="none">
                plane.SetNormal(0, 0, 1);<br clear="none">
<br clear="none">
                // create the box from points and sequence<br clear="none">
                vtkPolyData polyData = new vtkPolyData();<br clear="none">
                vtkPoints vtkPoints = new vtkPoints();<br clear="none">
                vtkFloatArray d = new vtkFloatArray();<br clear="none">
                d.SetJavaArray(points);<br clear="none">
                d.SetNumberOfComponents(3);<br clear="none">
                vtkPoints.SetData(d);<br clear="none">
                polyData.SetPoints(vtkPoints);<br clear="none">
                vtkCellArray vtkCells = new vtkCellArray();<br clear="none">
                vtkIdTypeArray array = new vtkIdTypeArray();<br clear="none">
                vtkIntArray intArray = new vtkIntArray();<br clear="none">
                intArray.SetJavaArray(seq);<br clear="none">
                array.DeepCopy(intArray);<br clear="none">
                vtkCells.SetCells(seq.length, array);<br clear="none">
                polyData.SetPolys(vtkCells);<br clear="none">
<br clear="none">
                vtkClipClosedSurface clipClosedSurface = new vtkClipClosedSurface();<br clear="none">
                vtkPlaneCollection planes = new vtkPlaneCollection();<br clear="none">
                planes.AddItem(plane);<br clear="none">
                clipClosedSurface.SetClippingPlanes(planes);<br clear="none">
                clipClosedSurface.AddInputData(polyData);<br clear="none">
                clipClosedSurface.Update();   // THIS CRASHES<br clear="none">
<br clear="none">
                vtkDataSetMapper clipMapper = new vtkDataSetMapper();<br clear="none">
                clipMapper.SetInputConnection(clipClosedSurface.GetOutputPort());<br clear="none">
<br clear="none">
                boxActor = new vtkActor();<br clear="none">
                boxActor.SetMapper(clipMapper);<br clear="none">
                boxActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);<br clear="none">
<br clear="none">
        }<br></blockquote></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></div>