[vtkusers] select individual iso-lines

Amy Henderson amy.henderson at kitware.com
Thu Feb 20 13:39:04 EST 2003


You could also use the vtkConnectivityFilter to extract these two separate 
pieces.

- Amy

At 01:34 PM 2/20/2003 -0500, Jeremy Winston wrote:
>Dean Inglis wrote:
>>Hi,
>>I am using vtkContourFilter to generate the inner and outer perimeter 
>>contours from a
>>binary thresholded image of a bone cross-section.
>>The filter generates the closed outer bone surface contour and the closed 
>>marrow-bone surface
>>contour. Is there a way to extract each one
>>separately from the vtkPolyData output?
>
>Dean,
>    Here are some snippets of Tcl/vtk code I wrote for a
>similar purpose.  I pass the output of MarchingSquares to
>vtkStripper, which pulls contiguous segments together into
>polylines, one polyline for each contour.  The function
>skipContours() "walks through" each polyline, and if it has
>fewer than minPts points, changes its associated scalar value.
>You would use your own criteria, but the data structures would
>be similar.  If you're using C++, there are some convenience
>functions to iterate through the list of contours more
>conveniently.
>    See
>http://public.kitware.com/pipermail/vtkusers/2002-September/013435.html
>in the list archives for more details on my code.
>
>HTH,
>-Jeremy
>
>--- snippets: ---
>vtkGESignaReader ctReader
>
>vtkExtractVOI extract
>   extract SetInput [ctReader GetOutput]
>
>vtkMergePoints ctLocator
>vtkMarchingSquares ctContour
>   ctContour SetInput [extract GetOutput]
>   ctContour SetLocator ctLocator
>
>vtkStripper ctStrip
>   ctStrip SetInput [ctContour GetOutput]
>
>vtkPolyDataWriter ctWriter
>   ctWriter SetInput [ctStrip GetOutput]
>
>...
>
>proc skipContours {} {
>   global minpts thresh numSelected fs
>   set intT [expr int($thresh)]                 ;# Scalar value of contour pts
>   set c [ctStrip GetOutput]                    ;# Contours
>   set sd [[$c GetPointData] GetScalars]        ;# Scalar data
>   set ld [[$c GetLines] GetData]               ;# Line data
>   set numLines [$c GetNumberOfLines]           ;# Number of contour lines
>   set numSelected $numLines                    ;# Number of contours selected
>   set flag 0                                   ;# Set if scalars are changed
>   for {set idx 0; set i 0} {$i<$numLines} {incr i} { ;# For each line...
>     set nPts [$ld GetComponent $idx 0]         ;# of points in this line
>     set endPt [expr $idx + $nPts]              ;# Indx to last pt in this 
> line
>     if {$nPts < $minpts} {                     ;# If too few pts in line...
>       for {set j [expr $idx+1]} {$j<=$endPt} {incr j} {;# For @ pt in the 
> line
>         set ptNo [$ld GetComponent $j 0]       ;# Point # (indx into scalars)
>         set sv [$sd GetComponent $ptNo 0]      ;# Get pt's current scalar 
> value
>         if {$sv} {                             ;# If value is non-zero
>           incr flag                            ;# Scalar data are changed
>           $sd SetComponent $ptNo 0 0           ;# Set pt's scalar to 0
>         }
>       }
>       incr numSelected -1                      ;# Decrement selected count
>     } else {                                   ;# Don't skip this line
>       for {set j [expr $idx+1]} {$j<=$endPt} {incr j} {;# For @ pt in the 
> line
>         set ptNo [$ld GetComponent $j 0]       ;# Point # (indx into scalars)
>         set sv [$sd GetComponent $ptNo 0]      ;# Get pt's current scalar 
> value
>         if {!$sv} {                            ;# If value is zero
>           incr flag                            ;# Scalar data are changed
>           $sd SetComponent $ptNo 0 $intT       ;# Reset pt's scalar to 
> orig val
>         }
>       }
>     }
>     incr idx [expr $nPts + 1]                  ;# Move to next line
>   }
>   if {$flag} {                                 ;# If scalars have changed
>     $sd Modified
>     renWin Render
>   }
>   $fs.m config -text [format "%s of %s contour(s) selected" \
>     $numSelected $numLines]
>}
>
>--- end. ---
>
>
>_______________________________________________
>This is the private VTK discussion list. Please keep messages on-topic. 
>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers







More information about the vtkusers mailing list