[vtkusers] programmable source multiple hexahedrons in unstructured grid

Favre Jean jfavre at cscs.ch
Mon Feb 22 15:49:15 EST 2016


I don't know the details of your app, but you should follow the following schema
I'll assume for simplicity, that the hexahedra do not share any vertices with any other hexahedra
if they do, then you need to figure out how to avoid replicating points.

# use "output", as the pre-defined vtkUnstructuredGrid created for you
# create a single vtkPoints and add all vertices to it
# if you have N hexahedra, you'll add 8xN points
# create a single vtkDoubleArray of size N
# offset the indices of each hexahedra by 8

    points = vtk.vtkPoints()

    #Create the attribute
    NodeLength = vtk.vtkDoubleArray()
    NodeLength.SetName('Node lenght')
    I=0
    for  materialpath, x , y , z , leafsize in octree:
        # create the coordinates for the points
        l = .5*leafsize
        xL = int(x)-l
        xR = int(x)+l
        yL = int(y)-l
        yR = int(y)+l
        zL = int(z)-l
        zR = int(z)+l

        points.InsertNextPoint(xL, yL, zL)
        points.InsertNextPoint(xR, yL, zL)
        points.InsertNextPoint(xR, yR, zL)
        points.InsertNextPoint(xL, yR, zL)
        points.InsertNextPoint(xL, yL, zR)
        points.InsertNextPoint(xR, yL, zR)
        points.InsertNextPoint(xR, yR, zR)
        points.InsertNextPoint(xL, yR, zR)

        # Create a hexahedron from the points
        hex_ = vtk.vtkHexahedron()
        for i in range(0, numberOfVertices):
            hex_.GetPointIds().SetId(i, 8*I+i)

        NodeLength.InsertNextValue(leafsize)

        # Add the geometry to the unstructured grid
        output.InsertNextCell(hex_.GetCellType(), hex_.GetPointIds())
        I = I +1

    # Add the points and hexahedron to an unstructured grid
    output.Points = points
    output.CellData.SetScalars(NodeLength)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160222/6aefdedf/attachment.html>


More information about the vtkusers mailing list