Geant4 10.7.0
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
 
G4int 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 266 of file G4ClippablePolygon.cc.

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

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

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

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

Referenced by BehindOf().

◆ GetMinPoint()

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

Definition at line 136 of file G4ClippablePolygon.cc.

137{
138 G4int noLeft = vertices.size();
139 if (noLeft==0)
140 G4Exception("G4ClippablePolygon::GetMinPoint()",
141 "GeomSolids0002", FatalException, "Empty polygon.");
142
143 const G4ThreeVector *answer = &(vertices[0]);
144 G4double min = answer->operator()(axis);
145
146 for( G4int 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()

G4int G4ClippablePolygon::GetNumVertices ( ) const
inline

◆ GetPlanerExtent()

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

Definition at line 329 of file G4ClippablePolygon.cc.

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

Referenced by BehindOf(), and InFrontOf().

◆ InFrontOf()

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

Definition at line 202 of file G4ClippablePolygon.cc.

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