[vtkusers] "Solid" polyhedron

Jens K. Becker becker at jkbecker.de
Tue Feb 17 10:02:09 EST 2009


Hi all,

I have tried using the approach with a 3D delaunay tirangulation, and I
can now display polyhedra as a volume. But I can not clip it. I have
copied together a small program (see below) that shows how I tried to do
it. I have no idea why I can not clip it using the box-widget, could
somebody let me know where I am going wrong (or what I am missing)? That
would be super!

Thanks in advance,

Jens

CODE:

import vtk

points = vtk.vtkPoints()

points.InsertPoint(0,0,0,0)
points.InsertPoint(1,1000,0,0)
points.InsertPoint(2,0,1000,0)
points.InsertPoint(3,1000,1000,0)
points.InsertPoint(4,0,0,1000)
points.InsertPoint(5,1000,0,1000)
points.InsertPoint(6,0,1000,1000)
points.InsertPoint(7,1000,1000,1000)


profile = vtk.vtkPolyData()
profile.SetPoints(points)

FacetID = vtk.vtkIntArray()

for x in range(0,160):
	FacetID.InsertNextValue(x)


profile.GetCellData().SetScalars(FacetID)
profile.GetPointData().SetScalars(FacetID)


# Delaunay3D is used to triangulate the points. The Tolerance is the
# distance that nearly coincident points are merged
# together. (Delaunay does better if points are well spaced.) The
# alpha value is the radius of circumcircles, circumspheres. Any mesh
# entity whose circumcircle is smaller than this value is output.
delny = vtk.vtkDelaunay3D()
delny.SetInput(profile)
delny.SetTolerance(0.01)
#delny.SetAlpha(0.2)
#delny.BoundingTriangulationOff()


# Create transfer mapping scalar value to opacity
opacityTransferFunction=vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(0,0.0)
opacityTransferFunction.AddPoint(160,255.0)

# Create transfer mapping scalar value to color
colorTransferFunction=vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0)
colorTransferFunction.AddRGBPoint(1.0,0.0,0.0,1.0)
colorTransferFunction.AddRGBPoint(160.0,1.0,1.0,1.0)

volumeProperty=vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationTypeToLinear()

volumeMapper=vtk.vtkUnstructuredGridVolumeRayCastMapper()
volumeMapper.SetInputConnection(delny.GetOutputPort())


# The volume holds the mapper and the property and
# can be used to position/orient the volume
volume=vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)


# Create the RenderWindow, Renderer and both Actors
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)


# When interaction starts, the requested frame rate is increased.
def StartInteraction(obj, event):
    global renWin
    renWin.SetDesiredUpdateRate(10)

# When interaction ends, the requested frame rate is decreased to
# normal levels. This causes a full resolution render to occur.
def EndInteraction(obj, event):
    global renWin
    renWin.SetDesiredUpdateRate(0.001)

# The implicit function vtkPlanes is used in conjunction with the
# volume ray cast mapper to limit which portion of the volume is
# volume rendered.
planes = vtk.vtkPlanes()
def ClipVolumeRender(obj, event):
    global planes, volumeMapper
    obj.GetPlanes(planes)
    volumeMapper.SetClippingPlanes(planes)

# The SetInteractor method is how 3D widgets are associated with the
# render window interactor.  Internally, SetInteractor sets up a bunch
# of callbacks using the Command/Observer mechanism (AddObserver()).
boxWidget = vtk.vtkBoxWidget()
boxWidget.SetInteractor(iren)
boxWidget.SetInput(delny.GetOutput())
boxWidget.SetPlaceFactor(2.0)
boxWidget.PlaceWidget()
boxWidget.InsideOutOn()
boxWidget.AddObserver("StartInteractionEvent", StartInteraction)
boxWidget.AddObserver("InteractionEvent", ClipVolumeRender)
boxWidget.AddObserver("EndInteractionEvent", EndInteraction)

outlineProperty = boxWidget.GetOutlineProperty()
outlineProperty.SetRepresentationToWireframe()
outlineProperty.SetColor(0,0,0)
outlineProperty.SetLineWidth(5)

# Add the actors to the renderer, set the background and size
ren.AddVolume(volume)
renWin.AddRenderer(ren)
ren.SetBackground(1, 1, 1)
renWin.SetSize(400, 400)

iren.Initialize()
renWin.Render()
iren.Start()


On Thu, 2009-02-05 at 09:45 -0500, David E DeMarle wrote:
> vtkPolyData can only represent the external surfaces, because it can
> only contain 2D cell types, such as triangle.
> 
> vtkUnstructuredGrid can represent the internal volume as well, because
> it can contain 3D cell types, such a tetrahedra.
> 
> You can use the Delauney filters to create 2D or 3D cells out of a set
> of points.
> 
> 
> On Wed, Feb 4, 2009 at 8:05 AM, Jens K. Becker <becker at jkbecker.de> wrote:
> > Hi all,
> >
> > I have a polyhedron that I can display using vtk. The polyhedron is
> > essentially defined by vertices that define triangluar facets which make
> > up the outer shell of it. I use vtk to display the outer shell, the
> > different vertices (as spheres) and edges of facets (as tubes). But it
> > is only the outer shell that is displayed, the polyhedra are hollow. How
> > can I color the whole polyhedron? I dont even know where to start
> > looking to achieve this. Eveything I read about creating volumes does
> > not apply to the kind of data I have (which essentially are the
> > coordinates of vertices in 3D and which vertex belongs to which facet).
> > Any help and hints are welcome!
> >
> > Greetings,
> > Jens
> >
> > --
> > Dr. J.K. Becker
> > University of Tuebingen - Institute for Geoscience
> > Sigwartst. 10 - 72076 Tuebingen (Germany)
> > Tel.: ++49 7071 29 73139   Fax: +49 7071 5059
> > Web: http://www.jkbecker.de
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> 
> 
> 
-- 
Dr. J.K. Becker
University of Tuebingen - Institute for Geoscience
Sigwartst. 10 - 72076 Tuebingen (Germany)
Tel.: ++49 7071 29 73139   Fax: +49 7071 5059
Web: http://www.jkbecker.de




More information about the vtkusers mailing list