[vtkusers] polyline and appendpolydata problem
kenichiro yoshimi
rccm.kyoshimi at gmail.com
Sat Oct 21 00:41:18 EDT 2017
Hi
I tested your code with the following input files as a trial, however
the problem didn't occur.
---indexFile---
3
3
---------------
---pointFile---
0.0 0.0 0.0
0.0 1.0 0.0
0.0 2.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
1.0 2.0 0.0
---------------
I think you need to firstly check the validity of the input file format.
Thanks a lot
2017-10-21 8:07 GMT+09:00 Elvis Chen <elvis.chen at gmail.com>:
> 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);
> }
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list