コード例 #1
0
ファイル: ofApp.cpp プロジェクト: doronrk/MorphOpenCL
//--------------------------------------------------------------
void ofApp::update(){
    //Update particles positions
    
    //Link parameters to OpenCL (see Particle.cl):
    opencl.kernel("updateParticle")->setArg(0, particles.getCLMem());
	opencl.kernel("updateParticle")->setArg(1, particlePos.getCLMem());
   
    //Execute OpenCL computation and wait it finishes
    opencl.kernel("updateParticle")->run1D( N );
	opencl.finish();
    
    // update bin sizes
    soundMutex.lock();
    for (int h = 0; h < fftHistory.size(); h++)
    {
        vector<float> fftBins = fftHistory[h];
        for (int i = 0; i < fftBins.size(); i++)
        {
            if (i < ignoreFFTbelow * fftBins.size())
            {
                fftBins[i] = 0.0;
            } else
            {
                fftBins[i] = abs(fftBins[i] * (1 + pow(i, freqScalingExponent)/fftBins.size()));
                fftBins[i] = pow(fftBins[i], amplitudeScalingExponent);
            }
        }
    }
    drawSignal = middleSignal;
    soundMutex.unlock();
    downsampleBins(downsampledBins, fftHistory[0]);
    // don't let the particles go off the screen
    cutoff(drawSignal, 0.4, 0);
}
コード例 #2
0
ファイル: samplv1widget_filt.cpp プロジェクト: rncbc/samplv1
// Parameter accessors.
void samplv1widget_filt::setCutoff ( float fCutoff )
{
	if (::fabsf(m_fCutoff - fCutoff) > 0.001f) {
		m_fCutoff = safe_value(fCutoff);
		update();
		emit cutoffChanged(cutoff());
	}
}
コード例 #3
0
ファイル: Energy.c プロジェクト: accre/user-misc
//finds the energy of a single point
double ptenergy(pt *pts, pt thePt, nbhd theNbhd, double s, double radius,int dim){
    int i;
    double energy = 0;
    double ptdist;
    for(i = 0; i < theNbhd.neighborcount; i++){
        ptdist = dist(pts[theNbhd.neighbors[i]], thePt,dim);
        energy += cutoff(ptdist, radius)/pow(ptdist, s);
    }
    return energy;
}
コード例 #4
0
ファイル: main-xpehh.cpp プロジェクト: liuchchc/hapbin
int main(int argc, char** argv)
{
    int ret = 0;
    std::size_t numSnps;
#if MPI_FOUND
    MPI_Init(&argc, &argv);
#endif
    Argument<bool> help('h', "help", "Show this help", true, false);
    Argument<bool> version('v', "version", "Version information", true, false);
    Argument<std::string> hapA('d', "hapA", "Hap file for population A", false, false, "");
    Argument<std::string> hapB('e', "hapB", "Hap file for population B", false, false, "");
    Argument<std::string> map('m', "map", "Map file", false, false, "");
    Argument<double> cutoff('c', "cutoff", "EHH cutoff value (default: 0.05)", false, false, 0.05);
    Argument<double> minMAF('f', "minmaf", "Minimum allele frequency (default: 0.05)", false, false, 0.00);
    Argument<double> binfac('b', "bin", "Frequency bin size (default: 0.02)", false, false, 0.02);
    Argument<unsigned long long> scale('s', "scale", "Gap scale parameter in bp, used to scale gaps > scale parameter as in Voight, et al.", false, false, 20000);
    Argument<std::string> outfile('o', "out", "Output file", false, false, "out.txt");
    ArgParse argparse({&help, &version, &hapA, &hapB, &map, &outfile, &cutoff, &minMAF, &scale, &binfac}, "Usage: xpehhbin --map input.map --hapA inputA.hap --hapB inputB.hap");
    if (!argparse.parseArguments(argc, argv)) 
    {
        ret = 1;
        goto out;
    }
    if (help.value())
    {
        argparse.showHelp();
        goto out;
    }
    else if (version.value())
    {
        argparse.showVersion();
        goto out;
    }
    else if (!hapA.wasFound() || !hapB.wasFound() || !map.wasFound())
    {
        std::cout << "Please specify --hapA, --hapB, and --map." << std::endl;
        ret = 2;
        goto out;
    }
    
    numSnps = HapMap::querySnpLength(hapA.value().c_str());
    std::cout << "Haplotypes in population A: " << numSnps << std::endl;
    numSnps = HapMap::querySnpLength(hapB.value().c_str());
    std::cout << "Haplotypes in population B: " << numSnps << std::endl;
    
    calcXpehh(hapA.value(), hapB.value(), map.value(), outfile.value(), cutoff.value(), minMAF.value(), (double) scale.value(), binfac.value());

out:
#if MPI_FOUND
    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Finalize();
#endif
    return ret;
}
コード例 #5
0
ファイル: dafuse.cpp プロジェクト: AlexLuya/HPCC-Platform
 void addDirCache(CDirCacheItem *val)
 {
     CDateTime now;
     now.setNow();
     CDateTime cutoff(now);
     cutoff.adjustTime(-DIRCACHE_TIMEOUT);
     ForEachItemInRev(i,dircache) {
         CDirCacheItem &item = dircache.item(i);
         if (item.dt.compare(cutoff)<0)
             dircache.remove(i);
     }
コード例 #6
0
ファイル: samplv1widget_filt.cpp プロジェクト: rncbc/samplv1
// Drag/move curve.
void samplv1widget_filt::dragCurve ( const QPoint& pos )
{
	const int h  = height();
	const int w  = width();

	const int dx = (pos.x() - m_posDrag.x());
	const int dy = (pos.y() - m_posDrag.y());

	if (dx || dy) {
		const int h2 = (h >> 1);
		const int x = int(cutoff() * float(w));
		const int y = int(reso() * float(h2));
		setCutoff(float(x + dx) / float(w));
		setReso(float(y - dy) / float(h2));
		m_posDrag = pos;
	}
}
コード例 #7
0
ファイル: icenode.cpp プロジェクト: oyaGG/aaOcean
SICALLBACK aaOcean_BeginEvaluate( ICENodeContext& in_ctxt )
{
    // get ocean pointer from user-data
    aaOcean *pOcean = (aaOcean *)(CValue::siPtrType)in_ctxt.GetUserData();

    // get ICE node input port arrays
    CDataArrayLong PointID( in_ctxt, ID_IN_PointID);
    CDataArrayLong resolution( in_ctxt, ID_IN_RESOLUTION);      
    CDataArrayLong seed( in_ctxt, ID_IN_SEED);
    CDataArrayFloat waveHeight( in_ctxt, ID_IN_WAVE_HEIGHT);
    CDataArrayFloat waveSpeed( in_ctxt, ID_IN_WAVESPEED);
    CDataArrayFloat chop( in_ctxt, ID_IN_CHOP);
    CDataArrayFloat oceanScale( in_ctxt, ID_IN_OCEAN_SCALE );
    CDataArrayFloat oceanDepth( in_ctxt, ID_IN_OCEAN_DEPTH );
    CDataArrayFloat windDir( in_ctxt, ID_IN_WINDDIR );
    CDataArrayFloat cutoff( in_ctxt, ID_IN_CUTOFF);
    CDataArrayFloat velocity( in_ctxt, ID_IN_WINDVELOCITY);
    CDataArrayLong  windAlign( in_ctxt, ID_IN_WINDALIGN );
    CDataArrayFloat damp( in_ctxt, ID_IN_DAMP);
    CDataArrayBool enableFoam( in_ctxt, ID_IN_ENABLEFOAM);
    CDataArrayFloat time( in_ctxt, ID_IN_TIME);
    CDataArrayFloat loopTime( in_ctxt, ID_IN_REPEAT_TIME);
    CDataArrayFloat surfaceTension( in_ctxt, ID_IN_SURFACE_TENSION);
    CDataArrayFloat randWeight( in_ctxt, ID_IN_RAND_WEIGHT);

    pOcean->input(resolution[0], 
        seed[0],
        oceanScale[0], 
        oceanDepth[0],
        surfaceTension[0],
        velocity[0], 
        cutoff[0], 
        windDir[0], 
        windAlign[0], 
        damp[0], 
        waveSpeed[0], 
        waveHeight[0],
        chop[0], 
        time[0],
        loopTime[0],
        enableFoam[0],
        randWeight[0]);

    return CStatus::OK;
}
コード例 #8
0
ファイル: Energy.c プロジェクト: accre/user-misc
//finds the gradient for a given point
void ptgrad( pt *pts, pt thePt, nbhd theNbhd, double s, double radius , double *theGrad,int dim){
    int i,j;
    double ptdist;
    double gradfactor;
    
    pt nbhrPt;
    for(j=0;j<dim;j++){
        theGrad[j]=0;
    }
    for(i=0;i<theNbhd.neighborcount;i++){
        nbhrPt=pts[theNbhd.neighbors[i]];
        ptdist=dist(nbhrPt, thePt,dim);
        gradfactor=-1*s*cutoff(ptdist, radius)/pow(ptdist, s+2)+2*cutoffPrime(ptdist,radius)/(radius*radius*pow(ptdist,s));

        for(j=0;j<dim;j++){
            theGrad[j]+=gradfactor*(thePt.components[j]-nbhrPt.components[j]);
            
        }
    }
}
コード例 #9
0
 string simplifyPath(string path) {
   vector<string> cult;
   cutoff(path,cult);
   stack<string> sta;
   sta.push("/");
   for(int i=0;i<cult.size();i++){
     if(cult[i]=="/.") continue;
     else if(cult[i]=="/.."){
       if(sta.top()!="/")
         sta.pop();
     }
     else sta.push(cult[i]);
   }
   string s="";
   while(!sta.empty()){
     string top=sta.top();
     sta.pop();
     if(s!="" && top=="/") continue;
     s=top+s;
   }
   return s;
 }
コード例 #10
0
ファイル: Energy.c プロジェクト: accre/user-misc
//finds the total energy by including a cutoff
double energy(pt *pts, int numPts, nbhd *nbhds, double s, double radius, int dim, double* minDistance){
    int i,j;
    double pten;
    double ptdist;
    double totalEn=0;
    *minDistance = 100;
    nbhd theNbhd;
    for(i = 0; i < numPts; i++){
        pten=0;
        theNbhd=nbhds[i];
        for(j = 0; j < theNbhd.neighborcount; j++){
            if (theNbhd.neighbors[j]<i) {
                ptdist = dist(pts[theNbhd.neighbors[j]], pts[i],dim);
                
                if (ptdist < *minDistance) *minDistance = ptdist;
                
                pten += cutoff(ptdist, radius)/pow(ptdist, s);
            }
        }
        totalEn += pten;
    }
    return 2*totalEn;
}
コード例 #11
0
ファイル: Material.hpp プロジェクト: lexarvn/RayTracer
 void cutoff(double cut)
 {
     r = cutoff(r, cut);
     g = cutoff(g, cut);
     b = cutoff(b, cut);
 }
コード例 #12
0
void MO_matrix_blas::init() {


  //mo_counter.Resize(nmo);
  //mo_counter=0.0;
  //n_calls=0;

  //Determine where to cut off the basis functions
  
  cutoff.Resize(totbasis);
  int basiscounter=0;
  for(int i=0; i< centers.size(); i++)
  {
    for(int j=0; j< centers.nbasis(i); j++)
    {
      Basis_function* tempbasis=basis(centers.basis(i,j));
      for(int n=0; n< tempbasis->nfunc(); n++)
      {
        //cout << "cutoff " << endl;
        cutoff(basiscounter)=tempbasis->cutoff(n);
        //cout << "rcut(" << basiscounter << ") "
        //     << cutoff(basiscounter) << endl;
        basiscounter++;
      }
    }
  }

  obj_cutoff.Resize(basis.GetDim(0));
  for(int b=0; b< basis.GetDim(0); b++) {
    int nf=basis(b)->nfunc();
    doublevar maxcut=basis(b)->cutoff(0);
    for(int n=1; n< nf; n++) {
      doublevar cut=basis(b)->cutoff(n);
      if(cut > maxcut) maxcut=cut;
    }
    obj_cutoff(b)=maxcut;
  }
  
  
  nfunctions.Resize(basis.GetDim(0));
  for(int b=0; b< basis.GetDim(0); b++) {
    nfunctions(b)=basis(b)->nfunc();
  }
  

  moCoeff.Resize(totbasis, nmo);


  ifstream ORB(orbfile.c_str());
  if(!ORB) error("couldn't find orb file ", orbfile);

  Array3 <int> coeffmat;
  Array1 <doublevar> coeff;
  readorb(ORB,centers, nmo, maxbasis, kpoint,coeffmat, coeff);
  string in;
  ORB.close();

  //Find the cutoffs

  int totfunc=0;

  for(int ion=0; ion<centers.size(); ion++) {
    int f=0;
    doublevar dot=0;
    for(int d=0; d<3; d++) dot+=centers.centers_displacement(ion,d)*kpoint(d);
    
    //cout << "kptfac " << cos(dot*pi) << "  displacement " 
    //    << centers.centers_displacement(ion,0) << "   "
    //    << endl;            
    doublevar kptfac=cos(dot*pi);
        
    for(int n=0; n< centers.nbasis(ion); n++) {

      int fnum=centers.basis(ion,n);
      int imax=basis(fnum)->nfunc();

      for(int i=0; i<imax; i++){ 
        for(int mo=0; mo<nmo; mo++) {	   

          if(coeffmat(mo,ion, f) == -1) {
            moCoeff(totfunc,mo)=0.0;
            //cout << "missing MO pointer: mo# " << mo << " ion # " << ion
            //<< " function on ion: " << f << endl;
            //error("In the orb file, there is a missing pointer. It might "
            //      "be a badly structured file.");
          }
          else moCoeff(totfunc, mo)=magnification_factor*kptfac*coeff(coeffmat(mo,ion,f));
        }//mo
        f++;  //keep a total of functions on center
        totfunc++;
      } //i
    } //n
  }  //ion


  //output_array(moCoeff);

}
コード例 #13
0
ファイル: samplv1widget_filt.cpp プロジェクト: rncbc/samplv1
void samplv1widget_filt::mouseReleaseEvent ( QMouseEvent *pMouseEvent )
{
	QFrame::mouseReleaseEvent(pMouseEvent);

	if (m_bDragging) {
		dragCurve(pMouseEvent->pos());
		m_bDragging = false;
		unsetCursor();
	}
}


void samplv1widget_filt::wheelEvent ( QWheelEvent *pWheelEvent )
{
	const int delta = (pWheelEvent->delta() / 60);

	if (pWheelEvent->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier)) {
		const int h2 = (height() >> 1);
		const int y = int(reso() * float(h2));
		setReso(float(y + delta) / float(h2));
	} else {
		const int w2 = (width() >> 1);
		const int x = int(cutoff() * float(w2));
		setCutoff(float(x + delta) / float(w2));
	}
}


// end of samplv1widget_filt.cpp
コード例 #14
0
ファイル: samplv1widget_filt.cpp プロジェクト: rncbc/samplv1
// Draw curve.
void samplv1widget_filt::paintEvent ( QPaintEvent *pPaintEvent )
{
	QPainter painter(this);

	const QRect& rect = QWidget::rect();
	const int h  = rect.height();
	const int w  = rect.width();

	const int h2 = h >> 1;
	const int h4 = h >> 2;
	const int w4 = w >> 2;
	const int w8 = w >> 3;

	const int iSlope = int(m_fSlope);
	const int ws = w8 - (iSlope == 1 ? (w8 >> 1) : 0);

	int x = w8 + int(m_fCutoff * float(w - w4));
	int y = h2 - int(m_fReso   * float(h + h4));

	QPolygon poly(6);
	QPainterPath path;

	const int iType = (iSlope == 3 ? 4 : int(m_fType));
	// Low, Notch
	if (iType == 0 || iType == 3) {
		if (iType == 3) x -= w8;
		poly.putPoints(0, 6,
			0, h2,
			x - w8, h2,
			x, h2,
			x, y,
			x + ws, h,
			0, h);
		path.moveTo(poly.at(0));
		path.lineTo(poly.at(1));
		path.cubicTo(poly.at(2), poly.at(3), poly.at(4));
		path.lineTo(poly.at(5));
		if (iType == 3) x += w8;
	}
	// Band
	if (iType == 1) {
		const int y2 = (y + h4) >> 1;
		poly.putPoints(0, 6,
			0, h,
			x - w8 - ws, h,
			x - ws, y2,
			x + ws, y2,
			x + w8 + ws, h,
			0, h);
		path.moveTo(poly.at(0));
		path.lineTo(poly.at(1));
		path.cubicTo(poly.at(2), poly.at(3), poly.at(4));
		path.lineTo(poly.at(5));
	}
	// High, Notch
	if (iType == 2 || iType == 3) {
		if (iType == 3) { x += w8; y = h2; }
		poly.putPoints(0, 6,
			x - ws, h,
			x, y,
			x, h2,
			x + w8, h2,
			w, h2,
			w, h);
		path.moveTo(poly.at(0));
		path.cubicTo(poly.at(1), poly.at(2), poly.at(3));
		path.lineTo(poly.at(4));
		path.lineTo(poly.at(5));
		if (iType == 3) x -= w8;
	}
	// Formant
	if (iType == 4) {
		const int x2 = (x - w4) >> 2;
		const int y2 = (y - h4) >> 2;
		poly.putPoints(0, 6,
			0, h2,
			x2, h2,
			x - ws, h2,
			x, y2,
			x + ws, h,
			0, h);
		path.moveTo(poly.at(0));
	#if 0
		path.lineTo(poly.at(1));
		path.cubicTo(poly.at(2), poly.at(3), poly.at(4));
	#else
		const int n3 = 5; // num.formants
		const int w3 = (x + ws - x2) / n3 - 1;
		const int w6 = (w3 >> 1);
		const int h3 = (h4 >> 1);
		int x3 = x2; int y3 = y2;
		for (int i = 0; i < n3; ++i) {
			poly.putPoints(1, 3,
				x3, h2,
				x3 + w6, y3,
				x3 + w3, y3 + h2);
			path.cubicTo(poly.at(1), poly.at(2), poly.at(3));
			x3 += w3; y3 += h3;
		}
		path.lineTo(poly.at(4));
	#endif
		path.lineTo(poly.at(5));
	}

	const QPalette& pal = palette();
	const bool bDark = (pal.window().color().value() < 0x7f);
	const QColor& rgbLite = (isEnabled()
		? (bDark ? Qt::darkYellow : Qt::yellow) : pal.mid().color());
	const QColor& rgbDark = pal.window().color().darker(180);

	painter.fillRect(rect, rgbDark);

	painter.setPen(bDark ? Qt::gray : Qt::darkGray);

	QLinearGradient grad(0, 0, w << 1, h << 1);
	grad.setColorAt(0.0f, rgbLite);
	grad.setColorAt(1.0f, Qt::black);

	painter.setRenderHint(QPainter::Antialiasing, true);

	painter.setBrush(grad);
	painter.drawPath(path);

#ifdef CONFIG_DEBUG_0
	painter.drawText(QFrame::rect(),
		Qt::AlignTop|Qt::AlignHCenter,
		tr("Cutoff(%1) Reso(%2)")
		.arg(int(100.0f * cutoff()))
		.arg(int(100.0f * reso())));
#endif

	painter.setRenderHint(QPainter::Antialiasing, false);

	painter.end();

	QFrame::paintEvent(pPaintEvent);
}
コード例 #15
0
ファイル: cdfwchisq.c プロジェクト: ahnitz/lalsuite
REAL8 cdfwchisq(qfvars *vars, REAL8 sigma, REAL8 acc, INT4 *ifault)
{

   INT4 nt, ntm;
   REAL8 acc1, almx, xlim, xnt, xntm;
   REAL8 utx, tausq, wnstd, intv, intv1, x, up, un, d1, d2;
   REAL8 qfval;
   INT4 rats[] = {1, 2, 4, 8};

   *ifault = 0;
   vars->count = 0;
   vars->integrationValue = 0.0;
   vars->integrationError = 0.0;
   qfval = -1.0;
   acc1 = acc;
   vars->arrayNotSorted = 1;
   vars->fail = 0;
   xlim = (REAL8)vars->lim;

   /* find wnmean, wnstd, wnmax and wnmin of weights, check that parameter values are valid */
   vars->sigsq = sigma*sigma;    //Sigma squared
   wnstd = vars->sigsq;          //weights*noise standard deviation initial value
   vars->wnmax = 0.0;            //Initial value for weights*noise maximum
   vars->wnmin = 0.0;            //Initial value for weights*noise minimum
   vars->wnmean = 0.0;           //Initial value for weights*noise 'mean'
   for (UINT4 ii=0; ii<vars->weights->length; ii++ ) {
      if ( vars->dofs->data[ii] < 0  ||  vars->noncentrality->data[ii] < 0.0 ) {
         *ifault = 3;
         return qfval;
      } /* return error if any degrees of freedom is less than 0 or noncentrality parameter is less than 0.0 */

      wnstd += vars->weights->data[ii]*vars->weights->data[ii] * (2 * vars->dofs->data[ii] + 4.0 * vars->noncentrality->data[ii]);
      vars->wnmean += vars->weights->data[ii] * (vars->dofs->data[ii] + vars->noncentrality->data[ii]);

      //Find maximum and minimum values
      if (vars->wnmax < vars->weights->data[ii]) {
         vars->wnmax = vars->weights->data[ii];
      } else if (vars->wnmin > vars->weights->data[ii]) {
         vars->wnmin = vars->weights->data[ii];
      }
   }

   if ( wnstd == 0.0  ) {
      if (vars->c>0.0) qfval = 1.0;
      else qfval = 0.0;
      return qfval;
   }

   if ( vars->wnmin == 0.0 && vars->wnmax == 0.0 && sigma == 0.0 ) {
      *ifault = 3;
      return qfval;
   }

   wnstd = sqrt(wnstd);

   //almx is absolute value maximum of weights
   if (vars->wnmax < -vars->wnmin) almx = -vars->wnmin;
   else almx = vars->wnmax;

   /* starting values for findu, cutoff */
   utx = 16.0/wnstd;
   up = 4.5/wnstd;
   un = -up;

   /* truncation point with no convergence factor */
   findu(vars, &utx, 0.5*acc1);

   /* does convergence factor help */
   if (vars->c!=0.0  && almx>0.07*wnstd) {
      tausq = 0.25*acc1/coeff(vars, vars->c);
      if (vars->fail) vars->fail = 0;
      else if (truncation(vars, utx, tausq) < 0.2*acc1) {
         vars->sigsq += tausq;
         findu(vars, &utx, 0.25*acc1);
      }
   }
   acc1 *= 0.5;

      /* find RANGE of distribution, quit if outside this */
   l1:
      d1 = cutoff(vars, acc1, &up) - vars->c;
      if (d1 < 0.0) {
         qfval = 1.0;
         return qfval;
      }
      d2 = vars->c - cutoff(vars, acc1, &un);
      if (d2 < 0.0) {
         qfval = 0.0;
         return qfval;
      }

      /* find integration interval */
      if (d1>d2) intv = LAL_TWOPI/d1;
      else intv = LAL_TWOPI/d2;

      /* calculate number of terms required for main and auxillary integrations */
      xnt = utx/intv;
      xntm = 3.0/sqrt(acc1);

      if (xnt>xntm*1.5) {
         //parameters for auxillary integration
         if (xntm>xlim) {
            *ifault = 1;
            return qfval;
         }
         ntm = (INT4)round(xntm);
         intv1 = utx/ntm;
         x = LAL_TWOPI/intv1;
         if (x<=fabs(vars->c)) goto l2;

         //calculate convergence factor
         REAL8 coeffvalplusx = coeff(vars, vars->c+x);
         REAL8 coeffvalminusx = coeff(vars, vars->c-x);
         tausq = (1.0/3.0)*acc1/(1.1*(coeffvalminusx + coeffvalplusx));
         if (vars->fail) goto l2;
         acc1 = (2.0/3.0)*acc1;

         //auxillary integration
         //fprintf(stderr,"Num terms in auxillary integration %d\n", ntm);
         integrate(vars, ntm, intv1, tausq, 0);
         xlim -= xntm;
         vars->sigsq += tausq;

         //find truncation point with new convergence factor
         findu(vars, &utx, 0.25*acc1);
         acc1 *= 0.75;
         goto l1;
      }

      /* main integration */
   l2:
      if (xnt > xlim) {
         *ifault = 1;
         return qfval;
      }
      nt = (INT4)round(xnt);
      //fprintf(stderr,"Num terms in main integration %d\n", nt);
      integrate(vars, nt, intv, 0.0, 1);
      qfval = 0.5 - vars->integrationValue;

      /* test whether round-off error could be significant allow for radix 8 or 16 machines */
      up = vars->integrationError;
      x = up + 0.1*acc;
      for (UINT4 ii=0; ii<4; ii++) {
         if (rats[ii] * x == rats[ii] * up) *ifault = 2;
      }

      return qfval;
} /* cdfwchisq() */
コード例 #16
0
void game_manager::init(int w, int h) {
    WINDOW_WIDTH = w;
    WINDOW_HEIGHT = h;

    last_time_ = glutGet(GLUT_ELAPSED_TIME);

    auto frog_ = std::make_shared<frog>();
    frog_->position() = vector3(0.0, FROG_LEVEL, 1.95);
    frog_->scale(0.1);
    game_objects_.push_back(frog_);
    collision_manager::instance().register_object(frog_);

    auto car1_ = std::make_shared<car>();
    car1_->position() = vector3(-1.2, ROAD_LEVEL, LINE_4);
    car1_->scale(0.1);
    car1_->speed().x() = 1.0;
    game_objects_.push_back(car1_);
    collision_manager::instance().register_object(car1_);

    for (int i = 0; i < 3; i++) {
        auto truck_ = std::make_shared<truck>();
        truck_->position() = vector3(-1.5 + i * 1.5, ROAD_LEVEL, LINE_3);
        truck_->scale(0.1);
        truck_->speed().x() = 0.5;
        game_objects_.push_back(truck_);
        collision_manager::instance().register_object(truck_);
    }

    auto bus1_ = std::make_shared<bus>();
    bus1_->position() = vector3(0.9, ROAD_LEVEL, LINE_5);
    bus1_->scale(0.1);
    bus1_->speed().x() = 1.5;
    game_objects_.push_back(bus1_);
    collision_manager::instance().register_object(bus1_);

    auto bus2_ = std::make_shared<bus>();
    bus2_->position() = vector3(-0.1, ROAD_LEVEL, LINE_4);
    bus2_->scale(0.1);
    bus2_->speed().x() = 1.0;
    game_objects_.push_back(bus2_);
    collision_manager::instance().register_object(bus2_);

    for (int i = 0; i < 2; i++) {
        auto log_ = std::make_shared<timberlog>();
        log_->position() = vector3(-0.6 + i * 2.0, RIVER_LEVEL, LINE_1);
        log_->scale(0.1);
        log_->speed().x() = 0.5;
        game_objects_.push_back(log_);
        collision_manager::instance().register_object(log_);

        auto log1_ = std::make_shared<timberlog>();
        log1_->position() = vector3(-1.1 + i * 1.9, RIVER_LEVEL, LINE_2);
        log1_->scale(0.1);
        log1_->speed().x() = 0.75;
        game_objects_.push_back(log1_);
        collision_manager::instance().register_object(log1_);
    }

    for (int i = 0; i < 4; i++) {
        auto turtle_ = std::make_shared<turtle>();
        turtle_->position() =
            vector3(-2.5 + i * 1.3, RIVER_LEVEL + 0.05, LINE_6);
        turtle_->scale(0.1);
        turtle_->speed().x() = 0.75;
        game_objects_.push_back(turtle_);
        collision_manager::instance().register_object(turtle_);
    }

    auto river_ = std::make_shared<river>();
    river_->position() = vector3(0.0, 0.0, LINE_1);
    game_objects_.push_back(river_);
    collision_manager::instance().register_object(river_);

    auto tunnel_ = std::make_shared<tunnel>();
    tunnel_->position() = vector3(0.0, 0.0, LINE_1);
    game_objects_.push_back(tunnel_);

    auto road_ = std::make_shared<road>();
    road_->position() = vector3(0.0, 0.0, LINE_4);
    game_objects_.push_back(road_);

    // INVALID CAMERAS: they will be set correctly on reshape
    // Camera 0: top view orthogonal camera
    cameras_.push_back(std::make_shared<orthogonal_camera>());
    cameras_.back()->eye().set(0.0, 0.0, 0.0);
    cameras_.back()->at().set(0.0, -1.0, 0.0);
    cameras_.back()->up().set(0.0, 0.0, -1.0);

    // Camera 1: top view perspective camera
    cameras_.push_back(std::make_shared<perspective_camera>());
    cameras_.back()->eye().set(0.0, 3.0, 2.0);
    cameras_.back()->at().set(0.0, 0.0, 0.0);
    cameras_.back()->up().set(0.0, 0.0, -1.0);

    // Camera 2: frog perspective camera
    cameras_.push_back(frog_->cam());

    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT0));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT1));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT2));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT3));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT4));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT5));
    light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT6));
    light_sources_.push_back(frog_->headlight());

    auto light = light_sources_[0];
    light->ambient().set(0.2, 0.2, 0.2, 1.0);
    light->diffuse().set(0.3, 0.3, 0.3, 1.0);
    light->position().set(0.0, 5.0, 0.0, 1.0);
    light->turn_on();
    light->toggle_key() = 'n';

    for (size_t i : {1, 2, 3, 4, 5, 6}) {
        light = light_sources_[i];
        light->toggle_key() = 'c';
        light->diffuse().set(0.23, 0.23, 0.23, 1.0);
        light->turn_off();

        light->position().x() = i % 2 == 0 ? 2.0 : -2.0;
        light->direction().x() = -light->position().x() / 2;

        light->position().y() = 1.5;
        light->direction().y() = -light->position().y();

        light->position().z() = -2.0 + 2.0 * ((i - 1) / 2);
        light->direction().z() = -light->position().z() / 2;

        // make positional light
        light->position().w() = 1;
        light->cutoff() = 30;
        light->exponent() = 15;
    }
}
コード例 #17
0
ファイル: worm.c プロジェクト: FredrIQ/fiqhack
/*  cutworm()
 *
 *  Check for mon->wormno before calling this function!
 *
 *  When hitting a worm (worm) at position x, y, with a weapon (weap),
 *  there is a chance that the worm will be cut in half, and a chance
 *  that both halves will survive.
 */
void
cutworm(struct monst *worm, xchar x, xchar y, struct obj *weap)
{
    struct wseg *curr, *new_tail;
    struct monst *new_worm;
    int wnum = worm->wormno;
    int cut_chance, new_wnum;

    if (!wnum)
        return; /* bullet proofing */

    if (x == worm->mx && y == worm->my)
        return; /* hit on head */

    /* cutting goes best with a bladed weapon */
    cut_chance = rnd(20);       /* Normally 1-16 does not cut */
    /* Normally 17-20 does */

    if (weap && objects[weap->otyp].oc_dir & SLASH)
        cut_chance += 10;       /* With a slashing weapon 1- 6 does not cut */
    /* 7-20 does */

    if (cut_chance < 17)
        return; /* not good enough */

    /* Find the segment that was attacked. */
    curr = level->wtails[wnum];

    while ((curr->wx != x) || (curr->wy != y)) {
        curr = curr->nseg;
        if (!curr) {
            impossible("cutworm: no segment at (%d,%d)", (int)x, (int)y);
            return;
        }
    }

    /* If this is the tail segment, then the worm just loses it. */
    if (curr == level->wtails[wnum]) {
        shrink_worm(wnum);
        return;
    }

    /* 
     *  Split the worm.  The tail for the new worm is the old worm's tail.
     *  The tail for the old worm is the segment that follows "curr",
     *  and "curr" becomes the dummy segment under the new head.
     */
    new_tail = level->wtails[wnum];
    level->wtails[wnum] = curr->nseg;
    curr->nseg = NULL;  /* split the worm */

    /* 
     *  At this point, the old worm is correct.  Any new worm will have
     *  it's head at "curr" and its tail at "new_tail".
     */

    /* Sometimes the tail end dies. */
    if (rn2(3) || !(new_wnum = get_wormno(level)) || !worm->m_lev) {
        cutoff(worm, new_tail);
        return;
    }

    remove_monster(level, x, y);        /* clone_mon puts new head here */
    if (!(new_worm = clone_mon(worm, x, y))) {
        cutoff(worm, new_tail);
        return;
    }
    new_worm->wormno = new_wnum;        /* affix new worm number */

    /* Devalue the monster level of both halves of the worm. */
    worm->m_lev =
        ((unsigned)worm->m_lev <=
         3) ? (unsigned)worm->m_lev : max((unsigned)worm->m_lev - 2, 3);
    new_worm->m_lev = worm->m_lev;

    /* Calculate the mhp on the new_worm for the (lower) monster level. */
    new_worm->mhpmax = new_worm->mhp = dice((int)new_worm->m_lev, 8);

    /* Calculate the mhp on the old worm for the (lower) monster level. */
    if (worm->m_lev > 3) {
        worm->mhpmax = dice((int)worm->m_lev, 8);
        if (worm->mhpmax < worm->mhp)
            worm->mhp = worm->mhpmax;
    }

    level->wtails[new_wnum] = new_tail; /* We've got all the info right now */
    level->wheads[new_wnum] = curr;     /* so we can do this faster than */
    level->wgrowtime[new_wnum] = 0L;    /* trying to call initworm().  */

    /* Place the new monster at all the segment locations. */
    place_wsegs(new_worm);

    if (flags.mon_moving)
        pline(msgc_monneutral, "%s is cut in half.", Monnam(worm));
    else
        pline(msgc_combatgood, "You cut %s in half.", mon_nam(worm));
}
コード例 #18
0
static int command_battcutoff(int argc, char **argv)
{
	return cutoff();
}
コード例 #19
0
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
	return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
コード例 #20
0
void MO_matrix_blas::updateLap(
  Sample_point * sample, 
  int e, 
  int listnum,
  Array2 <doublevar> & newvals) {

#ifdef USE_BLAS
  int centermax=centers.size();

  assert(e < sample->electronSize());
  assert(newvals.GetDim(1) >=5);


  Array1 <doublevar> R(5);
  static Array2 <doublevar> symmvals_temp(maxbasis,5);
  static Array2 <doublevar> newvals_T;
  Array2 <doublevar> & moCoefftmp(moCoeff_list(listnum));
  int totbasis=moCoefftmp.GetDim(0);
  int nmo_list=moCoefftmp.GetDim(1);
  newvals_T.Resize(5, nmo_list);
  newvals_T=0.0;

  int b;
  int totfunc=0;
  
  centers.updateDistance(e, sample);

  static Array1 <MOBLAS_CalcObjLap> calcobjs(totbasis);
  int ncalcobj=0;
  

  for(int ion=0; ion < centermax; ion++)  {
    centers.getDistance(e, ion, R);
    for(int n=0; n< centers.nbasis(ion); n++) {
      b=centers.basis(ion, n);
      if(R(0) < obj_cutoff(b)) {
        basis(b)->calcLap(R, symmvals_temp);
        int imax=nfunctions(b);
        for(int i=0; i< imax; i++) {
          if(R(0) < cutoff(totfunc)) {
            calcobjs(ncalcobj).moplace=moCoefftmp.v+totfunc*nmo_list;
            
            for(int j=0; j< 5; j++) {
              calcobjs(ncalcobj).sval[j]=symmvals_temp(i,j);
              //cblas_daxpy(nmo_list,symmvals_temp(i,j),
              //            moCoefftmp.v+totfunc*nmo_list,1,
              //            newvals_T.v+j*nmo_list,1);
            }           
            ncalcobj++;
          }
          totfunc++;
        }
      }
      else {
        totfunc+=nfunctions(b);
      }
    }
  }

  for(int i=0; i< ncalcobj; i++) { 
    for(int j=0; j< 5; j++) { 
      cblas_daxpy(nmo_list,calcobjs(i).sval[j],calcobjs(i).moplace,1,
          newvals_T.v+j*nmo_list,1);
    }
    //cblas_dger(CblasRowMajor,5,nmo_list,1.,
    //      calcobjs(i).sval,1,
    //      calcobjs(i).moplace,1,
    //      newvals_T.v,nmo_list);
  }
  

  for(int m=0; m < nmo_list; m++) {
    for(int j=0; j< 5; j++) {
      newvals(m,j)=newvals_T(j,m);
    }
  }

#else
  error("BLAS libraries not compiled in, so you cannot use BLAS_MO");
#endif

}
コード例 #21
0
int board_cut_off_battery(void)
{
	return cutoff();
}