42 namespace G4TrajectoryDrawerUtils {
52 std::vector<G4double>& trajectoryLineTimes,
53 std::vector<G4double>& auxiliaryPointTimes,
54 std::vector<G4double>& stepPointTimes)
66 std::vector<G4ThreeVector> positions;
75 if (positions.size() == 0 ||
76 trajectoryPointPosition != positions[positions.size()-1]) {
84 std::vector<G4AttValue>* trajectoryPointAttValues =
86 if (!trajectoryPointAttValues) {
87 static G4bool warnedNoAttValues =
false;
88 if (!warnedNoAttValues) {
90 "*************************************************************************"
91 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: no att values."
92 "\n*************************************************************************"
94 warnedNoAttValues =
true;
98 G4bool foundPreTime =
false, foundPostTime =
false;
99 for (std::vector<G4AttValue>::iterator i =
100 trajectoryPointAttValues->begin();
101 i != trajectoryPointAttValues->end(); ++i) {
102 if (i->GetName() ==
"PreT") {
103 trajectoryPointPreTime =
107 if (i->GetName() ==
"PostT") {
108 trajectoryPointPostTime =
110 foundPostTime =
true;
113 if (!foundPreTime || !foundPostTime) {
114 static G4bool warnedTimesNotFound =
false;
115 if (!warnedTimesNotFound) {
117 "*************************************************************************"
118 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: times not found."
119 "\n You need to specify \"/vis/scene/add/trajectories rich\""
120 "\n*************************************************************************"
122 warnedTimesNotFound =
true;
127 delete trajectoryPointAttValues;
130 const std::vector<G4ThreeVector>* auxiliaries
132 if (0 != auxiliaries) {
133 for (
size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
134 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux];
135 if (positions.size() == 0 ||
136 auxPointPosition != positions[positions.size()-1]) {
138 positions.push_back(trajectoryPointPosition);
139 trajectoryLine.push_back(auxPointPosition);
140 auxiliaryPoints.push_back(auxPointPosition);
144 (auxPointPosition - lastTrajectoryPointPosition).mag();
146 (trajectoryPointPosition - auxPointPosition).mag();
147 G4double t = trajectoryPointPreTime +
148 (trajectoryPointPostTime - trajectoryPointPreTime) *
150 trajectoryLineTimes.push_back(t);
151 auxiliaryPointTimes.push_back(t);
157 positions.push_back(trajectoryPointPosition);
158 trajectoryLine.push_back(trajectoryPointPosition);
159 stepPoints.push_back(trajectoryPointPosition);
161 trajectoryLineTimes.push_back(trajectoryPointPostTime);
162 stepPointTimes.push_back(trajectoryPointPostTime);
164 lastTrajectoryPointPosition = trajectoryPointPosition;
172 std::vector<G4double>& trajectoryLineTimes)
177 std::vector<G4double> newTrajectoryLineTimes;
179 newTrajectoryLine.push_back(trajectoryLine[0]);
180 newTrajectoryLineTimes.push_back(trajectoryLineTimes[0]);
181 size_t lineSize = trajectoryLine.size();
183 for (
size_t i = 1; i < trajectoryLine.size(); ++i) {
184 G4double deltaT = trajectoryLineTimes[i] - trajectoryLineTimes[i - 1];
187 std::max(timeIncrement, deltaT / 100.);
189 (
int(trajectoryLineTimes[i - 1]/practicalTimeIncrement) + 1) *
190 practicalTimeIncrement;
191 t <= trajectoryLineTimes[i];
192 t += practicalTimeIncrement) {
194 (trajectoryLine[i] - trajectoryLine[i - 1]) *
195 ((t - trajectoryLineTimes[i - 1]) / deltaT);
196 newTrajectoryLine.push_back(pos);
197 newTrajectoryLineTimes.push_back(t);
200 newTrajectoryLine.push_back(trajectoryLine[i]);
201 newTrajectoryLineTimes.push_back(trajectoryLineTimes[i]);
205 trajectoryLine = newTrajectoryLine;
206 trajectoryLineTimes = newTrajectoryLineTimes;
217 if (0 == pVVisManager)
return;
224 pVVisManager->
Draw(trajectoryLine);
227 if (myContext.
GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) {
236 pVVisManager->
Draw(auxiliaryPoints);
248 pVVisManager->
Draw(stepPoints);
256 std::vector<G4double>& trajectoryLineTimes,
257 std::vector<G4double>& auxiliaryPointTimes,
258 std::vector<G4double>& stepPointTimes)
263 if (0 == pVVisManager)
return;
269 for (
size_t i = 1; i < trajectoryLine.size(); ++i ) {
271 slice.push_back(trajectoryLine[i -1]);
272 slice.push_back(trajectoryLine[i]);
273 trajectoryLineAttribs.SetStartTime(trajectoryLineTimes[i - 1]);
274 trajectoryLineAttribs.SetEndTime(trajectoryLineTimes[i]);
276 pVVisManager->
Draw(slice);
280 if (myContext.
GetDrawAuxPts() && (auxiliaryPoints.size() > 0)) {
284 for (
size_t i = 0; i < auxiliaryPoints.size(); ++i ) {
286 point.push_back(auxiliaryPoints[i]);
290 auxiliaryPointsAttribs.SetStartTime(auxiliaryPointTimes[i]);
291 auxiliaryPointsAttribs.SetEndTime(auxiliaryPointTimes[i]);
293 pVVisManager->
Draw(point);
301 for (
size_t i = 0; i < stepPoints.size(); ++i ) {
303 point.push_back(stepPoints[i]);
307 stepPointsAttribs.SetStartTime(stepPointTimes[i]);
308 stepPointsAttribs.SetEndTime(stepPointTimes[i]);
310 pVVisManager->
Draw(point);
325 std::vector<G4double> trajectoryLineTimes;
326 std::vector<G4double> stepPointTimes;
327 std::vector<G4double> auxiliaryPointTimes;
331 trajectoryLine, auxiliaryPoints, stepPoints,
332 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
337 trajectoryLine, trajectoryLineTimes);
340 trajectoryLine, auxiliaryPoints, stepPoints,
341 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
G4bool GetStepPtsVisible() const
void DrawLineAndPoints(const G4VTrajectory &traj, const G4VisTrajContext &)
static void DrawWithTime(const G4VisTrajContext &myContext, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints, std::vector< G4double > &trajectoryLineTimes, std::vector< G4double > &auxiliaryPointTimes, std::vector< G4double > &stepPointTimes)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
virtual const G4ThreeVector GetPosition() const =0
virtual void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
static const G4double pos
G4bool GetDrawLine() const
G4VMarker::SizeType GetAuxPtsSizeType() const
G4bool GetLineVisible() const
G4double GetAuxPtsSize() const
G4double GetStepPtsSize() const
G4Polymarker::MarkerType GetStepPtsType() const
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)
G4Polymarker::MarkerType GetAuxPtsType() const
static G4VVisManager * GetConcreteInstance()
virtual std::vector< G4AttValue > * CreateAttValues() const
G4double GetTimeSliceInterval() const
G4VMarker::FillStyle GetStepPtsFillStyle() const
virtual int GetPointEntries() const =0
G4VMarker::SizeType GetStepPtsSizeType() const
static void DrawWithoutTime(const G4VisTrajContext &myContext, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints)
void SetSize(SizeType, G4double)
G4bool GetDrawAuxPts() const
G4bool GetAuxPtsVisible() const
G4Colour GetAuxPtsColour() const
static void SliceLine(G4double timeIncrement, G4Polyline &trajectoryLine, std::vector< G4double > &trajectoryLineTimes)
void SetVisibility(G4bool=true)
G4Colour GetStepPtsColour() const
G4VMarker::FillStyle GetAuxPtsFillStyle() const
virtual const std::vector< G4ThreeVector > * GetAuxiliaryPoints() const
G4Colour GetLineColour() const
G4GLOB_DLL std::ostream G4cout
void SetMarkerType(MarkerType)
G4bool GetDrawStepPts() const
static G4double ConvertToDimensionedDouble(const char *st)
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
void SetVisAttributes(const G4VisAttributes *)
void SetFillStyle(FillStyle)