vtkObject继承vtkObjectBase ,增加了一个MTime为数据最新的修改时间戳。
中的vtkBaseTypeMacro表示当前类与父类的关系,便于在vtk调试中使用。
vtkWeakPointer是vtkObjectBase的指针,跟随物体销毁而内存位置清零重置。多次引用不影响vtkWeakPointer的值。内存地址不变化。
DebugOn,调试开关,程序出错时会显示错误信息。
Modified()表示手动调用实现修改数据。
GetMTime()得当修改时间。
RemoveObserver(unsigned long tag);删除观察者或者命令或者事件,跟C#中的委托事件相似,取掉触发关系,一般与vtkCommand结合使用。参数为定义的vtkCommand的值。
void InternalGrabFocus(vtkCommand* mouseEvents, vtkCommand* keypressEvents = nullptr);
void InternalReleaseFocus();
上述两个方法允许或者释放完全专有的控制所有事件。
举个例子。如下。
class GraphAnimate : public vtkCommand { public: static GraphAnimate* New() { return new GraphAnimate(); } vtkTypeMacro(GraphAnimate, vtkCommand); void Execute(vtkObject*, unsigned long, void*) override//vtkcommand子类中必须重写执行内容方法。 { this->GraphItem->UpdatePositions(); this->View->Render(); this->View->GetRenderWindow()->GetInteractor()->CreateOneShotTimer(10); } vtkGraphItem* GraphItem; vtkContextView* View; }; //------------------------------------------------------------------------------ int main(int, char*[]) { // Set up a 2D context view, context test object and add it to the scene vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New(); view->GetRenderer()->SetBackground(1.0, 1.0, 1.0); view->GetRenderWindow()->SetSize(800, 600); vtkSmartPointer<vtkRandomGraphSource> source = vtkSmartPointer<vtkRandomGraphSource>::New(); source->SetNumberOfVertices(100); source->SetNumberOfEdges(0); source->StartWithTreeOn(); source->Update(); vtkSmartPointer<vtkGraphItem> item = vtkSmartPointer<vtkGraphItem>::New(); item->SetGraph(source->GetOutput()); view->GetScene()->AddItem(item); vtkSmartPointer<GraphAnimate> anim = vtkSmartPointer<GraphAnimate>::New(); anim->View = view; anim->GraphItem = item; view->GetRenderWindow()->GetInteractor()->Initialize(); view->GetRenderWindow()->GetInteractor()->CreateOneShotTimer(10); view->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::TimerEvent, anim); view->GetRenderWindow()->GetInteractor()->Start(); }