ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceToSoNode.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class SurfaceToSoNode //
8// //
9// Author: Andreas Salzburger <Andreas.Salzburger@cern.ch> (primary) //
10// Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
11// //
12// Initial VP1 version: June 2007 //
13// //
15
18
19#include <Inventor/C/errors/debugerror.h>
20//#include <Inventor/nodes/SoNode.h>
21#include <Inventor/nodes/SoSeparator.h>
22#include <Inventor/nodes/SoTransform.h>
23#include <Inventor/nodes/SoVertexProperty.h>
24#include <Inventor/nodes/SoLineSet.h>
29
30#include "TrkSurfaces/Surface.h"
44
45#include "GeoModelKernel/GeoSimplePolygonBrep.h"
46
47const double SurfaceToSoNode::surfaceThickness = 0.1;
48
54
56
57SoNode* SurfaceToSoNode::translateSurface(const Trk::Surface& sf, const bool& simple) const
58{
59
60 SoNode* sono =0;
61 const Trk::CylinderSurface* ccsf = dynamic_cast<const Trk::CylinderSurface*>(&sf);
62 if (ccsf) sono = this->translateCylinderSurface(*ccsf);
63
64 const Trk::DiscSurface* cdsf = sono ? 0 : dynamic_cast<const Trk::DiscSurface*>(&sf);
65 if (cdsf) sono = this->translateDiscSurface(*cdsf);
66
67 const Trk::PlaneSurface* cpsf = sono ? 0 : dynamic_cast<const Trk::PlaneSurface*>(&sf);
68 if (cpsf) sono = this->translatePlaneSurface(*cpsf);
69
70 const Trk::StraightLineSurface* cssf = sono ? 0 : dynamic_cast<const Trk::StraightLineSurface*>(&sf);
71 if (cssf) sono = this->translateStraightLineSurface(*cssf, simple);
72
73 const Trk::PerigeeSurface* cpersf = sono ? 0 : dynamic_cast<const Trk::PerigeeSurface*>(&sf);
74 if (cpersf) sono = this->translatePerigeeSurface(*cpersf);
75
76 if (!sono) {
77 std::cout<<"ERROR! Surface unknown!"<<std::endl;
78 return 0;
79 }
80
81 // place and transform them
82 SoSeparator* sosep = new SoSeparator();
83
84 // Horrible hack for ITK annulus bounds. What should really happen is we draw the surface where the bounds are. But this was never done before.
85 Amg::Transform3D transform = sf.transform();
86 if (cpsf) {
87 const Trk::AnnulusBounds* cannulus = dynamic_cast<const Trk::AnnulusBounds*>(&(cpsf->bounds()));
88 if (cannulus){
89 Amg::Vector3D vec(0.0,0.5*(cannulus->maxR()+cannulus->minR()),0.0);
90 transform.translate(vec);
91 }
92 }
93
94 SoTransform* sotra = VP1LinAlgUtils::toSoTransform(transform);
95 sosep->addChild(sotra);
96 sosep->addChild(sono);
97
98 return sosep;
99}
100
102{
103 const Trk::RectangleBounds* crecbo = dynamic_cast<const Trk::RectangleBounds*>(&(psf.bounds()));
104 if (crecbo){
105 SoGenericBox * gb = new SoGenericBox;
107 gb->drawEdgeLines.setValue(true);
108 return gb;
109 }
110
111 const Trk::TrapezoidBounds* ctrabo = dynamic_cast<const Trk::TrapezoidBounds*>(&(psf.bounds()));
112 if (ctrabo){
113 SoGenericBox * gb = new SoGenericBox;
114 const double hminphi = ctrabo->minHalflengthPhi();
115 const double hmaxphi = ctrabo->maxHalflengthPhi();
116 const double heta = ctrabo->halflengthEta();
117 gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
118 hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
119 hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
120 gb->drawEdgeLines.setValue(true);
121 return gb;
122 }
123 const Trk::RotatedTrapezoidBounds* crottrabo = dynamic_cast<const Trk::RotatedTrapezoidBounds*>(&(psf.bounds()));
124 if (crottrabo){
125 SoGenericBox * gb = new SoGenericBox;
126 const double hminphi = crottrabo->minHalflengthY();
127 const double hmaxphi = crottrabo->maxHalflengthY();
128 const double heta = crottrabo->halflengthX();
129 gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
130 hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
131 hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
132 gb->drawEdgeLines.setValue(true);
133 return gb;
134 }
135 const Trk::DiamondBounds* cdiabo = dynamic_cast<const Trk::DiamondBounds*>(&(psf.bounds()));
136 if (cdiabo){
137 double dz=0.25;
138 std::vector<double> x,y;
139 x.push_back(cdiabo->minHalflengthX());y.push_back( -2*cdiabo->halflengthY1());
140 x.push_back(cdiabo->medHalflengthX());y.push_back( 0.);
141 if (cdiabo->halflengthY2()>0.) {
142 x.push_back(cdiabo->maxHalflengthX()); y.push_back( 2*cdiabo->halflengthY2());
143 x.push_back(-cdiabo->maxHalflengthX());y.push_back( 2*cdiabo->halflengthY2());
144 }
145 x.push_back(-cdiabo->medHalflengthX());y.push_back( 0.);
146 x.push_back(-cdiabo->minHalflengthX());y.push_back( -2*cdiabo->halflengthY1());
147
148 SbPolyhedronPolygonXSect sbPoly(x,y,dz);
149 return new SoPolyhedron(sbPoly);
150 }
151
152 const Trk::AnnulusBounds* cannulus = dynamic_cast<const Trk::AnnulusBounds*>(&(psf.bounds()));
153 if (cannulus){
154 SoGenericBox * gb = new SoGenericBox;
155 const double hminphi = 0.5*cannulus->minR()*cannulus->phi();
156 const double hmaxphi = 0.5*cannulus->maxR()*cannulus->phi();
157 const double heta = 0.5 * (cannulus->maxR() - cannulus->minR());
158 gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
159 hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
160 hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
161 gb->drawEdgeLines.setValue(true);
162 return gb;
163 }
164 const Trk::NoBounds* nobo = dynamic_cast<const Trk::NoBounds*>(&(psf.bounds()));
165 if (nobo){
166 SoGenericBox * gb = new SoGenericBox;
167 gb->setParametersForBox(50.0,50.0,0.5*surfaceThickness);
168 gb->drawEdgeLines.setValue(false);
169 return gb;
170 }
171
172 return 0;
173}
174
176{
177 //std::cout<<"translateCylinderSurface"<<std::endl;
178
179 double radius = csf.bounds().r();
180 double hlength = csf.bounds().halflengthZ();
181
182 SoTubs* cylinderSurface = new SoTubs();
183 (*cylinderSurface).pRMin = radius-0.25;
184 (*cylinderSurface).pRMax = radius+0.25;
185 (*cylinderSurface).pDz = hlength;
186
187 return cylinderSurface;
188
189}
190
192{
193 //std::cout<<"translateDiscSurface"<<std::endl;
194 const Trk::DiscBounds* cdbo = dynamic_cast<const Trk::DiscBounds*>(&(dsf.bounds()));
195 if (cdbo){
196 double iradius = cdbo->rMin();
197 double oradius = cdbo->rMax();
198 double halfphisec = cdbo->halfPhiSector();
199
200 SoTubs* discSurface = new SoTubs();
201 (*discSurface).pRMin = iradius;
202 (*discSurface).pRMax = oradius;
203 (*discSurface).pDz = 0.25;
204
205 if (fabs(halfphisec-M_PI)>10e-5){
206 // sweep back the rotation as the sweepangle starts from x-axis
207 (*discSurface).pSPhi = -halfphisec;
208 (*discSurface).pDPhi = 2.* halfphisec;
209 }
210
211 return discSurface;
212 }
213 return 0;
214}
215
216SoNode* SurfaceToSoNode::translateStraightLineSurface(const Trk::StraightLineSurface& slsf, const bool& simple ) const
217{
218 //std::cout<<"translateStraightLineSurface"<<std::endl;
219 const Trk::CylinderBounds* ccbo = dynamic_cast<const Trk::CylinderBounds*>(&(slsf.bounds()));
220 if (ccbo){
221 double hlength = ccbo->halflengthZ();
222 if ( simple )
223 {
224 SoVertexProperty * scatVtxProperty = new SoVertexProperty();
225 scatVtxProperty->vertex.set1Value(0, 0.0,0.0,-hlength);
226 scatVtxProperty->vertex.set1Value(1, 0.0,0.0, hlength);
227 SoLineSet * lineSurface = new SoLineSet();
228 lineSurface->numVertices = 2;
229 lineSurface->vertexProperty = scatVtxProperty;
230 return lineSurface;
231 }
232
233 double radius = ccbo->r();
234 SoTubs* lineSurface = new SoTubs();
235 (*lineSurface).pRMin = 0.;
236 (*lineSurface).pRMax = radius;
237 (*lineSurface).pDz = hlength;
238 return lineSurface;
239 }
240 return 0;
241}
242
244{
245 //TK: Why do we need depend on the input???? FIXME
246 //std::cout<<"translatePerigeeSurface"<<std::endl;
247 SoTubs* perigeeSurface = new SoTubs();
248 (*perigeeSurface).pRMin = 0.;
249 (*perigeeSurface).pRMax = 5.;
250 (*perigeeSurface).pDz = 4000.;
251 return perigeeSurface;
252}
#define M_PI
std::vector< size_t > vec
#define y
#define x
void setParametersForBox(float dx, float dy, float dz, float xcenter=0.0, float ycenter=0.0, float zcenter=0.0)
void setParametersForTrapezoid(float dz, float theta, float phi, float dy1, float dx1, float dx2, float dy2, float dx3, float dx4, float alp1, float alp2)
static void initClass()
SoSFBool drawEdgeLines
SoPolyhedron is an Inventor encapsulation of the HepPolyedron class written by E.Chernyaev.
SoTubs - Inventor version of the G4Tubs Geant Geometry entity.
Definition SoTubs.h:52
static void initClass()
Class Initializer, required.
Definition SoTubs.cxx:63
SoNode * translateCylinderSurface(const Trk::CylinderSurface &csf) const
SoNode * translatePerigeeSurface(const Trk::PerigeeSurface &persf) const
SoNode * translateStraightLineSurface(const Trk::StraightLineSurface &slsf, const bool &simple=false) const
SoNode * translatePlaneSurface(const Trk::PlaneSurface &psf) const
SoNode * translateDiscSurface(const Trk::DiscSurface &dsf) const
virtual ~SurfaceToSoNode()
static const double surfaceThickness
SoNode * translateSurface(const Trk::Surface &sf, const bool &simple=false) const
Bounds for a annulus-like, planar Surface.
double minR() const
This method returns the smaller radius.
double maxR() const
This method returns the bigger radius.
double phi() const
This method returns the opening angle.
Bounds for a cylindrical Surface.
virtual double r() const override final
This method returns the radius.
double halflengthZ() const
This method returns the halflengthZ.
Class for a CylinderSurface in the ATLAS detector.
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
Bounds for a double trapezoidal ("diamond"), planar Surface.
double minHalflengthX() const
This method returns the halflength in X at minimal Y (first coordinate of local surface frame)
double maxHalflengthX() const
This method returns the halflength in X at maximal Y (first coordinate of local surface frame)
double medHalflengthX() const
This method returns the (maximal) halflength in X (first coordinate of local surface frame)
double halflengthY1() const
This method returns the halflength in Y of trapezoid at negative/positive Y (second coordinate)
double halflengthY2() const
Class to describe the bounds for a planar DiscSurface.
Definition DiscBounds.h:44
double rMax() const
This method returns outer radius.
double rMin() const
This method returns inner radius.
double halfPhiSector() const
This method returns the halfPhiSector which is covered by the disc.
Class for a DiscSurface in the ATLAS detector.
Definition DiscSurface.h:54
const SurfaceBounds & bounds() const override final
This method returns the bounds by reference.
Bounds object for a boundless surface (...)
Definition NoBounds.h:30
Class describing the Line to which the Perigee refers to.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
virtual const SurfaceBounds & bounds() const override final
This method returns the bounds by reference, static NoBounds in case of no boundaries.
Bounds for a rectangular, planar surface.
double halflengthPhi() const
This method returns the halflength in phi (first coordinate of local surface frame)
double halflengthEta() const
This method returns the halflength in Eta (second coordinate of local surface frame)
Bounds for a rotated trapezoidal, planar Surface.
double halflengthX() const
This method returns the minimal halflength in X (first coordinate of local surface frame)
double maxHalflengthY() const
This method returns the halflength in Y (second coordinate of local surface frame)
double minHalflengthY() const
This method returns the maximal halflength in X (first coordinate of local surface frame)
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
virtual const SurfaceBounds & bounds() const override final
This method returns the bounds of the Surface by reference.
Abstract Base Class for tracking surfaces.
Bounds for a trapezoidal, planar Surface.
double maxHalflengthPhi() const
This method returns the maximal halflength in phi (first coordinate of local surface frame)
double minHalflengthPhi() const
This method returns the minimal halflength in phi (first coordinate of local surface frame)
double halflengthEta() const
This method returns the halflength in eta (second coordinate of local surface frame)
static SoTransform * toSoTransform(const HepGeom::Transform3D &, SoTransform *t=0)
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D