Visual Layer Overview(5)Hit Testing in the Visual Layer

Hit Testing in the Visual Layer
 
这部分介绍了Windows Presentation Foundation中visual layer.使用VisualTreeHelper class来完成Hit Test的功能。这意味着你可以确定一个geometry 或者point是否落到一个visual object的边界之内,使你实现UI的行为,例如drag and drop。
 
1. Hit Testing Scenarios
UIElement class提供了InputHitTest方法,使你能够使用给定的元素的坐标值来做Hit Test。在大多数的情况下,InputHitTest方法提供了元素所需的Hit Test功能,但是,在visual layer的Hit Test时,还有一些情形需要你来实现:
•      与non-UIElement objects的Hit Test。例如:DrawingVisual objects
•      与geometry of objects的Hit Test:需要实现与几何体而不是坐标的Hit Test
•      与多个 objects的Hit Test
•      忽略UIElement hit testing 策略
 
2. Hit Testing Support
VisualTreeHelper class的HitTest的目的就是确定一个几何体或者点的坐标是否在一个给定的对象的边界内,例如control 或者graphic element。例如:可以使用Hit Test来确定鼠标点击的矩形边界是否在一个圆形对象之内。还可以override默认的Hit Test的实现来执行自定义的Hit Test计算。
下图显示了一个非矩形对象和它的矩形边界:
 
3. Hit Testing and Z-Order
Windows Presentation Foundation visual layer在所有的z-order levels支持对象的Hit Test。
在下图中,圆形对象在矩形和三角对象的上面。如果只对最上面的对象的碰撞感兴趣,可以设定Hit Test在最上面的对象停止,虽然制定的坐标包含在下面的两层对象之内。
 如果想不管z-order,枚举坐标所有的对象包含的所有的对象,可以设定返回所有的对象
 
4. Event Handling for Hit Testing
一个捕捉碰撞事件的通用的技术就是在感兴趣的所有对象上覆盖一个透明的轻量的UIElement 对象。透明的UIElement 对象虽然是不可见的,但是可以捕获事件,例如:鼠标点击。
下图显示了透明的UIElement 对象和感兴趣的其他对象的关系
 
5. Using Default Hit Testing
可以使用HitTest方法指定一个visual object和一个点坐标来确定一个点是否在一个可视化的对象之内
下面的代码显示了怎么给设UIElement定鼠标事件处理
C#
// Respond to the left mouse button down event by initiating the hit test.
 
public void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);
 
    // Perform the hit test against a given portion of the visual object tree.
    HitTestResult result = VisualTreeHelper.HitTest(myCanvas, pt);
 
    if (result != null)
    {
        // Perform action on hit visual object.
    }
}
 
6. Using a Hit Test Result Callback
    VisualTreeHelper.HitTest(myCanvas, null,
        new HitTestResultCallback(MyHitTestResult),
        new PointHitTestParameters(pt));
 
7. Using a Hit Test Filter Callback
 VisualTreeHelper.HitTest(myCanvas,
                      new HitTestFilterCallback(MyHitTestFilter),
                      new HitTestResultCallback(MyHitTestResult),
                      new PointHitTestParameters(pt));
 
8. Overriding Default Hit Testing
可以通过override HitTestCore 方法override一个visual object的默认的Hit Test行为,这意味着当你调用HitTest 方法时,你的重载的HitTestCore 方法将被调用
// Override default hit test support in visual object.
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
    Point pt = hitTestParameters.HitPoint;
 
    // Perform custom actions during the hit test processing.
 
    // Return hit on bounding rectangle of visual object.
    return new PointHitTestResult(this, pt);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Visual segmentation is one of the most important tasks in computer vision, which involves dividing an image into multiple segments, each of which corresponds to a different object or region of interest in the image. In recent years, transformer-based methods have emerged as a promising approach for visual segmentation, leveraging the self-attention mechanism to capture long-range dependencies in the image. This survey paper provides a comprehensive overview of transformer-based visual segmentation methods, covering their underlying principles, architecture, training strategies, and applications. The paper starts by introducing the basic concepts of visual segmentation and transformer-based models, followed by a discussion of the key challenges and opportunities in applying transformers to visual segmentation. The paper then reviews the state-of-the-art transformer-based segmentation methods, including both fully transformer-based approaches and hybrid approaches that combine transformers with other techniques such as convolutional neural networks (CNNs). For each method, the paper provides a detailed description of its architecture and training strategy, as well as its performance on benchmark datasets. Finally, the paper concludes with a discussion of the future directions of transformer-based visual segmentation, including potential improvements in model design, training methods, and applications. Overall, this survey paper provides a valuable resource for researchers and practitioners interested in the field of transformer-based visual segmentation.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值