ATLAS Offline Software
Loading...
Searching...
No Matches
VP1CylindricalGrid.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 VP1CylindricalGrid //
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
18
19#include <Inventor/nodes/SoSeparator.h>
20#include <Inventor/nodes/SoVertexProperty.h>
21#include <Inventor/nodes/SoLineSet.h>
22#include <Inventor/nodes/SoTranslation.h>
23#include <Inventor/nodes/SoPackedColor.h>
24#include <Inventor/SbColor4f.h>
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 SoSeparator * attachsep);
40 SoSeparator * attachSep;
41
42 bool shown;
43 SbColor4f colourAndTransp;
44 double extent;
45 double spacing;
46
47 SoSeparator * sep;
48 SoPackedColor * circlecol;
49
50 void rebuild3DObjects();
51 void updateColour();
52};
53
54//____________________________________________________________________
56 IVP1System * sys,QObject * parent)
57 : QObject(parent), VP1HelperClassBase(sys,"VP1CylindricalGrid"), m_d(new Imp(this,attachsep))
58{
59}
60
61//____________________________________________________________________
63{
64 setShown(false);
65 if (m_d->sep)
66 m_d->sep->unref();
67 if (m_d->circlecol)
68 m_d->circlecol->unref();
69 m_d->attachSep->unref();
70 delete m_d;
71}
72
73//____________________________________________________________________
75 : theclass(tc), attachSep(as), shown(false),
76 colourAndTransp(SbColor4f(1,1,1,1)),extent(10), spacing(1),
77 sep(0), circlecol(0)
78{
79 attachSep->ref();
80}
81
82//____________________________________________________________________
84{
85 theclass->messageVerbose("(Re)building 3D objects");
86
87 if (sep) {
88 sep->removeAllChildren();
89 } else {
90 sep = new SoSeparator;
91 sep->ref();
92 }
93
94 const bool save = sep->enableNotify(false);
95
96 int nmax; double distmax;
97 if (!VP1Floor::calcParsFromExtentAndSpacing( theclass, extent, spacing, 20/*max lines*/, nmax, distmax )) {
98 nmax = 10;
99 distmax = 10*SYSTEM_OF_UNITS::m;
100 theclass->message("ERROR: Problems calculating nmax/distmax.");
101 }
102
103 if (!circlecol) {
104 circlecol = new SoPackedColor();
105 circlecol->ref();
106 }
107
108 //Add circles:
109 sep->addChild(circlecol);
110
111 for (int ir=1;ir<=nmax;++ir) {
113 SoSeparator * s = new SoSeparator;
114 SoTranslation *t1= new SoTranslation();
115 t1->translation.setValue(0.0,0.0,-distmax-spacing);
116 s->addChild(t1);
117 for (int iz = -nmax; iz<=nmax; ++iz) {
118 SoTranslation *t2= new SoTranslation();
119 t2->translation.setValue(0.0,0.0,spacing);
120 s->addChild(t2);
121 s->addChild(circle);
122 }
123 sep->addChild(s);
124 }
125
126 //Add lines:
127
128 SoVertexProperty * grid_cylindrical_vertices = new SoVertexProperty();
129
130 int ivert(0);
131 int nsublines(0);
132 static const double invsqrttwo = 1.0/sqrt(2.0);
133 for (int ir=1;ir<=nmax;++ir) {
134 double r = ir*spacing;
135 double r2 = r*invsqrttwo;
136 grid_cylindrical_vertices->vertex.set1Value(ivert++,r,0,-distmax);
137 grid_cylindrical_vertices->vertex.set1Value(ivert++,r,0,+distmax);
138 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,r,-distmax);
139 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,r,+distmax);
140 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r,0,-distmax);
141 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r,0,+distmax);
142 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,-r,-distmax);
143 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,-r,+distmax);
144 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,r2,-distmax);
145 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,r2,+distmax);
146 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,-r2,-distmax);
147 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,-r2,+distmax);
148 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,r2,-distmax);
149 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,r2,+distmax);
150 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,-r2,-distmax);
151 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,-r2,+distmax);
152 nsublines+=8;
153 }
154
155 grid_cylindrical_vertices->materialBinding=SoMaterialBinding::OVERALL;
156 grid_cylindrical_vertices->normalBinding=SoNormalBinding::OVERALL;
157 SoLineSet * line = new SoLineSet();
158 line->numVertices.enableNotify(FALSE);
159 line->numVertices.setNum(nsublines);
160 for (int i=0;i<nsublines;++i)
161 line->numVertices.set1Value(i,2);
162 line->vertexProperty = grid_cylindrical_vertices;
163 line->numVertices.enableNotify(TRUE);
164 line->numVertices.touch();
165
166 sep->addChild(line);
167 updateColour();
168
169 if (save) {
170 sep->enableNotify(true);
171 sep->touch();
172 }
173
174}
175
176//____________________________________________________________________
178{
179 theclass->messageVerbose("Updating packed colour");
180 if (circlecol)
181 circlecol->orderedRGBA = colourAndTransp.getPackedValue();
182 if (!sep||sep->getNumChildren()<1)
183 return;
184 SoNode * n = sep->getChild(0);
185 if (!n||n->getTypeId()!=SoLineSet::getClassTypeId())
186 return;
187 SoLineSet * line = static_cast<SoLineSet*>(n);
188 SoVertexProperty * vertices = static_cast<SoVertexProperty *>(line->vertexProperty.getValue());
189 if (vertices)
190 vertices->orderedRGBA = colourAndTransp.getPackedValue();
191}
192
193//____________________________________________________________________
195{
196 messageVerbose("Signal received: setShown("+str(b)+")");
197 if (m_d->shown==b)
198 return;
199 m_d->shown=b;
200 if (m_d->shown) {
201 m_d->rebuild3DObjects();
202 if (m_d->attachSep->findChild(m_d->sep)<0)
203 m_d->attachSep->addChild(m_d->sep);
204 } else {
205 if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
206 m_d->attachSep->removeChild(m_d->sep);
207 }
208}
209
210//____________________________________________________________________
212{
213 messageVerbose("Signal received in setColourAndTransp slot.");
214 if (m_d->colourAndTransp==ct)
215 return;
216 m_d->colourAndTransp=ct;
217 if (m_d->shown)
218 m_d->updateColour();
219}
220
221//____________________________________________________________________
222void VP1CylindricalGrid::setExtent(const double& e)
223{
224 messageVerbose("Signal received: setExtent("+str(e)+")");
225 if (m_d->extent==e)
226 return;
227 m_d->extent=e;
228 if (m_d->shown)
229 m_d->rebuild3DObjects();
230}
231
232//____________________________________________________________________
234{
235 messageVerbose("Signal received: setSpacing("+str(s)+")");
236 if (m_d->spacing==s)
237 return;
238 m_d->spacing=s;
239 if (m_d->shown)
240 m_d->rebuild3DObjects();
241}
static Double_t tc
const int nmax(200)
Imp(VP1CylindricalGrid *, SoSeparator *attachsep)
VP1CylindricalGrid * theclass
void setSpacing(const double &)
void setExtent(const double &)
VP1CylindricalGrid(SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
void setColourAndTransp(const SbColor4f &)
static bool calcParsFromExtentAndSpacing(const VP1HelperClassBase *, const double &extent, const double &spacing, const int &nmaxlimit, int &nmax, double &distmax)
Definition VP1Floor.cxx:30
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
static SoNode * createCircle(const double &radius)
int ir
counter of the current depth
Definition fastadd.cxx:49
int r
Definition globals.cxx:22