[vtkusers] using vtkClipClosedSurface() on a box crashes

David Gobbi david.gobbi at gmail.com
Mon May 25 22:37:58 EDT 2015


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 <vtkusers at vtk.org>
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]
> <http:///user/SendEmail.jtp?type=node&node=5732000&i=0>> 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);
>
>         }
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://vtk.1045678.n5.nabble.com/using-vtkClipClosedSurface-on-a-box-crashes-tp5731995p5731996.html
>  To unsubscribe from using vtkClipClosedSurface() on a box crashes, click
> here.
> NAML
> <http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
>
>
> *vtkCuttingPlane.java* (8K) Download Attachment
> <http://vtk.1045678.n5.nabble.com/attachment/5731997/0/vtkCuttingPlane.java>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
> *ScreenShot.png* (30K) Download Attachment
> <http://vtk.1045678.n5.nabble.com/attachment/5731998/0/ScreenShot.png>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150525/c3730a3a/attachment.html>


More information about the vtkusers mailing list