[vtkusers] polyhedron in python

Meehan, Bernard MEEHANBT at nv.doe.gov
Tue Sep 9 20:02:43 EDT 2014


If you needed to make a generic polyhedron that wasn't in the vtkPlatonicSolidSource, you'd do something like this:


import vtk

# This is a Rhombic Dodecahedron.


# First, you need to store the vertex locations.

vertex_locations = vtk.vtkPoints()

vertex_locations.SetNumberOfPoints(14)

vertex_locations.SetPoint( 0, (-0.816497, -0.816497,  0.00000))

vertex_locations.SetPoint( 1, (-0.816497,  0.000000, -0.57735))

vertex_locations.SetPoint( 2, (-0.816497,  0.000000,  0.57735))

vertex_locations.SetPoint( 3, (-0.816497,  0.816497,  0.00000))

vertex_locations.SetPoint( 4, ( 0.000000, -0.816497, -0.57735))

vertex_locations.SetPoint( 5, ( 0.000000, -0.816497,  0.57735))

vertex_locations.SetPoint( 6, ( 0.000000,  0.000000, -1.15470))

vertex_locations.SetPoint( 7, ( 0.000000,  0.000000,  1.15470))

vertex_locations.SetPoint( 8, ( 0.000000,  0.816497, -0.57735))

vertex_locations.SetPoint( 9, ( 0.000000,  0.816497,  0.57735))

vertex_locations.SetPoint(10, ( 0.816497, -0.816497,  0.00000))

vertex_locations.SetPoint(11, ( 0.816497,  0.000000, -0.57735))

vertex_locations.SetPoint(12, ( 0.816497,  0.000000,  0.57735))

vertex_locations.SetPoint(13, ( 0.816497,  0.816497,  0.00000))


# Next, you describe the polygons that represent the faces using the vertex

# indices in the vtkPoints that stores the vertex locations. There are a number

# of ways to do this that you can find in examples on the Wiki.


polygon_faces = vtk.vtkCellArray()


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  7)

q.GetPointIds().SetId(1, 12)

q.GetPointIds().SetId(2, 10)

q.GetPointIds().SetId(3,  5)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  7)

q.GetPointIds().SetId(1, 12)

q.GetPointIds().SetId(2, 13)

q.GetPointIds().SetId(3,  9)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  7)

q.GetPointIds().SetId(1,  9)

q.GetPointIds().SetId(2,  3)

q.GetPointIds().SetId(3,  2)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  7)

q.GetPointIds().SetId(1,  2)

q.GetPointIds().SetId(2,  0)

q.GetPointIds().SetId(3,  5)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  6)

q.GetPointIds().SetId(1, 11)

q.GetPointIds().SetId(2, 10)

q.GetPointIds().SetId(3,  4)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  6)

q.GetPointIds().SetId(1,  4)

q.GetPointIds().SetId(2,  0)

q.GetPointIds().SetId(3,  1)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  6)

q.GetPointIds().SetId(1,  1)

q.GetPointIds().SetId(2,  3)

q.GetPointIds().SetId(3,  8)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  6)

q.GetPointIds().SetId(1,  8)

q.GetPointIds().SetId(2, 13)

q.GetPointIds().SetId(3, 11)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0, 10)

q.GetPointIds().SetId(1, 11)

q.GetPointIds().SetId(2, 13)

q.GetPointIds().SetId(3, 12)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0, 13)

q.GetPointIds().SetId(1,  8)

q.GetPointIds().SetId(2,  3)

q.GetPointIds().SetId(3,  9)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  3)

q.GetPointIds().SetId(1,  1)

q.GetPointIds().SetId(2,  0)

q.GetPointIds().SetId(3,  2)

polygon_faces.InsertNextCell(q)


q = vtk.vtkQuad()

q.GetPointIds().SetId(0,  0)

q.GetPointIds().SetId(1,  4)

q.GetPointIds().SetId(2, 10)

q.GetPointIds().SetId(3,  5)

polygon_faces.InsertNextCell(q)


# Next you create a vtkPolyData to store your face and vertex information that

# represents your polyhedron.

pd = vtk.vtkPolyData()

pd.SetPoints(vertex_locations)

pd.SetPolys(polygon_faces)


#---------------------#

# visualization stuff #

#---------------------#

mapper = vtk.vtkPolyDataMapper()

mapper.SetInputData(pd)


actor = vtk.vtkActor()

actor.SetMapper(mapper)


ren = vtk.vtkRenderer()

ren.AddActor(actor)


renw = vtk.vtkRenderWindow()

renw.AddRenderer(ren)


iren = vtk.vtkRenderWindowInteractor()

iren.SetRenderWindow(renw)


ren.ResetCamera()

renw.Render()

iren.Start()


From: Christopher Mullins <christopher.mullins at kitware.com<mailto:christopher.mullins at kitware.com>>
Date: Tuesday, September 9, 2014 1:28 PM
To: George <george.gerber at gmail.com<mailto:george.gerber at gmail.com>>
Cc: VTK <vtkusers at vtk.org<mailto:vtkusers at vtk.org>>
Subject: Re: [vtkusers] polyhedron in python

The Geometric Objects examples (c++[1] and python[2]) might be what you're looking for.

[1] http://www.vtk.org/Wiki/VTK/Examples/Cxx#Geometric_Objects
[2] http://www.vtk.org/Wiki/VTK/Examples/Python#Geometric_Objects

On Tue, Sep 9, 2014 at 4:19 PM, George <george.gerber at gmail.com<mailto:george.gerber at gmail.com>> wrote:
Good day,

Would somebody be so kind as to give a basic example of creating a
polyhedron in python (or c++ if necessary)? I have searched google
extensively, without any luck.

Best regards,
George



--
View this message in context: http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com<http://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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers



--
Christopher Mullins
R&D Engineer
Kitware Inc.,
919.869.8871
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140910/aac0c0b5/attachment.html>


More information about the vtkusers mailing list