[vtkusers] converting vtkPolyLines to vtkLines
David Gobbi
david.gobbi at gmail.com
Wed Oct 10 10:52:22 EDT 2012
Hi Roman,
The vtkTriangleFilter will break polylines into line segments.
I don't know why this is not documented.
- David
On Wed, Oct 10, 2012 at 5:57 AM, Dr. Roman Grothausmann
<grothausmann.roman at mh-hannover.de> wrote:
> Dear mailing list members,
>
>
> Since there seems no filter in VTK to convert vtkPolyLines to vtkLines I
> tried to do this manually. The code I use for that is below. Am I doing it
> appropriately or would there be a better way?
>
> Thanks
> Roman
>
> ////vtkPolyLine2vtkLine(mesh);
> vtkCell *cell;
> vtkCell *edge;
> vtkPolyData *new_mesh= vtkPolyData::New();
> vtkPoints *points= vtkPoints::New();
> vtkCellArray *lines= vtkCellArray::New();
>
> points= mesh->GetPoints(); //GetVerts()
>
> for (vtkIdType i= 0; i < N; i++){
> cell= mesh->GetCell(i);
> if (cell->GetCellType() == VTK_POLY_LINE) {
> std::cerr << "Cell " << i << " is of type " <<
> vtkCellTypes::GetClassNameFromTypeId(mesh->GetCell(i)->GetCellType()) <<
> std::endl;
> vtkIdType noe= cell->GetNumberOfEdges(); //vtkPolyLine does not
> consist of edges!!!
> //vtkIdType noe= cell->GetNumberOfLines(); vtkCell has no member
> named GetNumberOfLines
> vtkIdType nop= cell->GetNumberOfPoints();
> std::cerr << "Cell contains " << noe << " edges and " << nop <<
> " points." << std::endl;
>
> for (vtkIdType j= 1; j < nop; j++){ //start at 1 since a
> polyline has nop-1 lines!
> vtkIdType pi= cell->GetPointId(j);
> vtkLine *line= vtkLine::New();
> line->GetPointIds()->SetId(0,cell->GetPointId(j - 1));
> line->GetPointIds()->SetId(1,cell->GetPointId(j));
>
> //line->GetPointIds()->InsertNextId(edge->GetPointIds()->GetId(0));
>
> //line->GetPointIds()->InsertNextId(edge->GetPointIds()->GetId(1));
> lines->InsertNextCell(line);
> }
> }
> }
>
> new_mesh->SetPoints(points);
> new_mesh->SetLines(lines);
>
>
>
>
> On 14/09/12 21:21, Dr. Roman Grothausmann wrote:
>>
>> Hello Darshan Pai,
>>
>>
>> Thanks for Your reply. Isn't vtkStripper for conversion of vtkLines to
>> vtkPolyLines? I would need a filter for doing the opposite.
>> I tried vtkStripper with SetMaximumLength(1) and SetMaximumLength(0) but
>> the output was still vtkPolyLines. Would I have to convert these
>> vtkPolyLines with just two vertices into vtkLines manually?
>>
>> Many thanks for Your help
>> Roman
>>
>> On 14/09/12 17:27, Darshan Pai wrote:
>>>
>>> You can try using vtkStripper.
>>>
>>> Regards
>>>
>>>
>>> On Fri, Sep 14, 2012 at 5:53 AM, Dr. Roman Grothausmann
>>> <grothausmann.roman at mh-hannover.de
>>> <mailto:grothausmann.roman at mh-hannover.de>> wrote:
>>>
>>> Dear mailing list members,
>>>
>>>
>>> How to convert vtkPolyLines to vtkLines? vtkTriangleFilter does the
>>> corresponding conversion of triangles-strips, but what filter to use
>>> for vtkPolyLines? vtkCleanPolyData only does it for degenerate cells.
>>>
>>> Many thanks for any help or hints
>>> Roman
More information about the vtkusers
mailing list