2.2.5 C#中显示控件BDPictureBox 的实现----ROI交互续2
1 ROI数组作用说明
变量:m_ROIs[5]
ROI 使用效果图
ROI数组说明
2 ROI显示逻辑图
ROI 交互主要是在设定状态下, runmode下只要普通显示即可
3 主要ROI显示函数函数
- 判断当前鼠标是否获取KeyPoint
- 鼠标move时,拖放ROI的姿态和大小
- 显示更新ROI
3.1 get_interactive_key_draw_point
获取当前ROI 关键点选中信息
/// <summary>
/// get_interactive_key_draw_point
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private int get_interactive_key_draw_point(int x, int y)
{
int point_index = 0;
try
{
if (m_raw_mat != null && !m_raw_mat.IsDisposed)
{
switch (m_ROIs[m_ROI_index].m_nType)
{
case 0:// Rect1
point_index = get_interactive_rect1_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 1:// Rect2
point_index = get_interactive_rect2_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 2:// Circle
point_index = get_interactive_circle_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 3:// Ellips
point_index = get_interactive_ellips_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 4:// arc
point_index = get_interactive_arc_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 5:// poly
point_index = get_interactive_poly_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 6://
point_index = get_interactive_point_key_draw_point(ref m_ROIs[m_ROI_index], x, y);
break;
case 7://
break;
default:
break;
}
}
}
catch (Exception ex)
{
label_img_info.Text = ex.Message;
point_index = -1;
}
return point_index;
}
3.2 drag_interactive_ROI
拖放当前ROI ,并且更新ROI
/// <summary>
/// drag_interactive_ROI
/// 更新drag之后的 ROI
/// </summary>
/// <param name="x_dist">distx in ccs</param>
/// <param name="y_dist">disty in ccs</param>
private void drag_interactive_ROI(float x_dist, float y_dist)
{
List<float> temp_data = new List<float>();
//step 0: clear overlay
// clear_ROIs(Black, 2);
// step1: 重新计算rect1
try
{
if (m_raw_mat != null && !m_raw_mat.IsDisposed)
{
switch (m_ROIs[m_ROI_index].m_nType)
{
case 0:// Rect1
drag_interactive_rect1(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 1:// Rect2
drag_interactive_rect2(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 2:// Circle
drag_interactive_circle(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 3:// Ellips
drag_interactive_ellipse(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 4:// arc
drag_interactive_arc(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 5:// poly
drag_interactive_poly(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 6://
drag_interactive_point(ref m_ROIs[m_ROI_index], x_dist, y_dist);
break;
case 7://
break;
default:
break;
}
}
}
catch (Exception ex)
{
label_img_info.Text = "Drag InterActive ROI:" + ex.Message;
}
}
3.3 显示更新ROI
/// <summary>
/// Disp_InterActive_ROIs_quickflush_without_Update_Image
/// remark: drag ROI 时使用,这是不需要更新 局部图片,只要更新 overlay
/// </summary>
/// <param name="m_roi_s"></param>
/// <param name="colortype"></param>
/// <param name="thick"></param>
public void Disp_InterActive_ROIs_without_Update_Image(ROI[] m_roi_s, Scalar colortype, int thick)
{
if (m_roi_s == null) return;
ROI[] m_quick_rois = new ROI[5];
ROI[] m_temp_rois = new ROI[5];
Scalar linecolor = new Scalar(0, 0, 0);
try
{
// lock (mutex_display)
{
if (BD_OperateSet.MatisNotNull(m_extract_zoom_overlay))
{
m_ROIs = m_roi_s;
DispManager.get_DispCTX().update_display_hom2d(ref hom2d_quick );
m_quick_rois = BD_OperateSet.Affine_ROIs(m_roi_s, hom2d_quick);
// step 0: disp ROI
for (int i = 0; i < m_quick_rois.Length; i++)
{
if (i > 0) linecolor = MaskColor_Roi;
else linecolor = colortype;
if (m_quick_rois[0].m_fDatas.Count > 0)
{
if (m_quick_rois[i].m_fDatas != null)
{
// b_overlay_zero = false;
if (m_quick_rois[i].m_fDatas.Count > 0)
{
switch (m_quick_rois[i].m_nType)
{
case 0:// Rect0
if (m_ROI_index == i) disp_interactive_rect1_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Rect1(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 1:// Rect2
if (m_ROI_index == i) disp_interactive_rect2_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Rect2(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 2:// Circle
if (m_ROI_index == i) disp_interactive_circle_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Circle(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 3:// Ellips
if (m_ROI_index == i) disp_interactive_ellips_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Ellipse(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 4:// ARC
if (m_ROI_index == i) disp_interactive_arc_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Arc(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 5:// Poly
if (m_ROI_index == i) disp_interactive_poly_points_quickflush(m_quick_rois[i], linecolor, thick);
else BD_OperateSet.Disp_Polygen(ref m_extract_zoom_overlay, m_quick_rois[i], linecolor, thick);
break;
case 6://
if (m_ROI_index == i) disp_interactive_point_quickflush(m_quick_rois[m_ROI_index], linecolor, thick);
else BD_OperateSet.Disp_Point(ref m_extract_zoom_overlay, m_quick_rois[m_ROI_index], linecolor, thick);
break;
case 7://
break;
case 8://
break;
default:
break;
}
}
}
}
}
// step 1: disp masks
update_Overlay_toDisplay();
pB_Display.Invalidate();// pB_Display.Update();
}
}
}
catch (Exception ex)
{
label_img_info.Text = "Disp InterActive ROIs:" + ex.Message;
}
}