[vtkusers] data for 3D surface - script

Malcolm Drummond malcolm at geovision.co.za
Fri Jul 1 14:08:49 EDT 2005


Here's the script I knocked together several years ago, hacked a bit to work with 4.2. If you play around with the shepard filter parameters you should get something much better. Also keep in mind that I'm using randomized values here - so the dataset is unrealistically spikey.

If you have directional bias you'll either have to do some research into other algorithms or use a commercial package like Surfer for interploation. 

HTH
Malcolm Drummond

# ------------------------------------------------------
package require vtk

# Create the RenderWindow, Renderer and both Actors
#
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin


set res 50
# ------------------------------------------------------
# create some points - this would be read in 
#
vtkMath math
vtkPoints points
for {set i 0} {$i<50} {incr i 1} {
    eval points InsertPoint $i [math Random 0 1] [math Random 0 1] [math Random 0 0.25]
}

vtkPolyData pd
    pd SetPoints points

# ------------------------------------------------------
# you start here
#
vtkElevationFilter elev
 elev SetInput pd

# reset z to 0.0 for shepard method
vtkTransform transform
 transform Scale 1.0 1.0 0.0
vtkTransformPolyDataFilter tpf
 tpf SetInput [elev GetOutput]
 tpf SetTransform transform

# filter requires domensions to be a volume - use min z dimension (2)
# make sure bottom layer is at 0.0 elevation
vtkShepardMethod shepard
 shepard SetInput [tpf GetOutput]
 shepard SetModelBounds 0 1 0 1 0.0 0.1
 shepard SetMaximumDistance 0.75
 shepard SetSampleDimensions $res $res 2
 shepard Update

# extract bottom layer
vtkExtractVOI voi
 voi SetInput [shepard GetOutput]
 voi SetVOI 0 $res 0 $res 0 0

vtkGeometryFilter gf
 gf SetInput [voi GetOutput]
vtkWarpScalar ws
 ws SetInput [gf GetOutput]

vtkDataSetMapper map
    map SetInput [ws GetOutput]

vtkActor block
    block SetMapper map

# glyph original points
vtkSphereSource ss
 ss SetRadius 0.025

vtkGlyph3D g3d
 g3d SetInput pd
 g3d SetSource [ss GetOutput]

vtkPolyDataMapper pdm
 pdm SetInput [g3d GetOutput]

vtkActor glyphs
 glyphs SetMapper pdm

# Add the actors to the renderer, set the background and size
ren1 AddActor block
ren1 AddActor glyphs
ren1 SetBackground 1 1 1
renWin SetSize 500 500

set cam1 [ren1 GetActiveCamera]
#$cam1 Azimuth 160
$cam1 Roll 60
$cam1 Elevation -45
#$cam1 Azimuth 135
$cam1 Zoom 1.5
ren1 ResetCameraClippingRange

renWin Render

wm withdraw .

  ----- Original Message ----- 
  From: Doug Henry 
  To: Malcolm Drummond 
  Cc: vtkusers 
  Sent: Thursday, June 30, 2005 10:26 PM
  Subject: Re: [vtkusers] data for 3D surface


  thanks, code is always helpful if its easy for you to find, otherwise I'll figure it out.  I'm always looking for different ways to do things with vtk, sometimes the code that doesn't solve the immediate problem will teach me something I can use later.  Stringing filters together to tweak data in the pipeline seems easy in vtk.  I don't quite have my hands around how to get my data in to a useable form by vtk yet, but I imagine (or hope) the light will turn on eventually.

  -thanks again



  On 6/30/05, Malcolm Drummond <malcolm at geovision.co.za> wrote:
    Hi Doug

    I'd convert your data into x,y,z then run it through vtkDelaunay2D (which just uses x and y for the triangulation). This will give you a triangulated mesh as vtkPolyData output. The points do not need to be regular.

    If you want a regular grid you could convert the z values to scalars with vtkElevation filter and resample with vtkShepardMethod. I did this a long, long time ago but could probably dig out some demo code if you want it.

    HTH
    Malcolm Drummond
    GeoVision cc
      ----- Original Message ----- 
      From: Doug Henry 
      To: VTK 
      Sent: Thursday, June 30, 2005 2:46 PM
      Subject: [vtkusers] data for 3D surface


      I am looking to make a surface plot similar to matlab's surf function.  I have location (az,el) and magnitude data, which can easily be turned in to x,y,z data if needed, and I would like to create a simple surface (mesh) from this data.  What options are available for doing this?  Do I need data at regular intervals, I saw reference to structured and unstructured grids.

      -thanks




--------------------------------------------------------------------------


      _______________________________________________
      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



    _______________________________________________
    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 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050701/eef94ca8/attachment.htm>


More information about the vtkusers mailing list