[vtkusers] directly adding elements to unstructured grids... extension to mo re than one

Roberson, Kyle Kyle_Roberson at duratekinc.com
Mon Apr 14 12:20:58 EDT 2003


I'm trying to make unstructured grids out of various ABAQUS elements. I can
successfully make a picture of the model by making an unstructured grid for
EACH element and turning it into an independent actor. I would like to put
several elements into each unstructured grid and turn that into an actor to
make my subsequent manipulations easier to handle. However, I havent figured
out how to do that. When I add more than one to the unstructured grid, no
graphics come out the other end.

Here's what I'm doing now (in Python). Only two types of elements are in to
save space.

Cheers,
Kyle


# Create the usual rendering stuff.

ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(1280, 1024)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.SetBackground(.1, .2, .4)

# Use the brute-force method to make an actor for each thing


for k,v in elem.items() :

    if v[0] == "S3R" :

        thingPoints = vtk.vtkPoints()
        thingPoints.SetNumberOfPoints(3)
        thingPoints.InsertPoint(0, node[v[2]][0], node[v[2]][1],
node[v[2]][2])
        thingPoints.InsertPoint(1, node[v[3]][0], node[v[3]][1],
node[v[3]][2])
        thingPoints.InsertPoint(2, node[v[4]][0], node[v[4]][1],
node[v[4]][2])


        aThing = vtk.vtkTriangle()
        aThing.GetPointIds().SetId(0, 0)
        aThing.GetPointIds().SetId(1, 1)
        aThing.GetPointIds().SetId(2, 2)

        aThingGrid = vtk.vtkUnstructuredGrid()
        aThingGrid.Allocate(1, 1)
        aThingGrid.InsertNextCell(aThing.GetCellType(),\
                                       aThing.GetPointIds())
        aThingGrid.SetPoints(thingPoints)


        aThingMapper = vtk.vtkDataSetMapper()
        aThingMapper.SetInput(aThingGrid)
        aThingActor = vtk.vtkActor()
        aThingActor.SetMapper(aThingMapper)
        aThingActor.GetProperty().SetDiffuseColor(1, 1, 0)
        # aThingActor.GetProperty().SetOpacity(0.15)


        aThingActor.GetProperty().SetRepresentationToWireframe()

        ren.AddActor(aThingActor)

    elif v[0] == "S4R" :
        thingPoints = vtk.vtkPoints()
        thingPoints.SetNumberOfPoints(4)
        thingPoints.InsertPoint(0, node[v[2]][0], node[v[2]][1],
node[v[2]][2])
        thingPoints.InsertPoint(1, node[v[3]][0], node[v[3]][1],
node[v[3]][2])
        thingPoints.InsertPoint(2, node[v[4]][0], node[v[4]][1],
node[v[4]][2])
        thingPoints.InsertPoint(3, node[v[5]][0], node[v[5]][1],
node[v[5]][2])

        aThing = vtk.vtkQuad()
        aThing.GetPointIds().SetId(0, 0)
        aThing.GetPointIds().SetId(1, 1)
        aThing.GetPointIds().SetId(2, 2)
        aThing.GetPointIds().SetId(3, 3)

        aThingGrid = vtk.vtkUnstructuredGrid()
        aThingGrid.Allocate(1, 1)
        aThingGrid.InsertNextCell(aThing.GetCellType(),\
                                       aThing.GetPointIds())
        aThingGrid.SetPoints(thingPoints)


        aThingMapper = vtk.vtkDataSetMapper()
        aThingMapper.SetInput(aThingGrid)
        aThingActor = vtk.vtkActor()
        aThingActor.SetMapper(aThingMapper)
        aThingActor.GetProperty().SetDiffuseColor(1, 1, 0)
        #    aThingActor.GetProperty().SetOpacity(0.15)


        aThingActor.GetProperty().SetRepresentationToWireframe()

        ren.AddActor(aThingActor)
        
# ... several more for different elements elided ...

# Render the scene and start interaction.

iren.Initialize()
renWin.Render()
iren.Start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030414/610f682e/attachment.htm>


More information about the vtkusers mailing list