[vtkusers] Delete point from PolyData
meakcey
meakcey at gmail.com
Thu Nov 22 19:07:17 EST 2018
I am working on a polydata which includes points, normals, colors and ids.
I have managed that by reading point cloud data like below
pcl::PointCloud<pcl::PointNormal>::Ptr pointCloud(new
pcl::PointCloud<pcl::PointNormal>);
pcl::io::loadPLYFile("sample.ply", *pointCloud);
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName ("Colors");
// Set point normals
vtkSmartPointer<vtkDoubleArray> pointNormalsArray =
vtkSmartPointer<vtkDoubleArray>::New();
pointNormalsArray->SetNumberOfComponents(3); //3d normals (ie x,y,z)
pointNormalsArray->SetName("Normals");
vtkSmartPointer<vtkIdTypeArray> pointIds =
vtkSmartPointer<vtkIdTypeArray>::New();
pointIds->SetNumberOfComponents(1);
pointIds->SetName("pointIds");
unsigned char tmpColor[3] = {200, 200, 100};
for(unsigned int i=0; i<pointCloud->size(); i++){
points->InsertNextPoint(pointCloud->points[i].x,
pointCloud->points[i].y, pointCloud->points[i].z);
double pn[3] = {pointCloud->points[i].normal_x,
pointCloud->points[i].normal_y, pointCloud->points[i].normal_z};
pointNormalsArray->InsertNextTypedTuple(pn);
colors->InsertNextTypedTuple(tmpColor);
pointIds->InsertNextValue(i);
}
vtkSmartPointer<vtkPolyData> pointsPoly =
vtkSmartPointer<vtkPolyData>::New();
pointsPoly->SetPoints(points);
vtkSmartPointer<vtkVertexGlyphFilter> vertexFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
vertexFilter->SetInputConnection(idFilter->GetOutputPort());
vertexFilter->SetInputData(pointsPoly);
vertexFilter->Update();
vtkPointCloud = vtkSmartPointer<vtkPolyData>::New();
vtkPointCloud ->ShallowCopy(vertexFilter->GetOutput());
vtkPointCloud ->GetPointData()->SetScalars(colors);
vtkPointCloud ->GetPointData()->SetNormals(pointNormalsArray);
vtkPointCloud ->GetPointData()->AddArray(pointIds);
I am able to render this created polydata and can select areas by getting
know ids and so on.
Now I want to some of the points from this set with code below but it is
getting crashed.
for(unsigned int j=20; j<30; j++){
vPointCloud->DeletePoint(j);
}
sceneActor->Modified();
How can delete points referring to ids assigned?
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list