ATLAS Offline Software
VP1CartesianGrid.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1CartesianGrid //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: July 2008 //
12 // //
14 
16 #include "VP1GuideLineSystems/VP1Floor.h"//for calcPars... static method
17 
18 #include <Inventor/nodes/SoSeparator.h>
19 #include <Inventor/nodes/SoVertexProperty.h>
20 #include <Inventor/nodes/SoLineSet.h>
21 #include <Inventor/SbColor4f.h>
22 
23 #ifdef BUILDVP1LIGHT
24  #include "CLHEP/Units/SystemOfUnits.h"
25  #define SYSTEM_OF_UNITS CLHEP
26 #else
27  #include "GaudiKernel/SystemOfUnits.h"
28  #define SYSTEM_OF_UNITS Gaudi::Units
29 #endif
30 
31 //____________________________________________________________________
33 public:
35  SoSeparator * attachsep);
37  SoSeparator * attachSep;
38 
39  bool shown;
40  SbColor4f colourAndTransp;
41  double extent;
42  double spacing;
43 
44  SoSeparator * sep;
45 
46  void rebuild3DObjects();
47  void updateColour();
48 };
49 
50 //____________________________________________________________________
51 VP1CartesianGrid::VP1CartesianGrid(SoSeparator * attachsep,
52  IVP1System * sys,QObject * parent)
53  : QObject(parent), VP1HelperClassBase(sys,"VP1CartesianGrid"), m_d(new Imp(this,attachsep))
54 {
55 }
56 
57 //____________________________________________________________________
59 {
60  setShown(false);
61  if (m_d->sep)
62  m_d->sep->unref();
63  m_d->attachSep->unref();
64  delete m_d;
65 }
66 
67 //____________________________________________________________________
69  : theclass(tc), attachSep(as), shown(false),
70  colourAndTransp(SbColor4f(1,1,1,1)),extent(10), spacing(1), sep(0)
71 {
72  attachSep->ref();
73 }
74 
75 //____________________________________________________________________
77 {
78  theclass->messageVerbose("(Re)building 3D objects");
79 
80  if (sep) {
81  sep->removeAllChildren();
82  } else {
83  sep = new SoSeparator;
84  sep->ref();
85  }
86 
87  const bool save = sep->enableNotify(false);
88 
89  int nmax; double distmax;
90  if (!VP1Floor::calcParsFromExtentAndSpacing( theclass, extent, spacing, 40/*max lines*/, nmax, distmax )) {
91  nmax = 10;
92  distmax = 10*SYSTEM_OF_UNITS::m;
93  theclass->message("ERROR: Problems calculating nmax/distmax.");
94  }
95 
96  SoVertexProperty * grid_cartesian_vertices = new SoVertexProperty();
97 
98  int ivert(0);
99  int nsublines(0);
100 
101  //First, loop over (x,z) values and add one line parallel with the y-axis through each.
102  for (int ix = -nmax; ix<=nmax; ++ix)
103  for (int iz = -nmax; iz<=nmax; ++iz) {
104  double x = ix*spacing;
105  double z = iz*spacing;
106  grid_cartesian_vertices->vertex.set1Value(ivert++,x,-distmax,z);
107  grid_cartesian_vertices->vertex.set1Value(ivert++,x,+distmax,z);
108  ++nsublines;
109  }
110 
111  //Next, loop over y values and add a plane of lines parallel to the x-z plane.
112  for (int iy = -nmax; iy<=nmax; ++iy) {
113  double y = iy*spacing;
114  for (int ix = -nmax; ix<=nmax; ++ix) {
115  double x = ix*spacing;
116  grid_cartesian_vertices->vertex.set1Value(ivert++,x,y,-distmax);
117  grid_cartesian_vertices->vertex.set1Value(ivert++,x,y,+distmax);
118  ++nsublines;
119  }
120  for (int iz = -nmax; iz<=nmax; ++iz) {
121  double z = iz*spacing;
122  grid_cartesian_vertices->vertex.set1Value(ivert++,-distmax,y,z);
123  grid_cartesian_vertices->vertex.set1Value(ivert++,+distmax,y,z);
124  ++nsublines;
125  }
126  }
127 
128  grid_cartesian_vertices->materialBinding=SoMaterialBinding::OVERALL;
129  grid_cartesian_vertices->normalBinding=SoNormalBinding::OVERALL;
130  SoLineSet * line = new SoLineSet();
131  line->numVertices.enableNotify(FALSE);
132  line->numVertices.setNum(nsublines);
133  for (int i=0;i<nsublines;++i)
134  line->numVertices.set1Value(i,2);
135  line->vertexProperty = grid_cartesian_vertices;
136  line->numVertices.enableNotify(TRUE);
137  line->numVertices.touch();
138 
139  sep->addChild(line);
140  updateColour();
141 
142  if (save) {
143  sep->enableNotify(true);
144  sep->touch();
145  }
146 
147 }
148 
149 //____________________________________________________________________
151 {
152  theclass->messageVerbose("Updating packed colour");
153  if (!sep||sep->getNumChildren()<1)
154  return;
155  SoNode * n = sep->getChild(0);
156  if (!n||n->getTypeId()!=SoLineSet::getClassTypeId())
157  return;
158  SoLineSet * line = static_cast<SoLineSet*>(n);
159  SoVertexProperty * vertices = static_cast<SoVertexProperty *>(line->vertexProperty.getValue());
160  if (!vertices)
161  return;
162  vertices->orderedRGBA = colourAndTransp.getPackedValue();
163 }
164 
165 //____________________________________________________________________
167 {
168  messageVerbose("Signal received: setShown("+str(b)+")");
169  if (m_d->shown==b)
170  return;
171  m_d->shown=b;
172  if (m_d->shown) {
174  if (m_d->attachSep->findChild(m_d->sep)<0)
175  m_d->attachSep->addChild(m_d->sep);
176  } else {
177  if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
178  m_d->attachSep->removeChild(m_d->sep);
179  }
180 }
181 
182 //____________________________________________________________________
184 {
185  messageVerbose("Signal received in setColourAndTransp slot.");
186  if (m_d->colourAndTransp==ct)
187  return;
189  if (m_d->shown)
190  m_d->updateColour();
191 }
192 
193 //____________________________________________________________________
194 void VP1CartesianGrid::setExtent(const double& e)
195 {
196  messageVerbose("Signal received: setExtent("+str(e)+")");
197  if (m_d->extent==e)
198  return;
199  m_d->extent=e;
200  if (m_d->shown)
202 }
203 
204 //____________________________________________________________________
205 void VP1CartesianGrid::setSpacing(const double&s)
206 {
207  messageVerbose("Signal received: setSpacing("+str(s)+")");
208  if (m_d->spacing==s)
209  return;
210  m_d->spacing=s;
211  if (m_d->shown)
213 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
VP1CartesianGrid::~VP1CartesianGrid
virtual ~VP1CartesianGrid()
Definition: VP1CartesianGrid.cxx:58
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1CartesianGrid::Imp::shown
bool shown
Definition: VP1CartesianGrid.cxx:39
VP1CartesianGrid::Imp::attachSep
SoSeparator * attachSep
Definition: VP1CartesianGrid.cxx:37
VP1CartesianGrid::setShown
void setShown(bool)
Definition: VP1CartesianGrid.cxx:166
VP1CartesianGrid::Imp::extent
double extent
Definition: VP1CartesianGrid.cxx:41
x
#define x
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
VP1CartesianGrid::setSpacing
void setSpacing(const double &)
Definition: VP1CartesianGrid.cxx:205
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
IVP1System
Definition: IVP1System.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
beamspotman.n
n
Definition: beamspotman.py:731
VP1Floor.h
VP1CartesianGrid::setColourAndTransp
void setColourAndTransp(const SbColor4f &)
Definition: VP1CartesianGrid.cxx:183
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.Constants.TRUE
bool TRUE
for job options legacy (TODO: get rid of these!) ----------------------—
Definition: Control/AthenaCommon/python/Constants.py:22
VP1Floor::calcParsFromExtentAndSpacing
static bool calcParsFromExtentAndSpacing(VP1HelperClassBase *, const double &extent, const double &spacing, const int &nmaxlimit, int &nmax, double &distmax)
Definition: VP1Floor.cxx:30
SCT_ConditionsData::OVERALL
@ OVERALL
Definition: SCT_ConditionsParameters.h:24
VP1CartesianGrid::Imp::updateColour
void updateColour()
Definition: VP1CartesianGrid.cxx:150
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
calibdata.ct
ct
Definition: calibdata.py:418
VP1CartesianGrid::Imp::theclass
VP1CartesianGrid * theclass
Definition: VP1CartesianGrid.cxx:36
grepfile.sep
sep
Definition: grepfile.py:38
VP1CartesianGrid
Definition: VP1CartesianGrid.h:26
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
python.Constants.FALSE
bool FALSE
Definition: Control/AthenaCommon/python/Constants.py:23
y
#define y
VP1CartesianGrid::setExtent
void setExtent(const double &)
Definition: VP1CartesianGrid.cxx:194
VP1CartesianGrid::VP1CartesianGrid
VP1CartesianGrid(SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
Definition: VP1CartesianGrid.cxx:51
VP1CartesianGrid::Imp::spacing
double spacing
Definition: VP1CartesianGrid.cxx:42
VP1CartesianGrid::Imp::sep
SoSeparator * sep
Definition: VP1CartesianGrid.cxx:44
VP1CartesianGrid::Imp
Definition: VP1CartesianGrid.cxx:32
VP1CartesianGrid::Imp::rebuild3DObjects
void rebuild3DObjects()
Definition: VP1CartesianGrid.cxx:76
VP1CartesianGrid.h
VP1CartesianGrid::Imp::colourAndTransp
SbColor4f colourAndTransp
Definition: VP1CartesianGrid.cxx:40
nmax
const int nmax(200)
VP1CartesianGrid::m_d
Imp * m_d
Definition: VP1CartesianGrid.h:44
VP1CartesianGrid::Imp::Imp
Imp(VP1CartesianGrid *, SoSeparator *attachsep)
Definition: VP1CartesianGrid.cxx:68