[vtkusers] How connect vtk3DSImporter data into pipeline?

Carl Trapani carl at skytopsoftware.com
Mon Sep 8 14:22:46 EDT 2008


Hi All,

I'm trying to get a cut through a 3D object loaded from a 3DS model to 
produce a 2D image. Because vtk3DSImporter is not a simple data source 
(it is an importer that holds many objects rather than a reader or 
generating algorithm), I'm having a hard time figuring out how to 
connect it into the VTK pipeline using the new style of Connections and 
Ports:

filter->SetInputConnection(source->GetOutputPort());

I read the 3DS file, then get the only actor in the model and it's 
mapper. I can get things to work by getting the dataSet from the mapper 
and then setting the cutter's input to the dataSet:

cutter->SetInput( dataSet );

But this is old style. When I try the new style:

cutter->SetInputConnection(mapper->GetOutputPort());

I get an error: vtkPainterPolyDataMapper (01B5E8F0): Attempt to get 
output port index 0 for an algorithm with 0 output ports.

Can anyone tell me how I might get the 3D data from my 3DS importer 
wired into vtkCutter?

More of my code is below. Thanks much in advance for any suggestions.
Carl Trapani
Skytop Software

--------------- CODE SNIPPET-------------------

    // Import/read the 3DS file
    vtk3DSImporter *importer = vtk3DSImporter::New();
    importer->SetFileName( argv[1] );
    importer->Read();

    // Get vtkDataSet which holds the geometry of the 3DS model
    // Getting the DataSet involves:
    //    -getting the vtkRenderer from vtk3DSImporter
    //    -getting the vtkActor from vtkActors in vtkRenderer
    //    -getting the vtkMapper from vtkActor
    //    -getting the vtkDataSet from vtkMapper
    vtkRenderer *impRen = importer->GetRenderer();
    vtkActorCollection *actors = impRen->GetActors();
    vtkActor *actor = actors->GetNextActor();  // doesn't work!??
    actor = actors->GetLastActor();

    vtkMapper *mapper = actor->GetMapper();
    mapper->Update();
    vtkDataSet *dataSet = mapper->GetInput();
   
    // Calculate the z coordinate from z-%-from-center.
    double z = calculateZ( argv[2], dataSet );
   
    // vtkPlane is the cutting function used in the cutter.
    vtkPlane *plane = vtkPlane::New();
    plane->SetOrigin( 0.0, 0.0, z );
    plane->SetNormal( 0.0, 0.0, 1.0 );

    // Setup the cutter, it's cutting function (plane)
    // and wire it to the dataSet from the imported model.
    vtkCutter *cutter = vtkCutter::New();
    cutter->SetCutFunction( plane );
    //cutter->SetInput( dataSet );           // <-- This works
    cutter->SetInputConnection(mapper->GetOutputPort());  // <--  This 
throws ERROR
    cutter->Update();




More information about the vtkusers mailing list