28#if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
40G4Qt3DViewer::G4Qt3DViewer
41(G4Qt3DSceneHandler& sceneHandler,
const G4String& name)
42:
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(),
name)
43, fQt3DSceneHandler(sceneHandler)
49 setObjectName(fName.c_str());
51 fVP.SetAutoRefresh(
true);
52 fDefaultVP.SetAutoRefresh(
true);
59 auto uiQt =
dynamic_cast<G4UIQt*
>(UI->GetG4UIWindow());
62 G4cerr <<
"G4Qt3DViewer::G4Qt3DViewer requires G4UIQt"
66 fUIWidget = QWidget::createWindowContainer(
this);
67 uiQt->AddTabWidget(fUIWidget,QString(fName));
69 setRootEntity(fQt3DSceneHandler.fpQt3DScene);
72G4Qt3DViewer::~G4Qt3DViewer()
75void G4Qt3DViewer::SetView()
80 = fSceneHandler.GetScene()->GetStandardTargetPoint()
81 + fVP.GetCurrentTargetPoint ();
82 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
83 if(radius<=0.) radius = 1.;
84 const G4double cameraDistance = fVP.GetCameraDistance (radius);
86 targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
87 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
88 const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
89 const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius);
90 const GLdouble left = -right;
91 const GLdouble top = fVP.GetFrontHalfHeight (pnear, radius);
92 const GLdouble bottom = -top;
94 camera()->setObjectName((fName +
" camera").c_str());
95 camera()->setViewCenter(G4Qt3DUtils::ConvertToQVector3D(targetPoint));
96 camera()->setPosition(G4Qt3DUtils::ConvertToQVector3D(cameraPosition));
97 camera()->setUpVector(G4Qt3DUtils::ConvertToQVector3D(fVP.GetUpVector()));
106 const auto& size = fUIWidget->size();
114 if (fVP.GetFieldHalfAngle() == 0.) {
115 camera()->lens()->setOrthographicProjection
116 (left*aspectRatio,right*aspectRatio,bottom,top,pnear,pfar);
118 camera()->lens()->setPerspectiveProjection
119 (2.*fVP.GetFieldHalfAngle()/deg,aspectRatio,pnear,pfar);
123void G4Qt3DViewer::ClearView()
126void G4Qt3DViewer::DrawView()
137 if (!fNeedKernelVisit) KernelVisitDecision();
138 G4bool kernelVisitWasNeeded = fNeedKernelVisit;
143 if (kernelVisitWasNeeded) {
152void G4Qt3DViewer::ShowView()
157void G4Qt3DViewer::FinishView()
162void G4Qt3DViewer::SwitchToVisSubThread()
176void G4Qt3DViewer::SwitchToMasterThread()
189#ifdef G4MULTITHREADED
204 fNeedKernelVisit =
true;
210void G4Qt3DViewer::KernelVisitDecision () {
215 if (CompareForKernelVisit(fLastVP)) {
227 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
232 fVP.GetCBDAlgorithmNumber()) ||
233 (lastVP.
IsSection () != fVP.IsSection ()) ||
234 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
235 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
241 fVP.GetDefaultVisAttributes()->
GetColour()) ||
243 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
245 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
247 fVP.GetVisAttributesModifiers())
257 if (lastVP.
GetCBDParameters().size() != fVP.GetCBDParameters().size())
return true;
268void G4Qt3DViewer::keyPressEvent(QKeyEvent* ev)
274void G4Qt3DViewer::keyReleaseEvent(QKeyEvent* )
279void G4Qt3DViewer::mouseDoubleClickEvent(QMouseEvent* ) {}
281void G4Qt3DViewer::mouseMoveEvent(QMouseEvent* ev)
300 if (fKeyPressed && fKey == Qt::Key_Shift) {
302 const G4double sceneRadius = fQt3DSceneHandler.fpScene->GetExtent().GetExtentRadius();
304 const G4double dxScene = dx*sceneRadius/scale;
305 const G4double dyScene = dy*sceneRadius/scale;
306 fVP.IncrementPan(-dxScene,dyScene);
311 const G4Vector3D& x_prime = fVP.GetViewpointDirection().
cross(fVP.GetUpVector());
312 const G4Vector3D& y_prime = x_prime.
cross(fVP.GetViewpointDirection());
314 G4Vector3D newViewpointDirection = fVP.GetViewpointDirection();
315 newViewpointDirection += dx*x_prime/scale;
316 newViewpointDirection += dy*y_prime/scale;
317 fVP.SetViewpointDirection(newViewpointDirection.
unit());
321 newUpVector += dx*x_prime/scale;
322 newUpVector += dy*y_prime/scale;
323 fVP.SetUpVector(newUpVector.
unit());
332void G4Qt3DViewer::mousePressEvent(QMouseEvent* ev)
334 fMousePressed =
true;
335 fMousePressedX = ev->x();
336 fMousePressedY = ev->y();
339void G4Qt3DViewer::mouseReleaseEvent(QMouseEvent* )
341 fMousePressed =
false;
344void G4Qt3DViewer::wheelEvent(QWheelEvent* ev)
347 const G4double angleY = ev->angleDelta().y();
349 if (fVP.GetFieldHalfAngle() == 0.) {
351 fVP.MultiplyZoomFactor(1.+angleY/scale);
353 const G4double scale = fVP.GetFieldHalfAngle()/(10.*deg);
354 fVP.SetDolly(fVP.GetDolly()+angleY/scale);
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4bool GetColour(const G4String &key, G4Colour &result)
static G4UImanager * GetUIpointer()
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
const G4Colour & GetBackgroundColour() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
G4bool IsCullingCovered() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
const char * name(G4int ptype)
G4bool IsMultithreadedApplication()