[vtkusers] How connect vtk3DSImporter data into pipeline?

Carl Trapani carl at skytopsoftware.com
Wed Sep 10 17:01:34 EDT 2008


Excellent! Both suggestions ( dataSet->GetProducerPort() and 
actors->InitTraversal() ) worked perfectly!

Thanks very much Eduardo.
Carl

Eduardo K. Saldanha wrote:
> On Mon, Sep 8, 2008 at 3:22 PM, Carl Trapani <carl at skytopsoftware.com> wrote:
>   
>> 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());
>>     
>
> The method GetOutputPort() should be called by the producer of the
> dataSet, not by the mapper.
> As you already have a dataSet you could call dataSet->GetProducerPort()
>
>   
>> 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!??
>>     
>
> You need to call actors->InitTraversal() before call GetNexActor()
>
>   
>>   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();
>>
>> _______________________________________________
>> This is the private VTK discussion list.
>> Please keep messages on-topic. Check the FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>     
>
>
> ---
> Eduardo K. Saldanha
>   


-- 
Carl Trapani (carl at skytopsoftware.com)
Skytop Software (http://www.skytopsoftware.com)
32 Washington St., Suite 222
Camden ME 04843
(207) 975-1685




More information about the vtkusers mailing list