55 std::vector<G4double>& trajectoryLineTimes,
56 std::vector<G4double>& auxiliaryPointTimes,
57 std::vector<G4double>& stepPointTimes)
69 std::vector<G4ThreeVector> positions;
78 if (positions.size() == 0 ||
79 trajectoryPointPosition != positions[positions.size()-1]) {
82 G4double trajectoryPointPreTime = -std::numeric_limits<double>::max();
83 G4double trajectoryPointPostTime = std::numeric_limits<double>::max();
87 std::vector<G4AttValue>* trajectoryPointAttValues =
89 if (!trajectoryPointAttValues) {
90 static G4bool warnedNoAttValues =
false;
91 if (!warnedNoAttValues) {
93 "*************************************************************************"
94 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: no att values."
95 "\n*************************************************************************"
97 warnedNoAttValues =
true;
101 G4bool foundPreTime =
false, foundPostTime =
false;
102 for (std::vector<G4AttValue>::iterator i =
103 trajectoryPointAttValues->begin();
104 i != trajectoryPointAttValues->end(); ++i) {
105 if (i->GetName() ==
"PreT") {
106 trajectoryPointPreTime =
110 if (i->GetName() ==
"PostT") {
111 trajectoryPointPostTime =
113 foundPostTime =
true;
116 if (!foundPreTime || !foundPostTime) {
117 static G4bool warnedTimesNotFound =
false;
118 if (!warnedTimesNotFound) {
120 "*************************************************************************"
121 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: times not found."
122 "\n You need to specify \"/vis/scene/add/trajectories rich\""
123 "\n*************************************************************************"
125 warnedTimesNotFound =
true;
130 delete trajectoryPointAttValues;
133 const std::vector<G4ThreeVector>* auxiliaries
135 if (0 != auxiliaries) {
136 for (
size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
137 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux];
138 if (positions.size() == 0 ||
139 auxPointPosition != positions[positions.size()-1]) {
141 positions.push_back(trajectoryPointPosition);
142 trajectoryLine.push_back(auxPointPosition);
143 auxiliaryPoints.push_back(auxPointPosition);
147 (auxPointPosition - lastTrajectoryPointPosition).mag();
149 (trajectoryPointPosition - auxPointPosition).mag();
150 G4double t = trajectoryPointPreTime +
151 (trajectoryPointPostTime - trajectoryPointPreTime) *
153 trajectoryLineTimes.push_back(t);
154 auxiliaryPointTimes.push_back(t);
160 positions.push_back(trajectoryPointPosition);
161 trajectoryLine.push_back(trajectoryPointPosition);
162 stepPoints.push_back(trajectoryPointPosition);
164 trajectoryLineTimes.push_back(trajectoryPointPostTime);
165 stepPointTimes.push_back(trajectoryPointPostTime);
167 lastTrajectoryPointPosition = trajectoryPointPosition;
173 static void SliceLine(
G4double timeIncrement,
175 std::vector<G4double>& trajectoryLineTimes)
180 std::vector<G4double> newTrajectoryLineTimes;
182 newTrajectoryLine.push_back(trajectoryLine[0]);
183 newTrajectoryLineTimes.push_back(trajectoryLineTimes[0]);
184 size_t lineSize = trajectoryLine.size();
186 for (
size_t i = 1; i < trajectoryLine.size(); ++i) {
187 G4double deltaT = trajectoryLineTimes[i] - trajectoryLineTimes[i - 1];
190 std::max(timeIncrement, deltaT / 100.);
192 (
int(trajectoryLineTimes[i - 1]/practicalTimeIncrement) + 1) *
193 practicalTimeIncrement;
194 t <= trajectoryLineTimes[i];
195 t += practicalTimeIncrement) {
197 (trajectoryLine[i] - trajectoryLine[i - 1]) *
198 ((t - trajectoryLineTimes[i - 1]) / deltaT);
199 newTrajectoryLine.push_back(pos);
200 newTrajectoryLineTimes.push_back(t);
203 newTrajectoryLine.push_back(trajectoryLine[i]);
204 newTrajectoryLineTimes.push_back(trajectoryLineTimes[i]);
208 trajectoryLine = std::move(newTrajectoryLine);
209 trajectoryLineTimes = std::move(newTrajectoryLineTimes);
212 static void DrawWithoutTime(
const G4VisTrajContext& myContext,
213 G4Polyline& trajectoryLine,
214 G4Polymarker& auxiliaryPoints,
215 G4Polymarker& stepPoints)
220 if (0 == pVVisManager)
return;
223 G4VisAttributes trajectoryLineAttribs(myContext.
GetLineColour());
224 trajectoryLineAttribs.SetLineWidth(myContext.
GetLineWidth());
227 pVVisManager->
Draw(trajectoryLine);
231 && (auxiliaryPoints.size() > 0)) {
239 pVVisManager->
Draw(auxiliaryPoints);
243 && (stepPoints.size() > 0)) {
251 pVVisManager->
Draw(stepPoints);
255 static void DrawWithTime(
const G4VisTrajContext& myContext,
256 G4Polyline& trajectoryLine,
257 G4Polymarker& auxiliaryPoints,
258 G4Polymarker& stepPoints,
259 std::vector<G4double>& trajectoryLineTimes,
260 std::vector<G4double>& auxiliaryPointTimes,
261 std::vector<G4double>& stepPointTimes)
266 if (0 == pVVisManager)
return;
269 G4VisAttributes trajectoryLineAttribs(myContext.
GetLineColour());
270 trajectoryLineAttribs.SetLineWidth(myContext.
GetLineWidth());
272 for (
size_t i = 1; i < trajectoryLine.size(); ++i ) {
274 slice.push_back(trajectoryLine[i -1]);
275 slice.push_back(trajectoryLine[i]);
276 trajectoryLineAttribs.SetStartTime(trajectoryLineTimes[i - 1]);
277 trajectoryLineAttribs.SetEndTime(trajectoryLineTimes[i]);
279 pVVisManager->
Draw(slice);
284 && (auxiliaryPoints.size() > 0)) {
287 for (
size_t i = 0; i < auxiliaryPoints.size(); ++i ) {
289 point.push_back(auxiliaryPoints[i]);
293 auxiliaryPointsAttribs.SetStartTime(auxiliaryPointTimes[i]);
294 auxiliaryPointsAttribs.SetEndTime(auxiliaryPointTimes[i]);
296 pVVisManager->
Draw(point);
301 && (stepPoints.size() > 0)) {
304 for (
size_t i = 0; i < stepPoints.size(); ++i ) {
306 point.push_back(stepPoints[i]);
310 stepPointsAttribs.SetStartTime(stepPointTimes[i]);
311 stepPointsAttribs.SetEndTime(stepPointTimes[i]);
313 pVVisManager->
Draw(point);
328 std::vector<G4double> trajectoryLineTimes;
329 std::vector<G4double> stepPointTimes;
330 std::vector<G4double> auxiliaryPointTimes;
334 trajectoryLine, auxiliaryPoints, stepPoints,
335 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
340 trajectoryLine, trajectoryLineTimes);
342 DrawWithTime(context,
343 trajectoryLine, auxiliaryPoints, stepPoints,
344 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
348 DrawWithoutTime(context, trajectoryLine, auxiliaryPoints, stepPoints);
CLHEP::Hep3Vector G4ThreeVector
void SetMarkerType(MarkerType)
static G4double ConvertToDimensionedDouble(const char *st)
void SetSize(SizeType, G4double)
void SetFillStyle(FillStyle)
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual const std::vector< G4ThreeVector > * GetAuxiliaryPoints() const
virtual const G4ThreeVector GetPosition() const =0
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
virtual G4int GetPointEntries() const =0
static G4VVisManager * GetConcreteInstance()
virtual void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
G4bool GetDrawAuxPts() const
G4Colour GetStepPtsColour() const
G4double GetLineWidth() const
G4double GetStepPtsSize() const
G4bool GetLineVisible() const
G4double GetTimeSliceInterval() const
G4bool GetDrawLine() const
G4VMarker::SizeType GetStepPtsSizeType() const
G4Polymarker::MarkerType GetAuxPtsType() const
G4double GetAuxPtsSize() const
G4VMarker::SizeType GetAuxPtsSizeType() const
G4Colour GetAuxPtsColour() const
G4VMarker::FillStyle GetStepPtsFillStyle() const
G4VMarker::FillStyle GetAuxPtsFillStyle() const
G4bool GetAuxPtsVisible() const
G4bool GetStepPtsVisible() const
G4Colour GetLineColour() const
G4Polymarker::MarkerType GetStepPtsType() const
G4bool GetDrawStepPts() const
void SetVisAttributes(const G4VisAttributes *)
TimesValidity GetPointsAndTimes(const G4VTrajectory &traj, const G4VisTrajContext &context, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints, std::vector< G4double > &trajectoryLineTimes, std::vector< G4double > &auxiliaryPointTimes, std::vector< G4double > &stepPointTimes)
void DrawLineAndPoints(const G4VTrajectory &traj, const G4VisTrajContext &)