请教各位大佬 我想用vtk实现 鼠标左键画曲线 出现问题
vtk吧
全部回复
仅看楼主
level 3
艾尔格力 楼主
我想用鼠标画曲线,就是一段段 直线连接成曲线,代码如下:
double x = this->Interactor->GetEventPosition()[0];//xy是否是不断变化的?
double y = this->Interactor->GetEventPosition()[1];
/*int x = this->Interactor->GetMousePosition;
int y = this->Interactor->GetEventPosition;*/
double worldpos[4];
vtkPoints* points1 = vtkPoints::New();
this->ComputeDisplayToWorld(x, y, 0, worldpos);
points1->InsertNextPoint(worldpos[0], worldpos[1], worldpos[2]);//points1得到的是一个点还是很多点?
for (int i=0;i<points1->GetNumberOfPoints();i++)
{vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(points1->GetPoint(i));
lineSource->SetPoint2(points1->GetPoint(i+1));
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(lineSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor1 = vtkSmartPointer<vtkActor>::New();
actor1->SetMapper(mapper);
actor1->GetProperty()->SetColor(1.0, 0.0, 0.0);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(actor1);
renderer->GetRenderWindow()->GetInteractor()->Initialize();
renderer->GetRenderWindow()->GetInteractor()->Render();
获取当前鼠标位置,然后鼠标移动获取下一位置,然后画线,目前发现线起点总是 在右侧不知道为什么,求大佬指导!
2018年07月10日 15点07分 1
level 3
艾尔格力 楼主
没人就自己顶一顶
2018年07月10日 15点07分 2
level 3
艾尔格力 楼主
再顶一顶

2018年07月11日 01点07分 3
level 7
int* clickPos = this->GetInteractor()->GetEventPosition();
this->GetInteractor()->GetPicker()->Pick(clickPos[0], clickPos[1], 0, render);
这样来获取点坐标试试
2018年07月11日 07点07分 4
level 3
艾尔格力 楼主
多谢大佬!!
2018年07月20日 00点07分 5
1