[vtkusers] using vtkClipClosedSurface() on a box crashes
David Gobbi
david.gobbi at gmail.com
Mon May 25 20:08:46 EDT 2015
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 <vtkusers at vtk.org>
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/41571826/attachment.html>
More information about the vtkusers
mailing list