16s01 4 yıl önce
ebeveyn
işleme
d18a7d8b98

+ 10 - 31
src/CalculateArea.java

@@ -3,18 +3,27 @@ import java.io.PrintWriter;
 import java.util.ArrayList;
 
 public class CalculateArea {
+
     ArrayList<Double> Pointx_input = new ArrayList<>();
+
     ArrayList<Double> Pointy_input = new ArrayList<>();
 
     ArrayList<Double> Pointx_input_initial;
+
     ArrayList<Double> Pointy_input_initial;
 
     ArrayList<Double> Row_input = new ArrayList<>();
+
     ArrayList<Double> Theta_input = new ArrayList<>();
+
     ArrayList<Double> centerx_history;
+
     ArrayList<Double> centery_history;
+
     ArrayList<DataType<Double>> Result_Row = new ArrayList<>();
+
     ArrayList<DataType<Double>> Result_Theta = new ArrayList<>();
+
     double FinalCenterX;
     double FinalCenterY;
     double RusedforMeanShift;
@@ -23,7 +32,6 @@ public class CalculateArea {
     double IncreasingRate;
     double Area = 0.0 ;
 
-
     public CalculateArea(ArrayList<Double> Pointx_input,ArrayList<Double> Pointy_input,ArrayList<Double> centerx_history,ArrayList<Double> centery_history){
         this.Pointx_input_initial = Pointx_input;
         this.Pointy_input_initial = Pointy_input;
@@ -65,7 +73,7 @@ public class CalculateArea {
         double Max = 0 ;
         int IndexofMax = 0;
         for(int i = 0 ; i < centerx_history.size(); i++ ){
-            System.out.println("FindPointinsideR(centerx_history.get(i),centery_history.get(i),R): " + FindPointinsideR(centerx_history.get(i),centery_history.get(i),R));
+            System.out.println("findPointinsideR(centerx_history.get(i),centery_history.get(i),R): " + FindPointinsideR(centerx_history.get(i),centery_history.get(i),R));
             System.out.println("第 " + i + " 个历史圆");
             if(FindPointinsideR(centerx_history.get(i),centery_history.get(i),R) > Max){
                 Max = FindPointinsideR(centerx_history.get(i),centery_history.get(i),R);
@@ -101,7 +109,6 @@ public class CalculateArea {
 
     public void exchange(){
         for (int i = 0 ; i < Pointx_input_initial.size();i++ ){
-//            System.out.println("Pointx_input_initial "+Pointx_input_initial);
             Pointx_input.add(Pointx_input_initial.get(i) - FinalCenterX);
             Pointy_input.add(Pointy_input_initial.get(i) - FinalCenterY);
         }
@@ -132,10 +139,6 @@ public class CalculateArea {
         ArrayList<Double> AngleArrangeList = new ArrayList<>();
         java.io.File file4 = new java.io.File("C:\\Users\\87969\\Desktop\\test\\meanshiftAreaSectorR.txt");
         PrintWriter Result_OutPu2 = new PrintWriter(file4);
-//        System.out.println("Row_input " + Row_input);
-//        System.out.println("Theta_input" + Theta_input);
-//        System.out.println("Row_input_forcal" + Row_input_forcal);
-//        System.out.println("Theta_input_forcal" + Theta_input_forcal);
         for(int i = 0 ; i < 2 * Math.PI / SplitTheta ;i++){
             AngleArrangeList.add(SplitTheta * i);
         }
@@ -144,15 +147,7 @@ public class CalculateArea {
             System.out.println("第 " + i + " 次外部循环");
             ArrayList<Double> Row_input_temp = new ArrayList<>();
             ArrayList<Double> Theta_input_temp = new ArrayList<>();
-//            System.out.println("AngleArrangeList.get(i) " + AngleArrangeList.get(i));
-//            System.out.println("!!!!!!!!!!!!Theta_input_forcal.size() is  " + Theta_input_forcal.size());
             for(int j = 0 ; j < Theta_input_forcal.size() ; j++){
-//                System.out.println("第 " + i + " 次外部循环");
-//                System.out.println("第 " + j + " 次内部筛选点循环");
-//                System.out.println("Theta_input_forcal.get(j) is : " + Theta_input_forcal.get(j));
-//                System.out.println("AngleArrangeList.get(i) is : " + AngleArrangeList.get(i));
-//                System.out.println("(AngleArrangeList.get(i) + SplitTheta ) is : " + (AngleArrangeList.get(i) + SplitTheta));
-//                System.out.println((Theta_input_forcal.get(j) > AngleArrangeList.get(i)) && Theta_input_forcal.get(j) < (AngleArrangeList.get(i) + SplitTheta ));
                 if((Theta_input_forcal.get(j) > AngleArrangeList.get(i)) && Theta_input_forcal.get(j) < (AngleArrangeList.get(i) + SplitTheta )){
                     System.out.println("第 " + i + " 次外部循环,第 " + j + " 次内部循环");
                     Row_input_temp.add(Row_input_forcal.get(j));
@@ -160,18 +155,13 @@ public class CalculateArea {
                 }
             }
             int AllNumberofPointsinthisSector = Row_input_temp.size();
-//            System.out.println("第 " + i + " 次外部循环");
-//            System.out.println("**********Row_input_temp" + Row_input_temp);
-//            System.out.println("Theta_input_temp" + Theta_input_temp);
             double temp_radius = SplitRadiusWidth;
             ArrayList<Integer> insideRowNumber_history = new ArrayList<>();//在扇形内的点的编号
             ArrayList<Integer> insideRowNumberlength = new ArrayList<>();//记录上一个半径下,扇形区域内点的个数
             int insideRowNumberlength_history = 1;
             while (true){
-//                System.out.println("&&&&&&&&&&&&&&&& " + insideRowNumList(temp_radius,Row_input_temp).size());
                 insideRowNumberlength.add(insideRowNumList(temp_radius,Row_input_temp).size());//
                 int temp_size = insideRowNumberlength.size();
-//                if(insideRowNumberlength.get(temp_size - 1) / insideRowNumberlength.get(temp_size - 2 ) < IncreasingRate){
                 if(((insideRowNumberlength.get(temp_size - 1) /insideRowNumberlength_history)  < IncreasingRate) && ((insideRowNumberlength.get(temp_size - 1)) < 0.8 * temp_size)){
                     break;
                 }
@@ -184,21 +174,16 @@ public class CalculateArea {
                     for (int ij = 0 ; ij < insideRowNumberList_temp.size();ij++){
                         insideRowNumber_history.add(insideRowNumberList_temp.get(ij));
                     }
-//                    insideRowNumber_history = insideRowNumList(temp_radius,Row_input_temp);
-//                    insideRowNumber_history = insideRowNumList(temp_radius,Row_input_temp);
                     temp_radius = temp_radius + SplitRadiusWidth;
                     insideRowNumberlength_history = insideRowNumberlength.get(temp_size - 1);
                 }
             }
             ArrayList<Double> Result_Row_temp = new ArrayList<>();
             ArrayList<Double> Result_Theta_temp = new ArrayList<>();
-//            System.out.println("insideRowNumber_history.size() " + insideRowNumber_history.size());
             for(int ii = 0 ; ii < insideRowNumber_history.size() ; ii++){
-//                System.out.println("Row_input_temp.get(insideRowNumber_history.get(ii)) " + Row_input_temp.get(insideRowNumber_history.get(ii)) );
                 Result_Row_temp.add(Row_input_temp.get(insideRowNumber_history.get(ii)));
                 Result_Theta_temp.add(Theta_input_temp.get(insideRowNumber_history.get(ii)));
             }
-//            System.out.println("Result_Row_temp: " + Result_Row_temp);
             DataType<Double> Row_data = new DataType<>(Result_Row_temp);
             DataType<Double> Theta_data = new DataType<>(Result_Theta_temp);
             Result_Row.add(Row_data);
@@ -209,7 +194,6 @@ public class CalculateArea {
         System.out.println("最终面积为: " + Area);
         Result_OutPu2.close();
         java.io.File file3 = new java.io.File("C:\\Users\\87969\\Desktop\\test\\meanshiftAreaRowandTheta.txt");
-//        java.io.File file3 = new java.io.File("C:\\Users\\87969\\Desktop\\test\\meanshiftAreaSectorR.txt");
         PrintWriter Result_OutPut = new PrintWriter(file3);
 
 
@@ -218,20 +202,15 @@ public class CalculateArea {
             Result_OutPut.println("第" + iii + "个扇形的thetalist " + Result_Theta.get(iii).Data);
         }
         Result_OutPut.close();
-//        System.out.println("Result_Row: " + Result_Row);
-//        System.out.println("Result_Theta: " + Result_Theta);
     }
 
     public ArrayList<Integer> insideRowNumList(double Radius,ArrayList<Double>Row_input_temp){
         ArrayList<Integer> insideRowNumber = new ArrayList<>();
-//        System.out.println("555555555555555555 " + Row_input_temp);
-//        System.out.println("666666666666666666 " + Radius);
         for(int i = 0 ; i < Row_input_temp.size() ; i++){
             if( Row_input_temp.get(i) < Radius ){
                 insideRowNumber.add(i);
             }
         }
-//        System.out.println("1111111@@@@@@@@@@@@@@@@@@@@@@@@@@ " + insideRowNumber);
         return insideRowNumber;
     }
 }

+ 138 - 114
src/MeanShift.java

@@ -3,66 +3,76 @@ import java.io.PrintWriter;
 import java.util.ArrayList;
 
 public class MeanShift {
-    public ArrayList<Double> pointx;
-    public ArrayList<Double> pointy;
+    public ArrayList<Double> pointx;//所有点的x坐标集
+    public ArrayList<Double> pointy;//所有点的y坐标集
     public double R;
     ArrayList<Double> centerx_history_forArea = new ArrayList<>();
     ArrayList<Double> centery_history_forArea = new ArrayList<>();
     ArrayList<ResultDataType> result = new ArrayList<>();
-    public void setPointxAndPonty(ArrayList<Double> pointx_input,ArrayList<Double> pointy_input){
+    public void setPointxAndPointy(ArrayList<Double> pointx_input, ArrayList<Double> pointy_input){
         this.pointx = pointx_input;
         this.pointy = pointy_input;
     }
-    public void setR(double R_input){
-        this.R = R_input;
+    public void setR(double rinput){
+        this.R = rinput;
     }
 
-    public ArrayList<Integer> DL(ArrayList<Integer> NumList){
-        for(int i = 0;i < NumList.size();i++){
-            int temp_index = (int)(Math.random()*(NumList.size() - i)) + i;
-            int temp = NumList.get(i);
-            NumList.set(i,NumList.get(temp_index));
-            NumList.set(temp_index,temp);
+
+    //洗牌算法,打乱ArrayList
+    public ArrayList<Integer> shuffle(ArrayList<Integer> list){
+        for(int i = 0;i < list.size();i++){
+            int temp_index = (int)(Math.random()*(list.size() - i)) + i;
+            int temp = list.get(i);
+            list.set(i,list.get(temp_index));
+            list.set(temp_index,temp);
         }
-        return NumList;
+        return list;
     }
 
-    public Integer PickUpAPointNum(ArrayList<Integer> NumListLeft){
-        NumListLeft = DL(NumListLeft);
-        return NumListLeft.get(0);
+
+    //从一个元素为整数的ArrayList里随机挑选一个元素
+    public Integer pickUpAPointNum(ArrayList<Integer> numListLeft){
+        numListLeft = shuffle(numListLeft);
+        return numListLeft.get(0);
     }
 
-    public ArrayList<Integer> FindPointinsideR(double centerx,double centery){
+
+    //记录下点集里,距离圆心(centerX,centerY)的距离小于R的所有点的index
+    public ArrayList<Integer> findPointinsideR(double centerX, double centerY){
         ArrayList<Integer> NuminsideR = new ArrayList<>();
         for(int i = 0 ; i < pointx.size() ; i++){
-            if (CalculateDistance(pointx.get(i),pointy.get(i),centerx,centery) < R){
+            if (calculateDistance(pointx.get(i),pointy.get(i),centerX,centerY) < R){
                 NuminsideR.add(i);
             }
         }
         return NuminsideR;
     }
 
-    public double CalculateDistance(Double x1,Double y1, Double x2 ,Double y2){
+    //计算两点之间的距离
+    public double calculateDistance(Double x1, Double y1, Double x2 , Double y2){
         return Math.sqrt(Math.pow((x1-x2),2) + Math.pow((y1-y2),2));
     }
 
-    public double[] CalculateMh(ArrayList<Integer> NuminsideR,double centerx,double centery){
-        double Sumx = 0.;
-        double Sumy = 0.;
-        double[] mh = new double[2];
-        for(int i = 0 ; i < NuminsideR.size();i++){
-            Sumx = Sumx + pointx.get(NuminsideR.get(i)) - centerx;
-            Sumy = Sumy + pointy.get(NuminsideR.get(i)) - centery;
+
+    //计算平均向量
+    public double[] calculateMeanVector(ArrayList<Integer> indexOfPointInsideR, double centerX, double centerY){
+        double sumX = 0.;
+        double sumY = 0.;
+        double[] meanVector = new double[2];
+        for(int i = 0 ; i < indexOfPointInsideR.size();i++){
+            sumX = sumX + pointx.get(indexOfPointInsideR.get(i)) - centerX;
+            sumY = sumY + pointy.get(indexOfPointInsideR.get(i)) - centerY;
         }
 
-        mh[0] = Sumx/NuminsideR.size();
-        mh[1] = Sumy/NuminsideR.size();
-        return mh;
+        meanVector[0] = sumX/indexOfPointInsideR.size();
+        meanVector[1] = sumY/indexOfPointInsideR.size();
+        return meanVector;
     }
 
+    //比较圆心分别为(x1,y1)和(x2,y2)的两个圆,哪个圆内的点的数量更多。
     public boolean judgeDensity(double x1,double y1,double x2,double y2){
-        int N_old = FindPointinsideR(x1,y1).size();
-        int N_new = FindPointinsideR(x2,y2).size();
+        int N_old = findPointinsideR(x1,y1).size();
+        int N_new = findPointinsideR(x2,y2).size();
         if (N_old >= N_new){
             return true;
         }
@@ -70,143 +80,157 @@ public class MeanShift {
             return false;
         }
     }
-    public ArrayList<ResultDataType> MainLoop() throws FileNotFoundException {
-        ArrayList<Integer> numlist = new ArrayList<>();
-        ArrayList<Integer> numlist_used = new ArrayList<>();
-        ArrayList<Integer> numlist_class = new ArrayList<>();
-        ArrayList<Integer> numlist_unused = new ArrayList<>();
-        ArrayList<Integer> numlist_center = new ArrayList<>();
-        ArrayList<Double> centerx_history = new ArrayList<>();
-        ArrayList<Double> centery_history = new ArrayList<>();
-        for (int i = 0; i < pointx.size() ; i++){
-            numlist.add(i);
+
+    //
+    public ArrayList<ResultDataType> mainLoop() throws FileNotFoundException {
+        ArrayList<Integer> numList = new ArrayList<>();
+        ArrayList<Integer> numListUsed = new ArrayList<>();
+        ArrayList<Integer> numListClass = new ArrayList<>();
+        ArrayList<Integer> numListUnused = new ArrayList<>();
+        ArrayList<Integer> numListCenter = new ArrayList<>();
+        ArrayList<Double> centerXHistory = new ArrayList<>();
+        ArrayList<Double> centerYHistory = new ArrayList<>();
+
+        for (int i = 0; i < pointx.size() ; i++){//把所有点的index存入numList
+            numList.add(i);
         }
-        numlist_unused = numlist;
-        int count_for_outside_loop = 0;
-        while (!numlist_unused.isEmpty()){
-            count_for_outside_loop = count_for_outside_loop + 1;
-            int num = PickUpAPointNum(numlist_unused);
-            ArrayList<Integer> NuminsideR = new ArrayList<>();
-            double centerx = pointx.get(num);
-            double centery = pointy.get(num);
-            int inital_num = num;
-            System.out.println("the NO. " + count_for_outside_loop + " outside loop and num picked is " + inital_num);
-            double inital_centerx = centerx;
-            double inital_centery = centery;
-            double centerx_next_test ;
-            double centery_next_test ;
-            int count_for_inside_loop = 0;
+
+        numListUnused = numList;//初始所有的点都是没有被当做圆心的
+        int counterForOutsideLoop = 0;//外循环计数器
+
+        while (!numListUnused.isEmpty()){
+            counterForOutsideLoop = counterForOutsideLoop + 1;
+            int num = pickUpAPointNum(numListUnused);//从还没被选中过作为圆心的点中随机挑选一个,
+            ArrayList<Integer> indexOfPointsInsideR = new ArrayList<>();//在圆内的点的序号
+            double centerX = pointx.get(num);
+            double centerY = pointy.get(num);
+            int inital_num = num;//圆心的点的序号
+            System.out.println("the NO. " + counterForOutsideLoop + " outside loop and num picked is " + inital_num);
+            double inital_centerx = centerX;
+            double inital_centery = centerY;
+            double centerXNextTest ;//下一个圆心的横坐标
+            double centerYNextTest ;//下一个圆心的纵坐标
+            int counterForInsideLoop = 0;//内循环计数器
             while(true){
-                count_for_inside_loop = count_for_inside_loop + 1;
-                NuminsideR = FindPointinsideR(centerx,centery);
-                double[] mh = CalculateMh(NuminsideR,centerx,centery);
-                centerx_next_test = centerx + mh[0];
-                centery_next_test = centery + mh[1];
-                if(!judgeDensity(centerx,centery,centerx_next_test,centery_next_test)){
-                    System.out.println("第 " + count_for_outside_loop + " 次外循环的第 " + count_for_inside_loop + " 次漂移");
-                    System.out.println("当前圆心为" + centerx + " " + centery);
-                    System.out.println("当前圆内点个数为:" + NuminsideR.size());
-                    centerx = centerx_next_test;
-                    centery = centery_next_test;
+                counterForInsideLoop = counterForInsideLoop + 1;
+                indexOfPointsInsideR = findPointinsideR(centerX,centerY);//圆心为(centerX,centerY)的圆内的所有点的序号
+                double[] meanVector = calculateMeanVector(indexOfPointsInsideR,centerX,centerY);//偏移向量
+                centerXNextTest = centerX + meanVector[0];//下一个圆心的横坐标
+                centerYNextTest = centerY + meanVector[1];//下一个圆心的纵坐标
+                if(!judgeDensity(centerX,centerY,centerXNextTest,centerYNextTest)){//只有当下一个圆内的点更多才会触发偏移
+                    System.out.println("第 " + counterForOutsideLoop + " 次外循环的第 " + counterForInsideLoop + " 次漂移");
+                    System.out.println("当前圆心为" + centerX + " " + centerY);
+                    System.out.println("当前圆内点个数为:" + indexOfPointsInsideR.size());
+                    centerX = centerXNextTest;//
+                    centerY = centerYNextTest;//
                 }
                 else{
-                    System.out.println("第 " + count_for_outside_loop + " 次外循环,漂移结束。");
+                    System.out.println("第 " + counterForOutsideLoop + " 次外循环,漂移结束。");
                     break;
                 }
             }
             int max = 0;
             int compare_density_count=0;
             ArrayList<Integer> count_num_cd = new ArrayList<>();
-            for(int i = 0 ; i < centerx_history.size();i++){
-                if(CalculateDistance(centerx,centery,centerx_history.get(i),centery_history.get(i)) < 2*R){
-                    count_num_cd.add(i);
+            for(int i = 0 ; i < centerXHistory.size();i++){
+                if(calculateDistance(centerX,centerY,centerXHistory.get(i),centerYHistory.get(i)) < 2*R){//
+                    count_num_cd.add(i);//所有与当前圆发生重叠的历史圆
                 }
                 else {
                     max += 1;
                 }
             }
-            if(max == centerx_history.size()){
-                System.out.println("第 " + count_for_outside_loop + " 次外循环。该循环的圆心和历史收敛圆心距离大于2R。");
-                centerx_history.add(centerx);
-                centery_history.add(centery);
-                numlist_center.add(num);
-                numlist_class.addAll(NuminsideR);
-                ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numlist_used);
-                ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numlist_unused);
-                ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numlist_class);
-                ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numlist_center);
-                ArrayList<Integer> numlist_forcal = new ArrayList<>(numlist);
+            if(max == centerXHistory.size()){//所有历史圆心与该圆心的距离大于2R,该圆心直接被收集到centerX,YHistory中
+                System.out.println("第 " + counterForOutsideLoop + " 次外循环。该循环的圆心和历史收敛圆心距离大于2R。");
+                centerXHistory.add(centerX);
+                centerYHistory.add(centerY);
+                numListCenter.add(num);
+                numListClass.addAll(indexOfPointsInsideR);
+                ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numListUsed);
+                ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numListUnused);
+                ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numListClass);//
+                ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numListCenter);
+                ArrayList<Integer> numlist_forcal = new ArrayList<>(numList);
                 numlist_class_forcal.removeAll(numlist_center_forcal);
+
                 numlist_center_forcal.addAll(numlist_center_forcal);
                 numlist_used_forcal = numlist_center_forcal;
                 numlist_forcal.removeAll(numlist_used_forcal);
                 numlist_unused_forcal = numlist_forcal;
-                numlist_unused = numlist_unused_forcal;
+                numListUnused = numlist_unused_forcal;
             }
-            else{
+            else{//发生重叠
                 ArrayList<Integer> cd_NuminsideR = new ArrayList<>();
-                System.out.println("第 " + count_for_outside_loop + " 次外循环。当前收敛的圆和历史部分圆重叠。");
+                System.out.println("第 " + counterForOutsideLoop + " 次外循环。当前收敛的圆和历史部分圆重叠。");
                 System.out.println("重叠了 " + count_num_cd.size() + " 个");
 
                 for (int i = 0 ; i < count_num_cd.size(); i++){
-                    int length = FindPointinsideR(centerx_history.get(count_num_cd.get(i)),centery_history.get(count_num_cd.get(i))).size();
-                    cd_NuminsideR.add(length);
+                    int length = findPointinsideR(centerXHistory.get(count_num_cd.get(i)),centerYHistory.get(count_num_cd.get(i))).size();
+                    cd_NuminsideR.add(length);//和当前漂移后的圆发生重叠的历史圆的包含点数
                 }
                 int temp_for_count_num_cd = count_num_cd.size();
                 ArrayList<Double> centerx_history_to_disappear = new ArrayList<>();
                 ArrayList<Double> centery_history_to_disappear = new ArrayList<>();
                 for(int i = 0 ; i < temp_for_count_num_cd ; i++){
-                    if(NuminsideR.size() > cd_NuminsideR.get(i)){
+                    if(indexOfPointsInsideR.size() > cd_NuminsideR.get(i)){
                         compare_density_count = compare_density_count + 1;
-                        ArrayList<Integer>  the_circle_disappear= FindPointinsideR(centerx_history.get(count_num_cd.get(i)),centery_history.get(count_num_cd.get(i)));
-                        centerx_history_to_disappear.add(centerx_history.get(count_num_cd.get(i)));
-                        centery_history_to_disappear.add(centery_history.get(count_num_cd.get(i)));
-                        numlist_class.removeAll((ArrayList<Integer>)the_circle_disappear);
+                        ArrayList<Integer>  the_circle_disappear= findPointinsideR(centerXHistory.get(count_num_cd.get(i)),centerYHistory.get(count_num_cd.get(i)));
+                        centerx_history_to_disappear.add(centerXHistory.get(count_num_cd.get(i)));
+                        centery_history_to_disappear.add(centerYHistory.get(count_num_cd.get(i)));
+                        numListClass.removeAll((ArrayList<Integer>)the_circle_disappear);
                     }
                 }
                 for(int i = 0 ; i < centerx_history_to_disappear.size(); i++){
-                    centerx_history.remove(centerx_history_to_disappear.get(i));
-                    centery_history.remove(centery_history_to_disappear.get(i));
+                    centerXHistory.remove(centerx_history_to_disappear.get(i));
+                    centerYHistory.remove(centery_history_to_disappear.get(i));
                 }
                 if(compare_density_count == cd_NuminsideR.size()){
                     System.out.println("当前收敛圆比和它重叠的历史收敛的圆密度都大");
-                    centerx_history.add(centerx);
-                    centery_history.add(centery);
-                    numlist_center.add(num);
-                    numlist_class.addAll(NuminsideR);
-                    ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numlist_used);
-                    ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numlist_unused);
-                    ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numlist_class);
-                    ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numlist_center);
-                    ArrayList<Integer> numlist_forcal = new ArrayList<>(numlist);
+                    centerXHistory.add(centerX);
+                    centerYHistory.add(centerY);
+
+
+                    numListCenter.add(num);
+                    numListClass.addAll(indexOfPointsInsideR);
+                    ArrayList<Integer> numlist_used_forcal = new ArrayList<>(numListUsed);
+                    ArrayList<Integer> numlist_unused_forcal = new ArrayList<>(numListUnused);
+
+                    //forcal是为了在不影响原有的arraylist前提下,用原有的arraylist参与计算
+                    ArrayList<Integer> numlist_class_forcal = new ArrayList<>(numListClass);
+                    ArrayList<Integer> numlist_center_forcal = new ArrayList<>(numListCenter);
+                    ArrayList<Integer> numlist_forcal = new ArrayList<>(numList);
                     numlist_class_forcal.removeAll(numlist_center_forcal);
-                    numlist_center_forcal.addAll(numlist_center_forcal);
+
+//                    numlist_center_forcal.addAll(numlist_center_forcal);
+                    numlist_center_forcal.addAll(numlist_class_forcal);
                     numlist_used_forcal = numlist_center_forcal;
                     numlist_forcal.removeAll(numlist_used_forcal);
                     numlist_unused_forcal = numlist_forcal;
-                    numlist_unused = numlist_unused_forcal;
+                    numListUnused = numlist_unused_forcal;//所有未使用过的点,既包含圆心也包含被圆心所代表的圆围住的点
                 }
+            ///当前收敛圆和部分历史圆重叠
             }
-            numlist_unused.remove((Integer)inital_num);
+            numListUnused.remove((Integer)inital_num);//外循环是从未使用过的点里随机挑一个出来的,这个点也必须从未使用的点序号列表里清除。
         }
-        for(int i = 0 ; i < centerx_history.size();i++){
-            ArrayList<Integer> out_NuminsideR = FindPointinsideR(centerx_history.get(i),centery_history.get(i));
+        ///////
+        for(int i = 0 ; i < centerXHistory.size();i++){
+            ArrayList<Integer> out_NuminsideR = findPointinsideR(centerXHistory.get(i),centerYHistory.get(i));
             result.add(new ResultDataType(out_NuminsideR));
         }
-        for (int i = 0 ; i < centerx_history.size() - 1; i++){
-            for (int j = i+1 ; j < centerx_history.size(); j++){
-                double temp =CalculateDistance(centerx_history.get(i),centery_history.get(i),centerx_history.get(j),centery_history.get(j));
+        for (int i = 0 ; i < centerXHistory.size() - 1; i++){
+            for (int j = i+1 ; j < centerXHistory.size(); j++){
+                double temp = calculateDistance(centerXHistory.get(i),centerYHistory.get(i),centerXHistory.get(j),centerYHistory.get(j));
                 System.out.println("ths distance is  " + temp);
             }
         }
 
         java.io.File file3 = new java.io.File("C:\\Users\\87969\\Desktop\\test\\meanshiftLastcircle.txt");
         PrintWriter TestData_OutPut = new PrintWriter(file3);
-        for(int i = 0; i < centerx_history.size();i++){
-            TestData_OutPut.println(centerx_history.get(i) + " " + centery_history.get(i));
+        for(int i = 0; i < centerXHistory.size();i++){
+            TestData_OutPut.println(centerXHistory.get(i) + " " + centerYHistory.get(i));
         }
-        centerx_history_forArea = centerx_history;
-        centery_history_forArea = centery_history;
+        centerx_history_forArea = centerXHistory;
+        centery_history_forArea = centerYHistory;
         TestData_OutPut.close();
         return result;
     }

+ 0 - 2
src/ReadData.java

@@ -12,8 +12,6 @@ public class ReadData {
             pointx_input.add(input.nextDouble());
             pointy_input.add(input.nextDouble());
         }
-//        System.out.println("///pointx_input is " + pointx_input);
-//        System.out.println("///pointx_input's length is " + pointx_input.size());
         input.close();
     }
 }

+ 2 - 10
src/TestMeanShift.java

@@ -14,17 +14,14 @@ public class TestMeanShift {
         ReadData readData = new ReadData();
         readData.Read();
         MeanShift meanShift = new MeanShift();
-        meanShift.setPointxAndPonty(readData.pointx_input,readData.pointy_input);
+        meanShift.setPointxAndPointy(readData.pointx_input,readData.pointy_input);
         meanShift.setR(RusedforMeanshift);
         ArrayList<ResultDataType> result ;
-        result = meanShift.MainLoop();
-//        System.out.println("///result is " + result);
+        result = meanShift.mainLoop();
         for(int i = 0 ; i < result.size();i++){
             Result_OutPut.println(result.get(i).numOfPoint);
         }
         Result_OutPut.close();
-
-
         pointx_input = readData.pointx_input;
         pointy_input = readData.pointy_input;
         centerx_history_forArea = meanShift.centerx_history_forArea;
@@ -34,14 +31,9 @@ public class TestMeanShift {
         calculateArea.setSplitTheta(Math.PI / 180);
         calculateArea.setSplitRadiusWidth(0.3 * RusedforMeanshift);
         calculateArea.setIncreasingRate(1.005);
-
-
         calculateArea.configFinalCircle();
         calculateArea.exchange();
         calculateArea.DktoPolar();
         calculateArea.LoopforCalculateArea();
-
-
     }
-
 }

+ 40 - 0
src/test/ConnectToSourceDB.java

@@ -0,0 +1,40 @@
+package test;
+
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class ConnectToSourceDB {
+    String userName;
+    String passwd;
+    String driver;
+    String url;//uat
+
+    Connection connection = null;
+
+
+    public void setConnPara(String userName,String passwd,String driver, String url){
+        this.userName = userName;
+        this.passwd = passwd;
+        this.driver = driver;
+        this.url = url;
+    }
+
+
+    public Connection getConnection() {
+
+        try {
+            Class.forName(driver);
+            connection = (Connection) DriverManager.getConnection(url, userName, passwd);
+        }catch(ClassNotFoundException e){
+            throw new RuntimeException("class not find!",e);
+        }catch (SQLException e){
+            throw new RuntimeException("get connection error",e);
+        }
+        return connection;
+    }
+
+
+
+}

+ 31 - 0
src/test/DbOperate.java

@@ -0,0 +1,31 @@
+package test;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class DbOperate {
+
+//    public Connection getConnection(){
+//
+//    }
+
+    public ResultSet runQuerySql(Connection connection, String sql) throws SQLException {
+        Statement statement = connection.createStatement();
+        ResultSet resultSet = statement.executeQuery(sql);
+        return resultSet;
+    }
+
+    public void runInsertSql(Connection connection,String sql) throws SQLException {
+        Statement statement = connection.createStatement();
+        statement.executeLargeUpdate(sql);
+    }
+
+    public ResultSet runQuerySqlByStatement(Statement statement, String sql) throws SQLException {
+//        Statement statement = connection.createStatement();
+        ResultSet resultSet = statement.executeQuery(sql);
+        return resultSet;
+    }
+
+}

+ 34 - 0
src/test/GetPoints.java

@@ -0,0 +1,34 @@
+package test;
+
+
+import test.entity.Point;
+
+import java.sql.Connection;
+import java.util.ArrayList;
+
+//暂时先自己写connection从数据库中获取
+
+public class GetPoints {
+
+    public ArrayList<Point> returnPoints(){
+
+        ArrayList<Point> pointList = new ArrayList<>();
+
+        return pointList;
+
+    }
+
+    public void getPoints(){
+
+        String userName = "nps_tc01";
+        String password = "nps_tc01";
+        String driver = "oracle.jdbc.driver.OracleDriver";
+        String url = "jdbc:oracle:thin:@jsdinghehui.com:10521:ORCL";
+
+        ConnectToSourceDB connectToSourceDB = new ConnectToSourceDB();
+        connectToSourceDB.setConnPara(userName,password,driver,url);
+//        Connection
+
+    }
+
+}

+ 314 - 0
src/test/Split.java

@@ -0,0 +1,314 @@
+package test;
+
+import test.entity.Index;
+import test.entity.OccupyPerX;
+import test.entity.Point;
+import test.entity.WholeIndexOccupy;
+
+import java.util.ArrayList;
+
+public class Split {
+
+    ArrayList<Double> xIndexCorList = new ArrayList<>();//格点横坐标List
+    ArrayList<Double> yIndexCorList = new ArrayList<>();//格点纵坐标List
+
+    public int numOfGaps = 100;
+
+    Tool tool = new Tool();
+
+    WholeIndexOccupy wholeIndexOccupy = new WholeIndexOccupy(numOfGaps);//初始网格占用情况
+
+    public double xGap;
+
+    public double yGap;
+
+
+    //输入垛位的初始实际形状,形成网格
+    public void cal(ArrayList<Point> pointsList){
+
+        double minX = 0.;
+
+        double minY = 0.;
+
+        double maxX = 0.;
+
+        double maxY = 0.;
+
+        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;
+
+            }
+
+        }
+
+
+        Point pointA = new Point();
+        Point pointB = new Point();
+        Point pointC = new Point();
+        Point pointD = new Point();
+
+        pointA.setColX(minX);
+        pointA.setColY(minY);
+
+        pointB.setColX(minX);
+        pointB.setColX(maxY);
+
+        pointC.setColX(maxX);
+        pointC.setColY(maxY);
+
+        pointD.setColX(maxX);
+        pointD.setColY(minY);
+
+        ArrayList<Point> rectanglePoints = new ArrayList<>();
+        rectanglePoints.add(pointA);
+        rectanglePoints.add(pointB);
+        rectanglePoints.add(pointC);
+        rectanglePoints.add(pointD);
+
+
+        decideIndex(rectanglePoints);
+        getLines(pointsList);
+
+
+    }
+
+    public void decideIndex(ArrayList<Point> fourPointsList){
+
+        Point pointA = fourPointsList.get(0);
+        Point pointB = fourPointsList.get(1);
+        Point pointC = fourPointsList.get(2);
+        Point pointD = fourPointsList.get(3);
+
+        double distanceAB = calculateDistance(pointA,pointB);//纵向间距
+        double distanceBC = calculateDistance(pointB,pointC);//横向间距
+
+        double minX = pointA.getColX();
+        double minY = pointA.getColY();
+        double maxX = pointC.getColX();
+        double maxY = pointC.getColY();
+
+        xGap = distanceAB / numOfGaps;
+        yGap = distanceBC / numOfGaps;
+
+//        ArrayList<Double> xIndexCorList = new ArrayList<>();//格点横坐标List
+//        ArrayList<Double> yIndexCorList = new ArrayList<>();//格点纵坐标List
+
+        for (int i = 0 ; i < numOfGaps + 1; i++){
+
+            xIndexCorList.add(minX);
+            minX = minX + xGap;
+            yIndexCorList.add(minY);
+            minY = minY + yGap;
+        }
+
+    }
+
+    public double  calculateDistance(Point point1,Point point2){
+
+        double corX1 = point1.getColX();
+        double corY1 = point1.getColY();
+        double corX2 = point2.getColX();
+        double corY2 = point2.getColY();
+        double distance = Math.sqrt(Math.pow((corX1 - corX2),2) + Math.pow((corY1 - corY2),2));
+        return distance;
+
+    }
+
+
+    //根据实际形状的各个点形成直线
+    public void getLines(ArrayList<Point> pointsList){
+
+
+
+        for (int i = 0 ; i< pointsList.size() - 1;i++){
+
+            Point pointI = pointsList.get(i);
+            Point pointJ = pointsList.get(i + 1);
+
+            //直线一般式相关的参数,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);
+            lineOccupy(pointI,pointJ,lineParamList);
+
+
+
+        }
+
+
+
+    }
+
+    //计算直线在各个网格内的占据情况
+    public void lineOccupy(Point pointI,Point pointJ,ArrayList<Double> lineParamList){
+
+        Double xMin = xIndexCorList.get(0);
+        Double yMin = yIndexCorList.get(0);
+
+
+        //该直线起始点的网格位置
+        Index indexI = identifyIndex(pointI);
+        Index indexJ = identifyIndex(pointJ);
+
+        //
+        Integer xIndexBegin = indexI.getxIndex();//网格横向起始编号
+        Integer yIndexBegin = indexI.getxIndex();//网格纵向起始编号
+
+        Integer xIndexEnd = indexJ.getxIndex();//网格横向终止编号
+        Integer yIndexEnd = indexJ.getxIndex();//网格纵向终止编号
+
+
+
+        for (int i = xIndexBegin;i < xIndexEnd + 1; i++){
+
+            Integer minYIndex;
+            Integer maxYIndex;
+
+            Double xInputBegin;
+            Double xInputEnd;
+
+            Double yOutBegin;
+            Double yOutEnd;
+
+
+            xInputBegin = xMin + xGap * i;//当前网格的起始横坐标
+            xInputEnd = xInputBegin + xGap;//当前网格的终止横坐标
+
+
+            yOutBegin = tool.getLineYValue(xInputBegin,lineParamList);//当前网格的起始纵坐标
+            yOutEnd = tool.getLineYValue(xInputEnd,lineParamList);//当前网格的终止纵坐标
+
+//            Double yBeginIndexTemp = (yOutBegin - yMin)/yGap;
+//            Integer yBeginIndex = yBeginIndexTemp.intValue();
+
+
+            Integer yBeginIndex = identifyYIndex(yOutBegin);
+            Integer yEndIndex = identifyYIndex(yOutEnd);
+            Integer yIndexMax;
+            Integer yIndexMin;
+
+
+            if (yBeginIndex > yEndIndex){
+
+                yIndexMin = yEndIndex;
+                yIndexMax = yBeginIndex;
+
+            }
+            else {
+
+                yIndexMax = yEndIndex;
+                yIndexMin = yBeginIndex;
+
+            }
+            OccupyPerX occupyPerX =  new OccupyPerX();
+            occupyPerX.setMaxYIndex(yIndexMax);
+            occupyPerX.setMinYIndex(yIndexMin);
+            wholeIndexOccupy.setOccupyPerXArrayList(occupyPerX,i);
+        }
+    }
+
+    //输入x,得到y值
+
+
+
+    public Index identifyIndex(Point point){
+
+        Double pointX = point.getColX();
+        Double pointY = point.getColY();
+
+        //网格的起始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;
+
+        Integer xIndex = xIndexTemp.intValue();
+        Integer yIndex = yIndexTemp.intValue();
+
+        Index index = new Index();
+        index.setxIndex(xIndex);
+        index.setyIndex(yIndex);
+
+        return index;
+
+    }
+
+    public  Integer identifyYIndex(Double yCor){
+
+
+//        Double xMin = xIndexCorList.get(0);
+        Double yMin = yIndexCorList.get(0);
+        Double yIndexTemp = (yCor - yMin)/yGap;
+        Integer yIndex = yIndexTemp.intValue();
+        return yIndex;
+
+
+    }
+
+    public  Integer identifyXIndex(Double xCor){
+
+
+//        Double xMin = xIndexCorList.get(0);
+        Double xMin = xIndexCorList.get(0);
+        Double xIndexTemp = (xCor - xMin)/xGap;
+        Integer xIndex = xIndexTemp.intValue();
+        return xIndex;
+
+
+    }
+
+
+
+
+
+
+
+
+
+
+
+}

+ 56 - 0
src/test/Tool.java

@@ -0,0 +1,56 @@
+package test;
+
+import test.entity.Point;
+
+import java.util.ArrayList;
+
+public class Tool {
+
+
+    public ArrayList<Double> calLineabc(Point point1, Point point2){
+
+        Double x1 = point1.getColX();
+        Double y1 = point1.getColY();
+        Double x2 = point2.getColX();
+        Double y2 = point2.getColY();
+
+
+        Double lineA = (y1 - y2) / (x1 - x2);
+        Double lineB = -1.0;
+        Double lineC = y1 - lineA * x2;
+
+        ArrayList<Double> lineParamList = new ArrayList<>();
+
+        lineParamList.add(lineA);
+        lineParamList.add(lineB);
+        lineParamList.add(lineC);
+
+        return  lineParamList;
+    }
+
+    public Double distanceFromPointToLine(ArrayList<Double> lineParamList,Point point){
+
+        Double x = point.getColX();
+        Double y = point.getColY();
+
+        Double lineA = lineParamList.get(0);
+        Double lineB = lineParamList.get(1);
+        Double lineC = lineParamList.get(2);
+
+
+        Double value1 = lineA * x + lineB * y + lineC;
+        Double value2 = Math.sqrt(Math.pow(lineA,2) + Math.pow(lineB,2));
+        Double dis = Math.abs(value1 / value2);
+
+        return dis;
+    }
+
+    public Double getLineYValue(Double x,ArrayList<Double> lineParamList){
+
+        Double lineA = lineParamList.get(0);
+        Double lineC = lineParamList.get(2);
+        Double y = lineA * x + lineC;
+        return y;
+
+    }
+}

+ 158 - 0
src/test/cal.java

@@ -0,0 +1,158 @@
+package test;
+
+import test.entity.OccupyPerX;
+import test.entity.Point;
+import test.entity.WholeIndexOccupy;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
+public class cal {
+
+    ArrayList<OccupyPerX> occupyPerXArrayList = new ArrayList<>();
+
+    public void countNumber(){
+
+        GetPoints getPointsRealShape = new GetPoints();
+        ArrayList<Point> realShapePoints = getPointsRealShape.returnPoints();//实际形状的平面坐标
+        GetPoints getPoints = new GetPoints();//所有待计算点
+        ArrayList<Point> allPoints = getPoints.returnPoints();//所有待计算点,铲车作业平面坐标
+        Split split = new Split();
+        split.cal(realShapePoints);
+
+        ArrayList<Double> xIndexCorList = split.xIndexCorList;//格点横坐标List
+        ArrayList<Double> yIndexCorList = split.yIndexCorList;//格点纵坐标List
+        WholeIndexOccupy wholeIndexOccupy = split.wholeIndexOccupy;//初始垛位的占用情况
+        Double xGap = split.xGap;//横向上采用的间隔
+        Double yGap = split.yGap;//纵向上采用的间隔
+
+        Double minX = xIndexCorList.get(0);
+        Double maxX = xIndexCorList.get(xIndexCorList.size());
+        Double minY = yIndexCorList.get(0);
+        Double maxY = yIndexCorList.get(yIndexCorList.size());
+
+
+        ArrayList<Point> pointAfterExclude = new ArrayList<>();//过滤后的所有点的坐标
+
+
+        //对待计算点,进行过滤,过滤掉在网格以外的,这部分后面单独写个过滤类
+        for(int i = 0 ; i < allPoints.size();i++){
+
+            Point point = allPoints.get(i);
+            Double corX = point.getColX();
+            Double corY = point.getColY();
+
+            if ( (corX < maxX) && (corX > minX) && (corY < maxY) && (corY > minY)){
+
+                pointAfterExclude.add(point);
+
+            }
+
+        }
+
+        //占用的网格为1,不占用的网格0
+        ArrayList<ArrayList<Integer>> occupyList = changeWholeIndexOccupyToList(wholeIndexOccupy);
+
+//        for (int i = 0 ; i < occupyList.size();i++){
+//
+//
+//
+//        }
+
+
+        for (int i = 0; i < pointAfterExclude.size();i++){
+
+            Point point = pointAfterExclude.get(i);
+            Double x = point.getColX();
+            Double y = point.getColY();
+            Integer xIndex = split.identifyXIndex(x);
+            Integer yIndex = split.identifyYIndex(y);
+            ArrayList<Integer> arrayList = occupyList.get(xIndex);
+            arrayList.set(yIndex,0);
+            occupyList.set(xIndex,arrayList);
+
+        }
+
+        for (int i = 0 ; i < occupyList.size();i++){
+
+            ArrayList<Integer> arrayList = occupyList.get(i);
+            String arrayListString = arrayList.toString();
+            String[] arrays = arrayListString.split("0");
+            String maxString ="";
+
+
+            //这里需要再想想
+            for (int j = 0 ; j < arrays.length;j++){
+
+                    String temp = arrays[j];
+                    if (temp.length() > maxString.length()){
+
+                        maxString = temp;
+                    }
+
+            }
+
+            Integer indexBegin = arrayListString.indexOf(maxString) - 1;
+            Integer indexEnd = indexBegin + maxString.length();
+
+            OccupyPerX occupyPerX = new OccupyPerX();
+            occupyPerX.setMinYIndex(indexBegin);
+            occupyPerX.setMaxYIndex(indexEnd);
+            occupyPerXArrayList.add(occupyPerX);
+
+        }
+
+
+
+
+
+
+    }
+
+
+
+    public ArrayList<ArrayList<Integer>> changeWholeIndexOccupyToList(WholeIndexOccupy wholeIndexOccupy){
+
+        ArrayList<OccupyPerX> occupyPerXArrayList = wholeIndexOccupy.getOccupyPerXArrayList();
+
+        Integer numOfGaps = occupyPerXArrayList.size();
+
+        ArrayList<ArrayList<Integer>> occupyList = new ArrayList<>();
+
+        for (int i = 0 ; i < numOfGaps;i++){
+
+            ArrayList<Integer> arrayList = new ArrayList<>();
+
+            for (int j = 0 ; j < numOfGaps ; j++){
+
+                arrayList.add(0);
+
+            }
+            occupyList.add(arrayList);
+        }
+
+        for (int i = 0 ; i < occupyPerXArrayList.size(); i++){
+
+            OccupyPerX occupyPerX =  occupyPerXArrayList.get(i);
+
+            Integer minYIndex = occupyPerX.getMinYIndex();
+
+            Integer maxYIndex = occupyPerX.getMaxYIndex();
+
+            ArrayList<Integer> arrayList = occupyList.get(i);
+
+            for (int j = minYIndex ; j < (maxYIndex + 1); j++){
+
+                arrayList.set(j,1);
+
+            }
+
+            occupyList.set(i,arrayList);
+
+        }
+
+        return occupyList;
+
+    }
+
+}

+ 23 - 0
src/test/entity/Index.java

@@ -0,0 +1,23 @@
+package test.entity;
+
+public class Index {
+
+    public Integer xIndex;
+    public Integer yIndex;
+
+    public Integer getxIndex() {
+        return xIndex;
+    }
+
+    public void setxIndex(Integer xIndex) {
+        this.xIndex = xIndex;
+    }
+
+    public Integer getyIndex() {
+        return yIndex;
+    }
+
+    public void setyIndex(Integer yIndex) {
+        this.yIndex = yIndex;
+    }
+}

+ 23 - 0
src/test/entity/OccupyPerX.java

@@ -0,0 +1,23 @@
+package test.entity;
+
+public class OccupyPerX {
+
+    public Integer minYIndex;
+    public Integer maxYIndex;
+
+    public Integer getMinYIndex() {
+        return minYIndex;
+    }
+
+    public void setMinYIndex(Integer minYIndex) {
+        this.minYIndex = minYIndex;
+    }
+
+    public Integer getMaxYIndex() {
+        return maxYIndex;
+    }
+
+    public void setMaxYIndex(Integer maxYIndex) {
+        this.maxYIndex = maxYIndex;
+    }
+}

+ 24 - 0
src/test/entity/Point.java

@@ -0,0 +1,24 @@
+package test.entity;
+
+public class Point {
+
+    public Double colX;
+
+    public Double colY;
+
+    public Double getColX() {
+        return colX;
+    }
+
+    public void setColX(Double colX) {
+        this.colX = colX;
+    }
+
+    public Double getColY() {
+        return colY;
+    }
+
+    public void setColY(Double colY) {
+        this.colY = colY;
+    }
+}

+ 73 - 0
src/test/entity/WholeIndexOccupy.java

@@ -0,0 +1,73 @@
+package test.entity;
+
+import java.util.ArrayList;
+
+public class WholeIndexOccupy {
+
+    ArrayList<OccupyPerX> occupyPerXArrayList = new ArrayList<>();
+
+    public WholeIndexOccupy(Integer numberOfGaps){
+
+        for (int i = 0;i < numberOfGaps;i++){
+
+            OccupyPerX occupyPerX = new OccupyPerX();
+            occupyPerX.setMinYIndex(-2);
+            occupyPerX.setMaxYIndex(-1);
+            occupyPerXArrayList.add(occupyPerX);
+
+        }
+
+    }
+
+
+    public void setOccupyPerXArrayList(OccupyPerX occupyPerX,Integer xIndex){
+
+        OccupyPerX occupyPerXOld = occupyPerXArrayList.get(xIndex);
+
+        Integer minYIndexOld = occupyPerXOld.getMinYIndex();
+        Integer maxYIndexOld = occupyPerXOld.getMaxYIndex();
+
+        Integer minYIndexForCal = occupyPerX.getMinYIndex();
+        Integer maxYIndexForCal = occupyPerX.getMaxYIndex();
+
+        Integer minYIndexTemp;
+        Integer maxYIndexTemp;
+
+        if (minYIndexOld < minYIndexForCal){
+
+            minYIndexTemp = minYIndexOld;
+
+        }
+        else{
+
+            minYIndexTemp = minYIndexForCal;
+
+        }
+
+
+        if (maxYIndexOld > maxYIndexForCal){
+
+            maxYIndexTemp = maxYIndexOld;
+
+        }
+        else{
+
+            maxYIndexTemp = maxYIndexForCal;
+
+        }
+
+        OccupyPerX occupyPerX1 = new OccupyPerX();
+        occupyPerX1.setMinYIndex(minYIndexTemp);
+        occupyPerX1.setMaxYIndex(maxYIndexTemp);
+        occupyPerXArrayList.set(xIndex,occupyPerX1);
+
+    }
+
+    public ArrayList<OccupyPerX> getOccupyPerXArrayList() {
+
+        return occupyPerXArrayList;
+
+    }
+
+
+}