次のように、ポイントクラウド マップから 5 つのポイントを選択するソフトウェアがあります。
void Visualizer::pointPickingEventOccurred (const pcl::visualization::PointPickingEvent &event)
{
std::cout << "[INOF] Point picking event occurred." << std::endl;
float x, y, z;
if (event.getPointIndex () == -1)
{
return;
}
event.getPoint(x, y, z);
std::cout << "[INOF] Point coordinate ( " << x << ", " << y << ", " << z << ")" << std::endl;
points->InsertNextPoint(x, y, z);
}
その後、ボタンを押して vtkPolyLine と 3DGlyph を使用してポイント間に線を引きます。
void Visualizer::drawLine(){
// Create one sphere for all
sphere->SetPhiResolution(21);
sphere->SetThetaResolution(21);
sphere->SetRadius(.08);
vtkNew<vtkNamedColors> colors;
vtkNew<vtkPolyLine> polyLine;
polyLine->GetPointIds()->SetNumberOfIds(5);
for (unsigned int i = 0; i < 5; i++)
{
polyLine->GetPointIds()->SetId(i, i);
}
// Create a cell array to store the lines in and add the lines to it
vtkNew<vtkCellArray> cells;
cells->InsertNextCell(polyLine);
// Create a polydata to store everything in
vtkNew<vtkPolyData> polyData;
// Add the points to the dataset
polyData->SetPoints(points);
// Add the lines to the dataset
polyData->SetLines(cells);
// Create cells
vtkSmartPointer<vtkUnstructuredGrid> ug = vtkSmartPointer<vtkUnstructuredGrid>::New();
ug->SetPoints(points);
ug->InsertNextCell(polyLine->GetCellType(), polyLine->GetPointIds());
// Label the points
vtkSmartPointer<vtkLabeledDataMapper> labelMapper = vtkSmartPointer<vtkLabeledDataMapper>::New();
labelMapper->SetInputData(ug);
vtkSmartPointer<vtkActor2D> labelActor = vtkSmartPointer<vtkActor2D>::New();
labelActor->SetMapper(labelMapper);
viewer->addActorToRenderer(labelActor);
// Glyph the points
vtkSmartPointer<vtkGlyph3DMapper> pointMapper = vtkSmartPointer<vtkGlyph3DMapper>::New();
pointMapper->SetInputData(ug);
pointMapper->SetSourceConnection(sphere->GetOutputPort());
pointMapper->ScalingOff();
pointMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> pointActor = vtkSmartPointer<vtkActor>::New();
pointActor->SetMapper(pointMapper);
pointActor->GetProperty()->SetDiffuseColor(colors->GetColor3d("Banana").GetData());
pointActor->GetProperty()->SetSpecular(.6);
pointActor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
pointActor->GetProperty()->SetSpecularPower(100);
viewer->addActorToRenderer(pointActor);
// Setup actor and mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polyData);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());
actor->GetProperty()->EdgeVisibilityOn();
actor->GetProperty()->SetLineWidth(5);
actor->GetProperty()->SetOpacity(.5);
viewer->addActorToRenderer(actor);
}
points
線を作成した後、リストには以前のポイントの値がまだ残っているため、明らかに別の線を作成できません。
「drawline」関数の最後にあるポイント リストを空にしようとしました。
vtkSmartPointer<vtkPoints> newPoints =
vtkSmartPointer<vtkPoints>::New();
for(vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
{
if(i != id)
{
double p[3];
points->GetPoint(i,p);
newPoints->InsertNextPoint(p);
}
}
points->ShallowCopy(newPoints);
しかし、私はまだ別の行を作成できません