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

G4ClippablePolygon in a utility class defining a polygon that can be clipped by a voxel. More...

#include <G4ClippablePolygon.hh>

Public Member Functions

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

Detailed Description

G4ClippablePolygon in a utility class defining a polygon that can be clipped by a voxel.

Definition at line 51 of file G4ClippablePolygon.hh.

Constructor & Destructor Documentation

◆ G4ClippablePolygon()

G4ClippablePolygon::G4ClippablePolygon ( )

Default Constructor and Destructor.

Definition at line 38 of file G4ClippablePolygon.cc.

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

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

◆ ~G4ClippablePolygon()

G4ClippablePolygon::~G4ClippablePolygon ( )
default

Member Function Documentation

◆ AddVertexInOrder()

void G4ClippablePolygon::AddVertexInOrder ( const G4ThreeVector & vertex)

Adds a vertex to collection.

Definition at line 46 of file G4ClippablePolygon.cc.

47{
48 vertices.push_back( vertex );
49}

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

◆ BehindOf()

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

Decides if this polygon is behind another. Remarks in previous method are valid here too.

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}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
G4bool GetPlanerExtent(const G4ThreeVector &pointOnPlane, const G4ThreeVector &planeNormal, G4double &min, G4double &max) const
G4bool Empty() const
const G4ThreeVector GetNormal() const
const G4ThreeVector * GetMaxPoint(const EAxis axis) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668

Referenced by G4SolidExtentList::AddSurface().

◆ ClearAllVertices()

void G4ClippablePolygon::ClearAllVertices ( )

Clears the collection of vertices.

Definition at line 53 of file G4ClippablePolygon.cc.

54{
55 vertices.clear();
56}

Referenced by G4PolyconeSide::CalculateExtent().

◆ Clip()

G4bool G4ClippablePolygon::Clip ( const G4VoxelLimits & voxelLimit)

Clips the polygon along the Cartesian axes, as specified in 'voxelLimit'.

Returns
true if the collection of vertices is not empty.

Definition at line 60 of file G4ClippablePolygon.cc.

61{
62 if (voxelLimit.IsLimited())
63 {
64 ClipAlongOneAxis( voxelLimit, kXAxis );
65 ClipAlongOneAxis( voxelLimit, kYAxis );
66 ClipAlongOneAxis( voxelLimit, kZAxis );
67 }
68
69 return (!vertices.empty());
70}
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 )

Clips the polygon along just one axis, as specified in 'voxelLimit'.

Definition at line 374 of file G4ClippablePolygon.cc.

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

◆ Empty()

G4bool G4ClippablePolygon::Empty ( ) const
inline

Returns true if collection of vertices is empty.

Referenced by BehindOf(), and InFrontOf().

◆ GetExtent()

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

Computes the polygon extent along the specified 'axis'.

Parameters
[in]axisThe Cartesian axis along which computing the extent.
[out]minThe minimum extent value.
[out]maxThe maximum extent value.
Returns
false if invalid polygon (no vertices).

Definition at line 91 of file G4ClippablePolygon.cc.

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

◆ GetMaxPoint()

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

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

Returns a pointer to the minimum or maximum point along specified 'axis'. Take care! Do not use pointer after destroying parent polygon.

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

Accessor and setter for normal vector.

Referenced by BehindOf(), and InFrontOf().

◆ GetNumVertices()

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

Returns the number of vertices in the polygon.

◆ GetPlanerExtent()

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

Gets min/max vertices distance in or out of a plane.

Parameters
[in]pointOnPlaneThe point on the plane.
[in]planeNormalThe normal vector to the plane.
[out]minThe minimum distance from the plane.
[out]maxThe maximum distance from the plane.
Returns
false if invalid polygon (no vertices).

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 {
359 min = component;
360 }
361 else if (component > max )
362 {
363 max = component;
364 }
365 }
366
367 return true;
368}
double dot(const Hep3Vector &) const

Referenced by BehindOf(), and InFrontOf().

◆ InFrontOf()

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

Decides if the polygon is in "front" of another when viewed along the specified 'axis'. For our purposes here, it is sufficient to use the minimum extent of the polygon along the axis to determine this.

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}
const G4ThreeVector * GetMinPoint(const EAxis axis) const

Referenced by G4SolidExtentList::AddSurface().

◆ PartialClip()

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

Clips the polygon while ignoring the indicated axis.

Returns
true if the collection of vertices is not empty.

Definition at line 76 of file G4ClippablePolygon.cc.

78{
79 if (voxelLimit.IsLimited())
80 {
81 if (IgnoreMe != kXAxis) { ClipAlongOneAxis( voxelLimit, kXAxis ); }
82 if (IgnoreMe != kYAxis) { ClipAlongOneAxis( voxelLimit, kYAxis ); }
83 if (IgnoreMe != kZAxis) { ClipAlongOneAxis( voxelLimit, kZAxis ); }
84 }
85
86 return (!vertices.empty());
87}

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

◆ SetNormal()

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

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