Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CompositeCurve.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id$
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4CircularCurve.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4CompositeCurve.hh"
37 #include "G4Line.hh"
38 
39 
41 
43 {
44  G4CurveVector cv;
45  for (size_t i=0; i<vertices.size(); i++)
46  {
47  G4Point3D p1= vertices[i];
48  G4Point3D p2= vertices[(i+1) % vertices.size()];
49 
50  G4Line* l= new G4Line;
51  l->Init(p1, p2-p1);
52  l->SetBounds(p1, p2);
53  cv.push_back(l);
54  }
55 
56  Init(cv);
57 }
58 
60 {
61  // Remove segments and delete all its contents
62 
63  G4Curve* a = 0;
64  while (segments.size()>0)
65  {
66  a = segments.back();
67  segments.pop_back();
68  for (G4CurveVector::iterator i=segments.begin(); i!=segments.end();)
69  {
70  if (*i==a)
71  {
72  i = segments.erase(i);
73  }
74  else
75  {
76  ++i;
77  }
78  }
79  delete a;
80  }
81 }
82 
84 {
85  return G4String("G4CompositeCurve");
86 }
87 
89 {
90  G4CurveVector newSegments;
91  G4Curve* a = 0;
92  G4Curve* c = 0;
93 
94  for (size_t i=0; i<segments.size(); i++)
95  {
96  c = segments[i]->Project(tr);
97  if (c==0)
98  {
99  // Remove newSegments and delete all its contents
100  while (newSegments.size()>0)
101  {
102  a = newSegments.back();
103  newSegments.pop_back();
104  for (G4CurveVector::iterator it=newSegments.begin();
105  it!=newSegments.end();)
106  {
107  if (*it==a)
108  {
109  it = newSegments.erase(it);
110  }
111  else
112  {
113  ++it;
114  }
115  }
116  delete a;
117  }
118  return 0;
119  }
120  newSegments.push_back(c);
121  }
122 
124  r->Init(newSegments);
125  return r;
126 }
127 
129 
131 {
132  G4Exception("G4CompositeCurve::GetPMax()", "GeomSolids0002",
133  FatalException, "Not applicable to base class.");
134  return 0;
135 }
136 
138 {
139  G4Exception("G4CompositeCurve::GetPoint()", "GeomSolids0002",
140  FatalException, "Not applicable to base class.");
141  // Fake return value
142  return G4Point3D();
143 }
144 
146 {
147  G4Exception("G4CompositeCurve::GetPPoint()", "GeomSolids0002",
148  FatalException, "Not applicable to base class.");
149  return 0;
150 }
151 
153 
154 /*
155 void G4CompositeCurve::IntersectRay2D(const G4Ray& ray,
156  G4CurveRayIntersection& is)
157 {
158  is.Reset();
159 
160  for (G4int i=0; i<segments.entries(); i++)
161  {
162  G4Curve& c= *(segments(i));
163  G4CurveRayIntersection isTmp(c, ray);
164  c.IntersectRay2D(ray, isTmp);
165  if (isTmp.GetDistance() < is.GetDistance())
166  is= isTmp;
167  }
168 
169  lastIntersection= is;
170 }
171 */
172 
174 {
175  G4int nbinter = 0;
176  G4int temp = 0;
177 
178  for (size_t i=0; i<segments.size(); i++)
179  {
180  G4Curve& c= *(segments[i]);
181  temp = c.IntersectRay2D(ray);
182 
183  // test if the point is on the composite curve
184  if( temp == 999 )
185  return 999;
186  else
187  nbinter+= temp;
188  }
189 
190  return nbinter;
191 }
192 
194 {
195  if (lastIntersection.GetDistance() == kInfinity)
196  return false;
197 
198  return lastIntersection.GetCurve().Tangent(lastIntersection, v);
199  // should be true
200  // cp is ignored for the moment
201 }
202 
203 
205 {
206  const G4BoundingBox3D* b= segments[0]->BBox();
207  bBox.Init(b->GetBoxMin(), b->GetBoxMax());
208 
209  for (size_t i=1; i<segments.size(); i++)
210  {
211  b= segments[i]->BBox();
212  bBox.Extend(b->GetBoxMin());
213  bBox.Extend(b->GetBoxMax());
214  }
215 
216  // init for efficient parameter <-> 3D point conversions
217 }