Exemple #1
0
    /**
     * Constructor
     * @param n polynom degree
     * @param coeff polynom coefficient from highest degree
     */
    Polynom(int n, double *coeff) {
        BNB_ASSERT(n >= 3);
        setDim(1);
        mN = n;
        mF = (double*)malloc((n + 1) * sizeof(double));
        mDF = (double*)malloc((n + 1) * sizeof(double));
        mDDF = (double*)malloc((n + 1) * sizeof(double));
        mDDDF = (double*)malloc((n + 1) * sizeof(double));
        for(int i = 0; i <= n; i ++) {
            mF[i] = coeff[i];
        }
        derive(n, mF, mDF);
        derive(n - 1, mDF, mDDF);
        derive(n - 2, mDDF, mDDDF);
        printf("\nDF: ");
        for(int i = 0; i <= (n - 1); i ++)
            printf("%lf ", mDF[i]);
        printf("\nDDF: ");
        for(int i = 0; i <= (n - 2); i ++)
            printf("%lf ", mDDF[i]);
        printf("\nDDDF: ");
        for(int i = 0; i <= (n - 3); i ++)
            printf("%lf ", mDDDF[i]);

    }
bool ContainerViewUI::calcAndSetDimRecursive()
{
	for (auto i=children.begin(); i!=children.end(); i++)
	{
		(*i)->calcAndSetDimRecursive();
	}
	
	return setDim(calcDim());
}
Exemple #3
0
    void dismiss ()
    {
//      BNB_ASSERT(mMemManager == MMRegistry::getMemManager());
      if(mDim > 0) {
	(*(int*)(mCounterBlock.mP))--;
	if ((*(int*)(mCounterBlock.mP)) == 0){
	  mMemManager->free(mXBlock);
	  mMemManager->free(mCounterBlock);
	}
	setDim(0);
      }
    }
Exemple #4
0
    void assign(const SmartArrayPtr& sp)
    {
      if(sp.mDim > 0) {
	if(mMemManager != sp.mMemManager) {
	  alloc(sp.mDim);
	  for(int i = 0; i < sp.mDim; i ++) 
	    ((T*)mXBlock.mP)[i] = sp[i];
	} else {
	  mCounterBlock = sp.mCounterBlock;
	  mXBlock = sp.mXBlock;
	  (*(int*)(mCounterBlock.mP))++;
	}
      }
      setDim(sp.mDim);
    }
Exemple #5
0
template <class T> Vector<T>& Vector<T>::operator+= (const Vector<T>& w)

/*
  Operator += for Vectors always makes sure that there is enough
  space.
*/

{
  if (w.dim() > dim())  /* enlarge v if necessary and extend by zero */
    setDim(w.dim());

  for (Ulong j = 0; j < w.dim(); j++)
    d_list[j] += w[j];

  return *this;
}
Exemple #6
0
    /**
     * Allocate memory for this pointer
     *
     * @param num number of items
     *
     */
    void alloc (unsigned int num)
    {
      if(mMemManager == NULL) {
	mMemManager = MMRegistry::getMemManager();
      }
      //BNB_ASSERT(mMemManager == MMRegistry::getMemManager());
      if(mDim != 0) {
        BNB_ERROR_REPORT("Trying to allocate non-null pointer");
      }	
      if(num > 0) {
	setDim(num);
	mCounterBlock = mMemManager->alloc(sizeof(int));
	*((int*)mCounterBlock.mP) = 1;
	mXBlock = mMemManager->alloc(sizeof(T) * num);
      }
    }
Exemple #7
0
CubeBox& CubeBox::operator=(KCubeBoxWidget& box)
{
   if(dim()!=box.dim())
   {
      setDim(box.dim());
   }

   for(int i=0;i<dim();i++)
      for(int j=0;j<dim();j++)
      {
         *cubes[i][j]=*box[i][j];
      }

   currentPlayer=(CubeBox::Player)box.player();

   return *this;
}
Exemple #8
0
CubeBox& CubeBox::operator=(const CubeBox& box)
{
   if(this!=&box)
   {
      if(dim()!=box.dim())
      {
         setDim(box.dim());
      }


      for(int i=0;i<dim();i++)
         for(int j=0;j<dim();j++)
         {
            *cubes[i][j]=*box.cubes[i][j];
         }
   }

   currentPlayer=box.currentPlayer;

   return *this;
}
Exemple #9
0
DSDetails::DSDetails(DSDetails &d)
	{
	setMin(d.min);
	setMax(d.max);
	setDim(d.dim);
	}
Exemple #10
0
SEXP readBGEN2List(BGenFile* bin) {
  // Rprintf("vcfColumn.size() = %u\n", FLAG_vcfColumn.size());
  // Rprintf("vcfInfo.size() = %u\n", FLAG_infoTag.size());
  // Rprintf("vcfIndv.size() = %u\n", FLAG_indvTag.size());
  // also append sample names at the end
  // 7: chrom, pos, varId, rsId, alleles, isPhased, prob, sampleId
  int retListLen = 8;
  if (retListLen == 0) {
    return R_NilValue;
  }

  int numAllocated =
      0;  // record how many times we allocate (using PROTECT in R);
  SEXP ret;
  PROTECT(ret = allocVector(VECSXP, retListLen));
  numAllocated++;

  //  store results
  std::vector<std::string> idVec;
  std::vector<std::string> chrom;
  std::vector<int> pos;
  std::vector<std::string> varId;
  std::vector<std::string> rsId;
  std::vector<std::string> alleles;
  // std::vector<std::vector<bool> > missing;
  std::vector<bool> isPhased;
  std::vector<std::vector<double> >
      prob;  // prob[variant][each_sample * (prob1, prob2, ...)]

  // std::map<std::string, std::vector<std::string> > infoMap;

  // std::map<std::string, std::vector<std::string> > indvMap;
  /// int nRow = 0;  // # of positions that will be outputed

  // get effective sample names
  const int N = bin->getNumSample();
  std::vector<std::string> sm = bin->getSampleIdentifier();  // all sample names
  std::vector<std::string>& names = idVec;
  if (!sm.size()) {
    char buf[1024];
    for (int i = 0; i < N; ++i) {
      sprintf(buf, "sample_%d", i);
      sm.push_back(buf);
    }
  }

  const size_t sampleSize = bin->getNumEffectiveSample();
  for (size_t i = 0; i != sampleSize; ++i) {
    names.push_back(sm[bin->getEffectiveIndex(i)]);
  }

  // real working part
  int nRecord = 0;
  const int numProbValues =
      3;  // if multi-allelic/multi-haploid, this value can be different
  int maxProbValues = -1;
  while (bin->readRecord()) {
    // REprintf("read a record\n");
    const BGenVariant& var = bin->getVariant();
    const size_t sampleSize = bin->getNumEffectiveSample();

    // store results here
    nRecord++;
    chrom.push_back(var.chrom);
    pos.push_back(var.pos);
    varId.push_back(var.varid);
    rsId.push_back(var.rsid);
    alleles.push_back(toString(var.alleles, ","));
    isPhased.push_back(var.isPhased);
    prob.resize(nRecord);

    std::vector<double>& p = prob[nRecord - 1];
    p.reserve(sampleSize * numProbValues);

    for (size_t i = 0; i != sampleSize; ++i) {
      int beg = var.index[bin->getEffectiveIndex(i)];
      int end = var.index[bin->getEffectiveIndex(i) + 1];
      if (end - beg > maxProbValues) {
        maxProbValues = end - beg;
      }
      for (int j = 0; j < numProbValues; ++j) {
        if (j < numProbValues) {
          p.push_back(var.prob[beg + j]);
        } else {
          p.push_back(-9);
        }
      }
      // REprintf("beg = %d, end = %d, prob[%d][%d] len = %d\n", beg,end,
      // nRecord - 1, i, p[i].size());
    }

    // Rprintf("Done add indv\n");
  }  // end while
  if (maxProbValues > numProbValues) {
    REprintf("some sample has more than %d > %d probabilities per variant!\n",
             maxProbValues, numProbValues);
  }

  // pass value back to R (see Manual Chapter 5)
  std::vector<std::string> listNames;
  int retListIdx = 0;
  storeResult(chrom, ret, retListIdx++);
  storeResult(pos, ret, retListIdx++);
  storeResult(varId, ret, retListIdx++);
  storeResult(rsId, ret, retListIdx++);
  storeResult(alleles, ret, retListIdx++);
  storeResult(isPhased, ret, retListIdx++);
  storeResult(prob, ret, retListIdx);
  for (size_t i = 0; i != prob.size(); ++i) {
    SEXP s = VECTOR_ELT(VECTOR_ELT(ret, retListIdx), i);
    setDim(numProbValues, sampleSize, s);
  }

  retListIdx++;
  listNames.push_back("chrom");
  listNames.push_back("pos");
  listNames.push_back("varid");
  listNames.push_back("rsid");
  listNames.push_back("alleles");
  listNames.push_back("isPhased");
  listNames.push_back("probability");

  // store sample ids
  // Rprintf("set sample id");
  listNames.push_back("sampleId");
  storeResult(idVec, ret, retListIdx++);

  // Rprintf("set list names\n");
  SEXP sListNames;
  PROTECT(sListNames = allocVector(STRSXP, listNames.size()));
  numAllocated++;
  for (unsigned int i = 0; i != listNames.size(); ++i) {
    SET_STRING_ELT(sListNames, i, mkChar(listNames[i].c_str()));
  }
  setAttrib(ret, R_NamesSymbol, sListNames);

  // finish up
  UNPROTECT(numAllocated);
  // Rprintf("Unprotected: %d\n", (retListLen + 1));
  return (ret);
}
Exemple #11
0
void FeatPyramid::featpyramid (const IplImage *im, const Model *model, int padX, int padY)
{
  float sbin, interval;
  float sc;
  int imsize[2];
  float maxScale;
  IplImage *imAux = NULL;
  int pad[3];

  if (padX == -1 && padY == -1)
  {
    padX = getPaddingX(model);
    padY = getPaddingY(model);
  }

  sbin = (float)model->getSbin();
  interval = (float) model->getInterval()+1.0;
  sc = pow (2, 1/(interval));
  imsize[0] = im->height;
  imsize[1] = im->width;
  maxScale = 1 + floor ( log ( min (imsize[0], imsize[1]) /
  (5*sbin) ) / log(sc) );

  // It is the number of elements that will contain pyramid->features
  // and pyramid->scales. At less must be 2*interval
  if ( (maxScale + interval) < (2*interval) )
    setDim (int(2*interval));

  else
    setDim (int(maxScale + interval));

  assert (getDim() > 0);
//  _feat = new CvMatND* [getDim()];    // Suspicious
  _feat.reserve(getDim());
  for (int i = 0; i < getDim(); i++) // Pre-allocate memory
	  _feat.push_back(cv::Mat());
//  assert (_feat != NULL);
  assert(!_feat.empty());
  _scales = new float [getDim()]; // Suspicious
  assert (_scales != NULL);

  // Field imsize is setted
  assert (imsize[0] > 0);
  assert (imsize[1] > 0);

  setImSize (imsize);
//cout << "Antes de bucle featpyramid" << endl;
  for (int i = 0; i < interval; i++)
  {
    // Image is resized
    imAux = resize (im, (1/pow(sc, i)));

    // "First" 2x interval
    //setFeat(process(imAux, sbin/2), i);
	setFeat(process2(imAux, sbin/2), i);
    setScales(2/pow(sc, i), i);

    // "Second" 2x interval
    //setFeat (process (imAux, sbin), (int)(i+interval));
	setFeat (process2 (imAux, sbin), (int)(i+interval));
    setScales (1/pow(sc, i), (int)(i+interval));

    // Remaining intervals
    IplImage *imAux2; // mjmarin added
    for (int j = (int)(i+interval); j < (int)maxScale; j = j+(int)interval)
    {
      // mjmarin: memory leak fixed
      //imAux = resize (imAux, 0.5); // Old sentence
      imAux2 = resize (imAux, 0.5);
      cvReleaseImage(&imAux);
      imAux = imAux2;

      //setFeat (process (imAux, sbin), (int)(j+interval));
	  setFeat (process2 (imAux, sbin), (int)(j+interval));
      setScales ((float)(0.5 * getScales()[j]), (int)(j+interval));
    }

    // mjmarin: more release needed for imAux
    cvReleaseImage(&imAux);
  }
  // Second loop
  for (int i = 0; i < getDim(); i++ )
  {
    // Add 1 to padding because feature generation deletes a 1-cell
    // Wide border around the feature map
    pad[0] = padY + 1;
    pad[1] = padX + 1;
    pad[2] = 0;    
    
    //CvMatND* tmpfeat = getFeat()[i];
	cv::Mat tmpfeat = getFeat()[i];
	CvMatND tmpND = tmpfeat;
    //CvMatND* tmppad = padArray (tmpfeat, pad, 0);
	CvMatND* tmppad = padArray (&tmpND, pad, 0);
    setFeat (tmppad, i);
    //cvReleaseMatND(&tmpfeat); // mjmarin: commented out since it should be auto released with use of cv::Mat
    

    // Write boundary occlusion feature
	cv::Mat fMat = getFeat()[i];
    for (int j = 0; j <= padY; j++)
      //for (int k = 0; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = 0; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = getFeat()[i]->dim[0].size - padY -1; j < getFeat()[i]->dim[0].size; j++)
	for (int j = fMat.size.p[0] - padY -1; j < fMat.size.p[0]; j++)
      //for (int k = 0; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = 0; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = 0; j < getFeat()[i]->dim[0].size; j++)
	for (int j = 0; j < fMat.size.p[0]; j++)
      for (int k = 0; k <= padX; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = 0; j < getFeat()[i]->dim[0].size; j++)
	for (int j = 0; j < fMat.size.p[0]; j++)
      //for (int k = getFeat()[i]->dim[1].size - padX - 1; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = fMat.size.p[1] - padX - 1; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;
  }

  setPadX (padX);
  setPadY (padY);
}
Exemple #12
0
 Sinus ()
 {
   setDim(1);
 }
Exemple #13
0
 void setRNABase(RNABase<double>* base)
 {
   mRNABase = base;
   setDim(base->getDim());
   mAux.alloc(base->getDim());
 }
void CollisionBox::setDim(vec3 d)
{
	//sets the dimensions of the box
	setDim((float)d.x, (float)d.y,(float)d.z);
}
Exemple #15
0
// Set our default damage, position and velocity
Projectile::Projectile()
{
	setDamage(1);
	
	switch (rand() % 10)
	{
	case 0:
		setPos(Vector2(-10, 0));
		break;
	case 1:
		setPos(Vector2(-20, 0));
		break;
	case 2:
		setPos(Vector2(-10, -10));
		break;
	case 3:
		setPos(Vector2(10, 10));
		break;
	case 4:
		setPos(Vector2(10, -10));
		break;
	case 5:
		setPos(Vector2(10, -20));
		break;
	case 6:
		setPos(Vector2(20, -10));
		break;
	case 7:
		setPos(Vector2(-10, 20));
		break;
	case 8:
		setPos(Vector2(-20, 10));
		break;
	case 9:
		setPos(Vector2(-10, 30));
		break;
	default:
		setPos(Vector2(-30, 10));
		break;
		break;
	}

	setVel(Vector2(0, 0));
	setDim(Vector2(16, 16));

	accRate = 8;
	attackSpeed = 12;
	maxSpeed = 10;

	attackTimer = 2;
	timerSet = false;

	dest = Vector2(0, 0);
	attacking = false;

	setSpriteName("Projectile");

	if (!loaded)
	{
		loadTexture(getSpriteName(), "../textures/projectile.png", 1, 1);
		loaded = true;
	}
}
Exemple #16
0
 /**
  * The constructor
  */
 SmartArrayPtr (unsigned int num = 0)
 {
   mMemManager = NULL;
   setDim(0);
   alloc(num);
 }