Geant4 11.1.1
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 ( )
virtual

Definition at line 46 of file G4ClippablePolygon.cc.

47{
48}

Member Function Documentation

◆ AddVertexInOrder()

void G4ClippablePolygon::AddVertexInOrder ( const G4ThreeVector  vertex)
virtual

Definition at line 52 of file G4ClippablePolygon.cc.

53{
54 vertices.push_back( vertex );
55}
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 270 of file G4ClippablePolygon.cc.

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

60{
61 vertices.clear();
62}

Referenced by G4PolyconeSide::CalculateExtent().

◆ Clip()

G4bool G4ClippablePolygon::Clip ( const G4VoxelLimits voxelLimit)
virtual

Definition at line 66 of file G4ClippablePolygon.cc.

67{
68 if (voxelLimit.IsLimited())
69 {
70 ClipAlongOneAxis( voxelLimit, kXAxis );
71 ClipAlongOneAxis( voxelLimit, kYAxis );
72 ClipAlongOneAxis( voxelLimit, kZAxis );
73 }
74
75 return (vertices.size() > 0);
76}
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 372 of file G4ClippablePolygon.cc.

374{
375 if (!voxelLimit.IsLimited(axis)) return;
376
377 G4ThreeVectorList tempPolygon;
378
379 //
380 // Build a "simple" voxelLimit that includes only the min extent
381 // and apply this to our vertices, producing result in tempPolygon
382 //
383 G4VoxelLimits simpleLimit1;
384 simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity );
385 ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 );
386
387 //
388 // If nothing is left from the above clip, we might as well return now
389 // (but with an empty vertices)
390 //
391 if (tempPolygon.size() == 0)
392 {
393 vertices.clear();
394 return;
395 }
396
397 //
398 // Now do the same, but using a "simple" limit that includes only the max
399 // extent. Apply this to out tempPolygon, producing result in vertices.
400 //
401 G4VoxelLimits simpleLimit2;
402 simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) );
403 ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 );
404
405 //
406 // If nothing is left, return now
407 //
408 if (vertices.size() == 0) return;
409}
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 416 of file G4ClippablePolygon.cc.

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

100{
101 //
102 // Okay, how many entries do we have?
103 //
104 std::size_t noLeft = vertices.size();
105
106 //
107 // Return false if nothing is left
108 //
109 if (noLeft == 0) return false;
110
111 //
112 // Initialize min and max to our first vertex
113 //
114 min = max = vertices[0].operator()( axis );
115
116 //
117 // Compare to the rest
118 //
119 for( std::size_t i=1; i<noLeft; ++i )
120 {
121 G4double component = vertices[i].operator()( axis );
122 if (component < min )
123 min = component;
124 else if (component > max )
125 max = component;
126 }
127
128 return true;
129}
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 166 of file G4ClippablePolygon.cc.

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

Referenced by BehindOf().

◆ GetMinPoint()

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

Definition at line 136 of file G4ClippablePolygon.cc.

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

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 333 of file G4ClippablePolygon.cc.

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

Referenced by BehindOf(), and InFrontOf().

◆ InFrontOf()

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

Definition at line 206 of file G4ClippablePolygon.cc.

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

84{
85 if (voxelLimit.IsLimited())
86 {
87 if (IgnoreMe != kXAxis) ClipAlongOneAxis( voxelLimit, kXAxis );
88 if (IgnoreMe != kYAxis) ClipAlongOneAxis( voxelLimit, kYAxis );
89 if (IgnoreMe != kZAxis) ClipAlongOneAxis( voxelLimit, kZAxis );
90 }
91
92 return (vertices.size() > 0);
93}

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: