예제 #1
0
파일: beziercurve.cpp 프로젝트: qbdp/pencil
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)";
    }
}
예제 #2
0
파일: beziercurve.cpp 프로젝트: qbdp/pencil
QPointF BezierCurve::getPointOnCubic(int i, qreal t)
{
    return (1.0-t)*(1.0-t)*(1.0-t)*getVertex(i-1)
           + 3*t*(1.0-t)*(1.0-t)*getC1(i)
           + 3*t*t*(1.0-t)*getC2(i)
           + t*t*t*getVertex(i);
}
예제 #3
0
파일: beziercurve.cpp 프로젝트: qbdp/pencil
void BezierCurve::addPoint(int position, const QPointF point)
{
    if ( position > -1 && position < getVertexSize() )
    {
        QPointF v1 = getVertex(position-1);
        QPointF v2 = getVertex(position);
        QPointF c1o = getC1(position);
        QPointF c2o = getC2(position);

        c1[position] = point + 0.2*(v2-v1);
        c2[position] = v2 + (c2o-v2)*(0.5);

        c1.insert(position, v1 + (c1o-v1)*(0.5) );
        c2.insert(position, point - 0.2*(v2-v1));
        vertex.insert(position, point);
        pressure.insert(position, getPressure(position));
        selected.insert(position, isSelected(position) && isSelected(position-1));

        //smoothCurve();
    }
    else
    {
        qDebug() << "Error BezierCurve::addPoint(int, QPointF)";
    }
}
int main(int argc, char *argv[])
{
    int size , rank;
    MPI_Init(&argc , &argv);
    MPI_Status status;
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Request resquest[2];    
    MPI_Comm_size(MPI_COMM_WORLD , &size);
    MPI_Comm_rank(MPI_COMM_WORLD , &rank);          
    srandom(rank);
    long a = 12, b = 555551 , mid , c1 , c2 , c3 , start , end; 
    if(rank == 0){
        start = MPI_Wtime();
        c1 = getC1(a, b);
        c2 = getC2(a , b); 
        c3 = getC3(a , b);  
        MPI_Send(&c1 , 10 , MPI_LONG , 1 , 1 , MPI_COMM_WORLD);
        MPI_Send(&c2 , 10 , MPI_LONG , 1 , 2 , MPI_COMM_WORLD);
        MPI_Send(&c3 , 10 , MPI_LONG , 1 , 3 , MPI_COMM_WORLD);     
    }else if(rank == 1){
        MPI_Recv(&c1 , 10 , MPI_LONG , 0 , 1 , MPI_COMM_WORLD , &status);
        MPI_Recv(&c2 , 10 , MPI_LONG , 0 , 2 , MPI_COMM_WORLD , &status);
        MPI_Recv(&c3 , 10 , MPI_LONG , 0 , 3 , MPI_COMM_WORLD , &status);
        long sum = (c1*pow(10 , getCount(a))) + ((c3- c1 - c2) * pow(10 , getCount(a)/2)) + c2;
        end = MPI_Wtime();
        //printf("a x b : %d , Time : %1.4f\n",sum, (end - start));
        printf("%d x %d : %d\n", a , b , sum);

    }    
    MPI_Finalize();
    return 0;
}
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 getC2(long i ,long j){
    if (i < 10 || j < 10){
        return (int)i * j;
    }
    int n = getCount(i);    
    long b = (long) (i % (int)pow(10, n / 2));    
    long d = (long) (j % (int)pow(10, n / 2));
    long c2 = getC2(b, d);
    return c2;
}
예제 #7
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;
}