The best way would be to create a vtkPolyData, and use the vtkPolyData::SetPoints to give the list of points and vtkPolyData::SetVerts to give the vtkCellArray describing the cells around the points (so VTK can render the points).
In VTK, points are only 3D coordinates. They serve as a support for cells.
To have a valid point cloud, you need:
a vtkDataSet that support explicit points, here we will use a vtkPolyData
the vtkPoints containing the points, which you already have
the vtkCellArray containing the cells so you have a valid VTK data set
We can construct one like that:
// vtk data set to fill
vtkNew<vtkPolyData> myPolyData;
// compute a vtkIdList that contains ids of each points
vtkIdType numPoints = myVtkPoints->GetNumberOfPoints();
vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
pointIds->SetNumberOfIds(numPoints);
for (vtkIdType i = 0; i < numPoints; ++i)
{
pointIds->SetId(i, i);
}
// create a vtkCellArray from this list
vtkSmartPointer<vtkCellArray> polyPoint = vtkSmartPointer<vtkCellArray>::New();
polyPoint->InsertNextCell(pointIds);
// give the points and cells to the final poly data
myPolyData->SetPoints(myVtkPoints);
myPolyData->SetVerts(polyPoint);
In this code, I assume you have myVtkPoints that is the vtkPoints containing the positions of points in your point cloud
I added the above code to my code, but the renderwindow still shows it as points.
below is my code:
vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
pointIds->SetNumberOfIds(numPoints);
for (vtkIdType i = 0; i < numPoints; ++i)
{
pointIds->SetId(i, i);
}
// create a vtkCellArray from this list
vtkSmartPointer<vtkCellArray> polyPoint = vtkSmartPointer<vtkCellArray>::New();
polyPoint->InsertNextCell(pointIds);
// give the points and cells to the final poly data
m_vtkPolydata->SetPoints(m_vtkPCDPoints);
m_vtkPolydata->SetVerts(polyPoint);
vtkNew<vtkVertexGlyphFilter> m_vtkGlyphFilter;
m_vtkGlyphFilter->SetInputData(m_vtkPolydata);
m_vtkGlyphFilter->Update();
vtkNew<vtkPolyDataMapper> m_vtkPolydataMapper;
m_vtkPolydataMapper->SetInputData(m_vtkPolydata);
vtkNew<vtkActor> m_vtkActor;
m_vtkActor->SetMapper(m_vtkPolydataMapper);
vtkNew<vtkRenderer> m_vtkRenderer;
m_vtkRenderer->AddActor(m_vtkActor);
m_vtkRenderer->SetBackground(.1, .2, .3);
vtkNew<vtkRenderWindow> m_vtkRenderWindow;
m_vtkRenderWindow->AddRenderer(m_vtkRenderer);
m_vtkRenderWindow->Render();
Oh I see, you want to create a surface from your points. Maybe you should have a look at vtkDelaunay2d. This filter can take the polydata we created as input and should provide a triangulated surface like the one you want as output.
I already have tested with the vtkDelaunay2d sample code.
I modified the code as below, the stack overflow exception occurred.
My code:
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
vtkNew<vtkPLYReader> reader;
reader->SetFileName("test.ply");
reader->Update();
// Create a set of heights on a grid.
// This is often called a "terrain map".
vtkNew<vtkPoints> points;
points->DeepCopy(reader->GetOutput()->GetPoints());
// Add the grid points to a polydata object
vtkNew<vtkPolyData> polydata;
polydata->SetPoints(points);
//... same as the sample code
}
Exam_VTK.zip (2.0 MB)
Please see my full code. It is a modified code based on the vtkDelaunay2d sample code.
Thanks again…!
=============== modified ===============
I found that the solution for the ‘stack overflow’ exception.
There is no error if I increase the stack size.
[Project > Properties > Linker > System > StackSize]
But the converting speed from the point to vtkDelaunay2d is so slow.
Is there any way to speed up the conversion?
Nice you succeeded to convert your file.
What is the approximate size of your point cloud ? In your scene, it looks like you represent points using glyphs. This can also be a bottleneck on a large scene. Can you try to use the Point Gaussian representation instead ? This one is computed in the screen space and does not create additional geometry for each point.
Thank you for your guide
Actually what I want is just to represent the mesh data from the point data.
I think I have to study VTK library deeply, because there are so many functions.
So, if I have a further question I will create a new topic.
Thanks again!