[vtkusers] Bug in vtkStripper on a very simple case ?

pof jd379252 at gmail.com
Sun Dec 9 15:37:17 EST 2012


Hum I see.
(from what I understand), the first integer of each line is simply the 
number of points of the corresponding LINE

Le 09/12/2012 21:33, David Gobbi a écrit :
> Then where would the "9" go?
>
> The stripper uses a simple algorithm, it just chooses a starting
> point, goes as far as it can in each direction to create the first
> polyline, and then repeats this procedure until all the line segments
> are accounted for.  It doesn't exhaustively search though all
> permutations to see which one gives the smallest number of output
> polylines... that would cause the algorithm to run many times slower.
>
>
>
>
> On Sun, Dec 9, 2012 at 1:12 PM, pof <jd379252 at gmail.com> wrote:
>> Hi David
>>
>> the first polyline being:
>>
>>    9 0 1 2 3 4 5 19 6 7
>> and the third polyline (actually it is a segment) being:
>>    2 18 0
>> I don't see why they shoud not merge together as (unless I misunderstand
>> something):
>>    10 18 0 1 2 3 4 5 19 6 7
>>
>> Am I wrong?
>>
>>
>> Le 09/12/2012 21:05, David Gobbi a écrit :
>>
>>> Hi JD,
>>>
>>> It could only merge those two lines if it joined them with a "T".
>>> A polyline cannot have any branches.
>>>
>>>    - David
>>>
>>>
>>> On Sun, Dec 9, 2012 at 12:16 PM, pof <jd379252 at gmail.com> wrote:
>>>> Hi all,
>>>>
>>>> I get a strange result (which may be a bug) using vtk stripper, i.e. it
>>>> does
>>>> not merge LINES as polylines as it is expected to.
>>>> In this example (see below an extract of the polydata produced by
>>>> vtkStripper), only 2 polylines should be obtained, but vtkStripper forgot
>>>> to
>>>> merge the first and the third line together, though they obviously share
>>>> point with Id=0 (btw, the fact that only Id 0 remains unmerged might not
>>>> be
>>>> pure luck).
>>>>
>>>> LINES 3 24
>>>> 9 0 1 2 3 4 5 19 6 7
>>>> 10 9 8 17 13 12 15 14 11 10 16
>>>> 2 18 0
>>>> Does anybody have an idea or an explanation?
>>>> Thanks
>>>> JD
>>>>
>>>> PS: Here below is the complete source file that generates these data and
>>>> in
>>>> which vtkStripper is used.
>>>>
>>>> //////////////////////////////////////////////////////
>>>> // Example modified from IntersectionPolyDataFilter.cxx
>>>> //////////////////////////////////////////////////////
>>>> #include <vtkActor.h>
>>>> #include <vtkIntersectionPolyDataFilter.h>
>>>> #include <vtkPolyDataMapper.h>
>>>> #include <vtkPolyDataWriter.h>
>>>> #include <vtkProperty.h>
>>>> #include <vtkRenderer.h>
>>>> #include <vtkRenderWindow.h>
>>>> #include <vtkRenderWindowInteractor.h>
>>>> #include <vtkSmartPointer.h>
>>>> #include <vtkSphereSource.h>
>>>> #include <vtkCellArray.h>
>>>> #include <vtkStripper.h>
>>>>
>>>> int main(int argc, char *argv[])
>>>> {
>>>>     vtkSmartPointer<vtkSphereSource> sphereSource1 =
>>>> vtkSmartPointer<vtkSphereSource>::New();
>>>>     sphereSource1->SetCenter(0.0, 0.0, 0.0);
>>>>     sphereSource1->SetRadius(2.0f);
>>>>     sphereSource1->SetPhiResolution(20);
>>>>     sphereSource1->SetThetaResolution(20);
>>>>     sphereSource1->Update();
>>>>     vtkSmartPointer<vtkPolyDataMapper> sphere1Mapper =
>>>> vtkSmartPointer<vtkPolyDataMapper>::New();
>>>>     sphere1Mapper->SetInputConnection( sphereSource1->GetOutputPort() );
>>>>     sphere1Mapper->ScalarVisibilityOff();
>>>>     vtkSmartPointer<vtkActor> sphere1Actor =
>>>> vtkSmartPointer<vtkActor>::New();
>>>>     sphere1Actor->SetMapper( sphere1Mapper );
>>>>     sphere1Actor->GetProperty()->SetOpacity(.3);
>>>>     sphere1Actor->GetProperty()->SetColor(1,0,0);
>>>>
>>>>     /////////////////////////
>>>>     // BEGIN MODIFICATIONS //
>>>>     /////////////////////////
>>>>     // Create a planar object
>>>>     // Define 4 vertices
>>>>     vtkSmartPointer<vtkPoints> PlanePoints =
>>>> vtkSmartPointer<vtkPoints>::New();
>>>>     vtkSmartPointer<vtkCellArray> PlaneCells =
>>>> vtkSmartPointer<vtkCellArray>::New();
>>>>     PlanePoints->InsertNextPoint(-3, -1, 0);
>>>>     PlanePoints->InsertNextPoint(3, -1, 0);
>>>>     PlanePoints->InsertNextPoint(-3, 1, 0);
>>>>     PlanePoints->InsertNextPoint(3, 1, 0);
>>>>     // Create 2 trianglar faces
>>>>     PlaneCells->InsertNextCell(3);
>>>>     PlaneCells->InsertCellPoint(0);
>>>>     PlaneCells->InsertCellPoint(1);
>>>>     PlaneCells->InsertCellPoint(2);
>>>>     PlaneCells->InsertNextCell(3);
>>>>     PlaneCells->InsertCellPoint(1);
>>>>     PlaneCells->InsertCellPoint(3);
>>>>     PlaneCells->InsertCellPoint(2);
>>>>     // Create the polydata from points and faces
>>>>     vtkSmartPointer<vtkPolyData> ProtectionWall =
>>>> vtkSmartPointer<vtkPolyData>::New();
>>>>     ProtectionWall->SetPoints(PlanePoints);
>>>>     ProtectionWall->SetPolys(PlaneCells);
>>>>     /////////////////////////
>>>>     // END MODIFICATIONS //
>>>>     /////////////////////////
>>>>
>>>>     vtkSmartPointer<vtkPolyDataMapper> planeMapper =
>>>> vtkSmartPointer<vtkPolyDataMapper>::New();
>>>>     planeMapper->SetInputConnection( ProtectionWall->GetProducerPort() );
>>>>     planeMapper->ScalarVisibilityOff();
>>>>
>>>>     vtkSmartPointer<vtkActor> planeActor =
>>>> vtkSmartPointer<vtkActor>::New();
>>>>     planeActor->SetMapper( planeMapper );
>>>>     planeActor->GetProperty()->SetOpacity(.3);
>>>>     planeActor->GetProperty()->SetColor(0,1,0);
>>>>
>>>>     // Get intersection segments (LINES) using the
>>>> vtkIntersectionPolyDataFilter
>>>>     vtkSmartPointer<vtkIntersectionPolyDataFilter>
>>>> intersectionPolyDataFilter
>>>> = vtkSmartPointer<vtkIntersectionPolyDataFilter>::New();
>>>>     intersectionPolyDataFilter->SplitFirstOutputOff();
>>>>     intersectionPolyDataFilter->SplitSecondOutputOff();
>>>>     intersectionPolyDataFilter->SetInputConnection( 0,
>>>> sphereSource1->GetOutputPort() );
>>>>     intersectionPolyDataFilter->SetInputConnection( 1,
>>>> ProtectionWall->GetProducerPort() );
>>>>     intersectionPolyDataFilter->Update();
>>>>
>>>>     /////////////////////////
>>>>     // BEGIN MODIFICATIONS //
>>>>     /////////////////////////
>>>>     // Try to get the polylines (there should be 2) from the segments
>>>> (LINES)
>>>>     vtkSmartPointer<vtkStripper> stripper =
>>>> vtkSmartPointer<vtkStripper>::New();
>>>>
>>>> stripper->SetInputConnection(intersectionPolyDataFilter->GetOutputPort());
>>>>     stripper->Update();
>>>>     // Save resulting polydata on a file, in which we see that there are 3
>>>> polylines (actually the second polyline is ok,
>>>>     // but the first and third polylines should have been further merged
>>>>     vtkSmartPointer<vtkPolyDataWriter> wr =
>>>> vtkSmartPointer<vtkPolyDataWriter>::New();
>>>>     wr->SetFileName("polylines.txt");
>>>>     wr->SetInputConnection(stripper->GetOutputPort());
>>>>     wr->Write();
>>>>     ///////////////////////
>>>>     // END MODIFICATIONS //
>>>>     ///////////////////////
>>>>
>>>>     vtkSmartPointer<vtkPolyDataMapper> intersectionMapper =
>>>> vtkSmartPointer<vtkPolyDataMapper>::New();
>>>>     intersectionMapper->SetInputConnection( stripper->GetOutputPort() );
>>>>     intersectionMapper->ScalarVisibilityOff();
>>>>
>>>>     vtkSmartPointer<vtkActor> intersectionActor =
>>>> vtkSmartPointer<vtkActor>::New();
>>>>     intersectionActor->SetMapper( intersectionMapper );
>>>>
>>>>     vtkSmartPointer<vtkRenderer> renderer =
>>>> vtkSmartPointer<vtkRenderer>::New();
>>>>     renderer->AddViewProp(sphere1Actor);
>>>>     renderer->AddViewProp(planeActor);
>>>>     renderer->AddViewProp(intersectionActor);
>>>>
>>>>     vtkSmartPointer<vtkRenderWindow> renderWindow =
>>>> vtkSmartPointer<vtkRenderWindow>::New();
>>>>     renderWindow->AddRenderer( renderer );
>>>>
>>>>     vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
>>>>       vtkSmartPointer<vtkRenderWindowInteractor>::New();
>>>>     renWinInteractor->SetRenderWindow( renderWindow );
>>>>
>>>>     renderWindow->Render();
>>>>     renderWindow->SetSize(600, 600);
>>>>     renderer->SetBackground(0.1, 0.2, 0.4);
>>>>     renWinInteractor->Start();
>>>>
>>>>     return EXIT_SUCCESS;
>>>> }
>>




More information about the vtkusers mailing list