Example #1
0
File: link.c Project: UIKit0/dia
static void
link_update_data(Link *link)
{
  Connection *conn = &link->connection;
  DiaObject *obj = &conn->object;
  Rectangle rect;
  Point p1,p2,p3,p4,pa;

/* Too complex to easily decide */
/*
  if (connpoint_is_autogap(conn->endpoint_handles[0].connected_to) ||
      connpoint_is_autogap(conn->endpoint_handles[1].connected_to)) {
    connection_adjust_for_autogap(conn);
  }
*/
  obj->position = conn->endpoints[0];

  link->pm_handle.pos = link->pm;

  connection_update_handles(conn);
  connection_update_boundingbox(conn);

  /* endpoint */
  p1 = conn->endpoints[0];
  p2 = conn->endpoints[1];

  /* bezier */
  compute_line(&p1,&p2,&link->pm,link->line);

  /* connection point */
  link->connector.pos.x=p1.x;
  link->connector.pos.y=p1.y;

  /* Update boundingbox for mid-point (TBD is this necessary ?) */
  rectangle_add_point(&obj->bounding_box, &link->pm);

  /* Add boundingbox for annotation text (over-estimated) : */
  pa=compute_annot(&p1,&p2,&link->pm,0.75,0.75);
  rect.left = pa.x-0.3;
  rect.right = rect.left+0.6;
  rect.top = pa.y - LINK_FONTHEIGHT;
  rect.bottom = rect.top + 2*LINK_FONTHEIGHT;
  rectangle_union(&obj->bounding_box, &rect);

  /* Add boundingbox for dependency decoration (with some overestimation toi be safe) */
  pa=bezier_line_eval(link->line,2,0.25);
  p3.x=pa.x-LINK_DEP_WIDTH*1.5;
  p3.y=pa.y-LINK_DEP_HEIGHT*1.5;
  p4.x=p3.x+LINK_DEP_WIDTH*3;
  p4.y=p3.y+LINK_DEP_HEIGHT*3;
  rect.left=p3.x;
  rect.right=p4.x;
  rect.top=p3.y;
  rect.bottom=p4.y;
  rectangle_union(&obj->bounding_box, &rect);
}
Example #2
0
static void
mbr_update_data(Mbr *mbr)
{
  Connection *conn = &mbr->connection;
  DiaObject *obj = &conn->object;
  Rectangle rect;
  Point p1,p2;
  Point p3,p4;
  gchar *text;

/* Too complex to easily decide -- this is essentially a bezier curve */
/*
  if (connpoint_is_autogap(conn->endpoint_handles[0].connected_to) ||
      connpoint_is_autogap(conn->endpoint_handles[1].connected_to)) {
    connection_adjust_for_autogap(conn);
  }
*/
  obj->position = conn->endpoints[0];

  mbr->pm_handle.pos = mbr->pm;

  connection_update_handles(conn);
  connection_update_boundingbox(conn);

  /* text width */
  text=compute_text(mbr);
  mbr->text_width = dia_font_string_width(text, mbr_font, MBR_DECFONTHEIGHT);
  mbr->text_ascent = dia_font_ascent(text, mbr_font, MBR_DECFONTHEIGHT);

  /* endpoint */
  p1 = conn->endpoints[0];
  p2 = conn->endpoints[1];

 /* bezier */
  compute_line(&p1,&p2,&mbr->pm,mbr->line);

  /* Add boundingbox for mid decoration (slightly overestimated) : */
  p3.x=mbr->pm.x-MBR_DEC_SIZE;
  p3.y=mbr->pm.y-MBR_DEC_SIZE;
  p4.x=p3.x+MBR_DEC_SIZE*2;
  p4.y=p3.y+MBR_DEC_SIZE*2;
  rect.left=p3.x;
  rect.right=p4.x;
  rect.top=p3.y;
  rect.bottom=p4.y;
  rectangle_union(&obj->bounding_box, &rect);

  /* Add boundingbox for text: */
  rect.left = mbr->pm.x-mbr->text_width/2;
  rect.right = rect.left + mbr->text_width;
  rect.top = mbr->pm.y - mbr->text_ascent;
  rect.bottom = rect.top + MBR_DECFONTHEIGHT;
  rectangle_union(&obj->bounding_box, &rect);

  g_free(text);   /* free auxilliary text */
}
Example #3
0
void Lowpass::filter_segment(
  float x0,
  float y0,
  float x1,
  float y1,
  float scale
)
{
  /* create the radial filter if it hasn't already been made */
  if (!filter_made)
    create_radial_filter();

  /* get the filter radius at the segment's center */
  float rad = rad_image->get_value((x0 + x1) * 0.5, (y0 + y1) * 0.5);

  /* find coordinates of line segment ends */
  x0 = x0 * xsize - 0.5;
  y0 = y0 * ysize / image->getaspect() - 0.5;
  x1 = x1 * xsize - 0.5;
  y1 = y1 * ysize / image->getaspect() - 0.5;

  /* find which pixels the segment can affect */

  int i0 = (int) Min (floor (x0 - rad), floor (x1 - rad));
  int i1 = (int) Max (ceil  (x0 + rad), ceil  (x1 + rad));
  int j0 = (int) Min (floor (y0 - rad), floor (y1 - rad));
  int j1 = (int) Max (ceil  (y0 + rad), ceil  (y1 + rad));

  /* clamp these values to the image size */
  i0 = Max (i0, 0);
  j0 = Max (j0, 0);
  i1 = Min (i1, xsize-1);
  j1 = Min (j1, ysize-1);

  /* compute equation for line through the segment */
  float a,b,c;
  compute_line (x0, y0, x1, y1, a, b, c);

  /* loop over the possibly affected pixels, adding the segment's */
  /* contribution to the image */

  for (int i = i0; i <= i1; i++)
    for (int j = j0; j <= j1; j++) {
      float value = better_filter_segment (i, j, x0, y0, x1, y1, a, b, c);
      image->pixel(i,j) += value * scale;
    }
}
Example #4
0
static void msglist_add(const char *msg) {
	int x, y;
	getyx(stdscr, y, x);
	move(0, 0);

	int n = compute_line(msg);
	int i;

	for (i = 0; i < n; ++i) {
		deleteln();
	}

	int newy = window_y - INPUT_MAXLINE - 2 - n + 1;
	move(newy, 0);
	for (i = 0; i < n; ++i) {
		insertln();
	}
	printw("%s", msg);
	move(y, x);

	refresh();
}
Example #5
0
/* -------------------------------------------------------------------------- */
unsigned int rt_compute_work( thread_info_t *ti)
{
    unsigned int i;
    unsigned int work_count = 0;

    struct timeval tv_start, tv_end;

    printf("t_id %d started doing work\n", ti->t_id);
    ti->sta_working = 0;

    while( ti->curr <= ti->end && finish_sig != 1 && ti->sta_v_sig == 0)
    {
        i = ti->curr;
        
        gettimeofday(&tv_start, NULL);
    
        compute_line( i, ti->t_id);
        ti->curr++;
        work_count++;
        
        gettimeofday(&tv_end, NULL);
        
        /* THIS IS NOT NICE! FIXME is there a better way to do this? */
        rt_update_estimate( ti, ((tv_end.tv_sec - tv_start.tv_sec)*1000000 + 
                                tv_end.tv_usec - tv_start.tv_usec) / 100);
    }
    
    /* When this thread gets the victim signal it needs to stop working now */
    if( ti->sta_v_sig)
    {
        ti->sta_v_sig = 0;
        rt_become_victim( ti);
    }
    
    return work_count;
}
Example #6
0
/* creation here */
static DiaObject *
mbr_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
{
  Mbr *mbr;
  Connection *conn;
  LineBBExtras *extra;
  DiaObject *obj;

  if (mbr_font == NULL) {
    mbr_font = dia_font_new_from_style(DIA_FONT_SANS, MBR_DECFONTHEIGHT);
  }

  mbr = g_malloc0(sizeof(Mbr));

  conn = &mbr->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  conn->endpoints[1].y -= 2;

  obj = &conn->object;
  extra = &conn->extra_spacing;
  switch (GPOINTER_TO_INT(user_data)) {
    case 1: mbr->type=MBR_CONTRIBUTES; break;
    case 2: mbr->type=MBR_OBSTRUCTS; break;
    case 3: mbr->type=MBR_CONFLICTS; break;
    case 4: mbr->type=MBR_RESP; break;
    case 5: mbr->type=MBR_MONITORS; break;
    case 6: mbr->type=MBR_CONTROLS; break;
    case 7: mbr->type=MBR_CAPABLEOF; break;
    case 8: mbr->type=MBR_PERFORMS; break;
    case 9: mbr->type=MBR_INPUT; break;
    case 10: mbr->type=MBR_OUTPUT; break;
    default: mbr->type=MBR_CONTRIBUTES; break;
  }

  obj->type = &kaos_mbr_type;
  obj->ops = &mbr_ops;

  /* connectionpoint init */
  connection_init(conn, 3, 0);

  mbr->text_width = 0.0;
  mbr->text_ascent = 0.0;

  mbr->pm.x=0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  mbr->pm.y=0.5*(conn->endpoints[0].y + conn->endpoints[1].y);
  mbr->pm_handle.id = HANDLE_MOVE_MID_POINT;
  mbr->pm_handle.type = HANDLE_MINOR_CONTROL;
  mbr->pm_handle.connect_type = HANDLE_NONCONNECTABLE;
  mbr->pm_handle.connected_to = NULL;
  obj->handles[2] = &mbr->pm_handle;

  compute_line(&conn->endpoints[0],&conn->endpoints[1],&mbr->pm,mbr->line);

  extra->start_long =
  extra->start_trans =
  extra->end_long = MBR_WIDTH/2.0;
  extra->end_trans = MAX(MBR_WIDTH,MBR_ARROWLEN)/2.0;

  mbr_update_data(mbr);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];

  /* bug workaround */
  if (GPOINTER_TO_INT(user_data)!=0) mbr->init=-1; else mbr->init=0;

  return &mbr->connection.object;
}
Example #7
0
File: link.c Project: UIKit0/dia
/* creation here */
static DiaObject *
link_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Link *link;
  Connection *conn;
  LineBBExtras *extra;
  DiaObject *obj;

  if (link_font == NULL) {
    link_font = dia_font_new_from_style(DIA_FONT_SANS, LINK_FONTHEIGHT);
  }

  link = g_malloc0(sizeof(Link));

  conn = &link->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  conn->endpoints[1].y -= 2;

  obj = &conn->object;
  extra = &conn->extra_spacing;

  switch (GPOINTER_TO_INT(user_data)) {
    case 1: link->type=UNSPECIFIED; break;
    case 2: link->type=POS_CONTRIB; break;
    case 3: link->type=NEG_CONTRIB; break;
    case 4: link->type=DEPENDENCY;  break;
    case 5: link->type=DECOMPOSITION; break;
    case 6: link->type=MEANS_ENDS;  break;
    default: link->type=UNSPECIFIED; break;
  }

  obj->type = &istar_link_type;
  obj->ops = &link_ops;

  /* connectionpoint init */
  connection_init(conn, 3, 0);   /* with mid-control */

  link->pm.x=0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  link->pm.y=0.5*(conn->endpoints[0].y + conn->endpoints[1].y);
  link->pm_handle.id = HANDLE_MOVE_MID_POINT;
  link->pm_handle.type = HANDLE_MINOR_CONTROL;
  link->pm_handle.connect_type = HANDLE_NONCONNECTABLE;
  link->pm_handle.connected_to = NULL;
  obj->handles[2] = &link->pm_handle;

  compute_line(&conn->endpoints[0],&conn->endpoints[1],&link->pm,link->line);

  extra->start_long =
  extra->start_trans =
  extra->end_long = LINK_WIDTH/2.0;
  extra->end_trans = MAX(LINK_WIDTH,LINK_ARROWLEN)/2.0;

  link_update_data(link);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];

  /* bug workaround */
  if (GPOINTER_TO_INT(user_data)!=0) link->init=-1; else link->init=0;

  return &link->connection.object;
}
Example #8
0
float Lowpass::new_quality(Streamline *st)
{
  float a,b,c;

  if (!filter_made) {
    create_radial_filter();
  }

  /* clear out the list of value contributions to the pixels */
  st->clear_values();

  /* examine each line segment in a streamline to find their contribution */
  /* to a low-pass filtered version of the image */

  for (int n = 0; n < st->samples - 1; n++) {

    /* find coordinates of line segment ends */

    float x0 = st->xs(n);
    float y0 = st->ys(n);
    float x1 = st->xs(n+1);
    float y1 = st->ys(n+1);
    float taper_scale = 0.5 * (st->pts[n].intensity + st->pts[n+1].intensity);

    float rad = rad_image->get_value((x0 + x1) * 0.5, (y0 + y1) * 0.5);

    x0 = x0 * xsize - 0.5;
    y0 = y0 * ysize / image->getaspect() - 0.5;
    x1 = x1 * xsize - 0.5;
    y1 = y1 * ysize / image->getaspect() - 0.5;

    /* find which pixels the segment can affect */

    int i0 = (int) Min (floor (x0 - rad), floor (x1 - rad));
    int i1 = (int) Max (ceil  (x0 + rad), ceil  (x1 + rad));
    int j0 = (int) Min (floor (y0 - rad), floor (y1 - rad));
    int j1 = (int) Max (ceil  (y0 + rad), ceil  (y1 + rad));

    /* clamp these values to the image size */
    i0 = Max (i0, 0);
    j0 = Max (j0, 0);
    i1 = Min (i1, xsize-1);
    j1 = Min (j1, ysize-1);

    /* compute equation for line through the segment */

    compute_line (x0, y0, x1, y1, a, b, c);

    /* loop over the possibly affected pixels */

    for (int i = i0; i <= i1; i++) {
      for (int j = j0; j <= j1; j++) {
        float value = better_filter_segment (i, j, x0, y0, x1, y1, a, b, c);
        value *= taper_scale;
        if (value > 0)
          st->add_value(i, j, value);
      }
    }
  }

  /* compute what the average pixel value would be if we added the streamline */

  float new_sum = sum;

  for (int n = 0; n < st->num_values; n++) {
    int i,j;
    float value;
    st->get_value (n, i, j, value);
    new_sum -= Square (target - image->pixel(i,j));
    image->pixel(i,j) += value;
    new_sum += Square (target - image->pixel(i,j));
  }

  /* take out what we added in */
  for (int n = 0; n < st->num_values; n++) {
    int i,j;
    float value;
    st->get_value (n, i, j, value);
    image->pixel(i,j) -= value;
  }


  return (new_sum);
}