ATLAS Offline Software
Loading...
Searching...
No Matches
SbPolyhedrizeAction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
27
28#include <map>
29
31 : m_polyhedron(nullptr)
32{
33 setDepthLimit(0);
34}
35
36
41
42void 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
65void SbPolyhedrizeAction::handleUnion(const GeoShapeUnion *unio)
66{
67 SbPolyhedrizeAction auxA,auxB;
68 unio->getOpA()->exec(&auxA);
69 unio->getOpB()->exec(&auxB);
70 m_polyhedron = std::make_unique<SbPolyhedron>(auxA.getPolyhedron()->add(*auxB.getPolyhedron()));
71}
72
73void SbPolyhedrizeAction::handleIntersection(const GeoShapeIntersection *isect)
74{
75 SbPolyhedrizeAction auxA,auxB;
76 isect->getOpA()->exec(&auxA);
77 isect->getOpB()->exec(&auxB);
78 m_polyhedron=std::make_unique<SbPolyhedron>(auxA.getPolyhedron()->intersect(*auxB.getPolyhedron()));
79}
80
81void SbPolyhedrizeAction::handleSubtraction(const GeoShapeSubtraction *subtract)
82{
83 SbPolyhedrizeAction auxA,auxB;
84 subtract->getOpA()->exec(&auxA);
85 subtract->getOpB()->exec(&auxB);
86 m_polyhedron=std::make_unique<SbPolyhedron>(auxA.getPolyhedron()->subtract(*auxB.getPolyhedron()));
87}
88
89void SbPolyhedrizeAction::handleBox(const GeoBox *box)
90{
91 m_polyhedron=std::make_unique<SbPolyhedronBox> (box->getXHalfLength(),
92 box->getYHalfLength(),
93 box->getZHalfLength());
94}
95
96void SbPolyhedrizeAction::handleCons(const GeoCons *cons)
97{
98 m_polyhedron = std::make_unique<SbPolyhedronCons> (cons->getRMin1(),
99 cons->getRMax1(),
100 cons->getRMin2(),
101 cons->getRMax2(),
102 cons->getDZ(),
103 cons->getSPhi(),
104 cons->getDPhi());
105}
106
107void SbPolyhedrizeAction::handlePara(const GeoPara *para)
108{
109 m_polyhedron=std::make_unique<SbPolyhedronPara>(para->getXHalfLength(),
110 para->getYHalfLength(),
111 para->getZHalfLength(),
112 para->getAlpha(),
113 para->getTheta(),
114 para->getPhi());
115}
116
117void 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 = std::make_unique<SbPolyhedronPcon> (pcon->getSPhi(), pcon->getDPhi(), pcon->getNPlanes (), z, rmn, rmx);
129
130 delete[]z;
131 delete[]rmn;
132 delete[]rmx;
133}
134
135void 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 = std::make_unique<SbPolyhedronPgon> (pgon->getSPhi(), pgon->getDPhi(), pgon->getNSides(), pgon->getNPlanes (), z, rmn, rmx);
147
148 delete[]z;
149 delete[]rmn;
150 delete[]rmx;
151}
152
153void SbPolyhedrizeAction::handleTrap(const GeoTrap *trap)
154{
155 m_polyhedron = std::make_unique<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
166void SbPolyhedrizeAction::handleTrd(const GeoTrd *trd)
167{
168 m_polyhedron = std::make_unique<SbPolyhedronTrd2> (trd->getXHalfLength1(),
169 trd->getXHalfLength2(),
170 trd->getYHalfLength1(),
171 trd->getYHalfLength2(),
172 trd->getZHalfLength());
173}
174
175void SbPolyhedrizeAction::handleTube(const GeoTube *tube)
176{
177 m_polyhedron = std::make_unique<SbPolyhedronTube> (tube->getRMin(),tube->getRMax(),tube->getZHalfLength());
178}
179
180void SbPolyhedrizeAction::handleTubs(const GeoTubs *tubs)
181{
182 m_polyhedron= std::make_unique<SbPolyhedronTubs> (tubs->getRMin(),
183 tubs->getRMax(),
184 tubs->getZHalfLength(),
185 tubs->getSPhi(),
186 tubs->getDPhi());
187}
188
189void 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
199 m_polyhedron = std::make_unique<SbPolyhedronPolygonXSect>(x,y,dz);
200}
201
202void 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.reset(polyhedron);
269}
270
271void 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 = std::make_unique<SbPolyhedronGenericTrap>(gentrap->getZHalfLength(),vertices);
278}
279
281{
282 //transfer ownership via raw ptr
283 return m_polyhedron.release();
284}
285
286
287
288
289
290
Scalar mag() const
mag method
#define y
#define x
#define z
virtual void handleSubtraction(const GeoShapeSubtraction *subtract)
virtual void handleTrap(const GeoTrap *trap)
virtual void handleTrd(const GeoTrd *trd)
SbPolyhedron * getPolyhedron()
virtual void handleTube(const GeoTube *tube)
virtual void handleTubs(const GeoTubs *tubs)
virtual void handleSimplePolygonBrep(const GeoSimplePolygonBrep *brep)
virtual void handleTessellatedSolid(const GeoTessellatedSolid *tessellated)
virtual void handlePara(const GeoPara *para)
virtual void handleShift(const GeoShapeShift *shift)
virtual void handleGenericTrap(const GeoGenericTrap *gentrap)
virtual void handlePgon(const GeoPgon *pgon)
virtual void handleIntersection(const GeoShapeIntersection *isect)
virtual void handleCons(const GeoCons *cons)
virtual void handleBox(const GeoBox *box)
virtual void handleUnion(const GeoShapeUnion *unio)
std::unique_ptr< SbPolyhedron > m_polyhedron
virtual void handlePcon(const GeoPcon *pcon)
void AddFacet(const int iv1, const int iv2, const int iv3, const int iv4=0)
void AddVertex(const double v1, const double v2, const double v3)
SbPolyhedron intersect(const SbPolyhedron &p) const
SbPolyhedron add(const SbPolyhedron &p) const
SbPolyhedron subtract(const SbPolyhedron &p) const