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.15 2010-11-14 22:13:55 allison Exp $ >> 27 // GEANT4 tag $Name: geant4-09-04-patch-01 $ 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" >> 42 #include <sstream> 40 43 41 #include <utility> << 44 namespace G4TrajectoryDrawerUtils { 42 45 43 #define G4warn G4cout << 44 46 45 namespace G4TrajectoryDrawerUtils { << 47 void GetPoints(const G4VTrajectory& traj, >> 48 G4Polyline& trajectoryLine, >> 49 G4Polymarker& auxiliaryPoints, >> 50 G4Polymarker& stepPoints) >> 51 { >> 52 // Keep positions. Don't store unless first or different. >> 53 std::vector<G4ThreeVector> positions; 46 54 47 enum TimesValidity {InvalidTimes, ValidTimes << 55 for (G4int i=0; i<traj.GetPointEntries(); i++) { 48 56 49 TimesValidity GetPointsAndTimes << 57 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i); 50 (const G4VTrajectory& traj, << 58 const G4ThreeVector& trajectoryPointPosition = 51 const G4VisTrajContext& context, << 59 aTrajectoryPoint->GetPosition(); 52 G4Polyline& trajectoryLine, << 60 53 G4Polymarker& auxiliaryPoints, << 61 // Only store if first or if different 54 G4Polymarker& stepPoints, << 62 if (positions.size() == 0 || 55 std::vector<G4double>& trajectoryLineTimes, << 63 trajectoryPointPosition != positions[positions.size()-1]) { 56 std::vector<G4double>& auxiliaryPointTimes, << 64 57 std::vector<G4double>& stepPointTimes) << 65 const std::vector<G4ThreeVector>* auxiliaries >> 66 = aTrajectoryPoint->GetAuxiliaryPoints(); >> 67 if (0 != auxiliaries) { >> 68 for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) { >> 69 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux]; >> 70 if (positions.size() == 0 || >> 71 auxPointPosition != positions[positions.size()-1]) { >> 72 // Only store if first or if different >> 73 positions.push_back(trajectoryPointPosition); >> 74 trajectoryLine.push_back(auxPointPosition); >> 75 auxiliaryPoints.push_back(auxPointPosition); >> 76 } >> 77 } >> 78 } >> 79 >> 80 positions.push_back(trajectoryPointPosition); >> 81 trajectoryLine.push_back(trajectoryPointPosition); >> 82 stepPoints.push_back(trajectoryPointPosition); >> 83 } >> 84 } >> 85 } >> 86 >> 87 /*** >> 88 void DrawLineAndPoints(const G4VTrajectory& traj, const G4int& i_mode, const G4Colour& colour, const G4bool& visible) { >> 89 // If i_mode>=0, draws a trajectory as a polyline (default is blue for >> 90 // positive, red for negative, green for neutral) and, if i_mode!=0, >> 91 // adds markers - yellow circles for step points and magenta squares >> 92 // for auxiliary points, if any - whose screen size in pixels is >> 93 // given by std::abs(i_mode)/1000. E.g: i_mode = 5000 gives easily >> 94 // visible markers. >> 95 >> 96 static G4bool warnedAboutIMode = false; >> 97 std::ostringstream oss; >> 98 oss << "WARNING: DEPRECATED use of i_mode (i_mode: " << i_mode >> 99 << "). Feature will be removed at a future major release."; >> 100 if (!warnedAboutIMode) { >> 101 G4Exception >> 102 ("G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, i_mode, colour, visible)", >> 103 "", >> 104 JustWarning, >> 105 oss.str().c_str()); >> 106 warnedAboutIMode = true; >> 107 } >> 108 >> 109 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); >> 110 if (0 == pVVisManager) return; >> 111 >> 112 const G4double markerSize = std::abs(i_mode)/1000; >> 113 G4bool lineRequired (i_mode >= 0); >> 114 G4bool markersRequired (markerSize > 0.); >> 115 >> 116 // Return if don't need to do anything >> 117 if (!lineRequired && !markersRequired) return; >> 118 >> 119 // Get points to draw >> 120 G4Polyline trajectoryLine; >> 121 G4Polymarker stepPoints; >> 122 G4Polymarker auxiliaryPoints; >> 123 >> 124 GetPoints(traj, trajectoryLine, auxiliaryPoints, stepPoints); >> 125 >> 126 if (lineRequired) { >> 127 G4VisAttributes trajectoryLineAttribs(colour); >> 128 trajectoryLineAttribs.SetVisibility(visible); >> 129 trajectoryLine.SetVisAttributes(&trajectoryLineAttribs); >> 130 pVVisManager->Draw(trajectoryLine); >> 131 } >> 132 >> 133 if (markersRequired) { >> 134 auxiliaryPoints.SetMarkerType(G4Polymarker::squares); >> 135 auxiliaryPoints.SetScreenSize(markerSize); >> 136 auxiliaryPoints.SetFillStyle(G4VMarker::filled); >> 137 G4VisAttributes auxiliaryPointsAttribs(G4Colour(0.,1.,1.)); // Magenta >> 138 auxiliaryPointsAttribs.SetVisibility(visible); >> 139 auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs); >> 140 pVVisManager->Draw(auxiliaryPoints); >> 141 >> 142 stepPoints.SetMarkerType(G4Polymarker::circles); >> 143 stepPoints.SetScreenSize(markerSize); >> 144 stepPoints.SetFillStyle(G4VMarker::filled); >> 145 G4VisAttributes stepPointsAttribs(G4Colour(1.,1.,0.)); // Yellow. >> 146 stepPoints.SetVisAttributes(&stepPointsAttribs); >> 147 pVVisManager->Draw(stepPoints); >> 148 } >> 149 >> 150 } >> 151 ***/ >> 152 >> 153 static void GetTimes(const G4VTrajectory& traj, >> 154 std::vector<G4double>& trajectoryLineTimes, >> 155 std::vector<G4double>& auxiliaryPointTimes, >> 156 std::vector<G4double>& stepPointTimes) 58 { 157 { 59 TimesValidity validity = InvalidTimes; << 158 // It is important check that the sizes of times vectors produced 60 if (context.GetTimeSliceInterval()) validi << 159 // by this function matches those of points vectors from >> 160 // GetPoints. If not, assume that the time information is >> 161 // invalid. 61 162 62 // Memory for last trajectory point positi 163 // Memory for last trajectory point position for auxiliary point 63 // time interpolation algorithm. There ar << 164 // algorithm. There are no auxiliary points for the first 64 // for the first trajectory point, so its << 165 // trajectory point, so its initial value is immaterial. 65 // immaterial. << 66 G4ThreeVector lastTrajectoryPointPosition; 166 G4ThreeVector lastTrajectoryPointPosition; 67 167 68 // Keep positions. Don't store unless fir 168 // Keep positions. Don't store unless first or different. 69 std::vector<G4ThreeVector> positions; 169 std::vector<G4ThreeVector> positions; 70 170 71 for (G4int iPoint=0; iPoint<traj.GetPointE << 171 for (G4int i=0; i<traj.GetPointEntries(); i++) { 72 172 73 G4VTrajectoryPoint* aTrajectoryPoint = t << 173 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i); 74 const G4ThreeVector& trajectoryPointPosi 174 const G4ThreeVector& trajectoryPointPosition = 75 aTrajectoryPoint->GetPosition(); << 175 aTrajectoryPoint->GetPosition(); 76 176 77 // Only store if first or if different 177 // Only store if first or if different 78 if (positions.size() == 0 || 178 if (positions.size() == 0 || 79 trajectoryPointPosition != positions[posit 179 trajectoryPointPosition != positions[positions.size()-1]) { 80 180 81 // Pre- and Post-Point times from the trajec 181 // Pre- and Post-Point times from the trajectory point... 82 G4double trajectoryPointPreTime = -std::nume 182 G4double trajectoryPointPreTime = -std::numeric_limits<double>::max(); 83 G4double trajectoryPointPostTime = std::nume 183 G4double trajectoryPointPostTime = std::numeric_limits<double>::max(); 84 << 184 std::vector<G4AttValue>* trajectoryPointAttValues = 85 if (context.GetTimeSliceInterval() && validi << 185 aTrajectoryPoint->CreateAttValues(); 86 << 186 if (!trajectoryPointAttValues) { 87 std::vector<G4AttValue>* trajectoryPointAt << 187 G4cout << "G4TrajectoryDrawerUtils::GetTimes: no att values." 88 aTrajectoryPoint->CreateAttValues(); << 188 << G4endl; 89 if (!trajectoryPointAttValues) { << 189 return; 90 static G4bool warnedNoAttValues = false; << 190 } else { 91 if (!warnedNoAttValues) { << 191 G4bool foundPreTime = false, foundPostTime = false; 92 G4warn << << 192 for (std::vector<G4AttValue>::iterator i = 93 "******************************************* << 193 trajectoryPointAttValues->begin(); 94 "\n* WARNING: G4TrajectoryDrawerUtils::GetP << 194 i != trajectoryPointAttValues->end(); ++i) { 95 "\n***************************************** << 195 if (i->GetName() == "PreT") { 96 << G4endl; << 196 trajectoryPointPreTime = 97 warnedNoAttValues = true; << 197 G4UIcommand::ConvertToDimensionedDouble(i->GetValue()); >> 198 foundPreTime = true; 98 } 199 } 99 validity = InvalidTimes; << 200 if (i->GetName() == "PostT") { 100 } else { << 201 trajectoryPointPostTime = 101 G4bool foundPreTime = false, foundPostTi << 202 G4UIcommand::ConvertToDimensionedDouble(i->GetValue()); 102 for (std::vector<G4AttValue>::iterator i << 203 foundPostTime = true; 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 } 204 } 116 if (!foundPreTime || !foundPostTime) { << 205 } 117 static G4bool warnedTimesNotFound = fa << 206 if (!foundPreTime || !foundPostTime) { 118 if (!warnedTimesNotFound) { << 207 static G4bool warnedTimesNotFound = false; 119 G4warn << << 208 if (!warnedTimesNotFound) { 120 "******************************************* << 209 G4cout << 121 "\n* WARNING: G4TrajectoryDrawerUtils::GetP << 210 "WARNING: G4TrajectoryDrawerUtils::GetTimes: times not found." 122 "\n You need to specify \"/vis/scene/add/tra << 211 << G4endl; 123 "\n***************************************** << 212 warnedTimesNotFound = true; 124 << G4endl; << 125 warnedTimesNotFound = true; << 126 } << 127 validity = InvalidTimes; << 128 } 213 } >> 214 return; 129 } 215 } 130 delete trajectoryPointAttValues; // << 131 } 216 } 132 217 133 const std::vector<G4ThreeVector>* auxiliarie 218 const std::vector<G4ThreeVector>* auxiliaries 134 = aTrajectoryPoint->GetAuxiliaryPoints(); 219 = aTrajectoryPoint->GetAuxiliaryPoints(); 135 if (0 != auxiliaries) { 220 if (0 != auxiliaries) { 136 for (size_t iAux=0; iAux<auxiliaries->size 221 for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) { >> 222 // Interpolate time for auxiliary points... 137 const G4ThreeVector& auxPointPosition = 223 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux]; >> 224 G4double s1 = (auxPointPosition - lastTrajectoryPointPosition).mag(); >> 225 G4double s2 = (trajectoryPointPosition - auxPointPosition).mag(); >> 226 G4double t = trajectoryPointPreTime + >> 227 (trajectoryPointPostTime - trajectoryPointPreTime) * >> 228 (s1 / (s1 + s2)); >> 229 // Only store if first or if different 138 if (positions.size() == 0 || 230 if (positions.size() == 0 || 139 auxPointPosition != positions[positions.si 231 auxPointPosition != positions[positions.size()-1]) { 140 // Only store if first or if different << 141 positions.push_back(trajectoryPointPos 232 positions.push_back(trajectoryPointPosition); 142 trajectoryLine.push_back(auxPointPosit << 233 trajectoryLineTimes.push_back(t); 143 auxiliaryPoints.push_back(auxPointPosi << 234 auxiliaryPointTimes.push_back(t); 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 } 235 } 157 } 236 } 158 } 237 } 159 238 160 positions.push_back(trajectoryPointPosition) 239 positions.push_back(trajectoryPointPosition); 161 trajectoryLine.push_back(trajectoryPointPosi << 240 trajectoryLineTimes.push_back(trajectoryPointPostTime); 162 stepPoints.push_back(trajectoryPointPosition << 241 stepPointTimes.push_back(trajectoryPointPostTime); 163 if (validity == ValidTimes) { << 242 164 trajectoryLineTimes.push_back(trajectoryPo << 243 lastTrajectoryPointPosition = trajectoryPointPosition; 165 stepPointTimes.push_back(trajectoryPointPo << 166 } << 167 lastTrajectoryPointPosition = trajecto << 168 } 244 } 169 } << 245 } 170 return validity; << 171 } 246 } 172 247 173 static void SliceLine(G4double timeIncrement 248 static void SliceLine(G4double timeIncrement, 174 G4Polyline& trajectoryLine, 249 G4Polyline& trajectoryLine, 175 std::vector<G4double>& trajectoryLineTim 250 std::vector<G4double>& trajectoryLineTimes) 176 { 251 { 177 // Assumes valid arguments from GetPoints 252 // Assumes valid arguments from GetPoints and GetTimes. 178 253 179 G4Polyline newTrajectoryLine; 254 G4Polyline newTrajectoryLine; 180 std::vector<G4double> newTrajectoryLineTim 255 std::vector<G4double> newTrajectoryLineTimes; 181 256 182 newTrajectoryLine.push_back(trajectoryLine 257 newTrajectoryLine.push_back(trajectoryLine[0]); 183 newTrajectoryLineTimes.push_back(trajector 258 newTrajectoryLineTimes.push_back(trajectoryLineTimes[0]); 184 size_t lineSize = trajectoryLine.size(); 259 size_t lineSize = trajectoryLine.size(); 185 if (lineSize > 1) { 260 if (lineSize > 1) { 186 for (size_t i = 1; i < trajectoryLine.si 261 for (size_t i = 1; i < trajectoryLine.size(); ++i) { 187 G4double deltaT = trajectoryLineTimes[i] - t 262 G4double deltaT = trajectoryLineTimes[i] - trajectoryLineTimes[i - 1]; 188 if (deltaT > 0.) { 263 if (deltaT > 0.) { 189 G4double practicalTimeIncrement = 264 G4double practicalTimeIncrement = 190 std::max(timeIncrement, deltaT / 100.); 265 std::max(timeIncrement, deltaT / 100.); 191 for (G4double t = 266 for (G4double t = 192 (int(trajectoryLineTimes[i - 1]/practical 267 (int(trajectoryLineTimes[i - 1]/practicalTimeIncrement) + 1) * 193 practicalTimeIncrement; 268 practicalTimeIncrement; 194 t <= trajectoryLineTimes[i]; 269 t <= trajectoryLineTimes[i]; 195 t += practicalTimeIncrement) { 270 t += practicalTimeIncrement) { 196 G4ThreeVector pos = trajectoryLine[i - 1 271 G4ThreeVector pos = trajectoryLine[i - 1] + 197 (trajectoryLine[i] - trajectoryLine[i 272 (trajectoryLine[i] - trajectoryLine[i - 1]) * 198 ((t - trajectoryLineTimes[i - 1]) / de 273 ((t - trajectoryLineTimes[i - 1]) / deltaT); 199 newTrajectoryLine.push_back(pos); 274 newTrajectoryLine.push_back(pos); 200 newTrajectoryLineTimes.push_back(t); 275 newTrajectoryLineTimes.push_back(t); 201 } 276 } 202 } 277 } 203 newTrajectoryLine.push_back(trajectoryLine[i 278 newTrajectoryLine.push_back(trajectoryLine[i]); 204 newTrajectoryLineTimes.push_back(trajectoryL 279 newTrajectoryLineTimes.push_back(trajectoryLineTimes[i]); 205 } 280 } 206 } 281 } 207 282 208 trajectoryLine = std::move(newTrajectoryLi << 283 trajectoryLine = newTrajectoryLine; 209 trajectoryLineTimes = std::move(newTraject << 284 trajectoryLineTimes = newTrajectoryLineTimes; 210 } 285 } 211 286 212 static void DrawWithoutTime(const G4VisTrajC 287 static void DrawWithoutTime(const G4VisTrajContext& myContext, 213 G4Polyline& trajectoryLine, 288 G4Polyline& trajectoryLine, 214 G4Polymarker& auxiliaryPoints, 289 G4Polymarker& auxiliaryPoints, 215 G4Polymarker& stepPoints) 290 G4Polymarker& stepPoints) 216 { 291 { 217 // Draw without time slice information 292 // Draw without time slice information 218 293 219 G4VVisManager* pVVisManager = G4VVisManage 294 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 220 if (0 == pVVisManager) return; 295 if (0 == pVVisManager) return; 221 296 222 if (myContext.GetDrawLine() && myContext.G << 297 if (myContext.GetDrawLine()) { 223 G4VisAttributes trajectoryLineAttribs(my 298 G4VisAttributes trajectoryLineAttribs(myContext.GetLineColour()); 224 trajectoryLineAttribs.SetLineWidth(myCon << 299 trajectoryLineAttribs.SetVisibility(myContext.GetLineVisible()); 225 trajectoryLine.SetVisAttributes(&traject 300 trajectoryLine.SetVisAttributes(&trajectoryLineAttribs); 226 301 227 pVVisManager->Draw(trajectoryLine); 302 pVVisManager->Draw(trajectoryLine); 228 } 303 } 229 304 230 if (myContext.GetDrawAuxPts() && myContext << 305 if (myContext.GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) { 231 && (auxiliaryPoints.size() > 0)) { << 232 auxiliaryPoints.SetMarkerType(myContext. 306 auxiliaryPoints.SetMarkerType(myContext.GetAuxPtsType()); 233 auxiliaryPoints.SetSize(myContext.GetAux 307 auxiliaryPoints.SetSize(myContext.GetAuxPtsSizeType(), myContext.GetAuxPtsSize()); 234 auxiliaryPoints.SetFillStyle(myContext.G 308 auxiliaryPoints.SetFillStyle(myContext.GetAuxPtsFillStyle()); 235 309 236 G4VisAttributes auxiliaryPointsAttribs(m 310 G4VisAttributes auxiliaryPointsAttribs(myContext.GetAuxPtsColour()); >> 311 auxiliaryPointsAttribs.SetVisibility(myContext.GetAuxPtsVisible()); 237 auxiliaryPoints.SetVisAttributes(&auxili 312 auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs); 238 313 239 pVVisManager->Draw(auxiliaryPoints); 314 pVVisManager->Draw(auxiliaryPoints); 240 } 315 } 241 316 242 if (myContext.GetDrawStepPts() && myContex << 317 if (myContext.GetDrawStepPts() && (stepPoints.size() > 0)) { 243 && (stepPoints.size() > 0)) { << 244 stepPoints.SetMarkerType(myContext.GetSt 318 stepPoints.SetMarkerType(myContext.GetStepPtsType()); 245 stepPoints.SetSize(myContext.GetStepPtsS 319 stepPoints.SetSize(myContext.GetStepPtsSizeType(), myContext.GetStepPtsSize()); 246 stepPoints.SetFillStyle(myContext.GetSte 320 stepPoints.SetFillStyle(myContext.GetStepPtsFillStyle()); 247 321 248 G4VisAttributes stepPointsAttribs(myCont 322 G4VisAttributes stepPointsAttribs(myContext.GetStepPtsColour()); >> 323 stepPointsAttribs.SetVisibility(myContext.GetStepPtsVisible()); 249 stepPoints.SetVisAttributes(&stepPointsA 324 stepPoints.SetVisAttributes(&stepPointsAttribs); 250 325 251 pVVisManager->Draw(stepPoints); 326 pVVisManager->Draw(stepPoints); 252 } 327 } 253 } 328 } 254 329 255 static void DrawWithTime(const G4VisTrajCont 330 static void DrawWithTime(const G4VisTrajContext& myContext, 256 G4Polyline& trajectoryLine, 331 G4Polyline& trajectoryLine, 257 G4Polymarker& auxiliaryPoints, 332 G4Polymarker& auxiliaryPoints, 258 G4Polymarker& stepPoints, 333 G4Polymarker& stepPoints, 259 std::vector<G4double>& trajectoryLine 334 std::vector<G4double>& trajectoryLineTimes, 260 std::vector<G4double>& auxiliaryPoint 335 std::vector<G4double>& auxiliaryPointTimes, 261 std::vector<G4double>& stepPointTimes 336 std::vector<G4double>& stepPointTimes) 262 { 337 { 263 // Draw with time slice information 338 // Draw with time slice information 264 339 265 G4VVisManager* pVVisManager = G4VVisManage 340 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 266 if (0 == pVVisManager) return; 341 if (0 == pVVisManager) return; 267 342 268 if (myContext.GetDrawLine() && myContext.G << 343 if (myContext.GetDrawLine()) { 269 G4VisAttributes trajectoryLineAttribs(my 344 G4VisAttributes trajectoryLineAttribs(myContext.GetLineColour()); 270 trajectoryLineAttribs.SetLineWidth(myCon << 345 trajectoryLineAttribs.SetVisibility(myContext.GetLineVisible()); 271 346 272 for (size_t i = 1; i < trajectoryLine.si 347 for (size_t i = 1; i < trajectoryLine.size(); ++i ) { 273 G4Polyline slice; 348 G4Polyline slice; 274 slice.push_back(trajectoryLine[i -1]); 349 slice.push_back(trajectoryLine[i -1]); 275 slice.push_back(trajectoryLine[i]); 350 slice.push_back(trajectoryLine[i]); 276 trajectoryLineAttribs.SetStartTime(trajector 351 trajectoryLineAttribs.SetStartTime(trajectoryLineTimes[i - 1]); 277 trajectoryLineAttribs.SetEndTime(trajectoryL 352 trajectoryLineAttribs.SetEndTime(trajectoryLineTimes[i]); 278 slice.SetVisAttributes(&trajectoryLineAttrib 353 slice.SetVisAttributes(&trajectoryLineAttribs); 279 pVVisManager->Draw(slice); 354 pVVisManager->Draw(slice); 280 } 355 } 281 } 356 } 282 357 283 if (myContext.GetDrawAuxPts() && myContext << 358 if (myContext.GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) { 284 && (auxiliaryPoints.size() > 0)) { << 285 G4VisAttributes auxiliaryPointsAttribs(m 359 G4VisAttributes auxiliaryPointsAttribs(myContext.GetAuxPtsColour()); >> 360 auxiliaryPointsAttribs.SetVisibility(myContext.GetAuxPtsVisible()); 286 361 287 for (size_t i = 0; i < auxiliaryPoints.s 362 for (size_t i = 0; i < auxiliaryPoints.size(); ++i ) { 288 G4Polymarker point; 363 G4Polymarker point; 289 point.push_back(auxiliaryPoints[i]); 364 point.push_back(auxiliaryPoints[i]); 290 point.SetMarkerType(myContext.GetAuxPtsType( 365 point.SetMarkerType(myContext.GetAuxPtsType()); 291 point.SetSize(myContext.GetAuxPtsSizeType(), 366 point.SetSize(myContext.GetAuxPtsSizeType(), myContext.GetAuxPtsSize()); 292 point.SetFillStyle(myContext.GetAuxPtsFillSt 367 point.SetFillStyle(myContext.GetAuxPtsFillStyle()); 293 auxiliaryPointsAttribs.SetStartTime(auxiliar 368 auxiliaryPointsAttribs.SetStartTime(auxiliaryPointTimes[i]); 294 auxiliaryPointsAttribs.SetEndTime(auxiliaryP 369 auxiliaryPointsAttribs.SetEndTime(auxiliaryPointTimes[i]); 295 point.SetVisAttributes(&auxiliaryPointsAttri 370 point.SetVisAttributes(&auxiliaryPointsAttribs); 296 pVVisManager->Draw(point); 371 pVVisManager->Draw(point); 297 } 372 } 298 } 373 } 299 374 300 if (myContext.GetDrawStepPts() && myContex << 375 if (myContext.GetDrawStepPts() && (stepPoints.size() > 0)) { 301 && (stepPoints.size() > 0)) { << 302 G4VisAttributes stepPointsAttribs(myCont 376 G4VisAttributes stepPointsAttribs(myContext.GetStepPtsColour()); >> 377 stepPointsAttribs.SetVisibility(myContext.GetStepPtsVisible()); 303 378 304 for (size_t i = 0; i < stepPoints.size() 379 for (size_t i = 0; i < stepPoints.size(); ++i ) { 305 G4Polymarker point; 380 G4Polymarker point; 306 point.push_back(stepPoints[i]); 381 point.push_back(stepPoints[i]); 307 point.SetMarkerType(myContext.GetStepPtsType 382 point.SetMarkerType(myContext.GetStepPtsType()); 308 point.SetSize(myContext.GetStepPtsSizeType() 383 point.SetSize(myContext.GetStepPtsSizeType(), myContext.GetStepPtsSize()); 309 point.SetFillStyle(myContext.GetStepPtsFillS 384 point.SetFillStyle(myContext.GetStepPtsFillStyle()); 310 stepPointsAttribs.SetStartTime(stepPointTime 385 stepPointsAttribs.SetStartTime(stepPointTimes[i]); 311 stepPointsAttribs.SetEndTime(stepPointTimes[ 386 stepPointsAttribs.SetEndTime(stepPointTimes[i]); 312 point.SetVisAttributes(&stepPointsAttribs); 387 point.SetVisAttributes(&stepPointsAttribs); 313 pVVisManager->Draw(point); 388 pVVisManager->Draw(point); 314 } 389 } 315 } 390 } 316 } 391 } 317 392 >> 393 void DrawLineAndPoints(const G4VTrajectory& traj, const G4VisTrajContext& context, const G4int& i_mode) >> 394 { >> 395 static G4bool warnedAboutIMode = false; >> 396 std::ostringstream oss; >> 397 oss << "WARNING: DEPRECATED use of i_mode (i_mode: " << i_mode >> 398 << "). Feature will be removed at a future major release."; >> 399 if (!warnedAboutIMode) { >> 400 G4Exception >> 401 ("G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, context, i_mode)", >> 402 "", >> 403 JustWarning, >> 404 oss.str().c_str()); >> 405 warnedAboutIMode = true; >> 406 } >> 407 >> 408 // Extra copy while i_mode is still around >> 409 G4VisTrajContext myContext(context); >> 410 >> 411 if (i_mode != 0) { >> 412 const G4double markerSize = std::abs(i_mode)/1000; >> 413 G4bool lineRequired (i_mode >= 0); >> 414 G4bool markersRequired (markerSize > 0.); >> 415 >> 416 myContext.SetDrawLine(lineRequired); >> 417 myContext.SetDrawAuxPts(markersRequired); >> 418 myContext.SetDrawStepPts(markersRequired); >> 419 >> 420 myContext.SetAuxPtsSize(markerSize); >> 421 myContext.SetStepPtsSize(markerSize); >> 422 } >> 423 >> 424 // Return if don't need to do anything >> 425 if (!myContext.GetDrawLine() && !myContext.GetDrawAuxPts() && !myContext.GetDrawStepPts()) return; >> 426 >> 427 // Get points to draw >> 428 G4Polyline trajectoryLine; >> 429 G4Polymarker stepPoints; >> 430 G4Polymarker auxiliaryPoints; >> 431 >> 432 GetPoints(traj, trajectoryLine, auxiliaryPoints, stepPoints); >> 433 >> 434 if (myContext.GetTimeSliceInterval()) { >> 435 >> 436 // Get corresponding track time information, if any >> 437 std::vector<G4double> trajectoryLineTimes; >> 438 std::vector<G4double> stepPointTimes; >> 439 std::vector<G4double> auxiliaryPointTimes; >> 440 >> 441 GetTimes(traj, trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); >> 442 >> 443 // Check validity >> 444 if (trajectoryLineTimes.size() != trajectoryLine.size() || >> 445 stepPointTimes.size() != stepPoints.size() || >> 446 auxiliaryPointTimes.size() != auxiliaryPoints.size()) { >> 447 >> 448 // Revert to drawing without time information... >> 449 DrawWithoutTime(myContext, trajectoryLine, auxiliaryPoints, stepPoints); >> 450 } else { >> 451 >> 452 SliceLine(myContext.GetTimeSliceInterval(), >> 453 trajectoryLine, trajectoryLineTimes); >> 454 >> 455 DrawWithTime(myContext, >> 456 trajectoryLine, auxiliaryPoints, stepPoints, >> 457 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); >> 458 } >> 459 >> 460 } else { >> 461 >> 462 DrawWithoutTime(myContext, trajectoryLine, auxiliaryPoints, stepPoints); >> 463 >> 464 } >> 465 } >> 466 318 void DrawLineAndPoints(const G4VTrajectory& 467 void DrawLineAndPoints(const G4VTrajectory& traj, const G4VisTrajContext& context) 319 { 468 { 320 // Return if don't need to do anything 469 // Return if don't need to do anything 321 if (!context.GetDrawLine() && !context.Get 470 if (!context.GetDrawLine() && !context.GetDrawAuxPts() && !context.GetDrawStepPts()) return; 322 471 323 // Get points and times (times are returne << 472 // Get points to draw 324 // is requested). << 325 G4Polyline trajectoryLine; 473 G4Polyline trajectoryLine; 326 G4Polymarker stepPoints; 474 G4Polymarker stepPoints; 327 G4Polymarker auxiliaryPoints; 475 G4Polymarker auxiliaryPoints; 328 std::vector<G4double> trajectoryLineTimes; << 476 329 std::vector<G4double> stepPointTimes; << 477 GetPoints(traj, trajectoryLine, auxiliaryPoints, stepPoints); 330 std::vector<G4double> auxiliaryPointTimes; << 478 331 << 479 if (context.GetTimeSliceInterval()) { 332 TimesValidity validity = GetPointsAndTimes << 480 333 (traj, context, << 481 // Get corresponding track time information, if any 334 trajectoryLine, auxiliaryPoints, stepPo << 482 std::vector<G4double> trajectoryLineTimes; 335 trajectoryLineTimes, auxiliaryPointTime << 483 std::vector<G4double> stepPointTimes; 336 << 484 std::vector<G4double> auxiliaryPointTimes; 337 if (validity == ValidTimes) { << 485 338 << 486 GetTimes(traj, trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); 339 SliceLine(context.GetTimeSliceInterval() << 487 340 trajectoryLine, trajectoryLineTimes); << 488 // Check validity 341 << 489 if (trajectoryLineTimes.size() != trajectoryLine.size() || 342 DrawWithTime(context, << 490 stepPointTimes.size() != stepPoints.size() || 343 trajectoryLine, auxiliaryPoints, stepPo << 491 auxiliaryPointTimes.size() != auxiliaryPoints.size()) { 344 trajectoryLineTimes, auxiliaryPointTime << 492 >> 493 // Revert to drawing without time information... >> 494 DrawWithoutTime(context, trajectoryLine, auxiliaryPoints, stepPoints); >> 495 } else { >> 496 >> 497 SliceLine(context.GetTimeSliceInterval(), >> 498 trajectoryLine, trajectoryLineTimes); >> 499 >> 500 DrawWithTime(context, >> 501 trajectoryLine, auxiliaryPoints, stepPoints, >> 502 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes); >> 503 } 345 504 346 } else { 505 } else { 347 506 348 DrawWithoutTime(context, trajectoryLine, 507 DrawWithoutTime(context, trajectoryLine, auxiliaryPoints, stepPoints); 349 508 350 } 509 } 351 } 510 } 352 } 511 } 353 512