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
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();
获取当前鼠标位置,然后鼠标移动获取下一位置,然后画线,目前发现线起点总是 在右侧不知道为什么,求大佬指导!
