Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RTQtScanner.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29
30#include "G4RTQtScanner.hh"
31
32//#include "G4TheRayTracer.hh"
33//#include "G4RayTracerQtViewer.hh"
34#include "G4ViewParameters.hh"
35#include "G4UImanager.hh"
36#include "G4UIQt.hh"
37
38#include <QLabel>
39#include <QImage>
40#include <QPainter>
41#include <QColor>
42
43#define G4warn G4cout
44
47, theNRow(0), theNColumn(0)
48, theIRow(0), theIColumn(0)
49, fpImageLabel(nullptr)
50, fpImage(nullptr)
51{}
52
54
56 theNRow = nRow;
57 theNColumn = nColumn;
58 theIRow = 0;
59 theIColumn = -1;
60}
61
63{
64 // Increment column and, if necessary, increment row...
65 ++theIColumn;
66 if (theIColumn >= theNColumn) {
67 theIColumn = 0;
68 ++theIRow;
69 }
70
71 // Return if finished...
72 if (theIRow >= theNRow) {
73 // ...and paint the image
74 fpImageLabel->setPixmap(QPixmap::fromImage(*fpImage));
75 QPainter windowPainter(fpImageLabel);
76 windowPainter.drawImage(0, 0, *fpImage);
77 return false;
78 }
79
80 // Return current row and column...
81 iRow = theIRow;
82 iColumn = theIColumn;
83 return true;
84}
85
87{
88 auto UI = G4UImanager::GetUIpointer();
89 auto uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
90 if (!uiQt) {
91 G4warn << "G4RTQtScanner::GetQtWindow: RayTracerQt requires G4UIQt"
92 << G4endl;
93 return false;
94 }
95 uiQt->AddTabWidget(this,QString(name));
96 setBackgroundRole(QPalette::Dark);
97
98 theWindowSizeX = vp.GetWindowSizeHintX(); // As used by the ray tracer
99 theWindowSizeY = vp.GetWindowSizeHintY(); // and to make fpImage
100 fpImage = new QImage(theWindowSizeX, theWindowSizeY, QImage::Format_RGB32);
101 fpImageLabel = new QLabel;
102 fpImageLabel->setPixmap(QPixmap::fromImage(*fpImage));
103 setWidget(fpImageLabel);
104 setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
105 ensureVisible(theWindowSizeX/2, theWindowSizeY/2);
106
107 return true;
108}
109
111(unsigned char red, unsigned char green, unsigned char blue)
112// Add a coloured point to the image at current position.
113{
114 QPainter painter(fpImage);
115 painter.setPen(QPen(QColor(int(red), int(green), int(blue))));
116 painter.drawPoint(theIColumn, theIRow);
117}
#define G4warn
Definition G4Scene.cc:41
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
virtual void Initialize(G4int nRow, G4int nColumn)
virtual G4bool Coords(G4int &iRow, G4int &iColumn)
virtual void Draw(unsigned char red, unsigned char green, unsigned char blue)
G4bool GetQtWindow(const G4String &name, G4ViewParameters &)
virtual ~G4RTQtScanner()
QLabel * fpImageLabel
G4bool AddTabWidget(QWidget *, QString)
Definition G4UIQt.cc:3215
static G4UImanager * GetUIpointer()
unsigned int GetWindowSizeHintX() const
unsigned int GetWindowSizeHintY() const