ATLAS Offline Software
Loading...
Searching...
No Matches
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//____________________________________________________________________
33public:
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//____________________________________________________________________
51VP1CartesianGrid::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) {
173 m_d->rebuild3DObjects();
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;
188 m_d->colourAndTransp=ct;
189 if (m_d->shown)
190 m_d->updateColour();
191}
192
193//____________________________________________________________________
194void 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)
201 m_d->rebuild3DObjects();
202}
203
204//____________________________________________________________________
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)
212 m_d->rebuild3DObjects();
213}
static Double_t tc
const int nmax(200)
#define y
#define x
#define z
Imp(VP1CartesianGrid *, SoSeparator *attachsep)
VP1CartesianGrid * theclass
void setExtent(const double &)
void setSpacing(const double &)
void setColourAndTransp(const SbColor4f &)
VP1CartesianGrid(SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
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