[vtkusers] using vtkClipClosedSurface() on a box crashes

David Gobbi david.gobbi at gmail.com
Mon May 25 23:22:54 EDT 2015


The fact that the box was open completely slipped my notice :)

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.

Reverse the faces, and the result is a closed half-box:

  4, 3,2,1,0,
  4, 2,6,5,1,
  4, 6,7,4,5,
  4, 7,3,0,4,
  4, 4,5,1,0,
  4, 7,6,2,3

 - David

On Mon, May 25, 2015 at 9:02 PM, kent myers via vtkusers <vtkusers at vtk.org>
wrote:

> HI David,
>
> The order of calling SetNumberOfComponents did not make any difference.  I
> am using vtkIdTypeArray and filling it with a vtkIntArray.
>
> The documentation at http://www.vtk.org/Wiki/VTK/Closed_Surface_Clipping says
> that the vtkClipClosedSurface filter "When given a closed surface as input,
> it will produce a closed surface as output."
>
> Do you have any idea why it did not give me a close rectangular box after
> the clip?
>
> Thanks again for you help.  I will keep looking for an efficient way to
> pass point and sequence data from Java.
>
> Kent
>
>
>
>
>
>   On Monday, May 25, 2015 7:40 PM, David Gobbi [via VTK] <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5732003&i=0>> wrote:
>
>
> 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.
>
>  - David
>
>
> On Mon, May 25, 2015 at 7:55 PM, kent myers via vtkusers <[hidden email]>
> wrote:
>
> Hi David,
>
> 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:
>
> http://public.kitware.com/pipermail/vtkusers/2010-January/056525.html
>
> 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?
>
> Thanks,
>
> Kent
>
>
>
>   On Monday, May 25, 2015 5:33 PM, David Gobbi [via VTK] <[hidden email]>
> wrote:
>
>
> Hi Kent,
>
> Yes, it displayed half a box (see attached screenshot).
>
> Let's just say that code like "vtkPoints vtkPoints = new vtkPoints();"
> doesn't fill me with confidence. Can you try building the polydata
> as per my python example and see if that works?
>
> - David
>
>
> On Mon, May 25, 2015 at 6:23 PM, kent myers via vtkusers <[hidden email]>
> wrote:
>
> Hi David,
>
> 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.
>
> 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.
>
> Thanks for taking a look.
>
> Kent
>
>
>
>
>
>   On Monday, May 25, 2015 5:09 PM, David Gobbi [via VTK] <[hidden email]>
> wrote:
>
>
> Hi Kent,
>
> 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?
>
> I translated your code into python (I'm not much of a Java programmer),
> and it ran without any errors:
>
>
> from vtk import *
>
> points = [
>   0.0, 0.0, 0.0,
>   1.0, 0.0, 0.0,
>   1.0, 1.0, 0.0,
>   0.0, 1.0, 0.0,
>   0.0, 0.0, 1.0,
>   1.0, 0.0, 1.0,
>   1.0, 1.0, 1.0,
>   0.0, 1.0, 1.0,
> ]
>
> seq = [
>   4, 0,1,2,3,
>   4, 1,5,6,2,
>   4, 5,4,7,6,
>   4, 4,0,3,7,
>   4, 0,1,5,4,
>   4, 3,2,6,7
> ]
>
> # create a plane for clipping
> plane = vtkPlane();
> plane.SetOrigin(0.0, 0.0, 0.5);
> plane.SetNormal(0, 0, 1);
>
> # create the box from points and sequence
> polyData = vtkPolyData();
> pts = vtkPoints();
> for i in range(8):
>     pts.InsertNextPoint(points[i*3:(i+1)*3])
> polyData.SetPoints(pts);
> cells = vtkCellArray();
> for i in range(6):
>     cells.InsertNextCell(4)
>     for j in range(1,5):
>         cells.InsertCellPoint(seq[5*i + j])
> polyData.SetPolys(cells);
>
> clipClosedSurface = vtkClipClosedSurface();
> planes = vtkPlaneCollection();
> planes.AddItem(plane);
> clipClosedSurface.SetClippingPlanes(planes);
> clipClosedSurface.AddInputData(polyData);
> clipClosedSurface.Update();   # THIS CRASHES
>
> clipMapper = vtkDataSetMapper();
> clipMapper.SetInputConnection(clipClosedSurface.GetOutputPort());
>
> boxActor = vtkActor();
> boxActor.SetMapper(clipMapper);
> boxActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);
>
> ren = vtkRenderer()
> ren.AddActor(boxActor)
>
> win = vtkRenderWindow()
> win.AddRenderer(ren)
>
> iren = vtkRenderWindowInteractor()
> win.SetInteractor(iren)
>
> iren.Initialize()
> iren.Start()
>
> On Mon, May 25, 2015 at 5:18 PM, kent myers via vtkusers <[hidden email]>
> wrote:
>
> I am trying to clip a box constructed as a polydata mesh.  I have tried the
> vtkClipPolyData class based on the quadric surface example in the following
> link, but have not succeeded.
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/SolidClip
>
> I found the vtkClipClosedSurface class and it seems like exactly what I am
> looking for, but I could not find any examples of how to use it.  The code
> below shows my attempt.  It crashes when calling the Update() method.
> Without that call, I get no visible result.
>
> Any help would be appreciated!
>
> Kent
>
>         private static void createBox() {
>                 float[] points = {
>                                 0.0f, 0.0f, 0.0f,
>                                 1.0f, 0.0f, 0.0f,
>                                 1.0f, 1.0f, 0.0f,
>                                 0.0f, 1.0f, 0.0f,
>                                 0.0f, 0.0f, 1.0f,
>                                 1.0f, 0.0f, 1.0f,
>                                 1.0f, 1.0f, 1.0f,
>                                 0.0f, 1.0f, 1.0f,
>                                 };
>                 int[] seq = {
>                                 4, 0, 1, 2, 3,
>                                 4, 1,5,6,2,
>                                 4, 5,4,7,6,
>                                 4, 4,0,3,7,
>                                 4, 0,1,5,4,
>                                 4, 3,2,6,7};
>
>
>                 // create a plane for clipping
>                 vtkPlane plane = new vtkPlane();
>                 plane.SetOrigin(0.0, 0.0, 0.5);
>                 plane.SetNormal(0, 0, 1);
>
>                 // create the box from points and sequence
>                 vtkPolyData polyData = new vtkPolyData();
>                 vtkPoints vtkPoints = new vtkPoints();
>                 vtkFloatArray d = new vtkFloatArray();
>                 d.SetJavaArray(points);
>                 d.SetNumberOfComponents(3);
>                 vtkPoints.SetData(d);
>                 polyData.SetPoints(vtkPoints);
>                 vtkCellArray vtkCells = new vtkCellArray();
>                 vtkIdTypeArray array = new vtkIdTypeArray();
>                 vtkIntArray intArray = new vtkIntArray();
>                 intArray.SetJavaArray(seq);
>                 array.DeepCopy(intArray);
>                 vtkCells.SetCells(seq.length, array);
>                 polyData.SetPolys(vtkCells);
>
>                 vtkClipClosedSurface clipClosedSurface = new
> vtkClipClosedSurface();
>                 vtkPlaneCollection planes = new vtkPlaneCollection();
>                 planes.AddItem(plane);
>                 clipClosedSurface.SetClippingPlanes(planes);
>                 clipClosedSurface.AddInputData(polyData);
>                 clipClosedSurface.Update();   // THIS CRASHES
>
>                 vtkDataSetMapper clipMapper = new vtkDataSetMapper();
>
> clipMapper.SetInputConnection(clipClosedSurface.GetOutputPort());
>
>                 boxActor = new vtkActor();
>                 boxActor.SetMapper(clipMapper);
>                 boxActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);
>
>         }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150525/9e3dbd06/attachment.html>


More information about the vtkusers mailing list