[vtkusers] How to create a cube with vtkPolyData

Jothy jothybasu at gmail.com
Tue May 18 06:12:40 EDT 2010


Hi David,

I tried the vtkHexahedron example. But, when I try to cut this I get a line
across the cut plane . see the screenshot and also the code.

Could you please figure it out?

from vtk import*


#Setup the coordinates of eight points
#(the two faces must be in counter clockwise order as viewd from the
outside)
P0 = [0.0, 0.0, 0.0];
P1 = [1.0, 0.0, 0.0];
P2 = [1.0, 1.0, 0.0];
P3 = [0.0, 1.0, 0.0];
P4 = [0.0, 0.0, 1.0];
P5 = [1.0, 0.0, 1.0];
P6 = [1.0, 1.0, 1.0];
P7 = [0.0, 1.0, 1.0];


#Create the points
points = vtkPoints();
points.InsertNextPoint(P0);
points.InsertNextPoint(P1);
points.InsertNextPoint(P2);
points.InsertNextPoint(P3);
points.InsertNextPoint(P4);
points.InsertNextPoint(P5);
points.InsertNextPoint(P6);
points.InsertNextPoint(P7);

#Create a hexahedron from the points
hexa = vtkHexahedron();
hexa.GetPointIds().SetId(0,0);
hexa.GetPointIds().SetId(1,1);
hexa.GetPointIds().SetId(2,2);
hexa.GetPointIds().SetId(3,3);
hexa.GetPointIds().SetId(4,4);
hexa.GetPointIds().SetId(5,5);
hexa.GetPointIds().SetId(6,6);
hexa.GetPointIds().SetId(7,7);

#Add the hexahedron to a cell array
hexs = vtkCellArray();
hexs.InsertNextCell(hexa);

#Add the points and hexahedron to an unstructured grid
uGrid =vtkUnstructuredGrid();
uGrid.SetPoints(points);
uGrid.InsertNextCell(hexa.GetCellType(), hexa.GetPointIds());
aBeamMapper = vtkDataSetMapper()
aBeamMapper.SetInput(uGrid)
aBeamActor = vtkActor()
aBeamActor.SetMapper(aBeamMapper)
aBeamActor.AddPosition(0,0,0)
aBeamActor.GetProperty().SetColor(1,1,0)
aBeamActor.GetProperty().SetOpacity(0.60)
aBeamActor.GetProperty().EdgeVisibilityOn()
aBeamActor.GetProperty().SetEdgeColor(1,1,1)
aBeamActor.GetProperty().SetLineWidth(1.5)

#create a plane to cut,here it cuts in the XZ direction (xz
normal=(1,0,0);XY =(0,0,1),YZ =(0,1,0)
plane=vtkPlane()
plane.SetOrigin(0.5,0,0)
plane.SetNormal(1,0,0)

#create cutter
cutter=vtkCutter()
cutter.SetCutFunction(plane)
cutter.SetInput(aBeamActor.GetMapper().GetInput())
cutter.Update()
cutterMapper=vtkPolyDataMapper()
cutterMapper.SetInputConnection( cutter.GetOutputPort())

#create plane actor
planeActor=vtkActor()
planeActor.GetProperty().SetColor(1,0.5,0.5)
planeActor.GetProperty().SetLineWidth(2)
planeActor.SetMapper(cutterMapper)

# Setup a renderer, render window, and interactor
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
#renderWindow.SetWindowName("Test")

renderWindow.AddRenderer(renderer);
renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

#Add the actor to the scene
renderer.AddActor(aBeamActor)
renderer.AddActor(planeActor)
renderer.SetBackground(0,0,0) # Background color white

#Render and interact
renderWindow.Render()
*
*
I think it has be passed through a filter. But what it's that??

Thanks,

Jothy


On Mon, May 17, 2010 at 10:08 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>>
wrote:
> On Mon, May 17, 2010 at 5:03 PM, Jothy <jothybasu at gmail.com> wrote:
>> Hi all,
>>
>> I want to create a hexahedron using vtkPolyData. I think there is no
>> example in wiki. I created it with a vtkHexaHedron but when I cut it
>> it produces a line across the cut section.I don't want this. I am not
>> able to solve this problem for many months.I used it passing through
>> vtkstripper, vtkTriangle. Finally found that only if the input is of
>> vtkPolyData, cutter will not produce that line across the cut section.
>> Can some with kind enough :), add an example of how to create cube or
>> cone with vtkPoldata.
>>
>> Many thanks,
>>
>> Jothy
>
> I don't really understand your question. The title and your last
> sentence talk about cubes and cones
>
> http://www.vtk.org/Wiki/VTK/Examples/GeometricObjects/Cube
> http://www.vtk.org/Wiki/VTK/Examples/GeometricObjects/Display/Cone
>
> but the beginning talks about hexahedrons
>
> http://www.vtk.org/Wiki/VTK/Examples/GeometricObjects/Hexahedron
>
> Let us know if these links do not help.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100518/b18080aa/attachment.htm>


More information about the vtkusers mailing list