Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ClippablePolygon Class Reference

#include <G4ClippablePolygon.hh>

Collaboration diagram for G4ClippablePolygon:

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 55 of file G4ClippablePolygon.hh.

Constructor & Destructor Documentation

G4ClippablePolygon::G4ClippablePolygon ( )

Definition at line 48 of file G4ClippablePolygon.cc.

49  : normal(0.,0.,0.)
50 {
52 }
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()

Here is the call graph for this function:

G4ClippablePolygon::~G4ClippablePolygon ( )
virtual

Definition at line 58 of file G4ClippablePolygon.cc.

59 {
60 }

Member Function Documentation

void G4ClippablePolygon::AddVertexInOrder ( const G4ThreeVector  vertex)
virtual

Definition at line 66 of file G4ClippablePolygon.cc.

67 {
68  vertices.push_back( vertex );
69 }
G4ThreeVectorList vertices

Here is the caller graph for this function:

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

Definition at line 296 of file G4ClippablePolygon.cc.

298 {
299  //
300  // If things are empty, do something semi-sensible
301  //
302  G4int noLeft = vertices.size();
303  if (noLeft==0) return false;
304 
305  if (other.Empty()) return true;
306 
307  //
308  // Get minimum of other polygon
309  //
310  const G4ThreeVector *maxPointOther = other.GetMaxPoint( axis );
311  const G4double maxOther = maxPointOther->operator()(axis);
312 
313  //
314  // Get minimum of this polygon
315  //
316  const G4ThreeVector *maxPoint = GetMaxPoint( axis );
317  const G4double max = maxPoint->operator()(axis);
318 
319  //
320  // Easy decision
321  //
322  if (max > maxOther+kCarTolerance) return true; // Clear winner
323 
324  if (maxOther > max+kCarTolerance) return false; // Clear loser
325 
326  //
327  // We have a tie (this will not be all that rare since our
328  // polygons are connected)
329  //
330  // Check to see if there is a vertex in the other polygon
331  // that is in front of this one (or vice versa)
332  //
333  G4bool answer;
334  G4ThreeVector normalOther = other.GetNormal();
335 
336  if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
337  {
338  G4double minP, maxP;
339  GetPlanerExtent( *maxPointOther, normalOther, minP, maxP );
340 
341  answer = (normalOther(axis) > 0) ? (maxP > +kCarTolerance)
342  : (minP < -kCarTolerance);
343  }
344  else
345  {
346  G4double minP, maxP;
347  other.GetPlanerExtent( *maxPoint, normal, minP, maxP );
348 
349  answer = (normal(axis) > 0) ? (minP < -kCarTolerance)
350  : (maxP > +kCarTolerance);
351  }
352  return answer;
353 }
virtual G4bool GetPlanerExtent(const G4ThreeVector &pointOnPlane, const G4ThreeVector &planeNormal, G4double &min, G4double &max) const
int G4int
Definition: G4Types.hh:78
const G4ThreeVector GetNormal() const
virtual const G4ThreeVector * GetMaxPoint(const EAxis axis) const
G4ThreeVectorList vertices
bool G4bool
Definition: G4Types.hh:79
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4bool Empty() const
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

void G4ClippablePolygon::ClearAllVertices ( )
virtual

Definition at line 75 of file G4ClippablePolygon.cc.

76 {
77  vertices.clear();
78 }
G4ThreeVectorList vertices

Here is the caller graph for this function:

G4bool G4ClippablePolygon::Clip ( const G4VoxelLimits voxelLimit)
virtual

Definition at line 84 of file G4ClippablePolygon.cc.

85 {
86  if (voxelLimit.IsLimited()) {
87  ClipAlongOneAxis( voxelLimit, kXAxis );
88  ClipAlongOneAxis( voxelLimit, kYAxis );
89  ClipAlongOneAxis( voxelLimit, kZAxis );
90  }
91 
92  return (vertices.size() > 0);
93 }
virtual void ClipAlongOneAxis(const G4VoxelLimits &voxelLimit, const EAxis axis)
G4bool IsLimited() const
G4ThreeVectorList vertices

Here is the call graph for this function:

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

Definition at line 401 of file G4ClippablePolygon.cc.

403 {
404  if (!voxelLimit.IsLimited(axis)) return;
405 
406  G4ThreeVectorList tempPolygon;
407 
408  //
409  // Build a "simple" voxelLimit that includes only the min extent
410  // and apply this to our vertices, producing result in tempPolygon
411  //
412  G4VoxelLimits simpleLimit1;
413  simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity );
414  ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 );
415 
416  //
417  // If nothing is left from the above clip, we might as well return now
418  // (but with an empty vertices)
419  //
420  if (tempPolygon.size() == 0)
421  {
422  vertices.clear();
423  return;
424  }
425 
426  //
427  // Now do the same, but using a "simple" limit that includes only the max
428  // extent. Apply this to out tempPolygon, producing result in vertices.
429  //
430  G4VoxelLimits simpleLimit2;
431  simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) );
432  ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 );
433 
434  //
435  // If nothing is left, return now
436  //
437  if (vertices.size() == 0) return;
438 }
static const G4double kInfinity
Definition: geomdefs.hh:42
void AddLimit(const EAxis pAxis, const G4double pMin, const G4double pMax)
G4bool IsLimited() const
G4ThreeVectorList vertices
std::vector< G4ThreeVector > G4ThreeVectorList
void ClipToSimpleLimits(G4ThreeVectorList &pPolygon, G4ThreeVectorList &outputPolygon, const G4VoxelLimits &pVoxelLimit)
G4double GetMaxExtent(const EAxis pAxis) const
G4double GetMinExtent(const EAxis pAxis) const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 445 of file G4ClippablePolygon.cc.

448 {
449  G4int i;
450  G4int noVertices=pPolygon.size();
451  G4ThreeVector vEnd,vStart;
452 
453  outputPolygon.clear();
454 
455  for (i=0;i<noVertices;i++)
456  {
457  vStart=pPolygon[i];
458  if (i==noVertices-1)
459  {
460  vEnd=pPolygon[0];
461  }
462  else
463  {
464  vEnd=pPolygon[i+1];
465  }
466 
467  if (pVoxelLimit.Inside(vStart))
468  {
469  if (pVoxelLimit.Inside(vEnd))
470  {
471  // vStart and vEnd inside -> output end point
472  //
473  outputPolygon.push_back(vEnd);
474  }
475  else
476  {
477  // vStart inside, vEnd outside -> output crossing point
478  //
479  pVoxelLimit.ClipToLimits(vStart,vEnd);
480  outputPolygon.push_back(vEnd);
481  }
482  }
483  else
484  {
485  if (pVoxelLimit.Inside(vEnd))
486  {
487  // vStart outside, vEnd inside -> output inside section
488  //
489  pVoxelLimit.ClipToLimits(vStart,vEnd);
490  outputPolygon.push_back(vStart);
491  outputPolygon.push_back(vEnd);
492  }
493  else // Both point outside -> no output
494  {
495  }
496  }
497  }
498 }
int G4int
Definition: G4Types.hh:78
G4bool Inside(const G4ThreeVector &pVec) const
G4bool ClipToLimits(G4ThreeVector &pStart, G4ThreeVector &pEnd) const

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4ClippablePolygon::Empty ( ) const
inline

Here is the caller graph for this function:

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

Definition at line 117 of file G4ClippablePolygon.cc.

120 {
121  //
122  // Okay, how many entries do we have?
123  //
124  G4int noLeft = vertices.size();
125 
126  //
127  // Return false if nothing is left
128  //
129  if (noLeft == 0) return false;
130 
131  //
132  // Initialize min and max to our first vertex
133  //
134  min = max = vertices[0].operator()( axis );
135 
136  //
137  // Compare to the rest
138  //
139  G4int i;
140  for( i=1; i<noLeft; i++ )
141  {
142  G4double component = vertices[i].operator()( axis );
143  if (component < min )
144  min = component;
145  else if (component > max )
146  max = component;
147  }
148 
149  return true;
150 }
int G4int
Definition: G4Types.hh:78
G4ThreeVectorList vertices
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

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

Definition at line 190 of file G4ClippablePolygon.cc.

191 {
192  G4int noLeft = vertices.size();
193  if (noLeft==0)
194  G4Exception("G4ClippablePolygon::GetMaxPoint()",
195  "GeomSolids0002", FatalException, "Empty polygon.");
196 
197  const G4ThreeVector *answer = &(vertices[0]);
198  G4double max = answer->operator()(axis);
199 
200  G4int i;
201  for( i=1; i<noLeft; i++ )
202  {
203  G4double component = vertices[i].operator()( axis );
204  if (component > max)
205  {
206  answer = &(vertices[i]);
207  max = component;
208  }
209  }
210 
211  return answer;
212 }
int G4int
Definition: G4Types.hh:78
G4ThreeVectorList vertices
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
T max(const T t1, const T t2)
brief Return the largest of the two arguments
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 159 of file G4ClippablePolygon.cc.

160 {
161  G4int noLeft = vertices.size();
162  if (noLeft==0)
163  G4Exception("G4ClippablePolygon::GetMinPoint()",
164  "GeomSolids0002", FatalException, "Empty polygon.");
165 
166  const G4ThreeVector *answer = &(vertices[0]);
167  G4double min = answer->operator()(axis);
168 
169  G4int i;
170  for( i=1; i<noLeft; i++ )
171  {
172  G4double component = vertices[i].operator()( axis );
173  if (component < min)
174  {
175  answer = &(vertices[i]);
176  min = component;
177  }
178  }
179 
180  return answer;
181 }
int G4int
Definition: G4Types.hh:78
G4ThreeVectorList vertices
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

const G4ThreeVector G4ClippablePolygon::GetNormal ( ) const
inline

Here is the caller graph for this function:

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

Definition at line 361 of file G4ClippablePolygon.cc.

365 {
366  //
367  // Okay, how many entries do we have?
368  //
369  G4int noLeft = vertices.size();
370 
371  //
372  // Return false if nothing is left
373  //
374  if (noLeft == 0) return false;
375 
376  //
377  // Initialize min and max to our first vertex
378  //
379  min = max = planeNormal.dot(vertices[0]-pointOnPlane);
380 
381  //
382  // Compare to the rest
383  //
384  G4int i;
385  for( i=1; i<noLeft; i++ )
386  {
387  G4double component = planeNormal.dot(vertices[i] - pointOnPlane);
388  if (component < min )
389  min = component;
390  else if (component > max )
391  max = component;
392  }
393 
394  return true;
395 }
double dot(const Hep3Vector &) const
int G4int
Definition: G4Types.hh:78
G4ThreeVectorList vertices
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 231 of file G4ClippablePolygon.cc.

233 {
234  //
235  // If things are empty, do something semi-sensible
236  //
237  G4int noLeft = vertices.size();
238  if (noLeft==0) return false;
239 
240  if (other.Empty()) return true;
241 
242  //
243  // Get minimum of other polygon
244  //
245  const G4ThreeVector *minPointOther = other.GetMinPoint( axis );
246  const G4double minOther = minPointOther->operator()(axis);
247 
248  //
249  // Get minimum of this polygon
250  //
251  const G4ThreeVector *minPoint = GetMinPoint( axis );
252  const G4double min = minPoint->operator()(axis);
253 
254  //
255  // Easy decision
256  //
257  if (min < minOther-kCarTolerance) return true; // Clear winner
258 
259  if (minOther < min-kCarTolerance) return false; // Clear loser
260 
261  //
262  // We have a tie (this will not be all that rare since our
263  // polygons are connected)
264  //
265  // Check to see if there is a vertex in the other polygon
266  // that is behind this one (or vice versa)
267  //
268  G4bool answer;
269  G4ThreeVector normalOther = other.GetNormal();
270 
271  if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
272  {
273  G4double minP, maxP;
274  GetPlanerExtent( *minPointOther, normalOther, minP, maxP );
275 
276  answer = (normalOther(axis) > 0) ? (minP < -kCarTolerance)
277  : (maxP > +kCarTolerance);
278  }
279  else
280  {
281  G4double minP, maxP;
282  other.GetPlanerExtent( *minPoint, normal, minP, maxP );
283 
284  answer = (normal(axis) > 0) ? (maxP > +kCarTolerance)
285  : (minP < -kCarTolerance);
286  }
287  return answer;
288 }
virtual G4bool GetPlanerExtent(const G4ThreeVector &pointOnPlane, const G4ThreeVector &planeNormal, G4double &min, G4double &max) const
virtual const G4ThreeVector * GetMinPoint(const EAxis axis) const
int G4int
Definition: G4Types.hh:78
const G4ThreeVector GetNormal() const
G4ThreeVectorList vertices
bool G4bool
Definition: G4Types.hh:79
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4bool Empty() const
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 101 of file G4ClippablePolygon.cc.

103 {
104  if (voxelLimit.IsLimited()) {
105  if (IgnoreMe != kXAxis) ClipAlongOneAxis( voxelLimit, kXAxis );
106  if (IgnoreMe != kYAxis) ClipAlongOneAxis( voxelLimit, kYAxis );
107  if (IgnoreMe != kZAxis) ClipAlongOneAxis( voxelLimit, kZAxis );
108  }
109 
110  return (vertices.size() > 0);
111 }
virtual void ClipAlongOneAxis(const G4VoxelLimits &voxelLimit, const EAxis axis)
G4bool IsLimited() const
G4ThreeVectorList vertices

Here is the call graph for this function:

Here is the caller graph for this function:

void G4ClippablePolygon::SetNormal ( const G4ThreeVector newNormal)
inline

Here is the caller graph for this function:

Member Data Documentation

G4double G4ClippablePolygon::kCarTolerance
protected

Definition at line 123 of file G4ClippablePolygon.hh.

G4ThreeVector G4ClippablePolygon::normal
protected

Definition at line 122 of file G4ClippablePolygon.hh.

G4ThreeVectorList G4ClippablePolygon::vertices
protected

Definition at line 121 of file G4ClippablePolygon.hh.


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