Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ClippablePolygon Class Reference

#include <G4ClippablePolygon.hh>

Public Member Functions

 G4ClippablePolygon ()
 
virtual ~G4ClippablePolygon ()
 
virtual void AddVertexInOrder (const G4ThreeVector vertex)
 
virtual void ClearAllVertices ()
 
void SetNormal (const G4ThreeVector &newNormal)
 
const G4ThreeVector GetNormal () const
 
virtual G4bool Clip (const G4VoxelLimits &voxelLimit)
 
virtual G4bool PartialClip (const G4VoxelLimits &voxelLimit, const EAxis IgnoreMe)
 
virtual void ClipAlongOneAxis (const G4VoxelLimits &voxelLimit, const EAxis axis)
 
virtual G4bool GetExtent (const EAxis axis, G4double &min, G4double &max) const
 
virtual const G4ThreeVectorGetMinPoint (const EAxis axis) const
 
virtual const G4ThreeVectorGetMaxPoint (const EAxis axis) const
 
std::size_t GetNumVertices () const
 
G4bool Empty () const
 
virtual G4bool InFrontOf (const G4ClippablePolygon &other, EAxis axis) const
 
virtual G4bool BehindOf (const G4ClippablePolygon &other, EAxis axis) const
 
virtual G4bool GetPlanerExtent (const G4ThreeVector &pointOnPlane, const G4ThreeVector &planeNormal, G4double &min, G4double &max) const
 

Protected Member Functions

void ClipToSimpleLimits (G4ThreeVectorList &pPolygon, G4ThreeVectorList &outputPolygon, const G4VoxelLimits &pVoxelLimit)
 

Protected Attributes

G4ThreeVectorList vertices
 
G4ThreeVector normal
 
G4double kCarTolerance
 

Detailed Description

Definition at line 47 of file G4ClippablePolygon.hh.

Constructor & Destructor Documentation

◆ G4ClippablePolygon()

G4ClippablePolygon::G4ClippablePolygon ( )

Definition at line 38 of file G4ClippablePolygon.cc.

39 : normal(0.,0.,0.)
40{
42}
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()

◆ ~G4ClippablePolygon()

G4ClippablePolygon::~G4ClippablePolygon ( )
virtualdefault

Member Function Documentation

◆ AddVertexInOrder()

void G4ClippablePolygon::AddVertexInOrder ( const G4ThreeVector vertex)
virtual

Definition at line 50 of file G4ClippablePolygon.cc.

51{
52 vertices.push_back( vertex );
53}
G4ThreeVectorList vertices

Referenced by G4PolyconeSide::CalculateExtent(), G4PolyhedraSide::CalculateExtent(), and G4PolyPhiFace::CalculateExtent().

◆ BehindOf()

G4bool G4ClippablePolygon::BehindOf ( const G4ClippablePolygon & other,
EAxis axis ) const
virtual

Definition at line 268 of file G4ClippablePolygon.cc.

270{
271 //
272 // If things are empty, do something semi-sensible
273 //
274 std::size_t noLeft = vertices.size();
275 if (noLeft==0) return false;
276
277 if (other.Empty()) return true;
278
279 //
280 // Get minimum of other polygon
281 //
282 const G4ThreeVector *maxPointOther = other.GetMaxPoint( axis );
283 const G4double maxOther = maxPointOther->operator()(axis);
284
285 //
286 // Get minimum of this polygon
287 //
288 const G4ThreeVector *maxPoint = GetMaxPoint( axis );
289 const G4double max = maxPoint->operator()(axis);
290
291 //
292 // Easy decision
293 //
294 if (max > maxOther+kCarTolerance) return true; // Clear winner
295
296 if (maxOther > max+kCarTolerance) return false; // Clear loser
297
298 //
299 // We have a tie (this will not be all that rare since our
300 // polygons are connected)
301 //
302 // Check to see if there is a vertex in the other polygon
303 // that is in front of this one (or vice versa)
304 //
305 G4bool answer;
306 G4ThreeVector normalOther = other.GetNormal();
307
308 if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
309 {
310 G4double minP, maxP;
311 GetPlanerExtent( *maxPointOther, normalOther, minP, maxP );
312
313 answer = (normalOther(axis) > 0) ? (maxP > +kCarTolerance)
314 : (minP < -kCarTolerance);
315 }
316 else
317 {
318 G4double minP, maxP;
319 other.GetPlanerExtent( *maxPoint, normal, minP, maxP );
320
321 answer = (normal(axis) > 0) ? (minP < -kCarTolerance)
322 : (maxP > +kCarTolerance);
323 }
324 return answer;
325}
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
virtual G4bool GetPlanerExtent(const G4ThreeVector &pointOnPlane, const G4ThreeVector &planeNormal, G4double &min, G4double &max) const
G4bool Empty() const
const G4ThreeVector GetNormal() const
virtual const G4ThreeVector * GetMaxPoint(const EAxis axis) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments

Referenced by G4SolidExtentList::AddSurface().

◆ ClearAllVertices()

void G4ClippablePolygon::ClearAllVertices ( )
virtual

Definition at line 57 of file G4ClippablePolygon.cc.

58{
59 vertices.clear();
60}

Referenced by G4PolyconeSide::CalculateExtent().

◆ Clip()

G4bool G4ClippablePolygon::Clip ( const G4VoxelLimits & voxelLimit)
virtual

Definition at line 64 of file G4ClippablePolygon.cc.

65{
66 if (voxelLimit.IsLimited())
67 {
68 ClipAlongOneAxis( voxelLimit, kXAxis );
69 ClipAlongOneAxis( voxelLimit, kYAxis );
70 ClipAlongOneAxis( voxelLimit, kZAxis );
71 }
72
73 return (!vertices.empty());
74}
virtual void ClipAlongOneAxis(const G4VoxelLimits &voxelLimit, const EAxis axis)
G4bool IsLimited() const
@ kYAxis
Definition geomdefs.hh:56
@ kXAxis
Definition geomdefs.hh:55
@ kZAxis
Definition geomdefs.hh:57

◆ ClipAlongOneAxis()

void G4ClippablePolygon::ClipAlongOneAxis ( const G4VoxelLimits & voxelLimit,
const EAxis axis )
virtual

Definition at line 370 of file G4ClippablePolygon.cc.

372{
373 if (!voxelLimit.IsLimited(axis)) return;
374
375 G4ThreeVectorList tempPolygon;
376
377 //
378 // Build a "simple" voxelLimit that includes only the min extent
379 // and apply this to our vertices, producing result in tempPolygon
380 //
381 G4VoxelLimits simpleLimit1;
382 simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity );
383 ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 );
384
385 //
386 // If nothing is left from the above clip, we might as well return now
387 // (but with an empty vertices)
388 //
389 if (tempPolygon.empty())
390 {
391 vertices.clear();
392 return;
393 }
394
395 //
396 // Now do the same, but using a "simple" limit that includes only the max
397 // extent. Apply this to out tempPolygon, producing result in vertices.
398 //
399 G4VoxelLimits simpleLimit2;
400 simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) );
401 ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 );
402
403 //
404 // If nothing is left, return now
405 //
406 if (vertices.empty()) return;
407}
std::vector< G4ThreeVector > G4ThreeVectorList
void ClipToSimpleLimits(G4ThreeVectorList &pPolygon, G4ThreeVectorList &outputPolygon, const G4VoxelLimits &pVoxelLimit)
G4double GetMinExtent(const EAxis pAxis) const
void AddLimit(const EAxis pAxis, const G4double pMin, const G4double pMax)
G4double GetMaxExtent(const EAxis pAxis) const

Referenced by Clip(), and PartialClip().

◆ ClipToSimpleLimits()

void G4ClippablePolygon::ClipToSimpleLimits ( G4ThreeVectorList & pPolygon,
G4ThreeVectorList & outputPolygon,
const G4VoxelLimits & pVoxelLimit )
protected

Definition at line 414 of file G4ClippablePolygon.cc.

417{
418 std::size_t noVertices = pPolygon.size();
419 G4ThreeVector vEnd,vStart;
420
421 outputPolygon.clear();
422
423 for (std::size_t i=0; i<noVertices; ++i)
424 {
425 vStart=pPolygon[i];
426 if (i==noVertices-1)
427 {
428 vEnd=pPolygon[0];
429 }
430 else
431 {
432 vEnd=pPolygon[i+1];
433 }
434
435 if (pVoxelLimit.Inside(vStart))
436 {
437 if (pVoxelLimit.Inside(vEnd))
438 {
439 // vStart and vEnd inside -> output end point
440 //
441 outputPolygon.push_back(vEnd);
442 }
443 else
444 {
445 // vStart inside, vEnd outside -> output crossing point
446 //
447 pVoxelLimit.ClipToLimits(vStart,vEnd);
448 outputPolygon.push_back(vEnd);
449 }
450 }
451 else
452 {
453 if (pVoxelLimit.Inside(vEnd))
454 {
455 // vStart outside, vEnd inside -> output inside section
456 //
457 pVoxelLimit.ClipToLimits(vStart,vEnd);
458 outputPolygon.push_back(vStart);
459 outputPolygon.push_back(vEnd);
460 }
461 else // Both point outside -> no output
462 {
463 }
464 }
465 }
466}
G4bool ClipToLimits(G4ThreeVector &pStart, G4ThreeVector &pEnd) const
G4bool Inside(const G4ThreeVector &pVec) const

Referenced by ClipAlongOneAxis().

◆ Empty()

G4bool G4ClippablePolygon::Empty ( ) const
inline

◆ GetExtent()

G4bool G4ClippablePolygon::GetExtent ( const EAxis axis,
G4double & min,
G4double & max ) const
virtual

Definition at line 95 of file G4ClippablePolygon.cc.

98{
99 //
100 // Okay, how many entries do we have?
101 //
102 std::size_t noLeft = vertices.size();
103
104 //
105 // Return false if nothing is left
106 //
107 if (noLeft == 0) return false;
108
109 //
110 // Initialize min and max to our first vertex
111 //
112 min = max = vertices[0].operator()( axis );
113
114 //
115 // Compare to the rest
116 //
117 for( std::size_t i=1; i<noLeft; ++i )
118 {
119 G4double component = vertices[i].operator()( axis );
120 if (component < min )
121 min = component;
122 else if (component > max )
123 max = component;
124 }
125
126 return true;
127}
T min(const T t1, const T t2)
brief Return the smallest of the two arguments

Referenced by G4SolidExtentList::AddSurface(), and G4SolidExtentList::GetExtent().

◆ GetMaxPoint()

const G4ThreeVector * G4ClippablePolygon::GetMaxPoint ( const EAxis axis) const
virtual

Definition at line 164 of file G4ClippablePolygon.cc.

165{
166 std::size_t noLeft = vertices.size();
167 if (noLeft==0)
168 {
169 G4Exception("G4ClippablePolygon::GetMaxPoint()",
170 "GeomSolids0002", FatalException, "Empty polygon.");
171 }
172
173 const G4ThreeVector *answer = &(vertices[0]);
174 G4double max = answer->operator()(axis);
175
176 for( std::size_t i=1; i<noLeft; ++i )
177 {
178 G4double component = vertices[i].operator()( axis );
179 if (component > max)
180 {
181 answer = &(vertices[i]);
182 max = component;
183 }
184 }
185
186 return answer;
187}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)

Referenced by BehindOf().

◆ GetMinPoint()

const G4ThreeVector * G4ClippablePolygon::GetMinPoint ( const EAxis axis) const
virtual

Definition at line 134 of file G4ClippablePolygon.cc.

135{
136 std::size_t noLeft = vertices.size();
137 if (noLeft==0)
138 {
139 G4Exception("G4ClippablePolygon::GetMinPoint()",
140 "GeomSolids0002", FatalException, "Empty polygon.");
141 }
142
143 const G4ThreeVector *answer = &(vertices[0]);
144 G4double min = answer->operator()(axis);
145
146 for( std::size_t i=1; i<noLeft; ++i )
147 {
148 G4double component = vertices[i].operator()( axis );
149 if (component < min)
150 {
151 answer = &(vertices[i]);
152 min = component;
153 }
154 }
155
156 return answer;
157}

Referenced by InFrontOf().

◆ GetNormal()

const G4ThreeVector G4ClippablePolygon::GetNormal ( ) const
inline

◆ GetNumVertices()

std::size_t G4ClippablePolygon::GetNumVertices ( ) const
inline

◆ GetPlanerExtent()

G4bool G4ClippablePolygon::GetPlanerExtent ( const G4ThreeVector & pointOnPlane,
const G4ThreeVector & planeNormal,
G4double & min,
G4double & max ) const
virtual

Definition at line 331 of file G4ClippablePolygon.cc.

335{
336 //
337 // Okay, how many entries do we have?
338 //
339 std::size_t noLeft = vertices.size();
340
341 //
342 // Return false if nothing is left
343 //
344 if (noLeft == 0) return false;
345
346 //
347 // Initialize min and max to our first vertex
348 //
349 min = max = planeNormal.dot(vertices[0]-pointOnPlane);
350
351 //
352 // Compare to the rest
353 //
354 for( std::size_t i=1; i<noLeft; ++i )
355 {
356 G4double component = planeNormal.dot(vertices[i] - pointOnPlane);
357 if (component < min )
358 min = component;
359 else if (component > max )
360 max = component;
361 }
362
363 return true;
364}
double dot(const Hep3Vector &) const

Referenced by BehindOf(), and InFrontOf().

◆ InFrontOf()

G4bool G4ClippablePolygon::InFrontOf ( const G4ClippablePolygon & other,
EAxis axis ) const
virtual

Definition at line 204 of file G4ClippablePolygon.cc.

206{
207 //
208 // If things are empty, do something semi-sensible
209 //
210 std::size_t noLeft = vertices.size();
211 if (noLeft==0) return false;
212
213 if (other.Empty()) return true;
214
215 //
216 // Get minimum of other polygon
217 //
218 const G4ThreeVector *minPointOther = other.GetMinPoint( axis );
219 const G4double minOther = minPointOther->operator()(axis);
220
221 //
222 // Get minimum of this polygon
223 //
224 const G4ThreeVector *minPoint = GetMinPoint( axis );
225 const G4double min = minPoint->operator()(axis);
226
227 //
228 // Easy decision
229 //
230 if (min < minOther-kCarTolerance) return true; // Clear winner
231
232 if (minOther < min-kCarTolerance) return false; // Clear loser
233
234 //
235 // We have a tie (this will not be all that rare since our
236 // polygons are connected)
237 //
238 // Check to see if there is a vertex in the other polygon
239 // that is behind this one (or vice versa)
240 //
241 G4bool answer;
242 G4ThreeVector normalOther = other.GetNormal();
243
244 if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
245 {
246 G4double minP, maxP;
247 GetPlanerExtent( *minPointOther, normalOther, minP, maxP );
248
249 answer = (normalOther(axis) > 0) ? (minP < -kCarTolerance)
250 : (maxP > +kCarTolerance);
251 }
252 else
253 {
254 G4double minP, maxP;
255 other.GetPlanerExtent( *minPoint, normal, minP, maxP );
256
257 answer = (normal(axis) > 0) ? (maxP > +kCarTolerance)
258 : (minP < -kCarTolerance);
259 }
260 return answer;
261}
virtual const G4ThreeVector * GetMinPoint(const EAxis axis) const

Referenced by G4SolidExtentList::AddSurface().

◆ PartialClip()

G4bool G4ClippablePolygon::PartialClip ( const G4VoxelLimits & voxelLimit,
const EAxis IgnoreMe )
virtual

Definition at line 80 of file G4ClippablePolygon.cc.

82{
83 if (voxelLimit.IsLimited())
84 {
85 if (IgnoreMe != kXAxis) ClipAlongOneAxis( voxelLimit, kXAxis );
86 if (IgnoreMe != kYAxis) ClipAlongOneAxis( voxelLimit, kYAxis );
87 if (IgnoreMe != kZAxis) ClipAlongOneAxis( voxelLimit, kZAxis );
88 }
89
90 return (!vertices.empty());
91}

Referenced by G4PolyconeSide::CalculateExtent(), G4PolyhedraSide::CalculateExtent(), and G4PolyPhiFace::CalculateExtent().

◆ SetNormal()

void G4ClippablePolygon::SetNormal ( const G4ThreeVector & newNormal)
inline

Member Data Documentation

◆ kCarTolerance

G4double G4ClippablePolygon::kCarTolerance
protected

Definition at line 115 of file G4ClippablePolygon.hh.

Referenced by BehindOf(), G4ClippablePolygon(), and InFrontOf().

◆ normal

G4ThreeVector G4ClippablePolygon::normal
protected

Definition at line 114 of file G4ClippablePolygon.hh.

Referenced by BehindOf(), and InFrontOf().

◆ vertices

G4ThreeVectorList G4ClippablePolygon::vertices
protected

The documentation for this class was generated from the following files: