コード例 #1
0
ファイル: Wflograph.cpp プロジェクト: caiograg/grafalgo
/** Copy contents of another Wflograph.
 *  @param original is a weighted flograph to be copied to this object
 */
void Wflograph::copyFrom(const Wflograph& original) {
        if (N != original.n() || maxEdge < original.m()) {
                resize(original.n(), original.m()); 
        } else {
                reset();
        } 
        N = original.n();
        for (edge e = original.first(); e != 0; e = original.next(e)) {
                edge ee = join(original.left(e),original.right(e));
                cpy(ee) = original.cpy(e); cst(ee) = original.cst(e);
                flo(ee) = original.flo(e);
        }
        setSrcSnk(original.src(),original.snk());
        sortAdjLists();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Kansukey/piscine_2019
int	main()
{
  Character leo("leo", 42);
  Character flo("flo", 42);
  Warrior   johann("johann", 56);
  Warrior   raph("raph", 56);

  if (leo.getLvl() != 42 ||
      leo.getPv() != 100 ||
      leo.getPower() != 100 ||
      leo.getName() != "leo" ||
      flo.getName() != "flo")
    {
      std::cout << "CRITICAL ERROR ON DEFAULT VALUES" << std::endl;
      return (-1);
    }
  if (johann.getLvl() != 56 ||
      johann.getPv() != 100 ||
      johann.getPower() != 100 ||
      johann.getName() != "johann" ||
      raph.getName() != "raph")
    {
      std::cout << "CRITICAL ERROR ON DEFAULT VALUES" << std::endl;
      return (-1);
    }
  flo.TakeDamage(leo.CloseAttack());
  flo.Range = Character::RANGE;
  leo.TakeDamage(flo.RangeAttack());

  flo.Heal();
  leo.Range = Character::RANGE;
  flo.TakeDamage(leo.RangeAttack());

  flo.Range = Character::CLOSE;
  leo.TakeDamage(flo.CloseAttack());
  leo.TakeDamage(flo.CloseAttack());

  leo.Heal();

  flo.RestorePower();

  leo.RestorePower();
  leo.RestorePower();
  leo.RestorePower();

  std::cout << leo.getName() << " is being a boss thanks to his food!" << std::endl;

  leo.Range = Character::CLOSE;
  flo.TakeDamage(leo.CloseAttack() * 6);
  if (flo.getPv() > 0)
    std::cout << "CRITICAL ERROR : FLO IS SUPPOSED TO BE DEAD!!" << std::endl;
  flo.TakeDamage(1);

  johann.TakeDamage(leo.CloseAttack());
  raph.Range = Character::RANGE;
  leo.TakeDamage(raph.RangeAttack());
  johann.TakeDamage(raph.RangeAttack());
  johann.TakeDamage(raph.CloseAttack());
  std::cout << leo.getName() << " Life remaining : " << leo.getPv() << std::endl;
  std::cout << leo.getName() << " Power remaining : " << leo.getPower() << std::endl;
  std::cout << johann.getName() << " Life remaining : " << johann.getPv() << std::endl;
  std::cout << johann.getName() << " Power remaining : " << johann.getPower() << std::endl;
  std::cout << raph.getName() << " Life remaining : " << raph.getPv() << std::endl;
  std::cout << raph.getName() << " Power remaining : " << raph.getPower() << std::endl;
  johann.Heal();
  std::cout << johann.getName() << " Life remaining : " << johann.getPv() << std::endl;
  johann.TakeDamage(raph.CloseAttack());
  johann.TakeDamage(raph.CloseAttack());
  johann.TakeDamage(raph.CloseAttack());
  raph.RestorePower();
  johann.TakeDamage(raph.CloseAttack());
  johann.TakeDamage(raph.CloseAttack());
}
コード例 #3
0
// get optical flow field descriptor
void optiflowDescriptor( int gid, int vid, vector<int>&label, vector<vector<float> > &pfeat, 
        vector<vector<float> > &nfeat)
{
	bool useDenseOF = USEDENSE;
    int flen = 50;
    vector<int> mos;
    ldLabel(gid, mos);
    char vname[512];
    Point2i isize;
 
    for(int v = vid; v < vid+1; ++v){
        sprintf(vname, "/home/fengzy/Projects/XProject/dataset/Set%.02d/video/%d.avi", gid, v);
        CvCapture *cap = cvCaptureFromFile(vname);
        if(!cap) continue;

        vector<vector<Point2f> > flo(flen);

        int width = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
        int height= cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
        vector<Point2f> densePt; densePt.reserve( width * height);
        for ( int h = 0; h <height; ++h)
            for ( int w = 0; w < width; ++w)
                densePt.push_back( Point2f(w,h));

        IplImage *pre, *nex;
        nex= cvQueryFrame(cap); pre = cvCreateImage(cvGetSize(nex), 8, 3);
        for(int i = 1; i <= flen; ++i){
            printf("[%d/%d]page\n",i,flen);
            cvCopy(nex, pre);
            nex = cvQueryFrame(cap);
            if(!nex) break;
            Mat mPre(pre), mNex(nex), mask;

            Point2i imgsize = SamplingOpticalFlow(mPre,mNex,mask,densePt, flo[i-1]);
            if(!isize.x) isize=imgsize;
        }
        //	 create histogram
        vector<float> floHist(flo.size()); //// remove the 1st and last frame's optical flow.
        char buff[512];
        sprintf(buff,"/home/fengzy/Projects/XProject/dataset/Set%.02d/feature/%d.txt",gid,v);
        FILE *fp = fopen(buff,"w+");

        vector<float> preFeat;
        vector<vector<float> >derivHist;
        for ( unsigned int nlen = 0; nlen < flo.size(); ++nlen)
        {
            vector<float> hist[4]; float count[4] = {0};
            for( int i = 0; i < 4; ++i) {hist[i] = vector<float>(9, 0);}

            for ( unsigned int ne = 0; ne < flo[nlen].size(); ++ne){
    //			// convert into angle
                float angle = 0, flolen = 1;
                if ( flo[nlen][ne].y ){
                    angle = tan2g(flo[nlen][ne].x, flo[nlen][ne].y);
                    angle = angle > 0 ? angle : 360 + angle;
                    // use flo length as weight
                    flolen = floLen( flo[nlen][ne].x, flo[nlen][ne].y);
                    flolen = flolen == 0 ? 1.0f : flolen;
                }
                int iy = ne/isize.x, ix = ne%isize.x;
                int indx = iy*2/isize.y + ix*2/isize.x;
                int inda = floor(angle/45.0f);
                if (int(angle) == 360) inda = 7;
                if(indx >= 4 || inda >= 8)
                    int db = 1;
                hist[0][inda] += flolen;
                count[0] += flolen;
            }
            vector<float> curFeat; 
            for ( int i = 0; i < 1; ++i)
            {
                // normalize
                if(!count[i]) count[i] = 1;
                transform(hist[i].begin(), hist[i].end(), hist[i].begin(),bind2nd( multiplies<float>(), float(1)/*/(count[i])*/ ));
                hist[i].back() = count[i];
                floHist.insert( floHist.end(), hist[i].begin(), hist[i].end());
                curFeat.insert(curFeat.end(), hist[i].begin(), hist[i].end());
                for(int j = 0; j < hist[i].size(); ++j)
                fprintf(fp,"%.08lf\t",hist[i][j]);
            }
            if( nlen) derivHist.push_back(difFeat(curFeat, preFeat));
            preFeat = curFeat;
            fprintf(fp,"\n");
        }
        for(int nf = 0; nf < derivHist.size(); ++nf){
            for(int ne = 0; ne < derivHist[nf].size(); ++ne)
                fprintf(fp,"%.08lf\t", derivHist[nf][ne]);
            fprintf(fp,"\n");
        }
        fclose(fp);
        
        if(mos[v] >= 0 && mos[v] <= 50) 
            pfeat.push_back(floHist); // for each video
        else nfeat.push_back(floHist);
    }
}