[vtkusers] Re: How to write multiple vtkPolyData into on single XML file

Goodwin Lawlor goodwin.lawlor at ucd.ie
Tue Nov 2 16:41:20 EST 2004


Hi Patrick,


for example, in tcl:

vtkXMLPolyDataReader reader
    reader SetFilename c:/filename.vtp
    reader Update

set data [reader GetOutput]
set numCells [$data GetNumberOfCells]

vtkRenderer ren
vtkIdList ptIds

for {set i 0} {$i < $numCells} {incr i} {

    if {[$data GetCellType $i] != 3 && [$data GetCellType $i] != 4} {
        continue
    }

    vtkPoints points$i
    vtkCellArray cells$i
    vtkPolyData pdata$i
    vtkPolyDataMapper mapper$i
    vtkActor actor $i

    ptIds Initialize
    $data GetCellPoints $i ptIds
    set numPts [ptIds GetNumberOfIds]
    cells$i InsertNextCell $numPts

    for {set j 0} {$j < $numPts} {incr j} {
        eval points$i SetPoint $j [$data GetPoint [ptIds GetId $j]]
        cells$i InsertCellPoint $j
    }

    pdata$i SetPoints points$i
    pdata$i SetLines cells$i
    mapper$i SetInput pdata$i
    actor$i SetMapper mapper$i
    ren AddActor actor$i

}

The code above is an example- I haven't run it so "caveat executor"

If you're coding in c++ its easier, use:
vtkPolyData::GetLines()
vtkCellArray::InitTraversal()
vtkCellArray::GetNextCell(vtkIdType & npts, vtkIdType *& pts)

hth

Goodwin

----- Original Message ----- 
From: "Peng (Patrick) Cheng" <peng-cheng at uiowa.edu>
To: "Goodwin Lawlor" <goodwin.lawlor at ucd.ie>
Cc: <vtkusers at public.kitware.com>
Sent: Tuesday, November 02, 2004 4:52 PM
Subject: Re: [vtkusers] Re: How to write multiple vtkPolyData into on single
XML file


> Hi Goodwin,
> Thanks for your help, Can you give me an example on how to "loop
> through" the polydata cells? and how to copy the data to another polydata?
> Thanks again.
> Patrick
>
> Goodwin Lawlor wrote:
> > Hi Patrick,
> >
> > Do you want each line to have its own mapper and actor? You may not need
> > to... cells can be picked and colored individually. Do you need to be
able
> > to transform each line?
> >
> > You can try to use vtkPolyDataConnectivityFilter for a start... get the
> > number of connected regions, then specifiy by region number one at a
time
> > and then DeepCopy each output into a new vtkPolyData (haven't tried this
but
> > its a suggestion).
> >
> > If you want each cell (be it a line or polyline) to have its own
> > mapper/actor, then you can loop through the appended polydata's cells,
> > copying each cell's topology (vtkCellArray) and geometry (vtkPoints)
into
> > its own vtkPolyData.
> >
> > hth
> >
> > Goodwin
> >
> > ps Q's are best kept on the mailing list for posterity
> >
> > ----- Original Message ----- 
> > From: "Peng (Patrick) Cheng" <peng-cheng at uiowa.edu>
> > To: "Goodwin Lawlor" <goodwin.lawlor at ucd.ie>
> > Sent: Monday, November 01, 2004 5:46 PM
> > Subject: Re: [vtkusers] Re: How to write multiple vtkPolyData into on
single
> > XML file
> >
> >
> >
> >>Hi Goodwin,
> >>I have another question, I did as you told me, append the data and write
> >>to a single file. and then I can read them back, but it only gives me
> >>one dataset, How can I extract the original lines out of the
vtkXMLReader?
> >>thanks
> >>Patrick
> >>
> >>Goodwin Lawlor wrote:
> >>
> >>>Hi Patrick,
> >>>
> >>>Use vtkAppendPolyData to append all your polydatas into one, then write
> >
> > this
> >
> >>>appended polydata out using vtkXMLWriter.
> >>>
> >>>hth
> >>>
> >>>Goodwin
> >>>
> >>>"Peng (Patrick) Cheng" <peng-cheng at uiowa.edu> wrote in message
> >>>news:418177F6.8050800 at uiowa.edu...
> >>>
> >>>
> >>>>hi all,
> >>>>
> >>>>I have hundreds of vtkPolyData in a list need to be output to a XML
> >>>>file, and later on read back. each of them is a line with a points and
a
> >>>>scalars. I was just wondering is it possible to write all these data
> >>>>into  one XML file with current vtkXMLWriter? or do I have to output
one
> >>>>file for each vtkPolyData?
> >>>>
> >>>>Patrick
> >>>>-- 
> >>>>
> >>>>Peng (Patrick) Cheng
> >>>>Research Assistant
> >>>>Radiology, Magnetic Resonance Imaging (MRI) Center
> >>>>University of Iowa Hospital and Clinics
> >>>>Iowa City, IA 52246
> >>>>
> >>>>Office:  0453-E JCP
> >>>>Phone:   (319)356-7808 (O)
> >>>>         (319)400-7442 (C)
> >>>>Email:   peng-cheng at uiowa.edu
> >>>>Website: http://css.engineering.uiowa.edu/~pcheng/
> >>>>
> >>>>
> >>>>
> >>>>_______________________________________________
> >>>>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
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>>_______________________________________________
> >>>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
> >>>
> >>
> >>-- 
> >>
> >>Peng (Patrick) Cheng
> >>Research Assistant
> >>Radiology, Magnetic Resonance Imaging (MRI) Center
> >>University of Iowa Hospital and Clinics
> >>Iowa City, IA 52246
> >>
> >>Office:  0453-E JCP
> >>Phone:   (319)356-7808 (O)
> >>          (319)400-7442 (C)
> >>Email:   peng-cheng at uiowa.edu
> >>Website: http://css.engineering.uiowa.edu/~pcheng/
> >>
> >>
> >>
> >>
> >
> >
> > _______________________________________________
> > 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
> >
>
> -- 
>
> Peng (Patrick) Cheng
> Research Assistant
> Radiology, Magnetic Resonance Imaging (MRI) Center
> University of Iowa Hospital and Clinics
> Iowa City, IA 52246
>
> Office:  0453-E JCP
> Phone:   (319)356-7808 (O)
>           (319)400-7442 (C)
> Email:   peng-cheng at uiowa.edu
> Website: http://css.engineering.uiowa.edu/~pcheng/
>
>
>
>




More information about the vtkusers mailing list