8#include <Inventor/C/errors/debugerror.h>
9#include <Inventor/nodes/SoVertexProperty.h>
10#include <Inventor/nodes/SoLineSet.h>
11#include <Inventor/nodes/SoPointSet.h>
12#include <Inventor/nodes/SoSeparator.h>
13#include <Inventor/nodes/SoCylinder.h>
14#include <Inventor/nodes/SoRotationXYZ.h>
15#include <Inventor/nodes/SoTranslation.h>
16#include <Inventor/nodes/SoInfo.h>
17#include <Inventor/nodes/SoTransform.h>
43 typename T::iterator it(t.begin()), itE(t.end());
52 theclass->message(
"sanitiseParameterValue WARNING - received nan paramter. Putting to 1.0e-5.");
59 theclass->messageVerbose(
"sanitiseParameterValue WARNING - received negative parameter. Flipping sign.");
70 theclass->message(
"sanitiseParameterValue WARNING - received nan paramter. Putting to 1.0e-5.");
77 theclass->messageVerbose(
"sanitiseParameterValue WARNING - received negative parameter. Flipping sign.");
80 if (
x < 1.0e-5 &&
x != 0.0 )
85 void summarise(
unsigned n,
const QString& shapename)
const;
95 m_d->cachedshape_point = 0;
96 m_d->cached_unittransform = 0;
104 theclass->messageDebug(
" WARNING: Created more than 100 ("+QString::number(n)+
") different "+shapename+
" shapes.");
106 theclass->messageVerbose(
"Created "+QString::number(n)+
" different "+shapename+
" shapes.");
116 m_d->summarise(
m_d->cachedshapes_drifttubes.size(),
"drift tube");
117 m_d->summarise(
m_d->cachedshapes_driftdiscs.size(),
"drift disc");
118 m_d->summarise(
m_d->cachedshapes_projdrifttubes.size(),
"projected drift tube");
119 m_d->summarise(
m_d->cachedshapes_strips.size(),
"strip");
120 m_d->summarise(
m_d->cachedshapes_cross.size(),
"cross");
128 if (
m_d->cachedshape_point)
129 m_d->cachedshape_point->unref();
130 if (
m_d->cached_unittransform)
131 m_d->cached_unittransform->unref();
140 m_d->sanitiseParameterValue(halfLength);
141 m_d->sanitiseParameterValueAllowZero(radius);
144 double id(halfLength-999999999.9*radius);
145 std::map<double,SoNode*>::const_iterator it =
m_d->cachedshapes_drifttubes.find(
id);
146 if (it!=
m_d->cachedshapes_drifttubes.end())
150 SoSeparator*sep =
new SoSeparator;
151 SoRotationXYZ * rot =
new SoRotationXYZ;
152 rot->axis.setValue(SoRotationXYZ::X);
153 rot->angle.setValue(
M_PI*0.5f);
155 SoCylinder * cyl =
new SoCylinder;
156 cyl->radius.setValue(radius);
157 cyl->height.setValue(2.0f*halfLength);
159 m_d->cachedshapes_drifttubes[id] = sep;
163 SoVertexProperty * scatVtxProperty =
new SoVertexProperty();
164 scatVtxProperty->vertex.set1Value(0, 0.0f,0.0f,-halfLength);
165 scatVtxProperty->vertex.set1Value(1, 0.0f,0.0f, halfLength);
166 SoLineSet * line =
new SoLineSet();
167 line->numVertices = 2;
168 line->vertexProperty = scatVtxProperty;
169 m_d->cachedshapes_drifttubes[id] = line;
179 m_d->sanitiseParameterValueAllowZero(radius);
183 std::map<double,SoNode*>::const_iterator it =
m_d->cachedshapes_driftdiscs.find(radius);
184 if (it!=
m_d->cachedshapes_driftdiscs.end())
187 SoSeparator*sep =
new SoSeparator;
188 SoRotationXYZ * rot =
new SoRotationXYZ;
189 rot->axis.setValue(SoRotationXYZ::X);
190 rot->angle.setValue(
M_PI*0.5f);
192 SoCylinder * cyl =
new SoCylinder;
193 cyl->radius.setValue(radius);
194 cyl->height.setValue(
m_d->driftdischeight);
197 m_d->cachedshapes_driftdiscs[radius] = sep;
204 bool inner,
bool outer )
206 m_d->sanitiseParameterValue(halfLength);
207 m_d->sanitiseParameterValueAllowZero(radius);
210 double id(halfLength-9999.9*radius-(inner?0.0:-9999799.99)-(outer?0.0:-9999997979.99));
211 std::map<double,SoNode*>::const_iterator it =
m_d->cachedshapes_projdrifttubes.find(
id);
212 if (it!=
m_d->cachedshapes_projdrifttubes.end())
215 if (!inner&&!outer) {
217 SoInfo * info =
new SoInfo;
219 m_d->cachedshapes_projdrifttubes[id] = info;
224 double halfLengthInner = halfLength<160.0 ? 2*349.3150-halfLength : halfLength;
225 m_d->sanitiseParameterValue(halfLengthInner);
228 SoSeparator*sep =
new SoSeparator;
229 SoRotationXYZ * rot =
new SoRotationXYZ;
230 rot->axis.setValue(SoRotationXYZ::X);
231 rot->angle.setValue(
M_PI*0.5f);
233 SoCylinder * cyl =
new SoCylinder;
234 cyl->radius.setValue(radius);
235 cyl->height.setValue(
m_d->driftdischeight);
237 SoTranslation * trans =
new SoTranslation;
238 trans->translation.setValue(0.0f,halfLengthInner,0.0f);
239 sep->addChild(trans);
243 SoTranslation * trans =
new SoTranslation;
244 trans->translation.setValue(0.0f,(inner?-halfLength-halfLengthInner:-halfLength),0.0f);
245 sep->addChild(trans);
248 m_d->cachedshapes_projdrifttubes[id] = sep;
252 SoPointSet * scatPointSet =
new SoPointSet;
253 SoVertexProperty * scatVtxProperty =
new SoVertexProperty;
256 scatVtxProperty->vertex.set1Value(i++,0.0f,0.0f,halfLengthInner);
258 scatVtxProperty->vertex.set1Value(i++,0.0f,0.0f,-halfLength);
259 scatPointSet->numPoints=i;
260 scatPointSet->vertexProperty.setValue(scatVtxProperty);
261 m_d->cachedshapes_projdrifttubes[id] = scatPointSet;
273 m_d->sanitiseParameterValueAllowZero(
length);
274 m_d->sanitiseParameterValueAllowZero(
width);
275 m_d->sanitiseParameterValueAllowZero(
depth);
278 std::map<double,SoNode*>::const_iterator it =
m_d->cachedshapes_strips.find(
id);
279 if (it!=
m_d->cachedshapes_strips.end())
284 std::cout <<
"lengthStrip==0.0, returning a point..." << std::endl;
288 SoVertexProperty * scatVtxProperty =
new SoVertexProperty();
289 scatVtxProperty->vertex.set1Value(0, 0.0f,-
length*0.5f,0.0f);
290 scatVtxProperty->vertex.set1Value(1, 0.0f,
length*0.5f,0.0f);
291 SoLineSet * line =
new SoLineSet();
292 line->numVertices = 2;
293 line->vertexProperty = scatVtxProperty;
294 m_d->cachedshapes_strips[id] = line;
305 m_d->cachedshapes_strips[id] = cube;
322 m_d->sanitiseParameterValueAllowZero(
length);
323 m_d->sanitiseParameterValueAllowZero(minWidth);
324 m_d->sanitiseParameterValueAllowZero(maxWidth);
325 m_d->sanitiseParameterValueAllowZero(
depth);
332 if (maxWidth==0.0&&
depth==0) {
334 std::cout <<
"lengthWire==0.0, returning a point..." << std::endl;
338 SoVertexProperty * scatVtxProperty =
new SoVertexProperty();
339 scatVtxProperty->vertex.set1Value(0, 0.0f,-
length*0.5f,0.0f);
340 scatVtxProperty->vertex.set1Value(1, 0.0f,
length*0.5f,0.0f);
341 SoLineSet * line =
new SoLineSet();
342 line->numVertices = 2;
343 line->vertexProperty = scatVtxProperty;
352 m_d->sanitiseParameterValue(minWidth);
353 m_d->sanitiseParameterValue(maxWidth);
368 m_d->sanitiseParameterValueAllowZero(
length);
369 m_d->sanitiseParameterValueAllowZero(minWidth);
370 m_d->sanitiseParameterValueAllowZero(maxWidth);
371 m_d->sanitiseParameterValueAllowZero(
depth);
378 if (maxWidth==0.0 &&
depth==0) {
380 std::cout <<
"maxWidth==0.0 && depth==0 && lengthPad==0.0, returning a point..." << std::endl;
385 SoVertexProperty * scatVtxProperty =
new SoVertexProperty();
386 scatVtxProperty->vertex.set1Value(0, 0.0f,-
length*0.5f,0.0f);
387 scatVtxProperty->vertex.set1Value(1, 0.0f,
length*0.5f,0.0f);
388 SoLineSet * line =
new SoLineSet();
389 line->numVertices = 2;
390 line->vertexProperty = scatVtxProperty;
400 m_d->sanitiseParameterValue(minWidth);
401 m_d->sanitiseParameterValue(maxWidth);
414 if (!
m_d->cachedshape_point) {
415 SoPointSet * scatPointSet =
new SoPointSet;
416 SoVertexProperty * scatVtxProperty =
new SoVertexProperty;
417 scatVtxProperty->vertex.set1Value(0,0.0f,0.0f,0.0f);
418 scatPointSet->numPoints=1;
419 scatPointSet->vertexProperty.setValue(scatVtxProperty);
420 m_d->cachedshape_point = scatPointSet;
421 m_d->cachedshape_point->ref();
423 return m_d->cachedshape_point;
429 std::map<double,SoNode*>::const_iterator it =
m_d->cachedshapes_cross.find(extent);
430 if (it!=
m_d->cachedshapes_cross.end())
433 SoVertexProperty * vertices =
new SoVertexProperty;
435 vertices->vertex.set1Value(iver++,-extent,0.0,0.0);
436 vertices->vertex.set1Value(iver++,+extent,0.0,0.0);
437 vertices->vertex.set1Value(iver++,0.0,-extent,0.0);
438 vertices->vertex.set1Value(iver++,0.0,+extent,0.0);
439 vertices->vertex.set1Value(iver++,0.0,0.0,-extent);
440 vertices->vertex.set1Value(iver++,0.0,0.0,+extent);
442 SoLineSet * cross =
new SoLineSet;
443 cross->vertexProperty = vertices;
445 cross->numVertices.set1Value(numlines++,2);
446 cross->numVertices.set1Value(numlines++,2);
447 cross->numVertices.set1Value(numlines++,2);
449 m_d->cachedshapes_cross[extent] = cross;
450 m_d->cachedshapes_cross[extent]->ref();
452 return m_d->cachedshapes_cross[extent];
458 if (!
m_d->cached_unittransform) {
459 m_d->cached_unittransform =
new SoTransform;
460 m_d->cached_unittransform->ref();
462 return m_d->cached_unittransform;
void summarise(unsigned n, const QString &shapename) const
std::map< double, SoNode *, CxxUtils::fpcompare_fn::less > cachedshapes_projdrifttubes
std::map< double, SoNode *, CxxUtils::fpcompare_fn::less > cachedshapes_drifttubes
std::map< double, SoNode *, CxxUtils::fpcompare_fn::less > cachedshapes_cross
SoTransform * cached_unittransform
static void unrefValues(T &t)
void sanitiseParameterValueAllowZero(double &x)
void sanitiseParameterValue(double &x)
const double driftdischeight
SoNode * cachedshape_point
HitsSoNodeManager * theclass
std::map< double, SoNode *, CxxUtils::fpcompare_fn::less > cachedshapes_driftdiscs
std::map< double, SoNode *, CxxUtils::fpcompare_fn::less > cachedshapes_strips
HitsSoNodeManager(IVP1System *sys=0)
SoNode * getShapeNode_Wire(double length, double minWidth=0, double maxWidth=0, double depth=0)
SoNode * getShapeNode_Point()
SoNode * getShapeNode_DriftDisc(double radius)
SoNode * getShapeNode_Cross(double extent)
SoNode * getShapeNode_Strip(double length, double width=0, double depth=0)
SoTransform * getUnitTransform()
SoNode * getShapeNode_Pad(double length, double minWidth=0, double maxWidth=0, double depth=0)
SoNode * getShapeNode_ProjectedDriftTube(double halfLength, double radius, bool inner, bool outer)
SoNode * getShapeNode_DriftTube(double halfLength, double radius)
void setParametersForBox(float dx, float dy, float dz, float xcenter=0.0, float ycenter=0.0, float zcenter=0.0)
void setParametersForTrd(float dx1, float dx2, float dy1, float dy2, float dz)
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
std::string depth
tag string for intendation
Workaround x86 precision issues for FP inequality comparisons.