void OverlayMenuDisplay::redraw() { ROS_DEBUG("redraw"); prepareOverlay(); { ScopedPixelBuffer buffer = overlay_->getBuffer(); QColor bg_color(0, 0, 0, 255.0 / 2.0); QColor fg_color(25, 255, 240, 255.0); QImage Hud = buffer.getQImage(*overlay_, bg_color); QPainter painter( &Hud ); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(fg_color, 1, Qt::SolidLine)); painter.setFont(font()); int line_height = fontMetrics().height(); int w = drawAreaWidth(next_menu_); painter.drawText(menu_padding_x, menu_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, next_menu_->title.c_str()); for (size_t i = 0; i < next_menu_->menus.size(); i++) { std::string menu = getMenuString(next_menu_, i); painter.drawText(menu_padding_x, line_height * ( 1 + i ) + menu_padding_y + menu_last_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, menu.c_str()); } if (next_menu_->current_index <= next_menu_->menus.size()) { // draw '>' painter.drawText(menu_padding_x - fontMetrics().width(">") * 2, line_height * ( 1 + next_menu_->current_index ) + menu_padding_y + menu_last_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, ">"); } // draw line int texture_width = overlay_->getTextureWidth(); int texture_height = overlay_->getTextureHeight(); painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height, menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.drawLine(texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height, texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height, texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height); painter.drawLine(menu_padding_x / 2, texture_height - menu_last_padding_y / 2, texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.end(); current_menu_ = next_menu_; } overlay_->setDimensions(overlay_->getTextureWidth(), overlay_->getTextureHeight()); int window_width = context_->getViewManager()->getRenderPanel()->width(); int window_height = context_->getViewManager()->getRenderPanel()->height(); double window_left = (window_width - (int)overlay_->getTextureWidth()) / 2.0; double window_top = (window_height - (int)overlay_->getTextureHeight()) / 2.0; overlay_->setPosition(window_left, window_top); }
void GrabCut::show() { Scalar fg_color(255,0,0); Scalar bg_color(0,255,0); cv::Mat scribbled_src = _src.clone(); const float alpha = 0.7f; for(int y=0; y < _gcut.rows; y++){ for(int x=0; x < _gcut.cols; x++){ if(_gcut.at<uchar>(y, x) == cv::GC_FGD) { cv::circle(scribbled_src, cv::Point(x, y), 2, fg_color, -1); } else if(_gcut.at<uchar>(y, x) == cv::GC_BGD) { cv::circle(scribbled_src, cv::Point(x, y), 2, bg_color, -1); } else if(_gcut.at<uchar>(y, x) == cv::GC_PR_BGD) { cv::Vec3b& pix = scribbled_src.at<cv::Vec3b>(y, x); pix[0] = (uchar)(pix[0] * alpha + bg_color[0] * (1-alpha)); pix[1] = (uchar)(pix[1] * alpha + bg_color[1] * (1-alpha)); pix[2] = (uchar)(pix[2] * alpha + bg_color[2] * (1-alpha)); } else if(_gcut.at<uchar>(y, x) == cv::GC_PR_FGD) { cv::Vec3b& pix = scribbled_src.at<cv::Vec3b>(y, x); pix[0] = (uchar)(pix[0] * alpha + fg_color[0] * (1-alpha)); pix[1] = (uchar)(pix[1] * alpha + fg_color[1] * (1-alpha)); pix[2] = (uchar)(pix[2] * alpha + fg_color[2] * (1-alpha)); } } } Rect roi; Mat scrb; roi = Rect(_src.cols,0,_src.cols,_src.rows); scribbled_src.copyTo(_dsp(roi)); Mat msk = getBinMask(); cv::Mat send = msk.clone(); cv::Mat sendFilter; cv::Mat resultMat = filterMaskAndMergeMat(send, _cutResultMask, _gcutBuffer); Mat fg = getFGByMask(resultMat);//getFG(); roi = Rect(_src.cols,_src.rows,_src.cols,_src.rows); fg.copyTo(_dsp(roi)); // imshow("fg", fg); // imshow("mergeResultMat", resultMat); _cutResultMask = resultMat; //Rect tmp = getMaskRct(_gcutBuffer); cvtColor(msk,msk,COLOR_GRAY2BGR); roi = Rect(0,_src.rows,_src.cols,_src.rows); msk.copyTo(_dsp(roi)); //imshow("msk", msk); //imshow("_mask", _mask); imshow(_name,_dsp); waitKey(1); }
void put_chars(struct part *p, unsigned char *c, int l) { static struct text_attrib_beginning ta_cache = { -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; static int bg_cache; static int fg_cache; int bg, fg; int i; struct link *link; struct point *pt; if (l < 0) overalloc(); /*printf("%d-", p->cx);for (i=0; i<l; i++) printf("%c", c[i]); printf("-\n");sleep(1);*/ while (par_format.align != AL_NO && p->cx == -1 && l && *c == ' ') c++, l--; if (!l) return; if (c[0] != ' ' || (c[1] && c[1] != ' ')) { last_tag_for_newline = (void *)&p->data->tags; } if (p->cx < par_format.leftmargin) p->cx = par_format.leftmargin; if (last_link || last_image || last_form || format.link || format.image || format.form) goto process_link; no_l: /*printf("%d %d\n",p->cx, p->cy);*/ if (memcmp(&ta_cache, &format, sizeof(struct text_attrib_beginning))) goto format_change; bg = bg_cache, fg = fg_cache; end_format_change: if (p->cx == par_format.leftmargin && *c == ' ' && par_format.align != AL_NO) c++, l--; if (p->y < p->cy + 1) p->y = p->cy + 1; if (nowrap && p->cx + l > rm(par_format)) return; set_hline(p, p->cx, p->cy, l, c, (((fg&0x08)<<3)|(bg<<3)|(fg&0x07))<<8, 1); p->cx += l; nobreak = 0; if (par_format.align != AL_NO) while (p->cx > rm(par_format) && p->cx > par_format.leftmargin) { int x; /*if (p->cx > p->x) { p->x = p->cx + par_format.rightmargin; if (c[l - 1] == ' ') p->x--; }*/ if (!(x = split_line(p))) break; /*if (LEN(p->cy-1) > p->x) p->x = LEN(p->cy-1);*/ align_line(p, p->cy - 1); nobreak = x - 1; } if ((p->xa += l) - (c[l-1] == ' ' && par_format.align != AL_NO) + par_format.leftmargin + par_format.rightmargin > p->xmax) p->xmax = p->xa - (c[l-1] == ' ' && par_format.align != AL_NO) + par_format.leftmargin + par_format.rightmargin; return; process_link: if ((last_link /*|| last_target*/ || last_image || last_form) && !xstrcmp(format.link, last_link) && !xstrcmp(format.target, last_target) && !xstrcmp(format.image, last_image) && format.form == last_form) { if (!p->data) goto x; link = &p->data->links[p->data->nlinks - 1]; if (!p->data->nlinks) { internal("no link"); goto no_l; } goto set_link; x:; } else { if (last_link) mem_free(last_link); /* !!! FIXME: optimize */ if (last_target) mem_free(last_target); if (last_image) mem_free(last_image); last_link = last_target = last_image = NULL; last_form = NULL; if (!(format.link || format.image || format.form)) goto no_l; if (d_opt->num_links) { unsigned char s[64]; unsigned char *fl = format.link, *ft = format.target, *fi = format.image; struct form_control *ff = format.form; format.link = format.target = format.image = NULL; format.form = NULL; s[0] = '['; snzprint(s + 1, 62, p->link_num); strcat(s, "]"); put_chars(p, s, strlen(s)); if (ff && ff->type == FC_TEXTAREA) line_break(p); if (p->cx == -1) p->cx = par_format.leftmargin; format.link = fl, format.target = ft, format.image = fi; format.form = ff; } p->link_num++; last_link = stracpy(format.link); last_target = stracpy(format.target); last_image = stracpy(format.image); last_form = format.form; if (!p->data) goto no_l; if (!(link = new_link(p->data))) goto no_l; link->num = p->link_num - 1; link->pos = DUMMY; if (!last_form) { link->type = L_LINK; link->where = stracpy(last_link); link->target = stracpy(last_target); } else { link->type = last_form->type == FC_TEXT || last_form->type == FC_PASSWORD || last_form->type == FC_FILE ? L_FIELD : last_form->type == FC_TEXTAREA ? L_AREA : last_form->type == FC_CHECKBOX || last_form->type == FC_RADIO ? L_CHECKBOX : last_form->type == FC_SELECT ? L_SELECT : L_BUTTON; link->form = last_form; link->target = stracpy(last_form->target); } link->where_img = stracpy(last_image); if (link->type != L_FIELD && link->type != L_AREA) { bg = find_nearest_color(&format.clink, 8); fg = find_nearest_color(&format.bg, 8); fg = fg_color(fg, bg); } else { fg = find_nearest_color(&format.fg, 8); bg = find_nearest_color(&format.bg, 8); fg = fg_color(fg, bg); } link->sel_color = ((fg & 8) << 3) | (fg & 7) | (bg << 3); link->n = 0; set_link: if ((unsigned)link->n + (unsigned)l > MAXINT / sizeof(struct point)) overalloc(); pt = mem_realloc(link->pos, (link->n + l) * sizeof(struct point)); link->pos = pt; for (i = 0; i < l; i++) pt[link->n + i].x = X(p->cx) + i, pt[link->n + i].y = Y(p->cy); link->n += l; } goto no_l; format_change: bg = find_nearest_color(&format.bg, 8); fg = find_nearest_color(&format.fg, 16); fg = fg_color(fg, bg); if (format.attr & AT_ITALIC) fg = fg ^ 0x01; if (format.attr & AT_UNDERLINE) fg = (fg ^ 0x04) | 0x08; if (format.attr & AT_BOLD) fg = fg | 0x08; fg = fg_color(fg, bg); if (format.attr & AT_GRAPHICS) bg = bg | 0x10; memcpy(&ta_cache, &format, sizeof(struct text_attrib_beginning)); fg_cache = fg; bg_cache = bg; goto end_format_change; }
void PieChartDisplay::drawPlot(double val) { QColor fg_color(fg_color_); if (auto_color_change_) { double r = std::min(1.0, fabs((val - min_value_) / (max_value_ - min_value_))); fg_color.setRed((max_color_.red() - fg_color_.red()) * r + fg_color_.red()); fg_color.setGreen((max_color_.green() - fg_color_.green()) * r + fg_color_.green()); fg_color.setBlue((max_color_.blue() - fg_color_.blue()) * r + fg_color_.blue()); } QColor fg_color2(fg_color); QColor bg_color(bg_color_); QColor text_color(text_color_); fg_color.setAlpha(fg_alpha_); fg_color2.setAlpha(fg_alpha2_); bg_color.setAlpha(bg_alpha_); text_color.setAlpha(text_alpha_); int width = overlay_->getTextureWidth(); int height = overlay_->getTextureHeight(); { ScopedPixelBuffer buffer = overlay_->getBuffer(); QImage Hud = buffer.getQImage(*overlay_, bg_color); QPainter painter( &Hud ); painter.setRenderHint(QPainter::Antialiasing, true); const int outer_line_width = 5; const int value_line_width = 10; const int value_indicator_line_width = 2; const int value_padding = 5; const int value_aabb_offset = outer_line_width + value_padding + value_line_width / 2; painter.setPen(QPen(fg_color, outer_line_width, Qt::SolidLine)); painter.drawEllipse(outer_line_width / 2, outer_line_width / 2, width - outer_line_width , height - outer_line_width - caption_offset_); painter.setPen(QPen(fg_color2, value_indicator_line_width, Qt::SolidLine)); painter.drawEllipse(value_aabb_offset, value_aabb_offset, width - value_aabb_offset * 2, height - value_aabb_offset * 2 - caption_offset_); const double ratio = (val - min_value_) / (max_value_ - min_value_); const double ratio_angle = ratio * 360.0; const double start_angle_offset = -90; painter.setPen(QPen(fg_color, value_line_width, Qt::SolidLine)); painter.drawArc(QRectF(value_aabb_offset, value_aabb_offset, width - value_aabb_offset * 2, height - value_aabb_offset * 2 - caption_offset_), start_angle_offset * 16 , ratio_angle * 16); QFont font = painter.font(); font.setPointSize(text_size_); font.setBold(true); painter.setFont(font); painter.setPen(QPen(text_color, value_line_width, Qt::SolidLine)); std::ostringstream s; s << std::fixed << std::setprecision(2) << val; painter.drawText(0, 0, width, height - caption_offset_, Qt::AlignCenter | Qt::AlignVCenter, s.str().c_str()); // caption if (show_caption_) { painter.drawText(0, height - caption_offset_, width, caption_offset_, Qt::AlignCenter | Qt::AlignVCenter, getName()); } // done painter.end(); // Unlock the pixel buffer } }
void Plotter2DDisplay::drawPlot() { QColor fg_color(fg_color_); QColor bg_color(bg_color_); fg_color.setAlpha(fg_alpha_); bg_color.setAlpha(bg_alpha_); if (auto_color_change_) { double r = std::min(std::max((buffer_[buffer_.size() - 1] - min_value_) / (max_value_ - min_value_), 0.0), 1.0); if (r > 0.3) { double r2 = (r - 0.3) / 0.7; fg_color.setRed((max_color_.red() - fg_color_.red()) * r2 + fg_color_.red()); fg_color.setGreen((max_color_.green() - fg_color_.green()) * r2 + fg_color_.green()); fg_color.setBlue((max_color_.blue() - fg_color_.blue()) * r2 + fg_color_.blue()); } } { ScopedPixelBuffer buffer = overlay_->getBuffer(); QImage Hud = buffer.getQImage(*overlay_); // initilize by the background color for (int i = 0; i < overlay_->getTextureWidth(); i++) { for (int j = 0; j < overlay_->getTextureHeight(); j++) { Hud.setPixel(i, j, bg_color.rgba()); } } // paste in HUD speedometer. I resize the image and offset it by 8 pixels from // the bottom left edge of the render window QPainter painter( &Hud ); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(fg_color, line_width_, Qt::SolidLine)); uint16_t w = overlay_->getTextureWidth(); uint16_t h = overlay_->getTextureHeight() - caption_offset_; double margined_max_value = max_value_ + (max_value_ - min_value_) / 2; double margined_min_value = min_value_ - (max_value_ - min_value_) / 2; for (size_t i = 1; i < buffer_length_; i++) { double v_prev = (margined_max_value - buffer_[i - 1]) / (margined_max_value - margined_min_value); double v = (margined_max_value - buffer_[i]) / (margined_max_value - margined_min_value); double u_prev = (i - 1) / (float)buffer_length_; double u = i / (float)buffer_length_; // chop within 0 ~ 1 v_prev = std::max(std::min(v_prev, 1.0), 0.0); u_prev = std::max(std::min(u_prev, 1.0), 0.0); v = std::max(std::min(v, 1.0), 0.0); u = std::max(std::min(u, 1.0), 0.0); uint16_t x_prev = (int)(u_prev * w); uint16_t x = (int)(u * w); uint16_t y_prev = (int)(v_prev * h); uint16_t y = (int)(v * h); painter.drawLine(x_prev, y_prev, x, y); } // draw border if (show_border_) { painter.drawLine(0, 0, 0, h); painter.drawLine(0, h, w, h); painter.drawLine(w, h, w, 0); painter.drawLine(w, 0, 0, 0); } // draw caption if (show_caption_) { QFont font = painter.font(); font.setPointSize(text_size_); font.setBold(true); painter.setFont(font); painter.drawText(0, h, w, caption_offset_, Qt::AlignCenter | Qt::AlignVCenter, getName()); } if (show_value_) { QFont font = painter.font(); font.setPointSize(w / 4); font.setBold(true); painter.setFont(font); std::ostringstream ss; ss << std::fixed << std::setprecision(2) << buffer_[buffer_.size() - 1]; painter.drawText(0, 0, w, h, Qt::AlignCenter | Qt::AlignVCenter, ss.str().c_str()); } // done painter.end(); } }