|
@@ -4,16 +4,35 @@ import com.sun.org.apache.bcel.internal.generic.NEW;
|
|
|
import index.entity.Box;
|
|
|
import index.entity.BoxEdge;
|
|
|
import index.entity.Point;
|
|
|
+import index.log.Log;
|
|
|
+
|
|
|
+import java.awt.*;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
public class ScanOutLine {
|
|
|
|
|
|
- ArrayList<String> scanPriority;
|
|
|
+ ArrayList<String> scanPriority = new ArrayList<>();
|
|
|
Integer numOfGaps;
|
|
|
ArrayList<ArrayList<BoxEdge>> shapeList = new ArrayList<>();
|
|
|
ArrayList<ArrayList<Point>> shapePointList = new ArrayList<>();
|
|
|
|
|
|
+ public ArrayList<ArrayList<BoxEdge>> getShapeList() {
|
|
|
+ return shapeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setShapeList(ArrayList<ArrayList<BoxEdge>> shapeList) {
|
|
|
+ this.shapeList = shapeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<ArrayList<Point>> getShapePointList() {
|
|
|
+ return shapePointList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setShapePointList(ArrayList<ArrayList<Point>> shapePointList) {
|
|
|
+ this.shapePointList = shapePointList;
|
|
|
+ }
|
|
|
+
|
|
|
//设置扫描的优先级
|
|
|
public ScanOutLine(ArrayList<String> ScanPriority){
|
|
|
|
|
@@ -33,35 +52,60 @@ public class ScanOutLine {
|
|
|
}
|
|
|
|
|
|
//迭代
|
|
|
- public void Scan(ArrayList<Box> allBusyBoxes,Integer numOfGaps) throws Exception{
|
|
|
+ public void scan(ArrayList<Box> allBusyBoxes,Integer numOfGaps) throws Exception{
|
|
|
|
|
|
this.numOfGaps = numOfGaps;
|
|
|
|
|
|
//获取所有的不重复的边
|
|
|
GetAllEdge getAllEdge = new GetAllEdge();
|
|
|
+ Log.print("网格数量:" + allBusyBoxes.size());
|
|
|
ArrayList<BoxEdge> boxEdgeArrayList = getAllEdge.cal(allBusyBoxes);
|
|
|
+ Log.print("形成的边总数为:" + boxEdgeArrayList.size());
|
|
|
|
|
|
//随机挑选一个边,然后从边中挑选一个点
|
|
|
|
|
|
//闭合轮廓list
|
|
|
|
|
|
-// ArrayList<ArrayList<BoxEdge>> shapeList = new ArrayList<>();
|
|
|
-// ArrayList<ArrayList<Point>> shapePointList = new ArrayList<>();
|
|
|
|
|
|
//挑边
|
|
|
Integer randomBoxEdgeIndex = (int) (Math.random() * boxEdgeArrayList.size());
|
|
|
+ Log.print("随机挑选第 " + randomBoxEdgeIndex + "条边");
|
|
|
BoxEdge initialBoxEdge = boxEdgeArrayList.get(randomBoxEdgeIndex);
|
|
|
|
|
|
+
|
|
|
+ Log.print("测试isEdgeEqual方法开始");
|
|
|
+
|
|
|
+ judgeEdgeEqual1(initialBoxEdge,initialBoxEdge);
|
|
|
+
|
|
|
+ Log.print("测试isEdgeEqual方法结束");
|
|
|
+
|
|
|
//挑点,这里挑点1或者点2都可以
|
|
|
Point pointInitial = initialBoxEdge.getPoint1();
|
|
|
|
|
|
+ int scanCounter = 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //某一个连通轮廓
|
|
|
+ ArrayList<BoxEdge> shapeSingle = new ArrayList<>();
|
|
|
+
|
|
|
+ //走过的点的list
|
|
|
+ ArrayList<Point> shapePoint = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
while (boxEdgeArrayList.size() !=0){
|
|
|
|
|
|
- //某一个连通轮廓
|
|
|
- ArrayList<BoxEdge> shapeSingle = new ArrayList<>();
|
|
|
+ Log.print("boxEdgeArrayList容量为: " + boxEdgeArrayList.size());
|
|
|
+
|
|
|
+ scanCounter = scanCounter + 1;
|
|
|
|
|
|
+ Log.print("第" + scanCounter + "次扫描");
|
|
|
+
|
|
|
+ //某一个连通轮廓
|
|
|
+// ArrayList<BoxEdge> shapeSingle = new ArrayList<>();
|
|
|
+//
|
|
|
//走过的点的list
|
|
|
- ArrayList<Point> shapePoint = new ArrayList<>();
|
|
|
+// ArrayList<Point> shapePoint = new ArrayList<>();
|
|
|
|
|
|
ArrayList<BoxEdge> matchBoxEdgeArrayList =new ArrayList<>();
|
|
|
|
|
@@ -72,10 +116,13 @@ public class ScanOutLine {
|
|
|
|
|
|
String direction = scanPriority.get(i);
|
|
|
|
|
|
+ Log.print("选择移动方向为: " + direction);
|
|
|
+
|
|
|
Point pointNextTemp = genNextStep(pointInitial, direction);
|
|
|
|
|
|
if (!isPointLegal(pointNextTemp, this.numOfGaps)) {
|
|
|
|
|
|
+ Log.print("沿 " + direction + " 方向没有可移动点");
|
|
|
continue;
|
|
|
|
|
|
}
|
|
@@ -93,28 +140,36 @@ public class ScanOutLine {
|
|
|
//如果找到了就跳出循环,不再从别的方向上去找下一步的点了
|
|
|
if (matchBoxEdgeArrayListTemp.size() != 0){
|
|
|
|
|
|
+
|
|
|
+ Log.print("在boxEdgeArrayList中找到和构造边相等的边");
|
|
|
matchBoxEdgeArrayList = matchBoxEdgeArrayListTemp;
|
|
|
+ pointNext = pointNextTemp;
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
+ else {
|
|
|
+
|
|
|
+ Log.print("沿" + direction + "方向未找到与构造边相等的边");
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
//四个方向上找了一遍,都没有找到边
|
|
|
if (matchBoxEdgeArrayList.size() == 0){
|
|
|
-
|
|
|
- //这里要分两种情况。
|
|
|
- //没有找到边,且boxEdgeArrayList的size为0
|
|
|
- //没有找到边,且boxEdgeArrayList的size不为0
|
|
|
+ Log.print("未找到边!当前boxEdgeArrayList容量为 " + boxEdgeArrayList.size());
|
|
|
+ Log.print("将当前轮廓添加到list中,并继续计算其余连通区域");
|
|
|
shapeList.add(shapeSingle);
|
|
|
shapePointList.add(shapePoint);
|
|
|
+ Log.print("已添加当前轮廓");
|
|
|
+ shapeSingle = new ArrayList<>();
|
|
|
+ shapePoint = new ArrayList<>();
|
|
|
+ Log.print("已创建空的新轮廓");
|
|
|
+ Log.print("从剩下的边里产生产生一个初始点");
|
|
|
//从剩下的边里产生产生一个初始点
|
|
|
Integer randomBoxEdgeIndexNextCircle = (int) (Math.random() * boxEdgeArrayList.size());
|
|
|
BoxEdge initialBoxEdgeNextCircle = boxEdgeArrayList.get(randomBoxEdgeIndexNextCircle);
|
|
|
-
|
|
|
//挑点,这里挑点1或者点2都可以
|
|
|
pointInitial = initialBoxEdgeNextCircle.getPoint1();
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
else if (matchBoxEdgeArrayList.size() > 1){
|
|
@@ -136,7 +191,16 @@ public class ScanOutLine {
|
|
|
|
|
|
boxEdgeArrayList = removeBoxEdge(boxEdgeFind,boxEdgeArrayList);
|
|
|
|
|
|
+ if (boxEdgeArrayList.size() == 0){
|
|
|
+
|
|
|
+ Log.print("剩余边容量为0,保存当前轮廓");
|
|
|
+ shapeList.add(shapeSingle);
|
|
|
+ shapePointList.add(shapePoint);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
pointInitial = pointNext;
|
|
|
+ Log.print("找到一条相连边");
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -159,34 +223,6 @@ public class ScanOutLine {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// public ArrayList<BoxEdge> findConnectEdge(Point point,ArrayList<BoxEdge> boxEdgeArrayList){
|
|
|
-//
|
|
|
-// //所有与该点相连的边,一般一个,有可能没有。
|
|
|
-// ArrayList<BoxEdge> boxEdgesConnected = new ArrayList<>();
|
|
|
-//
|
|
|
-// //
|
|
|
-//
|
|
|
-// for (int i = 0 ; i < boxEdgeArrayList.size();i++){
|
|
|
-//
|
|
|
-//
|
|
|
-// BoxEdge boxEdge = boxEdgeArrayList.get(i);
|
|
|
-// Point point1 = boxEdge.getPoint1();
|
|
|
-// Point point2 = boxEdge.getPoint2();
|
|
|
-// boolean isEqualToP1 = judgePointEqual(point,point1);
|
|
|
-// boolean isEqualToP2 = judgePointEqual(point,point2);
|
|
|
-//
|
|
|
-// if ( isEqualToP1 || isEqualToP2 ){
|
|
|
-//
|
|
|
-// boxEdgesConnected.add(boxEdge);
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
|
|
|
public boolean judgePointEqual(Point point1,Point point2){
|
|
|
|
|
@@ -194,6 +230,7 @@ public class ScanOutLine {
|
|
|
|
|
|
if ((point1.getColX().equals(point2.getColX())) && (point1.getColY().equals(point2.getColY()))){
|
|
|
|
|
|
+
|
|
|
isEqual = true;
|
|
|
|
|
|
}
|
|
@@ -261,11 +298,43 @@ public class ScanOutLine {
|
|
|
|
|
|
public boolean judgeEdgeEqual(BoxEdge boxEdge1,BoxEdge boxEdge2){
|
|
|
|
|
|
+// Log.print("检查边是否相等");
|
|
|
+ boolean isEdgeEqual = false;
|
|
|
+ Point boxEdge1Point1 = boxEdge1.getPoint1();
|
|
|
+// Log.printPoint(boxEdge1Point1);
|
|
|
+ Point boxEdge1Point2 = boxEdge1.getPoint2();
|
|
|
+// Log.printPoint(boxEdge1Point2);
|
|
|
+ Point boxEdge2Point1 = boxEdge2.getPoint1();
|
|
|
+// Log.printPoint(boxEdge2Point1);
|
|
|
+ Point boxEdge2Point2 = boxEdge2.getPoint2();
|
|
|
+// Log.printPoint(boxEdge2Point2);
|
|
|
+
|
|
|
+
|
|
|
+ if (((judgePointEqual(boxEdge1Point1,boxEdge2Point1))&&(judgePointEqual(boxEdge1Point2,boxEdge2Point2))) ||((judgePointEqual(boxEdge1Point1,boxEdge2Point2))&&(judgePointEqual(boxEdge1Point2,boxEdge2Point1)))){
|
|
|
+
|
|
|
+ isEdgeEqual = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// Log.print("检查结束,isEdgeEqual: " + isEdgeEqual);
|
|
|
+
|
|
|
+ return isEdgeEqual;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean judgeEdgeEqual1(BoxEdge boxEdge1,BoxEdge boxEdge2){
|
|
|
+
|
|
|
+ Log.print("检查边是否相等");
|
|
|
boolean isEdgeEqual = false;
|
|
|
Point boxEdge1Point1 = boxEdge1.getPoint1();
|
|
|
+ Log.printPoint(boxEdge1Point1);
|
|
|
Point boxEdge1Point2 = boxEdge1.getPoint2();
|
|
|
+ Log.printPoint(boxEdge1Point2);
|
|
|
Point boxEdge2Point1 = boxEdge2.getPoint1();
|
|
|
+ Log.printPoint(boxEdge2Point1);
|
|
|
Point boxEdge2Point2 = boxEdge2.getPoint2();
|
|
|
+ Log.printPoint(boxEdge2Point2);
|
|
|
+
|
|
|
|
|
|
if (((judgePointEqual(boxEdge1Point1,boxEdge2Point1))&&(judgePointEqual(boxEdge1Point2,boxEdge2Point2))) ||((judgePointEqual(boxEdge1Point1,boxEdge2Point2))&&(judgePointEqual(boxEdge1Point2,boxEdge2Point1)))){
|
|
|
|
|
@@ -273,6 +342,8 @@ public class ScanOutLine {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ Log.print("检查结束,isEdgeEqual: " + isEdgeEqual);
|
|
|
+
|
|
|
return isEdgeEqual;
|
|
|
|
|
|
}
|