Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 以编程方式选择vtk小部件_C++_Image Processing_Visual C++_Mfc_Vtk - Fatal编程技术网

C++ 以编程方式选择vtk小部件

C++ 以编程方式选择vtk小部件,c++,image-processing,visual-c++,mfc,vtk,C++,Image Processing,Visual C++,Mfc,Vtk,我正在努力实现VTK小部件的基本功能:选择和删除 我有一个VTKDistance小部件。在我创建之后,我打算点击他的手柄(见下图): 为了选择它,修改它并最终删除它。事实上,我不知道这个小部件何时被选中。如果我使用选择器: vtkPropPicker* pPicker = vtkPropPicker::New(); pPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer); TRACE("Pointer: %p\n", pPick

我正在努力实现VTK小部件的基本功能:选择和删除

我有一个VTKDistance小部件。在我创建之后,我打算点击他的手柄(见下图):

为了选择它,修改它并最终删除它。事实上,我不知道这个小部件何时被选中。如果我使用选择器:

vtkPropPicker* pPicker = vtkPropPicker::New();
pPicker->Pick(nPosition[0], nPosition[1], 0, m_pRenderer);
TRACE("Pointer: %p\n", pPicker->GetProp3D());
当我单击小部件句柄时,跟踪不会执行,但当我单击其余窗口中的任何位置时,跟踪是可见的

另外,第二次尝试,我尝试了回调:

void CVTKDoc::CreateDistanceWidget(CVTKView* pView)
{
vtkDistanceWidget* pDistanceWidget = vtkDistanceWidget::New();
pDistanceWidget->SetInteractor(pView->m_pInteractor);
// Create the default widget representation and set the label format
pDistanceWidget->CreateDefaultRepresentation();
static_cast<vtkDistanceRepresentation*>(pDistanceWidget->GetRepresentation())->SetLabelFormat(_T("%-#6.3g mm"));
// Allow the observer to access the widget
vtkCallbackCommand* pKeypressCallback = vtkCallbackCommand::New();
pKeypressCallback->SetCallback(&CVTKDoc::LeftButtonPressEvent);
pKeypressCallback->SetClientData(pDistanceWidget);
pDistanceWidget->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, pKeypressCallback);
pDistanceWidget->On();
// Add widget pointer to map to cleanup later
if (NULL != pDistanceWidget)
    InsertWidgetToMap(pView, pDistanceWidget);
pKeypressCallback->Delete();
}
void CVTKDoc::CreateDistanceWidget(CVTKView*pView)
{
vtkDistanceWidget*pDistanceWidget=vtkDistanceWidget::New();
pDistanceWidget->setinteractior(pView->m_pinteractior);
//创建默认小部件表示并设置标签格式
pDistanceWidget->CreateDefaultRepresentation();
静态转换(pDistanceWidget->GetRepresentation())->SetLabelFormat(_T(“%-#6.3g mm”);
//允许观察者访问小部件
vtkCallbackCommand*pKeypressCallback=vtkCallbackCommand::New();
pKeypressCallback->SetCallback(&CVTKDoc::LeftButtonPressEvent);
pKeypressCallback->SetClientData(pDistanceWidget);
pDistanceWidget->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent,pKeypressCallback);
pDistanceWidget->On();
//添加小部件指针以映射到以后的清理
if(NULL!=pDistanceWidget)
InsertWidgetOMAP(pView、pDistanceWidget);
pKeypressCallback->Delete();
}
然后(静态法)

void-CVTKDoc::KeypressCallbackFunction(vtkObject*调用者、长未签名int-eventId、void*clientData、void*callData)
{
CVTKDoc*pDoc=CVTKDoc::GetDoc();
vtkRenderWindowInteractor*pInteractor=静态_转换(调用者);
CString sKey=pInteractor->GetKeySym();
跟踪(“>>>%s\n”,sKey);
}
每次按下左按钮时,我都会看到跟踪,但是当我按下小部件手柄上的按钮时,回调函数根本不会执行,就像第一个解决方案中一样

我如何知道何时单击小部件句柄?

请显示a。您是否查看了vtk示例(例如)?请显示a。您是否查看了vtk示例(例如)?
void CVTKDoc::KeypressCallbackFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData)
{
CVTKDoc* pDoc = CVTKDoc::GetDoc();
vtkRenderWindowInteractor* pInteractor = static_cast<vtkRenderWindowInteractor*>(caller);
CString sKey = pInteractor->GetKeySym();
TRACE(">>>%s\n", sKey);
}