vtkStripper not joining contiguous lines to form a single vtkPolyLine.

Here is the rendering of three vtkLines:

Now I use vtkStripper in the hopes of getting a single vtkPolyLine:

    vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
    poly->SetPoints( points );
    poly->SetLines( segments );
    poly->GetCellData()->SetScalars( dataIndexes );


    vtkSmartPointer<vtkStripper> stripper = vtkSmartPointer<vtkStripper>::New();
    stripper->SetInputData( poly );
    stripper->SetMaximumLength( 200 );
    stripper->JoinContiguousSegmentsOn();
    stripper->Update();

    Application::instance()->logInfo("=====>" + QString::number( poly->GetNumberOfCells() ));
    Application::instance()->logInfo("=====>" + QString::number( stripper->GetOutput()->GetNumberOfCells() ));

Here’s what I get:
image

I was supposed to get just one object count in the second call.

Here is the data used to build the geometry:

test
8
x_initial
x_final
y_initial
y_final
z_initial
z_final
color_code
0.0	0.0	0.0	0.0	0.0	1.0	1
0.0	0.0	0.0	0.0	1.0	2.0	2
0.0	0.0	0.0	0.0	2.0	3.0	1

As can be seen, there is no geometry mismatch that would cause vtkStripper to misbehave.

I’ll appreciate any help.

Hello,

Could you try to run vtkCleanPolyData filter on the polydata before vtkStripper?

Yes, that solved it. Thanks a lotKenichiro! :grinning:

The code with the solution:

    vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
    poly->SetPoints( points );
    poly->SetLines( segments );
    poly->GetCellData()->SetScalars( dataIndexes );

    vtkSmartPointer<vtkCleanPolyData> cleanPolyData =  vtkSmartPointer<vtkCleanPolyData>::New();
    cleanPolyData->SetInputData( poly );
    cleanPolyData->Update();

    vtkSmartPointer<vtkStripper> stripper = vtkSmartPointer<vtkStripper>::New();
    stripper->SetInputConnection( cleanPolyData->GetOutputPort() );
    stripper->SetMaximumLength( 200 );
    stripper->JoinContiguousSegmentsOn();
    stripper->Update();

    Application::instance()->logInfo("=====>" + QString::number( poly->GetNumberOfCells() ));
    Application::instance()->logInfo("=====>" + QString::number( stripper->GetOutput()->GetNumberOfCells() ));
1 Like