level 3
文刀问道666
楼主
举个例子
class MouseInteractorStyle2 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle2* New();
vtkTypeMacro(MouseInteractorStyle2, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown()
{
int* clickPos = this->GetInteractor()->GetEventPosition();
// Pick from this location.
vtkSmartPointer<vtkPropPicker> picker =
vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
double* pos = picker->GetPickPosition();
std::cout << "Pick position (world coordinates) is: "
<< pos[0] << " " << pos[1]
<< " " << pos[2] << std::endl;
std::cout << "Picked actor: " << picker->GetActor() << std::endl;
//Create a sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(pos[0], pos[1], pos[2]);
sphereSource->SetRadius(1);
//Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1, 0, 0);
//this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetDefaultRenderer()->AddActor(actor);
this->GetDefaultRenderer()->AddActor(actor);
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
private:
};
vtkStandardNewMacro(MouseInteractorStyle2);
将其中的坐标信息提取出来使用,求大神指导
2017年06月14日 01点06分
1
class MouseInteractorStyle2 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle2* New();
vtkTypeMacro(MouseInteractorStyle2, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown()
{
int* clickPos = this->GetInteractor()->GetEventPosition();
// Pick from this location.
vtkSmartPointer<vtkPropPicker> picker =
vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
double* pos = picker->GetPickPosition();
std::cout << "Pick position (world coordinates) is: "
<< pos[0] << " " << pos[1]
<< " " << pos[2] << std::endl;
std::cout << "Picked actor: " << picker->GetActor() << std::endl;
//Create a sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(pos[0], pos[1], pos[2]);
sphereSource->SetRadius(1);
//Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1, 0, 0);
//this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetDefaultRenderer()->AddActor(actor);
this->GetDefaultRenderer()->AddActor(actor);
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
private:
};
vtkStandardNewMacro(MouseInteractorStyle2);
将其中的坐标信息提取出来使用,求大神指导