[vtkusers] Problem when using vtkDistanceWidget in MFC
Huoling Luo
shuiling119 at hotmail.com
Wed Apr 13 01:17:19 EDT 2011
Hello vtk users,
I use vtkDistanceWidget combining with MFC to process distance measurement, and I encountered a strange problem.
vtkImageViewer2 is used to display an image, which is a data member of CVtkView (CVtkView is derived from CView). vtkRenderWindow and vtkRenderWindowInteractor are also the data members of CVtkView. I wrote a new class named DistanceWidgetObserver, the code is:
// DistanceWidgetObserver.hclass DistanceWidgetObserver : public vtkCommand {public: DistanceWidgetObserver(vtkImageViewer2* pViewer, vtkDistanceWidget* pDistanceWidget); static DistanceWidgetObserver* New(vtkImageViewer2* pViewer, vtkDistanceWidget* pDistanceWidget) { return new DistanceWidgetObserver(pViewer, pDistanceWidget); }
protected: ~DistanceWidgetObserver();
vtkImageViewer2* m_pViewer; vtkDistanceWidget* m_pDistanceWidget; vtkDistanceRepresentation2D* m_pDistanceRep; vtkPointHandleRepresentation2D* m_pPointHandleRep;
private: void Execute(vtkObject *caller, unsigned long, void*);};
// DistanceWidgetObserver.cppDistanceWidgetObserver::DistanceWidgetObserver(vtkImageViewer2* pViewer, vtkDistanceWidget* pDistanceWidget){ m_pViewer = pViewer; m_pDistanceWidget = pDistanceWidget; m_pDistanceRep = vtkDistanceRepresentation2D::New(); m_pPointHandleRep = vtkPointHandleRepresentation2D::New();}
DistanceWidgetObserver::~DistanceWidgetObserver(){...}
void DistanceWidgetObserver::Execute(vtkObject *caller, unsigned long ulCommand, void*) { m_pDistanceWidget->SetInteractor(m_pViewer->GetRenderWindow()->GetInteractor()); m_pDistanceWidget->CreateDefaultRepresentation();
m_pPointHandleRep->GetProperty()->SetColor(1,0,0); m_pDistanceRep->SetHandleRepresentation(m_pPointHandleRep);
m_pDistanceRep->GetAxis()->SetNumberOfMinorTicks(4); m_pDistanceRep->GetAxis()->SetTickLength(5); m_pDistanceRep->GetAxis()->SetTitlePosition(0.5); m_pDistanceRep->RulerModeOn(); m_pDistanceRep->SetRulerDistance(10);
m_pDistanceWidget->SetRepresentation(m_pDistanceRep); static_cast<vtkDistanceRepresentation *>(m_pDistanceWidget->GetRepresentation()) ->SetLabelFormat("%-#.2f mm");}
Then I use DistanceWidgetObserver to instantiate a member in CVtkView, And in the function OnDraw() I wrote the following code:
// OnDraw() code:void CVtkView::OnDraw(){ ... m_pDistanceObserver = DistanceWidgetObserver::New(m_pImageViewer, m_pDistanceWidget); m_pImageViewer->Render();}
When I run this program and clicked the image, the program crashed.
Anyone knows why is it? If I did wrong, please correct me. Or please give me some tips on this topic of using vtkDistanceWidget combined with MFC.
Regards & thank you
Huoling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110413/780d2182/attachment.htm>
More information about the vtkusers
mailing list