00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4KnotVector.hh"
00037 #include "G4GeometryTolerance.hh"
00038
00039 G4KnotVector::G4KnotVector()
00040 : k_size(0), knots(0)
00041 {
00042 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00043 }
00044
00045 G4KnotVector::G4KnotVector(G4int sz)
00046 {
00047 k_size=sz;
00048 knots = new G4double[k_size];
00049 for(G4int a=0;a<k_size;a++)
00050 { knots[a]=0; }
00051 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00052 }
00053
00054
00055 G4KnotVector::~G4KnotVector()
00056 {
00057 delete [] knots;
00058 }
00059
00060 G4KnotVector::G4KnotVector(const G4KnotVector& orig)
00061 {
00062 delete [] knots;
00063 k_size = orig.k_size;
00064 knots = new G4double[k_size];
00065 for(register G4int a=0; a < orig.k_size; a++)
00066 { knots[a] = orig.knots[a]; }
00067 kCarTolerance = orig.kCarTolerance;
00068 }
00069
00070 G4KnotVector& G4KnotVector::operator=(const G4KnotVector& right)
00071 {
00072 if (&right == this) return *this;
00073 delete [] knots;
00074 k_size = right.k_size;
00075 knots = new G4double[k_size];
00076 for(register G4int a=0; a < right.k_size; a++)
00077 knots[a] = right.knots[a];
00078 kCarTolerance = right.kCarTolerance;
00079
00080 return *this;
00081 }
00082
00083 G4int G4KnotVector::GetKnotIndex(G4double k_value, G4int order) const
00084 {
00085 G4int i, knot_index;
00086 G4double knt;
00087
00088 knt = knots[order - 1];
00089 if ( k_value < knt )
00090 {
00091 if (ApxEq( k_value, knt))
00092 k_value = knt;
00093 else
00094 return -1;
00095 }
00096
00097 knt = knots[k_size - order + 1];
00098 if ( k_value > knt )
00099 {
00100 if (ApxEq( k_value, knt))
00101 k_value = knt;
00102 else
00103 return -1;
00104 }
00105
00106 if ( k_value == knots[k_size - order + 1] )
00107 knot_index = k_size - order - 1;
00108 else if ( k_value == knots[ order - 1] )
00109 knot_index = order - 1;
00110 else
00111 {
00112 knot_index = 0;
00113
00114 for ( i = 0; i < k_size - 1; i++)
00115 if((knots[i]<k_value) && (k_value <= knots[i+1]))
00116 knot_index = i;
00117 }
00118
00119 return knot_index;
00120 }
00121
00122
00123 G4KnotVector* G4KnotVector::MultiplyKnotVector(G4int num,
00124 G4double val)
00125 {
00126 G4int n;
00127 G4double* knots_to_add;
00128
00129 n = CheckKnotVector( val );
00130 knots_to_add = new G4double[num-n];
00131
00132 for (G4int i = 0; i < num - n; i++)
00133 knots_to_add[i] = val;
00134
00135 G4KnotVector* new_kv = new G4KnotVector();
00136 new_kv->k_size = num - n + GetSize();
00137 new_kv->knots = MergeKnotVector(knots_to_add, num-n);
00138
00139 delete [] knots_to_add;
00140
00141 return new_kv;
00142 }
00143
00144
00145 G4double* G4KnotVector::MergeKnotVector(const G4double* knots_to_add,
00146 G4int add_size )
00147 {
00148 G4double *newknots;
00149 G4int kv1_ptr = 0,
00150 kv2_ptr = 0,
00151 newptr;
00152 G4int old_size = k_size;
00153
00154 newknots = new G4double[k_size + add_size];
00155
00156 for ( newptr = 0; newptr < k_size+add_size; newptr++)
00157 if ( kv1_ptr >= add_size )
00158 newknots[newptr] = knots[kv2_ptr++];
00159 else if ( kv2_ptr >= old_size )
00160 newknots[newptr] = knots_to_add[kv1_ptr++];
00161 else if ( knots_to_add[kv1_ptr] < knots[kv2_ptr])
00162 newknots[newptr] = knots_to_add[kv1_ptr++];
00163 else
00164 newknots[newptr] = knots[kv2_ptr++];
00165
00166 return newknots;
00167 }
00168
00169
00170 G4int G4KnotVector::CheckKnotVector(G4double val) const
00171 {
00172 G4int num = 0;
00173
00174 for ( G4int i = 0; i < k_size; i++)
00175 {
00176
00177 if ( val == knots[i] )
00178 num++;
00179 }
00180
00181 return num;
00182 }
00183
00184
00185 void G4KnotVector::ExtractKnotVector( G4KnotVector* kv,
00186 G4int upper, G4int lower)
00187 {
00188 delete[] kv->knots;
00189 kv->k_size = upper-lower;
00190 kv->knots = new G4double[kv->k_size];
00191
00192 for ( G4int i = lower; i < upper; i++)
00193 kv->knots[i-lower] = knots[i];
00194 }