[vtkusers] Pb using vtkAppendPolyData & vtkPolyDataConnectivityFilter

Thomas Deschamps tdeschamps at lbl.gov
Mon Apr 14 20:02:42 EDT 2003


Hi vtkUsers,

I am using vtkAppendPolyData for selecting contours which have a certain 
length among all the contours I have.
My problem is that it takes a LOT of time.

The following code remove all the closed contours which have a length 
smaller than contourLength
           
void function( int contourLength, vtkPolyData * myPolyData )
{
    vtkPolyDataConnectivityFilter * connectivity = 
vtkPolyDataConnectivityFilter::New ();
    connectivity -> SetInput( myPolyData );
    connectivity -> SetExtractionModeToSpecifiedRegions();
    connectivity -> Update();

    vtkPolyData * localPolyData = vtkPolyData::New();
    int nbRegions = connectivity -> GetNumberOfExtractedRegions();
           
    for( int i = 0 ; i < nbRegions ; i++ ) {
        vtkAppendPolyData * append = vtkAppendPolyData::New();
        connectivity -> AddSpecifiedRegion(i);
        connectivity -> Update();
        int nbLines = connectivity -> GetOutput() -> GetNumberOfLines();
                              
        if( nbLines >= contourLength )
            append -> AddInput( connectivity -> GetOutput() );
               
        append -> AddInput( localPolyData );
        append -> Update();
        localPolyData -> DeepCopy( append -> GetOutput());
        connectivity -> DeleteSpecifiedRegion(i);
        append -> Delete();
     }
                      
     myPolyData -> DeepCopy( localPolyData );
     localPolyData -> Delete();
     connectivity -> Delete();
}

You may ask why I am not using the "append" outside of the loop.
This is because it looks like append -> AddInput() is not making a copy 
of the input polydata, but keeps track of the pointer, even if this 
pointer is modified in the future. Therefore it was not working like that.

When the number of contours is > 1000, and when each contour is between 
4 and 700 lines, it takes 30 minutes...
There is surely something more efficient that what I am doing, but I 
don't know what.
Thank you for reading this.

Thomas (tdeschamps at lbl.gov)






More information about the vtkusers mailing list