void BezierCurve::addPoint(int position, const qreal t) // t is the fraction where to split the bezier curve (ex: t=0.5) { // de Casteljau's method is used // http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm // http://www.damtp.cam.ac.uk/user/na/PartIII/cagd2002/halve.ps if ( position > -1 && position < getVertexSize() ) { QPointF vA = getVertex(position-1); QPointF vB = getVertex(position); QPointF c1o = getC1(position); QPointF c2o = getC2(position); QPointF c12 = (1-t)*c1o + t*c2o; QPointF cA1 = (1-t)*vA + t*c1o; QPointF cB2 = (1-t)*c2o + t*vB; QPointF cA2 = (1-t)*cA1 + t*c12; QPointF cB1 = (1-t)*c12 + t*cB2; QPointF vM = (1-t)*cA2 + t*cB1; setC1(position, cB1); setC2(position, cB2); c1.insert(position, cA1); c2.insert(position, cA2); vertex.insert(position, vM); pressure.insert(position, getPressure(position)); selected.insert(position, isSelected(position) && isSelected(position-1)); //smoothCurve(); } else { qDebug() << "Error BezierCurve::addPoint(int, qreal)"; } }
int CaGate_Yamada98::updateInternal(void) { // get the static table pointers and store them locally c1=getC1(); c2=getC2(); // allocate memory bool haveToInitTable = 1; if (!c1) { setC1(c1=(double *)malloc(IONGATE_CA_TABLE_SIZE*sizeof(double)));} if (!c2) { setC2(c2=(double *)malloc(IONGATE_CA_TABLE_SIZE*sizeof(double)));} // // set up the look up tables // if ( haveToInitTable ) { int i; double ca; double *p1,*p2; for(ca=IONGATE_CA_MIN,i=0,p1=c1,p2=c2;i<IONGATE_CA_TABLE_SIZE;i++,ca+=IONGATE_CA_INC,p1++,p2++) { (*p1) = exp(-DT/tau(ca)); (*p2) = (1.0-(*p1))*infty(ca); #ifdef _GUN_SOURCE if ( !finite((*p1)) ) { TheCsimError.add("CaGate_Yamada98::reset: There occurred undefined values (NaN or Inf) for C1!\n"); return -1; } if ( !finite((*p2)) ) { TheCsimError.add("CaGate_Yamada98::reset: There occurred undefined values (NaN or Inf) for C2!\n"); return -1; } #endif } } return 0; }
int VIonGate::updateInternal(void) { // get the static table pointers and store them locally c1=getC1(); c2=getC2(); // printf("VIonGate::updateInternal\n"); // allocate memory bool haveToInitTable = 0; if (!c1) { setC1(c1=(double *)malloc(VIONGATE_TABLE_SIZE*sizeof(double))); haveToInitTable = 1; } if (!c2) { setC2(c2=(double *)malloc(VIONGATE_TABLE_SIZE*sizeof(double))); haveToInitTable = 1; } if (dttable != DT) {haveToInitTable = 1;} // // set up the look up tables // if ( haveToInitTable ) { int i; double v; double *p1,*p2; if (nummethod == 0) { // generate lookup table for exponential euler method // printf("VIonGate::updateInternal Euler gate\n"); for(v=VIONGATE_VM_MIN,i=0,p1=c1,p2=c2;i<VIONGATE_TABLE_SIZE;i++,v+=VIONGATE_VM_INC,p1++,p2++) { (*p1) = exp(-DT/tau(v)); (*p2) = (1.0-(*p1))*infty(v); #ifndef _WIN32 if ( !finite((*p1)) ) { TheCsimError.add("VIonGate::updateInternal: There occurred undefined values (NaN or Inf) for C1!\n"); return -1; } if ( !finite((*p2)) ) { TheCsimError.add("VIonGate::updateInternal: There occurred undefined values (NaN or Inf) for C2!\n"); return -1; } #endif } } else { // printf("VIonGate::updateInternal Crank-Nicolson gate\n"); // generate lookup table for Crank-Nicolson method // See: Methods in Neuronal Modeling: From Ions to Networks // edited by Christof Koch and Idan Segev // Chapter 14: "Numerical Methods for Neuronal Modeling" // by Michael V. Mascagni and Arthur S. Sherman. for(v=VIONGATE_VM_MIN,i=0,p1=c1,p2=c2;i<VIONGATE_TABLE_SIZE;i++,v+=VIONGATE_VM_INC,p1++,p2++) { (*p1) = (1 - DT/2*(alpha(v) + beta(v))) / (1 + DT/2*(alpha(v) + beta(v))); (*p2) = DT*alpha(v)/(1+DT/2*(alpha(v) + beta(v))); #ifndef _WIN32 if ( !finite((*p1)) ) { TheCsimError.add("VIonGate::updateInternal: There occurred undefined values (NaN or Inf) for C1!\n"); return -1; } if ( !finite((*p2)) ) { TheCsimError.add("VIonGate::updateInternal: There occurred undefined values (NaN or Inf) for C2!\n"); return -1; } #endif } } } return 0; }