Example #1
0
File: ed.c Project: shaze/wcdest
int  ed(WorkPtr work, int s1, int s2, int rcflag) {
  // if rcflag==1 then we study the rc(s2) rather than s2
  int row, col, l1, l2, r1, r2, curr,prev;

  int num_words_1, num_words_2;
  int score=0;
  void *x, *y;
  dmat1Arr dmat[2];
  int the_min,min_min=0;


  dmat[0] = work->fn_data;
  dmat[1] = work->fn_data+MAX_SEQ_LEN;

  //memset(dmat[0],0,2*sizeof(dmatEntry)*MAX_SEQ_LEN);

  // rather than comparing the entire ESTs, we narrow down
  // the regions on the ESTs where the match could be
  get_bounds(work,s1, s2, &l1, &r1);  // bounds for s1
  get_bounds(work,s2, s1, &l2, &r2);  // bounds for s2
  if (r1-l1< 4)return (10*window_len);// don't bother if not there
  l1 = MAX(0,l1-window_len);     // region could star 
  l2 = MAX(0,l2-window_len);
  r1 = MIN(r1+window_len,seqInfo[s1].len);
  r2 = MIN(r2+window_len,seqInfo[s2].len);
  NUM_dfn++;
  num_words_1 = r1-word_len+1;
  num_words_2 = r2-word_len+1;

  create_word_lists(work,s1, s2, rcflag);
  prev=0;
  curr=1;
  for(row=0; row<=r1; row++) dmat[0][row].f = OPEN;
  for(col=l2; col<r2 && min_min  > theta ; col++) {
    dmat[curr][l1].f=dmat[curr][l1].m=0;
    dmat[curr][l1].e=OPEN;
    for (row=l1+1; row<=r1 && min_min > theta; row++) {
       the_min=0;
       dmat[curr][row].f = 
          MIN3(dmat[prev][row].e+EXTEND+OPEN,
               dmat[prev][row].f+EXTEND,
               dmat[prev][row].g+OPEN+EXTEND);
       if (dmat[curr][row].f < the_min) the_min = dmat[curr][row].f;
       dmat[curr][row].g = dmat[prev][row-1].m+
	 cost[work->word1[row-1]][work->word2[col]];
       if (dmat[curr][row].g < the_min) the_min = dmat[curr][row].g;
       dmat[curr][row].e = 
          MIN3(dmat[curr][row-1].e+EXTEND,
               dmat[curr][row-1].f+EXTEND+OPEN,
               dmat[curr][row-1].g+OPEN+EXTEND);
       if (dmat[curr][row].e < the_min) the_min = dmat[curr][row].e;
       dmat[curr][row].m=the_min;
       if (the_min<min_min) min_min=the_min;
    }
    prev = curr;
    curr = 1-curr;
  }

  return min_min;
}
Example #2
0
idxint ECOS_BB_solve(ecos_bb_pwork* prob) {
    idxint curr_node_idx = 0;

#if MI_PRINTLEVEL > 0
    if (prob->stgs->verbose){
        PRINTTEXT("Iter\tLower Bound\tUpper Bound\tGap\n");
        PRINTTEXT("================================================\n");
    }
#endif

    /* Initialize to root node and execute steps 1 on slide 6 */
    /* of http://stanford.edu/class/ee364b/lectures/bb_slides.pdf*/
    prob->iter = 0;
    initialize_root(prob);
    /*print_node(prob, curr_node_idx);*/
    get_bounds(curr_node_idx, prob);

    prob->global_L = prob->nodes[curr_node_idx].L;
    prob->global_U = prob->nodes[curr_node_idx].U;

    while ( should_continue(prob, curr_node_idx) ){

#if MI_PRINTLEVEL > 0
        if (prob->stgs->verbose){ print_progress(prob); }
#endif

        ++(prob->iter);

        /* Step 2*/
        /* Branch replaces nodes[curr_node_idx] with leftNode*/
        /* and nodes[prob->iter] with rightNode */
        branch(curr_node_idx, prob);

        /* Step 3*/
        get_bounds(curr_node_idx, prob);
        get_bounds(prob->iter, prob);

        /* Step 4*/
        prob->global_L = get_global_L(prob);

        curr_node_idx = get_next_node(prob);
    }
    load_solution(prob);

#if MI_PRINTLEVEL > 0
    if (prob->stgs->verbose){ print_progress(prob); }
#endif

    return get_ret_code(prob);
}
Example #3
0
double
getcomp(obj *p, int t)	/* return component of a position; these must now be */
			/* transformed as there is no later chance to do so. */
{
	float	bnd[4];

	switch (t) {
	case DOTX:	return Xformx(p, 1, p->o_x, p->o_y);
	case DOTY:	return Xformy(p, 1, p->o_x, p->o_y);
	case DOTRAD:
		switch (p->o_type) {
		case SECTOR:
		case ARC:
		case BOX:
		case ARROW:
		case LINE:	return p->o_val[N_VAL].f;
		case CIRCLE:
		case ELLIPSE:	break;	/* fall through to DOTWID case */
		}
	case DOTHT:
	case DOTWID:	if (p->o_type <= TEXT) {
				get_bounds(p, bnd, 1);
				if (t == DOTHT)
					return (bnd[3] - bnd[1]);
				else
					return (bnd[2] - bnd[0]);
			}
	}
	yyerror("can't happen getcomp");
	return 0; /* CK: silence warning */
}
Example #4
0
// ==============================================================
int get_indel_bounds(int gap_start, int gap_end)
// ==============================================================
{
	int_pair bounds = get_bounds(gap_start,gap_end);
	int gap_len = gap_end-gap_start;
	return -(bounds.first-gap_len);
}
Example #5
0
int
whatpos(obj *p, int corner, float *px, float *py)	/* what is the position (no side effect) */
{
	float	x, y, bnd[4];

	if (corner >= EAST && corner <= SW) {
		get_bounds(p, bnd, 2);	/* 2=>disregard line width */
					/* changed 3/18/91 by DBK  */
		switch (corner) {
	case NE:	x = bnd[2];		y = bnd[3];	break;
	case SW:	x = bnd[0];		y = bnd[1];	break;
	case SE:	x = bnd[2];		y = bnd[1];	break;
	case NW:	x = bnd[0];		y = bnd[3];	break;
	case NORTH:	x = (bnd[0]+bnd[2])/2;	y = bnd[3];	break;
	case SOUTH:	x = (bnd[0]+bnd[2])/2;	y = bnd[1];	break;
	case EAST:	x = bnd[2];	y = (bnd[1]+bnd[3])/2;	break;
	case WEST:	x = bnd[0];	y = (bnd[1]+bnd[3])/2;	break;
		}
	}
	else {	/* DBK--note that get_bounds returns the transformed position,
		   but the following calculations do not!! */
		x = p->o_x;
		y = p->o_y;

/* futz around for special cases: */

		switch (p->o_type) {
	case BLOCK:	if (corner == START)
				whatpos(p->o_next, START, &x, &y);
			else if (corner == END)
				whatpos(p->o_val[N_VAL+1].o->o_prev,END,&x,&y);
			break;
	case ARC:	if (corner == START) {
				x = p->o_val[N_VAL+2].f;
				y = p->o_val[N_VAL+3].f;
			}
			else if (corner == END)	{
				x = p->o_val[N_VAL+4].f;
				y = p->o_val[N_VAL+5].f;
			}
			break;
	case LINE:
	case SPLINE:
	case ARROW:	switch (corner) {
				int	n;
		case START:	x = p->o_val[N_VAL+4].f;
				y = p->o_val[N_VAL+5].f;
				break;
		case END:	n = N_VAL + 4 + 2*p->o_val[N_VAL+3].f;
				x = p->o_val[n].f;
				y = p->o_val[n+1].f;
				break;
			}
			break;
		}
	}
	*px = x;
	*py = y;
	return 1;
}
Example #6
0
//---------------------------------------------------------------------------------------
int GmoCompositeShape::add(GmoShape* pShape)
{
    m_components.push_back(pShape);

	if (m_components.size() == 1)
	{
		//copy bounds
		m_origin = pShape->get_origin();
		m_size = pShape->get_size();
	}
	else
	{
	    //TODO: Note from LenMus:
//        lmCompositeShape: the selection rectangle should not be the boundling rectangle
//        but each rectangle of each component shape. This will save the need to define
//        specific shapes just to override selection rectangle. i.i. metronome marks

		//compute new selection rectangle by union of individual selection rectangles
		URect bbox = get_bounds();
		bbox.Union(pShape->get_bounds());
		m_origin = bbox.get_top_left();
		m_size.width = bbox.get_width();
		m_size.height = bbox.get_height();
	}

	//return index to added shape
	return (int)m_components.size() - 1;
}
static void _convolution(const my_Dvector& vec1, const my_Dvector& vec2, my_Dvector& conv, int init, ThreadPool& pool)
{
    // To do the convolution I trim the beginning and ending points if they are zero (1e-30);
    int min1 (0), max1 (vec1.size());
    _trim_vec(vec1, min1, max1);

    int min2 (0), max2 (vec2.size());
    _trim_vec(vec2, min2, max2);

    int ini = max(min1+min2-init,0);
    int fin = min(int(conv.size()), max1 + max2 - 1);

    unsigned int nr_th = get_num_threads();
    unsigned int nr_job = max((fin-ini)/100, min(int(nr_th), fin-ini));
	my_Ivector lims (get_bounds(ini, fin, nr_job));
	std::vector< std::future<int> > results;

    //lambda function
    auto func = [&](my_Dvector& v, int com, int ter)
    {
        for (int ii=com;ii<ter;++ii){
            const int delta = max(ii+init-min2-max1,0);
            for (int j=min2+delta,k=(ii+init-min2-delta);j<max2 && k>=min1;++j,--k){
                v[ii] += vec1[k]*vec2[j];
            }
        }
        return 1;
    }; //

	for (unsigned int i=0;i<nr_job;++i) results.emplace_back(pool.enqueue(
        func, ref(conv), lims[i], lims[i+1]));
    for(auto && result: results) result.get();


}
my_Dvector convolution_same_orig(const my_Dvector& vec1, const my_Dvector& vec2, ThreadPool& pool)
{
    my_Dvector conv (vec1.size(),0.0);
    int init = vec2.size()/2;

    unsigned int nr_th = get_num_threads();
    my_Ivector lims (get_bounds(0,conv.size()));
    std::vector< std::future<int> > results;

    //lambda function
    auto func = [&](my_Dvector& v, int com, int ter)
    {
        for (int ii=com;ii<ter;++ii){
            for (int j=0,k=(ii+init);j<vec2.size() && k>=0;++j,--k){
                if (k<vec1.size()){ v[ii] += vec1[k]*vec2[j];}
            }
        }
        return 1;
    }; //
    for (unsigned int i=0;i<nr_th;++i) results.emplace_back(pool.enqueue(
                        func, ref(conv), lims[i], lims[i+1]));
    for(auto && result: results) result.get();

    return conv;
}
Example #9
0
void
scale_pic(void)		/* for PIC compatibility--called at end of parse */
{
	double	sc;
	obj	*o;
	int	i;
	float	bnd[4];

	if (picscale == 0.0)
		picscale = 1.0;
	if (picscale == 1.0)
		return;
	sc = 1.0 / picscale;
	
	for (o = objhead; o != objtail; o = o->o_next) {
		if (o->o_type == PLACE || o->o_type == TEXT ||
						o->o_type == MOVE) {
			o->o_x *= sc;
			o->o_y *= sc;
	/* NOTE!! may need to adjust center offset of text */
		}
		else if (o->o_type < TEXT) {	/* PIC couldn't scale text */
			for (i = 0; i < 6; i++)
				o->o_xform[i].f *= sc;
		}
		if (o->o_type == BLOCK)		/* skip the contents */
			o = o->o_val[N_VAL].o;
	}
	/* make arrowheads large to compensate for later shrinkage */
	for (o = objhead; o != objtail; o = o->o_next) {
		if ((o->o_type == LINE || o->o_type == SPLINE ||
		    o->o_type == ARROW) && (o->o_attr & HEAD12) != 0) {
			o->o_val[N_VAL+1].f *= picscale;
			o->o_val[N_VAL+2].f *= picscale;
		}
		if (o->o_type == ARC && (o->o_attr & HEAD12) != 0) {
			o->o_val[N_VAL+8].f *= picscale;
			o->o_val[N_VAL+9].f *= picscale;
		}
	}
	picscale = 1.0;

	Gbox[2] = Gbox[3] = -(Gbox[0] = Gbox[1] = 32767);
	for (o = objhead->o_next; o != objtail; o = o->o_next) {
		get_bounds(o, bnd, 1);
		track_bounds (bnd[0], bnd[1], bnd[2], bnd[3]);
		if (o->o_type == BLOCK)
			o = o->o_val[N_VAL].o;
	}
#if 0
	cur_xform[0].f /= v;
	cur_xform[1].f /= v;
	cur_xform[2].f /= v;
	cur_xform[3].f /= v;
	checkscale(v);
#endif
}
Example #10
0
//---------------------------------------------------------------------------------------
GmoBox* GmoBox::find_inner_box_at(LUnits x, LUnits y)
{
    URect bbox = get_bounds();
    if (bbox.contains(x, y))
    {
        std::vector<GmoBox*>::iterator it;
        for (it=m_childBoxes.begin(); it != m_childBoxes.end(); ++it)
        {
            GmoBox* pBox = (*it)->find_inner_box_at(x, y);
            if (pBox)
			    return pBox;
        }
        return this;
    }
    return NULL;
}
Example #11
0
void
translate (obj *p, double x, double y)           /* the easy case of applying a transformation */
{
	float	bnd[4];
	int	i;

	if (p->o_type == PLACE) {
		cur_xform[4].f += x;
		cur_xform[5].f += y;
	}
	else if (p->o_type <= TEXT) {
		if (p->o_type == BLOCK  || p->o_mxx != 1 || p->o_myy != 1
					|| p->o_mxy != 0 || p->o_myx != 0
					|| p->o_mxt != 0 || p->o_myt != 0) {
			p->o_mxt += x;
			p->o_myt += y;
		}
		else {	/* no existing transformation, move center */
			/* DBK: probably should also test to make sure
			   there is no higher level transformation?? */
			p->o_x += x;
			p->o_y += y;
			switch (p->o_type) {

			case LINE:
			case ARROW:
			case SPLINE:
				for (i = 0; i <= p->o_val[N_VAL+3].f; i++) {
					p->o_val[N_VAL+4+i+i].f += x;
					p->o_val[N_VAL+5+i+i].f += y;
				}
				break;
			case ARC:
			case SECTOR:
				p->o_val[N_VAL+2].f += x;
				p->o_val[N_VAL+3].f += y;
				p->o_val[N_VAL+4].f += x;
				p->o_val[N_VAL+5].f += y;
				break;
			}
		}
		get_bounds(p, bnd, 0);
		track_bounds(bnd[0], bnd[1], bnd[2], bnd[3]);
		redo_gbox = 1;
	}
}
Example #12
0
static void
apply(obj *p, double *M, double d)			/* apply matrix M (determinant d) to object p */
{
	float   bnd[4];

	if (p->o_type == PLACE) {
		matmult (cur_xform, M);
		if (d != 1)
			checkscale(sqrt(d));
	}
	else if (p->o_type <= TEXT) {
		matmult (p->o_xform, M);
		get_bounds(p, bnd, 0);
		track_bounds(bnd[0], bnd[1], bnd[2], bnd[3]);
		redo_gbox = 1;
	}
}
Example #13
0
void
get_tot_bounds(obj *o, float *box, int flag) {
    double  *tbox;
    double  xc, yc;

    get_bounds(o, box, flag);
    if (o->o_type == TEXT)	/* Then don't do text_bounds, it ignores */
	return;			/*	transformations. */
    if (o->o_nt1 < o->o_nt2) {	/* some associated strings */
	tbox = text_bounds(o);
	xc = Xformx(o, 0, o->o_x, o->o_y);
	yc = Xformy(o, 0, o->o_x, o->o_y);
	if (tbox[0] + xc < box[0])	box[0] = tbox[0] + xc;
	if (tbox[1] + yc < box[1])	box[1] = tbox[1] + yc;
	if (tbox[2] + xc > box[2])	box[2] = tbox[2] + xc;
	if (tbox[3] + yc > box[3])	box[3] = tbox[3] + yc;
    }
}
Example #14
0
int
main(int argc, char **argv)
{
    int lb, ub;
    double start,end;

    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD,&size);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);

    n = 0;
    if ( argc > 1 )
      n = atoi(argv[1]);
    if (n == 0)
      n = 4000;

    if (rank == 0 ) {
      //printf("Running asp on %d nodes with %d rows\n", size, n);
    }

    get_bounds(&lb, &ub);

    init_tab(n, lb, ub, &tab);

    // MPI_Barrier(MPI_COMM_WORLD);
    //MAGPIE_Reset_statistics(1);  /* print/reset statistics before do_asp() */
    /* will only have effect with -magpie-statistics */
 
    //MAGPIE_Reduce_associative(MPI_COMM_WORLD,1);

    //    start = MPI_Wtime();
    do_asp(tab, n, lb, ub);
    //end = MPI_Wtime();

    free_tab(tab, lb, ub);

    /* if (rank ==  0) { */
    /* 	printf("asp took %f\n",end - start); */
    /* } */
    MPI_Finalize();

    return 0;
}
Example #15
0
bool Indigo::NinePatch::load(const unsigned char* buffer, size_t len, int components)
{
	if (!Image::load(buffer,len,components))
		return false;

	bool ret = false;
	m_info = OOBase::allocate_shared<Indigo::NinePatch::Info>();
	if (!m_info)
		LOG_ERROR(("Failed to allocate 9-patch info block: %s",OOBase::system_error_text()));
	else if (m_width > 2 && m_height > 2)
		ret = get_bounds();
	
	if (!ret)
	{
		unload();
		m_info.reset();
	}

	return ret;
}
Example #16
0
static void draw_areas(float V[6][4], const float M[16],
                       int i, float p, float t)
{
    float b[6], x, y, a;
    GLuint o;

    while (dequeue_area(&x, &y, &a, &o))
    {
        /*float kk =*/ get_bounds(i, b, x, y, a);

        if (test_frustum(V, b) >= 0)
        {
            float k = get_value(b, M, terrain[i].bias);

            if (k > 1.0f && a > 360.0f * terrain[i].n / terrain[i].w)
            {
                float xm = x + a / 2;
                float ym = y + a / 2;

                float x0 = (t > xm) ? x : xm;
                float x1 = (t > xm) ? xm : x;
                float y0 = (p > ym) ? y : ym;
                float y1 = (p > ym) ? ym : y;

                enqueue_area(x0, y0, a / 2, o);
                enqueue_area(x1, y0, a / 2, o);
                enqueue_area(x0, y1, a / 2, o);
                enqueue_area(x1, y1, a / 2, o);
            }
            else
            {
                glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                glBindTexture(GL_TEXTURE_2D, o);

                draw_page(i, x, y, a);
            }
        }
    }
}
Example #17
0
	Cursor::State Textfield::send_cursor(Point<int16_t> cursorpos, bool clicked)
	{
		if (state == DISABLED)
			return Cursor::IDLE;

		auto abs_bounds = get_bounds();
		if (abs_bounds.contains(cursorpos))
		{
			if (clicked)
			{
				switch (state)
				{
				case NORMAL:
					set_state(FOCUSED);
					break;
				}
				return Cursor::CLICKING;
			}
			else
			{
				return Cursor::CANCLICK;
			}
		}
		else
		{
			if (clicked)
			{
				switch (state)
				{
				case FOCUSED:
					set_state(NORMAL);
					break;
				}
			}
			return Cursor::IDLE;
		}
	}
Example #18
0
bool Line::visit_collides(const Line *line) const
{
	float x3 = line->m_x1, y3 = line->m_x2;
	float x4 = line->m_x2, y4 = line->m_y2;
	/*
	float denom  = (y4 - y3) * (m_x2 - m_x1);
	float numera = (x4 - x3) *	(m_y1 - y3);
	float numerb = (m_x2 - m_x1) * (m_y2 - y3);
	denom  -= (line->m_x2 - line->m_x1) * (m_y2 - m_y1);
	numera -= (line->m_y2 - line->m_y1) * (m_x1 - line->m_x1);
	numerb -= (m_y2 - m_y1) * (m_x1 - line->m_x1);
	*/
	float x1 = m_x1, y1 = m_y1;
	float x2 = m_x2, y2 = m_y2;
	float denom  = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
	float numera = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
	float numerb = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
	if (fabs(denom) < EPSILON)
	{
		if (fabs(numera) < EPSILON && fabs(numerb) < EPSILON)
		{
			Rect b1 = get_bounds();
			Rect b2 = line->get_bounds();
			if (b1.collides(&b2))
				return true;
			/*
			return bounds.contains(line->m_x1, line->m_y1) ||
				bounds.contains(line->m_x2, line->m_y2);
			*/
		}
		return false;
	}
	float ua = numera / denom;
	float ub = numerb / denom;
	return 0 < ua && ua < 1 && 0 < ub && ub < 1;
}
Example #19
0
/// write a IUPAC coded consensus search pattern for fragrep to stdout
// ==============================================================
void write_pattern()
// ==============================================================
{
	int hght = AR.height();
	if (all_blocks.empty())
		return;
	std::cout<<all_blocks.size()<<"\n";
	int freq_A, freq_C, freq_G, freq_U;
	fragrep_pattern::iterator f_it = all_blocks.begin();
	fragrep_pattern::iterator f_end = all_blocks.end();
	int prev_block_end = f_it->first;
	for (; f_it!=f_end; ++f_it)
	{
		int_pair bounds = get_bounds(prev_block_end,f_it->first);
		std::string consensus = get_consensus_seq(f_it->first,f_it->second);
		int mismatches = get_mismatches(consensus,f_it->first,f_it->second);
		int deletions = get_deletions(f_it->first,f_it->second);	
		int indel_bounds = get_indel_bounds(prev_block_end,f_it->first);
		std::cout
			<<bounds.first<<" "<<bounds.second<<" "<<consensus
			<<" "<<mismatches<<" "<<deletions<<"\n";
		prev_block_end = f_it->second;
	}
}
Example #20
0
/// Creates difference images, returns the number that have a 0 metric.
/// If outputDir.isEmpty(), don't write out diff files.
static void create_diff_images (DiffMetricProc dmp,
                                const int colorThreshold,
                                RecordArray* differences,
                                const SkString& baseDir,
                                const SkString& comparisonDir,
                                const SkString& outputDir,
                                const StringArray& matchSubstrings,
                                const StringArray& nomatchSubstrings,
                                bool recurseIntoSubdirs,
                                bool getBounds,
                                bool verbose,
                                DiffSummary* summary) {
    SkASSERT(!baseDir.isEmpty());
    SkASSERT(!comparisonDir.isEmpty());

    FileArray baseFiles;
    FileArray comparisonFiles;

    get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, &baseFiles);
    get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdirs,
                  &comparisonFiles);

    if (!baseFiles.isEmpty()) {
        qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString*),
              SkCastForQSort(compare_file_name_metrics));
    }
    if (!comparisonFiles.isEmpty()) {
        qsort(comparisonFiles.begin(), comparisonFiles.count(),
              sizeof(SkString*), SkCastForQSort(compare_file_name_metrics));
    }

    int i = 0;
    int j = 0;

    while (i < baseFiles.count() &&
           j < comparisonFiles.count()) {

        SkString basePath(baseDir);
        SkString comparisonPath(comparisonDir);

        DiffRecord *drp = new DiffRecord;
        int v = strcmp(baseFiles[i]->c_str(), comparisonFiles[j]->c_str());

        if (v < 0) {
            // in baseDir, but not in comparisonDir
            drp->fResult = DiffRecord::kCouldNotCompare_Result;

            basePath.append(*baseFiles[i]);
            comparisonPath.append(*baseFiles[i]);

            drp->fBase.fFilename = *baseFiles[i];
            drp->fBase.fFullPath = basePath;
            drp->fBase.fStatus = DiffResource::kExists_Status;

            drp->fComparison.fFilename = *baseFiles[i];
            drp->fComparison.fFullPath = comparisonPath;
            drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status;

            VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, baseFiles[i]);

            ++i;
        } else if (v > 0) {
            // in comparisonDir, but not in baseDir
            drp->fResult = DiffRecord::kCouldNotCompare_Result;

            basePath.append(*comparisonFiles[j]);
            comparisonPath.append(*comparisonFiles[j]);

            drp->fBase.fFilename = *comparisonFiles[j];
            drp->fBase.fFullPath = basePath;
            drp->fBase.fStatus = DiffResource::kDoesNotExist_Status;

            drp->fComparison.fFilename = *comparisonFiles[j];
            drp->fComparison.fFullPath = comparisonPath;
            drp->fComparison.fStatus = DiffResource::kExists_Status;

            VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, comparisonFiles[j]);

            ++j;
        } else {
            // Found the same filename in both baseDir and comparisonDir.
            SkASSERT(DiffRecord::kUnknown_Result == drp->fResult);

            basePath.append(*baseFiles[i]);
            comparisonPath.append(*comparisonFiles[j]);

            drp->fBase.fFilename = *baseFiles[i];
            drp->fBase.fFullPath = basePath;
            drp->fBase.fStatus = DiffResource::kExists_Status;

            drp->fComparison.fFilename = *comparisonFiles[j];
            drp->fComparison.fFullPath = comparisonPath;
            drp->fComparison.fStatus = DiffResource::kExists_Status;

            SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()));
            if (baseFileBits) {
                drp->fBase.fStatus = DiffResource::kRead_Status;
            }
            SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullPath.c_str()));
            if (comparisonFileBits) {
                drp->fComparison.fStatus = DiffResource::kRead_Status;
            }
            if (NULL == baseFileBits || NULL == comparisonFileBits) {
                if (NULL == baseFileBits) {
                    drp->fBase.fStatus = DiffResource::kCouldNotRead_Status;
                    VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, baseFiles[i]);
                }
                if (NULL == comparisonFileBits) {
                    drp->fComparison.fStatus = DiffResource::kCouldNotRead_Status;
                    VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, comparisonFiles[j]);
                }
                drp->fResult = DiffRecord::kCouldNotCompare_Result;

            } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) {
                drp->fResult = DiffRecord::kEqualBits_Result;
                VERBOSE_STATUS("MATCH", ANSI_COLOR_GREEN, baseFiles[i]);
            } else {
                AutoReleasePixels arp(drp);
                get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixels_Mode);
                get_bitmap(comparisonFileBits, drp->fComparison,
                           SkImageDecoder::kDecodePixels_Mode);
                VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]);
                if (DiffResource::kDecoded_Status == drp->fBase.fStatus &&
                    DiffResource::kDecoded_Status == drp->fComparison.fStatus) {
                    create_and_write_diff_image(drp, dmp, colorThreshold,
                                                outputDir, drp->fBase.fFilename);
                } else {
                    drp->fResult = DiffRecord::kCouldNotCompare_Result;
                }
            }

            ++i;
            ++j;
        }

        if (getBounds) {
            get_bounds(*drp);
        }
        SkASSERT(DiffRecord::kUnknown_Result != drp->fResult);
        differences->push(drp);
        summary->add(drp);
    }

    for (; i < baseFiles.count(); ++i) {
        // files only in baseDir
        DiffRecord *drp = new DiffRecord();
        drp->fBase.fFilename = *baseFiles[i];
        drp->fBase.fFullPath = baseDir;
        drp->fBase.fFullPath.append(drp->fBase.fFilename);
        drp->fBase.fStatus = DiffResource::kExists_Status;

        drp->fComparison.fFilename = *baseFiles[i];
        drp->fComparison.fFullPath = comparisonDir;
        drp->fComparison.fFullPath.append(drp->fComparison.fFilename);
        drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status;

        drp->fResult = DiffRecord::kCouldNotCompare_Result;
        if (getBounds) {
            get_bounds(*drp);
        }
        differences->push(drp);
        summary->add(drp);
    }

    for (; j < comparisonFiles.count(); ++j) {
        // files only in comparisonDir
        DiffRecord *drp = new DiffRecord();
        drp->fBase.fFilename = *comparisonFiles[j];
        drp->fBase.fFullPath = baseDir;
        drp->fBase.fFullPath.append(drp->fBase.fFilename);
        drp->fBase.fStatus = DiffResource::kDoesNotExist_Status;

        drp->fComparison.fFilename = *comparisonFiles[j];
        drp->fComparison.fFullPath = comparisonDir;
        drp->fComparison.fFullPath.append(drp->fComparison.fFilename);
        drp->fComparison.fStatus = DiffResource::kExists_Status;

        drp->fResult = DiffRecord::kCouldNotCompare_Result;
        if (getBounds) {
            get_bounds(*drp);
        }
        differences->push(drp);
        summary->add(drp);
    }

    release_file_list(&baseFiles);
    release_file_list(&comparisonFiles);
}
Example #21
0
static void get_bounds(DiffRecord& drp) {
    get_bounds(drp.fBase, "base");
    get_bounds(drp.fComparison, "comparison");
}
Example #22
0
void OField :: set_size (DSize dsize )
{

  get_bounds().Size = dsize;

}
my_Ivector get_bounds(const int ini, const int fin)
{
    return get_bounds(ini, fin, num_threads);
}
Example #24
0
//---------------------------------------------------------------------------------------
bool GmoShape::hit_test(LUnits x, LUnits y)
{
    URect bbox = get_bounds();
    return bbox.contains(x, y);
}
Example #25
0
CL_Point CL_Quad::center() const
{
	CL_Rect r = get_bounds();
	return CL_Point((r.left+r.right)/2, (r.top+r.bottom)/2);
}
Example #26
0
// Find row/col beneath cursor
//
//    Returns R/C and context.
//    Also returns resizeflag, if mouse is hovered over a resize boundary.
//
Fl_Table_Copy::TableContext Fl_Table_Copy::cursor2rowcol(int &R, int &C, ResizeFlag &resizeflag) {
  // return values
  R = C = 0;
  resizeflag = RESIZE_NONE;
  // Row header?
  int X, Y, W, H;
  if ( row_header() ) {
    // Inside a row heading?
    get_bounds(CONTEXT_ROW_HEADER, X, Y, W, H);
    if ( Fl::event_inside(X, Y, W, H) ) {
      // Scan visible rows until found
      for ( R = toprow; R <= botrow; R++ ) {
        find_cell(CONTEXT_ROW_HEADER, R, 0, X, Y, W, H);
        if ( Fl::event_y() >= Y && Fl::event_y() < (Y+H) ) {
          // Found row?
          //     If cursor over resize boundary, and resize enabled,
          //     enable the appropriate resize flag.
          //
          if ( row_resize() ) {
            if ( Fl::event_y() <= (Y+3-0) ) { resizeflag = RESIZE_ROW_ABOVE; }
            if ( Fl::event_y() >= (Y+H-3) ) { resizeflag = RESIZE_ROW_BELOW; }
          }
          return(CONTEXT_ROW_HEADER);
        }
      }
      // Must be in row header dead zone
      return(CONTEXT_NONE);
    }
  }
  // Column header?
  if ( col_header() ) {
    // Inside a column heading?
    get_bounds(CONTEXT_COL_HEADER, X, Y, W, H);
    if ( Fl::event_inside(X, Y, W, H) ) {
      // Scan visible columns until found
      for ( C = leftcol; C <= rightcol; C++ ) {
        find_cell(CONTEXT_COL_HEADER, 0, C, X, Y, W, H);
        if ( Fl::event_x() >= X && Fl::event_x() < (X+W) ) {
          // Found column?
          //     If cursor over resize boundary, and resize enabled,
          //     enable the appropriate resize flag.
          //
          if ( col_resize() ) {
            if ( Fl::event_x() <= (X+3-0) ) { resizeflag = RESIZE_COL_LEFT; }
            if ( Fl::event_x() >= (X+W-3) ) { resizeflag = RESIZE_COL_RIGHT; }
          }
          return(CONTEXT_COL_HEADER);
        }
      }
      // Must be in column header dead zone
      return(CONTEXT_NONE);
    }
  }
  // Mouse somewhere in table?
  //     Scan visible r/c's until we find it.
  //
  if ( Fl::event_inside(tox, toy, tow, toh) ) {
    for ( R = toprow; R <= botrow; R++ ) {
      find_cell(CONTEXT_CELL, R, C, X, Y, W, H);
      if ( Fl::event_y() < Y ) break;		// OPT: thanks lars
      if ( Fl::event_y() >= (Y+H) ) continue;	// OPT: " "
      for ( C = leftcol; C <= rightcol; C++ ) {
        find_cell(CONTEXT_CELL, R, C, X, Y, W, H);
        if ( Fl::event_inside(X, Y, W, H) ) {
          return(CONTEXT_CELL);			// found it
        }
      }
    }
    // Must be in a dead zone of the table
    R = C = 0;
    return(CONTEXT_TABLE);
  }
  // Somewhere else
  return(CONTEXT_NONE);
}
Example #27
0
// Draw the entire Fl_Table_Copy
//    Override the draw() routine to draw the table.
//    Then tell the group to draw over us.
//
void Fl_Table_Copy::draw() {   
#if FLTK_ABI_VERSION >= 10301
    // NEW
    int scrollsize = _scrollbar_size ? _scrollbar_size : Fl::scrollbar_size();
#else
    // OLD
    int scrollsize = Fl::scrollbar_size();
#endif
  // Check if scrollbar size changed
  if ( ( vscrollbar && (scrollsize != vscrollbar->w()) ) || 
       ( hscrollbar && (scrollsize != hscrollbar->h()) ) ) {
    // handle size change, min/max, table dim's, etc
    table_resized();
  }

  draw_cell(CONTEXT_STARTPAGE, 0, 0,	 	// let user's drawing routine
            tix, tiy, tiw, tih);		// prep new page
  
  // Let fltk widgets draw themselves first. Do this after
  // draw_cell(CONTEXT_STARTPAGE) in case user moves widgets around.
  // Use window 'inner' clip to prevent drawing into table border.
  // (unfortunately this clips FLTK's border, so we must draw it explicity below)
  //
  fl_push_clip(wix, wiy, wiw, wih);
  {
    Fl_Group::draw();
  }
  fl_pop_clip();
  
  // Explicitly draw border around widget, if any
  draw_box(box(), x(), y(), w(), h(), color());
  
  // If Fl_Scroll 'table' is hidden, draw its box
  //    Do this after Fl_Group::draw() so we draw over scrollbars
  //    that leak around the border.
  //
  if ( ! table->visible() ) {
    if ( damage() & FL_DAMAGE_ALL || damage() & FL_DAMAGE_CHILD ) {
      draw_box(table->box(), tox, toy, tow, toh, table->color());
    }
  } 
  // Clip all further drawing to the inner widget dimensions
  fl_push_clip(wix, wiy, wiw, wih);
  {
    // Only redraw a few cells?
    if ( ! ( damage() & FL_DAMAGE_ALL ) && _redraw_leftcol != -1 ) {
      fl_push_clip(tix, tiy, tiw, tih);
      for ( int c = _redraw_leftcol; c <= _redraw_rightcol; c++ ) {
        for ( int r = _redraw_toprow; r <= _redraw_botrow; r++ ) { 
          _redraw_cell(CONTEXT_CELL, r, c);
        }
      }
      fl_pop_clip();
    }
    if ( damage() & FL_DAMAGE_ALL ) {
      int X,Y,W,H;
      // Draw row headers, if any
      if ( row_header() ) {
        get_bounds(CONTEXT_ROW_HEADER, X, Y, W, H);
        fl_push_clip(X,Y,W,H);
        for ( int r = toprow; r <= botrow; r++ ) {
          _redraw_cell(CONTEXT_ROW_HEADER, r, 0);
        }
        fl_pop_clip();
      }
      // Draw column headers, if any
      if ( col_header() ) {
        get_bounds(CONTEXT_COL_HEADER, X, Y, W, H);
        fl_push_clip(X,Y,W,H);
        for ( int c = leftcol; c <= rightcol; c++ ) {
          _redraw_cell(CONTEXT_COL_HEADER, 0, c);
        }
        fl_pop_clip();
      } 
      // Draw all cells.
      //    This includes cells partially obscured off edges of table.
      //    No longer do this last; you might think it would be nice
      //    to draw over dead zones, but on redraws it flickers. Avoid
      //    drawing over deadzones; prevent deadzones by sizing columns.
      //
      fl_push_clip(tix, tiy, tiw, tih); {
        for ( int r = toprow; r <= botrow; r++ ) {
          for ( int c = leftcol; c <= rightcol; c++ ) {
            _redraw_cell(CONTEXT_CELL, r, c); 
          }
        }
      }
      fl_pop_clip(); 
      // Draw little rectangle in corner of headers
      if ( row_header() && col_header() ) {
        fl_rectf(wix, wiy, row_header_width(), col_header_height(), color());
      }
      
      // Table has a boxtype? Close those few dead pixels
      if ( table->box() ) {
        if ( col_header() ) {
          fl_rectf(tox, wiy, Fl::box_dx(table->box()), col_header_height(), color());
        }
        if ( row_header() ) {
          fl_rectf(wix, toy, row_header_width(), Fl::box_dx(table->box()), color());
        }
      }
      
      // Table width smaller than window? Fill remainder with rectangle
      if ( table_w < tiw ) {
        fl_rectf(tix + table_w, tiy, tiw - table_w, tih, color()); 
        // Col header? fill that too
        if ( col_header() ) {
          fl_rectf(tix + table_w, 
                   wiy, 
                   // get that corner just right..
                   (tiw - table_w + Fl::box_dw(table->box()) - 
                    Fl::box_dx(table->box())),
                   col_header_height(),
                   color());
        }
      } 
      // Table height smaller than window? Fill remainder with rectangle
      if ( table_h < tih ) {
        fl_rectf(tix, tiy + table_h, tiw, tih - table_h, color()); 
        if ( row_header() ) {
          // NOTE:
          //     Careful with that lower corner; don't use tih; when eg. 
          //     table->box(FL_THIN_UPFRAME) and hscrollbar hidden, 
          //     leaves a row of dead pixels.
          //
          fl_rectf(wix, tiy + table_h, row_header_width(), 
                   (wiy+wih) - (tiy+table_h) - 
                   ( hscrollbar->visible() ? scrollsize : 0),
                   color());
        }
      }
    } 
    // Both scrollbars? Draw little box in lower right
    if ( vscrollbar->visible() && hscrollbar->visible() ) {
      fl_rectf(vscrollbar->x(), hscrollbar->y(), 
               vscrollbar->w(), hscrollbar->h(), color());
    } 
    draw_cell(CONTEXT_ENDPAGE, 0, 0,		// let user's drawing
              tix, tiy, tiw, tih);		// routines cleanup
    
    _redraw_leftcol = _redraw_rightcol = _redraw_toprow = _redraw_botrow = -1;
  }
  fl_pop_clip();
}
Example #28
0
void OField :: set_position (DPoint position )
{

  get_bounds().Origin = position;

}
Example #29
0
	Vec2<Type> Quadx<Type>::center() const
	{
		Rect r = get_bounds();
		return Vec2<Type>((r.left + r.right) / 2, (r.top + r.bottom) / 2);
	}
Example #30
0
static ReadSlide *
readslide_new( const char *filename, VipsImage *out, 
	int level, gboolean autocrop, const char *associated )
{
	ReadSlide *rslide;
	int64_t w, h;
	const char *error;
	const char *background;
	const char * const *properties;
	char *associated_names;

	if( level && 
		associated ) {
		vips_error( "openslide2vips",
			"%s", _( "specify only one of level or associated "
			"image" ) );
		return( NULL );
	}

	rslide = VIPS_NEW( out, ReadSlide );
	memset( rslide, 0, sizeof( *rslide ) );
	g_signal_connect( out, "close", G_CALLBACK( readslide_destroy_cb ),
		rslide );

	rslide->level = level;
	rslide->autocrop = autocrop;
	rslide->associated = g_strdup( associated );

	/* Non-crazy defaults, override below if we can.
	 */
	rslide->tile_width = 256;
	rslide->tile_height = 256;

	rslide->osr = openslide_open( filename );
	if( rslide->osr == NULL ) {
		vips_error( "openslide2vips", 
			"%s", _( "unsupported slide format" ) );
		return( NULL );
	}

	error = openslide_get_error( rslide->osr );
	if( error ) {
		vips_error( "openslide2vips",
			_( "opening slide: %s" ), error );
		return( NULL );
	}

	if( level < 0 || 
		level >= openslide_get_level_count( rslide->osr ) ) {
		vips_error( "openslide2vips",
			"%s", _( "invalid slide level" ) );
		return( NULL );
	}

	if( associated &&
		check_associated_image( rslide->osr, associated ) )
		return( NULL );

	if( associated ) {
		openslide_get_associated_image_dimensions( rslide->osr,
			associated, &w, &h );
		vips_image_set_string( out, "slide-associated-image",
			associated );
		vips_image_pipelinev( out, VIPS_DEMAND_STYLE_THINSTRIP, NULL );
	} 
	else {
		char buf[256];
		const char *value;

		openslide_get_level_dimensions( rslide->osr,
			level, &w, &h );
		rslide->downsample = openslide_get_level_downsample(
			rslide->osr, level );
		vips_image_set_int( out, "slide-level", level );
		vips_image_pipelinev( out, VIPS_DEMAND_STYLE_SMALLTILE, NULL );

		/* Try to get tile width/height. An undocumented, experimental
		 * feature.
		 */
		vips_snprintf( buf, 256, 
			"openslide.level[%d].tile-width", level );
		if( (value = openslide_get_property_value( rslide->osr, buf )) )
			rslide->tile_width = atoi( value );
		vips_snprintf( buf, 256, 
			"openslide.level[%d].tile-height", level );
		if( (value = openslide_get_property_value( rslide->osr, buf )) )
			rslide->tile_height = atoi( value );
		if( value )
			VIPS_DEBUG_MSG( "readslide_new: found tile-size\n" );

		/* Some images have a bounds in the header. Crop to 
		 * that if autocrop is set. 
		 */
		if( rslide->autocrop ) 
			if( !get_bounds( rslide->osr, &rslide->bounds ) )
				rslide->autocrop = FALSE; 
		if( rslide->autocrop ) {
			VipsRect image;

			rslide->bounds.left /= rslide->downsample;
			rslide->bounds.top /= rslide->downsample;
			rslide->bounds.width /= rslide->downsample;
			rslide->bounds.height /= rslide->downsample;

			/* Clip against image size.
			 */
			image.left = 0;
			image.top = 0;
			image.width = w;
			image.height = h;
			vips_rect_intersectrect( &rslide->bounds, &image, 
				&rslide->bounds );

			/* If we've clipped to nothing, ignore bounds.
			 */
			if( vips_rect_isempty( &rslide->bounds ) )
				rslide->autocrop = FALSE;
		}
		if( rslide->autocrop ) {
			w = rslide->bounds.width;
			h = rslide->bounds.height;
		}
	}

	rslide->bg = 0xffffff;
	if( (background = openslide_get_property_value( rslide->osr,
		OPENSLIDE_PROPERTY_NAME_BACKGROUND_COLOR )) )
		rslide->bg = strtoul( background, NULL, 16 );

	if( w <= 0 || 
		h <= 0 || 
		rslide->downsample < 0 ) {
		vips_error( "openslide2vips", _( "getting dimensions: %s" ),
			openslide_get_error( rslide->osr ) );
		return( NULL );
	}
	if( w > INT_MAX || 
		h > INT_MAX ) {
		vips_error( "openslide2vips",
			"%s", _( "image dimensions overflow int" ) );
		return( NULL );
	}

	if( !rslide->autocrop ) {
		rslide->bounds.left = 0;
		rslide->bounds.top = 0;
		rslide->bounds.width = w;
		rslide->bounds.height = h;
	}

	vips_image_init_fields( out, w, h, 4, VIPS_FORMAT_UCHAR,
		VIPS_CODING_NONE, VIPS_INTERPRETATION_RGB, 1.0, 1.0 );

	for( properties = openslide_get_property_names( rslide->osr );
		*properties != NULL; properties++ )
		vips_image_set_string( out, *properties,
			openslide_get_property_value( rslide->osr,
			*properties ) );

	associated_names = g_strjoinv( ", ", (char **)
		openslide_get_associated_image_names( rslide->osr ) );
	vips_image_set_string( out, 
		"slide-associated-images", associated_names );
	VIPS_FREE( associated_names );

	return( rslide );
}