Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ReduciblePolygon Class Reference

#include <G4ReduciblePolygon.hh>

Collaboration diagram for G4ReduciblePolygon:

Classes

struct  ABVertex
 

Public Member Functions

 G4ReduciblePolygon (const G4double a[], const G4double b[], G4int n)
 
 G4ReduciblePolygon (const G4double rmin[], const G4double rmax[], const G4double z[], G4int n)
 
virtual ~G4ReduciblePolygon ()
 
G4int NumVertices () const
 
G4double Amin () const
 
G4double Amax () const
 
G4double Bmin () const
 
G4double Bmax () const
 
void CopyVertices (G4double a[], G4double b[]) const
 
void ScaleA (G4double scale)
 
void ScaleB (G4double scale)
 
G4bool RemoveDuplicateVertices (G4double tolerance)
 
G4bool RemoveRedundantVertices (G4double tolerance)
 
void ReverseOrder ()
 
void StartWithZMin ()
 
G4double Area ()
 
G4bool CrossesItself (G4double tolerance)
 
G4bool BisectedBy (G4double a1, G4double b1, G4double a2, G4double b2, G4double tolerance)
 
void Print ()
 
 G4ReduciblePolygon (__void__ &)
 

Protected Member Functions

void Create (const G4double a[], const G4double b[], G4int n)
 
void CalculateMaxMin ()
 

Protected Attributes

G4double aMin
 
G4double aMax
 
G4double bMin
 
G4double bMax
 
G4int numVertices
 
ABVertexvertexHead
 

Friends

class G4ReduciblePolygonIterator
 
struct ABVertex
 

Detailed Description

Definition at line 61 of file G4ReduciblePolygon.hh.

Constructor & Destructor Documentation

G4ReduciblePolygon::G4ReduciblePolygon ( const G4double  a[],
const G4double  b[],
G4int  n 
)

Definition at line 49 of file G4ReduciblePolygon.cc.

52  : aMin(0.), aMax(0.), bMin(0.), bMax(0.),
53  vertexHead(0)
54 {
55  //
56  // Do all of the real work in Create
57  //
58  Create( a, b, n );
59 }
void Create(const G4double a[], const G4double b[], G4int n)
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
tuple b
Definition: test.py:12
const G4int n

Here is the call graph for this function:

G4ReduciblePolygon::G4ReduciblePolygon ( const G4double  rmin[],
const G4double  rmax[],
const G4double  z[],
G4int  n 
)

Definition at line 65 of file G4ReduciblePolygon.cc.

68  : aMin(0.), aMax(0.), bMin(0.), bMax(0.),
69  vertexHead(0)
70 {
71  //
72  // Translate
73  //
74  G4double *a = new G4double[n*2];
75  G4double *b = new G4double[n*2];
76 
77  G4double *rOut = a + n,
78  *zOut = b + n,
79  *rIn = rOut-1,
80  *zIn = zOut-1;
81 
82  G4int i;
83  for( i=0; i < n; i++, rOut++, zOut++, rIn--, zIn-- )
84  {
85  *rOut = rmax[i];
86  *rIn = rmin[i];
87  *zOut = *zIn = z[i];
88  }
89 
90  Create( a, b, n*2 );
91 
92  delete [] a;
93  delete [] b;
94 }
void Create(const G4double a[], const G4double b[], G4int n)
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
int G4int
Definition: G4Types.hh:78
tuple b
Definition: test.py:12
const G4int n
tuple z
Definition: test.py:28
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4ReduciblePolygon::~G4ReduciblePolygon ( )
virtual

Definition at line 149 of file G4ReduciblePolygon.cc.

150 {
151  ABVertex *curr = vertexHead;
152  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
153  {
154  ABVertex *toDelete = curr;
155  curr = curr->next;
156  delete toDelete;
157  }
158 }
G4ReduciblePolygon::G4ReduciblePolygon ( __void__ &  )

Definition at line 140 of file G4ReduciblePolygon.cc.

Member Function Documentation

G4double G4ReduciblePolygon::Amax ( ) const
inline

Definition at line 87 of file G4ReduciblePolygon.hh.

87 { return aMax; }

Here is the caller graph for this function:

G4double G4ReduciblePolygon::Amin ( ) const
inline

Definition at line 86 of file G4ReduciblePolygon.hh.

86 { return aMin; }

Here is the caller graph for this function:

G4double G4ReduciblePolygon::Area ( )

Definition at line 556 of file G4ReduciblePolygon.cc.

557 {
558  G4double answer = 0;
559 
560  ABVertex *curr = vertexHead, *next;
561  do // Loop checking, 13.08.2015, G.Cosmo
562  {
563  next = curr->next;
564  if (next==0) next = vertexHead;
565 
566  answer += curr->a*next->b - curr->b*next->a;
567  curr = curr->next;
568  } while( curr );
569 
570  return 0.5*answer;
571 }
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

G4bool G4ReduciblePolygon::BisectedBy ( G4double  a1,
G4double  b1,
G4double  a2,
G4double  b2,
G4double  tolerance 
)

Definition at line 511 of file G4ReduciblePolygon.cc.

514 {
515  G4int nNeg = 0, nPos = 0;
516 
517  G4double a12 = a2-a1, b12 = b2-b1;
518  G4double len12 = std::sqrt( a12*a12 + b12*b12 );
519  a12 /= len12; b12 /= len12;
520 
521  ABVertex *curr = vertexHead;
522  do // Loop checking, 13.08.2015, G.Cosmo
523  {
524  G4double av = curr->a - a1,
525  bv = curr->b - b1;
526 
527  G4double cross = av*b12 - bv*a12;
528 
529  if (cross < -tolerance)
530  {
531  if (nPos) return true;
532  nNeg++;
533  }
534  else if (cross > tolerance)
535  {
536  if (nNeg) return true;
537  nPos++;
538  }
539  curr = curr->next;
540  } while( curr );
541 
542  return false;
543 }
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

G4double G4ReduciblePolygon::Bmax ( ) const
inline

Definition at line 89 of file G4ReduciblePolygon.hh.

89 { return bMax; }

Here is the caller graph for this function:

G4double G4ReduciblePolygon::Bmin ( ) const
inline

Definition at line 88 of file G4ReduciblePolygon.hh.

88 { return bMin; }

Here is the caller graph for this function:

void G4ReduciblePolygon::CalculateMaxMin ( )
protected

Definition at line 594 of file G4ReduciblePolygon.cc.

595 {
596  ABVertex *curr = vertexHead;
597  aMin = aMax = curr->a;
598  bMin = bMax = curr->b;
599  curr = curr->next;
600  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
601  {
602  if (curr->a < aMin)
603  aMin = curr->a;
604  else if (curr->a > aMax)
605  aMax = curr->a;
606 
607  if (curr->b < bMin)
608  bMin = curr->b;
609  else if (curr->b > bMax)
610  bMax = curr->b;
611 
612  curr = curr->next;
613  }
614 }

Here is the caller graph for this function:

void G4ReduciblePolygon::CopyVertices ( G4double  a[],
G4double  b[] 
) const

Definition at line 168 of file G4ReduciblePolygon.cc.

169 {
170  G4double *anext = a, *bnext = b;
171  ABVertex *curr = vertexHead;
172  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
173  {
174  *anext++ = curr->a;
175  *bnext++ = curr->b;
176  curr = curr->next;
177  }
178 }
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
tuple b
Definition: test.py:12
double G4double
Definition: G4Types.hh:76
void G4ReduciblePolygon::Create ( const G4double  a[],
const G4double  b[],
G4int  n 
)
protected

Definition at line 103 of file G4ReduciblePolygon.cc.

105 {
106  if (n<3)
107  G4Exception("G4ReduciblePolygon::Create()", "GeomSolids0002",
108  FatalErrorInArgument, "Less than 3 vertices specified.");
109 
110  const G4double *anext = a, *bnext = b;
111  ABVertex *prev = 0;
112  do // Loop checking, 13.08.2015, G.Cosmo
113  {
114  ABVertex *newVertex = new ABVertex;
115  newVertex->a = *anext;
116  newVertex->b = *bnext;
117  newVertex->next = 0;
118  if (prev==0)
119  {
120  vertexHead = newVertex;
121  }
122  else
123  {
124  prev->next = newVertex;
125  }
126 
127  prev = newVertex;
128  } while( ++anext, ++bnext < b+n );
129 
130  numVertices = n;
131 
132  CalculateMaxMin();
133 }
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
tuple b
Definition: test.py:12
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4ReduciblePolygon::CrossesItself ( G4double  tolerance)

Definition at line 453 of file G4ReduciblePolygon.cc.

454 {
455  G4double tolerance2 = tolerance*tolerance;
456  G4double one = 1.0-tolerance,
457  zero = tolerance;
458  //
459  // Top loop over line segments. By the time we finish
460  // with the second to last segment, we're done.
461  //
462  ABVertex *curr1 = vertexHead, *next1=0;
463  while (curr1->next) // Loop checking, 13.08.2015, G.Cosmo
464  {
465  next1 = curr1->next;
466  G4double da1 = next1->a-curr1->a,
467  db1 = next1->b-curr1->b;
468 
469  //
470  // Inner loop over subsequent line segments
471  //
472  ABVertex *curr2 = next1->next;
473  while( curr2 ) // Loop checking, 13.08.2015, G.Cosmo
474  {
475  ABVertex *next2 = curr2->next;
476  if (next2==0) next2 = vertexHead;
477  G4double da2 = next2->a-curr2->a,
478  db2 = next2->b-curr2->b;
479  G4double a12 = curr2->a-curr1->a,
480  b12 = curr2->b-curr1->b;
481 
482  //
483  // Calculate intersection of the two lines
484  //
485  G4double deter = da1*db2 - db1*da2;
486  if (std::fabs(deter) > tolerance2)
487  {
488  G4double s1, s2;
489  s1 = (a12*db2-b12*da2)/deter;
490 
491  if (s1 >= zero && s1 < one)
492  {
493  s2 = -(da1*b12-db1*a12)/deter;
494  if (s2 >= zero && s2 < one) return true;
495  }
496  }
497  curr2 = curr2->next;
498  }
499  curr1 = next1;
500  }
501  return false;
502 }
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

G4int G4ReduciblePolygon::NumVertices ( ) const
inline

Definition at line 84 of file G4ReduciblePolygon.hh.

84 { return numVertices; }

Here is the caller graph for this function:

void G4ReduciblePolygon::Print ( void  )

Definition at line 577 of file G4ReduciblePolygon.cc.

578 {
579  ABVertex *curr = vertexHead;
580  do // Loop checking, 13.08.2015, G.Cosmo
581  {
582  G4cerr << curr->a << " " << curr->b << G4endl;
583  curr = curr->next;
584  } while( curr );
585 }
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
G4bool G4ReduciblePolygon::RemoveDuplicateVertices ( G4double  tolerance)

Definition at line 219 of file G4ReduciblePolygon.cc.

220 {
221  ABVertex *curr = vertexHead,
222  *prev = 0, *next = 0;
223  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
224  {
225  next = curr->next;
226  if (next == 0) next = vertexHead;
227 
228  if (std::fabs(curr->a-next->a) < tolerance &&
229  std::fabs(curr->b-next->b) < tolerance )
230  {
231  //
232  // Duplicate found: do we have > 3 vertices?
233  //
234  if (numVertices <= 3)
235  {
236  CalculateMaxMin();
237  return false;
238  }
239 
240  //
241  // Delete
242  //
243  ABVertex *toDelete = curr;
244  curr = curr->next;
245  delete toDelete;
246 
247  numVertices--;
248 
249  if (prev) prev->next = curr; else vertexHead = curr;
250  }
251  else
252  {
253  prev = curr;
254  curr = curr->next;
255  }
256  }
257 
258  //
259  // In principle, this is not needed, but why not just play it safe?
260  //
261  CalculateMaxMin();
262 
263  return true;
264 }

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4ReduciblePolygon::RemoveRedundantVertices ( G4double  tolerance)

Definition at line 273 of file G4ReduciblePolygon.cc.

274 {
275  //
276  // Under these circumstances, we can quit now!
277  //
278  if (numVertices <= 2) return false;
279 
280  G4double tolerance2 = tolerance*tolerance;
281 
282  //
283  // Loop over all vertices
284  //
285  ABVertex *curr = vertexHead, *next = 0;
286  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
287  {
288  next = curr->next;
289  if (next == 0) next = vertexHead;
290 
291  G4double da = next->a - curr->a,
292  db = next->b - curr->b;
293 
294  //
295  // Loop over all subsequent vertices, up to curr
296  //
297  for(;;)
298  {
299  //
300  // Get vertex after next
301  //
302  ABVertex *test = next->next;
303  if (test == 0) test = vertexHead;
304 
305  //
306  // If we are back to the original vertex, stop
307  //
308  if (test==curr) break;
309 
310  //
311  // Test for parallel line segments
312  //
313  G4double dat = test->a - curr->a,
314  dbt = test->b - curr->b;
315 
316  if (std::fabs(dat*db-dbt*da)>tolerance2) break;
317 
318  //
319  // Redundant vertex found: do we have > 3 vertices?
320  //
321  if (numVertices <= 3)
322  {
323  CalculateMaxMin();
324  return false;
325  }
326 
327  //
328  // Delete vertex pointed to by next. Carefully!
329  //
330  if (curr->next)
331  { // next is not head
332  if (next->next)
333  curr->next = test; // next is not tail
334  else
335  curr->next = 0; // New tail
336  }
337  else
338  vertexHead = test; // New head
339 
340  if ((curr != next) && (next != test)) delete next;
341 
342  numVertices--;
343 
344  //
345  // Replace next by the vertex we just tested,
346  // and keep on going...
347  //
348  next = test;
349  da = dat; db = dbt;
350  }
351  curr = curr->next;
352  }
353 
354  //
355  // In principle, this is not needed, but why not just play it safe?
356  //
357  CalculateMaxMin();
358 
359  return true;
360 }
double G4double
Definition: G4Types.hh:76
program test
Definition: Main_HIJING.f:1

Here is the call graph for this function:

Here is the caller graph for this function:

void G4ReduciblePolygon::ReverseOrder ( )

Definition at line 368 of file G4ReduciblePolygon.cc.

369 {
370  //
371  // Loop over all vertices
372  //
373  ABVertex *prev = vertexHead;
374  if (prev==0) return; // No vertices
375 
376  ABVertex *curr = prev->next;
377  if (curr==0) return; // Just one vertex
378 
379  //
380  // Our new tail
381  //
382  vertexHead->next = 0;
383 
384  for(;;)
385  {
386  //
387  // Save pointer to next vertex (in original order)
388  //
389  ABVertex *save = curr->next;
390 
391  //
392  // Replace it with a pointer to the previous one
393  // (in original order)
394  //
395  curr->next = prev;
396 
397  //
398  // Last vertex?
399  //
400  if (save == 0) break;
401 
402  //
403  // Next vertex
404  //
405  prev = curr;
406  curr = save;
407  }
408 
409  //
410  // Our new head
411  //
412  vertexHead = curr;
413 }

Here is the caller graph for this function:

void G4ReduciblePolygon::ScaleA ( G4double  scale)

Definition at line 186 of file G4ReduciblePolygon.cc.

187 {
188  ABVertex *curr = vertexHead;
189  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
190  {
191  curr->a *= scale;
192  curr = curr->next;
193  }
194 }

Here is the caller graph for this function:

void G4ReduciblePolygon::ScaleB ( G4double  scale)

Definition at line 202 of file G4ReduciblePolygon.cc.

203 {
204  ABVertex *curr = vertexHead;
205  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
206  {
207  curr->b *= scale;
208  curr = curr->next;
209  }
210 }
void G4ReduciblePolygon::StartWithZMin ( )

Definition at line 421 of file G4ReduciblePolygon.cc.

422 {
423  ABVertex *curr = vertexHead;
424  G4double bcurr = curr->b;
425  ABVertex *prev = curr;
426  while( curr ) // Loop checking, 13.08.2015, G.Cosmo
427  {
428  if(curr->b < bcurr)
429  {
430  bcurr = curr->b;
431  ABVertex *curr1 = curr;
432  while( curr1 ) // Loop checking, 13.08.2015, G.Cosmo
433  {
434  if(curr1->next == 0) { curr1->next = vertexHead; break; }
435  curr1 = curr1->next;
436  }
437  vertexHead = curr;
438  prev->next = 0;
439  }
440  prev = curr;
441  curr = curr->next;
442  }
443 }
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

Friends And Related Function Documentation

friend struct ABVertex
friend

Definition at line 140 of file G4ReduciblePolygon.hh.

friend class G4ReduciblePolygonIterator
friend

Definition at line 63 of file G4ReduciblePolygon.hh.

Member Data Documentation

G4double G4ReduciblePolygon::aMax
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

G4double G4ReduciblePolygon::aMin
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

G4double G4ReduciblePolygon::bMax
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

G4double G4ReduciblePolygon::bMin
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

G4int G4ReduciblePolygon::numVertices
protected

Definition at line 132 of file G4ReduciblePolygon.hh.

ABVertex* G4ReduciblePolygon::vertexHead
protected

Definition at line 149 of file G4ReduciblePolygon.hh.


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