实际操作中我们经常会用到通过交互操作改变vtkactor的数据vtkpolydata,比如光滑物体某个三角网格,移动某一个线条,或者某一点,而保持其他的不变,简单来说就是在class 中实现对vtkpolydata的重新写入,再使得重新渲染。实现步骤整理如下:
class callbacknew :public vtkCommand
{public:
static callbacknew *New()
{
return new callbacknew;
}
void SetActor(vtkActor * mainActor)
{this->classActor=mainActor;
this->pd=vtkPolyData::SafeDownCast(mainActor->GetMapper()->GetInputAsDataSet());//或者通过建立public函数进行直接赋值也行
}
virtual void Execute(vtkObject *, unsigned long event, void *)
{ if(event == vtkCommand::LeftButtonPressEvent){
//这里常用函数列出来
vtkSmartPointer<vtkIdList>pts = vtkSmartPointer<vtkIdList>::New();
polyda->GetCellPoints(cellid, pts);//不推荐polyda->GetCellPoints(CellId, npt, pIds);
double PointPos[3];
polyda->Ge