Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SurfaceList.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// G4SurfaceList.cc
33//
34// ----------------------------------------------------------------------
35
36#include "G4SurfaceList.hh"
37
39{
40 first = index = last = next = temp = (G4Surface*)0;
41 number_of_elements=0;
42}
43
44
46{
47 EmptyList();
48}
49
51{
52 if(number_of_elements)
53 {
55 srf->SetNextNode(first);
56 first = srf;
57 index=first;
58 number_of_elements++;
59 }
60}
61
62
64{
65 if(first == (G4Surface*)0)
66 {
67 index = srf;
68 first = srf;
69 last = srf;
70 first->SetNextNode(0);
71 }
72 else
73 {
74 srf->SetNextNode(last->GetNextNode());
75 last->SetNextNode(srf);
76 last = last->GetNextNode();
77 }
78
79 number_of_elements++;
80 index=first;
81}
82
83
85{
86 return index;
87}
88
89
91{
92 index = first;
93 for(G4int a=0;a<number;a++)
94 Step();
95
96 return index;
97}
98
99
101{
102 return last;
103}
104
105
107{
108 if(srf!=(G4Surface*)0)
109 {
110 number_of_elements--;
111 temp = first;
112
113 if(srf == first)
114 {
115 first=first->GetNextNode();
116 index = first;
117 if(number_of_elements == 0)last = first;
118 delete srf;
119 return;
120 }
121 else
122 {
123 while(temp->GetNextNode() != srf) temp = temp->GetNextNode();
124 index = srf->GetNextNode();
125 temp->SetNextNode(index);
126 if(srf == last) last = temp;
127 index = first;
128 delete srf;
129 }
130 }
131}
132
133
135{
136 // Remove the current pointer from the List
137 // Do not delete the object itself
138 if(number_of_elements)
139 {
140 if(first != index)
141 {
142 temp = first;
143
144 // Find previous
145 while(temp->GetNextNode() != index) temp = temp->GetNextNode();
146
147 // Hop over the one to be removed
148 temp->SetNextNode(index->GetNextNode());
149
150 // Correct the index pointer
151 index = temp->GetNextNode();
152 }
153 else
154 {
155 // Hop over the first
156 first = first->GetNextNode();
157 index = first;
158 }
159 }
160
161 number_of_elements--;
162}
163
164
166{
167 //Deletes all surfaces in List
168 while (first != (G4Surface*)0)
169 {
170 temp = first;
171 first = first->GetNextNode();
172 delete temp;
173 number_of_elements--;
174 }
175
176 last = index = first;
177}
178
179
181{
182 index = first;
183}
184
185
187{
188 if(index!=(G4Surface*)0)
189 index = index->GetNextNode();
190}
191
192
194{
195 if(number_of_elements == 1) return;
196
197 // First create a vector of the surface distances
198 // to the ray origin
199 G4Surface** distances = new G4Surface*[number_of_elements];
200 G4int x = 0;
201 MoveToFirst();
202
203 // Copy surface pointers to vector
204 if(number_of_elements > 1)
205 {
206 while(x < number_of_elements)
207 {
208 distances[x] = index;
209 index = index->GetNextNode();
210 x++;
211 }
212
213 MoveToFirst();
214
215 // Sort List of pointers using quick G4Sort
216 QuickG4Sort( distances, 0, number_of_elements-1 );
217
218 // Organize the linked List of surfaces according
219 // to the quickG4Sorted List.
220 x = 0;
221 first = distances[x];
222 last = first;
223 x++;
224
225 while (x < number_of_elements)
226 {
227 last->SetNextNode(distances[x]);
228 last = last->GetNextNode();
229 x++;
230 }
231
232 last->SetNextNode(0);
233 MoveToFirst();
234 }
235
236 delete[] distances;
237}
238
239
241{
242 register G4int i=left;
243 register G4int j=right;
244
245 G4Surface* elem1;
246 G4Surface* elem2 = Dist[(left+right)/2];
247
248 do
249 {
250 while ( (Dist[i]->GetDistance() < elem2->GetDistance()) && (i < right) )
251 i++;
252
253 while ( (elem2->GetDistance() < Dist[j]->GetDistance()) && (j > left))
254 j--;
255
256 if(i<=j)
257 {
258 elem1 = Dist[i];
259 Dist[i] = Dist[j];
260 Dist[j] = elem1;
261 i++;
262 j--;
263 }
264 } while (i<=j);
265
266 if( left < j )
267 QuickG4Sort(Dist, left, j );
268
269 if( i < right )
270 QuickG4Sort(Dist, i, right);
271}
int G4int
Definition: G4Types.hh:66
void QuickG4Sort(G4Surface **, G4int, G4int)
G4Surface * GetSurface()
void AddSurface(G4Surface *srf)
const G4Surface * GetLastSurface() const
void RemoveSurface(G4Surface *srf)
void RemovePointer()
void SetNextNode(G4Surface *)
G4double GetDistance() const
G4Surface * GetNextNode()