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

pof jd379252 at gmail.com
Thu Dec 20 13:11:25 EST 2012


Goodwin,
this is strange... I tried yesterday and I found it did not work (I must 
have done something with my testing).
I tested again, and this works.
Great and thanks
JD

Le 20/12/2012 17:05, Goodwin Lawlor a écrit :
> JD,
>
> Pass the final polyline through vtkCleanPolyData with 0.0 tolerance 
> (the default) and it should remove the coincident points.
>
> hth
>
> Goodwin
>
> On Thu, Dec 20, 2012 at 12:42 AM, pof <jd379252 at gmail.com 
> <mailto:jd379252 at gmail.com>> wrote:
>
>     Goodwin,
>
>     I tested the patch on the following simple case (5 segments)
>     # vtk DataFile Version 3.0
>     vtk output
>     ASCII
>     DATASET POLYDATA
>     POINTS 6 float
>     1.7 0.5 0 2 0 0 1.7 -0.5 0
>     1.6 -1 0 1.8 -0.2 0 1.6 1 0
>     LINES 5 15
>     2 0 1
>     2 2 3
>     2 4 2
>     2 1 4
>     2 5 0
>
>     without the patch, 2 polylines are obtained from the vtkStripper
>     LINES 2 9
>     5 0 1 4 2 3
>     2 5 0
>
>     whereas with the patch a single polyline is obained
>     LINES 1 8
>     7 5 0 0 1 4 2 3
>
>     Things are of course better, though a duplicate of one point
>     (point 0 in this case) is obtained, which should obviously have
>     been avoided.
>     So it looks there's stil some space to improve the patch.
>
>     In any case, I thank you for sharing this information with me.
>     JD
>
>
>     Le 19/12/2012 10:04, Goodwin Lawlor a écrit :
>>     I think vtkStripper was originally written to quickly produce
>>     vtkTriangleStrip/vtkPolyLine primitives that would render faster,
>>     not a computational geometry type class that would produce the
>>     longest possible polylines... it is a visualization library after
>>     all.
>>
>>     The seed point is arbitrary so you may not get the outcome you
>>     were looking for.
>>
>>     See this 2002 post, that contains a patch which may help:
>>     http://vtk.org/pipermail/vtkusers/2002-January/009372.html
>>
>>     There was a bug report too:
>>     http://www.vtk.org/Bug/print_bug_page.php?bug_id=832
>>
>>     hth
>>
>>     Goodwin
>>
>>
>>     On Mon, Dec 10, 2012 at 2:51 AM, David Gobbi
>>     <david.gobbi at gmail.com <mailto:david.gobbi at gmail.com>> wrote:
>>
>>         Insert vtkTriangleFilter before vtkStripper.  This will break any
>>         input polylines into line segments.  I don't know if it will
>>         help,
>>         but it might.
>>
>>          - David
>>
>>         On Sun, Dec 9, 2012 at 2:48 PM, pof <jd379252 at gmail.com
>>         <mailto:jd379252 at gmail.com>> wrote:
>>         > yes this is the way LINES objects are written on vtk files.
>>         > Ok, so I understand now the point you were making about the
>>         "T", which was
>>         > uncorrect.
>>         >
>>         > So back to the problem, why this vtkStripper is not able to
>>         merge those 2
>>         > lines?
>>         >
>>         > Le 09/12/2012 21:41, David Gobbi a écrit :
>>         >>
>>         >> Is it?  Maybe it is.  When you wrote the numbers, I
>>         assumed that
>>         >>
>>         >> all of the numbers that you listed were just point indices.
>>         >>
>>         >>
>>         >> On Sun, Dec 9, 2012 at 1:37 PM, pof <jd379252 at gmail.com
>>         <mailto:jd379252 at gmail.com>> wrote:
>>         >>>
>>         >>> 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
>>         <mailto: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 <mailto: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;
>>         >>>>>>> }
>>         >>>>>
>>         >>>>>
>>         >
>>         _______________________________________________
>>         Powered by www.kitware.com <http://www.kitware.com>
>>
>>         Visit other Kitware open-source projects at
>>         http://www.kitware.com/opensource/opensource.html
>>
>>         Please keep messages on-topic and check the VTK FAQ at:
>>         http://www.vtk.org/Wiki/VTK_FAQ
>>
>>         Follow this link to subscribe/unsubscribe:
>>         http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121220/6c6550db/attachment.htm>


More information about the vtkusers mailing list