void CustomVtkInteractorStyleTapeMeasure::StartRotate() {
Superclass::StartRotate();
vtkRenderer* renderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
this->Interactor->GetRenderWindow()->AddRenderer(renderer);
int* clickPos = this->GetInteractor()->GetEventPosition();
vtkAbstractPicker* abstractPicker = this->GetInteractor()->GetPicker();
int pickCode = abstractPicker->Pick(clickPos[0], clickPos[1], 0, renderer);
if (mPicked = pickCode != 0) {
double picked[3];
abstractPicker->GetPickPosition(picked);
vtkNew<vtkActor> vtkPointDisplay;
vtkNew<vtkSphereSource> sphereSource;
sphereSource->Update();
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputData(sphereSource->GetOutput());
vtkPointDisplay->SetMapper(sphereMapper);
vtkPointDisplay->SetPosition(picked);
vtkPointDisplay->SetScale(5,5,5);
mPointsDisplays->AddItem(vtkPointDisplay);
renderer->AddActor(vtkPointDisplay);
mLastPos[0] = picked[0];
mLastPos[1] = picked[1];
mLastPos[2] = picked[2];
if (mPointCount == 0) {
mPoints->InsertNextPoint(picked);
mPointCount++;
}
else
{
mPoints->SetPoint(mPointCount-1, picked);
}
mPoints->InsertNextPoint(picked);
mPointCount++;
mPolyLine->GetPointIds()->SetNumberOfIds(mPointCount);;// 设置点数
for (size_t i = 0; i < mPointCount; i++)
{
mPolyLine->GetPointIds()->SetId(i, i);
//double* point = mPoints->GetPoint(i);
//logger::log("(%f,%f,%f)", point[0], point[1], point[2]);
}
mCells->InsertNextCell(mPolyLine);
mCells->Modified();
mPolyData->SetPoints(mPoints);
mPolyData->SetLines(mCells);
mPolyData->Modified();
//mPolyDataMapper->SetInputData(mPolyData); It didn't have any effect
//mPolyDataMapper->Update();
//mPolyDataMapper->Modified();
//mActor->SetMapper(mPolyDataMapper);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(mPolyData);
mActor->SetMapper(mapper);
mActor->Modified();
Interactor->Render();
}
}
After testing, it was found that updating only the vtkMapper of vtkActor itself without replacing the new vtkPolyDataMapper object after editing vtkPoints has no effect