I am new to VTK and I have been struggling solving this for a while. I am trying to develop a software where I pick 5 points from a pointclouds and from these points I draw a line that connects the points and a glyph around each of the point. Now I am trying to create a method where I can pick the glyph and move it around. I have tried applying the following example: MoveAGlypth
namespace {
// Define interaction style
class InteractorStyleMoveGlyph : public vtkInteractorStyleTrackballActor
{
public:
static InteractorStyleMoveGlyph* New();
vtkTypeMacro(InteractorStyleMoveGlyph, vtkInteractorStyleTrackballActor);
InteractorStyleMoveGlyph()
{
this->MoveSphereSource = vtkSmartPointer<vtkSphereSource>::New();
this->MoveSphereSource->SetRadius(.1);
this->MoveSphereSource->Update();
this->MoveMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
this->MoveMapper->SetInputConnection(
this->MoveSphereSource->GetOutputPort());
this->MoveActor = vtkSmartPointer<vtkActor>::New();
this->MoveActor->SetMapper(this->MoveMapper);
this->MoveActor->GetProperty()->SetColor(
this->color->GetColor3d("Pink").GetData());
// this->MoveActor->VisibilityOff();
this->Move = false;
}
void OnMouseMove() override
{
if (!this->Move)
{
return;
}
vtkInteractorStyleTrackballActor::OnMouseMove();
}
void OnMiddleButtonUp() override
{
// Forward events
vtkInteractorStyleTrackballActor::OnMiddleButtonUp();
this->Move = false;
this->MoveActor->VisibilityOff();
this->Data->GetPoints()->SetPoint(this->SelectedPoint,
this->MoveActor->GetPosition());
this->Data->Modified();
this->GetCurrentRenderer()->Render();
this->GetCurrentRenderer()->GetRenderWindow()->Render();
}
void OnMiddleButtonDown() override
{
// Forward events
vtkInteractorStyleTrackballActor::OnMiddleButtonDown();
this->MoveActor->VisibilityOn();
if (static_cast<vtkCellPicker*>(this->InteractionPicker)->GetPointId() >= 0)
{
vtkIdType id =
dynamic_cast<vtkIdTypeArray*>(
this->GlyphData->GetPointData()->GetArray("InputPointIds"))
->GetValue(static_cast<vtkCellPicker*>(this->InteractionPicker)->GetPointId());
std::cout << "Id: " << id << std::endl;
this->Move = true;
this->SelectedPoint = id;
double p[3];
this->Data->GetPoint(id, p);
std::cout << "p: " << p[0] << " " << p[1] << " " << p[2] << std::endl;
this->MoveActor->SetPosition(p);
}
this->GetCurrentRenderer()->AddActor(this->MoveActor);
this->InteractionProp = this->MoveActor;
}
vtkNew<vtkNamedColors> color;
vtkPolyData* Data;
vtkPolyData* GlyphData;
vtkSmartPointer<vtkPolyDataMapper> MoveMapper;
vtkSmartPointer<vtkActor> MoveActor;
vtkSmartPointer<vtkSphereSource> MoveSphereSource;
bool Move;
vtkIdType SelectedPoint;
};
vtkStandardNewMacro(InteractorStyleMoveGlyph);
} // namespace
But I get an error in the last line of my function:
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);
// Set the custom stype to use for interaction.
vtkNew<InteractorStyleMoveGlyph> style;
viewer->getRenderWindow()->GetInteractor()->SetInteractorStyle(style);
style->Data = polyData;
style->GlyphData = pointMapper.GetOutput();
}
The error is here:
style->GlyphData = pointMapper.GetOutput();
I have tried to find the equivalent of getting the output but couldn’t find any