ATLAS Offline Software
VP1Letters.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1Letters //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: April 2008 //
12 // //
14 
16 #include "VP1HEPVis/SbPolyhedron.h"
18 #include <Inventor/nodes/SoMaterial.h>
19 #include <Inventor/nodes/SoCube.h>
20 #include <Inventor/nodes/SoSeparator.h>
21 #include <Inventor/nodes/SoTranslation.h>
22 #include <Inventor/nodes/SoRotationXYZ.h>
23 #include <algorithm>
24 #include <vector>
25 
26 #ifdef BUILDVP1LIGHT
27  #include "CLHEP/Units/SystemOfUnits.h"
28  #define SYSTEM_OF_UNITS CLHEP
29 #else
30  #include "GaudiKernel/SystemOfUnits.h"
31  #define SYSTEM_OF_UNITS Gaudi::Units
32 #endif
33 
34 //____________________________________________________________________
36 public:
37  Imp(VP1Letters *,
38  SoMaterial * mat,
39  SoSeparator * attachsep);
41  SoMaterial * material;
42  SoSeparator * attachSep;
43 
44  void createLetterAData(std::vector<double>& x, std::vector<double>&y);
45  void createLetterCData(std::vector<double>& x, std::vector<double>&y);
46  void normalizeLetterData(std::vector<double>& x, std::vector<double>&y,double yheight);
47  SoNode * createLetter(const std::vector<double>& x, const std::vector<double> & y);
48 
49  bool shown;
50  double zpos;
51  double vertpos;
52 
53  SoSeparator * sep;
54  SoTranslation * transA;
55  SoTranslation * transC;
56 
57  void updateFields();
58  void ensureInit3DObjects();
59 };
60 
61 //____________________________________________________________________
62 VP1Letters::VP1Letters(SoMaterial * mat,SoSeparator * attachsep,
63  IVP1System * sys,QObject * parent)
64  : QObject(parent), VP1HelperClassBase(sys,"VP1Letters"), m_d(new Imp(this,mat,attachsep))
65 {
66 }
67 
68 //____________________________________________________________________
70 {
71  setShown(false);
72  if (m_d->sep)
73  m_d->sep->unref();
74  if (m_d->transA)
75  m_d->transA->unref();
76  if (m_d->transC)
77  m_d->transC->unref();
78  m_d->material->unref();
79  m_d->attachSep->unref();
80  delete m_d;
81 }
82 
83 //____________________________________________________________________
84 VP1Letters::Imp::Imp(VP1Letters *tc,SoMaterial * mat,SoSeparator * as)
85  : theclass(tc), material(mat), attachSep(as), shown(false),
86  zpos(0),vertpos(0), sep(0), transA(0), transC(0)
87 {
88  material->ref();
89  attachSep->ref();
90 }
91 
92 
93 //_____________________________________________________________________________________
94 void VP1Letters::Imp::createLetterAData(std::vector<double>& x, std::vector<double>&y) {
95 
96  x.clear();
97  y.clear();
98  x.push_back(294.15418); y.push_back(175.81259);
99  x.push_back(230.15085); y.push_back(349.36906);
100  x.push_back(358.39109); y.push_back(349.36906);
101  x.push_back(294.15418); y.push_back(175.81259);
102  x.push_back(267.52506); y.push_back(129.32842);
103  x.push_back(321.01689); y.push_back(129.32842);
104  x.push_back(453.92891); y.push_back(478.07648);
105  x.push_back(404.87526); y.push_back(478.07648);
106  x.push_back(373.10719); y.push_back(388.61197);
107  x.push_back(215.90194); y.push_back(388.61197);
108  x.push_back(184.13386); y.push_back(478.07648);
109  x.push_back(134.37945); y.push_back(478.07648);
110  x.push_back(267.52506); y.push_back(129.32842);
111 }
112 
113 //_____________________________________________________________________________________
114 void VP1Letters::Imp::createLetterCData(std::vector<double>& x, std::vector<double>&y) {
115 
116  x.clear();
117  y.clear();
118  x.push_back(666.70068); y.push_back(278.58533);
119  x.push_back(668.72098); y.push_back(165.44825);
120  x.push_back(591.94939); y.push_back(127.06245);
121  x.push_back(496.99505); y.push_back(98.77818);
122  x.push_back(400.02041); y.push_back(94.73757);
123  x.push_back(299.00515); y.push_back(108.87971);
124  x.push_back(224.25386); y.push_back(145.2452);
125  x.push_back(149.50258); y.push_back(201.81374);
126  x.push_back(92.934034); y.push_back(280.60564);
127  x.push_back(56.568543); y.push_back(379.60059);
128  x.push_back(46.467017); y.push_back(486.67676);
129  x.push_back(52.527932); y.push_back(591.73262);
130  x.push_back(76.771593); y.push_back(682.64635);
131  x.push_back(109.09647); y.push_back(741.2352);
132  x.push_back(145.46197); y.push_back(783.66161);
133  x.push_back(189.90868); y.push_back(830.12862);
134  x.push_back(248.49753); y.push_back(864.47381);
135  x.push_back(327.28942); y.push_back(886.69717);
136  x.push_back(406.08132); y.push_back(898.819);
137  x.push_back(454.56865); y.push_back(898.819);
138  x.push_back(523.25902); y.push_back(886.69717);
139  x.push_back(600.03061); y.push_back(858.41289);
140  x.push_back(646.49763); y.push_back(838.20984);
141  x.push_back(668.72098); y.push_back(818.00679);
142  x.push_back(666.70068); y.push_back(710.93062);
143  x.push_back(616.19305); y.push_back(751.33672);
144  x.push_back(555.5839); y.push_back(785.68191);
145  x.push_back(484.87322); y.push_back(807.90527);
146  x.push_back(430.32498); y.push_back(809.92557);
147  x.push_back(379.81736); y.push_back(807.90527);
148  x.push_back(317.1879); y.push_back(791.74283);
149  x.push_back(280.82241); y.push_back(775.58039);
150  x.push_back(248.49753); y.push_back(749.31642);
151  x.push_back(214.15234); y.push_back(710.93062);
152  x.push_back(175.76654); y.push_back(652.34177);
153  x.push_back(159.6041); y.push_back(565.46866);
154  x.push_back(155.56349); y.push_back(480.61584);
155  x.push_back(161.62441); y.push_back(401.82394);
156  x.push_back(189.90868); y.push_back(314.95082);
157  x.push_back(242.43661); y.push_back(242.21984);
158  x.push_back(301.02546); y.push_back(203.83404);
159  x.push_back(361.63461); y.push_back(181.61069);
160  x.push_back(426.28437); y.push_back(177.57008);
161  x.push_back(511.13719); y.push_back(187.6716);
162  x.push_back(587.90878); y.push_back(217.97618);
163  x.push_back(644.47732); y.push_back(258.38228);
164  //Correct orientation for SbPolyhedronPolygonXSect:
165  std::reverse(x.begin(), x.end());
166  std::reverse(y.begin(), y.end());
167 }
168 
169 //_____________________________________________________________________________________
170 void VP1Letters::Imp::normalizeLetterData(std::vector<double>& x, std::vector<double>&y,double yheight)
171 {
172  //Translates and rescales so letter goes from -0.5*yheight to +0.5*yheight in y, and is centered around 0 in x.
173  if (x.size()!=y.size()) {
174  theclass->message("normalizeLetterData Error: Input vectors have different length!");
175  return;
176  }
177 
178  unsigned n = x.size();
179 
180  double xmin(1e20),xmax(-1e20),ymin(1e20),ymax(-1e20);
181  for (unsigned i = 0; i<n;++i) {
182  if (x.at(i)<xmin) xmin = x.at(i);
183  if (x.at(i)>xmax) xmax = x.at(i);
184  if (y.at(i)<ymin) ymin = y.at(i);
185  if (y.at(i)>ymax) ymax = y.at(i);
186  }
187 
188  assert(ymax>ymin&&xmax>xmin);
189 
190  double scale=yheight/(ymax-ymin);
191  double xoffset=-xmin-0.5*(xmax-xmin);
192  for (unsigned i = 0; i<n;++i) {
193  x.at(i) = (x.at(i)+xoffset)*scale;
194  y.at(i) = (y.at(i)-ymin)*scale-0.5*yheight;
195  }
196 
197 }
198 
199 //_____________________________________________________________________________________
200 SoNode * VP1Letters::Imp::createLetter(const std::vector<double>& x, const std::vector<double> &y) {
201  if (x.size()!=y.size()) {
202  theclass->message("createLetter Error: Input vectors have different length!");
203  return new SoCube;
204  }
205 
207  // SbPolyhedron * sbpoly = static_cast<SbPolyhedron*>(new SbPolyhedronPolygonXSect(x,y,0.3*m));
208  // SoPolyhedron * poly = new SoPolyhedron(sbpoly);
210  return poly;
211 }
212 
213 //____________________________________________________________________
215 {
216  if (sep)
217  return;
218  theclass->messageVerbose("Building 3D objects");
219  sep = new SoSeparator; sep->ref();
220  sep->addChild(material);
221 
222  //Create letters:
223  std::vector<double> x,y;
224  createLetterAData(x,y);
225  normalizeLetterData(x,y,2*SYSTEM_OF_UNITS::m);
226  SoNode * letterA = createLetter(x,y);
227  createLetterCData(x,y);
228  normalizeLetterData(x,y,2*SYSTEM_OF_UNITS::m);
229  SoNode * letterC = createLetter(x,y);
230 
231  transA = new SoTranslation;
232  transA->ref();
233  transC = new SoTranslation;
234  transC->ref();
235 
236  SoRotationXYZ * xf = new SoRotationXYZ();
237  xf->axis=SoRotationXYZ::Z;
238  xf->angle = 180*SYSTEM_OF_UNITS::deg;
239 
240  sep->addChild(transC);
241  sep->addChild(letterC);
242  sep->addChild(transA);
243  sep->addChild(xf);
244  sep->addChild(letterA);
245 }
246 
247 //____________________________________________________________________
249 {
250  ensureInit3DObjects();
251  theclass->messageVerbose("Updating fields");
252  transA->translation.setValue(0, 0, 2*zpos);
253  transC->translation.setValue(0, vertpos, -zpos);
254 }
255 
256 //____________________________________________________________________
258 {
259  messageVerbose("Signal received: setShown("+str(b)+")");
260  if (m_d->shown==b)
261  return;
262  m_d->shown=b;
263  if (m_d->shown) {
264  m_d->updateFields();
265  if (m_d->attachSep->findChild(m_d->sep)<0)
266  m_d->attachSep->addChild(m_d->sep);
267  } else {
268  if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
269  m_d->attachSep->removeChild(m_d->sep);
270  }
271 }
272 
273 //____________________________________________________________________
274 void VP1Letters::setZPos(const double&p)
275 {
276  messageVerbose("Signal received: setZPos("+str(p)+")");
277  if (m_d->zpos==p)
278  return;
279  m_d->zpos=p;
280  if (m_d->shown)
281  m_d->updateFields();
282 }
283 
284 //____________________________________________________________________
286 {
287  messageVerbose("Signal received: setVerticalPosition("+str(p)+")");
288  if (m_d->vertpos==p)
289  return;
290  m_d->vertpos=p;
291  if (m_d->shown)
292  m_d->updateFields();
293 }
VP1Letters::Imp::sep
SoSeparator * sep
Definition: VP1Letters.cxx:53
VP1Letters::Imp::material
SoMaterial * material
Definition: VP1Letters.cxx:41
ymin
double ymin
Definition: listroot.cxx:63
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
VP1Letters::setZPos
void setZPos(const double &)
Definition: VP1Letters.cxx:274
VP1Letters::setShown
void setShown(bool)
Definition: VP1Letters.cxx:257
Monitored::Z
@ Z
Definition: HistogramFillerUtils.h:24
VP1Letters::Imp::ensureInit3DObjects
void ensureInit3DObjects()
Definition: VP1Letters.cxx:214
VP1Letters::Imp::transA
SoTranslation * transA
Definition: VP1Letters.cxx:54
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:53
VP1Letters::Imp::transC
SoTranslation * transC
Definition: VP1Letters.cxx:55
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
deg
#define deg
Definition: SbPolyhedron.cxx:17
VP1Letters::Imp::createLetter
SoNode * createLetter(const std::vector< double > &x, const std::vector< double > &y)
Definition: VP1Letters.cxx:200
VP1Letters::Imp::Imp
Imp(VP1Letters *, SoMaterial *mat, SoSeparator *attachsep)
Definition: VP1Letters.cxx:84
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
VP1Letters::Imp::theclass
VP1Letters * theclass
Definition: VP1Letters.cxx:40
x
#define x
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
VP1Letters::Imp::attachSep
SoSeparator * attachSep
Definition: VP1Letters.cxx:42
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
DeMoUpdate.reverse
reverse
Definition: DeMoUpdate.py:563
SoPolyhedron.h
VP1Letters.h
IVP1System
Definition: IVP1System.h:36
VP1Letters::m_d
Imp * m_d
Definition: VP1Letters.h:43
lumiFormat.i
int i
Definition: lumiFormat.py:92
xmin
double xmin
Definition: listroot.cxx:60
VP1Letters::Imp::createLetterAData
void createLetterAData(std::vector< double > &x, std::vector< double > &y)
Definition: VP1Letters.cxx:94
beamspotman.n
n
Definition: beamspotman.py:731
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1Letters::~VP1Letters
virtual ~VP1Letters()
Definition: VP1Letters.cxx:69
VP1Letters::Imp::zpos
double zpos
Definition: VP1Letters.cxx:50
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
VP1Letters::Imp::vertpos
double vertpos
Definition: VP1Letters.cxx:51
grepfile.sep
sep
Definition: grepfile.py:38
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1Letters::Imp::updateFields
void updateFields()
Definition: VP1Letters.cxx:248
VP1Letters::Imp::shown
bool shown
Definition: VP1Letters.cxx:49
VP1Letters::setVerticalPosition
void setVerticalPosition(const double &)
Definition: VP1Letters.cxx:285
VP1Letters::Imp
Definition: VP1Letters.cxx:35
y
#define y
VP1Letters::Imp::createLetterCData
void createLetterCData(std::vector< double > &x, std::vector< double > &y)
Definition: VP1Letters.cxx:114
xmax
double xmax
Definition: listroot.cxx:61
VP1Letters::Imp::normalizeLetterData
void normalizeLetterData(std::vector< double > &x, std::vector< double > &y, double yheight)
Definition: VP1Letters.cxx:170
SoPolyhedron::initClass
static void initClass()
Definition: SoPolyhedron.cxx:47
SoPolyhedron
SoPolyhedron is an Inventor encapsulation of the HepPolyedron class written by E.Chernyaev.
Definition: SoPolyhedron.h:47
SbPolyhedron.h
ymax
double ymax
Definition: listroot.cxx:64
VP1Letters
Definition: VP1Letters.h:26
SbPolyhedronPolygonXSect
Definition: SbPolyhedron.h:534
VP1Letters::VP1Letters
VP1Letters(SoMaterial *mat, SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
Definition: VP1Letters.cxx:62