[vtkusers] polyline and appendpolydata problem

Elvis Chen elvis.chen at gmail.com
Fri Oct 20 19:07:59 EDT 2017


hi all,

I am working on a 3D surface reconstruction problem.  Think of a 3D laser
scanner, where I have multiple sets of 3D points (1 set per laser scan
line).  I would like to visualize them as a set of polylines, 1 polyline
per scan line.

I wrote the following code to read these data from 2 files. One file is a
set of 3D points, the other is a text file indicating the number of points
per scan line.  I then create 1 polyline per scan line, and append them
together using vtkappendpolydata. I then wrote the results into a .vtk file.

However, visualizing the .vtk file suggests that the beginning of the nth
scan line is connected to the end of the (n-1)th scan line.  How do I
create a set of the disconnected polylines?

any help is very much appreciated,

My codes are as following:

#include <vtkSmartPointer.h>
#include <vtkAppendPolyData.h>
#include <vtkPoints.h>
#include <vtkPolyLine.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataWriter.h>

int main ( int argc, char *argv[])
  {

  ifstream indexFile(argv[1]);
  ifstream pointFile(argv[2]);
  int num;
  double x, y, z;
  vtkSmartPointer< vtkAppendPolyData > append =
    vtkSmartPointer< vtkAppendPolyData >::New();

  while (indexFile >> num)
    {
    vtkSmartPointer< vtkPoints > points =
      vtkSmartPointer< vtkPoints >::New();
    vtkSmartPointer< vtkPolyLine > polyline =
      vtkSmartPointer< vtkPolyLine >::New();

    polyline->GetPointIds()->SetNumberOfIds(num);
    for (unsigned int i = 0; i < (unsigned int)num; i++)
      {
      pointFile >> x >> y >> z;
      points->InsertNextPoint(x, y, z);
      polyline->GetPointIds()->SetId(i, i);
      }

    vtkSmartPointer< vtkCellArray > cells =
      vtkSmartPointer< vtkCellArray >::New();
    cells->InsertNextCell(polyline);
    vtkSmartPointer< vtkPolyData > polyData =
      vtkSmartPointer< vtkPolyData >::New();
    polyData->SetPoints(points);
    polyData->SetLines(cells);
    polyData->Modified();

    append->AddInputData(polyData);
    append->Modified();
    }
  indexFile.close();
  pointFile.close();

  vtkSmartPointer< vtkPolyDataWriter > writer =
    vtkSmartPointer< vtkPolyDataWriter >::New();
  writer->SetFileName("test.vtk");
  writer->SetInputConnection(append->GetOutputPort());
  writer->Write();


  return (0);
  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171020/16b40649/attachment.html>


More information about the vtkusers mailing list