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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/Vtk/src/G4VtkQtViewer.cc (Version 11.3.0) and /visualization/Vtk/src/G4VtkQtViewer.cc (Version 8.1.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25                                                   
 26 #include "G4VtkQtViewer.hh"                       
 27                                                   
 28 #include "G4LogicalVolume.hh"                     
 29 #include "G4Qt.hh"                                
 30 #include "G4UIQt.hh"                              
 31 #include "G4UImanager.hh"                         
 32 #include "G4VSceneHandler.hh"                     
 33 #include "G4VtkInteractorStyle.hh"                
 34 #include "G4VtkQtSceneHandler.hh"                 
 35 #include "G4VtkUtility.hh"                        
 36                                                   
 37 #include <qcoreapplication.h>                     
 38 #include <qlabel.h>                               
 39 #include <qlayout.h>                              
 40 #include <qlineedit.h>                            
 41 #include <qopenglcontext.h>                       
 42 #include <qpushbutton.h>                          
 43 #include <qthread.h>                              
 44 #include <qtreewidget.h>                          
 45 #include <vtkActor.h>                             
 46 #include <vtkCamera.h>                            
 47 #include <vtkCylinderSource.h>                    
 48 #include <vtkGenericOpenGLRenderWindow.h>         
 49 #include <vtkNamedColors.h>                       
 50 #include <vtkNew.h>                               
 51 #include <vtkPolyDataMapper.h>                    
 52 #include <vtkProperty.h>                          
 53 #include <vtkRenderer.h>                          
 54 #include <vtkVersion.h>                           
 55                                                   
 56 #include <array>                                  
 57                                                   
 58 G4VtkQtViewer::G4VtkQtViewer(G4VSceneHandler&     
 59   : G4VtkViewer(sceneHandler, name)               
 60 {                                                 
 61   G4Qt::getInstance();                            
 62   //this->setFormat(QVTKOpenGLNativeWidget::de    
 63 }                                                 
 64                                                   
 65 G4VtkQtViewer::~G4VtkQtViewer()                   
 66 {                                                 
 67 }                                                 
 68                                                   
 69 void G4VtkQtViewer::Initialise()                  
 70 {                                                 
 71   CreateMainWindow(this, QString(GetName()));     
 72                                                   
 73   // Specific GL render window and interactor     
 74   _renderWindow = vtkGenericOpenGLRenderWindow    
 75                                                   
 76   _renderWindow->AddRenderer(renderer);           
 77   this->setRenderWindow(_renderWindow);           
 78                                                   
 79   // Set callback to match VTK parameters to G    
 80   geant4Callback->SetGeant4ViewParameters(&fVP    
 81   renderer->AddObserver(vtkCommand::EndEvent,     
 82                                                   
 83   // Hidden line removal                          
 84   renderer->SetUseHiddenLineRemoval(0);           
 85                                                   
 86   // Shadows                                      
 87   renderer->SetUseShadows(0);                     
 88                                                   
 89   vtkSmartPointer<G4VtkInteractorStyle> style     
 90     vtkSmartPointer<G4VtkInteractorStyle>::New    
 91   this->interactor()->SetInteractorStyle(style    
 92 }                                                 
 93                                                   
 94 void G4VtkQtViewer::CreateMainWindow(QVTKOpenG    
 95 {                                                 
 96   G4UImanager* UI = G4UImanager::GetUIpointer(    
 97   fUiQt = static_cast<G4UIQt*>(UI->GetG4UIWind    
 98   fUiQt->AddTabWidget((QWidget*)vtkWidget, nam    
 99   vtkWidget->setAttribute(Qt::WA_AcceptTouchEv    
100   fGLWidget = vtkWidget;                          
101   createSceneTreeWidget();                        
102 }                                                 
103                                                   
104 #ifdef G4MULTITHREADED                            
105                                                   
106 namespace {                                       
107   G4Mutex visSubThreadMutex = G4MUTEX_INITIALI    
108   G4Condition waitForVisSubThreadInitialized =    
109   G4bool visSubThreadEstablished = false;         
110   G4bool qObjectsSwitched = false;                
111   QVTKOpenGLNativeWidget* qVtkW = nullptr;        
112 }                                                 
113                                                   
114 void G4VtkQtViewer::DoneWithMasterThread()        
115 {                                                 
116   // Called by Main Thread !                      
117                                                   
118   // Initialise and check qVtkW - no need to c    
119   qVtkW = dynamic_cast<QVTKOpenGLNativeWidget*    
120   if (qVtkW == nullptr) return;                   
121                                                   
122   // Done with master thread                      
123   qVtkW->doneCurrent();                           
124                                                   
125   // Set current QThread for the way back         
126   fQVtkContextMainThread = QThread::currentThr    
127 }                                                 
128                                                   
129 void G4VtkQtViewer::MovingToVisSubThread()        
130 {                                                 
131   // Still on master thread but vis thread has    
132                                                   
133   if (qVtkW == nullptr) return;                   
134                                                   
135   // Wait until SwitchToVisSubThread has found    
136   {                                               
137   G4AutoLock lock(&visSubThreadMutex);            
138   G4CONDITIONWAITLAMBDA(&waitForVisSubThreadIn    
139   }                                               
140                                                   
141   // Move stuff to sub-thread                     
142   if(qVtkW->context()) qVtkW->context()->moveT    
143                                                   
144   // Inform sub-thread                            
145   G4AutoLock lock(&visSubThreadMutex);            
146   qObjectsSwitched = true;                        
147   lock.unlock();                                  
148   G4CONDITIONBROADCAST(&waitForVisSubThreadIni    
149 }                                                 
150                                                   
151 void G4VtkQtViewer::SwitchToVisSubThread()        
152 {                                                 
153   // Called by VisSub Thread !                    
154                                                   
155   if (qVtkW == nullptr) return;                   
156                                                   
157   fQVtkContextVisSubThread = QThread::currentT    
158                                                   
159   // Let MovingToVisSubThread know we have the    
160   {                                               
161   G4AutoLock lock(&visSubThreadMutex);            
162   visSubThreadEstablished = true;                 
163   G4CONDITIONBROADCAST(&waitForVisSubThreadIni    
164   }                                               
165                                                   
166   // Wait until MovingToVisSubThread has moved    
167   {                                               
168   G4AutoLock lock(&visSubThreadMutex);            
169   G4CONDITIONWAITLAMBDA(&waitForVisSubThreadIn    
170   }                                               
171                                                   
172   // make context current                         
173   qVtkW->makeCurrent();                           
174 }                                                 
175                                                   
176 void G4VtkQtViewer::DoneWithVisSubThread()        
177 {                                                 
178   // Called by vis sub thread                     
179                                                   
180   if (qVtkW == nullptr) return;                   
181                                                   
182   // finish with this vis sub thread context      
183   qVtkW->doneCurrent();                           
184                                                   
185   // and move it back to the main thread          
186   if(qVtkW->context()) qVtkW->context()->moveT    
187 }                                                 
188                                                   
189 void G4VtkQtViewer::SwitchToMasterThread()        
190 {                                                 
191   // Called by VisSub Thread !                    
192                                                   
193   if (qVtkW == nullptr) return;                   
194                                                   
195   qVtkW->makeCurrent();                           
196                                                   
197   visSubThreadEstablished = false;                
198   qObjectsSwitched = false;                       
199 }                                                 
200                                                   
201 #endif                                            
202                                                   
203 void G4VtkQtViewer::FinishView()                  
204 {                                                 
205   auto& fVtkSceneHandler = dynamic_cast<G4VtkS    
206   fVtkSceneHandler.Modified();                    
207                                                   
208   _renderWindow->Render();                        
209                                                   
210   auto qGLW = dynamic_cast<QVTKOpenGLNativeWid    
211   qGLW->interactor()->Initialize();               
212   qGLW->interactor()->Start();                    
213 }                                                 
214                                                   
215 void G4VtkQtViewer::createSceneTreeWidget() {}    
216                                                   
217 void G4VtkQtViewer::createSceneTreeComponent()    
218                                                   
219 QTreeWidgetItem*                                  
220 G4VtkQtViewer::createTreeWidgetItem(const PVPa    
221                                     int /*copy    
222                                     Qt::CheckS    
223                                     const G4Co    
224 {                                                 
225   QTreeWidgetItem* newItem = nullptr;             
226   return newItem;                                 
227 }                                                 
228                                                   
229 void G4VtkQtViewer::addNonPVSceneTreeElement(c    
230                                              i    
231 {}                                                
232                                                   
233 void G4VtkQtViewer::addPVSceneTreeElement(cons    
234                                           G4Ph    
235                                           int     
236 {}                                                
237                                                   
238 QString G4VtkQtViewer::getModelShortName(const    
239 {                                                 
240   QString modelShortName;                         
241   return modelShortName;                          
242 }                                                 
243                                                   
244 bool G4VtkQtViewer::parseAndInsertInSceneTree(    
245                                                   
246                                                   
247                                                   
248                                                   
249                                                   
250 {                                                 
251   return false;                                   
252 }                                                 
253                                                   
254 void G4VtkQtViewer::EnableClipperWidget()         
255 {                                                 
256   G4VtkViewer::EnableClipperWidget();             
257   auto qGLW = dynamic_cast<QVTKOpenGLNativeWid    
258   qGLW->interactor()->Initialize();               
259 }                                                 
260                                                   
261 void G4VtkQtViewer::SetWidgetInteractor(vtkAbs    
262 {                                                 
263   auto qGLW = dynamic_cast<QVTKOpenGLNativeWid    
264   widget->SetInteractor(qGLW->interactor());      
265 }                                                 
266