Browse Source

1、支持东西、南北方向同时作业,
2、支持生成多连通轮廓

haoqianpan 4 years ago
parent
commit
33e833a2f6

+ 2 - 2
src/main/java/index/TestMain.java

@@ -7,10 +7,10 @@ import java.sql.SQLException;
 
 public class TestMain {
 
-    public static void main(String[] args) throws SQLException, FileNotFoundException {
+    public static void main(String[] args) throws Exception {
 
         Cal cal = new Cal();
-        cal.calShape(1);
+        cal.calShape(0);
 
     }
 

+ 1 - 1
src/main/java/index/adjust/Adjust.java

@@ -219,7 +219,7 @@ public class Adjust {
 
     public boolean isCloseToZero(Double diff){
 
-        if (Math.abs(diff) < 1){
+        if (Math.abs(diff) < 2){
 
             return true;
         }

+ 83 - 0
src/main/java/index/alg/BoxCorTrans.java

@@ -0,0 +1,83 @@
+package index.alg;
+
+import index.entity.BoxEdge;
+import index.entity.Point;
+import index.entity.WholeIndex;
+
+import java.util.ArrayList;
+
+public class BoxCorTrans {
+
+    WholeIndex wholeIndex;
+
+    public BoxCorTrans(WholeIndex wholeIndex){
+
+        this.wholeIndex = wholeIndex;
+
+    }
+
+    public Point pointTrans(Point pointForTrans){
+
+        Double xFt = pointForTrans.getColX();
+        Double yFt = pointForTrans.getColY();
+
+        Double xAt = xFt * wholeIndex.getxGap() + wholeIndex.getMinX();
+        Double yAt = yFt * wholeIndex.getyGap() + wholeIndex.getMinY();
+
+        Point pointAfterTrans = new Point();
+
+        pointAfterTrans.setColX(xAt);
+        pointAfterTrans.setColY(yAt);
+
+        return pointAfterTrans;
+
+    }
+
+    public ArrayList<Point> pointArrayListTrans(ArrayList<Point> pointArrayListForTrans){
+
+        ArrayList<Point> pointArrayListAfterTrans = new ArrayList<>();
+
+        for (int i = 0 ; i < pointArrayListForTrans.size();i++){
+
+            Point point = pointArrayListForTrans.get(i);
+            Point pointAt = pointTrans(point);
+            pointArrayListAfterTrans.add(pointAt);
+
+        }
+        return pointArrayListAfterTrans;
+    }
+
+    public BoxEdge boxEdgeTrans(BoxEdge boxEdgeForTrans){
+
+        BoxEdge boxEdgeAfterTrans = new BoxEdge();
+        Point point1 = boxEdgeForTrans.getPoint1();
+        Point point2 = boxEdgeForTrans.getPoint2();
+
+        point1 = pointTrans(point1);
+        point2 = pointTrans(point2);
+
+        boxEdgeAfterTrans.setPoint1(point1);
+        boxEdgeAfterTrans.setPoint2(point2);
+
+        return boxEdgeAfterTrans;
+
+    }
+
+    public ArrayList<BoxEdge> boxEdgeArrayListTrans(ArrayList<BoxEdge> boxEdgeArrayListForTrans){
+
+        ArrayList<BoxEdge> boxEdgeArrayListAfterTrans = new ArrayList<>();
+        for (int i = 0 ; i < boxEdgeArrayListForTrans.size();i++){
+
+            BoxEdge boxEdge = boxEdgeArrayListForTrans.get(i);
+            boxEdge = boxEdgeTrans(boxEdge);
+            boxEdgeArrayListAfterTrans.add(boxEdge);
+
+        }
+
+        return boxEdgeArrayListAfterTrans;
+
+    }
+
+
+
+}

+ 125 - 0
src/main/java/index/alg/BoxFlow.java

@@ -0,0 +1,125 @@
+package index.alg;
+
+import index.alg.boxscan.ScanOutLine;
+import index.entity.*;
+import index.log.Log;
+import index.plot.Plot;
+
+import java.util.ArrayList;
+
+public class BoxFlow {
+
+    public void start(ArrayList<Point> initialPoints,ArrayList<Point> allWorkPoints) throws Exception {
+
+        Plot plot = new Plot("/Users/haoqianpan/file/programfile/meanshift/out/boxscan/");
+
+        plot.collectData("initial.txt",initialPoints);
+
+        //计算分割网格的一些参数
+        BuildInitialWholeIndex buildInitialWholeIndex = new BuildInitialWholeIndex();
+        WholeIndex wholeIndex = buildInitialWholeIndex.build(initialPoints,100,100);
+
+        Log.print("已分割");
+
+        //获取直线
+        BuildLines buildLines = new BuildLines();
+        ArrayList<LineSegment> lineSegments = buildLines.build(initialPoints);
+
+        Log.print("已获取直线");
+
+        //计算初始形状的占用情况
+        BuildInitialOccupy buildInitialOccupy = new BuildInitialOccupy();
+        OccupyPoint occupyPoint = buildInitialOccupy.build(lineSegments,wholeIndex);
+
+        Log.print("初始占用情况已计算");
+
+        //过滤掉太远的作业点
+        WorkPointsExclude workPointsExclude = new WorkPointsExclude();
+        ArrayList<Point> pointsExclude = workPointsExclude.pointsExclude(allWorkPoints,wholeIndex);
+
+        Log.print("作业点已过滤");
+
+        plot.collectData("pointsexclude.txt",pointsExclude);
+
+        //作业点填充
+        FillWorkPoints fillWorkPoints = new FillWorkPoints();
+        ArrayList<ArrayList<Integer>> indexsList = fillWorkPoints.Fill(wholeIndex,pointsExclude);
+
+        Log.print("作业点已填充");
+
+        //计算作业后的占用情况
+        BuildChangedOccupy buildChangedOccupy = new BuildChangedOccupy();
+        buildChangedOccupy.build(occupyPoint,wholeIndex,indexsList);
+
+        Log.print("作业后占用情况已计算");
+
+        //构造box
+        BuildBoxFromList buildBoxFromList = new BuildBoxFromList();
+        ArrayList<Box> boxArrayList = buildBoxFromList.build(wholeIndex,indexsList);
+
+        Log.print("已构造box");
+
+        //扫描
+
+        Log.print("开始扫描");
+
+        ScanOutLine scanOutLine = new ScanOutLine();
+        scanOutLine.scan(boxArrayList,100);
+        ArrayList<ArrayList<BoxEdge>> shapeList = scanOutLine.getShapeList();
+        ArrayList<ArrayList<Point>> shapePointList = scanOutLine.getShapePointList();
+
+
+        Log.print("扫描结束");
+
+
+        BoxCorTrans boxCorTrans = new BoxCorTrans(wholeIndex);
+
+
+        //中点
+        ArrayList<ArrayList<Point>> pointsArrayList = new ArrayList<>();
+
+        //取边的中点相连
+        for (int i = 0 ; i < shapeList.size();i++){
+
+            ArrayList<Point> points = new ArrayList<>();
+            ArrayList<BoxEdge> boxEdges = shapeList.get(i);
+            for (int j = 0 ; j < boxEdges.size();j++){
+
+                BoxEdge boxEdge = boxEdges.get(j);
+                Point pointMiddle = boxEdge.getMiddlePoint();
+                points.add(pointMiddle);
+
+            }
+
+            points = boxCorTrans.pointArrayListTrans(points);
+            points.add(points.get(0));
+            plot.collectData("shapemiddle-" + i,points);
+            pointsArrayList.add(points);
+
+        }
+
+//        for (int i = 0 ; i < pointsArrayList.size();i++){
+//
+//            ArrayList<Point> points = shapePointList.get(i);
+//            points.add(points.get(0));
+//            points = boxCorTrans.pointArrayListTrans(points);
+//            System.out.println(points.size());
+//            plot.collectData("shape-" + i,points);
+//
+//        }
+
+        //网格端点直连
+        for (int i = 0 ; i < shapePointList.size();i++){
+
+            ArrayList<Point> points = shapePointList.get(i);
+            points.add(points.get(0));
+            points = boxCorTrans.pointArrayListTrans(points);
+            System.out.println(points.size());
+            plot.collectData("shape-" + i,points);
+        }
+
+        plot.normalPrint();
+
+    }
+
+}

+ 89 - 0
src/main/java/index/alg/BuildBoxFromList.java

@@ -0,0 +1,89 @@
+package index.alg;
+
+import index.entity.Box;
+import index.entity.Point;
+import index.entity.WholeIndex;
+
+import java.util.ArrayList;
+
+public class BuildBoxFromList {
+
+    Integer workNumber = 0;
+    Integer occupyNumber = 1;
+    Integer otherNumber = 3;
+
+
+    //
+    public ArrayList<Box> build(WholeIndex wholeIndex,ArrayList<ArrayList<Integer>> indexsList){
+
+        Double minX = wholeIndex.getMinX();
+        Double minY = wholeIndex.getMinY();
+        Integer numOfGapsX = wholeIndex.getNumOfGapsX();
+        Integer numOfGapsY = wholeIndex.getNumOfGapsY();
+        Double xGap =wholeIndex.getxGap();
+        Double yGap = wholeIndex.getyGap();
+
+        ArrayList<Box> boxArrayList = new ArrayList<>();
+        for (int i = 0 ; i < indexsList.size();i++){
+
+            ArrayList<Integer> indexs = indexsList.get(i);
+            for (int j = 0 ; j < indexs.size();j++){
+
+                Integer symbolNumber = indexs.get(j);
+
+                if (symbolNumber.equals(occupyNumber)){
+
+                    Point leftUpPoint = new Point();
+                    Point rightUpPoint = new Point();
+                    Point rightDownPoint = new Point();
+                    Point leftDownPoint = new Point();
+
+//                    Double minXOfBox = i * xGap;
+//                    Double maxXOfBox = minXOfBox + xGap;
+//                    Double minYOfBox = j * yGap;
+//                    Double maxYOfBox = minYOfBox + yGap;
+
+                    double minXOfBox = i;
+                    double maxXOfBox = i + 1 ;
+                    double minYOfBox = j;
+                    double maxYOfBox = j + 1;
+
+                    //左上角的点
+                    leftUpPoint.setColX(minXOfBox);
+                    leftUpPoint.setColY(maxYOfBox);
+
+                    //右上角的点
+                    rightUpPoint.setColX(maxXOfBox);
+                    rightUpPoint.setColY(maxYOfBox);
+
+                    //右下角的点
+                    rightDownPoint.setColX(maxXOfBox);
+                    rightDownPoint.setColY(minYOfBox);
+
+                    //左下角的点
+                    leftDownPoint.setColX(minXOfBox);
+                    leftDownPoint.setColY(minYOfBox);
+
+                    ArrayList<Point> pointsList = new ArrayList<>();
+                    pointsList.add(leftUpPoint);
+                    pointsList.add(rightUpPoint);
+                    pointsList.add(rightDownPoint);
+                    pointsList.add(leftDownPoint);
+
+                    Box box = new Box();
+                    box.setPointsList(pointsList);
+                    box.setPointSymbol(leftUpPoint);
+                    box.buildBoxEdgeArrayList();
+                    boxArrayList.add(box);
+                }
+
+            }
+
+        }
+
+        return boxArrayList;
+
+
+    }
+
+}

+ 50 - 0
src/main/java/index/alg/BuildChangedOccupy.java

@@ -0,0 +1,50 @@
+package index.alg;
+
+import index.entity.*;
+
+import java.util.ArrayList;
+
+public class BuildChangedOccupy {
+
+    Integer workNumber = 0;
+    Integer occupyNumber = 1;
+    Integer otherNumber = 3;
+    public void build(OccupyPoint occupyPointInitial, WholeIndex wholeIndex, ArrayList<ArrayList<Integer>> indexsList){
+
+        OccupyIndex occupyIndex = OccupyTransfer.pointToIndex(wholeIndex,occupyPointInitial);
+        ArrayList<ArrayList<BeginEndIndex>> occupyIndexs = occupyIndex.getOccupyIndexs();
+
+        for (int i = 0; i < occupyIndexs.size(); i++){
+
+            ArrayList<BeginEndIndex> beginEndIndexArrayList = occupyIndexs.get(i);
+
+            ArrayList<Integer> indexs =indexsList.get(i);
+
+            for (int j = 0; j < beginEndIndexArrayList.size();j++){
+
+                BeginEndIndex beginEndIndex = beginEndIndexArrayList.get(j);
+                Index beginIndex = beginEndIndex.getBeginIndex();
+                Index endIndex = beginEndIndex.getEndIndex();
+
+                Integer yBeginIndex = beginIndex.getyIndex();
+                Integer yEndIndex = endIndex.getyIndex();
+
+                for (int k = yBeginIndex; k <= yEndIndex ; k++){
+                        if (!indexs.get(k).equals(workNumber)){
+                            indexs.set(k,occupyNumber);
+                        }
+                }
+            }
+
+            indexsList.set(i,indexs);
+
+        }
+
+
+
+
+
+
+    }
+
+}

+ 134 - 0
src/main/java/index/alg/BuildInitialOccupy.java

@@ -0,0 +1,134 @@
+package index.alg;
+
+import index.entity.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class BuildInitialOccupy {
+
+    public OccupyPoint build(ArrayList<LineSegment> linesList, WholeIndex wholeIndex) throws Exception{
+
+        Double minX = wholeIndex.getMinX();
+        Double minY = wholeIndex.getMinY();
+        Integer numOfGapsX = wholeIndex.getNumOfGapsX();
+        Integer numOfGapsY = wholeIndex.getNumOfGapsY();
+        Double xGap =wholeIndex.getxGap();
+        Double yGap = wholeIndex.getyGap();
+
+        //占用情况
+        ArrayList<ArrayList<BeginEndPoint>> occupyPoints = new ArrayList<>();
+        CurveTool curveTool = new CurveTool();
+        for (int i = 0 ; i < numOfGapsX;i++){
+            //当前列的x,取网格的中部
+            Double xTemp = minX + i * xGap + 0.5 * xGap;
+            //与当前列相交的线段,应该为偶数
+            ArrayList<LineSegment> lineSegments = findLine(xTemp,linesList);
+
+            if (lineSegments.size() % 2 !=0){
+
+                throw new Exception("初始图形不规范!");
+
+            }
+
+            Integer lineSegmentsSize = lineSegments.size();
+            Integer halfLineSegmentSize = lineSegmentsSize / 2;
+
+            //当前列的占用情况
+            ArrayList<BeginEndPoint> beginEndPoints = new ArrayList<>();
+
+            for (int j = 0;j < lineSegmentsSize - 1;j=j+2){
+
+                LineSegment lineSegment1 = lineSegments.get(j);
+                LineSegment lineSegment2 = lineSegments.get( j + 1);
+
+                ArrayList<Double> paramList1 = lineSegment1.getLineParamList();
+                ArrayList<Double> paramList2 = lineSegment2.getLineParamList();
+
+                Double y1 = curveTool.getLineYValue(xTemp,paramList1);
+                Double y2 = curveTool.getLineYValue(xTemp,paramList2);
+
+                Point point1 = new Point(xTemp,y1);
+                Point point2 = new Point(xTemp,y2);
+                BeginEndPoint beginEndPoint = new BeginEndPoint(point1,point2);
+                beginEndPoints.add(beginEndPoint);
+            }
+
+            occupyPoints.add(beginEndPoints);
+        }
+
+        OccupyPoint occupyPoint = new OccupyPoint();
+
+        occupyPoint.setOccupyPoints(occupyPoints);
+
+        return occupyPoint;
+
+    }
+
+    //从小到大排序
+    public ArrayList<LineSegment> findLine(Double x ,ArrayList<LineSegment> linesList){
+
+        ArrayList<LineSegment> lineSegments = new ArrayList<>();
+
+        for (int i = 0 ; i < linesList.size();i++){
+
+            LineSegment lineSegment = linesList.get(i);
+            BeginEndPoint beginEndPoint = lineSegment.getBeginEndPoint();
+            Point pointBegin = beginEndPoint.getBeginPoint();
+            Point pointEnd = beginEndPoint.getEndPoint();
+            Double beginX = pointBegin.getColX();
+            Double endX = pointEnd.getColX();
+            if (x >= beginX && x <= endX){
+                lineSegments.add(lineSegment);
+            }
+        }
+
+
+        CurveTool curveTool = new CurveTool();
+        ArrayList<Map> lineAndHeight = new ArrayList<>();
+        for (int i = 0 ; i < lineSegments.size();i++){
+
+            LineSegment lineSegment = lineSegments.get(i);
+            ArrayList<Double> paramList = lineSegment.getLineParamList();
+            Double height = curveTool.getLineYValue(x,paramList);
+            Map map = new HashMap();
+            map.put("HEIGHT",height);
+            map.put("LINE",lineSegment);
+            lineAndHeight.add(map);
+
+        }
+
+        for (int i = 0 ; i < lineAndHeight.size() - 1;i++){
+
+            Map mapI = lineAndHeight.get(i);
+            Double heightI = (Double) mapI.get("HEIGHT");
+            for (int j = i + 1 ; j < lineAndHeight.size();j++){
+                Map mapJ = lineAndHeight.get(j);
+                Double heightJ = (Double) mapJ.get("HEIGHT");
+                if (heightI >  heightJ){
+                        Map mapTemp = mapI;
+                        mapI = mapJ;
+                        mapJ = mapTemp;
+                        lineAndHeight.set(i,mapI);
+                        lineAndHeight.set(j,mapJ);
+                }
+            }
+        }
+
+        ArrayList<LineSegment> lineSegmentsAfterSort = new ArrayList<>();
+        for (int i = 0;i < lineAndHeight.size();i++){
+
+            Map map = lineAndHeight.get(i);
+            LineSegment lineSegment = (LineSegment) map.get("LINE");
+            lineSegmentsAfterSort.add(lineSegment);
+        }
+
+        return lineSegmentsAfterSort;
+
+    }
+
+}
+
+

+ 76 - 0
src/main/java/index/alg/BuildInitialWholeIndex.java

@@ -0,0 +1,76 @@
+package index.alg;
+
+import index.entity.Point;
+import index.entity.WholeIndex;
+import index.file.OperateFile;
+
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+
+public class BuildInitialWholeIndex {
+
+
+    //
+    public WholeIndex build(ArrayList<Point> pointsList,Integer numOfGapsX,Integer numOfGapsY){
+
+        pointsList.add(pointsList.get(0));
+
+        Point point0 = pointsList.get(0);
+
+        double minX = point0.getColX();
+
+        double minY = point0.getColY();
+
+        double maxX = point0.getColX();
+
+        double maxY = point0.getColY();
+
+        for (int i = 0 ; i < pointsList.size();i++){
+
+            Point point = pointsList.get(i);
+
+            double corX = point.getColX();
+            double corY = point.getColY();
+
+            if (corX < minX){
+
+                minX = corX;
+
+            }
+
+            if (corX > maxX){
+
+                maxX = corX;
+
+            }
+
+            if (corY < minY){
+
+                minY = corY;
+
+            }
+
+            if (corY > maxY){
+
+                maxY = corY;
+
+            }
+
+        }
+
+        double xGap = (maxX - minX) / numOfGapsX;
+        double yGap = (maxY - minY) / numOfGapsY;
+
+        WholeIndex wholeIndex = new WholeIndex();
+        wholeIndex.setMinX(minX);
+        wholeIndex.setMinY(minY);
+        wholeIndex.setNumOfGapsX(numOfGapsX);
+        wholeIndex.setNumOfGapsY(numOfGapsY);
+        wholeIndex.setxGap(xGap);
+        wholeIndex.setyGap(yGap);
+
+        return wholeIndex;
+
+    }
+
+}

+ 41 - 0
src/main/java/index/alg/BuildLines.java

@@ -0,0 +1,41 @@
+package index.alg;
+
+import index.entity.BeginEndPoint;
+import index.entity.LineSegment;
+import index.entity.Point;
+
+import javax.swing.text.Segment;
+import java.util.ArrayList;
+
+public class BuildLines {
+
+    public ArrayList<LineSegment> build(ArrayList<Point> pointsList){
+
+        ArrayList<LineSegment> lineSegments = new ArrayList<>();
+        CurveTool tool = new CurveTool();
+
+        for (int i = 0 ; i < (pointsList.size() - 1);i++){
+
+            //两个点形成直线
+            Point pointI = pointsList.get(i);
+            Point pointJ = pointsList.get(i + 1);
+            boolean isTest = false;
+
+            //直线一般式相关的参数,A,B,C
+            ArrayList<Double> lineParamList  = tool.calLineabc(pointI,pointJ);
+            BeginEndPoint beginEndPoint = new BeginEndPoint(pointI,pointJ);
+            LineSegment lineSegment = new LineSegment();
+            lineSegment.setBeginEndPoint(beginEndPoint);
+            lineSegment.setLineParamList(lineParamList);
+            lineSegments.add(lineSegment);
+
+        }
+
+        return lineSegments;
+
+    }
+
+
+
+
+}

+ 8 - 2
src/main/java/index/alg/Cal.java

@@ -23,7 +23,7 @@ public class Cal {
     Integer numOfGaps = 100;
     Fit fit = new Fit();
 
-    public ArrayList<Point> calShape(Integer workDirection) throws SQLException, FileNotFoundException {
+    public ArrayList<Point> calShape(Integer workDirection) throws Exception {
         GetPoints getPoints = new GetPoints();
         getPoints.getPoints(workDirection);
         ArrayList<Point> realShapePoints = getPoints.realShapePoints;//实际形状的平面坐标
@@ -68,6 +68,12 @@ public class Cal {
             }
         }
         System.out.println("过滤后点数量:" + pointAfterExclude.size());
+
+        //
+        BoxFlow boxFlow = new BoxFlow();
+        boxFlow.start(realShapePoints,pointAfterExclude);
+        //
+
         //对所有的轨迹点经过排除后剩下来的点
 //        operateFile.printPoint("Y:\\pointsexclude.txt",pointAfterExclude);
         operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/pointsexclude.txt",pointAfterExclude);
@@ -204,7 +210,7 @@ public class Cal {
 //        ArrayList<Point> shapeFill = fit.allCircleFitDefault(afterAdjustPointsList);
 //        shape = fit.excludePoints(shape);
         shape.add(shape.get(0));
-        ArrayList<Point> afterAdjustPointsList = adjust.fillArrayListPlus(occupyShapeList,shape,5);
+        ArrayList<Point> afterAdjustPointsList = adjust.fillArrayListPlus(occupyShapeList,shape,10);
 //        System.out.println(shape.size());
 //        for (int i = 0 ; i < shape.size() ; i++){
 //            System.out.println(shape.get(i).getColX() + " " + shape.get(i).getColY() );

+ 166 - 0
src/main/java/index/alg/FillWorkPoints.java

@@ -0,0 +1,166 @@
+package index.alg;
+
+import index.entity.Index;
+import index.entity.Point;
+import index.entity.WholeIndex;
+
+import java.util.ArrayList;
+
+public class FillWorkPoints {
+
+    Integer workNumber = 0;
+    Integer occupyNumber = 1;
+    Integer otherNumber = 3;
+
+    //填充
+    public ArrayList<ArrayList<Integer>> Fill(WholeIndex wholeIndex,ArrayList<Point> pointsExclude){
+
+        //占用情况,作业点经过的地方是0,未经过是3
+        ArrayList<ArrayList<Integer>> indexsList = new ArrayList<>();
+
+        //网格划分的情况
+        Double minX = wholeIndex.getMinX();
+        Double minY = wholeIndex.getMinY();
+        Integer numOfGapsX = wholeIndex.getNumOfGapsX();
+        Integer numOfGapsY = wholeIndex.getNumOfGapsY();
+        Double xGap =wholeIndex.getxGap();
+        Double yGap = wholeIndex.getyGap();
+
+        //赋初值
+        indexsList = indexsListInitial(indexsList,numOfGapsX,numOfGapsY);
+
+
+        IndexTool indexTool = new IndexTool(wholeIndex);
+        //判断占用情况,
+        for (int i = 0 ; i < pointsExclude.size() ;i++){
+            Point pointWork = pointsExclude.get(i);
+            Index indexWork = indexTool.identifyIndex(pointWork);
+            setIndexValue(indexWork,indexsList,workNumber);
+        }
+
+
+        //纵向填充
+        for (int i = 0 ; i < indexsList.size();i++){
+
+            ArrayList<Integer> indexsForFill = indexsList.get(i);
+            fillList(indexsForFill,workNumber,5);
+            indexsList.set(i,indexsForFill);
+        }
+
+        //换个方向填充
+        indexsList = changedDirect(indexsList);
+
+        for (int i = 0 ; i < indexsList.size();i++){
+
+            ArrayList<Integer> indexsForFill = indexsList.get(i);
+            fillList(indexsForFill,workNumber,5);
+            indexsList.set(i,indexsForFill);
+        }
+
+        //再转回来
+        indexsList = changedDirect(indexsList);
+
+        return indexsList;
+
+
+    }
+
+    public void setIndexValue(Index indexWork,ArrayList<ArrayList<Integer>> indexsList,Integer value){
+
+        Integer xIndex = indexWork.getxIndex();
+        Integer yIndex = indexWork.getyIndex();
+
+        ArrayList<Integer> indexsForRevise = indexsList.get(xIndex);
+        indexsForRevise.set(yIndex,value);
+        indexsList.set(xIndex,indexsForRevise);
+
+    }
+
+    public ArrayList<ArrayList<Integer>> changedDirect(ArrayList<ArrayList<Integer>> indexsList){
+
+        Integer xSize = indexsList.size();
+        ArrayList<Integer> indexs0  = indexsList.get(0);
+        Integer ySize = indexs0.size();
+
+        ArrayList<ArrayList<Integer>> indexsListAfterChanged = new ArrayList<>();
+
+        for (int i = 0 ; i < ySize;i++){
+
+
+            ArrayList<Integer> changed = new ArrayList<>();
+            for (int j = 0 ; j < xSize ;j++){
+
+                ArrayList<Integer> row = indexsList.get(j);
+                changed.add(row.get(i));
+            }
+
+            indexsListAfterChanged.add(changed);
+
+        }
+
+        return indexsListAfterChanged;
+
+
+
+
+    }
+
+    public ArrayList<ArrayList<Integer>> indexsListInitial(ArrayList<ArrayList<Integer>> indexsList,Integer numOfGapsX,Integer numberOfGapsY){
+
+        for (int i = 0 ; i < numOfGapsX;i++){
+
+            ArrayList<Integer> indexs = new ArrayList<>();
+            for (int j = 0 ; j < numberOfGapsY;j++){
+
+                indexs.add(otherNumber);
+
+            }
+            indexsList.add(indexs);
+
+        }
+
+        return indexsList;
+
+    }
+
+
+    //当间隙小于scale时就填充
+    public void fillList( ArrayList<Integer> indexsForFill,Integer characterValue,Integer scale){
+
+
+        //当前列,被占据的网格的编号(纵向编号)
+        ArrayList<Integer> hasCharaIndexList = new ArrayList<>();
+
+         for (int i = 0 ; i < indexsForFill.size();i++){
+
+             if (indexsForFill.get(i).equals(characterValue)){
+
+                hasCharaIndexList.add(i);
+
+             }
+
+         }
+
+         for (int i = 0 ; i < hasCharaIndexList.size() - 1;i++){
+
+             Integer thisIndex = hasCharaIndexList.get(i);
+             Integer nextIndex = hasCharaIndexList.get(i + 1);
+
+             if (((nextIndex - thisIndex) < scale) &&((nextIndex - thisIndex) != 1)){
+
+                 for (int j = (thisIndex + 1) ; j < nextIndex ; j++){
+
+                     //填充
+                     indexsForFill.set(j,characterValue);
+
+                 }
+
+             }
+
+         }
+
+    }
+
+
+
+}

+ 47 - 29
src/main/java/index/alg/GetPoints.java

@@ -7,15 +7,14 @@ import index.db.ConnectToSourceDB;
 import index.db.DbOperate;
 import index.entity.Point;
 import index.file.OperateFile;
-
 import java.io.FileNotFoundException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+
+
 
 //暂时先自己写connection从数据库中获取
 
@@ -42,8 +41,6 @@ public class GetPoints {
 
     public void getPoints(Integer workDirection) throws SQLException, FileNotFoundException {
 
-
-
         //B50
 //        String realShapeBeginTime = "2020-07-09 15:06:00.000000";
 //        String realShapeEndTime = "2020-07-09 15:08:00.000000";
@@ -65,7 +62,6 @@ public class GetPoints {
 //        String allPointsBeginTime = "2020-07-15 11:33:00.000000";
 //        String allPointsEndTime = "2020-07-15 11:36:00.000000";
 
-
 //        A03
 //        String realShapeBeginTime = "2020-07-13 14:27:00.000000";
 //        String realShapeEndTime = "2020-07-13 14:30:00.000000";
@@ -113,19 +109,20 @@ public class GetPoints {
 ////        String realShapeEndTime = "2020-09-02 14:30:00.000000";
 
 //        a30
-        String realShapeBeginTime = "2020-09-02 18:06:42.000000";
-        String realShapeEndTime = "2020-09-02 18:08:18.000000";
-
-
-
-
+//        String realShapeBeginTime = "2020-09-02 18:06:42.000000";
+//        String realShapeEndTime = "2020-09-02 18:08:18.000000";
 
+        //b53-437跑垛位
+        String realShapeBeginTime = "2020-09-08 15:17:14.000000";
+        String realShapeEndTime = "2020-09-08 15:19:37.000000";
 
 
 //        String queryShapeSql = sqlFactory(realShapeBeginTime,realShapeEndTime,"港装K438");
 //        String queryShapeSql = sqlFactory(realShapeBeginTime,realShapeEndTime,"港装K121");
+//        String queryShapeSql = sqlFactory(realShapeBeginTime,realShapeEndTime,"港装K437");
 //        realShapePoints = buildPoints(queryShapeSql,workDirection);
-        realShapePoints = buildPointsFromFile("/Users/haoqianpan/file/programfile/gpsexc/in/a30.txt",workDirection);
+//        realShapePoints = buildPointsFromFile("/Users/haoqianpan/file/programfile/gpsexc/in/a30.txt",workDirection);
+        realShapePoints = buildPointsFromFile("/Users/haoqianpan/file/programfile/meanshift/in/a49shape.txt",workDirection);
 
         //
         ArrayList<String> userNameArrayList = new ArrayList<>();
@@ -138,16 +135,17 @@ public class GetPoints {
 //        machineIdList.add("港装K438");
 //        allPointsBeginTimeList.add("2020-08-27 11:05:00.000000");
 //        allPointsEndTimeList.add("2020-08-27 19:33:00.000000");
+
 ////        438第二次上下垛时间
 //        machineIdList.add("港装K438");
 //        allPointsBeginTimeList.add("2020-08-27 20:25:00.000000");
 //        allPointsEndTimeList.add("2020-08-28 07:15:00.000000");
-//
+
 ////        438第三次上下垛时间
 //        machineIdList.add("港装K438");
 //        allPointsBeginTimeList.add("2020-08-28 08:35:00.000000");
 //        allPointsEndTimeList.add("2020-08-28 21:24:00.000000");
-//
+
 ////        438第四次上下垛时间
 //        machineIdList.add("港装K438");
 //        allPointsBeginTimeList.add("2020-08-29 08:29:00.000000");
@@ -159,17 +157,42 @@ public class GetPoints {
 //        allPointsEndTimeList.add("2020-09-01 10:50:00.000000");
 
         //a30第一次上下垛时间
-        machineIdList.add("港装K121");
-        allPointsBeginTimeList.add("2020-09-01 12:11:00.000000");
-        allPointsEndTimeList.add("2020-09-02 11:00:00.000000");
-
-        machineIdList.add("港装K438");
-        allPointsBeginTimeList.add("2020-09-02 14:30:00.000000");
-        allPointsEndTimeList.add("2020-09-02 18:06:00.000000");
+//        machineIdList.add("港装K121");
+//        allPointsBeginTimeList.add("2020-09-01 12:11:00.000000");
+//        allPointsEndTimeList.add("2020-09-02 11:00:00.000000");
+//
+//        machineIdList.add("港装K438");
+//        allPointsBeginTimeList.add("2020-09-02 14:30:00.000000");
+//        allPointsEndTimeList.add("2020-09-02 18:06:00.000000");
+
+        //b53-437上下垛位
+//        machineIdList.add("港装K437");
+//        allPointsBeginTimeList.add("2020-09-08 15:19:37.000000");
+//        allPointsEndTimeList.add("2020-09-08 22:00:00.000000");
+        //b53-121上下垛位
+//        machineIdList.add("港装K121");
+//        allPointsBeginTimeList.add("2020-09-08 15:19:37.000000");
+//        allPointsEndTimeList.add("2020-09-08 22:00:00.000000");
 
+//        machineIdList.add("港装K736");
+//        allPointsBeginTimeList.add("2020-09-11 11:27:42.000000");
+//        allPointsEndTimeList.add("2020-09-11 23:23:00.000000");
 
+//        machineIdList.add("港装K736");
+//        allPointsBeginTimeList.add("2020-09-13 08:11:00.000000");
+//        allPointsEndTimeList.add("2020-09-13 13:20:00.000000");
+//
+//        machineIdList.add("港装K736");
+//        allPointsBeginTimeList.add("2020-09-13 23:35:00.000000");
+//        allPointsEndTimeList.add("2020-09-14 10:42:00.000000");
 
+        machineIdList.add("港装K736");
+        allPointsBeginTimeList.add("2020-09-11 12:11:00.000000");
+        allPointsEndTimeList.add("2020-09-18 10:20:00.000000");
 
+        machineIdList.add("港装K121");
+        allPointsBeginTimeList.add("2020-09-17 13:35:00.000000");
+        allPointsEndTimeList.add("2020-09-18 08:12:00.000000");
 
         for (int i  = 0 ; i < (machineIdList.size());i++){
 
@@ -186,11 +209,6 @@ public class GetPoints {
 
 
 
-
-
-
-
-
 //        realShapePoints = buildPoints(sql1);
 //        allPoints = buildPoints(sql2);
 //        realShapePoints = buildPointsFromFile("Y:\\programresult\\dbdiff\\points\\shape.txt");
@@ -205,6 +223,7 @@ public class GetPoints {
 //        allPoints = buildPointsFromFile("/Users/haoqianpan/file/programfile/meanshift/in/working_data_y_0.99999.txt");
 //        Connection
 
+
     }
 
     public ArrayList<Point> buildPoints(String sql,Integer workDirection) throws SQLException {
@@ -215,11 +234,10 @@ public class GetPoints {
         DbOperate dbOperate = new DbOperate();
 
         ResultSet resultSet = dbOperate.runQuerySql(connection,sql);
-
         GpsExchange gpsExchange = new GpsExchange();
-
         ArrayList<Date> dateArrayList = new ArrayList<>();
 
+
         while (resultSet.next()){
 
             Double lat = resultSet.getDouble(1);

+ 111 - 0
src/main/java/index/alg/IndexTool.java

@@ -0,0 +1,111 @@
+package index.alg;
+
+import index.entity.Index;
+import index.entity.Point;
+import index.entity.WholeIndex;
+
+public class IndexTool {
+
+    Double minX;
+    Double minY;
+    Integer numOfGapsX;
+    Integer numOfGapsY;
+    Double xGap;
+    Double yGap;
+
+
+    public IndexTool(WholeIndex wholeIndex){
+
+        this.minX = wholeIndex.getMinX();
+        this.minY = wholeIndex.getMinY();
+        this.numOfGapsX = wholeIndex.getNumOfGapsX();
+        this.numOfGapsY = wholeIndex.getNumOfGapsY();
+        this.xGap =wholeIndex.getxGap();
+        this.yGap = wholeIndex.getyGap();
+
+    }
+
+
+    public Index identifyIndex(Point point){
+
+        Double pointX = point.getColX();
+        Double pointY = point.getColY();
+
+
+        Double xIndexTemp = (pointX - minX) / xGap;
+        Double yIndexTemp = (pointY - minY) / yGap;
+
+        Integer xIndex = xIndexTemp.intValue();
+        Integer yIndex = yIndexTemp.intValue();
+        Index index = new Index();
+
+//        if (xIndex == numOfGapsX){
+//
+//            xIndex = xIndex -1;
+//
+//        }
+//
+//        if (yIndex == numOfGapsY){
+//
+//            yIndex = yIndex -1;
+//
+//        }
+
+        if (xIndex >= numOfGapsX){
+
+            xIndex = numOfGapsX -1;
+
+        }
+
+        if (yIndex >= numOfGapsY){
+
+            yIndex = numOfGapsY -1;
+
+        }
+
+
+
+        index.setxIndex(xIndex);
+        index.setyIndex(yIndex);
+
+        return index;
+
+    }
+
+    public  Integer identifyYIndex(Double yCor){
+
+
+        Double yIndexTemp = (yCor - minY)/yGap;
+        Integer yIndex = yIndexTemp.intValue();
+
+        if (yIndex >= numOfGapsY){
+
+            yIndex = numOfGapsY - 1;
+
+        }
+
+
+        return yIndex;
+
+
+    }
+
+    public  Integer identifyXIndex(Double xCor){
+
+
+//        Double xMin = xIndexCorList.get(0);
+        Double xIndexTemp = (xCor - minX)/xGap;
+        Integer xIndex = xIndexTemp.intValue();
+
+        if (xIndex >= numOfGapsX){
+
+            xIndex = numOfGapsX - 1;
+
+        }
+
+        return xIndex;
+
+
+    }
+
+}

+ 67 - 0
src/main/java/index/alg/OccupyTransfer.java

@@ -0,0 +1,67 @@
+package index.alg;
+
+import index.entity.*;
+
+import java.util.ArrayList;
+
+public  class OccupyTransfer {
+
+    public static OccupyIndex pointToIndex(WholeIndex wholeIndex, OccupyPoint occupyPoint){
+
+//         获取网格划分的一些参数
+        Double minX = wholeIndex.getMinX();
+        Double minY = wholeIndex.getMinY();
+        Integer numOfGapsX = wholeIndex.getNumOfGapsX();
+        Integer numOfGapsY = wholeIndex.getNumOfGapsY();
+        Double xGap =wholeIndex.getxGap();
+        Double yGap = wholeIndex.getyGap();
+
+        IndexTool indexTool = new IndexTool(wholeIndex);
+
+        //
+        ArrayList<ArrayList<BeginEndPoint>> occupyPoints = occupyPoint.getOccupyPoints();
+
+        //
+        ArrayList<ArrayList<BeginEndIndex>> occupyIndexs = new ArrayList<>();
+
+
+
+        for (int i = 0 ; i < occupyPoints.size();i++){
+
+            //一列
+            ArrayList<BeginEndPoint> thisOccupyPoint = occupyPoints.get(i);
+
+            //
+            ArrayList<BeginEndIndex> thisOccupyIndex = new ArrayList<>();
+
+            for (int j = 0 ; j < thisOccupyPoint.size();j++){
+
+                BeginEndPoint beginEndPoint = thisOccupyPoint.get(j);
+                Point beginPoint = beginEndPoint.getBeginPoint();
+                Point endPoint = beginEndPoint.getEndPoint();
+                Index beginIndex = indexTool.identifyIndex(beginPoint);
+                Index endIndex = indexTool.identifyIndex(endPoint);
+                BeginEndIndex beginEndIndex = new BeginEndIndex();
+                beginEndIndex.setBeginIndex(beginIndex);
+                beginEndIndex.setEndIndex(endIndex);
+                thisOccupyIndex.add(beginEndIndex);
+            }
+
+            occupyIndexs.add(thisOccupyIndex);
+
+
+        }
+
+        OccupyIndex occupyIndex = new OccupyIndex();
+        occupyIndex.setOccupyIndexs(occupyIndexs);
+        return occupyIndex;
+
+    }
+
+    public static void indexToPoint(){
+
+
+
+    }
+
+}

+ 7 - 102
src/main/java/index/alg/Split.java

@@ -30,29 +30,12 @@ public class Split {
 
         OperateFile operateFile = new OperateFile();
 
-//        pointsList.add(pointsList.get(0));
 
         operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/initial.txt",pointsList);
         pointsList.add(pointsList.get(0));
 
 
 
-
-        //垛位的初始形状,未网格化处理
-//        operateFile.printPoint("Y:\\initial.txt",pointsList);
-//        operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/initial.txt",pointsList);
-
-//        System.out.println("print initial points-----------------");
-//        for (int i = 0 ; i < pointsList.size(); i++){
-//
-//            Point point = pointsList.get(i);
-//            System.out.println(point.getColX() + " " + point.getColY());
-//
-//        }
-//
-//        System.out.println("print initial points end--------------");
-
-
         Point point0 = pointsList.get(0);
 
         double minX = point0.getColX();
@@ -130,24 +113,11 @@ public class Split {
         decideIndex(rectanglePoints);
         getLines(pointsList);
 
-//        System.out.println(wholeIndexOccupy.getOccupyPerXArrayList());
-
-
     }
 
     //横向纵向划分网格
     public void decideIndex(ArrayList<Point> fourPointsList){
 
-
-//        System.out.println("test");
-//        for (int i = 0 ; i < fourPointsList.size(); i++){
-//
-//            Point pointTemp = fourPointsList.get(i);
-//            System.out.println(pointTemp.getColX() + " " + pointTemp.getColY());
-//
-//        }
-//        System.out.println("test");
-
         Point pointA = fourPointsList.get(0);
         Point pointB = fourPointsList.get(1);
         Point pointC = fourPointsList.get(2);
@@ -166,8 +136,6 @@ public class Split {
         yGap = (maxY - minY) / numOfGaps;
         System.out.println("yGap is : " + yGap);
 
-//        ArrayList<Double> xIndexCorList = new ArrayList<>();//格点横坐标List
-//        ArrayList<Double> yIndexCorList = new ArrayList<>();//格点纵坐标List
 
         for (int i = 0 ; i < numOfGaps + 1; i++){
 
@@ -177,11 +145,6 @@ public class Split {
             minY = minY + yGap;
         }
 
-//        System.out.println(xIndexCorList);
-//
-//        System.out.println(" ");
-//        System.out.println(yIndexCorList);
-
     }
 
     public double  calculateDistance(Point point1,Point point2){
@@ -190,24 +153,16 @@ public class Split {
         double corY1 = point1.getColY();
         double corX2 = point2.getColX();
         double corY2 = point2.getColY();
-        System.out.println("计算距离:");
-        System.out.println("corx1:" + corX1);
-        System.out.println("cory1:" + corY1);
-        System.out.println("corx2:" + corX2);
-        System.out.println("cory2:" + corY2);
-        System.out.println("distance");
-
 
         double distance = Math.sqrt(Math.pow((corX1 - corX2),2) + Math.pow((corY1 - corY2),2));
         return distance;
 
     }
 
-
     //根据实际形状的各个点形成直线
-    public void getLines(ArrayList<Point> pointsList){
-
+    public  ArrayList<ArrayList<Double>> getLines(ArrayList<Point> pointsList){
 
+        ArrayList<ArrayList<Double>> linesParamList = new ArrayList<>();
 
         for (int i = 0 ; i < (pointsList.size() - 1);i++){
 
@@ -216,43 +171,16 @@ public class Split {
             Point pointJ = pointsList.get(i + 1);
             boolean isTest = false;
 
-//            if (i == (pointsList.size() - 2)){
-//
-//                System.out.println("这是最后那条直线pppppppppppppppppppppppppppp");
-//                System.out.println("这是最后那条直线pppppppppppppppppppppppppppp");
-//                System.out.println("这是最后那条直线pppppppppppppppppppppppppppp");
-//                System.out.println("这是最后那条直线pppppppppppppppppppppppppppp");
-//
-//
-//                System.out.println(pointI.getColX() + " " + pointI.getColY());
-//                System.out.println(pointJ.getColX() + " " + pointJ.getColY());
-//
-//                isTest = true;
-//
-//            }
-
-
-
             //直线一般式相关的参数,A,B,C
             ArrayList<Double> lineParamList  = tool.calLineabc(pointI,pointJ);
-
-            //线段起点终点所在网格的编号
-
-//            //第一个点的横纵坐标
-//            Double pointIx = pointI.getColX();
-//            Double pointIy = pointI.getColY();
-//            //第二个点的横纵坐标
-//            Double pointJx = pointJ.getColX();
-//            Double pointJy = pointJ.getColY();
-
-            //该直线起始点的网格位置
-//            Index indexI = identifyIndex(pointI);
-//            Index indexJ = identifyIndex(pointJ);
+            linesParamList.add(lineParamList);
             lineOccupy(pointI,pointJ,lineParamList,isTest);
 
+        }
+
+        return linesParamList;
 
 
-        }
 
 
 
@@ -263,7 +191,6 @@ public class Split {
 
         Double xMin = xIndexCorList.get(0);
         Double yMin = yIndexCorList.get(0);
-
         ///
         //该直线起始点的网格位置
         Index indexI = identifyIndex(pointI);
@@ -407,39 +334,18 @@ public class Split {
         //网格的起始x
         Double minX = xIndexCorList.get(0);
 
-
-//        //网格的终止x
-//        Double maxX = xIndexCorList.get(xIndexCorList.size());
-
         //网格的起始y
         Double minY = yIndexCorList.get(0);
-
         Double xIndexTemp = (pointX - minX) / xGap;
         Double yIndexTemp = (pointY - minY) / yGap;
 
-//        if (xIndexTemp > 100){
-//
-//            System.out.println(1111111111);
-//            System.out.println("x is :" + pointX);
-//            System.out.println("minx is : " + minX);
-//            System.out.println("xgap is :" + xGap);
-//            System.out.println("x - minx = " + (pointX - minX));
-//            System.out.println("result is " + (pointX - minX) / xGap);
-//
-//        }
 
-//        System.out.println("pointx: " + pointX +" - " +"minx: " + minX + " = " + (pointX - minX));
-//        System.out.println("(pointX - minX) / xGap: " + xIndexTemp);
 
 
         Integer xIndex = xIndexTemp.intValue();
         Integer yIndex = yIndexTemp.intValue();
 
-//        if (xIndex == 100){
-//
-//            System.out.println(1111111 + "  " + pointX + " " + xIndexTemp);
-//
-//        }
+
 
         Index index = new Index();
 
@@ -467,7 +373,6 @@ public class Split {
     public  Integer identifyYIndex(Double yCor){
 
 
-//        Double xMin = xIndexCorList.get(0);
         Double yMin = yIndexCorList.get(0);
         Double yIndexTemp = (yCor - yMin)/yGap;
         Integer yIndex = yIndexTemp.intValue();

+ 38 - 0
src/main/java/index/alg/WorkPointsExclude.java

@@ -0,0 +1,38 @@
+package index.alg;
+
+import index.entity.Point;
+import index.entity.WholeIndex;
+
+import java.util.ArrayList;
+
+public class WorkPointsExclude {
+
+    public ArrayList<Point> pointsExclude(ArrayList<Point> allWorkPoints, WholeIndex wholeIndex){
+
+        ArrayList<Point> pointAfterExclude = new ArrayList<>();
+
+        Double minX = wholeIndex.getMinX();
+        Double minY = wholeIndex.getMinY();
+        Integer numOfGapsX = wholeIndex.getNumOfGapsX();
+        Integer numOfGapsY = wholeIndex.getNumOfGapsY();
+        Double xGap =wholeIndex.getxGap();
+        Double yGap = wholeIndex.getyGap();
+
+        Double maxX = minX + numOfGapsX * xGap;
+        Double maxY = minY + numOfGapsY * yGap;
+
+
+        for(int i = 0 ; i < allWorkPoints.size();i++){
+            Point point = allWorkPoints.get(i);
+            Double corX = point.getColX();
+            Double corY = point.getColY();
+            if ( (corX < maxX) && (corX > minX) && (corY < maxY) && (corY > minY)){
+                pointAfterExclude.add(point);
+            }
+        }
+
+        return pointAfterExclude;
+
+    }
+
+}

+ 40 - 18
src/main/java/index/alg/boxscan/GetAllEdge.java

@@ -3,6 +3,7 @@ package index.alg.boxscan;
 import index.entity.Box;
 import index.entity.BoxEdge;
 import index.entity.Point;
+import index.log.Log;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -38,7 +39,7 @@ public class GetAllEdge {
             Point point2 = point12.get(1);
 
             String edgeUid;
-            if (point1.getColX() == point2.getColX()){
+            if (point1.getColX().equals(point2.getColX())){
 
                 if (point1.getColY() > point2.getColY()){
 
@@ -66,36 +67,57 @@ public class GetAllEdge {
             }
 
         //
-        ArrayList<String> uidListCopy = uidList;
+//        for (int i = 0 ; i < uidList.size();i++){
+//
+//            String uidTemp = uidList.get(i);
+//            Log.print(uidTemp);
+
+//        }
+//        Log.print(" " + uidList.indexOf("97.0-71.0-98.0-71.0"));
+//        Log.print(" " + uidList.lastIndexOf("97.0-71.0-98.0-71.0"));
+
+//        Log.print(" " + uidList.get(35052));
+//        Log.print(" " + uidList.get(35058));
+//
+//        Log.print(" " + uidList.size());
+
+//        ArrayList<String> uidListCopy = uidList;
+        ArrayList<String> uidListCopy = new ArrayList<>();
+        //copy
+        for (int i = 0 ; i < uidList.size();i++){
+
+            uidListCopy.add(uidList.get(i));
+
+        }
+
+
+
+
+
         for (int i = 0;i < uidList.size();i++){
 
             int frequency = Collections.frequency(uidListCopy,uidList.get(i));
 
-            if (frequency == 1){
 
 
+            if (frequency == 1){
+
                 boxEdgesWithOutDuplicates.add(boxEdges.get(i));
+
                 uidListCopy.remove(uidList.get(i));
 
             }
 
+            else {
+
+//                System.out.println(uidList.get(i) + " " + frequency);
+
+            }
+
         }
-        //
 
-//        LinkedHashSet<String> uidHashSet = new LinkedHashSet<>(uidList);
-//        ArrayList<String> uidListWithoutDuplicates = new ArrayList<String>(uidHashSet);
-//
-//
-//
-//        //这些不重复的边的uid在uidList中的标号
-//        ArrayList<Integer> withOutDuplicatesUidList = new ArrayList<>();
-//
-//        for (int i = 0 ; i < uidListWithoutDuplicates.size();i++){
-//            String uid = uidListWithoutDuplicates.get(i);
-//            Integer uidIndex = uidList.indexOf(uid);
-////            withOutDuplicatesUidList.add(uidIndex);
-//            boxEdgesWithOutDuplicates.add(boxEdges.get(uidIndex));
-//        }
+
+
         return boxEdgesWithOutDuplicates;
     }
 

+ 112 - 41
src/main/java/index/alg/boxscan/ScanOutLine.java

@@ -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;
 
     }

+ 23 - 0
src/main/java/index/entity/BeginEndIndex.java

@@ -0,0 +1,23 @@
+package index.entity;
+
+public class BeginEndIndex {
+
+    public Index beginIndex;
+    public Index endIndex;
+
+    public Index getBeginIndex() {
+        return beginIndex;
+    }
+
+    public void setBeginIndex(Index beginIndex) {
+        this.beginIndex = beginIndex;
+    }
+
+    public Index getEndIndex() {
+        return endIndex;
+    }
+
+    public void setEndIndex(Index endIndex) {
+        this.endIndex = endIndex;
+    }
+}

+ 46 - 0
src/main/java/index/entity/BeginEndPoint.java

@@ -0,0 +1,46 @@
+package index.entity;
+
+public class BeginEndPoint {
+
+    public Point beginPoint;
+    public Point endPoint;
+
+//    public BeginEndPoint(Point beginPoint,Point endPoint){
+//
+//        this.beginPoint = beginPoint;
+//        this.endPoint = endPoint;
+//    }
+
+    public BeginEndPoint(Point point1,Point point2){
+
+        double x1 = point1.getColX();
+        double x2 = point2.getColX();
+        if (x1 <= x2){
+            this.beginPoint = point1;
+            this.endPoint = point2;
+        }
+        else {
+
+            this.beginPoint = point2;
+            this.endPoint = point1;
+
+        }
+
+    }
+
+    public Point getBeginPoint() {
+        return beginPoint;
+    }
+
+    public void setBeginPoint(Point beginPoint) {
+        this.beginPoint = beginPoint;
+    }
+
+    public Point getEndPoint() {
+        return endPoint;
+    }
+
+    public void setEndPoint(Point endPoint) {
+        this.endPoint = endPoint;
+    }
+}

+ 26 - 2
src/main/java/index/entity/Box.java

@@ -4,10 +4,10 @@ import java.util.ArrayList;
 
 public class Box {
 
-    //网格的四个点,point里面并非真实物理坐标,用格子标号,比如(0,1),(1,0),(0,0),(1,1)
+    //网格的四个点,point里面并非真实物理坐标,用格子标号,比如(0,1),(1,0),(0,0),(1,1),new的时候要按照顺序
     ArrayList<Point> pointsList = new ArrayList<>();
 
-    //网格的标志点
+    //网格的标志点,选取左上角的那个点
     Point pointSymbol;
 
     //网格的四条边
@@ -39,4 +39,28 @@ public class Box {
     public void setBoxEdgeArrayList(ArrayList<BoxEdge> boxEdgeArrayList) {
         this.boxEdgeArrayList = boxEdgeArrayList;
     }
+
+    public void buildBoxEdgeArrayList(){
+
+        ArrayList<BoxEdge> boxEdgeArrayList = new ArrayList<>();
+
+        for (int i = 0 ; i < pointsList.size() - 1;i++){
+
+            Point pointI = pointsList.get(i);
+            Point pointJ = pointsList.get(i + 1);
+            BoxEdge boxEdge = new BoxEdge();
+            boxEdge.setPoint12(pointI,pointJ);
+            boxEdgeArrayList.add(boxEdge);
+
+        }
+
+        BoxEdge boxEdgeLast = new BoxEdge();
+        boxEdgeLast.setPoint12(pointsList.get(0),pointsList.get(pointsList.size() - 1));
+
+        boxEdgeArrayList.add(boxEdgeLast);
+
+        this.boxEdgeArrayList = boxEdgeArrayList;
+
+
+    }
 }

+ 19 - 0
src/main/java/index/entity/BoxEdge.java

@@ -52,4 +52,23 @@ public class BoxEdge {
 
     }
 
+    public Point getMiddlePoint(){
+
+        Double x1 = point1.getColX();
+        Double y1 = point1.getColY();
+
+        Double x2 = point2.getColX();
+        Double y2 = point2.getColY();
+
+        Double x3 = ( x1 + x2 ) / 2 ;
+        Double y3 = ( y1 + y2 ) / 2 ;
+
+        Point point = new Point();
+        point.setColX(x3);
+        point.setColY(y3);
+
+        return point;
+
+    }
+
 }

+ 25 - 0
src/main/java/index/entity/LineSegment.java

@@ -0,0 +1,25 @@
+package index.entity;
+
+import java.util.ArrayList;
+
+public class LineSegment {
+
+    ArrayList<Double> lineParamList;
+    BeginEndPoint beginEndPoint;
+
+    public ArrayList<Double> getLineParamList() {
+        return lineParamList;
+    }
+
+    public void setLineParamList(ArrayList<Double> lineParamList) {
+        this.lineParamList = lineParamList;
+    }
+
+    public BeginEndPoint getBeginEndPoint() {
+        return beginEndPoint;
+    }
+
+    public void setBeginEndPoint(BeginEndPoint beginEndPoint) {
+        this.beginEndPoint = beginEndPoint;
+    }
+}

+ 16 - 0
src/main/java/index/entity/OccupyIndex.java

@@ -0,0 +1,16 @@
+package index.entity;
+
+import java.util.ArrayList;
+
+public class OccupyIndex {
+
+    ArrayList<ArrayList<BeginEndIndex>> occupyIndexs;
+
+    public ArrayList<ArrayList<BeginEndIndex>> getOccupyIndexs() {
+        return occupyIndexs;
+    }
+
+    public void setOccupyIndexs(ArrayList<ArrayList<BeginEndIndex>> occupyIndexs) {
+        this.occupyIndexs = occupyIndexs;
+    }
+}

+ 16 - 0
src/main/java/index/entity/OccupyPoint.java

@@ -0,0 +1,16 @@
+package index.entity;
+
+import java.util.ArrayList;
+
+public class OccupyPoint {
+
+    ArrayList<ArrayList<BeginEndPoint>> occupyPoints;
+
+    public ArrayList<ArrayList<BeginEndPoint>> getOccupyPoints() {
+        return occupyPoints;
+    }
+
+    public void setOccupyPoints(ArrayList<ArrayList<BeginEndPoint>> occupyPoints) {
+        this.occupyPoints = occupyPoints;
+    }
+}

+ 14 - 0
src/main/java/index/entity/Point.java

@@ -6,6 +6,20 @@ public class Point {
 
     public Double colY;
 
+    public Point(Double colX,Double colY){
+
+        this.colX = colX;
+
+        this.colY = colY;
+
+
+    }
+
+    public Point(){
+
+
+    }
+
     public Double getColX() {
         return colX;
     }

+ 59 - 0
src/main/java/index/entity/WholeIndex.java

@@ -0,0 +1,59 @@
+package index.entity;
+
+public class WholeIndex {
+
+    Double minX;
+    Double minY;
+    Double xGap;
+    Double yGap;
+    Integer numOfGapsX;
+    Integer numOfGapsY;
+
+    public Double getMinX() {
+        return minX;
+    }
+
+    public void setMinX(Double minX) {
+        this.minX = minX;
+    }
+
+    public Double getMinY() {
+        return minY;
+    }
+
+    public void setMinY(Double minY) {
+        this.minY = minY;
+    }
+
+    public Double getxGap() {
+        return xGap;
+    }
+
+    public void setxGap(Double xGap) {
+        this.xGap = xGap;
+    }
+
+    public Double getyGap() {
+        return yGap;
+    }
+
+    public void setyGap(Double yGap) {
+        this.yGap = yGap;
+    }
+
+    public Integer getNumOfGapsX() {
+        return numOfGapsX;
+    }
+
+    public void setNumOfGapsX(Integer numOfGapsX) {
+        this.numOfGapsX = numOfGapsX;
+    }
+
+    public Integer getNumOfGapsY() {
+        return numOfGapsY;
+    }
+
+    public void setNumOfGapsY(Integer numOfGapsY) {
+        this.numOfGapsY = numOfGapsY;
+    }
+}