[vtkusers] Fwd: Re: Problem in Converting Lines to vtkPolyLine

Nicolas Sarrasin nsarrasin at phenix-systems.com
Thu Jan 6 08:55:01 EST 2011


Yes of course !

That's why I'm writing "For most of case it works well", vtkStripper 
helps me a lot.

But with this example, my convertion fails.

With debug, I found that the secondth (and last) line close the arc of 
circle but when I display it, this doesn't appear, as it's shown in the 
pictures I linked.

Le 06/01/2011 14:47, David Gobbi a écrit :
> Hi Nicolas,
>
> In my last email to you, I recommended the vtkStripper filter for
> generating a polyline from line segments.  Did you try it?
>
> Cheers,
>
>     David
>
>
> On Thu, Jan 6, 2011 at 3:30 AM, Nicolas Sarrasin
> <nsarrasin at phenix-systems.com>  wrote:
>> Hi all,
>> I'm trying to convert a set of line into one only vtkPolyLine. (original
>> post here :
>> http://vtk.1045678.n5.nabble.com/construct-a-vtkPolyLine-PolyGon-from-a-set-of-vtkLines-td3325716.html)
>>
>> I go through all the polylines of vtkPolyData->GetLines() and then get the
>> associated points.
>> For most of case it works well, but I'm actually encounter a problem on a
>> case.
>>
>> The input polydata
>> (http://img525.imageshack.us/img525/8370/vtkconvertioninit.png) is composed
>> of two lines which trace an arc of circle.
>> After the convertion, this arc is closed
>> (http://img502.imageshack.us/img502/8773/vtkconvertionres.png).
>> It comes from the second line which might not be correct.
>>
>> Can someone explain me what is going wrong ?
>>
>> Thanks by advance.
>>
>> Here is a c++ sample code with the input file attached (wire.vtp).
>> ****
>> #include<vtkSmartPointer.h>
>> #include<vtkCellArray.h>
>> #include<vtkPoints.h>
>> #include<vtkPolyData.h>
>> #include<vtkXMLPolyDataReader.h>
>> #include<vtkXMLPolyDataWriter.h>
>> #include<vtkPolyLine.h>#include<vtkSmartPointer.h>
>> #include<vtkCellArray.h>
>> #include<vtkPoints.h>
>> #include<vtkPolyData.h>
>> #include<vtkXMLPolyDataReader.h>
>> #include<vtkXMLPolyDataWriter.h>
>> #include<vtkPolyLine.h>
>>
>> int main (int argc, char *argv[])
>> {
>>      vtkSmartPointer<vtkXMLPolyDataReader>  reader =
>> vtkSmartPointer<vtkXMLPolyDataReader>::New();
>>      reader->SetFileName("./wire.vtp");
>>
>>      vtkSmartPointer<vtkPolyData>  init_data =
>> vtkSmartPointer<vtkPolyData>::New();
>>      init_data = reader->GetOutput();
>>
>>      vtkSmartPointer<vtkPoints>  init_points =
>> vtkSmartPointer<vtkPoints>::New();
>>      init_points=init_data->GetPoints();
>>
>>      vtkSmartPointer<vtkCellArray>  init_lineArray =
>> vtkSmartPointer<vtkCellArray>::New();
>>      init_lineArray = init_data->GetLines();
>>
>>      int nblines = init_lineArray->GetNumberOfCells();
>>
>>      vtkSmartPointer<vtkPolyData>  new_data =
>> vtkSmartPointer<vtkPolyData>::New();
>>      vtkSmartPointer<vtkPoints>  new_points =
>> vtkSmartPointer<vtkPoints>::New();
>>      vtkSmartPointer<vtkPolyLine>  polyline =
>> vtkSmartPointer<vtkPolyLine>::New();
>>      vtkSmartPointer<vtkCellArray>  new_lineArray =
>> vtkSmartPointer<vtkCellArray>::New();
>>
>>      double coords[3];
>>      vtkIdType nbpts=0, *pts=0;
>>      for( init_lineArray->InitTraversal(); init_lineArray->GetNextCell(nbpts,
>> pts);)
>>      {
>>          vtkIdType init_ind=0, new_ind=0;
>>          for(int p=0; p<nbpts; p++)
>>          {
>>              init_ind=pts[p];
>>              if(init_ind<0)
>>                  continue;
>>              init_points->GetPoint( init_ind, coords);
>>
>>              new_ind=new_points->InsertNextPoint(coords);
>>              polyline->GetPointIds()->InsertNextId(new_ind);
>>          }
>>      }
>>      new_lineArray->InsertNextCell(polyline);
>>      new_data->SetPoints(new_points);
>>      new_data->SetLines(new_lineArray);
>>
>>      vtkSmartPointer<vtkXMLPolyDataWriter>  writer =
>> vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>>      writer->SetFileName("./new_wire.vtp");
>>      writer->SetInput(new_data);
>>      writer->Write();
>> ****
>>

-- 
------------------------------------------------------------------------
Logo Phenix Systems <www.phenix-systems.com> 	Nicolas Sarrasin - 
Ingénieur Developpement 3D CFAO
Phenix systems <www.phenix-systems.com>
Parc Européen d'Entreprises
rue Richard Wagner - 63200 Riom FRANCE
tel : +33 (0)4 73 33 45 85 | fax : +33 (0)4 73 33 45 86
Pensez environnement !
N'imprimez ce mail que si c'est vraiment nécessaire



-- 
------------------------------------------------------------------------
Logo Phenix Systems <www.phenix-systems.com> 	Nicolas Sarrasin - 
Ingénieur Developpement 3D CFAO
Phenix systems <www.phenix-systems.com>
Parc Européen d'Entreprises
rue Richard Wagner - 63200 Riom FRANCE
tel : +33 (0)4 73 33 45 85 | fax : +33 (0)4 73 33 45 86
Pensez environnement !
N'imprimez ce mail que si c'est vraiment nécessaire


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110106/8bf10d3f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 2985 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110106/8bf10d3f/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo_contact.gif
Type: image/gif
Size: 2985 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110106/8bf10d3f/attachment-0001.gif>


More information about the vtkusers mailing list