Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
G4ReduciblePolygon Class Reference

#include <G4ReduciblePolygon.hh>

Data Structures

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.

References Create().

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)
const G4int n
G4ReduciblePolygon::G4ReduciblePolygon ( const G4double  rmin[],
const G4double  rmax[],
const G4double  z[],
G4int  n 
)

Definition at line 65 of file G4ReduciblePolygon.cc.

References test::a, test::b, Create(), and n.

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)
G4double z
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
const G4int n
double G4double
Definition: G4Types.hh:76
G4ReduciblePolygon::~G4ReduciblePolygon ( )
virtual

Definition at line 149 of file G4ReduciblePolygon.cc.

References curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

150 {
152  while( curr )
153  {
154  ABVertex *toDelete = curr;
155  curr = curr->next;
156  delete toDelete;
157  }
158 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
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.

References aMax.

Referenced by G4EnclosingCylinder::G4EnclosingCylinder(), and G4PolyPhiFace::G4PolyPhiFace().

87 { return aMax; }
G4double G4ReduciblePolygon::Amin ( ) const
inline
G4double G4ReduciblePolygon::Area ( )

Definition at line 556 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4GenericPolycone::Create(), G4Polycone::Create(), and G4Polyhedra::Create().

557 {
558  G4double answer = 0;
559 
560  ABVertex *curr = vertexHead, *next;
561  do
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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
double G4double
Definition: G4Types.hh:76
G4bool G4ReduciblePolygon::BisectedBy ( G4double  a1,
G4double  b1,
G4double  a2,
G4double  b2,
G4double  tolerance 
)

Definition at line 511 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4GenericPolycone::Create(), and G4Polycone::Create().

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 
522  do
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
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
double G4double
Definition: G4Types.hh:76
G4double G4ReduciblePolygon::Bmax ( ) const
inline
G4double G4ReduciblePolygon::Bmin ( ) const
inline

Definition at line 88 of file G4ReduciblePolygon.hh.

References bMin.

Referenced by G4EnclosingCylinder::G4EnclosingCylinder(), and G4PolyPhiFace::G4PolyPhiFace().

88 { return bMin; }
void G4ReduciblePolygon::CalculateMaxMin ( )
protected

Definition at line 594 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, aMax, aMin, G4ReduciblePolygon::ABVertex::b, bMax, bMin, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by Create(), RemoveDuplicateVertices(), and RemoveRedundantVertices().

595 {
597  aMin = aMax = curr->a;
598  bMin = bMax = curr->b;
599  curr = curr->next;
600  while( curr )
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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
void G4ReduciblePolygon::CopyVertices ( G4double  a[],
G4double  b[] 
) const

Definition at line 168 of file G4ReduciblePolygon.cc.

References test::a, G4ReduciblePolygon::ABVertex::a, test::b, G4ReduciblePolygon::ABVertex::b, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

169 {
170  G4double *anext = a, *bnext = b;
172  while( curr )
173  {
174  *anext++ = curr->a;
175  *bnext++ = curr->b;
176  curr = curr->next;
177  }
178 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
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.

References test::a, G4ReduciblePolygon::ABVertex::a, ABVertex, test::b, G4ReduciblePolygon::ABVertex::b, CalculateMaxMin(), FatalErrorInArgument, G4Exception(), n, G4ReduciblePolygon::ABVertex::next, numVertices, and vertexHead.

Referenced by G4ReduciblePolygon().

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
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 }
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
G4bool G4ReduciblePolygon::CrossesItself ( G4double  tolerance)

Definition at line 453 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4GenericPolycone::Create(), G4Polycone::Create(), and G4Polyhedra::Create().

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)
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 )
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
G4int G4ReduciblePolygon::NumVertices ( ) const
inline
void G4ReduciblePolygon::Print ( void  )

Definition at line 577 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, curr(), G4cerr, G4endl, G4ReduciblePolygon::ABVertex::next, and vertexHead.

578 {
580  do
581  {
582  G4cerr << curr->a << " " << curr->b << G4endl;
583  curr = curr->next;
584  } while( curr );
585 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
G4bool G4ReduciblePolygon::RemoveDuplicateVertices ( G4double  tolerance)

Definition at line 219 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, CalculateMaxMin(), curr(), G4ReduciblePolygon::ABVertex::next, numVertices, and vertexHead.

Referenced by G4GenericPolycone::Create(), G4Polycone::Create(), and G4Polyhedra::Create().

220 {
222  *prev = 0, *next = 0;
223  while( curr )
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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
G4bool G4ReduciblePolygon::RemoveRedundantVertices ( G4double  tolerance)

Definition at line 273 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, G4ReduciblePolygon::ABVertex::b, CalculateMaxMin(), curr(), G4ReduciblePolygon::ABVertex::next, numVertices, mcscore::test(), and vertexHead.

Referenced by G4GenericPolycone::Create(), G4Polycone::Create(), and G4Polyhedra::Create().

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 )
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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
def test
Definition: mcscore.py:117
double G4double
Definition: G4Types.hh:76
void G4ReduciblePolygon::ReverseOrder ( )

Definition at line 368 of file G4ReduciblePolygon.cc.

References curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4GenericPolycone::Create(), G4Polycone::Create(), and G4Polyhedra::Create().

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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
void G4ReduciblePolygon::ScaleA ( G4double  scale)

Definition at line 186 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::a, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4Polyhedra::G4Polyhedra().

187 {
189  while( curr )
190  {
191  curr->a *= scale;
192  curr = curr->next;
193  }
194 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
void G4ReduciblePolygon::ScaleB ( G4double  scale)

Definition at line 202 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::b, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

203 {
205  while( curr )
206  {
207  curr->b *= scale;
208  curr = curr->next;
209  }
210 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
void G4ReduciblePolygon::StartWithZMin ( )

Definition at line 421 of file G4ReduciblePolygon.cc.

References G4ReduciblePolygon::ABVertex::b, curr(), G4ReduciblePolygon::ABVertex::next, and vertexHead.

Referenced by G4Polycone::SetOriginalParameters(), and G4Polyhedra::SetOriginalParameters().

422 {
424  G4double bcurr = curr->b;
425  ABVertex *prev = curr;
426  while( curr )
427  {
428  if(curr->b < bcurr)
429  {
430  bcurr = curr->b;
431  ABVertex *curr1 = curr;
432  while( curr1 )
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 }
subroutine curr(MNUM, PIM1, PIM2, PIM3, PIM4, HADCUR)
Definition: leptonew.f:2041
double G4double
Definition: G4Types.hh:76

Friends And Related Function Documentation

friend struct ABVertex
friend

Definition at line 140 of file G4ReduciblePolygon.hh.

Referenced by Create().

friend class G4ReduciblePolygonIterator
friend

Definition at line 63 of file G4ReduciblePolygon.hh.

Field Documentation

G4double G4ReduciblePolygon::aMax
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

Referenced by Amax(), and CalculateMaxMin().

G4double G4ReduciblePolygon::aMin
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

Referenced by Amin(), and CalculateMaxMin().

G4double G4ReduciblePolygon::bMax
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

Referenced by Bmax(), and CalculateMaxMin().

G4double G4ReduciblePolygon::bMin
protected

Definition at line 131 of file G4ReduciblePolygon.hh.

Referenced by Bmin(), and CalculateMaxMin().

G4int G4ReduciblePolygon::numVertices
protected
ABVertex* G4ReduciblePolygon::vertexHead
protected

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