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 10.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/modeling/src/G4TrajectoryDrawerUtils.cc (Version 11.3.0) and /visualization/modeling/src/G4TrajectoryDrawerUtils.cc (Version 4.0.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 //                                                
 27 // Jane Tinslay, John Allison, Joseph Perl Nov    
 28 //                                                
 29 #include "G4TrajectoryDrawerUtils.hh"             
 30 #include "G4Colour.hh"                            
 31 #include "G4Polyline.hh"                          
 32 #include "G4Polymarker.hh"                        
 33 #include "G4VTrajectory.hh"                       
 34 #include "G4VTrajectoryPoint.hh"                  
 35 #include "G4VisAttributes.hh"                     
 36 #include "G4VisTrajContext.hh"                    
 37 #include "G4VVisManager.hh"                       
 38 #include "G4UIcommand.hh"                         
 39 #include "G4AttValue.hh"                          
 40                                                   
 41 #include <utility>                                
 42                                                   
 43 #define G4warn G4cout                             
 44                                                   
 45 namespace G4TrajectoryDrawerUtils {               
 46                                                   
 47   enum TimesValidity {InvalidTimes, ValidTimes    
 48                                                   
 49   TimesValidity GetPointsAndTimes                 
 50   (const G4VTrajectory& traj,                     
 51    const G4VisTrajContext& context,               
 52    G4Polyline& trajectoryLine,                    
 53    G4Polymarker& auxiliaryPoints,                 
 54    G4Polymarker& stepPoints,                      
 55    std::vector<G4double>& trajectoryLineTimes,    
 56    std::vector<G4double>& auxiliaryPointTimes,    
 57    std::vector<G4double>& stepPointTimes)         
 58   {                                               
 59     TimesValidity validity = InvalidTimes;        
 60     if (context.GetTimeSliceInterval()) validi    
 61                                                   
 62     // Memory for last trajectory point positi    
 63     // time interpolation algorithm.  There ar    
 64     // for the first trajectory point, so its     
 65     // immaterial.                                
 66     G4ThreeVector lastTrajectoryPointPosition;    
 67                                                   
 68     // Keep positions.  Don't store unless fir    
 69     std::vector<G4ThreeVector> positions;         
 70                                                   
 71     for (G4int iPoint=0; iPoint<traj.GetPointE    
 72                                                   
 73       G4VTrajectoryPoint* aTrajectoryPoint = t    
 74       const G4ThreeVector& trajectoryPointPosi    
 75   aTrajectoryPoint->GetPosition();                
 76                                                   
 77       // Only store if first or if different      
 78       if (positions.size() == 0 ||                
 79     trajectoryPointPosition != positions[posit    
 80                                                   
 81   // Pre- and Post-Point times from the trajec    
 82   G4double trajectoryPointPreTime = -std::nume    
 83   G4double trajectoryPointPostTime = std::nume    
 84                                                   
 85   if (context.GetTimeSliceInterval() && validi    
 86                                                   
 87     std::vector<G4AttValue>* trajectoryPointAt    
 88       aTrajectoryPoint->CreateAttValues();        
 89     if (!trajectoryPointAttValues) {              
 90       static G4bool warnedNoAttValues = false;    
 91       if (!warnedNoAttValues) {                   
 92         G4warn <<                                 
 93   "*******************************************    
 94   "\n*  WARNING: G4TrajectoryDrawerUtils::GetP    
 95   "\n*****************************************    
 96          << G4endl;                               
 97         warnedNoAttValues = true;                 
 98       }                                           
 99       validity = InvalidTimes;                    
100     } else {                                      
101       G4bool foundPreTime = false, foundPostTi    
102       for (std::vector<G4AttValue>::iterator i    
103        trajectoryPointAttValues->begin();         
104      i != trajectoryPointAttValues->end(); ++i    
105         if (i->GetName() == "PreT") {             
106     trajectoryPointPreTime =                      
107       G4UIcommand::ConvertToDimensionedDouble(    
108     foundPreTime = true;                          
109         }                                         
110         if (i->GetName() == "PostT") {            
111     trajectoryPointPostTime =                     
112       G4UIcommand::ConvertToDimensionedDouble(    
113     foundPostTime = true;                         
114         }                                         
115       }                                           
116       if (!foundPreTime || !foundPostTime) {      
117         static G4bool warnedTimesNotFound = fa    
118         if (!warnedTimesNotFound) {               
119     G4warn <<                                     
120   "*******************************************    
121   "\n*  WARNING: G4TrajectoryDrawerUtils::GetP    
122   "\n You need to specify \"/vis/scene/add/tra    
123   "\n*****************************************    
124            << G4endl;                             
125     warnedTimesNotFound = true;                   
126         }                                         
127         validity = InvalidTimes;                  
128       }                                           
129     }                                             
130           delete trajectoryPointAttValues;  //    
131   }                                               
132                                                   
133   const std::vector<G4ThreeVector>* auxiliarie    
134     = aTrajectoryPoint->GetAuxiliaryPoints();     
135   if (0 != auxiliaries) {                         
136     for (size_t iAux=0; iAux<auxiliaries->size    
137       const G4ThreeVector& auxPointPosition =     
138       if (positions.size() == 0 ||                
139     auxPointPosition != positions[positions.si    
140         // Only store if first or if different    
141         positions.push_back(trajectoryPointPos    
142         trajectoryLine.push_back(auxPointPosit    
143         auxiliaryPoints.push_back(auxPointPosi    
144         if (validity == ValidTimes) {             
145     // Interpolate time for auxiliary points..    
146     G4double s1 =                                 
147       (auxPointPosition - lastTrajectoryPointP    
148     G4double s2 =                                 
149       (trajectoryPointPosition - auxPointPosit    
150     G4double t = trajectoryPointPreTime +         
151       (trajectoryPointPostTime - trajectoryPoi    
152       (s1 / (s1 + s2));                           
153     trajectoryLineTimes.push_back(t);             
154     auxiliaryPointTimes.push_back(t);             
155         }                                         
156       }                                           
157     }                                             
158   }                                               
159                                                   
160   positions.push_back(trajectoryPointPosition)    
161   trajectoryLine.push_back(trajectoryPointPosi    
162   stepPoints.push_back(trajectoryPointPosition    
163   if (validity == ValidTimes) {                   
164     trajectoryLineTimes.push_back(trajectoryPo    
165     stepPointTimes.push_back(trajectoryPointPo    
166   }                                               
167         lastTrajectoryPointPosition = trajecto    
168       }                                           
169     }                                             
170     return validity;                              
171   }                                               
172                                                   
173   static void SliceLine(G4double timeIncrement    
174       G4Polyline& trajectoryLine,                 
175       std::vector<G4double>& trajectoryLineTim    
176   {                                               
177     // Assumes valid arguments from GetPoints     
178                                                   
179     G4Polyline newTrajectoryLine;                 
180     std::vector<G4double> newTrajectoryLineTim    
181                                                   
182     newTrajectoryLine.push_back(trajectoryLine    
183     newTrajectoryLineTimes.push_back(trajector    
184     size_t lineSize = trajectoryLine.size();      
185     if (lineSize > 1) {                           
186       for (size_t i = 1; i < trajectoryLine.si    
187   G4double deltaT = trajectoryLineTimes[i] - t    
188   if (deltaT > 0.) {                              
189     G4double practicalTimeIncrement =             
190       std::max(timeIncrement, deltaT / 100.);     
191     for (G4double t =                             
192      (int(trajectoryLineTimes[i - 1]/practical    
193      practicalTimeIncrement;                      
194          t <= trajectoryLineTimes[i];             
195          t += practicalTimeIncrement) {           
196       G4ThreeVector pos = trajectoryLine[i - 1    
197         (trajectoryLine[i] - trajectoryLine[i     
198         ((t - trajectoryLineTimes[i - 1]) / de    
199       newTrajectoryLine.push_back(pos);           
200       newTrajectoryLineTimes.push_back(t);        
201     }                                             
202   }                                               
203   newTrajectoryLine.push_back(trajectoryLine[i    
204   newTrajectoryLineTimes.push_back(trajectoryL    
205       }                                           
206     }                                             
207                                                   
208     trajectoryLine = std::move(newTrajectoryLi    
209     trajectoryLineTimes = std::move(newTraject    
210   }                                               
211                                                   
212   static void DrawWithoutTime(const G4VisTrajC    
213             G4Polyline& trajectoryLine,           
214             G4Polymarker& auxiliaryPoints,        
215             G4Polymarker& stepPoints)             
216   {                                               
217     // Draw without time slice information        
218                                                   
219     G4VVisManager* pVVisManager = G4VVisManage    
220     if (0 == pVVisManager) return;                
221                                                   
222     if (myContext.GetDrawLine() && myContext.G    
223       G4VisAttributes trajectoryLineAttribs(my    
224       trajectoryLineAttribs.SetLineWidth(myCon    
225       trajectoryLine.SetVisAttributes(&traject    
226                                                   
227       pVVisManager->Draw(trajectoryLine);         
228     }                                             
229                                                   
230     if (myContext.GetDrawAuxPts() && myContext    
231         && (auxiliaryPoints.size() > 0)) {        
232       auxiliaryPoints.SetMarkerType(myContext.    
233       auxiliaryPoints.SetSize(myContext.GetAux    
234       auxiliaryPoints.SetFillStyle(myContext.G    
235                                                   
236       G4VisAttributes auxiliaryPointsAttribs(m    
237       auxiliaryPoints.SetVisAttributes(&auxili    
238                                                   
239       pVVisManager->Draw(auxiliaryPoints);        
240     }                                             
241                                                   
242     if (myContext.GetDrawStepPts() && myContex    
243         && (stepPoints.size() > 0)) {             
244       stepPoints.SetMarkerType(myContext.GetSt    
245       stepPoints.SetSize(myContext.GetStepPtsS    
246       stepPoints.SetFillStyle(myContext.GetSte    
247                                                   
248       G4VisAttributes stepPointsAttribs(myCont    
249       stepPoints.SetVisAttributes(&stepPointsA    
250                                                   
251       pVVisManager->Draw(stepPoints);             
252     }                                             
253   }                                               
254                                                   
255   static void DrawWithTime(const G4VisTrajCont    
256          G4Polyline& trajectoryLine,              
257          G4Polymarker& auxiliaryPoints,           
258          G4Polymarker& stepPoints,                
259          std::vector<G4double>& trajectoryLine    
260          std::vector<G4double>& auxiliaryPoint    
261          std::vector<G4double>& stepPointTimes    
262   {                                               
263     // Draw with time slice information           
264                                                   
265     G4VVisManager* pVVisManager = G4VVisManage    
266     if (0 == pVVisManager) return;                
267                                                   
268     if (myContext.GetDrawLine() && myContext.G    
269       G4VisAttributes trajectoryLineAttribs(my    
270       trajectoryLineAttribs.SetLineWidth(myCon    
271                                                   
272       for (size_t i = 1; i < trajectoryLine.si    
273   G4Polyline slice;                               
274   slice.push_back(trajectoryLine[i -1]);          
275   slice.push_back(trajectoryLine[i]);             
276   trajectoryLineAttribs.SetStartTime(trajector    
277   trajectoryLineAttribs.SetEndTime(trajectoryL    
278   slice.SetVisAttributes(&trajectoryLineAttrib    
279   pVVisManager->Draw(slice);                      
280       }                                           
281     }                                             
282                                                   
283     if (myContext.GetDrawAuxPts() && myContext    
284         && (auxiliaryPoints.size() > 0)) {        
285       G4VisAttributes auxiliaryPointsAttribs(m    
286                                                   
287       for (size_t i = 0; i < auxiliaryPoints.s    
288   G4Polymarker point;                             
289   point.push_back(auxiliaryPoints[i]);            
290   point.SetMarkerType(myContext.GetAuxPtsType(    
291   point.SetSize(myContext.GetAuxPtsSizeType(),    
292   point.SetFillStyle(myContext.GetAuxPtsFillSt    
293   auxiliaryPointsAttribs.SetStartTime(auxiliar    
294   auxiliaryPointsAttribs.SetEndTime(auxiliaryP    
295   point.SetVisAttributes(&auxiliaryPointsAttri    
296   pVVisManager->Draw(point);                      
297       }                                           
298     }                                             
299                                                   
300     if (myContext.GetDrawStepPts() && myContex    
301         && (stepPoints.size() > 0)) {             
302       G4VisAttributes stepPointsAttribs(myCont    
303                                                   
304       for (size_t i = 0; i < stepPoints.size()    
305   G4Polymarker point;                             
306   point.push_back(stepPoints[i]);                 
307   point.SetMarkerType(myContext.GetStepPtsType    
308   point.SetSize(myContext.GetStepPtsSizeType()    
309   point.SetFillStyle(myContext.GetStepPtsFillS    
310   stepPointsAttribs.SetStartTime(stepPointTime    
311   stepPointsAttribs.SetEndTime(stepPointTimes[    
312   point.SetVisAttributes(&stepPointsAttribs);     
313   pVVisManager->Draw(point);                      
314       }                                           
315     }                                             
316   }                                               
317                                                   
318   void DrawLineAndPoints(const G4VTrajectory&     
319   {                                               
320     // Return if don't need to do anything        
321     if (!context.GetDrawLine() && !context.Get    
322                                                   
323     // Get points and times (times are returne    
324     // is requested).                             
325     G4Polyline trajectoryLine;                    
326     G4Polymarker stepPoints;                      
327     G4Polymarker auxiliaryPoints;                 
328     std::vector<G4double> trajectoryLineTimes;    
329     std::vector<G4double> stepPointTimes;         
330     std::vector<G4double> auxiliaryPointTimes;    
331                                                   
332     TimesValidity validity = GetPointsAndTimes    
333       (traj, context,                             
334        trajectoryLine, auxiliaryPoints, stepPo    
335        trajectoryLineTimes, auxiliaryPointTime    
336                                                   
337     if (validity == ValidTimes) {                 
338                                                   
339       SliceLine(context.GetTimeSliceInterval()    
340     trajectoryLine, trajectoryLineTimes);         
341                                                   
342       DrawWithTime(context,                       
343        trajectoryLine, auxiliaryPoints, stepPo    
344        trajectoryLineTimes, auxiliaryPointTime    
345                                                   
346     } else {                                      
347                                                   
348       DrawWithoutTime(context, trajectoryLine,    
349                                                   
350     }                                             
351   }                                               
352 }                                                 
353