41 namespace G4TrajectoryDrawerUtils {
51 std::vector<G4double>& trajectoryLineTimes,
52 std::vector<G4double>& auxiliaryPointTimes,
53 std::vector<G4double>& stepPointTimes)
65 std::vector<G4ThreeVector> positions;
74 if (positions.size() == 0 ||
75 trajectoryPointPosition != positions[positions.size()-1]) {
83 std::vector<G4AttValue>* trajectoryPointAttValues =
85 if (!trajectoryPointAttValues) {
86 static G4bool warnedNoAttValues =
false;
87 if (!warnedNoAttValues) {
89 "*************************************************************************"
90 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: no att values."
91 "\n*************************************************************************"
93 warnedNoAttValues =
true;
97 G4bool foundPreTime =
false, foundPostTime =
false;
98 for (std::vector<G4AttValue>::iterator i =
99 trajectoryPointAttValues->begin();
100 i != trajectoryPointAttValues->end(); ++i) {
101 if (i->GetName() ==
"PreT") {
102 trajectoryPointPreTime =
106 if (i->GetName() ==
"PostT") {
107 trajectoryPointPostTime =
109 foundPostTime =
true;
112 if (!foundPreTime || !foundPostTime) {
113 static G4bool warnedTimesNotFound =
false;
114 if (!warnedTimesNotFound) {
116 "*************************************************************************"
117 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: times not found."
118 "\n You need to specify \"/vis/scene/add/trajectories rich\""
119 "\n*************************************************************************"
121 warnedTimesNotFound =
true;
126 delete trajectoryPointAttValues;
129 const std::vector<G4ThreeVector>* auxiliaries
131 if (0 != auxiliaries) {
132 for (
size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
133 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux];
134 if (positions.size() == 0 ||
135 auxPointPosition != positions[positions.size()-1]) {
137 positions.push_back(trajectoryPointPosition);
138 trajectoryLine.push_back(auxPointPosition);
139 auxiliaryPoints.push_back(auxPointPosition);
143 (auxPointPosition - lastTrajectoryPointPosition).mag();
145 (trajectoryPointPosition - auxPointPosition).mag();
147 (trajectoryPointPostTime - trajectoryPointPreTime) *
149 trajectoryLineTimes.push_back(t);
150 auxiliaryPointTimes.push_back(t);
156 positions.push_back(trajectoryPointPosition);
157 trajectoryLine.push_back(trajectoryPointPosition);
158 stepPoints.push_back(trajectoryPointPosition);
160 trajectoryLineTimes.push_back(trajectoryPointPostTime);
161 stepPointTimes.push_back(trajectoryPointPostTime);
163 lastTrajectoryPointPosition = trajectoryPointPosition;
171 std::vector<G4double>& trajectoryLineTimes)
176 std::vector<G4double> newTrajectoryLineTimes;
178 newTrajectoryLine.push_back(trajectoryLine[0]);
179 newTrajectoryLineTimes.push_back(trajectoryLineTimes[0]);
180 size_t lineSize = trajectoryLine.size();
182 for (
size_t i = 1; i < trajectoryLine.size(); ++i) {
183 G4double deltaT = trajectoryLineTimes[i] - trajectoryLineTimes[i - 1];
186 std::max(timeIncrement, deltaT / 100.);
188 (
int(trajectoryLineTimes[i - 1]/practicalTimeIncrement) + 1) *
189 practicalTimeIncrement;
190 t <= trajectoryLineTimes[i];
191 t += practicalTimeIncrement) {
193 (trajectoryLine[i] - trajectoryLine[i - 1]) *
194 ((
t - trajectoryLineTimes[i - 1]) / deltaT);
195 newTrajectoryLine.push_back(pos);
196 newTrajectoryLineTimes.push_back(
t);
199 newTrajectoryLine.push_back(trajectoryLine[i]);
200 newTrajectoryLineTimes.push_back(trajectoryLineTimes[i]);
204 trajectoryLine = newTrajectoryLine;
205 trajectoryLineTimes = newTrajectoryLineTimes;
216 if (0 == pVVisManager)
return;
223 pVVisManager->
Draw(trajectoryLine);
227 && (auxiliaryPoints.size() > 0)) {
235 pVVisManager->
Draw(auxiliaryPoints);
239 && (stepPoints.size() > 0)) {
247 pVVisManager->
Draw(stepPoints);
255 std::vector<G4double>& trajectoryLineTimes,
256 std::vector<G4double>& auxiliaryPointTimes,
257 std::vector<G4double>& stepPointTimes)
262 if (0 == pVVisManager)
return;
268 for (
size_t i = 1; i < trajectoryLine.size(); ++i ) {
270 slice.push_back(trajectoryLine[i -1]);
271 slice.push_back(trajectoryLine[i]);
272 trajectoryLineAttribs.SetStartTime(trajectoryLineTimes[i - 1]);
273 trajectoryLineAttribs.SetEndTime(trajectoryLineTimes[i]);
275 pVVisManager->
Draw(slice);
280 && (auxiliaryPoints.size() > 0)) {
283 for (
size_t i = 0; i < auxiliaryPoints.size(); ++i ) {
285 point.push_back(auxiliaryPoints[i]);
289 auxiliaryPointsAttribs.SetStartTime(auxiliaryPointTimes[i]);
290 auxiliaryPointsAttribs.SetEndTime(auxiliaryPointTimes[i]);
292 pVVisManager->
Draw(point);
297 && (stepPoints.size() > 0)) {
300 for (
size_t i = 0; i < stepPoints.size(); ++i ) {
302 point.push_back(stepPoints[i]);
306 stepPointsAttribs.SetStartTime(stepPointTimes[i]);
307 stepPointsAttribs.SetEndTime(stepPointTimes[i]);
309 pVVisManager->
Draw(point);
324 std::vector<G4double> trajectoryLineTimes;
325 std::vector<G4double> stepPointTimes;
326 std::vector<G4double> auxiliaryPointTimes;
330 trajectoryLine, auxiliaryPoints, stepPoints,
331 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
336 trajectoryLine, trajectoryLineTimes);
339 trajectoryLine, auxiliaryPoints, stepPoints,
340 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);