Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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{
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
128/////////////////////////////////////////////////////////////////////////////
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
152////////////////////////////////////////////////////////////////////////////
153
154/*
155void 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}
std::vector< G4Curve * > G4CurveVector
@ FatalException
std::vector< G4Point3D > G4Point3DVector
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
void Init(const G4Point3D &)
G4Point3D GetBoxMin() const
void Extend(const G4Point3D &)
G4Point3D GetBoxMax() const
virtual G4double GetPMax() const
virtual G4Curve * Project(const G4Transform3D &tr=G4Transform3D::Identity)
virtual G4String GetEntityType() const
virtual G4bool Tangent(G4CurvePoint &cp, G4Vector3D &v)
virtual void InitBounded()
virtual G4double GetPPoint(const G4Point3D &p) const
virtual G4Point3D GetPoint(G4double param) const
void Init(const G4CurveVector &segments0)
virtual ~G4CompositeCurve()
virtual G4int IntersectRay2D(const G4Ray &ray)
G4Curve & GetCurve() const
virtual G4int IntersectRay2D(const G4Ray &ray)=0
void SetBounds(G4double p1, G4double p2)
G4BoundingBox3D bBox
Definition: G4Curve.hh:160
virtual G4bool Tangent(G4CurvePoint &cp, G4Vector3D &v)=0
Definition: G4Line.hh:45
void Init(const G4Point3D &pnt0, const G4Vector3D &dir0)
Definition: G4Ray.hh:49
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41