[vtkusers] using vtkClipClosedSurface() on a box crashes
kent myers
dakota_63124 at yahoo.com
Mon May 25 20:23:29 EDT 2015
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] <ml-node+s1045678n5731996h29 at n5.nabble.com> 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 clippingplane = vtkPlane();plane.SetOrigin(0.0, 0.0, 0.5);plane.SetNormal(0, 0, 1);
# create the box from points and sequencepolyData = 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
vtkCuttingPlane.java (8K) <http://vtk.1045678.n5.nabble.com/attachment/5731997/0/vtkCuttingPlane.java>
--
View this message in context: http://vtk.1045678.n5.nabble.com/using-vtkClipClosedSurface-on-a-box-crashes-tp5731995p5731997.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150525/12c109d5/attachment.html>
More information about the vtkusers
mailing list