Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4TrajectoryDrawerUtils.cc,v 1.12 2009/02/24 12:00:56 allison Exp $ >> 27 // GEANT4 tag $Name: geant4-09-03-patch-02 $ 26 // 28 // 27 // Jane Tinslay, John Allison, Joseph Perl Nov 29 // Jane Tinslay, John Allison, Joseph Perl November 2005 28 // 30 // 29 #include "G4TrajectoryDrawerUtils.hh" 31 #include "G4TrajectoryDrawerUtils.hh" 30 #include "G4Colour.hh" 32 #include "G4Colour.hh" 31 #include "G4Polyline.hh" 33 #include "G4Polyline.hh" 32 #include "G4Polymarker.hh" 34 #include "G4Polymarker.hh" 33 #include "G4VTrajectory.hh" 35 #include "G4VTrajectory.hh" 34 #include "G4VTrajectoryPoint.hh" 36 #include "G4VTrajectoryPoint.hh" 35 #include "G4VisAttributes.hh" 37 #include "G4VisAttributes.hh" 36 #include "G4VisTrajContext.hh" 38 #include "G4VisTrajContext.hh" 37 #include "G4VVisManager.hh" 39 #include "G4VVisManager.hh" 38 #include "G4UIcommand.hh" 40 #include "G4UIcommand.hh" 39 #include "G4AttValue.hh" 41 #include "G4AttValue.hh" 40 42 41 #include <utility> << 42 << 43 #define G4warn G4cout << 44 << 45 namespace G4TrajectoryDrawerUtils { 43 namespace G4TrajectoryDrawerUtils { 46 44 47 enum TimesValidity {InvalidTimes, ValidTimes << 48 45 49 TimesValidity GetPointsAndTimes << 46 void GetPoints(const G4VTrajectory& traj, G4Polyline& trajectoryLine, 50 (const G4VTrajectory& traj, << 47 G4Polymarker& auxiliaryPoints, G4Polymarker& stepPoints) 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 { 48 { 59 TimesValidity validity = InvalidTimes; << 49 for (G4int i=0; i<traj.GetPointEntries(); i++) { 60 if (context.GetTimeSliceInterval()) validi << 50 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i); 61 << 51 62 // Memory for last trajectory point positi << 52 const std::vector<G4ThreeVector>* auxiliaries 63 // time interpolation algorithm. There ar << 53 = aTrajectoryPoint->GetAuxiliaryPoints(); 64 // for the first trajectory point, so its << 54 65 // immaterial. << 55 if (0 != auxiliaries) { 66 G4ThreeVector lastTrajectoryPointPosition; << 56 for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) { >> 57 const G4ThreeVector pos((*auxiliaries)[iAux]); >> 58 trajectoryLine.push_back(pos); >> 59 auxiliaryPoints.push_back(pos); >> 60 } >> 61 } >> 62 const G4ThreeVector pos(aTrajectoryPoint->GetPosition()); >> 63 trajectoryLine.push_back(pos); >> 64 stepPoints.push_back(pos); >> 65 } >> 66 } 67 67 68 // Keep positions. Don't store unless fir << 68 void DrawLineAndPoints(const G4VTrajectory& traj, const G4int& i_mode, const G4Colour& colour, const G4bool& visible) { 69 std::vector<G4ThreeVector> positions; << 69 // If i_mode>=0, draws a trajectory as a polyline (default is blue for >> 70 // positive, red for negative, green for neutral) and, if i_mode!=0, >> 71 // adds markers - yellow circles for step points and magenta squares >> 72 // for auxiliary points, if any - whose screen size in pixels is >> 73 // given by std::abs(i_mode)/1000. E.g: i_mode = 5000 gives easily >> 74 // visible markers. >> 75 >> 76 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); >> 77 if (0 == pVVisManager) return; >> 78 >> 79 const G4double markerSize = std::abs(i_mode)/1000; >> 80 G4bool lineRequired (i_mode >= 0); >> 81 G4bool markersRequired (markerSize > 0.); >> 82 >> 83 // Return if don't need to do anything >> 84 if (!lineRequired && !markersRequired) return; >> 85 >> 86 // Get points to draw >> 87 G4Polyline trajectoryLine; >> 88 G4Polymarker stepPoints; >> 89 G4Polymarker auxiliaryPoints; >> 90 >> 91 GetPoints(traj, trajectoryLine, auxiliaryPoints, stepPoints); >> 92 >> 93 if (lineRequired) { >> 94 G4VisAttributes trajectoryLineAttribs(colour); >> 95 trajectoryLineAttribs.SetVisibility(visible); >> 96 trajectoryLine.SetVisAttributes(&trajectoryLineAttribs); >> 97 pVVisManager->Draw(trajectoryLine); >> 98 } >> 99 >> 100 if (markersRequired) { >> 101 auxiliaryPoints.SetMarkerType(G4Polymarker::squares); >> 102 auxiliaryPoints.SetScreenSize(markerSize); >> 103 auxiliaryPoints.SetFillStyle(G4VMarker::filled); >> 104 G4VisAttributes auxiliaryPointsAttribs(G4Colour(0.,1.,1.)); // Magenta >> 105 auxiliaryPointsAttribs.SetVisibility(visible); >> 106 auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs); >> 107 pVVisManager->Draw(auxiliaryPoints); >> 108 >> 109 stepPoints.SetMarkerType(G4Polymarker::circles); >> 110 stepPoints.SetScreenSize(markerSize); >> 111 stepPoints.SetFillStyle(G4VMarker::filled); >> 112 G4VisAttributes stepPointsAttribs(G4Colour(1.,1.,0.)); // Yellow. >> 113 stepPoints.SetVisAttributes(&stepPointsAttribs); >> 114 pVVisManager->Draw(stepPoints); >> 115 } >> 116 >> 117 } >> 118 >> 119 static void GetTimes(const G4VTrajectory& traj, >> 120 std::vector<G4double>& trajectoryLineTimes, >> 121 std::vector<G4double>& auxiliaryPointTimes, >> 122 std::vector<G4double>& stepPointTimes) >> 123 { >> 124 // It is important check that the sizes of times vectors produced >> 125 // by this function matches those of points vectors from >> 126 // GetPoints. If not, assume that the time information is >> 127 // invalid. 70 128 71 for (G4int iPoint=0; iPoint<traj.GetPointE << 129 G4ThreeVector lastTrajectoryPointPosition; >> 130 for (G4int i=0; i<traj.GetPointEntries(); i++) { >> 131 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i); 72 132 73 G4VTrajectoryPoint* aTrajectoryPoint = t << 133 // Pre- and Post-Point times from the trajectory point... >> 134 G4double trajectoryPointPreTime = -DBL_MAX; >> 135 G4double trajectoryPointPostTime = DBL_MAX; >> 136 std::vector<G4AttValue>* trajectoryPointAttValues = >> 137 aTrajectoryPoint->CreateAttValues(); >> 138 if (!trajectoryPointAttValues) { >> 139 G4cout << "G4TrajectoryDrawerUtils::GetTimes: no att values." >> 140 << G4endl; >> 141 return; >> 142 } else { >> 143 G4bool foundPreTime = false, foundPostTime = false; >> 144 for (std::vector<G4AttValue>::iterator i = >> 145 trajectoryPointAttValues->begin(); >> 146 i != trajectoryPointAttValues->end(); ++i) { >> 147 if (i->GetName() == "PreT") { >> 148 trajectoryPointPreTime = >> 149 G4UIcommand::ConvertToDimensionedDouble(i->GetValue()); >> 150 foundPreTime = true; >> 151 } >> 152 if (i->GetName() == "PostT") { >> 153 trajectoryPointPostTime = >> 154 G4UIcommand::ConvertToDimensionedDouble(i->GetValue()); >> 155 foundPostTime = true; >> 156 } >> 157 } >> 158 if (!foundPreTime || !foundPostTime) { >> 159 static G4bool warnedTimesNotFound = false; >> 160 if (!warnedTimesNotFound) { >> 161 G4cout << >> 162 "WARNING: G4TrajectoryDrawerUtils::GetTimes: times not found." >> 163 << G4endl; >> 164 warnedTimesNotFound = true; >> 165 } >> 166 return; >> 167 } >> 168 } >> 169 74 const G4ThreeVector& trajectoryPointPosi 170 const G4ThreeVector& trajectoryPointPosition = 75 aTrajectoryPoint->GetPosition(); 171 aTrajectoryPoint->GetPosition(); 76 172 77 // Only store if first or if different << 173 const std::vector<G4ThreeVector>* auxiliaries 78 if (positions.size() == 0 || << 174 = aTrajectoryPoint->GetAuxiliaryPoints(); 79 trajectoryPointPosition != positions[posit << 175 80 << 176 if (0 != auxiliaries) { 81 // Pre- and Post-Point times from the trajec << 177 for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) { 82 G4double trajectoryPointPreTime = -std::nume << 178 // Interpolate time for auxiliary points... 83 G4double trajectoryPointPostTime = std::nume << 179 const G4ThreeVector pos((*auxiliaries)[iAux]); 84 << 180 G4double s1 = (pos - lastTrajectoryPointPosition).mag(); 85 if (context.GetTimeSliceInterval() && validi << 181 G4double s2 = (trajectoryPointPosition - pos).mag(); 86 << 182 G4double t = trajectoryPointPreTime + 87 std::vector<G4AttValue>* trajectoryPointAt << 183 (trajectoryPointPostTime - trajectoryPointPreTime) * 88 aTrajectoryPoint->CreateAttValues(); << 184 (s1 / (s1 + s2)); 89 if (!trajectoryPointAttValues) { << 185 trajectoryLineTimes.push_back(t); 90 static G4bool warnedNoAttValues = false; << 186 auxiliaryPointTimes.push_back(t); 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 } 187 } >> 188 } 132 189 133 const std::vector<G4ThreeVector>* auxiliarie << 190 trajectoryLineTimes.push_back(trajectoryPointPostTime); 134 = aTrajectoryPoint->GetAuxiliaryPoints(); << 191 stepPointTimes.push_back(trajectoryPointPostTime); 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 192 160 positions.push_back(trajectoryPointPosition) << 193 lastTrajectoryPointPosition = trajectoryPointPosition; 161 trajectoryLine.push_back(trajectoryPointPosi << 194 } 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 } 195 } 172 196 173 static void SliceLine(G4double timeIncrement 197 static void SliceLine(G4double timeIncrement, 174 G4Polyline& trajectoryLine, 198 G4Polyline& trajectoryLine, 175 std::vector<G4double>& trajectoryLineTim 199 std::vector<G4double>& trajectoryLineTimes) 176 { 200 { 177 // Assumes valid arguments from GetPoints 201 // Assumes valid arguments from GetPoints and GetTimes. 178 202 179 G4Polyline newTrajectoryLine; 203 G4Polyline newTrajectoryLine; 180 std::vector<G4double> newTrajectoryLineTim 204 std::vector<G4double> newTrajectoryLineTimes; 181 205 182 newTrajectoryLine.push_back(trajectoryLine 206 newTrajectoryLine.push_back(trajectoryLine[0]); 183 newTrajectoryLineTimes.push_back(trajector 207 newTrajectoryLineTimes.push_back(trajectoryLineTimes[0]); 184 size_t lineSize = trajectoryLine.size(); 208 size_t lineSize = trajectoryLine.size(); 185 if (lineSize > 1) { 209 if (lineSize > 1) { 186 for (size_t i = 1; i < trajectoryLine.si 210 for (size_t i = 1; i < trajectoryLine.size(); ++i) { 187 G4double deltaT = trajectoryLineTimes[i] - t 211 G4double deltaT = trajectoryLineTimes[i] - trajectoryLineTimes[i - 1]; 188 if (deltaT > 0.) { 212 if (deltaT > 0.) { 189 G4double practicalTimeIncrement = 213 G4double practicalTimeIncrement = 190 std::max(timeIncrement, deltaT / 100.); 214 std::max(timeIncrement, deltaT / 100.); 191 for (G4double t = 215 for (G4double t = 192 (int(trajectoryLineTimes[i - 1]/practical 216 (int(trajectoryLineTimes[i - 1]/practicalTimeIncrement) + 1) * 193 practicalTimeIncrement; 217 practicalTimeIncrement; 194 t <= trajectoryLineTimes[i]; 218 t <= trajectoryLineTimes[i]; 195 t += practicalTimeIncrement) { 219 t += practicalTimeIncrement) { 196 G4ThreeVector pos = trajectoryLine[i - 1 220 G4ThreeVector pos = trajectoryLine[i - 1] + 197 (trajectoryLine[i] - trajectoryLine[i 221 (trajectoryLine[i] - trajectoryLine[i - 1]) * 198 ((t - trajectoryLineTimes[i - 1]) / de 222 ((t - trajectoryLineTimes[i - 1]) / deltaT); 199 newTrajectoryLine.push_back(pos); 223 newTrajectoryLine.push_back(pos); 200 newTrajectoryLineTimes.push_back(t); 224 newTrajectoryLineTimes.push_back(t); 201 } 225 } 202 } 226 } 203 newTrajectoryLine.push_back(trajectoryLine[i 227 newTrajectoryLine.push_back(trajectoryLine[i]); 204 newTrajectoryLineTimes.push_back(trajectoryL 228 newTrajectoryLineTimes.push_back(trajectoryLineTimes[i]); 205 } 229 } 206 } 230 } 207 231 208 trajectoryLine = std::move(newTrajectoryLi << 232 trajectoryLine = newTrajectoryLine; 209 trajectoryLineTimes = std::move(newTraject << 233 trajectoryLineTimes = newTrajectoryLineTimes; 210 } 234 } 211 235 212 static void DrawWithoutTime(const G4VisTrajC 236 static void DrawWithoutTime(const G4VisTrajContext& myContext, 213 G4Polyline& trajectoryLine, 237 G4Polyline& trajectoryLine, 214 G4Polymarker& auxiliaryPoints, 238 G4Polymarker& auxiliaryPoints, 215 G4Polymarker& stepPoints) 239 G4Polymarker& stepPoints) 216 { 240 { 217 // Draw without time slice information 241 // Draw without time slice information 218 242 219 G4VVisManager* pVVisManager = G4VVisManage 243 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 220 if (0 == pVVisManager) return; 244 if (0 == pVVisManager) return; 221 245 222 if (myContext.GetDrawLine() && myContext.G << 246 if (myContext.GetDrawLine()) { 223 G4VisAttributes trajectoryLineAttribs(my 247 G4VisAttributes trajectoryLineAttribs(myContext.GetLineColour()); 224 trajectoryLineAttribs.SetLineWidth(myCon << 248 trajectoryLineAttribs.SetVisibility(myContext.GetLineVisible()); 225 trajectoryLine.SetVisAttributes(&traject 249 trajectoryLine.SetVisAttributes(&trajectoryLineAttribs); 226 250 227 pVVisManager->Draw(trajectoryLine); 251 pVVisManager->Draw(trajectoryLine); 228 } 252 } 229 253 230 if (myContext.GetDrawAuxPts() && myContext << 254 if (myContext.GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) { 231 && (auxiliaryPoints.size() > 0)) { << 232 auxiliaryPoints.SetMarkerType(myContext. 255 auxiliaryPoints.SetMarkerType(myContext.GetAuxPtsType()); 233 auxiliaryPoints.SetSize(myContext.GetAux 256 auxiliaryPoints.SetSize(myContext.GetAuxPtsSizeType(), myContext.GetAuxPtsSize()); 234 auxiliaryPoints.SetFillStyle(myContext.G 257 auxiliaryPoints.SetFillStyle(myContext.GetAuxPtsFillStyle()); 235 258 236 G4VisAttributes auxiliaryPointsAttribs(m 259 G4VisAttributes auxiliaryPointsAttribs(myContext.GetAuxPtsColour()); >> 260 auxiliaryPointsAttribs.SetVisibility(myContext.GetAuxPtsVisible()); 237 auxiliaryPoints.SetVisAttributes(&auxili 261 auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs); 238 262 239 pVVisManager->Draw(auxiliaryPoints); 263 pVVisManager->Draw(auxiliaryPoints); 240 } 264 } 241 265 242 if (myContext.GetDrawStepPts() && myContex << 266 if (myContext.GetDrawStepPts() && (stepPoints.size() > 0)) { 243 && (stepPoints.size() > 0)) { << 244 stepPoints.SetMarkerType(myContext.GetSt 267 stepPoints.SetMarkerType(myContext.GetStepPtsType()); 245 stepPoints.SetSize(myContext.GetStepPtsS 268 stepPoints.SetSize(myContext.GetStepPtsSizeType(), myContext.GetStepPtsSize()); 246 stepPoints.SetFillStyle(myContext.GetSte 269 stepPoints.SetFillStyle(myContext.GetStepPtsFillStyle()); 247 270 248 G4VisAttributes stepPointsAttribs(myCont 271 G4VisAttributes stepPointsAttribs(myContext.GetStepPtsColour()); >> 272 stepPointsAttribs.SetVisibility(myContext.GetStepPtsVisible()); 249 stepPoints.SetVisAttributes(&stepPointsA 273 stepPoints.SetVisAttributes(&stepPointsAttribs); 250 274 251 pVVisManager->Draw(stepPoints); 275 pVVisManager->Draw(stepPoints); 252 } 276 } 253 } 277 } 254 278 255 static void DrawWithTime(const G4VisTrajCont 279 static void DrawWithTime(const G4VisTrajContext& myContext, 256 G4Polyline& trajectoryLine, 280 G4Polyline& trajectoryLine, 257 G4Polymarker& auxiliaryPoints, 281 G4Polymarker& auxiliaryPoints, 258 G4Polymarker& stepPoints, 282 G4Polymarker& stepPoints, 259 std::vector<G4double>& trajectoryLine 283 std::vector<G4double>& trajectoryLineTimes, 260 std::vector<G4double>& auxiliaryPoint 284 std::vector<G4double>& auxiliaryPointTimes, 261 std::vector<G4double>& stepPointTimes 285 std::vector<G4double>& stepPointTimes) 262 { 286 { 263 // Draw with time slice information 287 // Draw with time slice information 264 288 265 G4VVisManager* pVVisManager = G4VVisManage 289 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 266 if (0 == pVVisManager) return; 290 if (0 == pVVisManager) return; 267 291 268 if (myContext.GetDrawLine() && myContext.G << 292 if (myContext.GetDrawLine()) { 269 G4VisAttributes trajectoryLineAttribs(my 293 G4VisAttributes trajectoryLineAttribs(myContext.GetLineColour()); 270 trajectoryLineAttribs.SetLineWidth(myCon << 294 trajectoryLineAttribs.SetVisibility(myContext.GetLineVisible()); 271 295 272 for (size_t i = 1; i < trajectoryLine.si 296 for (size_t i = 1; i < trajectoryLine.size(); ++i ) { 273 G4Polyline slice; 297 G4Polyline slice; 274 slice.push_back(trajectoryLine[i -1]); 298 slice.push_back(trajectoryLine[i -1]); 275 slice.push_back(trajectoryLine[i]); 299 slice.push_back(trajectoryLine[i]); 276 trajectoryLineAttribs.SetStartTime(trajector 300 trajectoryLineAttribs.SetStartTime(trajectoryLineTimes[i - 1]); 277 trajectoryLineAttribs.SetEndTime(trajectoryL 301 trajectoryLineAttribs.SetEndTime(trajectoryLineTimes[i]); 278 slice.SetVisAttributes(&trajectoryLineAttrib 302 slice.SetVisAttributes(&trajectoryLineAttribs); 279 pVVisManager->Draw(slice); 303 pVVisManager->Draw(slice); 280 } 304 } 281 } 305 } 282 306 283 if (myContext.GetDrawAuxPts() && myContext << 307 if (myContext.GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) { 284 && (auxiliaryPoints.size() > 0)) { << 285 G4VisAttributes auxiliaryPointsAttribs(m 308 G4VisAttributes auxiliaryPointsAttribs(myContext.GetAuxPtsColour()); >> 309 auxiliaryPointsAttribs.SetVisibility(myContext.GetAuxPtsVisible()); 286 310 287 for (size_t i = 0; i < auxiliaryPoints.s 311 for (size_t i = 0; i < auxiliaryPoints.size(); ++i ) { 288 G4Polymarker point; 312 G4Polymarker point; 289 point.push_back(auxiliaryPoints[i]); 313 point.push_back(auxiliaryPoints[i]); 290 point.SetMarkerType(myContext.GetAuxPtsType( 314 point.SetMarkerType(myContext.GetAuxPtsType()); 291 point.SetSize(myContext.GetAuxPtsSizeType(), 315 point.SetSize(myContext.GetAuxPtsSizeType(), myContext.GetAuxPtsSize()); 292 point.SetFillStyle(myContext.GetAuxPtsFillSt 316 point.SetFillStyle(myContext.GetAuxPtsFillStyle()); 293 auxiliaryPointsAttribs.SetStartTime(auxiliar 317 auxiliaryPointsAttribs.SetStartTime(auxiliaryPointTimes[i]); 294 auxiliaryPointsAttribs.SetEndTime(auxiliaryP 318 auxiliaryPointsAttribs.SetEndTime(auxiliaryPointTimes[i]); 295 point.SetVisAttributes(&auxiliaryPointsAttri 319 point.SetVisAttributes(&auxiliaryPointsAttribs); 296 pVVisManager->Draw(point); 320 pVVisManager->Draw(point); 297 } 321 } 298 } 322 } 299 323 300 if (myContext.GetDrawStepPts() && myContex << 324 if (myContext.GetDrawStepPts() && (stepPoints.size() > 0)) { 301 && (stepPoints.size() > 0)) { << 302 G4VisAttributes stepPointsAttribs(myCont 325 G4VisAttributes stepPointsAttribs(myContext.GetStepPtsColour()); >> 326 stepPointsAttribs.SetVisibility(myContext.GetStepPtsVisible()); 303 327 304 for (size_t i = 0; i < stepPoints.size() 328 for (size_t i = 0; i < stepPoints.size(); ++i ) { 305 G4Polymarker point; 329 G4Polymarker point; 306 point.push_back(stepPoints[i]); 330 point.push_back(stepPoints[i]); 307 point.SetMarkerType(myContext.GetStepPtsType 331 point.SetMarkerType(myContext.GetStepPtsType()); 308 point.SetSize(myContext.GetStepPtsSizeType() 332 point.SetSize(myContext.GetStepPtsSizeType(), myContext.GetStepPtsSize()); 309 point.SetFillStyle(myContext.GetStepPtsFillS 333 point.SetFillStyle(myContext.GetStepPtsFillStyle()); 310 stepPointsAttribs.SetStartTime(stepPointTime 334 stepPointsAttribs.SetStartTime(stepPointTimes[i]); 311 stepPointsAttribs.SetEndTime(stepPointTimes[ 335 stepPointsAttribs.SetEndTime(stepPointTimes[i]); 312 point.SetVisAttributes(&stepPointsAttribs); 336 point.SetVisAttributes(&stepPointsAttribs); 313 pVVisManager->Draw(point); 337 pVVisManager->Draw(point); 314 } 338 } 315 } 339 } 316 } 340 } 317 341 318 void DrawLineAndPoints(const G4VTrajectory& << 342 void DrawLineAndPoints(const G4VTrajectory& traj, const G4VisTrajContext& context, const G4int& i_mode) 319 { 343 { >> 344 // Extra copy while i_mode is still around >> 345 G4VisTrajContext myContext(context); >> 346 >> 347 if (i_mode != 0) { >> 348 const G4double markerSize = std::abs(i_mode)/1000; >> 349 G4bool lineRequired (i_mode >= 0); >> 350 G4bool markersRequired (markerSize > 0.); >> 351 >> 352 myContext.SetDrawLine(lineRequired); >> 353 myContext.SetDrawAuxPts(markersRequired); >> 354 myContext.SetDrawStepPts(markersRequired); >> 355 >> 356 myContext.SetAuxPtsSize(markerSize); >> 357 myContext.SetStepPtsSize(markerSize); >> 358 >> 359 static G4bool warnedAboutIMode = false; >> 360 >> 361 if (!warnedAboutIMode) { >> 362 G4cout<<"Trajectory drawing configuration will be based on imode value of "<<i_mode<<G4endl; >> 363 warnedAboutIMode = true; >> 364 } >> 365 } >> 366 320 // Return if don't need to do anything 367 // Return if don't need to do anything 321 if (!context.GetDrawLine() && !context.Get << 368 if (!myContext.GetDrawLine() && !myContext.GetDrawAuxPts() && !myContext.GetDrawStepPts()) return; 322 369 323 // Get points and times (times are returne << 370 // Get points to draw 324 // is requested). << 325 G4Polyline trajectoryLine; 371 G4Polyline trajectoryLine; 326 G4Polymarker stepPoints; 372 G4Polymarker stepPoints; 327 G4Polymarker auxiliaryPoints; 373 G4Polymarker auxiliaryPoints; 328 std::vector<G4double> trajectoryLineTimes; << 374 329 std::vector<G4double> stepPointTimes; << 375 GetPoints(traj, trajectoryLine, auxiliaryPoints, stepPoints); 330 std::vector<G4double> auxiliaryPointTimes; << 376 331 << 377 if (myContext.GetTimeSliceInterval()) { 332 TimesValidity validity = GetPointsAndTimes << 378 333 (traj, context, << 379 // Get corresponding track time information, if any 334 trajectoryLine, auxiliaryPoints, stepPo << 380 std::vector<G4double> trajectoryLineTimes; 335 trajectoryLineTimes, auxiliaryPointTime << 381 std::vector<G4double> stepPointTimes; 336 << 382 std::vector<G4double> auxiliaryPointTimes; 337 if (validity == ValidTimes) { << 383 338 << 384 GetTimes(traj, trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); 339 SliceLine(context.GetTimeSliceInterval() << 385 340 trajectoryLine, trajectoryLineTimes); << 386 // Check validity 341 << 387 if (trajectoryLineTimes.size() != trajectoryLine.size() || 342 DrawWithTime(context, << 388 stepPointTimes.size() != stepPoints.size() || 343 trajectoryLine, auxiliaryPoints, stepPo << 389 auxiliaryPointTimes.size() != auxiliaryPoints.size()) { 344 trajectoryLineTimes, auxiliaryPointTime << 390 >> 391 // Revert to drawing without time information... >> 392 DrawWithoutTime(myContext, trajectoryLine, auxiliaryPoints, stepPoints); >> 393 } else { >> 394 >> 395 SliceLine(myContext.GetTimeSliceInterval(), >> 396 trajectoryLine, trajectoryLineTimes); >> 397 >> 398 DrawWithTime(myContext, >> 399 trajectoryLine, auxiliaryPoints, stepPoints, >> 400 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); >> 401 } 345 402 346 } else { 403 } else { 347 404 348 DrawWithoutTime(context, trajectoryLine, << 405 DrawWithoutTime(myContext, trajectoryLine, auxiliaryPoints, stepPoints); 349 406 350 } 407 } 351 } 408 } 352 } 409 } 353 410