[vtkusers] How do I output PolyData's points?

Matt Zumwalt mz108 at york.ac.uk
Wed Jul 9 09:55:57 EDT 2003


Hi all,
   I'm still having troubles trying to output a list containing a PolyData's 
point coordinates.  It seems that when I try to access the PolyData's 
geometry, I come up with zero points.  I've put a copy of my Tcl script 
below.  

     This is what the script returns to the standard output:
can't find package vtkParallelTCL 4.2
can't find package vtkPatentedTCL 4.2
points:
numberOfPoints: 0

   Here is the Tcl script I'm using.  (The 'for' loop is getting skipped 
entirely because, for some reason [[sphere GetOutput] GetNumberOfPoints] 
returns a value of zero.):


vtkSphereSource sphere 
 sphere SetThetaResolution 8
 sphere SetPhiResolution 8

set points [[sphere GetOutput] GetPoints]
puts "points: $points"

set numberOfPoints [[sphere GetOutput] GetNumberOfPoints]
puts "numberOfPoints: $numberOfPoints"

#make sure the array is cleared, then fill it with point info
# ! the for loop never executes because $numberOfPoints = 0 !
if {[array exists outarray]} {unset outarray}
for {set i 0} {$i < $numberOfPoints} {incr i} {
    set outarray($i) [points GetPoint $i]
    puts "point $i\: $outarray($i)"
}

take care,
 Matt Z


On Tuesday 08 July 2003 19:56, Amy Henderson wrote:
> At 08:51 PM 7/8/2003 +0000, Matt Zumwalt wrote:
> >Thanks Amy.
> >     Possibly someone knows what I'm doing wrong in translating Amy's code
> > from
> >C++ to Tcl?  I've gotten the following error (tcl code included below):
> >
> >         Error in startup script: Object named: sphere, could not find
> >         requested method: GetPoints
> >         or the method was called with incorrect arguments.
> >
> >             while executing
> >         "sphere GetPoints"
> >            invoked from within
> >         "set points [sphere GetPoints]"
> >             (file "PointsToArray.tcl" line 6)
> >
> >
> >This is what I've done in Tcl:
> >
> >package require vtk
> >
> >vtkSphereSource sphere
> >  sphere SetThetaResolution 8
> >  sphere SetPhiResolution 8
> >set points [sphere GetPoints]
> >set numberOfPoints [sphere GetNumberOfPoints]
>
> The above 2 lines should be:
>
> set points [[sphere GetOutput] GetPoints]
> set numberOfPoints [[sphere GetOutput] GetNumberOfPoints]
>
> - Amy
>
> >for {set i 0} {i < $numberOfPoints} {incr i} {
> >     set outarray($i) [points GetPoint $i]
> >}
> >
> >Thanks again,
> >MattZ
> >
> >On Tuesday 08 July 2003 18:18, Amy Henderson wrote:
> > > At 07:04 PM 7/8/2003 +0000, Matt Zumwalt wrote:
> > > >Hi all,
> > > >     I'm trying to figure out how to generate a list containing the
> > > > coordinates
> > > >for all the points in a PolyData object.  I need to pass the list as
> > > >parameters to one of the methods in an external program.   I'm sure
> > > > there must be some simple way of doing this, but I can't figure it
> > > > out.  Any help would be greatly appreciated.
> > >
> > > The following should work:
> > >
> > > vtkPoints *points = polyData->GetPoints();
> > > int numPts = polyData->GetNumberOfPoints();
> > > int i;
> > >
> > > float **ptArray = new float[numPts][3];
> > >
> > > for (i = 0; i < numPts; i++)
> > > {
> > > points->GetPoint(i, ptArray[i]);
> > > }
> > >
> > > - Amy
> > >
> > > >thanks,
> > > >  Matt Z
> > > >_______________________________________________
> > > >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://www.vtk.org/mailman/listinfo/vtkusers
> >
> >--
> >---------------------
> >MSc Candidate
> >Programme in Music Technology
> >Department of Electronics
> >University of York
> >_______________________________________________
> >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://www.vtk.org/mailman/listinfo/vtkusers





More information about the vtkusers mailing list