Beispiel #1
0
        void queue_debug::update_graph()
        {
            INVARIANT(_in_graph);
            INVARIANT(_out_graph);

            auto px = _x;
            _x+=GRAPH_STEP;

            m::mailbox_stats* stats = nullptr; 
            
            if(_mailbox_stats) stats = _mailbox_stats;
            else
            {
                auto mb = _mailbox.lock();
                if(!mb) return;
                stats = &(mb->stats());
            }

            CHECK(stats);
            auto in_push = stats->in_push_count;
            auto in_pop = stats->in_pop_count;
            auto out_push = stats->out_push_count;
            auto out_pop = stats->out_pop_count;
            stats->reset();

            draw_graph(*_in_graph, px, _prev_in_push+2, _x, in_push+2, _in_max, QPen{QBrush{QColor{"red"}}, 0.5});
            draw_graph(*_in_graph, px, _prev_in_pop, _x, in_pop, _in_max, QPen{QBrush{QColor{"orange"}}, 0.5});
            draw_graph(*_out_graph, px, _prev_out_push+2, _x, out_push+2, _out_max, QPen{QBrush{QColor{"green"}}, 0.5});
            draw_graph(*_out_graph, px, _prev_out_pop, _x, out_pop, _out_max, QPen{QBrush{QColor{"blue"}}, 0.5});
                    
            _prev_in_push = in_push;
            _prev_in_pop = in_pop;
            _prev_out_push = out_push;
            _prev_out_pop = out_pop;
        }
Beispiel #2
0
int main(int argc, char **argv) {
	int i, j;
	struct GRAPH *g, *tree=NULL;
	struct VERTEX *v;
	struct POINT p;
	DARNIT_KEYS keys;
	srand(time(NULL));
	d_init("Graphs", "uppg8", NULL);
	
	for(i=0; i<256; i++) {
		circle[i]=d_render_circle_new(32, 1);
		line[i]=d_render_line_new(1, 1);
	}
	
	for(j=0; j<4; j++)
		for(i=0; i<7; i++) {
			p.x=i*100+50;//(rand()%80)*10;
			p.y=j*100+50;//(rand()%48)*10;
			v=graph_add_vertex(&graph, p);
			for(g=graph; g; g=g->next)
				if(!(rand()%6))
					graph_add_edge(v, g->vertex, rand()%100, DIRECTION_DOUBLE);
		}
	tree=graph_prim(graph);
	draw_graph(graph);
	for(g=graph;;) {
		keys=d_keys_get();
		if(keys.start) {
			g=g==graph?tree:graph;
			draw_graph(g);
		}
		d_keys_set(keys);
		d_render_begin();
		d_render_tint(0xFF, 0xFF, 0xFF, 0xFF);
		for(i=0; i<vertices; i++)
			d_render_circle_draw(circle[i]);
		for(i=0; i<edges; i++) {
			d_render_tint(length[i], 0x7F, 0x0, 0xFF);
			d_render_line_draw(line[i], 1);
		}
		
		d_render_end();
		d_loop();
	}
	
	d_quit();
	return 0;
}
int main (int argc, char *argv[])
{
    graph g;
    int i;

    if(argc < 2)
    {
        printf("[main_maximum_partial] ERREUR : you have to specify a file containing a graph as the first argument of the main.\n");
        return EXIT_FAILURE;
    }

    else
    {
        gen_graph(argv[1], &g);
        draw_graph(g);

        subgraph desert;
        for(i=0 ; i<NB_VERTICES ; i++) desert[i]=0;

        maximum_partial(g,desert);

        draw_subgraph(desert,g.n);

        return EXIT_SUCCESS;
    }
}
Beispiel #4
0
int
exit_tk()
{
  int code;

  if (Tk_GetNumMainWindows() > 0) {
    sprintf(tcl_command_buffer, "done_calculation");
    code = Tcl_Eval(interp, tcl_command_buffer);
    if (code != TCL_OK) {
      fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
      return code;
    }
  }

  while (Tk_GetNumMainWindows() > 0) {
    sprintf(tcl_command_buffer, "tkwait variable window_changed");
    code = Tcl_Eval(interp, tcl_command_buffer);
    if (code != TCL_OK) {
      fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
      return code;
    }
    draw_graph(maxstep);
  }

  sprintf(tcl_command_buffer, "exit");
  Tcl_Eval(interp, tcl_command_buffer);
  Tcl_DeleteInterp(interp);
}
Beispiel #5
0
inline HRESULT IAtelier_summer::Draw()
{
    HRESULT hr = S_OK;
    CriticalLock::Scoped scope(_lockChange);
    bool bkgchanged = bkg_is_changed(_changed);
    //redraw all back-ground bitmap
    if (bkgchanged)
    {
        //draw backup graph using default bitmap render target
#ifdef  _DEBUG
        //MYTRACE(L"draw backup graph\n");
#endif  //_DEBUG
        _artist->BeginBmpDraw(true);
        _artist->SetTransform(&idmatrix);

        hr = draw_graph(true, IGlyph_summer::GLYPH_TYPE_BKG);

        if (SUCCEEDED(hr))
            hr = _artist->EndBmpDraw();
    }

    //if (SUCCEEDED(hr)) {
    //    if (bkgchanged || graph_is_changed(_changed))
    //    {
            _artist->BeginDraw(true);
            _artist->SetTransform(&idmatrix);

            //draw background first
            _artist->DrawBitmap(_artist->GetDefaultBmp(), _rect, _rect);

            //draw all graph
            hr = draw_graph(bkgchanged);
            //copy to screen-bitmap
            if (SUCCEEDED(hr))
                hr = CopyFromRenderTarget(_pHwndRT, _appbmp._screen, pntZero, _rect);

            if (SUCCEEDED(hr))
                hr = _artist->EndDraw();
    //    } else
    //        hr = draw_screen_bitmap();
    //}

    if (SUCCEEDED(hr))
        set_change(GLYPH_CHANGED_NONE);

    return hr;
}
Beispiel #6
0
void DecisionViewGraph::paintEvent(QPaintEvent *)
{
    if (dataIsChanging)
       return;

    QPainter painter(this);
    unsigned int margin = 20;
    draw_graph(painter, width(), height(), margin, X, Y, N);
}
Beispiel #7
0
/*############################# draw_stat() #############################*/
void
draw_stat(void)
{
   draw_x_axis();
   draw_x_values();
   draw_y_axis();
   draw_graph();

   return;
}
Beispiel #8
0
static bool
draw_commit_title(struct view *view, struct view_column *column,
		  const struct graph *graph, const struct graph_canvas *graph_canvas,
		  const struct ref *refs, const char *commit_title)
{
	if (graph && graph_canvas && column->opt.commit_title.graph &&
	    draw_graph(view, graph, graph_canvas))
		return true;
	if (draw_refs(view, column, refs))
		return true;
	return draw_text_overflow(view, commit_title, LINE_DEFAULT,
			column->opt.commit_title.overflow, 0);
}
Beispiel #9
0
/** Handle statustext and draw all things in infobar of specified screen
  *\param sc Screen number
  *\param str String
  */
void
statustext_handle(int sc, char *str)
{
     char *lastst;
     int i, nr, ng, ns, sw = 0;
     StatusRec r[128];
     StatusGraph g[128];
     StatusText s[128];

     /* If the str == the current statustext, return (not needed) */
     if(!str)
          return;

     if(sc == conf.systray.screen)
          sw = systray_get_width();

     barwin_refresh_color(infobar[sc].bar);

     /* save last status text address (for free at the end) */
     lastst = infobar[sc].statustext;

     infobar[sc].statustext = xstrdup(str);

     /* Store rectangles, located text & images properties. */
     nr = statustext_rectangle(r, str);
     ng = statustext_graph(g, str);
     ns = statustext_text(s, str);

     /* Draw normal text (and possibly colored with \#color\ blocks) */
     statustext_normal(sc, str);

     /* Draw rectangles with stored properties. */
     for(i = 0; i < nr; ++i)
          draw_rectangle(infobar[sc].bar->dr, r[i].x - sw, r[i].y, r[i].w, r[i].h, r[i].color);

     /* Draw graphs with stored properties. */
     for(i = 0; i < ng; ++i)
          draw_graph(infobar[sc].bar->dr, g[i].x - sw, g[i].y, g[i].w, g[i].h, g[i].color, g[i].data);

     /* Draw located text with stored properties. */
     for(i = 0; i < ns; ++i)
          draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, s[i].text);

     barwin_refresh(infobar[sc].bar);

     free(lastst);

     return;
}
Beispiel #10
0
int panel_draw(struct panel *panel, struct vidframe *frame)
{
	int err;

	if (!panel || !frame)
		return EINVAL;

	dim_frame(frame, panel->yoffs, panel->size.h);

	err = draw_text(panel, frame);
	if (err)
		return err;
	draw_graph(panel, frame);

	return 0;
}
Beispiel #11
0
void draw_vertex_callback_graph(tree *T, mp_graphics *G, INT *v, INT layer, tree_node *N, INT x, INT y, INT dx, INT dy)
{
	//INT d1;
	//BYTE str[1000];

	cout << "draw_vertex_callback_graph x=" << x << " y=" << y << " dx = " << dx << " dy=" << dy << endl;
	//d1 = LG->L[layer].Nodes[node].data1;
	//nb_V = LG->data1;
	
	//sprintf(str, "%ld", N->value);

	//G->aligned_text(x, y, "", str);

	if (f_graph_perm) {
		INT i, a, b, x, y, x1, y1;
		for (i = 0; i < layer; i++) {
			a = v[i];
			k2ij(a, x, y, graph_nb_V);
			x1 = graph_perm[x];
			y1 = graph_perm[y];
			b = ij2k(x1, y1, graph_nb_V);
			v[i] = b;
			}
		}


	if (f_multiple_circles) {
		draw_graph_on_multiple_circles(G, x, y, dx, dy, graph_nb_V, v, layer, nb_circles);
			// in GALOIS/draw.C
		}
	else {
		draw_graph(G, x, y, dx, dy, graph_nb_V, v, layer);
			// in GALOIS/draw.C
		}

}
Beispiel #12
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    //Устанавливаем ui и инициализируем окружение
    ui->setupUi(this);
    scene = new QGraphicsScene(QRect(10, 10, 331, 271),ui->graphicsView);
    timer = new QTimer();

    ui->graphicsView->setScene(scene);
    ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
    ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

    srand(time(NULL));
    timer->setInterval(1000/FRAME_RATE);
    qwt_install(ui->qwtwidg);

   //соединяем кнопки с функциями
    QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(check_button()));
    QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(calc()));
    QObject::connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(reset()));
    QObject::connect(ui->pushButton_2,SIGNAL(clicked()),scene,SLOT(update()));
            draw_graph(ui->spinBox->value(),m);
}
Beispiel #13
0
/** Draw a graph widget.
 * \param ctx The draw context.
 * \param w The widget node we are called from.
 * \param offset The offset to draw at.
 * \param used The already used width.
 * \param p A pointer to the object we're drawing onto.
 * \return The widget width.
 */
static void
graph_draw(widget_t *widget, draw_context_t *ctx,
           area_t geometry, wibox_t *p)
{
    int margin_top, y;
    graph_data_t *d = widget->data;
    area_t rectangle;
    vector_t color_gradient;

    if(!d->plots.len)
        return;

    /* box = the plot inside the rectangle */
    if(!d->box_height)
        d->box_height = round(ctx->height * d->height) - 2;

    margin_top = round((ctx->height - (d->box_height + 2)) / 2) + geometry.y;

    /* draw background */
    rectangle.x = geometry.x + 1;
    rectangle.y = margin_top + 1;
    rectangle.width = d->size;
    rectangle.height = d->box_height;
    draw_rectangle(ctx, rectangle, 1.0, true, &d->bg);

    /* for plot drawing */
    rectangle.y = margin_top + d->box_height + 1; /* bottom left corner as starting point */
    rectangle.width = d->size; /* rectangle.height is not used */

    draw_graph_setup(ctx); /* setup some drawing options */

    /* gradient begin either left or on the right of the rectangle */
    if(d->grow == Right)
        color_gradient.x = rectangle.x + rectangle.width;
    else
        color_gradient.x = rectangle.x;

    for(int i = 0; i < d->plots.len; i++)
    {
        plot_t *plot = &d->plots.tab[i];

        switch(plot->draw_style)
        {
        case Top_Style:
            color_gradient.y = rectangle.y - rectangle.height;
            if(plot->vertical_gradient)
            {
                color_gradient.x_offset = 0;
                color_gradient.y_offset = rectangle.height;
            }
            else
            {
                color_gradient.y_offset = 0;

                if(d->grow == Right)
                    color_gradient.x_offset = - rectangle.width;
                else
                    color_gradient.x_offset = rectangle.width;
            }

            for(y = 0; y < d->size; y++)
            {
                /* reverse values (because drawing from top) */
                d->draw_from[y] = d->box_height; /* i.e. no smaller value -> from top of box */
                d->draw_to[y] = d->box_height - plot->lines[y]; /* i.e. on full plot -> 0 = bottom */
            }
            draw_graph(ctx, rectangle , d->draw_from, d->draw_to, plot->index, d->grow, color_gradient,
                       &plot->color_start, &plot->pcolor_center, &plot->pcolor_end);
            break;
        case Bottom_Style:
            color_gradient.y = rectangle.y;
            if(plot->vertical_gradient)
            {
                color_gradient.x_offset = 0;
                color_gradient.y_offset = - rectangle.height;
            }
            else
            {
                color_gradient.y_offset = 0;

                if(d->grow == Right)
                    color_gradient.x_offset = - rectangle.width;
                else
                    color_gradient.x_offset = rectangle.width;
            }

            p_clear(d->draw_from, d->size);
            draw_graph(ctx, rectangle, d->draw_from, plot->lines, plot->index, d->grow, color_gradient,
                       &plot->color_start, &plot->pcolor_center, &plot->pcolor_end);
            break;
        case Line_Style:
            color_gradient.y = rectangle.y;
            if(plot->vertical_gradient)
            {
                color_gradient.x_offset = 0;
                color_gradient.y_offset = -rectangle.height;
            }
            else
            {
                color_gradient.y_offset = 0;
                if(d->grow == Right)
                    color_gradient.x_offset = - rectangle.width;
                else
                    color_gradient.x_offset = rectangle.width;
            }

            draw_graph_line(ctx, rectangle, plot->lines, plot->index, d->grow, color_gradient,
                            &plot->color_start, &plot->pcolor_center, &plot->pcolor_end);
            break;
        }
    }

    /* draw border (after line-drawing, what paints 0-values to the border) */
    rectangle.x = geometry.x;
    rectangle.y = margin_top;
    rectangle.width = d->size + 2;
    rectangle.height = d->box_height + 2;
    draw_rectangle(ctx, rectangle, 1.0, false, &d->border_color);
}
Beispiel #14
0
void
main(int argc, char *argv[])
{
  int c, i;
  int statistics = 0;
  int draw = 0;
  char initialize = 'p';

  extern char *optarg;

#ifndef NOTIMES
  srand48((long)time(NULL));
#else
  srand48(0);
#endif //NOTIMES

  if (readgraph())
    exit(1);

  if (nvertices == 0) {
    fprintf(stderr, "Empty graph\n");
    exit(1);
  }

  if (nvertices < 200)
    iter[1] = 200;
  else
    iter[1] = nvertices;

  iter[0] = iter[1] / 20;
  iter[2] = iter[1] / 10;

  height = 0.65 * sqrt((double)nvertices);

  while ((c = getopt(argc, argv, "fg:i:n:osv:w:B:D:E:H:NOW:")) != EOF)
  {
    switch (c) {
    case 'f':
      flat = 1;
      break;
    case 'g':
      sscanf( optarg, "%d,%d,%d", &(gstep[0]), &(gstep[1]), &(gstep[2]) );
      draw = 1;
      break;
    case 'i':
      initialize = optarg[0];
      break;
      break;
    case 'n':
      sscanf( optarg, "%d,%d,%d", &(iter[0]), &(iter[1]), &(iter[2]) );
      break;
    case 'o':
      fprintf(stdout,"%d\n",getpid());  fflush(stdout);
      break;
    case 's':
      statistics = 1;
      break;
    case 'v':
      sscanf( optarg, "%d,%d,%d", &(vstep[0]), &(vstep[1]), &(vstep[2]) );
      break;
    case 'w':
      bestangle = atof( optarg ) / 180.0 * M_PI;
      break;
    case 'B':
      frames_begin = atoi( optarg );
      break;
    case 'D':
      maxdist = atof( optarg );
      break;
    case 'E':
      frames_end = atoi( optarg );
      break;
    case 'H':
      height = atof( optarg );
      break;
    case 'N':
      print_frame_count = 1;
      break;
    case 'O':
      count_only = print_frame_count = 1;
      break;
    case 'W':
      sleep_ms = atoi(optarg);
      break;
    case '?':
      fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
      exit(1);
    }
  }

  switch(initialize) {
  case 'r':
    random_positions();
    break;
  case 's':
    initial_positions_planar(1);
    break;
  case 'z':
    zero_out_positions();
    break;
  case 'p':
    initial_positions_planar(0);
    break;
  default:
    break;
  }

  for (i = 1; i <= nvertices; i++) {
    vertices[i].saved_pos.x = vertices[i].pos.x;
    vertices[i].saved_pos.y = vertices[i].pos.y;
    vertices[i].saved_pos.z = vertices[i].pos.z;
  }

  maxstep = iter[0] + iter[1] + iter[2];

#if USE_TCL
  if (draw > 0) {
    init_tk();
    draw_graph(0);
    sprintf(tcl_command_buffer, "stop_go");
    c = Tcl_Eval(interp, tcl_command_buffer);
    if (c != TCL_OK) {
      fprintf(stderr, "in Tcl_Eval: %s\n", interp->result);
      exit(c);
    }
  }
#endif /*USE_TCL*/

  if (position())
    exit(1);

  if (writegraph())
    exit(1);

  if (statistics)
    show_statistics();

#if USE_TCL
  if (draw > 0)
    exit_tk();
#endif /*USE_TCL*/
}
Beispiel #15
0
Datei: draw.c Projekt: bbolli/tig
bool
view_column_draw(struct view *view, struct line *line, unsigned int lineno)
{
	struct view_column *column;
	struct view_column_data column_data = {};

	if (!view->ops->get_column_data(view, line, &column_data))
		return TRUE;

	for (column = view->columns; column; column = column->next) {
		mode_t mode = column_data.mode ? *column_data.mode : 0;
		int width = column->width;

		if (column->hidden)
			continue;

		switch (column->type) {
		case VIEW_COLUMN_DATE:
			if (draw_date(view, column, column_data.date))
				return TRUE;
			continue;

		case VIEW_COLUMN_AUTHOR:
			if (draw_author(view, column, column_data.author))
				return TRUE;
			continue;

		case VIEW_COLUMN_REF:
		{
			const struct ref *ref = column_data.ref;
			enum line_type type = !ref || !ref->valid ? LINE_DEFAULT : get_line_type_from_ref(ref);
			const char *name = ref ? ref->name : NULL;

			if (draw_field(view, type, name, width, ALIGN_LEFT, FALSE))
				return TRUE;
			continue;
		}

		case VIEW_COLUMN_ID:
			if (draw_id(view, column, column_data.id))
				return TRUE;
			continue;

		case VIEW_COLUMN_LINE_NUMBER:
			if (draw_lineno(view, column, column_data.line_number ? *column_data.line_number : lineno))
				return TRUE;
			continue;

		case VIEW_COLUMN_MODE:
			if (draw_mode(view, mode))
				return TRUE;
			continue;

		case VIEW_COLUMN_FILE_SIZE:
			if (draw_file_size(view, column, column_data.file_size ? *column_data.file_size : 0, mode))
				return TRUE;
			continue;

		case VIEW_COLUMN_COMMIT_TITLE:
			if (column_data.graph && draw_graph(view, column_data.graph))
				return TRUE;
			if (column_data.refs && draw_refs(view, column, column_data.refs))
				return TRUE;
			if (draw_commit_title(view, column_data.commit_title, 0))
				return TRUE;
			continue;

		case VIEW_COLUMN_FILE_NAME:
			if (draw_filename(view, column, column_data.file_name, TRUE, mode))
				return TRUE;
			continue;

		case VIEW_COLUMN_TEXT:
			if (line->wrapped && draw_text(view, LINE_DELIMITER, "+"))
				return TRUE;
			if (draw_text(view, line->type, column_data.text))
				return TRUE;
			continue;
		}
	}

	return TRUE;
}
Beispiel #16
0
int
  position(void)
{
  FILE *pipe;
  static char letter[] = { 'a', 'b', 'c' };
  int it, phase;
  int do_local, do_central, do_bondlength, do_angular;
  int i;
  struct vertex *v;
  double arg, temp;
  double maxdisp, sumdisp, avgdisp, sumlength, avglength;
  double bondlength;
  int frame_count;
  int step;

  for (i = 1; i <= nvertices; i++) {
    v = &vertices[i];
    v->saved_pos.x = v->pos.x;
    v->saved_pos.y = v->pos.y;
    v->saved_pos.z = v->pos.z;
  }

  step = 0;

#if USE_TCL
  if (gstep[0] > 0)
    for (it = 0; it < frames_begin; it++)
      frame_count = draw_graph(step);
#endif /*USE_TCL*/

  for (phase = 0; phase < 3; phase++) {
#if USE_TCL
    if (gstep[phase] > 0)
      frame_count = draw_graph(step);
#endif /*USE_TCL*/

    if (vstep[phase] > 0)
      fprintf(stderr, "Phase %c:\n", letter[phase]);

    for (it = 0; it < iter[phase]; ++it) {
      ++step;

      for (i = 1; i <= nvertices; i++)
	vertices[i].disp.x = vertices[i].disp.y = vertices[i].disp.z = 0.0;

      do_bondlength = 1;

      arg = 1.0 - (double)it / (double)iter[phase];

      switch (phase) {
      case 0:
	temp = arg * arg;
	bondlength = 0.0;

	do_central = 1;
	do_local = 0;
	do_angular = 0;
	break;
      case 1:
	temp = arg * arg * arg * arg;
	bondlength = 0.0;

	do_local = 1;
	do_central = 0;
	do_angular = 0;
	break;
      case 2:
	temp = 0.4 * arg * arg * arg;
	bondlength = 1.414;

	do_local = 0;
	do_central = 0;
	do_angular = 1;
	break;
      }

      if (do_bondlength)
	sumlength = compute_bondlength_forces(bondlength);

      if (do_local)
	compute_local_repulsive_forces();

      if (do_central)
	compute_central_repulsion_forces();

      if (do_angular)
	compute_angular_forces();

      perform_displacement(temp, &sumdisp, &maxdisp);

#if USE_TCL
      if ( gstep[phase] > 0
	   && ( it == iter[phase] - 1 || it % gstep[phase] == 0) )
      {
	frame_count = draw_graph(step);
      }
#endif /*USE_TCL*/

      if ( vstep[phase] > 0
	   && ( it == iter[phase] - 1 || it % vstep[phase] == 0) )
      {
	avgdisp = sumdisp / (double)nvertices;
	avglength = sumlength / (double)nedges;

	fprintf( stderr, "i = %3d, temp = %8.6lf, maxd = %8.6lf, ",
		 it, temp, maxdisp );
	fprintf( stderr, "avgd = %8.6lf, avgl = %8.6lf\n",
		 avgdisp, avglength );
      }
    }
  }

#if USE_TCL
  for (it = 0; it < frames_end; it++)
    frame_count = draw_graph(step);
#endif /*USE_TCL*/

  if (print_frame_count)
    fprintf( stderr, "Frame # = %d\n", frame_count );

  maxstep = step;

  return 0;
}
Beispiel #17
0
void draw_all()
{
	//draw_graph(true_to_ecc, 64, 192, 62);
	draw_graph(t_to_e_AstronomyAnswers, 192, 64, 62);
	
}
Beispiel #18
0
void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, stats_t *st_to, stats_t *tcp_rtt_stats, int re_tx, int pmtu, int tos, stats_t *close_st, stats_t *t_write, int n_cookies, char abbreviate, stats_t *stats_header_size)
{
	double k = 0.0;
	char force_redraw = 0;
	struct pollfd p = { 0, POLLIN, 0 };

	werase(w_stats);

	if (n_ok)
	{
		char buffer[4096] = { 0 }, *scc_str = NULL, *kalman_str = NULL;
		int buflen = 0;

		myprintloc(w_stats, 0, 0, "         %6s %6s %6s %6s %6s", gettext("latest"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
		show_stats_t(1, 0, gettext("resolve"), resolve,   abbreviate);
		show_stats_t(2, 0, gettext("connect"), connect,   abbreviate);
		show_stats_t(3, 0, gettext("ssl    "), ssl_setup, abbreviate);
		show_stats_t(4, 0, gettext("send   "), t_write,   abbreviate);
		show_stats_t(5, 0, gettext("request"), request,   abbreviate);
		show_stats_t(6, 0, gettext("close  "), close_st,  abbreviate);
		show_stats_t(7, 0, gettext("total  "), total,     abbreviate);

		scc_str    = format_value(get_cur_scc(), 5, 3, abbreviate);
		kalman_str = format_value(kalman_do(total -> cur), 5, 3, abbreviate);
		myprintloc(w_stats, 8, 0, gettext("ok: %3d, fail: %3d%s, scc: %s, kalman: %s"), n_ok, n_fail, use_tfo ? gettext(", with TFO") : "", scc_str, kalman_str);
		free(kalman_str);
		free(scc_str);

		if (max_x >= 44 * 2 + 1)
		{
			double trend = calc_trend();
			char trend_dir = ' ';

			myprintloc(w_stats, 0, 45, "         %6s %6s %6s %6s %6s", gettext("cur"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
			show_stats_t(1, 45, gettext("t offst"), st_to, abbreviate);

#if defined(linux) || defined(__FreeBSD__)
			show_stats_t(2, 45, gettext("tcp rtt"), tcp_rtt_stats, abbreviate);
#endif
			show_stats_t(3, 45, gettext("headers"), stats_header_size, abbreviate);

			if (trend < 0)
				trend_dir = '-';
			else if (trend > 0)
				trend_dir = '+';

			myprintloc(w_stats, 8, 48, gettext("# cookies: %d"), n_cookies);

#ifdef linux
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, re-tx: %2d, pmtu: %5d, TOS: %02x"), trend_dir, fabs(trend), re_tx, pmtu, tos);
#else
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, TOS: %02x"), trend_dir, fabs(trend), tos);
#endif
		}

		buflen = snprintf(buffer, sizeof buffer, gettext("HTTP rc: %s, SSL fp: %s"), last_connect_str, fp ? fp : gettext("n/a"));

		if (buflen <= max_x)
			myprintloc(w_stats, 9, 0, "%s", buffer);
		else
		{
			static char prev_sf[48] = { 0 };

			myprintloc(w_stats, 9, 0, gettext("http result code: %s"), last_connect_str);

			if (fp && strcmp(prev_sf, fp))
			{
				slow_log(gettext("\nSSL fingerprint: %s"), fp);

				memcpy(prev_sf, fp, 47);
			}
		}
	}

	memmove(&history[1], &history[0], (history_n - 1) * sizeof(double));
	memmove(&history_set[1], &history_set[0], (history_n - 1) * sizeof(char));

	history[0]= total -> cur;
	history_set[0] = 1;

	if (poll(&p, 1, 0) == 1 && p.revents == POLLIN)
	{
		int c = getch();

		if (c == 12) /* ^L */
			force_redraw = 1;

		if (c == 'H')
			pause_graphs = !pause_graphs;

		if (c == 'q')
			stop = 1;
	}

	if (dg && !pause_graphs)
	{
		draw_graph(k);
#ifdef FW
		draw_fft();
#endif
	}

	wnoutrefresh(w_stats);

	if (win_resize || force_redraw)
		recreate_terminal();
}
Beispiel #19
0
void MainWindow::printFile()
{
  GRPrintPagesDlg pagesdlg;
  if ( pagesdlg.exec() != QDialog::Accepted )
    return;

  int rows = pagesdlg.rows();
  int columns = pagesdlg.columns();

  QPrintDialog pr;
  if ( pr.exec() == QDialog::Accepted )
  {
    QPrinter *qp = pr.printer();

    int pwidth = qp->pageRect().width();
    int pheight = qp->pageRect().height();

    int npages = rows * columns;

    int gwidth = columns * pwidth, gheight = rows * pheight;

    QImage img(gwidth, gheight, QImage::Format_RGB444);

    if ( img.isNull() )
      return;

    // render graph

    QPainter gpaint;
    gpaint.begin(&img);

    gpaint.fillRect(img.rect(), Qt::white);

    QFont f("courier", 12);
    gpaint.setFont(f);

    QRect text_rect = gpaint.fontMetrics().boundingRect(G_title);
    int x = (gwidth - text_rect.width()) / 2;
    gpaint.drawText(x, text_rect.height(), G_title);

    PaintStruct ps;
    ps.p = &gpaint;
    ps.border = 60;
    set_drawing_rectangle(gwidth-120, gheight-120);
    display_complete_graph();
    draw_graph(draw_line, draw_rect, draw_poly, &ps);

    gpaint.end();

    // copy to pages

    QPainter prpaint;
    prpaint.begin(qp);

    QRect src;
    QRect dst(0, 0, pwidth, pheight);
    for ( int page = 0, col = 0, row = 0; page < npages; ++page )
    {
      src.setLeft(col*pwidth);
      src.setTop(row*pheight);
      src.setWidth(pwidth);
      src.setHeight(pheight);
      prpaint.drawImage(QPoint(0, 0), img, src);

      // next
      if ( page < npages - 1 )
        qp->newPage();

      if ( col < columns - 1 )
        ++col;
      else
      {
        ++row;
        col = 0;
      }
    }

    prpaint.end();

    //this will reset the drawing rectangle to the canvas values
    canvas->viewport()->repaint();
    display_complete_graph();
  }
}
Beispiel #20
0
void augment()                         //main function of the algorithm
{
    if (verbose)
    {
        printf("\n\nAugment(.) call\n");
        printf("Current matching is as follows:\n");
        print_matching();
    }

    if (max_match == n) return;        //check wether matching is already perfect
    int x, y, root;                    //just counters and root vertex
    int q[N], wr = 0, rd = 0;          //q - queue for bfs, wr,rd - write and read

    root = 0;                          // stop warning, it will be assigned below before xy has
                                       // a bunch of -1's in it to start.

                                       //pos in queue
    memset(S, false, sizeof(S));       //init set S
    memset(T, false, sizeof(T));       //init set T
    memset(prev, -1, sizeof(prev));    //init set prev - for the alternating tree
    for (x = 0; x < n; x++)            //finding root of the tree
        if (xy[x] == -1)
        {
            q[wr++] = root = x;
            prev[x] = -2;
            S[x] = true;
            break;
        }


    for (y = 0; y < n; y++)            //initializing slack array
    {
        slack[y] = lx[root] + ly[y] - cost[root][y];
        slackx[y] = root;
    } //second part of augment() function

    
    while (true)                                                        //main cycle
    {
        while (rd < wr)                                                 //building tree with bfs cycle
        {
            x = q[rd++];                                                //current vertex from X part
            for (y = 0; y < n; y++)                                     //iterate through all edges in equality graph
                if (cost[x][y] == lx[x] + ly[y] &&  !T[y])
                {
                    if (yx[y] == -1) break;                             //an exposed vertex in Y found, so
                                                                        //augmenting path exists!
                    T[y] = true;                                        //else just add y to T,
                    q[wr++] = yx[y];                                    //add vertex yx[y], which is matched
                                                                        //with y, to the queue
                    add_to_tree(yx[y], x);                              //add edges (x,y) and (y,yx[y]) to the tree
                }
            if (y < n) break;                                           //augmenting path found!
        }
        if (y < n) break;                                               //augmenting path found!

        if (verbose)
        {
            printf("Augmenting path not found\n");

            print_S_T_sets();
        }

        update_labels();                                                //augmenting path not found, so improve labeling

        draw_all_bfs_trees(root);

        wr = rd = 0;                
        for (y = 0; y < n; y++)        
        //in this cycle we add edges that were added to the equality graph as a
        //result of improving the labeling, we add edge (slackx[y], y) to the tree if
        //and only if !T[y] &&  slack[y] == 0, also with this edge we add another one
        //(y, yx[y]) or augment the matching, if y was exposed
            if (!T[y] &&  slack[y] == 0)
            {
                if (yx[y] == -1)                                        //exposed vertex in Y found - augmenting path exists!
                {
                    x = slackx[y];
                    break;
                }
                else
                {
                    T[y] = true;                                        //else just add y to T,
                    if (!S[yx[y]])    
                    {
                        q[wr++] = yx[y];                                //add vertex yx[y], which is matched with
                                                                        //y, to the queue
                        add_to_tree(yx[y], slackx[y]);                  //and add edges (x,y) and (y,
                                                                        //yx[y]) to the tree
                    }
                }
            }
        if (y < n) break;                                               //augmenting path found!
    }


    if (y < n)                                                          //we found augmenting path!
    {

        if (verbose)
        {
            draw_graph(y); 

            printf("Augmenting path found\n");

            printf("Exposed vertex y%d (via x%d)\n", y, x);

            printf("Matching before is as follows:\n");
            print_matching();

            draw_all_bfs_trees(root);
            pause_for_user();

            printf("Augmenting path:\n");
            //printf("(y) y%d --> x%d (x) ", y, x);
            printf("y%d --> x%d ", y, x);
            fflush(stdout);
            int tx = x;
            while (prev[tx] != -2)
            {
                printf("<===> y%d ", xy[tx]);
                fflush(stdout);
                tx = prev[tx];
                printf("--> x%d ", tx);
                fflush(stdout);
                if (tx == -1)
                {
                    printf("error :-(\n");
                    break;
                }

            }
            printf("\n");

            
        }

        max_match++;                                                    //increment matching
        //in this cycle we inverse edges along augmenting path
        for (int cx = x, cy = y, ty; cx != -2; cx = prev[cx], cy = ty)
        {
            ty = xy[cx];
            yx[cy] = cx;
            xy[cx] = cy;
        }

        if (verbose)
        {

            draw_graph(y); 
            pause_for_user();

            printf("Matching after is as follows:\n");
            print_matching();
            
            printf("\n");

        }



        augment();                                                      //recall function, go to step 1 of the algorithm
    }
}//end of augment() function
Beispiel #21
0
//---------------------------------------------------------------------------
void MainWindow::drawGraph(PaintStruct *p) {
  draw_graph(draw_line, draw_rect, draw_poly, p);
}
Beispiel #22
0
static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer p) {
    draw_graph(cr);
    return FALSE;
}
Beispiel #23
0
static BOOL CALLBACK status_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	status_t * s = (status_t*)GetWindowLong(hDlg, GWL_USERDATA);

	switch (uMsg)
	{
	case WM_INITDIALOG :
		SetWindowLong(hDlg, GWL_USERDATA, lParam);
		s = (status_t*)lParam;
		
		s->hGraph = GetDlgItem(hDlg, IDC_STATUS_GRAPH);
		s->hDc = GetDC(s->hGraph);
		{
			RECT rect;
			GetWindowRect(s->hGraph, &rect);
			s->width = rect.right - rect.left;  
			s->height = rect.bottom - rect.top;
		}
		s->width31 = s->width/31;
		s->stride = (s->width/4+1)*4;

		s->buffer = malloc(s->width * s->stride);

		s->bi = malloc(sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
		memset(s->bi, 0, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));

		s->bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
		s->bi->bmiHeader.biWidth  = s->stride;
		s->bi->bmiHeader.biHeight = s->height;
		s->bi->bmiHeader.biPlanes = 1;
		s->bi->bmiHeader.biBitCount = 8;
		s->bi->bmiHeader.biCompression = BI_RGB;

		set_bic(s->bi->bmiColors, CLR_BG,	   0,   0,   0);
		set_bic(s->bi->bmiColors, CLR_FG,	 128, 128, 128);
		set_bic(s->bi->bmiColors, CLR_QUANT_I,  255, 0,   0);
		set_bic(s->bi->bmiColors, CLR_QUANT_P,  0, 0,   255);
		set_bic(s->bi->bmiColors, CLR_QUANT_B,  0, 192,   0);

		SelectObject(s->hDc, GetStockObject(DEFAULT_GUI_FONT));
		SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);
		SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);
		GetTextMetrics(s->hDc, &s->tm);

		draw_graph(s);
		SetTimer(hDlg, IDC_STATUS_GRAPH, 1000, NULL);	/* 1 second */
 		break;

	case WM_DESTROY :
		free(s->buffer);
		free(s->bi);
		KillTimer(hDlg, IDC_STATUS_GRAPH);
		s->hDlg = NULL;
		break;

	case WM_DRAWITEM :
		if (wParam==IDC_STATUS_GRAPH) {
			int i;

			/* copy buffer into dc */
			SetDIBitsToDevice(s->hDc, 
				0, 0, s->width, s->height,
				0, 0, 0, s->height,
				s->buffer, s->bi, DIB_RGB_COLORS);

			SetTextAlign(s->hDc, GetTextAlign(s->hDc)|TA_CENTER);

			for (i=0; i<31; i++) {
				TextOut(s->hDc, i*s->width31 + s->width/62, 
					s->height-s->tm.tmHeight, number[i], strlen(number[i]));
			}
		}
		break;

	case WM_TIMER :
		if (wParam==IDC_STATUS_GRAPH) {
			double avg_q; char buf[16];

			SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, (unsigned int)s->count[1], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, (unsigned int)s->count[2], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, (unsigned int)s->count[3], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_NUM, (unsigned int)s->count[0], FALSE);
			
			SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_PQ_MIN, s->min_quant[2], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_PQ_MAX, s->max_quant[2], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_BQ_MIN, s->min_quant[3], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_BQ_MAX, s->max_quant[3], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_Q_MIN, s->min_quant[0], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_Q_MAX, s->max_quant[0], FALSE);

			SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);
			if (s->count[1]>0)
				SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, (unsigned int)(s->tot_length[1]/s->count[1]), FALSE);
			else
				SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, (unsigned int)(s->tot_length[1]/1024), FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);
			if (s->count[2]>0)
				SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, (unsigned int)(s->tot_length[2]/s->count[2]), FALSE);
			else
				SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, (unsigned int)(s->tot_length[2]/1024), FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);
			if (s->count[3]>0)
				SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, (unsigned int)(s->tot_length[3]/s->count[3]), FALSE);
			else
				SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, (unsigned int)(s->tot_length[3]/1024), FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);
			if (s->count[0]>0)
				SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, (int)(s->tot_length[0]/s->count[0]), FALSE);
			else
				SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);
			SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, (unsigned int)(s->tot_length[0]/1024), FALSE);

			if (s->count[0]>0) {
				uint64_t kbits = 8*s->tot_length[0]/1000;
				double secs = (double)s->count[0]/s->fps;
			   SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);
			}else{
				SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);
			}

			avg_q = avg_quant(s->quant[0], s->min_quant[1], s->max_quant[1], buf) * s->count[1];
			SetDlgItemText(hDlg, IDC_STATUS_IQ_AVG, buf);

			avg_q += avg_quant(s->quant[1], s->min_quant[2], s->max_quant[2], buf) * s->count[2];
			SetDlgItemText(hDlg, IDC_STATUS_PQ_AVG, buf);
			
			avg_q += avg_quant(s->quant[2], s->min_quant[3], s->max_quant[3], buf) * s->count[3];
			SetDlgItemText(hDlg, IDC_STATUS_BQ_AVG, buf);

			if (s->count[0] != 0) avg_q /= (double)s->count[0];
			sprintf(buf, "%.2f", avg_q);
			SetDlgItemText(hDlg, IDC_STATUS_Q_AVG, buf);

			draw_graph(s);
			InvalidateRect(s->hGraph, NULL, FALSE);
		}
		break;

	case WM_COMMAND :
		if (LOWORD(wParam)==IDCANCEL) {
			DestroyWindow(hDlg);
		}
		break;

	default :
		return FALSE;
	}

	return TRUE;
}
Beispiel #24
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Font font;
    const char *font_name;
    int i = 0;
    HPDF_Outline root;

    const char *encodings[] = {
            "StandardEncoding",
            "MacRomanEncoding",
            "WinAnsiEncoding",
            "ISO8859-2",
            "ISO8859-3",
            "ISO8859-4",
            "ISO8859-5",
            "ISO8859-9",
            "ISO8859-10",
            "ISO8859-13",
            "ISO8859-14",
            "ISO8859-15",
            "ISO8859-16",
            "CP1250",
            "CP1251",
            "CP1252",
            "CP1254",
            "CP1257",
            "KOI8-R",
            "Symbol-Set",
            "ZapfDingbats-Set",
            NULL
    };

    pdf = HPDF_NewEx (error_handler, NULL, NULL, 0, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    /* set compression mode */
    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* Set page mode to use outlines. */
    HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);

    /* get default font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* load font object */
    #ifdef __WIN32__
    font_name = HPDF_LoadType1FontFromFile (pdf, "type1\\a010013l.afm",
            "type1\\a010013l.pfb");
    #else
    font_name = HPDF_LoadType1FontFromFile (pdf, "type1/a010013l.afm",
            "type1/a010013l.pfb");
    #endif

    /* create outline root. */
    root = HPDF_CreateOutline (pdf, NULL, "Encoding list", NULL);
    HPDF_Outline_SetOpened (root, HPDF_TRUE);

    while (encodings[i]) {
        HPDF_Page page = HPDF_AddPage (pdf);
        HPDF_Outline outline;
        HPDF_Destination dst;
        HPDF_Font font2;

        HPDF_Page_SetWidth (page, PAGE_WIDTH);
        HPDF_Page_SetHeight (page, PAGE_HEIGHT);

        outline = HPDF_CreateOutline (pdf, root, encodings[i], NULL);
        dst = HPDF_Page_CreateDestination (page);
        HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);
        /* HPDF_Destination_SetFitB(dst); */
        HPDF_Outline_SetDestination(outline, dst);

        HPDF_Page_SetFontAndSize (page, font, 15);
        draw_graph (page);

        HPDF_Page_BeginText (page);
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_MoveTextPos (page, 40, PAGE_HEIGHT - 50);
        HPDF_Page_ShowText (page, encodings[i]);
        HPDF_Page_ShowText (page, " Encoding");
        HPDF_Page_EndText (page);

        if (strcmp (encodings[i], "Symbol-Set") == 0)
            font2 = HPDF_GetFont (pdf, "Symbol", NULL);
        else if (strcmp (encodings[i], "ZapfDingbats-Set") == 0)
            font2 = HPDF_GetFont (pdf, "ZapfDingbats", NULL);
        else
            font2 = HPDF_GetFont (pdf, font_name, encodings[i]);

        HPDF_Page_SetFontAndSize (page, font2, 14);
        draw_fonts (page);

        i++;
    }

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}