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
G4KnotVector.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// G4KnotVector.cc
33//
34// ----------------------------------------------------------------------
35
36#include "G4KnotVector.hh"
38
40 : k_size(0), knots(0)
41{
43}
44
46{
47 k_size=sz;
48 knots = new G4double[k_size];
49 for(G4int a=0;a<k_size;a++)
50 { knots[a]=0; }
52}
53
54
56{
57 delete [] knots;
58}
59
61{
62 delete [] knots;
63 k_size = orig.k_size;
64 knots = new G4double[k_size];
65 for(register G4int a=0; a < orig.k_size; a++)
66 { knots[a] = orig.knots[a]; }
67 kCarTolerance = orig.kCarTolerance;
68}
69
71{
72 if (&right == this) return *this;
73 delete [] knots;
74 k_size = right.k_size;
75 knots = new G4double[k_size];
76 for(register G4int a=0; a < right.k_size; a++)
77 knots[a] = right.knots[a];
78 kCarTolerance = right.kCarTolerance;
79
80 return *this;
81}
82
84{
85 G4int i, knot_index;
86 G4double knt;
87
88 knt = knots[order - 1];
89 if ( k_value < knt )
90 {
91 if (ApxEq( k_value, knt))
92 k_value = knt;
93 else
94 return -1;
95 }
96
97 knt = knots[k_size - order + 1];
98 if ( k_value > knt )
99 {
100 if (ApxEq( k_value, knt))
101 k_value = knt;
102 else
103 return -1;
104 }
105
106 if ( k_value == knots[k_size - order + 1] )
107 knot_index = k_size - order - 1;
108 else if ( k_value == knots[ order - 1] )
109 knot_index = order - 1;
110 else
111 {
112 knot_index = 0;
113
114 for ( i = 0; i < k_size - 1; i++)
115 if((knots[i]<k_value) && (k_value <= knots[i+1]))
116 knot_index = i;
117 }
118
119 return knot_index;
120}
121
122
124 G4double val)
125{
126 G4int n;
127 G4double* knots_to_add;
128
129 n = CheckKnotVector( val );
130 knots_to_add = new G4double[num-n];
131
132 for (G4int i = 0; i < num - n; i++)
133 knots_to_add[i] = val;
134
135 G4KnotVector* new_kv = new G4KnotVector();
136 new_kv->k_size = num - n + GetSize();
137 new_kv->knots = MergeKnotVector(knots_to_add, num-n);
138
139 delete [] knots_to_add;
140
141 return new_kv;
142}
143
144
146 G4int add_size )
147{
148 G4double *newknots;
149 G4int kv1_ptr = 0,
150 kv2_ptr = 0,
151 newptr;
152 G4int old_size = k_size;
153
154 newknots = new G4double[k_size + add_size];
155
156 for ( newptr = 0; newptr < k_size+add_size; newptr++)
157 if ( kv1_ptr >= add_size )
158 newknots[newptr] = knots[kv2_ptr++];
159 else if ( kv2_ptr >= old_size )
160 newknots[newptr] = knots_to_add[kv1_ptr++];
161 else if ( knots_to_add[kv1_ptr] < knots[kv2_ptr])
162 newknots[newptr] = knots_to_add[kv1_ptr++];
163 else
164 newknots[newptr] = knots[kv2_ptr++];
165
166 return newknots;
167}
168
169
171{
172 G4int num = 0;
173
174 for ( G4int i = 0; i < k_size; i++)
175 {
176 // if ( std::abs(val - knots[i]) < kCarTolerance)
177 if ( val == knots[i] )
178 num++;
179 }
180
181 return num;
182}
183
184
186 G4int upper, G4int lower)
187{
188 delete[] kv->knots;
189 kv->k_size = upper-lower;
190 kv->knots = new G4double[kv->k_size];
191
192 for ( G4int i = lower; i < upper; i++)
193 kv->knots[i-lower] = knots[i];
194}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4int GetSize() const
void ExtractKnotVector(G4KnotVector *kv, G4int upper, G4int lower)
G4double * MergeKnotVector(const G4double *knots_to_add, G4int add_size)
G4KnotVector & operator=(const G4KnotVector &right)
Definition: G4KnotVector.cc:70
G4int CheckKnotVector(G4double val) const
G4KnotVector * MultiplyKnotVector(G4int num, G4double value)
G4int GetKnotIndex(G4double k_value, G4int order) const
Definition: G4KnotVector.cc:83