算法来实现套索选择工具?套索、来实现、算法、工具

由网友(诉不尽离人话)分享简介:我开发一个Mac OS X的应用程序,它,因为它的一部分的用户界面,显示许多视觉元素,它是可以选择的主要观点。这些元件可以定位在视图内真正的任何地方。用户界面将支持选择这些元素的各种方法:矩形选框,椭圆选框选择和'自由'套索选择我已经有长方形和椭圆选框选择工作。该算法是pretty的简单;元件被视为已'选择'如果用矩形...

我开发一个Mac OS X的应用程序,它,因为它的一部分的用户界面,显示许多视觉元素,它是可以选择的主要观点。这些元件可以定位在视图内真正的任何地方。用户界面将支持选择这些元素的各种方法:矩形选框,椭圆选框选择和'自由'套索选择

我已经有长方形和椭圆选框选择工作。该算法是pretty的简单;元件被视为已'选择'如果用矩形/椭圆的面积的元件的区域相交。

套索选择将工作就像它在现代图像处理应用程序,如Photoshop;用户可以点击并拖动将关闭本身的路径,并含有绘制将被选择的路径中的元素

这个算法很可能会比矩形/椭圆选区要复杂得多,因为选择的方式是不受限制的。我想知道如果任何人有经验,写这样的事情,或者如果你能以什么样的编程技术是必要的,什么是最有效的方法,该算法可以工作在正确的方向指向我。

在此先感谢。

解决方案

我能想到的唯一的办法就是把套索轮廓多边形。然后你可以使用任何标准的点内的多边形测试检查选择哪些元素。

您将不得不作出决定怎样做时,多边形自身相交(如图8)。

递归算法在编程中的重要应用

当它变得太多了点构造多边形,以prevent,也许你可以跳过过于接近previous点(可能是3个像素左右,这取决于你的应用程序)。

I am developing a Mac OS X application which, as part of it's UI, will display many visual elements in it's main view which can be selected. These elements can be positioned really anywhere within the view. The UI will support various ways of selecting the elements: rectangular marquee selection, elliptical marquee selection, and 'free' lasso selection.

I already have rectangular and elliptical marquee selection working. The algorithm is pretty simple; an element is deemed 'selected' if the element's area intersects with the area of the rectangle/ellipse.

The lasso selection will work just as it does in modern image manipulation applications like Photoshop; the user can click-and-drag a path which will close itself, and the elements contained within the path drawn will be selected.

This algorithm will likely be much more complex than the rectangular/elliptical selection, since the form of the selection is unrestricted. I am wondering if anyone has experience writing something like this, or if you can point me in the right direction as to what kind of programming techniques are necessary, and what is the most efficient way this algorithm can work.

Thanks in advance.

解决方案

The only way I can think of is to treat the lasso outline as a polygon. Then you can use any standard point-inside-polygon test to check which elements to select.

You'll have to make a decision what to do when the polygon intersects itself (e.g. figure-8).

When constructing the polygon, to prevent it from getting too many points, maybe you can skip points that are too close to the previous point (maybe 3 pixels or so, depending on your application).

阅读全文

相关推荐

最新文章