ATLAS Offline Software
Loading...
Searching...
No Matches
TrackingSurfacesSystem.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-20235 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class TrackingSurfacesSystem //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: June 2007 //
12// //
14
16#include "ui_trackingsurfacescontrollerform.h"
17
19#include "TrkSurfaces/Surface.h"
22#include "GaudiKernel/SystemOfUnits.h"
23
24#include <Inventor/nodes/SoSeparator.h>
25#include <Inventor/nodes/SoLineSet.h>
26#include <Inventor/nodes/SoVertexProperty.h>
27#include <Inventor/nodes/SoSwitch.h>
28#include <Inventor/nodes/SoMaterial.h>
29
33
34//_____________________________________________________________________________________
36 : IVP13DSystemSimple("TrackingSurfacesSystem","This is an illustration of a very basic 3D system.","edward.moyse@gmail.com"), m_multiselection(0)
37{
38}
39
40//_____________________________________________________________________________________
42{
43 //Clear maps:
44 m_nodeToSurface.clear();
45 // std::cout<<&m_surfConvertor<<std::endl;
46 //1) Try to get the collection of (InDet) tracks from storegate:
47
48 //Sanity check:
49 if (!sg) {
50 message("Error: Got null storegate pointer");
51 return;
52 }
53
54
55 // SurfaceCollection* testsrfcol;
56 // StatusCode sc2 = evtStore()->retrieve(testsrfcol,"SurfaceCollection");
57 // if ( sc2.isFailure() )
58 // ATH_MSG_ERROR("Could not retrieve SurfaceCollection in StoreGate");
59 // else
60 // ATH_MSG_INFO("SurfaceCollection with " << testsrfcol->size() << " elements successfully retrieved in StoreGate");
61 //
62
63 const SurfaceCollection *surfColl;
64 std::string surfname="SurfaceCollection";
65 StatusCode status = sg->retrieve(surfColl, surfname);
66 if (status != StatusCode::SUCCESS || !surfColl) {
67 message("Error: Could not retrieve SurfaceCollection (used key="+QString(surfname.c_str())+")");
68 return;
69 }
70 message( "Loaded SurfaceCollection with key [" +QString(surfname.c_str())+"] and which contains [" + QString::number(surfColl->size()) + "] surfaces.");
71 //2) Add SoCooperativeSelection node under which we will put all the
72 //tracks. Register it and put its policy to TOGGLE (i.e. clicking
73 //adds or removes tracks from selection). In updateSelectionMode we
74 //will update its ACTIVE/INERT status depending on whether multiple
75 //selections are enabled: If ACTIVE, we get lists of selected nodes
76 //in the userChangedSelection(...) method, otherwise we get single
77 //nodes in the userPickedNode(...) method as always. We could also
78 //simply have changed its policy and gotten information about the
79 //clicks in a userSelectedSingleNode(...) method instead (the
80 //reason for the two available ways of doing this is that you might
81 //want to have several different selection nodes in your graph in
82 //the case where you have different types of physics objects
83 //displayed from the same system):
85 m_multiselection->policy = SoCooperativeSelection::TOGGLE;
86 registerSelectionNode(m_multiselection);//Always do this for SoCooperativeSelection nodes in your graph.
87 updateSelectionMode( true );//Since our controller starts with the single mode selected, we init like that also.
88
89 //2) Loop over the tracks and construct a relevant 3D object for each of them (a SoLineSet):
90
91 SurfaceCollection::const_iterator surfItr, surfItrEnd = surfColl->end();
92 SurfaceToSoNode surfCnv;
93 for ( surfItr = surfColl->begin() ; surfItr != surfItrEnd; ++surfItr) {
94 const Trk::Surface* surf = (*surfItr);
95
96 SoNode* node = surfCnv.translateSurface(*surf, false);
97 SoMaterial *material = new SoMaterial;
98 if(surf->isActive()){
99 material->diffuseColor.setValue(0.6, 0., 0.6);
100 } else {
101 material->diffuseColor.setValue(1., 0., 1.);
102 }
103
104 m_multiselection->addChild(material);
105 m_multiselection->addChild(node);
106
107 //Bookkeep which track this 3D object corresponds to (we will need this to display surface info when the user clicks):
108 m_nodeToSurface[node] = surf;
109
110 //To avoid GUI freeze-ups:
111 updateGUI();
112 }
113
114 //Add the selection node under the root:
115 root->addChild(m_multiselection);
116
117
118}
119
120//_____________________________________________________________________________________
121void TrackingSurfacesSystem::userPickedNode(SoNode* pickedNode, SoPath * /*pickedPath*/) {
122
123 //User clicked on "pickedNode". We should know which track this belongs to:
124
125 messageDebug("TrackingSurfacesSystem::userPickedNode - have been passed node ["+QString("0x%1").arg((quintptr)pickedNode,
126 QT_POINTER_SIZE * 2, 16, QChar('0'))+"] and have ["+QString::number(m_nodeToSurface.size())+"] nodes.");
127
128 if (m_nodeToSurface.find(pickedNode)==m_nodeToSurface.end()) {
129 message("Error: Do not have surface information for picked node");
130 return;
131 }
132 const Trk::Surface * matchedSurface=m_nodeToSurface.find(pickedNode)->second;
133
134 //Show some interesting information (from the first surface):
135 message("===> Surface info:");
136 QStringList l;
137 std::ostringstream s;
138 s << *(matchedSurface);
139 l << QString(s.str().c_str()).split('\n');
140 message(l);
141
142 //Zoom to surf:
143 CamList cameras = getCameraList();
144 for (CamListItr itCam = cameras.begin(); itCam!=cameras.end(); ++itCam) {
146 }
147}
148
149//_____________________________________________________________________________________
150void TrackingSurfacesSystem::userChangedSelection(SoCooperativeSelection*, const QSet<SoNode*> & nodes, QSet<SoPath*>)
151{
152 for (SoNode * node : nodes) {
153 //Surface pointer:
154 if (m_nodeToSurface.find(node)==m_nodeToSurface.end()) {
155 message("Error: Does not have surface information for all nodes");
156 return;
157 }
158 }
159}
160
161//_____________________________________________________________________________________
163{
164 QWidget * controller = new QWidget(0);
165 Ui::TrackingSurfacesControllerForm ui;
166 ui.setupUi(controller);
167
168 connect(ui.radioButton_select_single,SIGNAL(toggled(bool)),this,SLOT(updateSelectionMode(bool)));
169
170 return controller;
171}
172
173//_____________________________________________________________________________________
175{
176 //If multiselection not created or if we dont need to change anything - abort:
177 if ( !m_multiselection || single == (m_multiselection->activePolicy.getValue()==SoCooperativeSelection::INERT) )
178 return;
179
180 //When we change selection mode we deselect everything - always a good idea to avoid hard to debug problems later:
181 deselectAll();
182
183 if (single)
185 else
187
188}
DataVector< const Trk::Surface > SurfaceCollection
DataVector of const Surface / 24.08.2004 % clid.py SurfaceCollection 1185938832 SurfaceCollection.
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.
size_type size() const noexcept
Returns the number of elements in the collection.
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
std::set< SoCamera * > CamList
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
void registerSelectionNode(SoCooperativeSelection *)
CamList getCameraList()
CamList::iterator CamListItr
void messageDebug(const QString &) const
void message(const QString &) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
SoNode * translateSurface(const Trk::Surface &sf, const bool &simple=false) const
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
void userChangedSelection(SoCooperativeSelection *, const QSet< SoNode * > &, QSet< SoPath * >)
std::map< SoNode *, const Trk::Surface * > m_nodeToSurface
SoCooperativeSelection * m_multiselection
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Abstract Base Class for tracking surfaces.
bool isActive() const
Return 'true' if this surface is owned by the detector element.
static VP1CameraHelper * animatedZoomToSubTree(SoCamera *camera, SoGroup *sceneroot, SoNode *subtreeroot, double duration_in_secs=1.0, double clipVolPercent=100.0, double lastClipVolPercent=100.0, double slack=1.0, const SbVec3f &lookat=SbVec3f(999, 999, 999), const SbVec3f &upvec=SbVec3f(999, 999, 999), bool varySpeed=true, bool forceCircular=false)
Definition node.h:24