VTK观察者和picker学习--从源码中找解决方案
2010-05-07 00:23
302 查看
想实现如此一个功能,render中有数个actor,用鼠标点选其中一个时实现高亮通知!
首先能想到的当然是用picker,看看guid中的说明,这里似乎要用到propPicker,可惜并没找到专门对应于picker的实例,怎么使用呢?一头雾水。。。(这时就产生的畏惧心理,群里问了也没人搭理,只好硬着头皮写了,现在想来遇到问题首先是不能怕了!!)
纠结良久后,终于想着还是自己试着写吧,随便看了看文档,就看到有vtkPropPicker::GetActor()方法,想想有思路了开始行动吧~
第一篇:picker拾取并高亮通知
步骤一:先随便插入几个actor,用Source做为数据源~给上不同的Position和color~
步骤二:给propPicker添加observer,先查看propPicker和事件,感觉应该使用vtkCommand::EndPickEvent
写回调函数,这个简单直接调用GetActor()方法,然后通过vtkActor::GetProperty()->SetColor()变色
//回调
class vtkPickCallback : public vtkCommand
{
public:
static vtkPickCallback *New()
{ return new vtkPickCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkPropPicker *picker = reinterpret_cast<vtkPropPicker*>(caller);
vtkActor *pickActor = picker->GetActor();
if (pickActor != 0)
{
pickActor->GetProperty()->SetColor(1.0,0.0,0.0);
}
}
};
//add picker and Observer
vtkPropPicker *picker = vtkPropPicker::New();
vtkPickCallback *myCallback = vtkPickCallback::New();
picker->AddObserver(vtkCommand::EndPickEvent, myCallback);
编译调试。。。。按p拾取,没反应,在回调中加断点,无法进入。。。后来又仔细看了遍文档发现原来RenderWindowInteractor里面有内置的picker,也就是说一直以来都是那个内置的picker的EndPickEvent被触发了~添加iren->SetPicker(picker);
OK一切正常,心中一阵窃喜,没想到如此简单就完成一半的工作了,看来还是要真正自己动手啦~
第二篇:鼠标点选触发picker拾取事件
当然这样还是不行的,用p才能拾取交互性也太差了~下面要做的就是实现鼠标点选拾取,看来要给LeftButtonPressEvent添加observer
步骤三
先设计回调函数,从文档中查到,RenderWindowInteractor::InvokeEvent()方法,可以通过程序来手动添加事件(新手就是要多查文档,看书查出来,领悟出来的东西往往是最容易掌握的),具体使用方法如下:
class vtkButtonCallback : public vtkCommand
{
public:
static vtkButtonCallback *New()
{ return new vtkButtonCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
int *pos = new int[2];
iren->SetKeyCode('p');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
//虽然可以InvokeEvent,但每次启动时都必须先,按下任一快捷键(如't'),才能够真正触发事件!
}
};
//Add observer
vtkButtonCallback *myBtnCallback = vtkButtonCallback::New();
iren->AddObserver(vtkCommand:
eftButtonPressEvent, myBtnCallback);
编译。。运行。。鼠标点击无反应。。vtkButtonCallback 中加断点,能进入;vtkPickCallback 加断点,无法进入。。单步调试后发现,iren->InvokeEvent()可以进入,感觉像是把事件添加到事件堆栈,但并没有触发它。。
无意中按到T键(想换成traceball模式呢),再鼠标点选,可以实现picker,为什么呢?百思不得其解。。
中间是一个多小时的调试,加入一系列的,iren->render,updata之类的刷新方法,无果。。。。。。
第三篇:直接鼠标点选实现拾取[核心]
下面到核心内容了!!
步骤四 学习vtk源码的写法
突然想到有这样一种交互style叫做vtkInteractorStyleTrackballActor和vtkInteractorStyleJoystickActor,它实际上是可以实现鼠标点选每个Actor来对其旋转缩放的,它是如何实现的呢,首先打开头文件,发现里面有
virtual void OnMouseMove();
virtual void OnLeftButtonDown();
virtual void OnLeftButtonUp();
virtual void OnMiddleButtonDown();
virtual void OnMiddleButtonUp();
virtual void OnRightButtonDown();
virtual void OnRightButtonUp();
等一系列方法,转到定义?还在原地,想到定义在lib和dll中汗了一下~马上去找源文件,还好没删~找到我主要关注的OnLeftButtonDown();方法的实现
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballActor::OnLeftButtonDown()
{
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);
this->FindPickedActor(x, y);
if (this->CurrentRenderer == NULL || this->InteractionProp == NULL)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
if (this->Interactor->GetShiftKey())
{
this->StartPan();
}
else if (this->Interactor->GetControlKey())
{
this->StartSpin();
}
else
{
this->StartRotate();
}
}
显然 this->FindPokedRenderer(x, y);
this->FindPickedActor(x, y);
这两句是我所需要的!马上打到这两个方法的实现:(FindPokedRenderer()为vtkRenderWindowInteractor的方法,可以直接调用)
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballActor::FindPickedActor(int x, int y)
{
this->InteractionPicker->pick(x, y, 0.0, this->CurrentRenderer);
vtkProp *prop = this->InteractionPicker->GetViewProp();
if (prop != NULL)
{
this->InteractionProp = vtkProp3D::SafeDownCast(prop);
}
else
{
this->InteractionProp = NULL;
}
}
看看代码也不难嘛~好了着手改写~
步骤五
直接为vtkRenderWindowInteractor的LeftButtonPressEvent事件添加Observer,结合源码设计回调函数:
class vtkButtonCallback : public vtkCommand
{
public:
static vtkButtonCallback *New()
{ return new vtkButtonCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
int x = iren->GetEventPosition()[0];
int y = iren->GetEventPosition()[1];
vtkRenderer *CurrentRenderer = iren->FindPokedRenderer(x,y);
vtkCellPicker *Picker = vtkCellPicker::SafeDownCast(iren->GetPicker());
Picker->pick(x, y, 0.0, CurrentRenderer);
vtkProp *prop = Picker->GetViewProp();
if (prop != NULL)
{
vtkActor *InteractionProp = vtkActor::SafeDownCast(prop);
InteractionProp->GetProperty()->SetColor(1.0,0.0,0.0);
}
}
};
//Add Observer
vtkButtonCallback *myBtnCallback = vtkButtonCallback::New();
iren->AddObserver(vtkCommand:leftButtonPressEvent, myBtnCallback);
编译。。运行。。点击。。高亮~很完美,而且没有了picker时会出来的六面体边框
后记:一直以来对vtk的封装是又爱又恨,相对于opengl要自己写交互操作来说,vtk确实是方便不少~但高度封装的弊端就是定制性差。
群里,论坛里也经常会有人问,怎样屏蔽鼠标的旋转事件呀?怎样去掉鼠标对imageview的窗高的调整呀。。。这些不都是受vtk的默认的操控方式所累嘛~
但好在vtk的command/observer模式,能够让我们很方便的截获需要自己定制的事件,话说我们可以对vtkInteractorStyle进行重载,然后对通过vtkRenderWindowInteractor::SetInteractorStyle()方法实现对交互方案重新设计,还不满意?你甚至可以自己写一个类似于vtkInteractorStyle类,只要能对应上vtkRenderWindowInteractor的相应接口,这样是不是有点opengl的感觉
。
现在看来可以这样理解,vtk所给我们提供的那些InteractorStyle实际上只是为我们提供了一类范本,范本虽好,但肯定是不可能满足所有五花八门的需求的~所以不要太迷恋那些style,大胆的observer,大胆的重载吧~
PS:写到后面发现有点偏离主题了。。。反正核心思想是两个:一,从源码中学习,不仅规范,安全不易出错,而且常常是最佳的解决方案;二,不要被原有的东西所束缚,大胆的修改,尝试,大不了重装vtk~
附上代码:
代码如下:
直接添加LeftButtonPressEvent的Observer
首先能想到的当然是用picker,看看guid中的说明,这里似乎要用到propPicker,可惜并没找到专门对应于picker的实例,怎么使用呢?一头雾水。。。(这时就产生的畏惧心理,群里问了也没人搭理,只好硬着头皮写了,现在想来遇到问题首先是不能怕了!!)
纠结良久后,终于想着还是自己试着写吧,随便看了看文档,就看到有vtkPropPicker::GetActor()方法,想想有思路了开始行动吧~
第一篇:picker拾取并高亮通知
步骤一:先随便插入几个actor,用Source做为数据源~给上不同的Position和color~
步骤二:给propPicker添加observer,先查看propPicker和事件,感觉应该使用vtkCommand::EndPickEvent
写回调函数,这个简单直接调用GetActor()方法,然后通过vtkActor::GetProperty()->SetColor()变色
//回调
class vtkPickCallback : public vtkCommand
{
public:
static vtkPickCallback *New()
{ return new vtkPickCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkPropPicker *picker = reinterpret_cast<vtkPropPicker*>(caller);
vtkActor *pickActor = picker->GetActor();
if (pickActor != 0)
{
pickActor->GetProperty()->SetColor(1.0,0.0,0.0);
}
}
};
//add picker and Observer
vtkPropPicker *picker = vtkPropPicker::New();
vtkPickCallback *myCallback = vtkPickCallback::New();
picker->AddObserver(vtkCommand::EndPickEvent, myCallback);
编译调试。。。。按p拾取,没反应,在回调中加断点,无法进入。。。后来又仔细看了遍文档发现原来RenderWindowInteractor里面有内置的picker,也就是说一直以来都是那个内置的picker的EndPickEvent被触发了~添加iren->SetPicker(picker);
OK一切正常,心中一阵窃喜,没想到如此简单就完成一半的工作了,看来还是要真正自己动手啦~
第二篇:鼠标点选触发picker拾取事件
当然这样还是不行的,用p才能拾取交互性也太差了~下面要做的就是实现鼠标点选拾取,看来要给LeftButtonPressEvent添加observer
步骤三
先设计回调函数,从文档中查到,RenderWindowInteractor::InvokeEvent()方法,可以通过程序来手动添加事件(新手就是要多查文档,看书查出来,领悟出来的东西往往是最容易掌握的),具体使用方法如下:
class vtkButtonCallback : public vtkCommand
{
public:
static vtkButtonCallback *New()
{ return new vtkButtonCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
int *pos = new int[2];
iren->SetKeyCode('p');
iren->InvokeEvent(vtkCommand::CharEvent,NULL);
//虽然可以InvokeEvent,但每次启动时都必须先,按下任一快捷键(如't'),才能够真正触发事件!
}
};
//Add observer
vtkButtonCallback *myBtnCallback = vtkButtonCallback::New();
iren->AddObserver(vtkCommand:
eftButtonPressEvent, myBtnCallback);
编译。。运行。。鼠标点击无反应。。vtkButtonCallback 中加断点,能进入;vtkPickCallback 加断点,无法进入。。单步调试后发现,iren->InvokeEvent()可以进入,感觉像是把事件添加到事件堆栈,但并没有触发它。。
无意中按到T键(想换成traceball模式呢),再鼠标点选,可以实现picker,为什么呢?百思不得其解。。
中间是一个多小时的调试,加入一系列的,iren->render,updata之类的刷新方法,无果。。。。。。
第三篇:直接鼠标点选实现拾取[核心]
下面到核心内容了!!
步骤四 学习vtk源码的写法
突然想到有这样一种交互style叫做vtkInteractorStyleTrackballActor和vtkInteractorStyleJoystickActor,它实际上是可以实现鼠标点选每个Actor来对其旋转缩放的,它是如何实现的呢,首先打开头文件,发现里面有
virtual void OnMouseMove();
virtual void OnLeftButtonDown();
virtual void OnLeftButtonUp();
virtual void OnMiddleButtonDown();
virtual void OnMiddleButtonUp();
virtual void OnRightButtonDown();
virtual void OnRightButtonUp();
等一系列方法,转到定义?还在原地,想到定义在lib和dll中汗了一下~马上去找源文件,还好没删~找到我主要关注的OnLeftButtonDown();方法的实现
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballActor::OnLeftButtonDown()
{
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);
this->FindPickedActor(x, y);
if (this->CurrentRenderer == NULL || this->InteractionProp == NULL)
{
return;
}
this->GrabFocus(this->EventCallbackCommand);
if (this->Interactor->GetShiftKey())
{
this->StartPan();
}
else if (this->Interactor->GetControlKey())
{
this->StartSpin();
}
else
{
this->StartRotate();
}
}
显然 this->FindPokedRenderer(x, y);
this->FindPickedActor(x, y);
这两句是我所需要的!马上打到这两个方法的实现:(FindPokedRenderer()为vtkRenderWindowInteractor的方法,可以直接调用)
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballActor::FindPickedActor(int x, int y)
{
this->InteractionPicker->pick(x, y, 0.0, this->CurrentRenderer);
vtkProp *prop = this->InteractionPicker->GetViewProp();
if (prop != NULL)
{
this->InteractionProp = vtkProp3D::SafeDownCast(prop);
}
else
{
this->InteractionProp = NULL;
}
}
看看代码也不难嘛~好了着手改写~
步骤五
直接为vtkRenderWindowInteractor的LeftButtonPressEvent事件添加Observer,结合源码设计回调函数:
class vtkButtonCallback : public vtkCommand
{
public:
static vtkButtonCallback *New()
{ return new vtkButtonCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
int x = iren->GetEventPosition()[0];
int y = iren->GetEventPosition()[1];
vtkRenderer *CurrentRenderer = iren->FindPokedRenderer(x,y);
vtkCellPicker *Picker = vtkCellPicker::SafeDownCast(iren->GetPicker());
Picker->pick(x, y, 0.0, CurrentRenderer);
vtkProp *prop = Picker->GetViewProp();
if (prop != NULL)
{
vtkActor *InteractionProp = vtkActor::SafeDownCast(prop);
InteractionProp->GetProperty()->SetColor(1.0,0.0,0.0);
}
}
};
//Add Observer
vtkButtonCallback *myBtnCallback = vtkButtonCallback::New();
iren->AddObserver(vtkCommand:leftButtonPressEvent, myBtnCallback);
编译。。运行。。点击。。高亮~很完美,而且没有了picker时会出来的六面体边框
后记:一直以来对vtk的封装是又爱又恨,相对于opengl要自己写交互操作来说,vtk确实是方便不少~但高度封装的弊端就是定制性差。
群里,论坛里也经常会有人问,怎样屏蔽鼠标的旋转事件呀?怎样去掉鼠标对imageview的窗高的调整呀。。。这些不都是受vtk的默认的操控方式所累嘛~
但好在vtk的command/observer模式,能够让我们很方便的截获需要自己定制的事件,话说我们可以对vtkInteractorStyle进行重载,然后对通过vtkRenderWindowInteractor::SetInteractorStyle()方法实现对交互方案重新设计,还不满意?你甚至可以自己写一个类似于vtkInteractorStyle类,只要能对应上vtkRenderWindowInteractor的相应接口,这样是不是有点opengl的感觉
。
现在看来可以这样理解,vtk所给我们提供的那些InteractorStyle实际上只是为我们提供了一类范本,范本虽好,但肯定是不可能满足所有五花八门的需求的~所以不要太迷恋那些style,大胆的observer,大胆的重载吧~
PS:写到后面发现有点偏离主题了。。。反正核心思想是两个:一,从源码中学习,不仅规范,安全不易出错,而且常常是最佳的解决方案;二,不要被原有的东西所束缚,大胆的修改,尝试,大不了重装vtk~
附上代码:
通过给EndPickEvent和LeftButtonPressEvent添加Observer
这种解决方案的弊端是事件不知道如何触发,有高手知道如何解决的么?代码如下:
#include <vtkSphereSource.h> #include "vtkPolyDataMapper.h" #include "vtkActor.h" #include <vtkCubeSource.h> #include <vtkConeSource.h> #include "vtkCylinderSource.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkProperty.h" #include <vtkAbstractPicker.h> #include <vtkPropPicker.h> #include <vtkCommand.h> #include <iostream> #include <vtkAbstractPropPicker.h> #include <vtkInteractorStyleTrackballCamera.h> vtkInteractorStyleTrackballCamera *style/* = vtkInteractorStyleTrackballCamera::New()*/; class vtkPickCallback : public vtkCommand { public: static vtkPickCallback *New() { return new vtkPickCallback; } virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkPropPicker *picker = reinterpret_cast<vtkPropPicker*>(caller); vtkActor *pickActor = picker->GetActor(); if (pickActor != 0) { pickActor->GetProperty()->SetColor(1.0,0.0,0.0); } } }; class vtkButtonCallback : public vtkCommand { public: static vtkButtonCallback *New() { return new vtkButtonCallback; } virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller); int *pos = new int[2]; iren->SetKeyCode('p'); iren->InvokeEvent(vtkCommand::CharEvent,NULL); iren->Render(); //虽然可以InvokeEvent,但每次启动时都必须先,按下任一快捷键(如't'),才能够真正触发事件! } }; int main() { //add four actor from source vtkSphereSource *sphere = vtkSphereSource::New(); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInputConnection(sphere->GetOutputPort()); vtkActor *sphereActor = vtkActor::New(); sphereActor->SetMapper( sphereMapper); sphereActor-> SetOrigin(-4 ,1 ,0); sphereActor->RotateY(6); sphereActor->SetPosition(2.25 ,0 ,0); sphereActor->GetProperty()->SetColor(1 ,0 ,1); vtkCubeSource *cube = vtkCubeSource::New(); vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New(); cubeMapper->SetInputConnection(cube->GetOutputPort()); vtkActor *cubeActor =vtkActor::New(); cubeActor->SetMapper(cubeMapper); cubeActor->SetPosition( 0.0 ,0.25 ,0); cubeActor->GetProperty()->SetColor( 0 ,0 ,1); vtkConeSource *cone = vtkConeSource::New(); vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection(cone->GetOutputPort()); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper (coneMapper); coneActor->SetPosition (4 ,0 ,0.25); coneActor->GetProperty()->SetColor( 0 ,1 ,0); vtkCylinderSource *cylinder = vtkCylinderSource::New(); vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New(); cylinderMapper->SetInputConnection( cylinder->GetOutputPort()); cylinderMapper->SetResolveCoincidentTopologyToPolygonOffset();// vtkActor *cylinderActor = vtkActor::New(); cylinderActor->SetMapper( cylinderMapper); cylinderActor->SetPosition(1,2,4); cylinderActor->GetProperty()->SetColor( 1 ,1 ,0); //confiner Interactor vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); //添加这个后,InvokeEvent也能成功,但picker事件无法触发?? //change InteractorStyle //vtkInteractorStyleTrackballCamera/vtkInteractorStyleTrackballActor //vtkInteractorStyleJoystickActor/vtkInteractorStyleJoystickCamera //vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New(); // style = vtkInteractorStyleTrackballCamera::New(); // iren->SetInteractorStyle(style); //add picker and Observer vtkPropPicker *picker = vtkPropPicker::New(); iren->SetPicker(picker); vtkPickCallback *myCallback = vtkPickCallback::New(); picker->AddObserver(vtkCommand::EndPickEvent, myCallback); //add Observer vtkButtonCallback *myBtnCallback = vtkButtonCallback::New(); iren->AddObserver(vtkCommand::LeftButtonPressEvent, myBtnCallback); //add actor and render ren1->AddActor(sphereActor); ren1->AddActor(coneActor); ren1->AddActor(cubeActor); ren1->AddActor(cylinderActor); ren1->SetBackground(0.1, 0.2, 0.4); renWin->SetSize(500, 500); iren->Initialize(); iren->Start(); //delete(part) ren1->Delete(); renWin->Delete(); iren->Delete(); }
直接添加LeftButtonPressEvent的Observer
#include <vtkSphereSource.h> #include "vtkPolyDataMapper.h" #include "vtkActor.h" #include <vtkCubeSource.h> #include <vtkConeSource.h> #include "vtkCylinderSource.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkProperty.h" #include <vtkCommand.h> #include <iostream> #include <vtkAbstractPropPicker.h> #include <vtkInteractorStyleTrackballCamera.h> #include "vtkCellPicker.h" class vtkButtonCallback : public vtkCommand { public: static vtkButtonCallback *New() { return new vtkButtonCallback; } virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkRenderWindowInteractor *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller); int x = iren->GetEventPosition()[0]; int y = iren->GetEventPosition()[1]; vtkRenderer *CurrentRenderer = iren->FindPokedRenderer(x,y); vtkCellPicker *Picker = vtkCellPicker::SafeDownCast(iren->GetPicker()); Picker->Pick(x, y, 0.0, CurrentRenderer); vtkProp *prop = Picker->GetViewProp(); if (prop != NULL) { vtkActor *InteractionProp = vtkActor::SafeDownCast(prop); InteractionProp->GetProperty()->SetColor(1.0,0.0,0.0); } } }; int main() { //add four actor from source vtkSphereSource *sphere = vtkSphereSource::New(); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInputConnection(sphere->GetOutputPort()); vtkActor *sphereActor = vtkActor::New(); sphereActor->SetMapper( sphereMapper); sphereActor-> SetOrigin(-4 ,1 ,0); sphereActor->RotateY(6); sphereActor->SetPosition(2.25 ,0 ,0); sphereActor->GetProperty()->SetColor(1 ,0 ,1); vtkCubeSource *cube = vtkCubeSource::New(); vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New(); cubeMapper->SetInputConnection(cube->GetOutputPort()); vtkActor *cubeActor =vtkActor::New(); cubeActor->SetMapper(cubeMapper); cubeActor->SetPosition( 0.0 ,0.25 ,0); cubeActor->GetProperty()->SetColor( 0 ,0 ,1); vtkConeSource *cone = vtkConeSource::New(); vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection(cone->GetOutputPort()); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper (coneMapper); coneActor->SetPosition (4 ,0 ,0.25); coneActor->GetProperty()->SetColor( 0 ,1 ,0); vtkCylinderSource *cylinder = vtkCylinderSource::New(); vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New(); cylinderMapper->SetInputConnection( cylinder->GetOutputPort()); cylinderMapper->SetResolveCoincidentTopologyToPolygonOffset();// vtkActor *cylinderActor = vtkActor::New(); cylinderActor->SetMapper( cylinderMapper); cylinderActor->SetPosition(1,2,4); cylinderActor->GetProperty()->SetColor( 1 ,1 ,0); //confiner Interactor vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); //change InteractorStyle //vtkInteractorStyleTrackballCamera/vtkInteractorStyleTrackballActor //vtkInteractorStyleJoystickActor/vtkInteractorStyleJoystickCamera vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New(); iren->SetInteractorStyle(style); //add picker and Observer vtkCellPicker *InteractionPicker = vtkCellPicker::New(); iren->SetPicker(InteractionPicker); //add Observer vtkButtonCallback *myBtnCallback = vtkButtonCallback::New(); iren->AddObserver(vtkCommand::LeftButtonPressEvent, myBtnCallback); //add actor and render ren1->AddActor(sphereActor); ren1->AddActor(coneActor); ren1->AddActor(cubeActor); ren1->AddActor(cylinderActor); ren1->SetBackground(0.1, 0.2, 0.4); renWin->SetSize(500, 500); iren->Initialize(); iren->Start(); //delete(part) ren1->Delete(); renWin->Delete(); iren->Delete(); }
相关文章推荐
- Android源码学习之观察者模式应用
- SlideDateTimePicker 源码学习
- 【30分钟学习】二种简单实用的方法实现多语言解决方案(源码在附件)
- spring源码学习之:项目公共配置项解决方案
- junit源码学习--观察者模式
- TimePicker源码学习-TimePicker的结构
- 基于设计模式的学习之旅-----观察者模式(附源码)
- Android源码学习之观察者模式应用
- VTK学习笔记1—VTK安装及源码编译(Winxp + VS2010 + CMake2.8.6 + VTK5.8)
- 【spring源码学习】spring的aop目标对象中进行自我调用,且需要实施相应的事务定义的解决方案
- CassiniDev源码学习 - 可替代IIS的单机Web Form解决方案
- Android源码学习之观察者模式应用及优点介绍
- CassiniDev源码学习 - 可替代IIS的单机Web Form解决方案
- vtkPropPicker无法拾取vtkRenderer中的vtkLineSource的解决方案
- 源码推荐(0710B):基于Block的系统PickerImageController的封装,简单的搜索标签
- 共同学习Java源码--常用数据类型--String(四)
- Spring源码学习-容器初始化之FileSystemXmlApplicationContext(一)构造函数 推荐
- 结合redis设计与实现的redis源码学习-9-zipmap(压缩图)
- memcached源码学习-总结篇
- spark源码学习