7 #include "PlusConfigure.h" 10 #include "vtkMatrix4x4.h" 11 #include "vtkObjectFactory.h" 37 os << indent.GetNextIndent() <<
"Gamma Sigmoid: " << this->
gammaSigmoid << endl;
59 if (splineId <= 0 || splineId > 20)
135 double dSpline,
value, deriv, gradient[3];
138 dSpline =
CalculateDistanceBasis(transformMatrix->GetElement(0,3), transformMatrix->GetElement(1,3), transformMatrix->GetElement(2,3), n, 3);
154 force[
i] += gradient[
i];
160 double fMag = sqrt(force[0]*force[0]+force[1]*force[1]+force[2]*force[2]);
175 double tmp = exp(-a*
x);
185 deriv = a*tmp/( (1+tmp)*(1+tmp) );
197 double tmp = exp(-pow(
x*
x/(a*a), m));
201 deriv = tmp*2*m*pow(
x,2*m-1)/pow(a*a, m);
280 double Nu[10], Nv[10], Nw[10];
281 double dNu[10], dNv[10], dNw[10];
309 distDT +=
controlQ3D[Iw-2+k][Iv-2+
i][Iu-2+j]*Nw[k]*Nv[
i]*dNu[j];
313 gradient[0] = distDT;
322 distDT +=
controlQ3D[Iw-2+k][Iv-2+
i][Iu-2+j]*Nw[k]*dNv[
i]*Nu[j];
326 gradient[1] = distDT;
335 distDT +=
controlQ3D[Iw-2+k][Iv-2+
i][Iu-2+j]*dNw[k]*Nv[
i]*Nu[j];
339 gradient[2] = distDT;
348 double tmp1, tmp2, tmp3;
351 if( u<knot[0] || u>knot[K])
361 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
362 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
363 tmp3 = (knot[k+3]-u)/(knot[k+3]-knot[k])*(u-knot[k])/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
364 Nu = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(tmp1+tmp2) + tmp3;
368 tmp1 = (u-knot[k])/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
369 tmp2 = (knot[k+3]-u)/(knot[k+3]-knot[k+1])*(u-knot[k+1])/(knot[k+2]-knot[k+1]);
370 tmp3 = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(knot[k+2]-u)/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
371 Nu = (knot[k+3]-u)/(knot[k+3]-knot[k])*(tmp1+tmp2) + tmp3;
375 Nu = (knot[k+3]-u)*(knot[k+3]-u)*(knot[k+3]-u)/( (knot[k+3]-knot[k])*(knot[k+3]-knot[k+1])*(knot[k+3]-knot[k+2]) );
384 Nu = (u - knot[k-1])*(u - knot[k-1])*(u - knot[k-1])/( (knot[k+2]-knot[k-1])*(knot[k+1]-knot[k-1])*(knot[k]-knot[k-1]) );
388 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
389 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
390 Nu = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(tmp1+tmp2);
394 tmp3 = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(knot[k+2]-u)/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
404 Nu = (u - knot[k-1])*(u - knot[k-1])*(u - knot[k-1])/( (knot[k+2]-knot[k-1])*(knot[k+1]-knot[k-1])*(knot[k]-knot[k-1]) );
408 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
409 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
410 tmp3 = (knot[k+3]-u)/(knot[k+3]-knot[k])*(u-knot[k])/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
411 Nu = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(tmp1+tmp2) + tmp3;
415 tmp1 = (u-knot[k])/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
416 tmp2 = (knot[k+3]-u)/(knot[k+3]-knot[k+1])*(u-knot[k+1])/(knot[k+2]-knot[k+1]);
417 tmp3 = (u-knot[k-1])/(knot[k+2]-knot[k-1])*(knot[k+2]-u)/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
418 Nu = (knot[k+3]-u)/(knot[k+3]-knot[k])*(tmp1+tmp2) + tmp3;
422 Nu = (knot[k+3]-u)*(knot[k+3]-u)*(knot[k+3]-u)/( (knot[k+3]-knot[k])*(knot[k+3]-knot[k+1])*(knot[k+3]-knot[k+2]) );
435 double dtmp,dtmp1,dtmp2,dtmp3;
438 if( u<knot[0] || u>knot[K])
448 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
449 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
451 dtmp1 = ( (knot[k+1]-u) + (u-knot[k-1])*(-1) )/(knot[k+1]-knot[k-1])/(knot[k+1]-knot[k]);
452 dtmp2 = ( (-1)*(u-knot[k]) + (knot[k+2]-u) )/(knot[k+2]-knot[k])/(knot[k+1]-knot[k]);
454 dtmp = (knot[k+3]-knot[k])*(knot[k+2]-knot[k])*(knot[k+1]-knot[k]);
455 dtmp3 = ( (-1)*(u-knot[k])*(u-knot[k]) + (knot[k+3]-u)*2*(u-knot[k]) )/dtmp;
457 dNu = 1/(knot[k+2]-knot[k-1])*(tmp1+tmp2) + (u-knot[k-1])/(knot[k+2]-knot[k-1])*(dtmp1+dtmp2)+dtmp3;
461 tmp1 = (u-knot[k])/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
462 tmp2 = (knot[k+3]-u)/(knot[k+3]-knot[k+1])*(u-knot[k+1])/(knot[k+2]-knot[k+1]);
464 dtmp1 = ( (knot[k+2]-u) + (u-knot[k])*(-1) )/(knot[k+2]-knot[k])/(knot[k+2]-knot[k+1]);
465 dtmp2 = ( (-1)*(u-knot[k+1]) + (knot[k+3]-u) )/(knot[k+3]-knot[k+1])/(knot[k+2]-knot[k+1]);
467 dtmp = (knot[k+2]-knot[k-1])*(knot[k+2]-knot[k])*(knot[k+2]-knot[k+1]);
468 dtmp3 = ( (knot[k+2]-u)*(knot[k+2]-u) + (u-knot[k-1])*(-2)*(knot[k+2]-u) )/dtmp;
470 dNu = (-1)/(knot[k+3]-knot[k])*(tmp1+tmp2) + (knot[k+3]-u)/(knot[k+3]-knot[k])*(dtmp1+dtmp2)+dtmp3;
474 dNu = (-3)*(knot[k+3]-u)*(knot[k+3]-u)/( (knot[k+3]-knot[k])*(knot[k+3]-knot[k+1])*(knot[k+3]-knot[k+2]) );
483 dNu = 3*(u - knot[k-1])*(u - knot[k-1])/( (knot[k+2]-knot[k-1])*(knot[k+1]-knot[k-1])*(knot[k]-knot[k-1]) );
487 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
488 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
490 dtmp1 = ( (knot[k+1]-u) + (u-knot[k-1])*(-1) )/(knot[k+1]-knot[k-1])/(knot[k+1]-knot[k]);
491 dtmp2 = ( (-1)*(u-knot[k]) + (knot[k+2]-u) )/(knot[k+2]-knot[k])/(knot[k+1]-knot[k]);
493 dNu = 1/(knot[k+2]-knot[k-1])*(tmp1+tmp2) + (u-knot[k-1])/(knot[k+2]-knot[k-1])*(dtmp1+dtmp2);
497 dtmp = (knot[k+2]-knot[k-1])*(knot[k+2]-knot[k])*(knot[k+2]-knot[k+1]);
498 dtmp3 = ( (knot[k+2]-u)*(knot[k+2]-u) + (u-knot[k-1])*(-2)*(knot[k+2]-u) )/dtmp;
507 dNu = 3*(u - knot[k-1])*(u - knot[k-1])/( (knot[k+2]-knot[k-1])*(knot[k+1]-knot[k-1])*(knot[k]-knot[k-1]) );
511 tmp1 = (u-knot[k-1])/(knot[k+1]-knot[k-1])*(knot[k+1]-u)/(knot[k+1]-knot[k]);
512 tmp2 = (knot[k+2]-u)/(knot[k+2]-knot[k])*(u-knot[k])/(knot[k+1]-knot[k]);
514 dtmp1 = ( (knot[k+1]-u) + (u-knot[k-1])*(-1) )/(knot[k+1]-knot[k-1])/(knot[k+1]-knot[k]);
515 dtmp2 = ( (-1)*(u-knot[k]) + (knot[k+2]-u) )/(knot[k+2]-knot[k])/(knot[k+1]-knot[k]);
517 dtmp = (knot[k+3]-knot[k])*(knot[k+2]-knot[k])*(knot[k+1]-knot[k]);
518 dtmp3 = ( (-1)*(u-knot[k])*(u-knot[k]) + (knot[k+3]-u)*2*(u-knot[k]) )/dtmp;
520 dNu = 1/(knot[k+2]-knot[k-1])*(tmp1+tmp2) + (u-knot[k-1])/(knot[k+2]-knot[k-1])*(dtmp1+dtmp2)+dtmp3;
524 tmp1 = (u-knot[k])/(knot[k+2]-knot[k])*(knot[k+2]-u)/(knot[k+2]-knot[k+1]);
525 tmp2 = (knot[k+3]-u)/(knot[k+3]-knot[k+1])*(u-knot[k+1])/(knot[k+2]-knot[k+1]);
527 dtmp1 = ( (knot[k+2]-u) + (u-knot[k])*(-1) )/(knot[k+2]-knot[k])/(knot[k+2]-knot[k+1]);
528 dtmp2 = ( (-1)*(u-knot[k+1]) + (knot[k+3]-u) )/(knot[k+3]-knot[k+1])/(knot[k+2]-knot[k+1]);
530 dtmp = (knot[k+2]-knot[k-1])*(knot[k+2]-knot[k])*(knot[k+2]-knot[k+1]);
531 dtmp3 = ( (knot[k+2]-u)*(knot[k+2]-u) + (u-knot[k-1])*(-2)*(knot[k+2]-u) )/dtmp;
533 dNu = (-1)/(knot[k+3]-knot[k])*(tmp1+tmp2) + (knot[k+3]-u)/(knot[k+3]-knot[k])*(dtmp1+dtmp2)+dtmp3;
537 dNu = (-3)*(knot[k+3]-u)*(knot[k+3]-u)/( (knot[k+3]-knot[k])*(knot[k+3]-knot[k+1])*(knot[k+3]-knot[k+2]) );
560 double Nu[10], Nv[10], Nw[10];
584 distT +=
controlQ3D[Iw-2+k][Iv-2+
i][Iu-2+j]*Nw[k]*Nv[
i]*Nu[j];
597 for(
int i=0;
i<=K;
i++)
625 std::ifstream fpInKnot;
626 fpInKnot.open(fname.c_str());
628 if( !fpInKnot.is_open() )
636 fpInKnot >>
knot1[k];
641 fpInKnot >>
knot2[k];
646 fpInKnot >>
knot3[k];
675 std::ifstream fpInKnot;
676 fpInKnot.open(fname.c_str());
678 if( !fpInKnot.is_open() )
int GenerateForce(vtkMatrix4x4 *transformMatrix, double force[3])
double BasisFunction3(int k, double *knot, double u, int K)
double controlQ3D[DimCPoint_W][DimCPoint_V][DimCPoint_U]
int SetGamma(double gamma)
int fnGaussValueDeriv(double a, double x, double &value, double &deriv)
vtkStandardNewMacro(vtkPlusImplicitSplineForce) vtkPlusImplicitSplineForce
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
double knot3[NUM_INTERVALW_S+1]
double CalculateDistanceBasis(double x, double y, double z, int n, int direction)
int CalculateDistanceDerivativeBasis(double x, double y, double z, int n, int direction, double *gradient)
int ReadFileControlPoints(const std::string &fname)
double BasisFunction3DerivativeD(int k, double *knot, double u, int K)
vtkPlusImplicitSplineForce()
double knot1[NUM_INTERVALU_S+1]
int CalculateKnotIu(double u, double *knot, int K, int n)
const char const char * value
int ReadFile3DBSplineKnots(const std::string &fname)
Direction vectors of rods y
void SetInput(int splineId)
std::string ControlPoints
double knot2[NUM_INTERVALV_S+1]
virtual ~vtkPlusImplicitSplineForce()
int fnSigmoidValueDeriv(double a, double x, double &value, double &deriv)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
Position vectors of rods v