-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
103 lines (84 loc) · 3.25 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPlaneWidget.h>
#include <vtkDistanceWidget.h>
#include <vtkDistanceRepresentation.h>
#include <vtkCallbackCommand.h>
#include <vtkPicker.h>
#include <vtk3DWidget.h>
#include <QMouseEvent>
#include <QScreen>
void ClickCallbackFunction(vtkObject *caller, long unsigned eventID, void* clientData, void* callData);
QLabel *vtkLabel;
QLabel *qtLabel;
QLabel *globalLabel;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setMouseTracking(true);
vtkLabel = ui->label;
qtLabel = ui->label_2;
globalLabel = ui->label_3;
}
void MainWindow::initVTK()
{
//QTimer::singleShot(0, [=]() {
vtkSphereSource *sphereSource = vtkSphereSource::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5.0);
sphereSource->Update();
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkActor *sphereActor = vtkActor::New();
sphereActor->SetMapper(mapper);
vtkRenderer *renderer = vtkRenderer::New();
renderer->SetBackground(0.3, 0.4, 0.5);
renderer->AddActor(sphereActor);
vtkRenderWindow *renderWindow = ui->VTKWidget->GetRenderWindow();
renderWindow->AddRenderer(renderer);
vtkRenderWindowInteractor *renderWindowInteractor = renderWindow->GetInteractor();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkCallbackCommand *clickCallBack = vtkCallbackCommand::New();
clickCallBack->SetCallback(ClickCallbackFunction);
renderWindowInteractor->AddObserver(vtkCommand::MouseMoveEvent, clickCallBack);
qDebug() << QApplication::screens().at(0)->logicalDotsPerInch();
qDebug() << QApplication::screens().at(0)->physicalDotsPerInch();
qDebug() << renderWindow->GetDPI();
qDebug() << renderWindow->DetectDPI();
//});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mouseMoveEvent(QMouseEvent * eventMove)
{
QString qtTxt = QString("Qt: %1, %2").arg(eventMove->x()).arg(eventMove->y());
ui->label_2->setText(qtTxt);
QString globalStr = QString("global: %1, %2").arg(QCursor::pos().x()).arg(QCursor::pos().y());
ui->label_3->setText(globalStr);
}
void ClickCallbackFunction(vtkObject *caller, long unsigned eventID, void* clientData, void* callData)
{
vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
QString vtkStr = QString("VTK: %1,%2").arg(iren->GetEventPosition()[0]).arg(iren->GetEventPosition()[1]);
/*vtkStr.append(iren->GetEventPosition()[0]).append(",").append(iren->GetEventPosition()[1])
.append(",").append(iren->GetEventPosition()[2]);*/
vtkLabel->setText(vtkStr);
double picked[3];
iren->GetPicker()->GetPickPosition(picked);
//cout << picked[0] << "," << picked[1] << "," << picked[2] << endl;
QString globalStr = QString("global: %1, %2").arg(QCursor::pos().x()).arg(QCursor::pos().y());
globalLabel->setText(globalStr);
}