void LfpDisplayCanvas::renderOpenGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // clear buffers to preset values //glClear(GL_COLOR_BUFFER_BIT); // clear buffers to preset values if (animationIsActive) updateScreenBuffer(); for (int i = 0; i < nChans; i++) { bool isSelected = false; if (selectedChan == i) isSelected = true; if (checkBounds(i)) { //setViewport(i); //drawBorder(isSelected); drawWaveform(i,isSelected); drawChannelInfo(i,isSelected); } } drawScrollBars(); drawProgressBar(); drawTimeline(); // glFlush(); swapBuffers(); }
void smoothDepth( const Mat1f &scale_map, const Mat1d &ii_depth_map, const Mat_<uint32_t>& ii_depth_count, float base_scale, Mat1f &depth_out ) { float nan = std::numeric_limits<float>::quiet_NaN(); depth_out.create( ii_depth_map.rows-1, ii_depth_map.cols-1 ); for ( int y = 0; y < ii_depth_map.rows-1; y++ ) { for ( int x = 0; x < ii_depth_map.cols-1; ++x ) { float s = scale_map[y][x] * base_scale + 0.5f; if ( isnan(s) ) { depth_out(y,x) = nan; continue; } if ( s < 5 ) s=5; const int s_floor = s; const float t = s - s_floor; if ( !checkBounds( ii_depth_map, x, y, 1 ) ) { depth_out(y,x) = nan; continue; } depth_out(y,x) = (1.0-t) * meanDepth( ii_depth_map, ii_depth_count, x, y, s_floor ) + t * meanDepth( ii_depth_map, ii_depth_count, x, y, s_floor+1 ); } } }
void ScrollBarWidget::handleMouseMoved(int x, int y, int button) { // Do nothing if there are less items than fit on one page if (_numEntries <= _entriesPerPage) return; if (_draggingPart == kSliderPart) { int old_pos = _currentPos; _sliderPos = y - _sliderDeltaMouseDownPos; if (_sliderPos < UP_DOWN_BOX_HEIGHT) _sliderPos = UP_DOWN_BOX_HEIGHT; if (_sliderPos > _h - UP_DOWN_BOX_HEIGHT - _sliderHeight) _sliderPos = _h - UP_DOWN_BOX_HEIGHT - _sliderHeight; _currentPos = (_sliderPos - UP_DOWN_BOX_HEIGHT) * (_numEntries - _entriesPerPage) / (_h - 2 * UP_DOWN_BOX_HEIGHT - _sliderHeight); checkBounds(old_pos); } else { int old_part = _part; if (y <= UP_DOWN_BOX_HEIGHT) // Up arrow _part = kUpArrowPart; else if (y >= _h - UP_DOWN_BOX_HEIGHT) // Down arrow _part = kDownArrowPart; else if (y < _sliderPos) _part = kPageUpPart; else if (y >= _sliderPos + _sliderHeight) _part = kPageDownPart; else _part = kSliderPart; if (old_part != _part) draw(); } }
double Matrix::get(int i, int j){ checkBounds(i, j); return data[i * columns + j]; }
static void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble* buf) { if (!checkBounds((Env*) env, (Array*) array, start, len)) return; memcpy(((DoubleArray*) array)->values + start, buf, sizeof(jdouble) * len); }
static void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean* buf) { if (!checkBounds((Env*) env, (Array*) array, start, len)) return; memcpy(((BooleanArray*) array)->values + start, buf, sizeof(jboolean) * len); }
void ompl::base::ProjectionEvaluator::setBounds(const RealVectorBounds &bounds) { bounds_ = bounds; checkBounds(); }
void* arrayGet(Array* array, int index) { checkBounds(array, index); return array->contents[index]; }
void LinearCombination::setIndex(int i, GridPointIndex *x) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif indexes[i] = x; }
void LinearCombination::setFactor(int i, decimal f) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif factors[i] = f; }
void wlaFlyingObject::update(float deltaTime){ position += direction * speed * deltaTime; checkBounds(); }
bool VMCcuda::run() { if (UseDrift == "yes") return runWithDrift(); resetRun(); IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; IndexType updatePeriod= (QMCDriverMode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks+1)*nSteps; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw); vector<PosType> delpos(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw); vector<GradType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); double Esum; // First do warmup steps for (int step=0; step<myWarmupSteps; step++) { for(int iat=0; iat<nat; ++iat) { //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; ++iw) { PosType G = W[iw]->G[iat]; newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, true); if (W.UseBoundBox) checkBounds (newpos, acc); for(int iw=0; iw<nw; ++iw) { if(acc[iw] && ratios[iw]*ratios[iw] > Random()) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else { acc[iw] = false; nReject++; } } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } do { IndexType step = 0; nAccept = nReject = 0; Esum = 0.0; Estimators->startBlock(nSteps); do { ++step;++CurrentStep; for (int isub=0; isub<nSubSteps; isub++) { for(int iat=0; iat<nat; ++iat) { //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; ++iw) { PosType G = W[iw]->G[iat]; newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, true); if (W.UseBoundBox) checkBounds (newpos, acc); for(int iw=0; iw<nw; ++iw) { if(acc[iw] && ratios[iw]*ratios[iw] > Random()) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else { acc[iw]=false; nReject++; } } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } Psi.gradLapl(W, grad, lapl); H.evaluate (W, LocalEnergy); if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0) W.saveEnsemble(); Estimators->accumulate(W); } while(step<nSteps); Psi.recompute(W); // vector<RealType> logPsi(W.WalkerList.size(), 0.0); // Psi.evaluateLog(W, logPsi); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //Mover->stopRun(); //finalize a qmc section return finalize(block); }
bool VMCcuda::runWithDrift() { resetRun(); IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw), oldScale(nw), newScale(nw); vector<PosType> delpos(nw); vector<PosType> dr(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw), rplus(nw), rminus(nw); vector<PosType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); // First, do warmup steps for (int step=0; step<myWarmupSteps; step++) { for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, true); if (W.UseBoundBox) checkBounds (newpos, acc); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(acc[iw] && Random() < prob) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else { acc[iw] = false; nReject++; } } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } // Now do data collection steps do { IndexType step = 0; nAccept = nReject = 0; Estimators->startBlock(nSteps); do { step++; CurrentStep++; for (int isub=0; isub<nSubSteps; isub++) { for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, true); if (W.UseBoundBox) checkBounds (newpos, acc); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); // if (dot(drOld, drOld) > 25.0) // cerr << "Large drift encountered! Old drift = " << drOld << endl; RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; // if (dot(drNew, drNew) > 25.0) // cerr << "Large drift encountered! Drift = " << drNew << endl; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(acc[iw] && Random() < prob) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else { acc[iw] = false; nReject++; } } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } // cerr << "Rank = " << myComm->rank() << // " CurrentStep = " << CurrentStep << " isub = " << isub << endl; } Psi.gradLapl(W, grad, lapl); H.evaluate (W, LocalEnergy); if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0) W.saveEnsemble(); Estimators->accumulate(W); } while(step<nSteps); Psi.recompute(W); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //finalize a qmc section if (!myComm->rank()) gpu::cuda_memory_manager.report(); return finalize(block); }
// remove trailing rows without actually giving up the space. // DANGER: this trims rows. Not a memory leak but old row length // not "visibibly" saved void Matrix::shorten(int newr) { checkBounds(newr, 0, "shorten"); maxr = newr; }
// remove trailing columns without actually giving up the space. void Matrix::narrow(int newc) { checkBounds(0, newc, "narrow"); maxc = newc; }
void ViewDragger::startup() { checkBounds(true); }
void* arraySet(Array* array, int index, void* pointer) { checkBounds(array, index); void* old = array->contents[index]; array->contents[index] = pointer; return old; }
void LinearCombination::setPoint(int i, State *s) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif points[i] = s; }
void stateUpdate() { while(server.hasGameStarted()) { float elapsedTime = deltaClock.getElapsedTime().asMilliseconds(); float ballElapsedTime = ballClock.getElapsedTime().asMilliseconds(); ballSendTimer += elapsedTime; ballClock.restart(); if(elapsedTime >= 16.6) { deltaClock.restart(); //Update the ball's position. ballRect = sf::FloatRect(ballRect.left + ballVelocity.x, ballRect.top + ballVelocity.y, ballRect.width, ballRect.height); } //Check for paddle collisions. if(ballRect.intersects(onePaddleRect) && ballVelocity.x < 0) { ballVelocity.x *= (-1.0f); std::cout << "Ball rebound off Paddle One." << std::endl; ballCollisionDetected = true; } else if(ballRect.intersects(twoPaddleRect) && ballVelocity.x > 0) { ballVelocity.x *= (-1.0f); std::cout << "Ball rebound off Paddle Two." << std::endl; ballCollisionDetected = true; } checkBounds(); //Check and manage points for both players. if(ballRect.left <= LEFT_WALL + 3 && ballVelocity.x < 0) { server.sendAll("3 2"); player2Points++; std::cout << "Player 2 Score update: " << player2Points << std::endl; //Send the end game message if player 2 wins. if(player2Points >= MAX_POINTS) { server.sendAll("4 2"); server.stopGame(); std::cout << "Player Two win with points." << std::endl; } ballRect = sf::FloatRect(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, BALL_WIDTH, BALL_HEIGHT); ballCollisionDetected = true; } if(ballRect.left + ballRect.width >= SCREEN_WIDTH - 3 && ballVelocity.x > 0) { server.sendAll("3 1"); player1Points++; std::cout << "Player 1 Score update: " << player1Points << std::endl; //Send the end game message if player 1 wins. if(player1Points >= MAX_POINTS) { server.sendAll("4 1"); server.stopGame(); std::cout << "Player One win with points." << std::endl; } ballRect = sf::FloatRect(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, BALL_WIDTH, BALL_HEIGHT); ballCollisionDetected = true; std::cout << "Collided" << std::endl; } if(ballCollisionDetected || ballSendTimer >= (1/60)) { ballSendTimer = 0; std::time_t rawtime; std::time(&rawtime); //Send the ball packet. std::stringstream ballPacketStringStream; ballPacketStringStream << "1 " << ballRect.left << " " << ballRect.top << " " << ballVelocity.x << " " << ballVelocity.y << " " << (rawtime - ((playerOneLag + playerTwoLag)/2)); server.sendAll(ballPacketStringStream.str()); ballCollisionDetected = false; } } }
decimal LinearCombination::getFactor(int i) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif return factors[i]; }
static void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong* buf) { if (!checkBounds((Env*) env, (Array*) array, start, len)) return; memcpy(buf, ((LongArray*) array)->values + start, sizeof(jlong) * len); }
GridPointIndex *LinearCombination::getIndex(int i) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif return indexes[i]; }
static void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat* buf) { if (!checkBounds((Env*) env, (Array*) array, start, len)) return; memcpy(((FloatArray*) array)->values + start, buf, sizeof(jfloat) * len); }
State *LinearCombination::getPoint(int i) { #if !OPTIMIZE_LINEAR_COMBINATION_CHECKS checkBounds(i); #endif return points[i]; }
END_CLASS /* ================ idAI_Vagary::Event_ChooseObjectToThrow ================ */ void idAI_Vagary::Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset ) { idEntity * ent; idEntity * entityList[ MAX_GENTITIES ]; int numListedEntities; int i, index; float dist; idVec3 vel; idVec3 offsetVec( 0, 0, offset ); idEntity *enemyEnt = enemy.GetEntity(); if ( !enemyEnt ) { idThread::ReturnEntity( NULL ); } idVec3 enemyEyePos = lastVisibleEnemyPos + lastVisibleEnemyEyeOffset; const idBounds &myBounds = physicsObj.GetAbsBounds(); idBounds checkBounds( mins, maxs ); checkBounds.TranslateSelf( physicsObj.GetOrigin() ); numListedEntities = gameLocal.clip.EntitiesTouchingBounds( checkBounds, -1, entityList, MAX_GENTITIES ); index = gameLocal.random.RandomInt( numListedEntities ); for ( i = 0; i < numListedEntities; i++, index++ ) { if ( index >= numListedEntities ) { index = 0; } ent = entityList[ index ]; if ( !ent->IsType( idMoveable::Type ) ) { continue; } if ( ent->fl.hidden ) { // don't throw hidden objects continue; } idPhysics *entPhys = ent->GetPhysics(); const idVec3 &entOrg = entPhys->GetOrigin(); dist = ( entOrg - enemyEyePos ).LengthFast(); if ( dist < minDist ) { continue; } idBounds expandedBounds = myBounds.Expand( entPhys->GetBounds().GetRadius() ); if ( expandedBounds.LineIntersection( entOrg, enemyEyePos ) ) { // ignore objects that are behind us continue; } if ( PredictTrajectory( entPhys->GetOrigin() + offsetVec, enemyEyePos, speed, entPhys->GetGravity(), entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel ) ) { idThread::ReturnEntity( ent ); return; } } idThread::ReturnEntity( NULL ); }
inline double getWeight(int i) { if( checkBounds(i) ) return weight[i]; else return -1.0; };
void Matrix::set(double value, int i, int j){ checkBounds(i, j); data[i * columns + j] = value; }
bool MovementFunction::update(unsigned int frameTime){ t += frameTime; setSDL_RecPos(); return checkBounds(); }
/* * call-seq: put(pointer, value) * @param [AbstractMemory] pointer pointer on a {Struct} * @param [String, Array] value +value+ may be a String only if array's type is a kind of +int8+ * @return [value] * Set an array in a {Struct}. */ static VALUE array_field_put(VALUE self, VALUE pointer, VALUE value) { StructField* f; ArrayType* array; Data_Get_Struct(self, StructField, f); Data_Get_Struct(f->rbType, ArrayType, array); if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) { VALUE argv[2]; argv[0] = INT2FIX(f->offset); argv[1] = value; rb_funcall2(pointer, rb_intern("put_string"), 2, argv); } else { #ifdef notyet MemoryOp* op; int count = RARRAY_LEN(value); int i; AbstractMemory* memory = MEMORY(pointer); if (count > array->length) { rb_raise(rb_eIndexError, "array too large"); } /* clear the contents in case of a short write */ checkWrite(memory); checkBounds(memory, f->offset, f->type->ffiType->size); if (count < array->length) { memset(memory->address + f->offset + (count * array->componentType->ffiType->size), 0, (array->length - count) * array->componentType->ffiType->size); } /* now copy each element in */ if ((op = get_memory_op(array->componentType)) != NULL) { for (i = 0; i < count; ++i) { (*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i)); } } else if (array->componentType->nativeType == NATIVE_STRUCT) { for (i = 0; i < count; ++i) { VALUE entry = rb_ary_entry(value, i); Struct* s; if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) { rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct"); break; } Data_Get_Struct(entry, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size), s->pointer->address, array->componentType->ffiType->size); } } else { rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType)); } #else rb_raise(rb_eNotImpError, "cannot set array field"); #endif } return value; }
void ViewDragger::updateServer() { if (mMomentum.recentlyMoved()) { checkBounds(false); } }