<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#003333">
<small>Hi all,<br>
I'm trying to convert a set of line into one only vtkPolyLine.
(original post here :
<a class="moz-txt-link-freetext" href="http://vtk.1045678.n5.nabble.com/construct-a-vtkPolyLine-PolyGon-from-a-set-of-vtkLines-td3325716.html">http://vtk.1045678.n5.nabble.com/construct-a-vtkPolyLine-PolyGon-from-a-set-of-vtkLines-td3325716.html</a>)<br>
<br>
I go through all the polylines of vtkPolyData->GetLines() and
then get the associated points.<br>
For most of case it works well, but I'm actually encounter a
problem on a case.<br>
<br>
The input polydata
(<a class="moz-txt-link-freetext" href="http://img525.imageshack.us/img525/8370/vtkconvertioninit.png">http://img525.imageshack.us/img525/8370/vtkconvertioninit.png</a>) is
composed of two lines which trace an arc of circle. <br>
After the convertion, this arc is closed
(<a class="moz-txt-link-freetext" href="http://img502.imageshack.us/img502/8773/vtkconvertionres.png">http://img502.imageshack.us/img502/8773/vtkconvertionres.png</a>). <br>
It comes from the second line which might not be correct.<br>
<br>
Can someone explain me what is going wrong ?<br>
<br>
Thanks by advance.<br>
<br>
Here is a c++ sample code with the input file attached (wire.vtp).<br>
****<br>
#include <vtkSmartPointer.h><br>
#include <vtkCellArray.h><br>
#include <vtkPoints.h><br>
#include <vtkPolyData.h><br>
#include <vtkXMLPolyDataReader.h><br>
#include <vtkXMLPolyDataWriter.h><br>
#include <vtkPolyLine.h>#include <vtkSmartPointer.h><br>
#include <vtkCellArray.h><br>
#include <vtkPoints.h><br>
#include <vtkPolyData.h><br>
#include <vtkXMLPolyDataReader.h><br>
#include <vtkXMLPolyDataWriter.h><br>
#include <vtkPolyLine.h><br>
<br>
int main (int argc, char *argv[])<br>
{<br>
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();<br>
reader->SetFileName("./wire.vtp");<br>
<br>
vtkSmartPointer<vtkPolyData> init_data =
vtkSmartPointer<vtkPolyData>::New();<br>
init_data = reader->GetOutput();<br>
<br>
vtkSmartPointer<vtkPoints> init_points =
vtkSmartPointer<vtkPoints>::New();<br>
init_points=init_data->GetPoints();<br>
<br>
vtkSmartPointer<vtkCellArray> init_lineArray =
vtkSmartPointer<vtkCellArray>::New();<br>
init_lineArray = init_data->GetLines();<br>
<br>
int nblines = init_lineArray->GetNumberOfCells();<br>
<br>
vtkSmartPointer<vtkPolyData> new_data =
vtkSmartPointer<vtkPolyData>::New();<br>
vtkSmartPointer<vtkPoints> new_points =
vtkSmartPointer<vtkPoints>::New();<br>
vtkSmartPointer<vtkPolyLine> polyline =
vtkSmartPointer<vtkPolyLine>::New();<br>
vtkSmartPointer<vtkCellArray> new_lineArray =
vtkSmartPointer<vtkCellArray>::New();<br>
<br>
double coords[3];<br>
vtkIdType nbpts=0, *pts=0;<br>
for( init_lineArray->InitTraversal();
init_lineArray->GetNextCell(nbpts, pts);)<br>
{<br>
vtkIdType init_ind=0, new_ind=0;<br>
for(int p=0; p<nbpts; p++)<br>
{<br>
init_ind=pts[p];<br>
if(init_ind<0)<br>
continue;<br>
init_points->GetPoint( init_ind, coords);<br>
<br>
new_ind=new_points->InsertNextPoint(coords);<br>
polyline->GetPointIds()->InsertNextId(new_ind);<br>
}<br>
}<br>
new_lineArray->InsertNextCell(polyline);<br>
new_data->SetPoints(new_points);<br>
new_data->SetLines(new_lineArray);<br>
<br>
vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();<br>
writer->SetFileName("./new_wire.vtp");<br>
writer->SetInput(new_data);<br>
writer->Write();<br>
****<br>
<br>
<br>
</small>
</body>
</html>