yaochenkun / filling-algorithms

A testing program that gathers 4 Filling Algorithms based on Android and implemented in Java.一个基于Android平台、Java语言实现的4种填充算法的测试程序。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FillingAlgorithms

A testing program that gathers 4 Filling Algorithms based on Android and implemented in Java. These algorithms are:

  • Seed Filling Algorithm (种子填充算法):
     需事先给定一像素点作为种子点,再以该种子点为起点朝四连通或八连通方向递归填充,但仍基于像素,且区域内每一像素点均需入栈,易堆栈溢出。
    In this program this algorithm is easily to cause 'Stack Overflow', so it is usually Not Recommended。

  • Point-by-point Filling Algorithm (逐点判断算法):
     基于像素,对绘图窗口内每一像素点进行射线环绕探测来实现内点判定,孤立地考虑像素点与区域的关系,计算量较大。

  • Scanline Filling Algorithm (扫描线填充算法):
     扫描线填充算法也需给定一种子点,分别水平向右和向左地探测得到图形边界点,填充两端点之间的线段,并让该线段之上和之下的任意内点入栈,继而栈顶像素点出栈作为新的种子点,重复上述操作至栈空。

  • Active-edge-table Filling Algorithm (活性边表填充算法):
     该算法让扫描线以1像素的增量自下而上地扫描多边形,并利用边的斜率k计算增量值,从而快速定位下一步的端点坐标。
     In this program, I have improved the traditional active-edge-table filling algorithm and make it enable to adaptively find the better scanning direction.If you want to learn more please refer to file 一种强鲁棒性自适应活性边表算法.pdf in this repository.

ScreenShot

How to Test

  1. Draw a polygon on the canvas as you want.
  2. Click a button below (i.e. a filling algorithm) to fill the polygon with red color.Notes:
  • if you choose 'Seed Filling Algorithm (the first button)' or 'Scanline Filling Algorithm (the third button)', you must have to click anywhere in polygon to appoint a point (i.e. the seed). Only in this way can these 2 filling processes begin.
  • if you choose the other algorithms, you don't have to take any other subsequent actions.
  1. The other buttons' usages:
  • the first three buttons in the second row respectively mean scaning the polygon in portrait, landscape and the best direction when use Active-edge-table Filling Algorithm.
  • the last button in the first row means scanning without checking and correcting the x coordinates of the adjoining crossover points in polygon when use Active-edge-table Filling Algorithm.
  • the last button in the second row means clearing the canvas.

Test Result

Look at the top left corner:

  • 外接矩形面积(Area of Bounding Rectangle): means the area of bounding rectangle for the polygon.
  • 横度 (Horizontal Extent): means the offset or stretching extent in horizontal direction for the polygon.
  • 纵度 (Vertical Extent): means the offset or stretching extent in vertical direction for the polygon.
  • 运行时间 (Runtime): means the runtime of the alogrithm you select.

Environment and Configurations

  • Download and install Android Studio.
  • Install Android SDK 4.4 but is not necessary.
  • Import the whole project 'ScanlineTest' into Android Studio.
  • At last, maybe you should enter 'File > Settings > Editor > File Encodings' and adjust 'IDE Encoding', 'Project Encoding' and 'Default encoding for properties files' to 'GBK'.

For More

If you are interested in 'Filling Algorithms', you could refer to some books about 'Computer Graphics'.

About

A testing program that gathers 4 Filling Algorithms based on Android and implemented in Java.一个基于Android平台、Java语言实现的4种填充算法的测试程序。


Languages

Language:Java 100.0%