void CVView::setSelectedDataPointIndices(const QList<int> &L) { d->m_selected_line=cvline(0,0,0,0,0,0); d->m_selected_point_indices=L; emit selectedLineChanged(); emit selectedDataPointsChanged(); d->start_update_view(); }
/*---------------------------------------------------------------------------*/ void draw_window_sub(struct ctk_window *window, unsigned char focus) { unsigned char x, y; unsigned char x1, y1, x2; struct ctk_widget *w; unsigned char wfocus; x = window->x; y = window->y + 1; x1 = x + 1; y1 = y + 1; x2 = x1 + window->w; // |_ gotoxy(x, y1); cvline(window->h); cputc(CH_LLCORNER); chline(window->w); cputc(CH_LRCORNER); // - gotoxy(x, y); cputc(CH_ULCORNER); chline(window->w); cputc(CH_URCORNER); // | gotoxy(x2, y1); cvline(window->h); /* Draw inactive widgets. */ for(w = window->inactive; w != NULL; w = w->next) { draw_widget(w, x1, y1, focus); } /* Draw active widgets. */ for(w = window->active; w != NULL; w = w->next) { wfocus = focus; if(w == window->focused) { wfocus |= CTK_FOCUS_WIDGET; } draw_widget(w, x1, y1, wfocus); } }
// draw a vector field based on horizontal and vertical flow fields void drawmotionfield(iplimage* imgu, iplimage* imgv, iplimage* imgmotion, int xspace, int yspace, float cutoff, int multiplier, cvscalar color) { int x, y; cvpoint p0 = cvpoint(0,0); cvpoint p1 = cvpoint(0,0); float deltax, deltay, angle, hyp; for(y = yspace; y < imgu->height; y+= yspace ) { for(x = xspace; x < imgu->width; x+= xspace ){ p0.x = x; p0.y = y; deltax = *((float*)(imgu->imagedata + y*imgu->widthstep)+x); deltay = -(*((float*)(imgv->imagedata + y*imgv->widthstep)+x)); angle = atan2(deltay, deltax); hyp = sqrt(deltax*deltax + deltay*deltay); if(hyp > cutoff){ p1.x = p0.x + cvround(multiplier*hyp*cos(angle)); p1.y = p0.y + cvround(multiplier*hyp*sin(angle)); cvline( imgmotion, p0, p1, color,1, cv_aa, 0); p0.x = p1.x + cvround(3*cos(angle-m_pi + m_pi/4)); p0.y = p1.y + cvround(3*sin(angle-m_pi + m_pi/4)); cvline( imgmotion, p0, p1, color,1, cv_aa, 0); p0.x = p1.x + cvround(3*cos(angle-m_pi - m_pi/4)); p0.y = p1.y + cvround(3*sin(angle-m_pi - m_pi/4)); cvline( imgmotion, p0, p1, color,1, cv_aa, 0); } } } }
float compute_distance_from_point_to_line(const CVPoint &P,const CVLine &L) { //is there a faster formula? If anyone can help it would be appreciated. //first we move the point to zero CVLine L2=cvline(L.p1.x-P.x,L.p1.y-P.y,L.p1.z-P.z,L.p2.x-P.x,L.p2.y-P.y,L.p2.z-P.z); //Define n = the direction as a unit vector CVPoint n=cvpoint(L2.p2.x-L2.p1.x,L2.p2.y-L2.p1.y,L2.p2.z-L2.p1.z); float mag=sqrt(n.x*n.x+n.y*n.y+n.z*n.z); if (mag>0) {n.x/=mag; n.y/=mag; n.z/=mag;} //find the point along the line closest to zero float dotprod=L2.p1.x*n.x+L2.p1.y*n.y+L2.p1.z*n.z; CVPoint q=cvpoint(L2.p1.x-dotprod*n.x,L2.p1.y-dotprod*n.y,L2.p1.z-dotprod*n.z); //now return the distance from zero return sqrt(q.x*q.x+q.y*q.y+q.z*q.z); }
CVView::CVView(QWidget *parent) : QWidget(parent) { d=new CVViewPrivate; d->q=this; d->m_view_transformation.scale(0.6,0.6,0.6); d->m_inverse_view_transformation=d->m_view_transformation.inverse(); this->setMouseTracking(true); d->m_update_view_code=0; d->m_window_max=0.5; d->m_increment_weight=1; d->m_need_initialize_window=false; d->m_radius=0.5; d->m_scale=1; d->m_dx=d->m_dy=0; d->m_perspective_factor=1.2; d->m_selected_line=cvline(0,0,0,0,0,0); d->m_num_datapoints_to_select=10; d->m_is_moving=false; connect(this,SIGNAL(signal_do_update_view(long,long)),this,SLOT(slot_update_view(long,long)),Qt::QueuedConnection); }
/*-----------------------------------------------------------------------------------*/ static void draw_widget(struct ctk_widget *w, unsigned char x, unsigned char y, unsigned char clipx, unsigned char clipy, unsigned char clipy1, unsigned char clipy2, unsigned char focus) { unsigned char xpos, ypos, xscroll; unsigned char i, j; char c, *text; unsigned char wfocus; #if CTK_CONF_ICONS unsigned char len; #endif /* CTK_CONF_ICONS */ wfocus = 0; if(focus & CTK_FOCUS_WINDOW) { (void)textcolor(WIDGETCOLOR_FWIN); if(focus & CTK_FOCUS_WIDGET) { (void)textcolor(WIDGETCOLOR_FOCUS); wfocus = 1; } #if CTK_CONF_WINDOWS } else if(focus & CTK_FOCUS_DIALOG) { (void)textcolor(WIDGETCOLOR_DIALOG); if(focus & CTK_FOCUS_WIDGET) { (void)textcolor(WIDGETCOLOR_FOCUS); wfocus = 1; } #endif /* CTK_CONF_WINDOWS */ } else { (void)textcolor(WIDGETCOLOR); } xpos = x + w->x; ypos = y + w->y; switch(w->type) { case CTK_WIDGET_SEPARATOR: if(ypos >= clipy1 && ypos < clipy2) { chlinexy(xpos, ypos, w->w); } break; case CTK_WIDGET_LABEL: text = w->widget.label.text; for(i = 0; i < w->h; ++i) { if(ypos >= clipy1 && ypos < clipy2) { gotoxy(xpos, ypos); cputsn(text, w->w); if(w->w - (wherex() - xpos) > 0) { cclear(w->w - (wherex() - xpos)); } } ++ypos; text += w->w; } break; case CTK_WIDGET_BUTTON: if(ypos >= clipy1 && ypos < clipy2) { revers(wfocus != 0); cputcxy(xpos, ypos, '['); cputsn(w->widget.button.text, w->w); cputc(']'); revers(0); } break; case CTK_WIDGET_HYPERLINK: if(ypos >= clipy1 && ypos < clipy2) { revers(wfocus == 0); gotoxy(xpos, ypos); (void)textcolor(WIDGETCOLOR_HLINK); cputsn(w->widget.button.text, w->w); revers(0); } break; case CTK_WIDGET_TEXTENTRY: text = w->widget.textentry.text; xscroll = 0; if(w->widget.textentry.xpos >= w->w - 1) { xscroll = w->widget.textentry.xpos - w->w + 1; } for(j = 0; j < w->h; ++j) { if(ypos >= clipy1 && ypos < clipy2) { if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && w->widget.textentry.ypos == j) { revers(0); cputcxy(xpos, ypos, '>'); c = 1; for(i = 0; i < w->w; ++i) { if(c != 0) { c = text[i + xscroll]; } revers(i == w->widget.textentry.xpos - xscroll); if(c == 0) { cputc(' '); } else { cputc(c); } } revers(0); cputc('<'); } else { revers(wfocus != 0 && j == w->widget.textentry.ypos); cvlinexy(xpos, ypos, 1); gotoxy(xpos + 1, ypos); cputsn(text, w->w); i = wherex(); if(i - xpos - 1 < w->w) { cclear(w->w - (i - xpos) + 1); } cvline(1); } } ++ypos; text += w->widget.textentry.len + 1; } revers(0); break; #if CTK_CONF_ICONS case CTK_WIDGET_ICON: if(ypos >= clipy1 && ypos < clipy2) { revers(wfocus != 0); #if CTK_CONF_ICON_TEXTMAPS if(w->widget.icon.textmap != NULL) { for(i = 0; i < 3; ++i) { gotoxy(xpos, ypos); if(ypos >= clipy1 && ypos < clipy2) { cputc(w->widget.icon.textmap[0 + 3 * i]); cputc(w->widget.icon.textmap[1 + 3 * i]); cputc(w->widget.icon.textmap[2 + 3 * i]); } ++ypos; } } #endif /* CTK_CONF_ICON_TEXTMAPS */ len = (unsigned char)strlen(w->widget.icon.title); if(xpos + len >= sizex) { xpos = sizex - len; } gotoxy(xpos, ypos); if(ypos >= clipy1 && ypos < clipy2) { cputs(w->widget.icon.title); } revers(0); } break; #endif /* CTK_CONF_ICONS */ default: break; } }
/*-----------------------------------------------------------------------------------*/ void cvlinexy(unsigned char x, unsigned char y, unsigned char length) { gotoxy(x, y); cvline(length); }
/*-----------------------------------------------------------------------------------*/ static void draw_widget(struct ctk_widget *w, unsigned char x, unsigned char y, unsigned char clipx, unsigned char clipy, unsigned char clipy1, unsigned char clipy2, unsigned char focus) { unsigned char xpos, ypos, xscroll; unsigned char i, j; unsigned char iconnum; char c, *text; unsigned char len; /* if(focus & CTK_FOCUS_WINDOW) { textcolor(WIDGETCOLOR_FWIN); if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_FOCUS); } } else if(focus & CTK_FOCUS_DIALOG) { textcolor(WIDGETCOLOR_DIALOG); if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_FOCUS); } } else { textcolor(WIDGETCOLOR); } */ xpos = x + w->x; ypos = y + w->y; switch(w->type) { case CTK_WIDGET_SEPARATOR: textcolor(VNC_OUT_SEPARATORCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { /* chlinexy(xpos, ypos, w->w);*/ gotoxy(xpos, ypos); for(i = 0; i < w->w; ++i) { cputc(CH_SEPARATOR); } } break; case CTK_WIDGET_LABEL: textcolor(VNC_OUT_LABELCOLOR + focus); text = w->widget.label.text; for(i = 0; i < w->h; ++i) { if(ypos >= clipy1 && ypos < clipy2) { gotoxy(xpos, ypos); cputsn(text, w->w); if(w->w - (wherex() - xpos) > 0) { cclear(w->w - (wherex() - xpos)); } } ++ypos; text += w->w; } break; case CTK_WIDGET_BUTTON: textcolor(VNC_OUT_BUTTONCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { if(focus & CTK_FOCUS_WIDGET) { revers(1); } else { revers(0); } cputcxy(xpos, ypos, CH_BUTTONLEFT); cputsn(w->widget.button.text, w->w); cputc(CH_BUTTONRIGHT); revers(0); } break; case CTK_WIDGET_HYPERLINK: textcolor(VNC_OUT_HYPERLINKCOLOR + focus); if(ypos >= clipy1 && ypos < clipy2) { /* if(focus & CTK_FOCUS_WIDGET) { textcolor(WIDGETCOLOR_HLINK_FOCUS); revers(0); } else { textcolor(WIDGETCOLOR_HLINK); revers(1); }*/ gotoxy(xpos, ypos); cputsn(w->widget.button.text, w->w); revers(0); } break; case CTK_WIDGET_TEXTENTRY: textcolor(VNC_OUT_TEXTENTRYCOLOR + focus); text = w->widget.textentry.text; xscroll = 0; if(w->widget.textentry.xpos >= w->w - 1) { xscroll = w->widget.textentry.xpos - w->w + 1; } for(j = 0; j < w->h; ++j) { if(ypos >= clipy1 && ypos < clipy2) { if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && w->widget.textentry.ypos == j) { revers(0); cputcxy(xpos, ypos, '>'); c = 1; for(i = 0; i < w->w; ++i) { if(c != 0) { c = text[i + xscroll]; } if(i == w->widget.textentry.xpos - xscroll) { textcolor(VNC_OUT_TEXTENTRYCOLOR + (focus ^ 0x01)); revers(1); } else { revers(0); } if(c == 0) { cputc(' '); } else { cputc(c); } revers(0); textcolor(VNC_OUT_TEXTENTRYCOLOR + focus); } cputc('<'); } else { if(focus & CTK_FOCUS_WIDGET && j == w->widget.textentry.ypos) { revers(1); } else { revers(0); } cvlinexy(xpos, ypos, 1); gotoxy(xpos + 1, ypos); cputsn(text, w->w); i = wherex(); if(i - xpos - 1 < w->w) { cclear(w->w - (i - xpos) + 1); } cvline(1); } } ++ypos; text += w->widget.textentry.len + 1; } revers(0); break; #if CTK_CONF_ICONS case CTK_WIDGET_ICON: if(ypos >= clipy1 && ypos < clipy2) { textcolor(VNC_OUT_ICONCOLOR + focus); if(focus & 1) { revers(1); } else { revers(0); } x = xpos; len = strlen(w->widget.icon.title); if(x + len >= sizex) { x = sizex - len; } gotoxy(x, ypos + 3); if(ypos >= clipy1 && ypos < clipy2) { cputs(w->widget.icon.title); } #if CTK_CONF_ICON_BITMAPS if(w->widget.icon.bitmap != NULL) { iconnum = vnc_out_add_icon((struct ctk_icon *)w); textcolor(iconnum | (focus << 6)); gotoxy(xpos, ypos); cputc(0x80); cputc(0x81); cputc(0x82); cputc(0x83); ++ypos; gotoxy(xpos, ypos); cputc(0x90); cputc(0x91); cputc(0x92); cputc(0x93); ++ypos; gotoxy(xpos, ypos); cputc(0xa0); cputc(0xa1); cputc(0xa2); cputc(0xa3); ++ypos; textcolor(0); /* for(i = 0; i < 3; ++i) { if(ypos >= clipy1 && ypos < clipy2) { cputc(w->widget.icon.textmap[0 + 3 * i]); cputc(w->widget.icon.textmap[1 + 3 * i]); cputc(w->widget.icon.textmap[2 + 3 * i]); } ++ypos; }*/ } #endif /* CTK_CONF_ICON_BITMAPS */ revers(0); } break; #endif /* CTK_CONF_ICONS */ default: break; } }
/* Same as "gotoxy (x, y); cvline (length);" */ void __fastcall__ cvlinexy( unsigned char x, unsigned char y, unsigned char length ) { gotoxy( x, y ); cvline( length ); }