예제 #1
0
void generateRpn(int k){
    int i;
    if ( k==0 ){
        i=1;
    }else{
        i=0;
    }
    if ( aTree[k] == NULL ){
        return;
    }
    
    if ( hybrid(k) ){
        nprElements[aux] = aTree[k];
        aux++;
    }
    k *= treeLevelSize;
    for ( i; i<12; i++){
        generateRpn((k+i));
    }
    k /= treeLevelSize;
    if ( !hybrid(k) ){
        nprElements[aux] = aTree[k];
    }
    //nprElements[aux] = aTree[k];
    aux++;
}
예제 #2
0
/* filter out epsilon margin separated points */
static int separate (int n, double **q, double epsilon)
{
  if (epsilon <= 0.0) return n;

  double epshalf = .5 * epsilon,
	 epsq = epsilon * epsilon,
	 d [3], r;
  BOX *b, *g, **pb;
  SET *item;
  int i, m;

  ERRMEM (b = malloc (n * sizeof (BOX)));
  ERRMEM (pb = malloc (n * sizeof (BOX*)));

  for (i = 0, g = b; i < n; i ++, g ++)
  {
    double *e = g->extents,
	   *p = q [i];
    e [0] = p [0] - epshalf;
    e [1] = p [1] - epshalf;
    e [2] = p [2] - epshalf;
    e [3] = p [0] + epshalf;
    e [4] = p [1] + epshalf;
    e [5] = p [2] + epshalf;
    g->sgp = (void*) p;
    g->body = NULL;
    g->mark = NULL;
    pb [i] = g;
  }

  hybrid (pb, n, NULL, overlap);

  for (i = m = 0, g = b; i < n; i ++, g ++)
  {
    if (!g->mark)
    {
      double *a =  (double*) g->sgp;
      q [m ++] = a;

      for (item = SET_First ((SET*)g->body); item; item = SET_Next (item))
      {
	BOX *adj = item->data;
	double *b = (double*) adj->sgp;
	SUB (a, b, d);
	r = DOT (d, d);
	if (r < epsq) adj->mark = (void*) 1; /* epsilon separation */
      }
    }

    SET_Free (NULL, (SET**) &g->body);
  }

  free (pb);
  free (b);

  return m;
}
예제 #3
0
void ampegdecoder::decode3()
{
  int fr,gr,ch,sb,ss;
  for (fr=0; fr<(hdrlsf?2:1); fr++)
  {
    grsistruct si0[2][2];

    if (fr)
      decodehdr(0);

    if (!hdrbitrate)
    {
      for (gr=fr; gr<2; gr++)
        for (ch=0; ch<2; ch++)
          for (sb=0; sb<32; sb++)
            for (ss=0; ss<18; ss++)
            {
              fraction[ch][gr*18+ss][sb]=((sb&ss&1)?-1:1)*prevblck[ch][sb][ss];
              prevblck[ch][sb][ss]=0;
            }
      return;
    }

    readmain(si0);
    int stereo=(hdrmode==3)?1:2;
    int ngr=hdrlsf?1:2;
    for (gr=0;gr<ngr;gr++)
    {
      for (ch=0; ch<stereo; ch++)
      {
        readscalefac(si0[ch][gr], scalefac0[ch]);
        readhuffman(si0[ch][gr], xr0[ch]);
        doscale(si0[ch][gr], xr0[ch], scalefac0[ch]);
      }

      if (hdrmode==1)
        jointstereo(si0[1][gr], xr0, scalefac0[1]);

      for (ch=0; ch<stereo; ch++)
        hybrid(si0[ch][gr], fraction[ch]+(fr+gr)*18, prevblck[ch], xr0[ch]);
    }
  }
}
예제 #4
0
int conservation_scoring (Options *options, Alignment * alignment, 
			  int * similar_to, double ** score, double *** in_group_score) {

    int retval;
    Tree tree;
    
    int build_tree (Options * options, Alignment * alignment, Tree * tree);
    int entropy ( Alignment * alignment, int * similar_to, double *score);
    int hybrid (Alignment * alignment, Tree * tree,
		 int * similar_to, int normalize,  double *score);
    int in_group_entropy ( Alignment * alignment, int * similar_to, double **score);
			   
    /* build the seq similarity tree */
    //printf ("building the tree: ...");  fflush (stdout);
    memset (&tree, 0, sizeof(Tree));  
    retval  = build_tree(options, alignment, &tree);
    if (retval) return retval;

    hybrid  (alignment, &tree, NULL, 0, score[0]);
    entropy (alignment, NULL, score[1]);
 
    /* per-group scoring */
    in_group_entropy (alignment, NULL, in_group_score[0]);
    /* if I ever decide to add other cons methods, sub as rvet */
    /* it should be something like */
    /* in_group_rvET (alignment, NULL, in_group_score[1]); */
   
    
    /* sink the gapped positions to the bottom, if requested */
    if ( options->max_gaps ) {
	int method_ctr;
	int ctr, group;
	double max_score = -1;

	alignment->number_of_sunk_positions = 0;
	for ( ctr=0; ctr < alignment->length; ctr++ ) {
	    if ((double)alignment->column_gaps[ctr]/alignment->number_of_seqs > options->max_gaps ) {
		alignment->sunk[ctr] = 1;
		alignment->number_of_sunk_positions++;
	    }
	}
	for (method_ctr=0; method_ctr<=1; method_ctr++) {

	    max_score = -1;
	    
	    for ( ctr=0; ctr < alignment->length; ctr++ ) {
		if ( max_score < score[method_ctr][ctr] ) max_score = score[method_ctr][ctr];
	    }
	    for ( ctr=0; ctr < alignment->length; ctr++ ) {
		if (alignment->sunk[ctr] ) {
		    score[method_ctr][ctr] = max_score;
		}
	    }
	}
	/* in group entropy */
	for (group=0;  group< alignment->no_groups; group++) {

	    max_score = -1;
	    
	    for ( ctr=0; ctr < alignment->length; ctr++ ) {
		if (max_score < in_group_score[0][group][ctr] )
		    max_score = in_group_score[0][group][ctr];
	    }
	    
	    for ( ctr=0; ctr < alignment->length; ctr++ ) {
		if ((double)alignment->group[group].gaps[ctr]/alignment->group[group].no_members
		    > options->max_gaps ) {
		    in_group_score[0][group][ctr] = max_score;
		}
	    }
	    
	}
    }

    free_node_matrix (tree.group_root);
    free (tree.leaf);
    return 0;
}
예제 #5
0
int main()
{
	int idx, idx2;
	int cnt[10] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100};

	srandom(time(NULL));

	/* reset counter */

	TotalAlloc		= 0;
	TotalFree		= 0;
	NullAlloc			= 0;
	NullFree			= 0;
	TotalAllocSize	= 0;

	TITLE(Test Start);

	for (idx = 0 ; idx < DESTROY_COUNT ; idx ++)
	{
		int i;

		/* Init mm spool */
		for (i = 0 ; i < 10 ; i ++)
			cnt [i] = (random() % 100);

		/* Init */
		upnp_mm_init(cnt);

		SUBSUBTITLE(Start Round......);

		/* Dump */
		upnp_mm_dump();


		for (idx2 = 0 ; idx2 < REINIT_COUNT ; idx2 ++)
		{
			int i;

			SUBSUBTITLE(Reinit mm system......);
			
			bzero(my_alloc, (sizeof(void *) * MAX_ALLOC));

			for (i = 0 ; i < MAX_TEST_COUNT ; i ++)
			{
				allo();
				callo();
				reallo();
				sdup();
				hybrid();
				ran();
			}
			/* Reinit */
			upnp_mm_reinit();
		}

		SUBSUBTITLE(One Round Complete......);

		/* Dump */
		upnp_mm_dump();

		/* Destroy */
		upnp_mm_destroy();
	}

	/* Dump counter */
	TITLE(Test Complete);
	printf("\tTotalAlloc\t(Total Allocation Count)\t:\t%u\n", TotalAlloc);
	printf("\tTotalFree\t(Total Free Count)\t\t:\t%u\n", TotalFree);

	printf("\tNullAlloc\t(Total Count of out-of-memory)\t:\t%u", NullAlloc);
	if (NullAlloc)
		printf("\t(This COULD cause daemon stop!)\n");
	else
		printf("\n");
	
	printf("\tNullFree\t(Free with the NULL pointer)\t:\t%u\n", NullFree);
	printf("\tTotalAllocSize\t(Total Allocated memory size)\t:\t%u\n", TotalAllocSize);
	printf("\n");
	return 0;
}
// ######################################################################
Image<PixRGB<byte> > SuperPixelRoadSegmenter::getSuperPixel(Image<PixRGB<byte> > img)
{
    if(!img.initialized()) return Image<PixRGB<byte> >(320,240,ZEROS);

    // default parameters for the Superpixel segmentation
    float sigma = .5;
    uint k = 400;
    uint minSize = 100;
    int num_ccs;
    std::vector<std::vector<Point2D<int> > > groups;
    Image<int> groupImage =
        SuperPixelSegment(img,sigma, k, minSize, num_ccs, &groups);
    Image<PixRGB<byte> > sp_img = SuperPixelDebugImage(groups,img);
    Image<int> sp_size_img = SuperPixelRegionSizeImage(groups,groupImage);
    itsRawSuperPixelImg = sp_img;
    //debugWin(itsRawSuperPixelImg,"itsRawSuperPixelImg");
    int w = sp_img.getWidth();
    int h = sp_img.getHeight();

    // Look for road color,
    // let's assume it always show up in the middle bottom (h-5,w/2 +- 10)

    std::vector<PixRGB<byte> >	color_map;
    std::vector<int>	color_size_map;
    std::vector<int> 	color_map_count;

    // Pick all road pixel candidates
    int windowL = -SEARCH_WINDOW_W/2; //-10
    int windowR =  SEARCH_WINDOW_W/2; // 10
    int windowB =  SEARCH_WINDOW_BOTTOM;
    int windowT =  SEARCH_WINDOW_H;
    for(int i = windowL; i<= windowR; i++)
    {
        //We are search bottom area as most likely road pixel candidates
        for(int k = windowB; k <=windowT; k++) {

            //set our grow window float to the middle of road
            int middlePoint;
            if(itsMiddlePoint[k-1]!=0 && itsUseFloatWindow) {
                middlePoint = itsMiddlePoint[k-1]/4;//1/4 size image
                //LINFO("Float Window %d midpoint %d",middlePoint,k-1);
            } else {

                middlePoint = w/2;
                //LINFO("Fixed Window %d midpoint",middlePoint);
            }
            if(sp_img.coordsOk(middlePoint+i,h-k)) {
                PixRGB<byte> tmp_color = sp_img.getVal(middlePoint + i,h-k);
                int regionSize = sp_size_img.getVal(middlePoint+i,h-k);

                bool notfound = true;

                // Search color
                for(int j = 0; j < (int)color_map.size() && notfound ; j++)
                {
                    if(color_map[j] == tmp_color)
                    {
                        notfound = false;
                        color_map_count[j]++;
                    }
                }
                if(notfound)
                {
                    color_map.push_back(tmp_color);
                    color_map_count.push_back(0);
                    color_size_map.push_back(regionSize);
                }
            }
        }
    }

    if(color_map.size() > 1)
    {   //if we found more than one color
        //Some Option Here:
        //1.Choose max count color
        //2.Pick min color difference from previous avg road color pixel

        //if road color is not available, we pick max pixel color
        if(itsRoadColor == PixRGB<byte>(0,0,0)) {
            int max = color_map_count[0];
            int max_index = 0;
            for(int i = 1; i < (int)color_map_count.size() ; i++)
            {
                if(max < color_map_count[i])
                {
                    max = color_map_count[i];
                    max_index = i;
                }
            }
            itsRoadColor = color_map[max_index];
            //LINFO("Max count color have count %d",max);
        } else {
            //Pick min color difference color
            int min_index = 0;
            float min = colorDiff(itsRoadColor,color_map[0]);//
            for(int i = 1; i < (int)color_map_count.size() ; i++)
            {
                float cd = colorDiff(itsRoadColor,color_map[i]);
                int rs = color_size_map[i];//region size
                //LINFO("Road Region Size %d",rs);
                if(cd < min && rs > 100)
                {
                    min = cd;
                    min_index = i;
                }
            }
            itsRoadColorDiff = colorDiff(itsRoadColor,color_map[min_index]);

            //to prevent jump too much
            if(itsRoadColorDiff < 50.0) {
                itsRoadColor = color_map[min_index];
            } else {
                //keep avg color so it will help to solve kid-napping problem
                PixRGB<byte> avgColor = colorAvg(itsRoadColor,color_map[0],0.8);//first color will have 80% weight
                itsRoadColor = avgColor;
                //LINFO("COLOR DIFF1 %f",itsRoadColorDiff);
            }
        }
    }
    else
    {
        //if only one region
        itsRoadColorDiff = colorDiff(itsRoadColor,color_map[0]);
        itsRoadColorDiffSub = colorDiffSub(itsRoadColor,color_map[0]);


        if((itsRoadColorDiff < 50.0 && color_map[0].green() > 150)||itsRoadColor == PixRGB<byte>(0,0,0)) { //for outdoor concrete road
            //if((itsRoadColorDiff < 90.0 && color_map[0].green()<150)||itsRoadColor == PixRGB<byte>(0,0,0)){//indoor
            //if((itsRoadColorDiff < 90.0)||itsRoadColor == PixRGB<byte>(0,0,0)){//general, high fail rate
            itsRoadColor = color_map[0];
            //itsUseFloatWindow = false;//FIXXXXXX
        } else {
            PixRGB<byte> avgColor = colorAvg(itsRoadColor,color_map[0],0.8);//80% on first one
            itsRoadColor = avgColor;
            itsUseFloatWindow = true;
            //LINFO("COLOR DIFF2 %f,USE float window",itsRoadColorDiff);
        }
        //LINFO("Only one color (%d,%d,%d)",itsRoadColor.red(),itsRoadColor.green(),itsRoadColor.blue());
    }

    // use iterator!!!!!!
    Image<PixRGB<byte> > output(w,h,ZEROS); //image with full red road region
    Image<PixRGB<byte> > hybrid(w,h,ZEROS); //image with red grid dot road region
    itsRoadIndexMap = Image<int>(w, h, ZEROS);
    //	inplacePaste(output, sp_img, Point2D<int>(w, 0));
    for(int y = 0 ; y < h ; y ++)
    {
        int dot = 0;
        for(int x = 0 ; x < w ; x ++)
        {
            PixRGB<byte> c = sp_img.getVal(x,y);
            //LINFO("Pixel color(%d,%d,%d)road color(%d,%d,%d)",c.red(),c.green(),c.blue(),
            //		itsRoadColor.red(),itsRoadColor.green(),itsRoadColor.blue());
            if(c == itsRoadColor)	{
                //Set road color to red
                byte red = 250+c.red();
                if(red > 255) red = 255;
                //output.setVal(x,y,PixRGB<byte>(red,c.green()/32,c.blue()/32));//this will mess up find red region
                output.setVal(x,y,PixRGB<byte>(255,0,0));
                itsRoadIndexMap.setVal(x,y,255);
                if(dot % 3 == 0) {
                    hybrid.setVal(x,y,PixRGB<byte>(255,0,0));
                } else {
                    hybrid.setVal(x,y,c);
                }
                dot ++;
            }
            else {
                //set to it's color
                output.setVal(x,y,c);
                hybrid.setVal(x,y,c);
                itsRoadIndexMap.setVal(x,y,0);
                //					output.setVal(x,y,c);
            }
        }
    }
    LINFO("hi11");
    if(!output.initialized())
        return img;

    LINFO("hi12");
    //LINFO("Finish Road Finding");
    itsRawRoadSuperPixelImg = hybrid;
    return output;
}