ATLAS Offline Software
Loading...
Searching...
No Matches
Example3DSystem2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class Example3DSystem2 //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: June 2007 //
12// //
14
16
18#include "TrkTrack/Track.h"
21
22#include <Inventor/nodes/SoSeparator.h>
23#include <Inventor/nodes/SoLineSet.h>
24#include <Inventor/nodes/SoVertexProperty.h>
25
26//_____________________________________________________________________________________
28 : IVP13DSystemSimple("Ex3DSys2",
29 "This is an illustration of a very basic 3D system.\n"
30 "It simply transforms track information found in storegate"
31 " into relevant 3D objects (SoLineSet's).",
32 "Thomas.Kittelmann@cern.ch")
33{
34}
35
36//_____________________________________________________________________________________
38{
39 //1) Try to get the collection of (InDet) tracks from storegate:
40
41 //Sanity check:
42 if (!sg) {
43 message("Error: Got null storegate pointer");
44 return;
45 }
46
47 const TrackCollection *trackColl;
48 std::string trackname="Tracks";
49 StatusCode status = sg->retrieve(trackColl, trackname);
50 if (status != StatusCode::SUCCESS || !trackColl) {
51 message("Error: Could not retrieve track collection (used key="+QString(trackname.c_str())+")");
52 return;
53 }
54
55 //2) Loop over the tracks and construct a relevant 3D object for each of them (a SoLineSet):
56
57 TrackCollection::const_iterator trackItr, trackItrEnd = trackColl->end();
58
59 for ( trackItr = trackColl->begin() ; trackItr != trackItrEnd; ++trackItr) {
60 const Trk::Track *track = (*trackItr);
61 const DataVector<const Trk::TrackParameters> *params = track->trackParameters();
62
63 //Just a sanity check:
64 if ( !params )
65 continue;
66
67 //The list of points on this track should be set in a so-called
68 //SoVertexProperty (which one realises by reading the
69 //documentation for SoLineSet at http://doc.coin3d.org/Coin/):
70
71 SoVertexProperty *vertices = new SoVertexProperty();
72
73 int iver(0);
75 for (it = params->begin();it!=itE;++it) {
76 vertices->vertex.set1Value(iver++,(*it)->position().x(),(*it)->position().y(),(*it)->position().z());
77 }
78
79 //Create a set of lines from these vertices:
80 SoLineSet * line = new SoLineSet();
81 line->numVertices = iver;
82 line->vertexProperty = vertices;
83
84 //Add to the tree:
85 root->addChild(line);
86
87 //To avoid GUI freeze-ups:
88 updateGUI();
89
90 }
91
92}
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
void message(const QString &) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.