ATLAS Offline Software
SbPolyhedrizeAction.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GeoModelKernel/GeoShapeShift.h"
7 #include "GeoModelKernel/GeoShapeIntersection.h"
8 #include "GeoModelKernel/GeoShapeUnion.h"
9 #include "GeoModelKernel/GeoShapeSubtraction.h"
10 #include "GeoModelKernel/GeoBox.h"
11 #include "GeoModelKernel/GeoCons.h"
12 #include "GeoModelKernel/GeoPcon.h"
13 #include "GeoModelKernel/GeoPgon.h"
14 #include "GeoModelKernel/GeoTrap.h"
15 #include "GeoModelKernel/GeoTrd.h"
16 #include "GeoModelKernel/GeoTube.h"
17 #include "GeoModelKernel/GeoTubs.h"
18 #include "GeoModelKernel/GeoPara.h"
19 #include "GeoModelKernel/GeoSimplePolygonBrep.h"
20 #include "GeoModelKernel/GeoTessellatedSolid.h"
21 #include "GeoModelKernel/GeoFacet.h"
22 #include "GeoModelKernel/GeoGenericTrap.h"
23 #include "GeoModelKernel/GeoDefinitions.h"
25 
26 #include "VP1HEPVis/SbPolyhedron.h"
27 
28 #include <map>
29 
31  : m_polyhedron(NULL)
32 {
33  setDepthLimit(0);
34 }
35 
36 
38 {
39  delete m_polyhedron;
40 }
41 
42 void SbPolyhedrizeAction::handleShift(const GeoShapeShift *shift)
43 {
44  shift->getOp()->exec(this);
45  GeoTrf::RotationMatrix3D rotation=shift->getX().rotation();
46  GeoTrf::Vector3D translation = shift->getX().translation();
47 
48  // rbianchi - 14.12.2012
49 // SbVec3f trx(translation.x(),translation.y(),translation.z());
50 // SbRotation rot(SbMatrix(rotation.xx(),rotation.yx(),rotation.zx(),0,
51 // rotation.xy(),rotation.yy(),rotation.zy(),0,
52 // rotation.xz(),rotation.yz(),rotation.zz(),0,
53 // 0,0,0,1));
54  SbVec3d trx(translation.x(),translation.y(),translation.z());
55  #include <VP1HEPVis/SbRotation.h> //using doubles instead of floats.
56  HEPVis::SbRotation rot(rotation(0,0),rotation(1,0),rotation(2,0),0,
57  rotation(0,1),rotation(1,1),rotation(2,1),0,
58  rotation(0,2),rotation(1,2),rotation(2,2),0,
59  0,0,0,1);
60  //---
61 
62  m_polyhedron->Transform (rot, trx);
63 }
64 
65 void SbPolyhedrizeAction::handleUnion(const GeoShapeUnion *unio)
66 {
67  SbPolyhedrizeAction auxA,auxB;
68  unio->getOpA()->exec(&auxA);
69  unio->getOpB()->exec(&auxB);
71 }
72 
73 void SbPolyhedrizeAction::handleIntersection(const GeoShapeIntersection *isect)
74 {
75  SbPolyhedrizeAction auxA,auxB;
76  isect->getOpA()->exec(&auxA);
77  isect->getOpB()->exec(&auxB);
79 }
80 
81 void SbPolyhedrizeAction::handleSubtraction(const GeoShapeSubtraction *subtract)
82 {
83  SbPolyhedrizeAction auxA,auxB;
84  subtract->getOpA()->exec(&auxA);
85  subtract->getOpB()->exec(&auxB);
87 }
88 
89 void SbPolyhedrizeAction::handleBox(const GeoBox *box)
90 {
91  m_polyhedron=new SbPolyhedronBox (box->getXHalfLength(),
92  box->getYHalfLength(),
93  box->getZHalfLength());
94 }
95 
96 void SbPolyhedrizeAction::handleCons(const GeoCons *cons)
97 {
98  m_polyhedron = new SbPolyhedronCons (cons->getRMin1(),
99  cons->getRMax1(),
100  cons->getRMin2(),
101  cons->getRMax2(),
102  cons->getDZ(),
103  cons->getSPhi(),
104  cons->getDPhi());
105 }
106 
107 void SbPolyhedrizeAction::handlePara(const GeoPara *para)
108 {
109  m_polyhedron=new SbPolyhedronPara(para->getXHalfLength(),
110  para->getYHalfLength(),
111  para->getZHalfLength(),
112  para->getAlpha(),
113  para->getTheta(),
114  para->getPhi());
115 }
116 
117 void SbPolyhedrizeAction::handlePcon(const GeoPcon *pcon)
118 {
119  double *z = new double[pcon->getNPlanes ()];
120  double *rmn = new double[pcon->getNPlanes ()];
121  double *rmx = new double[pcon->getNPlanes ()];
122 
123  for (unsigned s = 0; s < pcon->getNPlanes (); s++) {
124  z[s] = pcon->getZPlane (s);
125  rmn[s] = pcon->getRMinPlane (s);
126  rmx[s] = pcon->getRMaxPlane (s);
127  }
128  m_polyhedron = new SbPolyhedronPcon (pcon->getSPhi(), pcon->getDPhi(), pcon->getNPlanes (), z, rmn, rmx);
129 
130  delete[]z;
131  delete[]rmn;
132  delete[]rmx;
133 }
134 
135 void SbPolyhedrizeAction::handlePgon(const GeoPgon *pgon)
136 {
137  double *z = new double[pgon->getNPlanes ()];
138  double *rmn = new double[pgon->getNPlanes ()];
139  double *rmx = new double[pgon->getNPlanes ()];
140 
141  for (unsigned s = 0; s < pgon->getNPlanes (); s++) {
142  z[s] = pgon->getZPlane (s);
143  rmn[s] = pgon->getRMinPlane (s);
144  rmx[s] = pgon->getRMaxPlane (s);
145  }
146  m_polyhedron = new SbPolyhedronPgon (pgon->getSPhi(), pgon->getDPhi(), pgon->getNSides(), pgon->getNPlanes (), z, rmn, rmx);
147 
148  delete[]z;
149  delete[]rmn;
150  delete[]rmx;
151 }
152 
153 void SbPolyhedrizeAction::handleTrap(const GeoTrap *trap)
154 {
155  m_polyhedron = new SbPolyhedronTrap (trap->getZHalfLength(),
156  trap->getTheta(),
157  trap->getPhi(),
158  trap->getDydzn(),
159  trap->getDxdyndzn(),
160  trap->getDxdypdzn(), 0,
161  trap->getDydzp(),
162  trap->getDxdyndzp(),
163  trap->getDxdypdzp(),0);
164 }
165 
166 void SbPolyhedrizeAction::handleTrd(const GeoTrd *trd)
167 {
168  m_polyhedron = new SbPolyhedronTrd2 (trd->getXHalfLength1(),
169  trd->getXHalfLength2(),
170  trd->getYHalfLength1(),
171  trd->getYHalfLength2(),
172  trd->getZHalfLength());
173 }
174 
176 {
177  m_polyhedron = new SbPolyhedronTube (tube->getRMin(),tube->getRMax(),tube->getZHalfLength());
178 }
179 
180 void SbPolyhedrizeAction::handleTubs(const GeoTubs *tubs)
181 {
182  m_polyhedron= new SbPolyhedronTubs (tubs->getRMin(),
183  tubs->getRMax(),
184  tubs->getZHalfLength(),
185  tubs->getSPhi(),
186  tubs->getDPhi());
187 }
188 
189 void SbPolyhedrizeAction::handleSimplePolygonBrep(const GeoSimplePolygonBrep *brep)
190 {
191  double dz = brep->getDZ();
192  std::vector<double> x, y;
193  for(unsigned int i=0; i<brep->getNVertices(); i++)
194  {
195  x.push_back(brep->getXVertex(i));
196  y.push_back(brep->getYVertex(i));
197  }
198 
200 }
201 
202 void SbPolyhedrizeAction::handleTessellatedSolid(const GeoTessellatedSolid *tessellated)
203 {
204  // ______ Perform actions a la SetSolidClosed ________
205  double vertTolerance = 1E-15; // kCarTolerance ??
206  std::vector<GeoFacetVertex> vertexList;
207  std::map<GeoFacet*,std::vector<size_t> > facetVertIndInSolid; // Vacet vertex indices in the vertexList
208 
209  // Loop over facets in the solid
210  for(size_t facetIndInSolid = 0; facetIndInSolid<tessellated->getNumberOfFacets(); ++facetIndInSolid) {
211  GeoFacet* facet = tessellated->getFacet(facetIndInSolid);
212 
213  facetVertIndInSolid[facet] = std::vector<size_t>();
214  std::vector<size_t>& current = facetVertIndInSolid[facet];
215  if(facet->getNumberOfVertices()==3)
216  current.resize(3,0);
217  else
218  current.resize(4,0);
219 
220  size_t vertexListSize = vertexList.size();
221  GeoFacetVertex vertex(0.,0.,0.);
222 
223  // Loop over vertices in the current facet
224  for(size_t vertexIndInFacet=0; vertexIndInFacet<facet->getNumberOfVertices(); ++vertexIndInFacet) {
225  vertex = facet->getVertex(vertexIndInFacet);
226 
227  // Check if we already have this vertex in our vertexList
228  bool found = false;
229  size_t j=0;
230  while(j<vertexListSize && !found) {
231  GeoFacetVertex vertexToCheck = vertexList[j];
232  found = (vertexToCheck-vertex).mag() < vertTolerance;
233  if(!found) j++;
234  }
235 
236  if(found) {
237  current[vertexIndInFacet] = j;
238  }
239  else {
240  vertexList.push_back(vertex);
241  current[vertexIndInFacet] = vertexList.size()-1;
242  }
243  }
244  }
245 
246  // ______ Create Polyhedron itself ______
247  SbPolyhedronArbitrary* polyhedron= new SbPolyhedronArbitrary(vertexList.size(),tessellated->getNumberOfFacets());
248 
249  // add vertices from the list
250  for(size_t vertexInd=0; vertexInd<vertexList.size(); ++vertexInd) {
251  GeoFacetVertex vertex = vertexList[vertexInd];
252  polyhedron->AddVertex(vertex.x(),vertex.y(),vertex.z());
253  }
254 
255  // add facets
256  for(size_t facetIndInSolid = 0; facetIndInSolid<tessellated->getNumberOfFacets(); ++facetIndInSolid) {
257  GeoFacet* facet = tessellated->getFacet(facetIndInSolid);
258  std::vector<size_t>& current = facetVertIndInSolid[facet];
259 
260  size_t v[4];
261  for (size_t j=0; j<4; j++)
262  v[j] = (j<current.size() ? current[j]+1 : 0);
263 
264  polyhedron->AddFacet(v[0],v[1],v[2],v[3]);
265  }
266 
267  polyhedron->Finalize();
268  m_polyhedron = polyhedron;
269 }
270 
271 void SbPolyhedrizeAction::handleGenericTrap(const GeoGenericTrap *gentrap)
272 {
273  std::vector<std::pair<double,double> > vertices;
274  vertices.reserve(8);
275  for(size_t i=0; i<8; ++i)
276  vertices.push_back(std::pair<double,double>(gentrap->getVertices()[i].x(),gentrap->getVertices()[i].y()));
277  m_polyhedron = new SbPolyhedronGenericTrap(gentrap->getZHalfLength(),vertices);
278 }
279 
281 {
282  return m_polyhedron;
283 }
284 
285 
286 
287 
288 
289 
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
SbPolyhedron
Definition: SbPolyhedron.h:231
SbPolyhedronTube
Definition: SbPolyhedron.h:479
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SbPolyhedrizeAction::handleTrd
virtual void handleTrd(const GeoTrd *trd)
Definition: SbPolyhedrizeAction.cxx:166
SbPolyhedron::add
SbPolyhedron add(const SbPolyhedron &p) const
Definition: SbPolyhedron.cxx:1842
SbPolyhedronTubs
Definition: SbPolyhedron.h:469
SbPolyhedrizeAction
Definition: SbPolyhedrizeAction.h:18
SbPolyhedrizeAction::handleTrap
virtual void handleTrap(const GeoTrap *trap)
Definition: SbPolyhedrizeAction.cxx:153
x
#define x
SbPolyhedronBox
Definition: SbPolyhedron.h:416
SbPolyhedrizeAction::handleIntersection
virtual void handleIntersection(const GeoShapeIntersection *isect)
Definition: SbPolyhedrizeAction.cxx:73
GeoPrimitives.h
SbPolyhedron::Transform
SbPolyhedron & Transform(const HEPVis::SbRotation &rot, const SbVec3d &trans)
Definition: SbPolyhedron.cxx:878
SbPolyhedronTrap
Definition: SbPolyhedron.h:425
SbPolyhedrizeAction::handlePgon
virtual void handlePgon(const GeoPgon *pgon)
Definition: SbPolyhedrizeAction.cxx:135
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
SbPolyhedrizeAction::handleGenericTrap
virtual void handleGenericTrap(const GeoGenericTrap *gentrap)
Definition: SbPolyhedrizeAction.cxx:271
xAOD::rotation
rotation
Definition: TrackSurface_v1.cxx:15
SbPolyhedrizeAction::handleShift
virtual void handleShift(const GeoShapeShift *shift)
Definition: SbPolyhedrizeAction.cxx:42
SbPolyhedronTrd2
Definition: SbPolyhedron.h:396
SbPolyhedronArbitrary
Definition: SbPolyhedron.h:552
SbRotation.h
SbPolyhedrizeAction::handlePcon
virtual void handlePcon(const GeoPcon *pcon)
Definition: SbPolyhedrizeAction.cxx:117
SbPolyhedrizeAction::getPolyhedron
const SbPolyhedron * getPolyhedron() const
Definition: SbPolyhedrizeAction.cxx:280
SbPolyhedronPgon
Definition: SbPolyhedron.h:488
SbPolyhedronPcon
Definition: SbPolyhedron.h:500
SbPolyhedronArbitrary::Finalize
void Finalize()
Definition: SbPolyhedron.cxx:2406
SbPolyhedrizeAction::SbPolyhedrizeAction
SbPolyhedrizeAction()
Definition: SbPolyhedrizeAction.cxx:30
SbPolyhedrizeAction::handleSimplePolygonBrep
virtual void handleSimplePolygonBrep(const GeoSimplePolygonBrep *brep)
Definition: SbPolyhedrizeAction.cxx:189
SbPolyhedrizeAction.h
SbPolyhedrizeAction::handleTessellatedSolid
virtual void handleTessellatedSolid(const GeoTessellatedSolid *tessellated)
Definition: SbPolyhedrizeAction.cxx:202
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
SbPolyhedrizeAction::handlePara
virtual void handlePara(const GeoPara *para)
Definition: SbPolyhedrizeAction.cxx:107
SbPolyhedronArbitrary::AddFacet
void AddFacet(const int iv1, const int iv2, const int iv3, const int iv4=0)
Definition: SbPolyhedron.cxx:2377
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.PyAthena.v
v
Definition: PyAthena.py:157
SbPolyhedrizeAction::handleTube
virtual void handleTube(const GeoTube *tube)
Definition: SbPolyhedrizeAction.cxx:175
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
SbPolyhedronArbitrary::AddVertex
void AddVertex(const double v1, const double v2, const double v3)
Definition: SbPolyhedron.cxx:2365
y
#define y
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
SbPolyhedrizeAction::handleSubtraction
virtual void handleSubtraction(const GeoShapeSubtraction *subtract)
Definition: SbPolyhedrizeAction.cxx:81
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
SbPolyhedrizeAction::handleUnion
virtual void handleUnion(const GeoShapeUnion *unio)
Definition: SbPolyhedrizeAction.cxx:65
SbPolyhedrizeAction::handleTubs
virtual void handleTubs(const GeoTubs *tubs)
Definition: SbPolyhedrizeAction.cxx:180
SbPolyhedrizeAction::handleBox
virtual void handleBox(const GeoBox *box)
Definition: SbPolyhedrizeAction.cxx:89
SbPolyhedrizeAction::~SbPolyhedrizeAction
virtual ~SbPolyhedrizeAction()
Definition: SbPolyhedrizeAction.cxx:37
SbPolyhedronGenericTrap
Definition: SbPolyhedron.h:572
SbPolyhedrizeAction::handleCons
virtual void handleCons(const GeoCons *cons)
Definition: SbPolyhedrizeAction.cxx:96
SbPolyhedron::subtract
SbPolyhedron subtract(const SbPolyhedron &p) const
Definition: SbPolyhedron.cxx:1878
SbPolyhedronCons
Definition: SbPolyhedron.h:448
SbPolyhedronPara
Definition: SbPolyhedron.h:438
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:25
SbPolyhedron.h
calibdata.tube
tube
Definition: calibdata.py:31
SbPolyhedron::intersect
SbPolyhedron intersect(const SbPolyhedron &p) const
Definition: SbPolyhedron.cxx:1860
HEPVis::SbRotation
Definition: SbRotation.h:35
SbPolyhedrizeAction::m_polyhedron
SbPolyhedron * m_polyhedron
Definition: SbPolyhedrizeAction.h:66
SbPolyhedronPolygonXSect
Definition: SbPolyhedron.h:534