[vtkusers] Triangle Geometry and Vertices

Jim Peterson jimcp at cox.net
Sun Dec 12 08:39:35 EST 2010


Paulo,
I am no Python expert, but if I understand the sequence of events, you 
should create the polydata object before writing the file.

Hope that helps,
Jim

Paulo Henrique Junqueira Amorim wrote:
> Hi,
>
> I'm trying to write this example ( 
> http://www.vtk.org/Wiki/VTK/Tutorials/TriangleGeometryVertices ) in 
> python language.
>
> When you open the VTK rendering window occurs Segmentation fault.
>
> I tried to open the file (.vtp) in the Paraview, when click on Apply, 
> the Paraview closes.
>
> Regards,
> Paulo
>
>
> *The code:
> *
> from vtk import *
>
> X = [1.0, 0.0, 0.0]
> Y = [0.0, 0.0, 1.0]
> Z = [0.0, 0.0, 0.0]
>  
> points = vtkPoints()
> vertices = vtkCellArray()
>
> ids = vtkIdList()
> ids.SetNumberOfIds(3)
>
> for i in xrange(3):
>     ids.SetId(i, i)
>     points.InsertNextPoint(X[i],Y[i],Z[i])
>     vertices.InsertNextCell(ids)
>    
> writer = vtkXMLPolyDataWriter()
> writer.SetFileName ( ".//TriangleVerts.vtp")
> writer.SetInput(polydata)
> writer.Write()
>
> polydata = vtkPolyData()
> polydata.SetPoints(points)
> polydata.SetVerts(vertices)
> polydata.Update()
>
> mapper = vtkPolyDataMapper()
> mapper.SetInput(polydata)
>
> actor = vtkActor()
> actor.SetMapper(mapper)
>  
> ren = vtkRenderer()
> ren.AddActor(actor)
>
> renWin = vtkRenderWindow()
> renWin.AddRenderer( ren )
>
> iren = vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
>
> renWin.Render()
>
>
> *VTP File Content:*
>
>
> <?xml version="1.0"?>
> <VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" 
> compressor="vtkZLibDataCompressor">
>   <PolyData>
>     <Piece NumberOfPoints="3"                    
> NumberOfVerts="3"                    
> NumberOfLines="0"                    
> NumberOfStrips="0"                    
> NumberOfPolys="0"                   >
>       <PointData>
>       </PointData>
>       <CellData>
>       </CellData>
>       <Points>
>         <DataArray type="Float32" Name="Points" NumberOfComponents="3" 
> format="appended" RangeMin="0"                    
> RangeMax="1"                    offset="0"                   />
>       </Points>
>       <Verts>
>         <DataArray type="Int64" Name="connectivity" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="48"                  />
>         <DataArray type="Int64" Name="offsets" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="108"                 />
>       </Verts>
>       <Lines>
>         <DataArray type="Int64" Name="connectivity" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="156"                 />
>         <DataArray type="Int64" Name="offsets" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="172"                 />
>       </Lines>
>       <Strips>
>         <DataArray type="Int64" Name="connectivity" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="188"                 />
>         <DataArray type="Int64" Name="offsets" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="204"                 />
>       </Strips>
>       <Polys>
>         <DataArray type="Int64" Name="connectivity" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="220"                 />
>         <DataArray type="Int64" Name="offsets" format="appended" 
> RangeMin=""                     RangeMax=""                     
> offset="236"                 />
>       </Polys>
>     </Piece>
>   </PolyData>
>   <AppendedData encoding="base64">
>    
> _AQAAAACAAAAkAAAAEAAAAA==eJxjYGiwZ8AJIHIAHX4Bfw==AQAAAACAAAAwAAAAGQAAAA==eJxjYICAFXqXL8XXM8ABIwMqgPEBffcDXA==AQAAAACAAAAYAAAAEAAAAA==eJxjYoAAFijNBqUBALgADQ==AAAAAACAAAAAAAAAAAAAAACAAAAAAAAAAAAAAACAAAAAAAAAAAAAAACAAAAAAAAAAAAAAACAAAAAAAAAAAAAAACAAAAAAAAA
>   </AppendedData>
> </VTKFile>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   




More information about the vtkusers mailing list