[vtkusers] Exporting/importing multiple polydata objects (was: Re: [vtkusers] triangulating a cylinder)
Obada Mahdi
omahdi at gmx.de
Sun Dec 10 19:05:43 EST 2006
Hi Deb!
[I have changed the subject line in order to attract other readers who
might have more suggestions in this regard. The thread started at
http://public.kitware.com/pipermail/vtkusers/2006-December/088522.html ]
On Sun, 10 Dec 2006, debbie larson wrote:
> Now that I have all the cylinders I would like to write them to a file
> using, I guess, vtkPolyDataWriter. The goal is to be able to read them
> using, say, vtkPolyDataReader and render them without the need of
> generating them. But I am not sure how to write several cylinders
> using vtkPolyDataWriter. I probably need to put all the cylinders
> into some structure like an array and then write that array to a file?
> What do I write to the file? The vtkPolyDataMapper or
> vtkCylinderSource objects?
There are roughly two different classes of writers/readers in VTK:
- vtkDataSetWriter/vtkDataSetReader derivates, like vtkPolyDataWriter
and vtkPolyDataReader, handle one data set at a time.
They can be placed into the pipeline where a "sink", like a mapper,
would be placed (vtkDataSetWriter), or where a source object would be
(vtkDataSetReader). In your current code, one vtkPolyDataWriter could
be used like one vtkPolyDataMapper. It would write one vtkPolyData
instance, corresponding to a single cylinder polydata. It does not,
however, include any properties handled further down the pipeline,
like those of vtkActor.
http://www.vtk.org/doc/nightly/html/classvtkDataSetWriter.html
http://www.vtk.org/doc/nightly/html/classvtkDataSetReader.html
- vtkExporter/vtkImporter derivates are capable of handling whole render
scenes, including actor properties, lights and cameras (to some
extent). I guess this is what you want, if you would like to have a
"snapshot" of the contents of a particular render window to be written
to disk.
You can check out the class inheritance tree in the documentation to
have a closer look at what file formats are supported for exporting
and importing whole scenes. They all seem to have different
capabilities, but I wouldn't know which one to choose for your
application--I'll leave that to the experts :-)
http://www.vtk.org/doc/nightly/html/classvtkExporter.html
http://www.vtk.org/doc/nightly/html/classvtkImporter.html
Now, regarding the use of vtkPolyDataWriter: As mentioned, it only deals
with the information stored in a vtkPolyData instance (points, cells and
point/cell data [scalars, normals, ...]), and only handles one instance
per output file. Using it directly in the context of your program is
probably not very effective, because you would have to store each
cylinder separately, and additionally record position and orientation
somewhere, effectively making some kind of a poor man's scene exporter.
Still, if for some reason it is desirable to output just the geometrical
information (vtkPolyData, that is) of all cylinders merged together as a
single polydata, you can use the vtkAppendPolyData filter, described at
http://www.vtk.org/doc/nightly/html/classvtkAppendPolyData.html
for combining multiple polydata sets into one, after using a transform
filter (vtkTransformPolyDataFilter) to rotate and translate each
cylinder into place (instead of transforming them through the actor).
Hope this helps in finding a proper solution,
Obada
> Here it is my current code
>
> Thanks!
>
> deb
>
> ---------------------------------------------------
> vtkCylinderSource* icylinder[num_cylinders];
>
> vtkPolyDataMapper *icylinderMapper[num_cylinders];
>
> vtkActor *icylinderActor[num_cylinders];
>
> vtkRenderer *ren1 = vtkRenderer::New();
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren1);
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
>
> ren1->SetBackground(0.1, 0.2, 0.4);
> renWin->SetSize(500, 500);
>
> vtkPolyDataWriter* writer=vtkPolyDataWriter::New();
> writer->SetFileName("cylinders.vtk");
>
> for (int i=0;i<num_cylinders;i++)
> {
>
>
> icylinder[i]=vtkCylinderSource2::New();
> icylinder[i]->SetHeight(cylinder_height);
> icylinder[i]->SetRadius(iradius);
> icylinder[i]->SetCenter(center_positionx,0,center_positiony);
> icylinder[i]->CappingOff();
> icylinder[i]->SetResolution(number_of_points);
> icylinder[i]->SetPlanes(number_of_planes);
>
> icylinderMapper[i]=vtkPolyDataMapper::New();
>
> icylinderMapper[i]->SetInputConnection(icylinder[i]->GetOutputPort());
>
> icylinderActor[i]=vtkActor::New();
>
> icylinderActor[i]->SetMapper(icylinderMapper[i]);
>
> icylinderActor[i]->GetProperty()->SetColor(0.5, 0.3882,
> 0.2784);//RGB color
> icylinderActor[i]->RotateX(30.0);
> icylinderActor[i]->RotateY(-45.0);
>
> ren1->AddActor(icylinderActor[i]);
>
> }
>
>
> ren1->ResetCamera();
> ren1->GetActiveCamera()->Zoom(1.0);
> renWin->Render();
>
>
> iren->Start();
>
>
> for (int i=0;i<num_cylinders;i++)
> {
> icylinder[i]->Delete();
>
> icylinderMapper[i]->Delete();
>
> icylinderActor[i]->Delete();
>
> }
> ren1->Delete();
> renWin->Delete();
> iren->Delete();
> -----------------------------------------------------------------------------
[quote of previous messages deleted]
More information about the vtkusers
mailing list