[vtkusers] converting vtkPolyLines to vtkLines

Dr. Roman Grothausmann grothausmann.roman at mh-hannover.de
Thu Oct 11 03:17:21 EDT 2012


On 10/10/12 16:52, David Gobbi wrote:
> Hi Roman,
>
> The vtkTriangleFilter will break polylines into line segments.

Thanks David, vtkTriangleFilter does the trick. I had come across it when I 
checked the doc of vtkStripper (which does the opposite), however neither its 
name nor its option PassLinesOn suggested breaking of polylines to me.

Thanks for Your hint
Roman

> 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

-- 
Dr. Roman Grothausmann

Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis

Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
30625 Hannover

Tel. +49 511 532-9574



More information about the vtkusers mailing list