#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkSmartPointer.h>
#include <vtkPointPicker.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkNamedColors.h>
#include <vtkObjectFactory.h>
#include<vtkLine.h>
#include<vtkProperty.h>
#include<vtkPolyLine.h>
#include<vtkUnstructuredGrid.h>
#include<vtkDataSetMapper.h>
#include<vtkLineSource.h>
#include<vtkRendererCollection.h>
#include<vtkCellPicker.h>
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
// Define interaction style
vtkSmartPointer<vtkRenderer> renderer;
double point1[3]{ 0 };
double point2[3]{ 0 };
double WorldPoint[3]{ 0 };
double WorldPoint1[3]{ 0 };
int *clickPos;
int *clickPos1;
int *movePos;
vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkActor> actor1 = vtkSmartPointer<vtkActor>::New();
class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static customMouseInteractorStyle* New();
vtkTypeMacro(customMouseInteractorStyle, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown()
{
std::cout << "Pressed left mouse button." << std::endl;
// Forward events
// vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
// int* clickPos = this->GetInteractor()->GetEventPosition();
clickPos = this->GetInteractor()->GetEventPosition();
point1[0] = clickPos[0];
point1[1] = clickPos[1];
renderer->SetDisplayPoint(point1[0], point1[1], 0);
renderer->DisplayToWorld();
WorldPoint[0] = (renderer->GetWorldPoint())[0];
WorldPoint[1] = (renderer->GetWorldPoint())[1];
WorldPoint[2] = (renderer->GetWorldPoint())[2];
// double* worldPosition = picker->GetPickPosition();
// std::cout << worldPosition[0] << "\t" << worldPosition[1] << std::endl;
// std::cout &
vtk随鼠标运动实时画直线
最新推荐文章于 2024-04-11 02:25:25 发布