예제 #1
0
 vector<int> searchRange(vector<int>& nums, int target) {
     int n = nums.size();
     vector<int> res(2, -1);
     int lower = getLowerBound(nums, target);
     int upper = getUpperBound(nums, target);
     if(lower <= upper) {
         res[0] = lower;
         res[1] = upper;
     }
     return res;
 }
예제 #2
0
bool CalCoreTrack::getState(float time, CalVector& translation, CalQuaternion& rotation) const
{
  std::vector<CalCoreKeyframe*>::const_iterator iteratorCoreKeyframeBefore;
  std::vector<CalCoreKeyframe*>::const_iterator iteratorCoreKeyframeAfter;

  // get the keyframe after the requested time
  iteratorCoreKeyframeAfter = getUpperBound(time);

  // check if the time is after the last keyframe
  if(iteratorCoreKeyframeAfter == m_keyframes.end())
  {
    // return the last keyframe state
    --iteratorCoreKeyframeAfter;
    rotation = (*iteratorCoreKeyframeAfter)->getRotation();
    translation = (*iteratorCoreKeyframeAfter)->getTranslation();

    return true;
  }

  // check if the time is before the first keyframe
  if(iteratorCoreKeyframeAfter == m_keyframes.begin())
  {
    // return the first keyframe state
    rotation = (*iteratorCoreKeyframeAfter)->getRotation();
    translation = (*iteratorCoreKeyframeAfter)->getTranslation();

    return true;
  }

  // get the keyframe before the requested one
  iteratorCoreKeyframeBefore = iteratorCoreKeyframeAfter;
  --iteratorCoreKeyframeBefore;

  // get the two keyframe pointers
  CalCoreKeyframe *pCoreKeyframeBefore;
  pCoreKeyframeBefore = *iteratorCoreKeyframeBefore;
  CalCoreKeyframe *pCoreKeyframeAfter;
  pCoreKeyframeAfter = *iteratorCoreKeyframeAfter;

  // calculate the blending factor between the two keyframe states
  float blendFactor;
  blendFactor = (time - pCoreKeyframeBefore->getTime()) / (pCoreKeyframeAfter->getTime() - pCoreKeyframeBefore->getTime());

  // blend between the two keyframes
  translation = pCoreKeyframeBefore->getTranslation();
  translation.blend(blendFactor, pCoreKeyframeAfter->getTranslation());

  rotation = pCoreKeyframeBefore->getRotation();
  rotation.blend(blendFactor, pCoreKeyframeAfter->getRotation());

  return true;
}
예제 #3
0
파일: CFitItem.cpp 프로젝트: bmoreau/COPASI
bool CFitItem::updateBounds(std::vector<COptItem * >::iterator it)
{
  while (*it != this)
    {
      if (mpLowerObject && (getLowerBound() == (*it)->getObjectCN()))
        mpLowerBound = &static_cast<CFitItem *>(*it)->getLocalValue();

      if (mpUpperObject && (getUpperBound() == (*it)->getObjectCN()))
        mpUpperBound = &static_cast<CFitItem *>(*it)->getLocalValue();

      ++it;
    }

  return true;
}
예제 #4
0
bool CalCoreMorphTrack::getState(float time, float & weight)
{
  std::vector<CalCoreMorphKeyframe>::iterator iteratorCoreMorphKeyframeBefore;
  std::vector<CalCoreMorphKeyframe>::iterator iteratorCoreMorphKeyframeAfter;

  // get the keyframe after the requested time
  iteratorCoreMorphKeyframeAfter = getUpperBound(time);

  // check if the time is after the last keyframe
  if(iteratorCoreMorphKeyframeAfter == m_keyframes.end())
  {
    // return the last keyframe state
    --iteratorCoreMorphKeyframeAfter;
    weight = (*iteratorCoreMorphKeyframeAfter).getWeight();

    return true;
  }

  // check if the time is before the first keyframe
  if(iteratorCoreMorphKeyframeAfter == m_keyframes.begin())
  {
    // return the first keyframe state
    weight = (*iteratorCoreMorphKeyframeAfter).getWeight();

    return true;
  }

  // get the keyframe before the requested one
  iteratorCoreMorphKeyframeBefore = iteratorCoreMorphKeyframeAfter;
  --iteratorCoreMorphKeyframeBefore;

  // get the two keyframe pointers
  CalCoreMorphKeyframe *pCoreMorphKeyframeBefore;
  pCoreMorphKeyframeBefore = &(*iteratorCoreMorphKeyframeBefore);
  CalCoreMorphKeyframe *pCoreMorphKeyframeAfter;
  pCoreMorphKeyframeAfter = &(*iteratorCoreMorphKeyframeAfter);

  // calculate the blending factor between the two keyframe states
  float blendFactor;
  blendFactor = (time - pCoreMorphKeyframeBefore->getTime()) / (pCoreMorphKeyframeAfter->getTime() - pCoreMorphKeyframeBefore->getTime());

  // blend between the two keyframes
  weight = pCoreMorphKeyframeBefore->getWeight();
  float otherWeight = pCoreMorphKeyframeAfter->getWeight();
  weight += blendFactor * (otherWeight-weight);

  return true;
}
예제 #5
0
파일: GEdge.cpp 프로젝트: fmach/agros2d
bool GEdge::computeDistanceFromMeshToGeometry (double &d2, double &dmax)
{
  d2 = 0.0; dmax = 0.0;
  if (geomType() == Line) return true;
  if (!lines.size())return false;
  IntPt *pts;
  int npts;
  lines[0]->getIntegrationPoints(2*lines[0]->getPolynomialOrder(), &npts, &pts);

  for (unsigned int i = 0; i < lines.size(); i++){
    MLine *l = lines[i];
    double t[256];

    for (int j=0; j< l->getNumVertices();j++){
      MVertex *v = l->getVertex(j);
      if (v->onWhat() == getBeginVertex()){
	t[j] = getLowerBound();
      }
      else if (v->onWhat() == getEndVertex()){
	t[j] = getUpperBound();
      }
      else {
	v->getParameter(0,t[j]);
      }
    }
    for (int j=0;j<npts;j++){
      SPoint3 p;
      l->pnt(pts[j].pt[0],0,0,p);
      double tinit = l->interpolate(t,pts[j].pt[0],0,0);
      GPoint pc = closestPoint(p, tinit);
      if (!pc.succeeded())continue;
      double dsq =
	(pc.x()-p.x())*(pc.x()-p.x()) +
	(pc.y()-p.y())*(pc.y()-p.y()) +
	(pc.z()-p.z())*(pc.z()-p.z());
      d2 += pts[i].weight * fabs(l->getJacobianDeterminant(pts[j].pt[0],0,0)) * dsq;
      dmax = std::max(dmax,sqrt(dsq));
    }
  }
  d2 = sqrt(d2);
  return true;
}
예제 #6
0
	bool AnimationTrack::getFrame(f32 timeMs, KeyFrame& frame) const
	{
		array_t<KeyFrame*>::const_iterator iterKeyframeBefore;
		array_t<KeyFrame*>::const_iterator iterKeyframeAfter;

		// get the key frame after the requested time
		iterKeyframeAfter = getUpperBound(timeMs);

		// check if the time is after the last key frame
		if(iterKeyframeAfter == m_keyFrames.end())
		{
			// return the last key frame
			--iterKeyframeAfter;

			frame = *(*iterKeyframeAfter);
								
			return true;
		}

		// check if the time is before the first key frame
		if(iterKeyframeAfter == m_keyFrames.begin())
		{
			// return the first key frame
			frame = *(*iterKeyframeAfter);			

			return true;
		}

		// get the key frame before the requested one
		iterKeyframeBefore = iterKeyframeAfter;
		--iterKeyframeBefore;

		// get the two key frame
		KeyFrame& keyframeBefore = *(*iterKeyframeBefore);
		KeyFrame& keyframeAfter = *(*iterKeyframeAfter);

		// blend between the two key frames
		//Note: use interp type of compute time blend pct, and use linear for value interp, and should take care of rotation
		frame.interpolateValueFrom(keyframeBefore, keyframeAfter);
		
		return true;
	}
void slave_computation(double start, long iterations)
{	
	int i;
	double size = 1.0/strips;
	long localSum[2]={0,0};
	double xleft, xright;
	long sum[2]={0,0};
	for (i=0; i<iterations; i++)
	{
		xleft=start+i*size;
		xright=start+(i+1)*size;
		localSum[0]+=getUpperBound(xleft);
		localSum[1]+=getLowerBound(xright);
	}
	MPI_Reduce(&localSum,&sum,2,MPI_LONG,MPI_SUM,nprocs-1,MPI_COMM_WORLD);
	//printf("id: %d, sum: %li \n", myid,sum[0]);
	if(myid == nprocs-1)
	{
		double result = (sum[0]+sum[1])/2.0*(size*size);
		printf("Integration result: %.8f", result);
	}
}
예제 #8
0
returnValue VariablesGrid::initializeFromBounds( )
{
    uint run1, run2;

    for( run1 = 0; run1 < getNumPoints(); run1++ ){
        for( run2 = 0; run2 < getNumValues(); run2++ ){

            if( fabs( getLowerBound(run1,run2) ) <  0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) <  0.999*INFTY ){

                operator()(run1,run2) = 0.5*( getLowerBound(run1,run2) + getUpperBound(run1,run2) );

            }

            if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) <  0.999*INFTY ){

                operator()(run1,run2) = getUpperBound(run1,run2);
            }

            if( fabs( getLowerBound(run1,run2) ) <  0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){

                operator()(run1,run2) = getLowerBound(run1,run2);
            }

            if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){

                operator()(run1,run2) = 0.0;
            }
        }
    }

	return SUCCESSFUL_RETURN;
}
예제 #9
0
bool BoundingBox::overlaps(BoundingBox *other) {
  return ( !(getUpperBound() > other->getLowerBound()) &&
	   !(getLowerBound() < other-> getUpperBound()) &&
	   !(getLeftBound() > other->getRightBound()) &&
	   !(getRightBound() < other->getLeftBound()) );
}
예제 #10
0
bool ZIntCuboidFace::isValid() const
{
  return (getLowerBound(0) <= getUpperBound(0)) &&
      (getLowerBound(1) <= getUpperBound(1));
}
예제 #11
0
bool ZIntCuboidFace::contains(ZIntCuboidFace::Corner pt) const
{
  return (pt.getX() >= getLowerBound(0) && pt.getX() <= getUpperBound(0) &&
          pt.getY() >= getLowerBound(1) && pt.getY() <= getUpperBound(1));
}
예제 #12
0
inline unsigned int FMPWPartTmpl<GainTmpl>::
doPartitionInternal(vector<unsigned char>& part) 
{
  typedef FMPartTmpl<FMBiPartCore, GainTmpl> PWPartMgrType; 
  typedef FMPartTmpl4<FMKWayPartCore4, FMKWayGainMgr2> RefineType; 

  unsigned int cost1 = _initCost;
  unsigned int cost = _initCost;

  RefineType rfMgr(getParam());
  rfMgr.setBalanceTol(getBalanceTol());
  rfMgr.setPValue(1);
  rfMgr.setQValue(10);
  rfMgr.setVerbosity(getVerbosity());
  rfMgr.setBoundType(getBoundType());
  rfMgr.noNeedSetHighFanoutNets();

  while (1) {
    initGrouping2();
    getNetlist().pairWisePhase1(part, _groupMap, _sGVec);
    //xxx int cost3 = cost;
    cost = cost1;

    for (unsigned int j=0; j<_numGroups; ++j) {
      const FMParam param(*_sGVec[j]);
      PWPartMgrType PWMgr(param);
      //xxx PWMgr.setBalanceTol(getBalanceTol());
      PWMgr.setUpperBound(getUpperBound());
      PWMgr.setLowerBound(getLowerBound());
      // PWMgr.setPValue(_pvalue);
      // PWMgr.setQValue(_qvalue);
      PWMgr.setVerbosity(getVerbosity());
      //xxx PWMgr.setBoundType(getBoundType());
      PWMgr.noNeedSetHighFanoutNets();
      PWMgr.setNoInit(cost);
      vector<unsigned char> pw_part;
      projectUp(part, pw_part, j);
      // cost = PWMgr.doPartitionOne(pw_part);
      boost::array<int, 64>& diff = getDiff();
      const unsigned int part0 = _groupInvMap[j];
      const unsigned int part1 = _moveTo[part0];
      int diff2[2];
      diff2[0] = diff[part0];
      diff2[1] = diff[part1];
      PWMgr.setDiff(diff2);
      cost = PWMgr.doPartitionOne4(pw_part);
      // PWMgr.doPartition(pw_part, 1);
      // cost = PWMgr.getBestCost();
      projectDown(part, pw_part, j);
      int* diff3 = PWMgr.getDiff();
      diff[part0] = diff3[0];
      diff[part1] = diff3[1];
      delete _sGVec[j];
    }
    // printDiff();
    // std::cout << "cost = " << cost << std::endl;

    assert(cost == getNetlist().cutCost(part, getNumPartitions()));
    //xxx initDiff(part);  

    rfMgr.setNoInit(cost); // only refine the solution
    rfMgr.setDiff(getDiff());
    cost1 = rfMgr.doPartitionOne4(part);
    // rfMgr.doPartition(part, 1);
    // cost1 = rfMgr.getBestCost();
    assert(cost1 == getNetlist().cutCost(part, getNumPartitions()));
    setDiff(rfMgr.getDiff());
    // printDiff();
    // std::cout << "cost1 = " << cost1 << std::endl;

    if (cost1 >= cost) break;
  }


  return cost1;
}