ATLAS Offline Software
Loading...
Searching...
No Matches
VP1EtaCone.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 VP1EtaCone //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: April 2008 //
12// //
14
16
17#include <Inventor/C/errors/debugerror.h>
18#include <Inventor/nodes/SoMaterial.h>
19#include <Inventor/nodes/SoCone.h>
20#include <Inventor/nodes/SoSeparator.h>
21#include <Inventor/nodes/SoTranslation.h>
22#include <Inventor/nodes/SoRotationXYZ.h>
23
24#ifdef BUILDVP1LIGHT
25 #include "CLHEP/Units/SystemOfUnits.h"
26 #define SYSTEM_OF_UNITS CLHEP
27#else
28 #include "GaudiKernel/SystemOfUnits.h"
29 #define SYSTEM_OF_UNITS Gaudi::Units
30#endif
31
32//____________________________________________________________________
34public:
36 SoMaterial * mat,
37 SoSeparator * attachsep);
39 SoMaterial * material;
40 SoSeparator * attachSep;
41
42 bool shown;
43 double etaval;
44 double extent;
45
46 SoSeparator * sep;
47 SoCone * cone1;
48 SoTranslation * trans1;
49 SoCone * innercone1;
50 SoTranslation * innertrans1;
51 SoCone * cone2;
52 SoTranslation * trans2;
53 SoCone * innercone2;
54 SoTranslation * innertrans2;
55
56 void updateFields();
58};
59
60//____________________________________________________________________
61VP1EtaCone::VP1EtaCone(SoMaterial * mat,SoSeparator * attachsep,
62 IVP1System * sys,QObject * parent)
63 : QObject(parent), VP1HelperClassBase(sys,"VP1EtaCone"), m_d(new Imp(this,mat,attachsep))
64{
65}
66
67//____________________________________________________________________
69{
70 setShown(false);
71 if (m_d->sep)
72 m_d->sep->unref();
73 m_d->material->unref();
74 m_d->attachSep->unref();
75 delete m_d;
76}
77
78//____________________________________________________________________
79VP1EtaCone::Imp::Imp(VP1EtaCone *tc,SoMaterial * mat,SoSeparator * as)
80 : theclass(tc), material(mat), attachSep(as), shown(false),
81 etaval(1), extent(1), sep(0),
82 cone1(0), trans1(0), innercone1(0), innertrans1(0),
83 cone2(0), trans2(0), innercone2(0), innertrans2(0)
84{
85 material->ref();
86 attachSep->ref();
87}
88
89//____________________________________________________________________
91{
92 if (sep)
93 return;
94 theclass->messageVerbose("Building 3D objects");
95 sep = new SoSeparator;
96 sep->ref();
97 sep->addChild(material);
98
99 SoSeparator * sepfirst = new SoSeparator;
100 SoSeparator * sepsecond = new SoSeparator;
101
102 for ( int i = 0;i<2;++i){
103 SoRotationXYZ * xf = new SoRotationXYZ();
104 xf->axis=SoRotationXYZ::X;
105 xf->angle = i==0 ? 90.0*SYSTEM_OF_UNITS::deg : -90*SYSTEM_OF_UNITS::deg;
106 SoTranslation * xl = new SoTranslation();
107 SoCone * cone = new SoCone();
108 SoTranslation * innerxl = new SoTranslation();
109 SoCone * innercone = new SoCone();
110
111 if (i==0) {
112 cone1 = cone;
113 trans1 = xl;
114 innercone1 = innercone;
115 innertrans1 = innerxl;
116 } else {
117 cone2 = cone;
118 trans2 = xl;
119 innercone2 = innercone;
120 innertrans2 = innerxl;
121 }
122
123 cone->removePart(SoCone::BOTTOM);
124 innercone->removePart(SoCone::BOTTOM);
125
126 SoSeparator * s(i==0?sepfirst:sepsecond);
127 s->addChild(xf);
128 s->addChild(xl);
129 s->addChild(cone);
130 s->addChild(innerxl);
131 s->addChild(innercone);
132 sep->addChild(s);
133 }
134}
135
136//____________________________________________________________________
138{
140 theclass->messageVerbose("Updating fields");
141
142 double theta = 2*atan(exp(-fabs(etaval)));
143 double tanfact = tan(theta);
144 bool etaconeextentisz = (extent<0);
145 double absextent = fabs(extent);
146 double coneHeight,bottomRadius;
147 if (etaconeextentisz) {
148 coneHeight = absextent;
149 bottomRadius = coneHeight*tanfact;
150 } else {
151 bottomRadius = absextent;
152 coneHeight=bottomRadius/tanfact;
153 }
154
155 theclass->messageVerbose("etaval = "+str(etaval));
156 theclass->messageVerbose("extent = "+str(extent));
157 theclass->messageVerbose("absextent = "+str(absextent));
158 theclass->messageVerbose("tanfact = "+str(tanfact));
159 theclass->messageVerbose("bottomRadius = "+str(bottomRadius));
160 theclass->messageVerbose("coneHeight = "+str(coneHeight));
161
162 cone1->bottomRadius = bottomRadius;
163 cone1->height = coneHeight;
164 cone2->bottomRadius = bottomRadius;
165 cone2->height = coneHeight;
166 trans1->translation.setValue(0, -coneHeight/2, 0);
167 trans2->translation.setValue(0, -coneHeight/2, 0);
168
169 innercone1->bottomRadius = bottomRadius;
170 innercone1->height = -coneHeight;
171 innercone2->bottomRadius = bottomRadius;
172 innercone2->height = -coneHeight;
173 //To avoid render flicker from the overlapping cones, we move the inner cone slightly away from origo:
174 const double epsilon = 0.50*SYSTEM_OF_UNITS::mm;
175 innertrans1->translation.setValue(0, coneHeight/2+1.001*coneHeight/2+epsilon, 0);
176 innertrans2->translation.setValue(0, coneHeight/2+1.001*coneHeight/2+epsilon, 0);
177
178}
179
180//____________________________________________________________________
182{
183 messageVerbose("Signal received: setShown("+str(b)+")");
184 if (m_d->shown==b)
185 return;
186 m_d->shown=b;
187 if (m_d->shown) {
188 m_d->updateFields();
189 if (m_d->attachSep->findChild(m_d->sep)<0)
190 m_d->attachSep->addChild(m_d->sep);
191 } else {
192 if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
193 m_d->attachSep->removeChild(m_d->sep);
194 }
195}
196
197//____________________________________________________________________
198void VP1EtaCone::setExtent(const double&p)
199{
200 messageVerbose("Signal received: setExtent("+str(p)+")");
201 if (m_d->extent==p)
202 return;
203 m_d->extent=p;
204 if (m_d->shown)
205 m_d->updateFields();
206}
207
208//____________________________________________________________________
209void VP1EtaCone::setEtaValue(const double&p)
210{
211 messageVerbose("Signal received: setEtaValue("+str(p)+")");
212 if (m_d->etaval==p)
213 return;
214 m_d->etaval=p;
215 if (m_d->shown)
216 m_d->updateFields();
217}
Scalar theta() const
theta method
static Double_t tc
SoSeparator * attachSep
SoCone * innercone1
SoTranslation * trans2
SoMaterial * material
SoSeparator * sep
SoTranslation * trans1
void ensureInit3DObjects()
SoTranslation * innertrans1
Imp(VP1EtaCone *, SoMaterial *mat, SoSeparator *attachsep)
SoCone * innercone2
SoTranslation * innertrans2
VP1EtaCone * theclass
void setEtaValue(const double &)
Imp * m_d
Definition VP1EtaCone.h:49
VP1EtaCone(SoMaterial *mat, SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
void setShown(bool)
virtual ~VP1EtaCone()
void setExtent(const double &)
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const