[vtk-developers] How to extract a part defined by closed points inside a unstructured Grid Surface
darkcminor
darkcminor at gmail.com
Mon Feb 24 00:17:11 EST 2014
I want to extract a part of a surface defined here by red points, in fact it
is a closed contour (What I want is to get a piece of cake defined by
contour)
I have this:
<http://vtk.1045678.n5.nabble.com/file/n5726086/have.png>
To get taht The current code is
/package require vtk
# Create a reader to read the unstructured grid data. We use a
# vtkDataSetReader which means the type of the output is unknown until
# the data file is read.
vtkDEMReader reader
reader SetFileName "$VTK_DATA_ROOT/Data/SainteHelens.dem"
reader Update
puts "Dataset reader actual memory: [[reader GetOutput]
GetActualMemorySize]"
puts "Dataset reader no of points: [[reader GetOutput]
GetNumberOfPoints]"
set lo [lindex [[reader GetOutput] GetScalarRange] 0]
set hi [lindex [[reader GetOutput] GetScalarRange] 1]
# Get the physical xy extent of dataset
scan [[reader GetOutput] GetWholeExtent] "%d %d %d %d %d %d" XminR XmaxR
YminR YmaxR ZminR ZmaxR
puts "Physical extent of dataset: $XminR $XmaxR $YminR $YmaxR $ZminR $ZmaxR"
# trims off points with no data (value -9999) in DEMS converted
# from ASCII arc grid files. This step could be used to crop the data
# at another elevation by changing the threshold value
vtkThreshold cropped
cropped SetInput [reader GetOutput]
cropped ThresholdByUpper -9998; # threshold value
cropped Update
puts "Threshold filter no of cells : [[cropped GetOutput]
GetNumberOfCells]"
puts "Threshold filter no of points: [[cropped GetOutput]
GetNumberOfPoints]"
# Create the geometry conneting the grid of location points
# at this point the surface is flat with an x-y grid of numbers
# (scalars) representing elevations
vtkGeometryFilter geom
geom SetInput [cropped GetOutput]
geom Update
puts "Geometry filter no of cells : [[geom GetOutput] GetNumberOfCells]"
puts "Geometry filter no of points: [[geom GetOutput] GetNumberOfPoints]"
# Now warp the surface based on the scalar elevation values
# This creates the 3D mesh model of the terrain.
vtkWarpScalar surface
surface SetInput [geom GetOutput]
surface SetScaleFactor 1; # $scale variable controls vertical exaggeration
surface Update
#surface UseNormalOn
#surface SetNormal 0 0 1
puts "Warp scalar no of cells : [[surface GetOutput] GetNumberOfCells]"
puts "Warp scalar no of points: [[surface GetOutput] GetNumberOfPoints]"
# Map dataset to graphics primitives
#
vtkDataSetMapper demMapper
demMapper SetInputConnection [surface GetOutputPort]
demMapper ScalarVisibilityOff; # This prevents surface being colored based
on scalar value
#
===========================================================================
# Create actor for surface topogrpahy
#
===========================================================================
vtkLODActor demActor
demActor SetMapper demMapper
[demActor GetProperty] SetInterpolationToGouraud
[demActor GetProperty] SetRepresentationToSurface
#
===========================================================================
# Create projected terrain path
#
===========================================================================
# Create some paths
vtkPoints pts
pts InsertNextPoint 562669 5.1198e+006 1992.77
pts InsertNextPoint 562100 5.1170e+006 1900.77
pts InsertNextPoint 562850 5.11181e+006 1912.57
pts InsertNextPoint 562659 5.1198e+006 1992.77
vtkCellArray lines
lines InsertNextCell 4
lines InsertCellPoint 0
lines InsertCellPoint 1
lines InsertCellPoint 2
lines InsertCellPoint 3
vtkPolyData terrainPaths
terrainPaths SetPoints pts
terrainPaths SetLines lines
vtkProjectedTerrainPath projectedPaths
projectedPaths SetInput terrainPaths
projectedPaths SetSource [reader GetOutput]
projectedPaths SetHeightOffset 25
projectedPaths SetHeightTolerance 5
projectedPaths SetProjectionModeToNonOccluded
projectedPaths SetProjectionModeToHug
projectedPaths Update
puts "Projected path filter no of cells : [[projectedPaths GetOutput]
GetNumberOfCells]"
#vtkPolyDataMapper pathMapper
# pathMapper SetInputConnection [projectedPaths GetOutputPort]
vtkTubeFilter pathTube
pathTube SetNumberOfSides 8
pathTube SetInputConnection [projectedPaths GetOutputPort]
pathTube SetRadius 10
vtkPolyDataMapper pathTubeMapper
pathTubeMapper SetInputConnection [pathTube GetOutputPort]
vtkActor pathActor
pathActor SetMapper pathTubeMapper
[pathActor GetProperty] SetColor 1 0 0
[pathActor GetProperty] SetSpecular .3
[pathActor GetProperty] SetSpecularPower 30
#
===========================================================================
# Create a cell picker
#
===========================================================================
# Create a cell picker.
vtkCellPicker picker
picker AddObserver EndPickEvent annotatePick
# Create a text mapper and actor to display the results of picking.
vtkTextMapper textMapper
set tprop [textMapper GetTextProperty]
$tprop SetFontFamilyToArial
$tprop SetFontSize 10
$tprop BoldOn
$tprop ShadowOn
$tprop SetColor 1 0 0
vtkActor2D textActor
textActor VisibilityOff
textActor SetMapper textMapper
#
===========================================================================
# Create renderer, render window and add actors to the renderer
#
===========================================================================
# Create the RenderWindow, Renderer and both Actors
#
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
iren SetPicker picker
# Add the actors to the renderer, set the background and size
#
ren1 AddActor demActor
ren1 AddActor pathActor
ren1 AddActor2D textActor
#ren1 AddActor probeActor
ren1 SetBackground .1 .2 .4
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren SetDesiredUpdateRate 5
ren1 ResetCamera
ren1 ResetCameraClippingRange
renWin Render
wm withdraw .
# Create a Tcl procedure to create the text for the text mapper used to
# display the results of picking.
proc annotatePick {} {
if { [picker GetCellId] < 0 } {
textActor VisibilityOff
} else {
set selPt [picker GetSelectionPoint]
set x [lindex $selPt 0]
set y [lindex $selPt 1]
set pickPos [picker GetPickPosition]
set xp [lindex $pickPos 0]
set yp [lindex $pickPos 1]
set zp [lindex $pickPos 2]
textMapper SetInput "($xp, $yp, $zp)"
textActor SetPosition $x $y
textActor VisibilityOn
}
renWin Render
}/
Now I was taking a look at vtkExtractGrid, however as surface is no
structured grid I do not know how to extract a part of the surface,
I was trying
/vtkExtractGrid extract
extract SetVOI 1 55 -1000 1000 -1000 1000
extract SetInputData #pass reader Output as surface?
vtkPlane plane
plane SetOrigin 0 4 2
plane SetNormal 0 1 0
vtkCutter cutter
cutter SetInputConnection [extract GetOutputPort]
cutter SetCutFunction plane
cutter GenerateCutScalarsOff
cutter SetSortByToSortByCell
vtkLookupTable clut
clut SetHueRange 0 .67
clut Build
vtkPolyDataMapper cutterMapper
cutterMapper SetInputConnection [cutter GetOutputPort]
cutterMapper SetScalarRange .18 .7
cutterMapper SetLookupTable clut
vtkActor cut
cut SetMapper cutterMapper
/
Could you please suggest an idea on how to extract or cut this surface
defined by contour?
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-extract-a-part-defined-by-closed-points-inside-a-unstructured-Grid-Surface-tp5726086.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
More information about the vtk-developers
mailing list