[vtkusers] 3D point to UnstructuredGrid‏

Meehan, Bernard MEEHANBT at nv.doe.gov
Tue Sep 2 11:41:54 EDT 2014


Hi -

First, there are a lot of things you are asking about in your email:
1) create vtkUnstructuredGrid from a collection of points
2) extracting points that exceed a given threshold
3) meshing the points

The meshing of the points can probably be done with a vtkDelaunay3D filter, and the rest of it I will describe - but in general the more specific you can be about your problem, the more likely it is that you will find answers. I'd also point you to the examples page on the wiki: http://www.vtk.org/Wiki/VTK/Examples, there are examples of how to do almost everything that you might want.

So, a partial answer to your question (at least as I was able to see it - Python source follows):

# First comment - is that all of this can easily be done in ParaView, however,
# it is easier for me to show this to you in a Python script than for me to
# describe what to click on in ParaView. Unless you have to go through piles of
# data - you should probably figure out how to do this in ParaView.

import random, vtk

points = vtk.vtkPoints()
temperature = vtk.vtkDoubleArray()
temperature.SetName("Temperature")

# Set up your array of random points, random temperature samples.
for i in range(5000):
  points.InsertPoint(i, random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1))
  temperature.InsertNextValue(random.weibullvariate(1, 5))

print temperature.GetMaxNorm()

# The situation you described did not necessarily require a
# vtkUnstructuredGrid, you could have also done it with a vtkPolyData. However,
# adding points and their associated temperature samples to a
# vtkUnstructuredGrid is straightforward.
ugrid = vtk.vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.GetPointData().SetScalars(temperature)

# Here, I am going to select points that have an associated temperature value
# that is greater than 1.0:
ugrid_thresh = vtk.vtkThresholdPoints()
ugrid_thresh.SetInputData(ugrid)
ugrid_thresh.ThresholdByUpper(1.0)
# Depending on what you're doing with the thresholded dataset, you may need to
# call "Update" on it to make sure that the data is ready to use.
ugrid_thresh.Update()

# All you have is points in your vtkUnstructuredGrid, so you will need to do
# something to see the structure in your data. The data I have created has sort
# of a messy structure though. Below, the vtkVertexGlyph filters are set up
# differently because in the first case, you are using the data itself to start
# the pipeline - in the second case, you are using the output of a filter to
# feed the input of the next filter.
before_glyph = vtk.vtkVertexGlyphFilter()
before_glyph.SetInputData(ugrid)

after_glyph = vtk.vtkVertexGlyphFilter()
after_glyph.SetInputConnection(ugrid_thresh.GetOutputPort())

# I'm using a vtkOutlineFilter here mostly to make the data look nicer. This
# isn't strictly necessary for any of the parts of your question.
outline = vtk.vtkOutlineFilter()
outline.SetInputData(ugrid)

#-----------------#
# Rendering Stuff #
#-----------------#
# The unstructured grid by itself doesn't have much interesting to look at
# inside of it, but if you were to change that, you would need a different
# mapper:
# umapper = vtk.vtkDataSetMapper()
# umapper.SetInputData(ugrid)

before_mapper = vtk.vtkPolyDataMapper()
before_mapper.SetInputConnection(before_glyph.GetOutputPort())

after_mapper = vtk.vtkPolyDataMapper()
after_mapper.SetInputConnection(after_glyph.GetOutputPort())

# If you are re-using data or filter outputs in the visualization pipeline,
# avoid re-using mappers and actors. Since I'm showing a before and after
# scenario as a left and right image, I will need two mappers and two actors to
# represent the outline.
outline_mapper1 = vtk.vtkPolyDataMapper()
outline_mapper1.SetInputConnection(outline.GetOutputPort())

outline_mapper2 = vtk.vtkPolyDataMapper()
outline_mapper2.SetInputConnection(outline.GetOutputPort())

outline_actor1 = vtk.vtkActor()
outline_actor1.SetMapper(outline_mapper1)

outline_actor2 = vtk.vtkActor()
outline_actor2.SetMapper(outline_mapper2)

before_actor = vtk.vtkActor()
before_actor.SetMapper(before_mapper)

after_actor = vtk.vtkActor()
after_actor.SetMapper(after_mapper)

left_ren = vtk.vtkRenderer()
left_ren.SetBackground(.3, .3, .3)
left_ren.SetViewport(0.0, 0.0, 0.5, 1.0)
left_ren.AddActor(before_actor)
left_ren.AddActor(outline_actor1)

right_ren = vtk.vtkRenderer()
right_ren.SetBackground(.3, .3, .3)
right_ren.SetViewport(0.5, 0.0, 1.0, 1.0)
# This line links the cameras for the two renderers so that manipulating the
# view in one viewport manipulates the view in both viewports.
right_ren.SetActiveCamera(left_ren.GetActiveCamera())
right_ren.AddActor(after_actor)
right_ren.AddActor(outline_actor2)

renw = vtk.vtkRenderWindow()
renw.AddRenderer(left_ren)
renw.AddRenderer(right_ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renw)

left_ren.ResetCamera()
renw.Render()
iren.Start()

From: Selcuk ÇALLI <selcukcalli at gmail.com<mailto:selcukcalli at gmail.com>>
Date: Tuesday, September 2, 2014 6:53 AM
To: "vtkusers at vtk.org<mailto:vtkusers at vtk.org>" <vtkusers at vtk.org<mailto:vtkusers at vtk.org>>
Subject: [vtkusers] 3D point to UnstructuredGrid‏

Can we obtain an UnstructuredGrid from 3D point array with values that exceed a threshold? I want to apply mesh to 3D point array. Is it possible? What kind of filters/functions do we need to do this process?

Best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140902/dc4e8b6c/attachment.html>


More information about the vtkusers mailing list