ATLAS Offline Software
Loading...
Searching...
No Matches
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
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//____________________________________________________________________
36public:
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();
59};
60
61//____________________________________________________________________
62VP1Letters::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//____________________________________________________________________
84VP1Letters::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//_____________________________________________________________________________________
94void 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//_____________________________________________________________________________________
114void 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//_____________________________________________________________________________________
170void 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//_____________________________________________________________________________________
200SoNode * 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);
209 SoPolyhedron * poly = new SoPolyhedron(SbPolyhedronPolygonXSect(x,y,0.3*SYSTEM_OF_UNITS::m));
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;
225 normalizeLetterData(x,y,2*SYSTEM_OF_UNITS::m);
226 SoNode * letterA = createLetter(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{
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//____________________________________________________________________
274void 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}
static Double_t tc
#define y
#define x
SoPolyhedron is an Inventor encapsulation of the HepPolyedron class written by E.Chernyaev.
static void initClass()
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
SoSeparator * sep
void createLetterCData(std::vector< double > &x, std::vector< double > &y)
SoTranslation * transA
void normalizeLetterData(std::vector< double > &x, std::vector< double > &y, double yheight)
void ensureInit3DObjects()
SoSeparator * attachSep
void createLetterAData(std::vector< double > &x, std::vector< double > &y)
Imp(VP1Letters *, SoMaterial *mat, SoSeparator *attachsep)
SoNode * createLetter(const std::vector< double > &x, const std::vector< double > &y)
SoTranslation * transC
VP1Letters * theclass
SoMaterial * material
Imp * m_d
Definition VP1Letters.h:44
VP1Letters(SoMaterial *mat, SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
void setShown(bool)
void setZPos(const double &)
virtual ~VP1Letters()
void setVerticalPosition(const double &)
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
double ymax
Definition listroot.cxx:64
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.