跳转至

交互式矢量图图形用户界面

原文链接:https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/interactive-vector-gui

7406 对此文章评分:

4.0

交互式矢量图图形用户界面

作者:匿名 发表日期:2016年12月15日,星期四

随着假期临近,我想展示一个轻松愉快的功能演示可能不错;你可以用它来在寒冷的冬夜为亲友带来欢乐。本周的博客文章展示了如何使用简单的 widget_window 来创建一个交互式的 vector 动画。代码分为四个部分:VectorBlog、VectorBlog_Event、VectorBlogMouseEvent 和 VectorBlogVectorBuilder。VectorBlog 创建 widget 本身并初始显示矢量信息。VectorBlog_Event 运行基础 widget 的事件。这主要是 widget 的关闭。VectorBlogMouseEvent 是 widget 窗口记录鼠标位置的机制。最后但同样重要的是,VectorBlogVectorBuilder 构建包含矢量水平和垂直分量的两个矩阵。运行以下代码时,会记录光标位置,创建一个距离加权的矢量图,然后将生成的图像显示在 widget 窗口中。这段代码中唯一棘手的部分在于有两个事件处理程序:一个用于基础 widget,另一个用于 widget 窗口中的鼠标事件。每次移动光标时,还必须维护和操作所显示图像的对象引用。

图 1:矢量图示例



;+

; Build the vecort components

; This is distance weighting

;-

pro VectorBlogVectorBuilder, dims = dims, pt = pt, u = u, v = v

  compile_opt IDL2



  ; Get all the x locations

  xs = findgen(dims[0])

  xs = xs#replicate(1,dims[1])



  ; Get all the y locations

  ys = findgen(dims[1])

  ys = transpose(ys# replicate(1,dims[0]))



  ; Build the horizontal components

  u = pt[0] - xs



  ; Build the vertical components

  v =  pt[1] - ys

end





;+

; The event handler called when the mouse is moved.

;-

FUNCTION VectorBlogMouseEvent, win, x, y, keymods

  COMPILE_OPT idl2



  ; Set the window

  win.SetCurrent



  ; Set the scale factor

  sc = .05



  ; Get the size of the window

  dims = win.DIMENSIONS * sc



  ; Get the vecotr information

  VectorBlogVectorBuilder, dims = dims, pt = [x*sc,y*sc], $

    u = u , v = v



  ; Build the vecotr image

  vector = vector(u,v,xrange=[0,dims[0]], yrange=[0,dims[1]], /current, AUTO_COLOR=1,  $

    RGB_TABLE=73, AXIS_STYLE = 0, LENGTH_SCALE=1.5, ARROW_THICK =3)



  ; Delete the old image

  win.uvalue.delete



  ; Display the new image

  win.uvalue = vector







END





;+

; The event handler for the widget

;-

pro VectorBlog_Event, ev

  compile_opt IDL2





end





pro VectorBlog

  compile_opt IDL2



  ; Setup the widget

  tlb = widget_base()

  wwindow = widget_window(tlb, MOUSE_MOTION_HANDLER='VectorBlogMouseEvent', $

    XSIZE=500, YSIZE=500)

  widget_control, tlb, /REALIZE



  ; Set the scale factor

  sc = .05



  ; Get infomation about the widget window

  WIDGET_CONTROL, wwindow, GET_VALUE=w

  dims = w.DIMENSIONS * sc



  ; Build the vecotr infomation

  VectorBlogVectorBuilder, dims = dims, pt = [(dims[0])/2.,(dims[1])/2.], $

    u = u , v = v



  ; Display the vectors

  vector = vector(u,v,xrange=[0,dims[0]], yrange=[0,dims[1]], /current, AUTO_COLOR=1,  $

    RGB_TABLE=73, AXIS_STYLE = 0, LENGTH_SCALE=1.5, ARROW_THICK =3)



  ; Record the vector object

  w.uvalue = vector

  WIDGET_CONTROL, tlb, SET_UVALUE=w



  ; Start the task manager

  XMANAGER, 'VectorBlog', tlb



end

在 IDL 8.6 中保持向后兼容性 - 保持冷静并阅读您的发行说明 IDL 8.6 新特性:IDLTasks