[vtkusers] can't move nodes and make plane cut at the same time on structured mesh

Mario Storti mario.storti at gmail.com
Sun Jan 4 18:41:59 EST 2009


Hi VTK-users!!

I'm a newbie to VTK. I started some days ago, and I'm trying to do
some examples by myself. My present goal is to visualize FEM (Finite
Element Method, i.e. unstructured) meshes. As the mesh is 3D I'm
interested in performing a PLANE CUT of the mesh. Also the mesh are of
variable geometry, i.e. I have the same topology (a.k.a. connectivity
in FEM terminology) for the tetra mesh but the coordinates of the mesh
varies. In fact my goal is to see the mesh for the combustion
chamber of a four stroke Internal Combustion Engine. Then I have a
FIXED topology/connectivity for each of the stages (admission,
compression/combustion and exhaust) but inside each stage the position
of the nodes changes with crank angle.

To simplify things, assume that I have a FIXED TOPOLOGY and MOVING
node (points) COORDINATES.

The problem is: I am not able to figure out how to make the
visualization of the mesh for MOVING NODES and with a PLANE CUT of the
mesh at the same time.

So far I was able to

a) Read a FIXED MESH (no moving coordinates) and perform a PLANE CUT
  (with vtkCutter), even with a plane that was moving in time. (This
  was written in C++.)

b) To make a MOVING MESH without the cut. (This one was written in
  Python).

In a) I started with creating a small mesh (vtkUnstructuredGrid,
composed of one single Wedge element) and moving one of the nodes of
the wedge.  (See below the code `simple3.py' for reference). The
process is `canonical'

   grid -> mapper -> actor -> renderer

Then the coordinate of a node is changed in a loop and set the flag of
the grid as Modified(). This works as expected. In addition I have a
rotating camera. I can see the wedge with one of the nodes moving.

Then I tried to add the PLANE CUT. Basically I added the following code

    plane = vtk.vtkPlane()
    plane.SetOrigin(0,0,0)
    plane.SetNormal(1,0,0)

    cutter = vtk.vtkCutter()
    cutter.SetInput(ugrid)
    cutter.SetCutFunction(plane);
    cutter.Update()

    ugmapper = vtk.vtkDataSetMapper()
    ugmapper.SetInputConnection(cutter.GetOutputPort())
    ugmapper.ScalarVisibilityOff()

    ugactor = vtk.vtkActor()
    ugactor.SetMapper(ugmapper)

    prop = ugactor.GetProperty()
    prop.SetRepresentationToWireframe()
    prop.SetColor(1,1,1)

(Complete code is in simple3c.py below).

The problem is: the code runs but NOTHING IS SHOWN. I tried other
variants as, for instance,  making a ProgrammableSource(), but also
without success.

Any hint is welcome!! TIA and KUDOS for the VTK team!!

Mario


-------------- cut "single3.py" cut ------------------------------
#!/usr/bin/env python

# DOES MOVING MESH
# DOESN'T INCLUDE CODE TO MAKE THE PLANE CUT

import vtk
import time

# Create grid
points = vtk.vtkPoints()
points.SetNumberOfPoints(6)
points.InsertPoint(0, 0, 1, 0)
points.InsertPoint(1, 0, 0, 0)
points.InsertPoint(2, 0, .5, .5)
points.InsertPoint(3, 1, 1, 0)
points.InsertPoint(4, 1, 0, 0)
points.InsertPoint(5, 1, .5, .5)

wedge = vtk.vtkWedge()
wedge.GetPointIds().SetId(0, 0)
wedge.GetPointIds().SetId(1, 1)
wedge.GetPointIds().SetId(2, 2)
wedge.GetPointIds().SetId(3, 3)
wedge.GetPointIds().SetId(4, 4)
wedge.GetPointIds().SetId(5, 5)

ugrid = vtk.vtkUnstructuredGrid()
ugrid.Allocate(1, 1)
ugrid.InsertNextCell(wedge.GetCellType(), wedge.GetPointIds())
ugrid.SetPoints(points)

# Create mapper
ugmapper = vtk.vtkDataSetMapper()
ugmapper.SetInput(ugrid)

# Create actor
ugactor = vtk.vtkActor()
ugactor.SetMapper(ugmapper)
ugactor.AddPosition(6, 0, 0)
ugactor.GetProperty().SetDiffuseColor(0, 1, 1)

# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 150)

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

# Initialize camera
ren.ResetCamera()
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(20)
ren.ResetCameraClippingRange()

# Render the scene
renWin.Render()

# Loop while: rotating the camera and modify
# node coordinates
y = 1
ady = 0.05
dy = -ady
while 1:
    time.sleep(0.03)
    renWin.Render()
    # Update node coordinate
    y += dy
    if y<0.1:
        dy = +ady
    if y>2:
        dy = -ady
    points.SetPoint(0, 0, y, 0)
    # Set Grid object as modified
    ugrid.Modified()
    # Rotate camera
    ren.GetActiveCamera().Azimuth( 1 )
-------------- cut "single3.py" cut ------------------------------

-------------- cut "single3c.py" cut ------------------------------
#!/usr/bin/env python

# DOES MOVING MESH
# DOES INCLUDE CODE TO MAKE THE PLANE CUT
# BUT IT DOESN'T WORK

import vtk
import time

# Create grid
points = vtk.vtkPoints()
points.SetNumberOfPoints(6)
points.InsertPoint(0, 0, 1, 0)
points.InsertPoint(1, 0, 0, 0)
points.InsertPoint(2, 0, .5, .5)
points.InsertPoint(3, 1, 1, 0)
points.InsertPoint(4, 1, 0, 0)
points.InsertPoint(5, 1, .5, .5)

wedge = vtk.vtkWedge()
wedge.GetPointIds().SetId(0, 0)
wedge.GetPointIds().SetId(1, 1)
wedge.GetPointIds().SetId(2, 2)
wedge.GetPointIds().SetId(3, 3)
wedge.GetPointIds().SetId(4, 4)
wedge.GetPointIds().SetId(5, 5)

ugrid = vtk.vtkUnstructuredGrid()
ugrid.Allocate(1, 1)
ugrid.InsertNextCell(wedge.GetCellType(), wedge.GetPointIds())
ugrid.SetPoints(points)

plane = vtk.vtkPlane()
plane.SetOrigin(0,0,0)
plane.SetNormal(1,0,0)

cutter = vtk.vtkCutter()
cutter.SetInput(ugrid)
cutter.SetCutFunction(plane);
cutter.Update()

ugmapper = vtk.vtkDataSetMapper()
ugmapper.SetInputConnection(cutter.GetOutputPort())
ugmapper.ScalarVisibilityOff()

ugactor = vtk.vtkActor()
ugactor.SetMapper(ugmapper)

prop = ugactor.GetProperty()
prop.SetRepresentationToWireframe()
prop.SetColor(1,1,1)

# Create actor
ugactor = vtk.vtkActor()
ugactor.SetMapper(ugmapper)
ugactor.AddPosition(6, 0, 0)
ugactor.GetProperty().SetDiffuseColor(0, 1, 1)

# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 150)

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

# Initialize camera
ren.ResetCamera()
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(20)
ren.ResetCameraClippingRange()

# Render the scene
renWin.Render()

# Loop while: rotating the camera and modify
# node coordinates
y = 1
ady = 0.05
dy = -ady
while 1:
    time.sleep(0.03)
    renWin.Render()
    # Update node coordinate
    y += dy
    if y<0.1:
        dy = +ady
    if y>2:
        dy = -ady
    points.SetPoint(0, 0, y, 0)
    # Set Grid object as modified
    ugrid.Modified()
    # Rotate camera
    ren.GetActiveCamera().Azimuth( 1 )
-------------- cut "single3c.py" cut ------------------------------


-- 
-------------------------
Mario Alberto Storti
Centro Internacional de Metodos Computacionales
  en Ingenieria - CIMEC (INTEC/CONICET-UNL)
INTEC, Guemes 3450 - 3000 Santa Fe, Argentina
Tel/Fax: +54-342-4511594, cel: +54-342-156144983
e-mail: mario.storti at gmail.com
http://www.cimec.org.ar/mstorti http://www.cimec.org.ar
-------------------------



More information about the vtkusers mailing list