00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021
00022 #include <iostream>
00023
00024 #include "gul_types.h"
00025 #include "gul_vector.h"
00026 #include "gunu_basics.h"
00027
00028
00029 namespace gunu {
00030
00031 using gul::hpoint;
00032 using gul::point;
00033 using gul::hpoint1;
00034 using gul::point1;
00035 using gul::set;
00036 using gul::euclid;
00037
00038
00039
00040
00041
00042 template< class T >
00043 void CalcGrevilleAbcissa( int n, int p, const Ptr<T>& U, Ptr<T>& G )
00044 {
00045
00046 T p_1,sum;
00047 int i,j;
00048
00049 p_1 = (T)1/(T)p;
00050
00051 for( i = 0; i <= n; i++ )
00052 {
00053 sum = (T)0;
00054 for( j = i+1; j <= i+p; j++ )
00055 sum += U[j];
00056
00057 G[i] = p_1 * sum;
00058 }
00059 }
00060
00061 template void CalcGrevilleAbcissa(
00062 int n, int p, const Ptr<float>& U, Ptr<float>& G );
00063 template void CalcGrevilleAbcissa(
00064 int n, int p, const Ptr<double>& U, Ptr<double>& G );
00065
00066
00067
00068
00069
00070 template< class T >
00071 GULAPI void EqualSpacedParameters( int n, T u1, T u2, Ptr<T>& U )
00072 {
00073 T d;
00074 int i;
00075
00076 gul::Assert<gul::Error>( gul::ndebug || (n >= 2) );
00077
00078 d = (u2-u1)/((T)(n-1));
00079
00080 U[0] = u1;
00081 U[n-1] = u2;
00082
00083 for( i = 1; i < n-1; i++ )
00084 U[i] = u1 + i*d;
00085 }
00086
00087 template GULAPI void EqualSpacedParameters(
00088 int n, float u1, float u2, Ptr<float>& U );
00089 template GULAPI void EqualSpacedParameters(
00090 int n, double u1, double u2, Ptr<double>& U );
00091
00092
00093
00094
00095
00096
00097 template< class T, class HP, class EP >
00098 void CalcSurfaceMesh( int nu, int pu, const Ptr<T>& U,
00099 int nv, int pv, const Ptr<T>& V,
00100 const Ptr< Ptr<HP> >& Pw,
00101 int nSampU, const Ptr<T>& sampU,
00102 int nSampV, const Ptr<T>& sampV,
00103 Ptr< Ptr<EP> >& sampP )
00104 {
00105 Ptr<T> ubase;
00106 Ptr< Ptr<T> > vbase;
00107 T u, v;
00108 int spanu, spanv, i, j, uind, vind, l, k;
00109 HP S, temp;
00110
00111 ubase.reserve_pool(pu+1);
00112
00113 vbase.reserve_pool(nSampV);
00114 for( i = 0; i < nSampV; i++ )
00115 vbase[i].reserve_pool(pv+1);
00116
00117 spanu = -1;
00118
00119 for( i = 0; i < nSampU; i++ )
00120 {
00121 u = sampU[i];
00122
00123 while( (spanu < nu) && (u >= U[spanu+1]) )
00124 spanu++;
00125
00126 CalcBasisFunctions( u, spanu, pu, U, ubase );
00127
00128 spanv = -1;
00129
00130 for( j = 0; j < nSampV; j++ )
00131 {
00132 v = sampV[j];
00133
00134 while( (spanv < nv) && (v >= V[spanv+1]) )
00135 spanv++;
00136
00137 if( i == 0 )
00138 CalcBasisFunctions( v, spanv, pv, V, vbase[j] );
00139
00140
00141
00142 uind = spanu-pu;
00143 set( S, (T)0 );
00144
00145 for( l = 0; l <= pv; l++ )
00146 {
00147 set( temp, (T)0 );
00148
00149 vind = spanv - pv + l;
00150
00151 for( k = 0; k <= pu; k++ )
00152 temp += ubase[k]*Pw[vind][uind+k];
00153
00154 S += vbase[j][l]*temp;
00155 }
00156 sampP[j][i] = euclid( S );
00157 }
00158 }
00159 }
00160
00161 template void CalcSurfaceMesh(
00162 int nu, int pu, const Ptr<float>& U,
00163 int nv, int pv, const Ptr<float>& V,
00164 const Ptr< Ptr< hpoint<float> > >& Pw,
00165 int nSampU, const Ptr<float>& sampU,
00166 int nSampV, const Ptr<float>& sampV,
00167 Ptr< Ptr< point<float> > >& sampP );
00168 template void CalcSurfaceMesh(
00169 int nu, int pu, const Ptr<float>& U,
00170 int nv, int pv, const Ptr<float>& V,
00171 const Ptr< Ptr< hpoint1<float> > >& Pw,
00172 int nSampU, const Ptr<float>& sampU,
00173 int nSampV, const Ptr<float>& sampV,
00174 Ptr< Ptr< point1<float> > >& sampP );
00175 template void CalcSurfaceMesh(
00176 int nu, int pu, const Ptr<float>& U,
00177 int nv, int pv, const Ptr<float>& V,
00178 const Ptr< Ptr< point<float> > >& Pw,
00179 int nSampU, const Ptr<float>& sampU,
00180 int nSampV, const Ptr<float>& sampV,
00181 Ptr< Ptr< point<float> > >& sampP );
00182 template void CalcSurfaceMesh(
00183 int nu, int pu, const Ptr<float>& U,
00184 int nv, int pv, const Ptr<float>& V,
00185 const Ptr< Ptr< point1<float> > >& Pw,
00186 int nSampU, const Ptr<float>& sampU,
00187 int nSampV, const Ptr<float>& sampV,
00188 Ptr< Ptr< point1<float> > >& sampP );
00189
00190
00191 template void CalcSurfaceMesh(
00192 int nu, int pu, const Ptr<double>& U,
00193 int nv, int pv, const Ptr<double>& V,
00194 const Ptr< Ptr< hpoint<double> > >& Pw,
00195 int nSampU, const Ptr<double>& sampU,
00196 int nSampV, const Ptr<double>& sampV,
00197 Ptr< Ptr< point<double> > >& sampP );
00198 template void CalcSurfaceMesh(
00199 int nu, int pu, const Ptr<double>& U,
00200 int nv, int pv, const Ptr<double>& V,
00201 const Ptr< Ptr< hpoint1<double> > >& Pw,
00202 int nSampU, const Ptr<double>& sampU,
00203 int nSampV, const Ptr<double>& sampV,
00204 Ptr< Ptr< point1<double> > >& sampP );
00205 template void CalcSurfaceMesh(
00206 int nu, int pu, const Ptr<double>& U,
00207 int nv, int pv, const Ptr<double>& V,
00208 const Ptr< Ptr< point<double> > >& Pw,
00209 int nSampU, const Ptr<double>& sampU,
00210 int nSampV, const Ptr<double>& sampV,
00211 Ptr< Ptr< point<double> > >& sampP );
00212 template void CalcSurfaceMesh(
00213 int nu, int pu, const Ptr<double>& U,
00214 int nv, int pv, const Ptr<double>& V,
00215 const Ptr< Ptr< point1<double> > >& Pw,
00216 int nSampU, const Ptr<double>& sampU,
00217 int nSampV, const Ptr<double>& sampV,
00218 Ptr< Ptr< point1<double> > >& sampP );
00219
00220
00221
00222
00223
00224
00225
00226 template< class T, class HP >
00227 GULAPI void ExtractIsoCurveU( T u,
00228 int nu, int pu, const Ptr<T>& U,
00229 int nv, int pv, const Ptr<T>& V,
00230 const Ptr< Ptr<HP> >& Pw,
00231 Ptr<HP>& Cw )
00232 {
00233 Ptr< T > N;
00234 int span,i,j;
00235
00236 N.reserve_place( reserve_stack(T,pu+1), pu+1 );
00237
00238 span = FindSpan( u, nu, pu, U );
00239 CalcBasisFunctions<T>( u, span, pu, U, N );
00240
00241
00242 for( j = 0; j <= nv; j++ )
00243 {
00244 set( Cw[j], (T)0.0 );
00245 for( i = 0; i <= pu; i++ )
00246 {
00247 Cw[j] += N[i] * Pw[j][span-pu+i];
00248 }
00249 }
00250 }
00251
00252 template GULAPI void ExtractIsoCurveU( float u,
00253 int nu, int pu, const Ptr<float>& U,
00254 int nv, int pv, const Ptr<float>& V,
00255 const Ptr< Ptr< hpoint<float> > >& Pw,
00256 Ptr< hpoint<float> >& Cw );
00257 template GULAPI void ExtractIsoCurveU( double u,
00258 int nu, int pu, const Ptr<double>& U,
00259 int nv, int pv, const Ptr<double>& V,
00260 const Ptr< Ptr< hpoint<double> > >& Pw,
00261 Ptr< hpoint<double> >& Cw );
00262 template GULAPI void ExtractIsoCurveU( float u,
00263 int nu, int pu, const Ptr<float>& U,
00264 int nv, int pv, const Ptr<float>& V,
00265 const Ptr< Ptr< point<float> > >& Pw,
00266 Ptr< point<float> >& Cw );
00267 template GULAPI void ExtractIsoCurveU( double u,
00268 int nu, int pu, const Ptr<double>& U,
00269 int nv, int pv, const Ptr<double>& V,
00270 const Ptr< Ptr< point<double> > >& Pw,
00271 Ptr< point<double> >& Cw );
00272
00273 template GULAPI void ExtractIsoCurveU( float u,
00274 int nu, int pu, const Ptr<float>& U,
00275 int nv, int pv, const Ptr<float>& V,
00276 const Ptr< Ptr< hpoint1<float> > >& Pw,
00277 Ptr< hpoint1<float> >& Cw );
00278 template GULAPI void ExtractIsoCurveU( double u,
00279 int nu, int pu, const Ptr<double>& U,
00280 int nv, int pv, const Ptr<double>& V,
00281 const Ptr< Ptr< hpoint1<double> > >& Pw,
00282 Ptr< hpoint1<double> >& Cw );
00283 template GULAPI void ExtractIsoCurveU( float u,
00284 int nu, int pu, const Ptr<float>& U,
00285 int nv, int pv, const Ptr<float>& V,
00286 const Ptr< Ptr< point1<float> > >& Pw,
00287 Ptr< point1<float> >& Cw );
00288 template GULAPI void ExtractIsoCurveU( double u,
00289 int nu, int pu, const Ptr<double>& U,
00290 int nv, int pv, const Ptr<double>& V,
00291 const Ptr< Ptr< point1<double> > >& Pw,
00292 Ptr< point1<double> >& Cw );
00293
00294
00295
00296
00297
00298
00299 template< class T, class HP >
00300 GULAPI void ExtractIsoCurveV( T v,
00301 int nu, int pu, const Ptr<T>& U,
00302 int nv, int pv, const Ptr<T>& V,
00303 const Ptr< Ptr<HP> >& Pw,
00304 Ptr<HP>& Cw )
00305 {
00306 Ptr< T > N;
00307 int span,i,j;
00308
00309 N.reserve_place( reserve_stack(T,pv+1), pv+1 );
00310
00311 span = FindSpan( v, nv, pv, V );
00312 CalcBasisFunctions<T>( v, span, pv, V, N );
00313
00314 for( j = 0; j <= nu; j++ )
00315 {
00316 set( Cw[j], (T)0.0 );
00317 for( i = 0; i <= pv; i++ )
00318 {
00319 Cw[j] += N[i] * Pw[span-pv+i][j];
00320 }
00321 }
00322 }
00323
00324
00325 template GULAPI void ExtractIsoCurveV( float v,
00326 int nu, int pu, const Ptr<float>& U,
00327 int nv, int pv, const Ptr<float>& V,
00328 const Ptr< Ptr< hpoint<float> > >& Pw,
00329 Ptr< hpoint<float> >& Cw );
00330 template GULAPI void ExtractIsoCurveV( double v,
00331 int nu, int pu, const Ptr<double>& U,
00332 int nv, int pv, const Ptr<double>& V,
00333 const Ptr< Ptr< hpoint<double> > >& Pw,
00334 Ptr< hpoint<double> >& Cw );
00335 template GULAPI void ExtractIsoCurveV( float v,
00336 int nu, int pu, const Ptr<float>& U,
00337 int nv, int pv, const Ptr<float>& V,
00338 const Ptr< Ptr< point<float> > >& Pw,
00339 Ptr< point<float> >& Cw );
00340 template GULAPI void ExtractIsoCurveV( double v,
00341 int nu, int pu, const Ptr<double>& U,
00342 int nv, int pv, const Ptr<double>& V,
00343 const Ptr< Ptr< point<double> > >& Pw,
00344 Ptr< point<double> >& Cw );
00345
00346 template GULAPI void ExtractIsoCurveV( float v,
00347 int nu, int pu, const Ptr<float>& U,
00348 int nv, int pv, const Ptr<float>& V,
00349 const Ptr< Ptr< hpoint1<float> > >& Pw,
00350 Ptr< hpoint1<float> >& Cw );
00351 template GULAPI void ExtractIsoCurveV( double v,
00352 int nu, int pu, const Ptr<double>& U,
00353 int nv, int pv, const Ptr<double>& V,
00354 const Ptr< Ptr< hpoint1<double> > >& Pw,
00355 Ptr< hpoint1<double> >& Cw );
00356 template GULAPI void ExtractIsoCurveV( float v,
00357 int nu, int pu, const Ptr<float>& U,
00358 int nv, int pv, const Ptr<float>& V,
00359 const Ptr< Ptr< point1<float> > >& Pw,
00360 Ptr< point1<float> >& Cw );
00361 template GULAPI void ExtractIsoCurveV( double v,
00362 int nu, int pu, const Ptr<double>& U,
00363 int nv, int pv, const Ptr<double>& V,
00364 const Ptr< Ptr< point1<double> > >& Pw,
00365 Ptr< point1<double> >& Cw );
00366
00367
00368 }