瀏覽代碼

判断控制点location值不能一样

wuweihao 3 年之前
父節點
當前提交
098e4846a3

+ 11 - 2
laser/src/main/java/com/fdkankan/indoor/base/convert/AffineTransform.java

@@ -7,7 +7,9 @@ public class AffineTransform {
     }
 
     public static double getScale(Point p1, Point b1, Point p2, Point b2) {
-        return getLength(b1, b2) / getLength(p1, p2);
+        // 被除数不能等于0
+        double a =  getLength(b1, b2) / getLength(p1, p2) ;
+        return a;
     }
 
     public static double getLength(Point p1, Point p2) {
@@ -26,7 +28,14 @@ public class AffineTransform {
     public static Point transformBoePoint(Point gp, double rotation, double scale, double dx, double dy) {
         double A = scale * Math.cos(rotation);
         double B = scale * Math.sin(rotation);
-        return new Point(A * gp.getX() - B * gp.getY() + dx, B * gp.getX() + A * gp.getY() + dy);
+        try {
+            Point point = new Point(A * gp.getX() - B * gp.getY() + dx, B * gp.getX() + A * gp.getY() + dy);
+
+            return point;
+        } catch (NullPointerException e){
+            e.getStackTrace();
+        }
+        return null;
     }
 
 }

+ 13 - 8
laser/src/main/java/com/fdkankan/indoor/base/convert/ConvertToVision.java

@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.time.LocalDateTime;
 
 import com.fdkankan.indoor.base.constant.TypeConstant;
+import com.fdkankan.indoor.base.exception.BaseRuntimeException;
 import com.fdkankan.indoor.base.util.SnowFlakeUUidUtils;
 import com.fdkankan.indoor.core.entity.ControlPointCalculateEntity;
 import com.fdkankan.indoor.core.entity.ControlPointEntity;
@@ -28,7 +29,6 @@ public class ConvertToVision {
 	SpecialPointService specialPointService;
 
 	private static JSONArray readVisionTxt(String path) throws IOException {
-//		String str = FileUtil.readStringFile(inputFilePath);
 		String str = FileUtil.readStringFile(path);
 		JSONObject json = JSONObject.fromObject(str);
 		JSONArray sweepLocations = json.getJSONArray("sweepLocations");
@@ -76,6 +76,7 @@ public class ConvertToVision {
 		JSONArray laserPanos = new JSONArray();
 		int visionSize = panoInfos.size();
 		log.info("漫游点位数量: {}", visionSize);
+		log.info("from: {}", from);
 		for(int i=0;i< visionSize;++i) {
 			JSONObject item = panoInfos.getJSONObject(i);
 			JSONObject laserPano = new JSONObject();
@@ -91,7 +92,6 @@ public class ConvertToVision {
 			// 2021-09-06改用floor类型的id
 			laserPano.put("site_model_entity_id", 11);
 
-			//JSONObject pose = item.getJSONObject("pose");
 			// vision.txt: puck、translation 这两个值是一样的。所以算出来的_location、_floor_location值也应该一样
 			JSONObject position2 = item.getJSONObject("puck");
 			JSONObject position1 = item.getJSONObject("translation");
@@ -106,12 +106,19 @@ public class ConvertToVision {
 			floor_location[1] = position2.getDouble("y");
 			floor_location[2] = position2.getDouble("z");
 			//gis坐标
-//			log.warn("=============== _location 开始" + i +" =========================");
-//			double[] _location = TransformGPS.convertLocationToGis(location,dto);
 			double[] _location = GisCoordinateUtil.transformLocationToBL(location[0], location[1], calculateEntity);
-//			log.warn("=============== _location 结束" + i +" =========================");
-//			double[] _floor_location = TransformGPS.convertLocationToGis(floor_location, dto);
+			if (_location == null) {
+				String msg = "_location坐标转换异常";
+				log.error(msg);
+				throw new BaseRuntimeException(msg);
+			}
 			double[] _floor_location = GisCoordinateUtil.transformLocationToBL(floor_location[0], floor_location[1], calculateEntity);
+			if (_floor_location == null) {
+				String msg = "_floor_location坐标转换异常";
+				log.error(msg);
+				throw new BaseRuntimeException(msg);
+			}
+
 			location[0] = _location[0];
 			location[1] = _location[1];
 			floor_location[0] = _floor_location[0];
@@ -142,10 +149,8 @@ public class ConvertToVision {
 
 			// 2021-09-14
 			if ("web".equals(from)) {
-				log.info("quaternation  from: {}", from);
 				laserPano.put("orientation", getQuaternation(rotation, calculateEntity.getRotation2()));
 			} else {
-				log.info("quaternation  from: {}", from);
 				laserPano.put("orientation", quaternation);
 			}
 

+ 18 - 5
laser/src/main/java/com/fdkankan/indoor/base/convert/GisCoordinateTransform.java

@@ -1,10 +1,12 @@
 package com.fdkankan.indoor.base.convert;
 
+import lombok.extern.slf4j.Slf4j;
 import org.locationtech.proj4j.*;
 
 /**
  * 提供常国家用坐标系转换方法
  */
+@Slf4j
 public  class GisCoordinateTransform {
     //CGCS2000坐标系参数
     private  static double CGCS2000_a=6378137.0;
@@ -37,13 +39,24 @@ public  class GisCoordinateTransform {
         ProjCoordinate p2 = new ProjCoordinate();
         p1.x = x;
         p1.y = y;
+        ProjCoordinate p;
+        try {
+             p= trans.transform(p1, p2);
+            double[] xy=new double[2];
+            xy[0]=p.x;
+            xy[1]=p.y;
+            if (xy == null) {
+                log.error("这里出现空值,应该抛出异常");
+            }
+            return  xy;
+        } catch (Exception e){
+            log.error("convertByProj4坐标转换异常");
+            log.error(e.getMessage());
+            e.getStackTrace();
+        }
 
-        ProjCoordinate p= trans.transform(p1, p2);
+    return null;
 
-        double[] xy=new double[2];
-        xy[0]=p.x;
-        xy[1]=p.y;
-        return  xy;
     }
 
 

+ 22 - 170
laser/src/main/java/com/fdkankan/indoor/base/convert/GisCoordinateUtil.java

@@ -70,15 +70,17 @@ public class GisCoordinateUtil {
      */
     public static  double[] transformLocationToBL(double loctionX,double loctionY, ControlPointCalculateEntity dto){
         Point point = new Point(loctionX,loctionY);
-//        log.warn("本地转经纬度 平面 start ====");
-//        log.info("参数 rotation:{}", dto.getRotation2());
-//        log.info("参数 scale:{}", dto.getScale2());
-//        log.info("参数 tx:{}", dto.getDx2());
-//        log.info("参数 ty:{}", dto.getDy2());
-        Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), dto.getRotation2(), dto.getScale2(), dto.getDx2(), dto.getDy2());
-//        log.info("本地坐标转平面坐标输出结果:{}, {}", resultPoint.getX(),resultPoint.getY());
-//        log.warn("本地转经纬度 平面 end ====");
-        return GisCoordinateTransform.convertByProj4(resultPoint.getX(),resultPoint.getY(),"EPSG:4547","EPSG:4490");
+
+            Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), dto.getRotation2(), dto.getScale2(), dto.getDx2(), dto.getDy2());
+//            log.info("toBL输入参数:{}, {}", resultPoint.getX(), resultPoint.getY());
+            double[] doubles = GisCoordinateTransform.convertByProj4(resultPoint.getX(), resultPoint.getY(), "EPSG:4547", "EPSG:4490");
+            if (doubles == null) {
+                String msg = "坐标转换为空值";
+                log.error(msg);
+                throw new BaseRuntimeException(msg);
+            }
+            return doubles;
+
     }
 
 
@@ -139,69 +141,6 @@ public class GisCoordinateUtil {
 //        }
 //    }
 
-//    /**
-//     * 解析json字符串
-//     *
-//     * @param jsonStr
-//     */
-//    private static void parseJSON(String jsonStr) {
-////        JSONObject json= JSONObject.fromObject(jsonStr);
-//        JSONObject json = JSONObject.parseObject(jsonStr);
-//        JSONArray points = json.getJSONArray("points");
-//        JSONObject aPoint = (JSONObject) points.get(0);
-//        JSONObject bPoint = (JSONObject) points.get(1);
-//        JSONObject aPointCoordinate = (JSONObject) aPoint.get("coordinate");
-//        JSONObject aPointLocation = (JSONObject) aPoint.get("location");
-//        JSONObject bPointCoordinate = (JSONObject) bPoint.get("coordinate");
-//        JSONObject bPointLocation = (JSONObject) bPoint.get("location");
-//        double alon = aPointCoordinate.getDouble("longitude");
-//        double alat = aPointCoordinate.getDouble("latitude");
-//        double aX = aPointLocation.getDouble("x");
-//        double aY = aPointLocation.getDouble("y");
-//        double blon = bPointCoordinate.getDouble("longitude");
-//        double blat = bPointCoordinate.getDouble("latitude");
-//        double bX = bPointLocation.getDouble("x");
-//        double bY = bPointLocation.getDouble("y");
-////        calculateVariable(alon, alat, aX, aY, blon, blat, bX, bY);
-//        //  System.out.println(alon+" "+alat+" "+aX+" "+aY+" "+blon+" "+blat+" "+bX+" "+bY);
-//    }
-
-
-
-
-
-
-    /**
-     * 经纬度转本地坐标
-     *
-     * @param position 经纬度
-     * @param dto      控制点
-     * @return
-     */
-//    public static double[] convertGpsToLocation(double[] position, ControlPointEntity dto) {
-//        double[] controlLocation1 = dto.getAgeControlLocation1();
-//        double[] controlLocation2 = dto.getAgeControlLocation2();
-//
-//        double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
-//        double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
-//        try {
-////            log.info("输入控制点3: {}, {}, {}, {}, {}, {}, {}, {}", controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
-////            GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
-//            double[] d = GisCoordinateUtil.transformBLToLocation(position[0], position[1]);
-//            return d;
-//        } catch (RuntimeException e) {
-//            log.error("坐标转换输入参数有误,请检查");
-//            e.printStackTrace();
-//        }
-//       return null;
-//    }
-
-
-
-
-
-
-
 
 
 
@@ -276,73 +215,16 @@ public class GisCoordinateUtil {
 
 
 
-
-
-//    /**
-//     * 控制点初始化作用, 只有控制点变化, 才会调用一次, 以后坐标转换都是基于这个值使用
-//     * @param alon
-//     * @param alat
-//     * @param aX
-//     * @param aY
-//     * @param blon
-//     * @param blat
-//     * @param bX
-//     * @param bY
-//     */
-//    public static  void calculateVariable (double alon,double alat,double aX,double aY,double blon,double blat,double bX,double bY){
-//
-//
-//        try {
-//            double[] a= new double[0];
-//            a = GisCoordinateTransform.convertByProj4(alon, alat,"EPSG:4490","EPSG:4547");
-//            double[] b= GisCoordinateTransform.convertByProj4(blon, blat,"EPSG:4490","EPSG:4547");
-//            log.info("经度2、纬度2: {}, {}", alon, alat );
-//            log.info("经度4、纬度4: {}, {}", blon, blat );
-//            log.info("大地2: {}, {}", a[0], a[1]);
-//            log.info("大地4: {}, {}", b[0], b[1]);
-//            Point point1 = new Point(a[0],a[1]);
-//            Point point2 = new Point(b[0],b[1]);
-//            Point newPoint1 = new Point(aX,aY);
-//            Point newPoint2 = new Point(bX,bY);
-//            log.info("========== start calculateVariable =================");
-//            // 2021-09-13 修改:前后对调一下
-//            rotation1 = Math.toRadians(AffineTransform.getAngle(point1 , point2 ) - AffineTransform.getAngle(newPoint1 , newPoint2 ));
-//            scale1 = AffineTransform.getScale( point1 , newPoint1 , point2 , newPoint2);
-////            log.info("rotation1: {}", rotation1);
-//            dx1 = AffineTransform.getXTranslation( point1 ,newPoint1, rotation1, scale1);
-//            dy1 = AffineTransform.getYTranslation( point1 ,newPoint1, rotation1, scale1);
-//            log.warn("rotation1: {}", rotation1);
-//            log.warn("scale1: {}", scale1);
-//            log.warn("tx1: {}", dx1);
-//            log.warn("ty1: {}", dy1);
-//            rotation2 = Math.toRadians(AffineTransform.getAngle(newPoint1 , newPoint2 ) - AffineTransform.getAngle(point1 , point2 ));
-////            log.info("rotation2: {}", rotation2);
-//            scale2 = AffineTransform.getScale( newPoint1 , point1 , newPoint2 , point2);
-//            dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale1);
-//            dy2 = AffineTransform.getYTranslation( newPoint1 ,point1, rotation2, scale1);
-//
-//            log.warn("rotation2: {}", rotation2);
-//            log.warn("scale2: {}", scale2);
-//            log.warn("tx2: {}", dx2);
-//            log.warn("ty2: {}", dy2);
-//
-//            log.info("========== end calculateVariable =================");
-//        } catch (RuntimeException e) {
-//            e.printStackTrace();
-//        }
-//    }
-
-
     /**
      * 控制点初始化作用, 只有控制点变化, 才会调用一次, 以后坐标转换都是基于这个值使用
-//     * @param alon
-//     * @param alat
-//     * @param aX
-//     * @param aY
-//     * @param blon
-//     * @param blat
-//     * @param bX
-//     * @param bY
+     * @param alon
+     * @param alat
+     * @param aX
+     * @param aY
+     * @param blon
+     * @param blat
+     * @param bX
+     * @param bY
      */
 //    public static  void calculateVariable (double alon,double alat,double aX,double aY,double blon,double blat,double bX,double bY){
     public static ControlPointCalculateEntity calculateVariable (ControlPointEntity dto){
@@ -378,12 +260,8 @@ public class GisCoordinateUtil {
 
             double rotation2 = Math.toRadians(AffineTransform.getAngle(newPoint1 , newPoint2 ) - AffineTransform.getAngle(point1 , point2 ));
             double scale2 = AffineTransform.getScale( newPoint1 , point1 , newPoint2 , point2);
-//            log.info("输入参数1:{}, {}", newPoint1.getX(), newPoint1.getY());
-//            log.info("输入参数2:{}, {}", point1.getX(), point1.getY());
-//            log.info("输入参数 rotation2:{}, {}", rotation2);
-//            log.info("输入参数 scale2:{}, {}", scale2);
-//            double dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale1);
-//            double dy2 = AffineTransform.getYTranslation( newPoint1 ,point1, rotation2, scale1);
+            log.info("scale2: {}", scale2);
+
 
             // 2021-09-13 这里应该使用scale2
             double dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale2);
@@ -403,16 +281,6 @@ public class GisCoordinateUtil {
             entity.setScale2(scale2);
             entity.setDx2(dx2);
             entity.setDy2(dy2);
-//            log.warn("平面坐标 start");
-//            log.info("参数 rotation1:{}", rotation1);
-//            log.info("参数 scale1:{}", scale1);
-//            log.info("参数 dx1:{}", dx1);
-//            log.info("参数 dy1:{}", dy1);
-//            log.info("参数 rotation2:{}", rotation2);
-//            log.info("参数 scale2:{}", scale2);
-//            log.info("参数 dx2:{}", dx2);
-//            log.info("参数 dy2:{}", dy2);
-//            log.warn("平面坐标 end");
 
             return entity;
         } catch (RuntimeException e) {
@@ -422,23 +290,7 @@ public class GisCoordinateUtil {
     }
 
 
-    /**
-     * 控制点赋值,初始化
-     */
-//    public void initAssign(ControlPointEntity dto){
-//        double[] controlLocation1 = dto.getAgeControlLocation1();
-//        double[] controlLocation2 = dto.getAgeControlLocation2();
-//
-//        double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
-//        double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
-//
-//        log.info("输入控制点1: {}, {}, {}, {}, {}, {}, {}, {}", controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
-//        GisCoordinateUtil.calculateVariable (
-//                controlCoordinate1[0],controlCoordinate1[1],
-//                controlLocation1[0],controlLocation1[1],
-//                controlCoordinate2[0],controlCoordinate2[1],
-//                controlLocation2[0],controlLocation2[1]);
-//    }
+
 
 
 

+ 9 - 1
laser/src/main/java/com/fdkankan/indoor/core/service/impl/InitServiceImpl.java

@@ -519,6 +519,7 @@ public class InitServiceImpl implements InitService {
 
         String s = cn.hutool.core.io.FileUtil.readUtf8String(path);
         com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(s);
+        log.info("控制点值: {}", jsonObject);
         com.alibaba.fastjson.JSONArray points = jsonObject.getJSONArray("points");
 
         com.alibaba.fastjson.JSONObject poi_1 = points.getJSONObject(0);
@@ -541,6 +542,14 @@ public class InitServiceImpl implements InitService {
         double[] ageLocation1 = {ageX_1, ageY_1};
         double[] ageLocation2 = {ageX_2, ageY_2};
 
+        // 控制点值一样的话,就变一个点,就不是两个点了
+        if (ageX_1 == ageX_2 && ageY_1 == ageY_1){
+            String msg = "默认控制点的location值不能一样";
+            log.error("默认控制点有误:{}", msg);
+            throw new BaseRuntimeException(msg);
+
+        }
+
         ControlPointEntity entity = new ControlPointEntity();
         entity.setGpsControlCoordinate1(gpsCoord1);
         entity.setGpsControlCoordinate2(gpsCoord2);
@@ -557,7 +566,6 @@ public class InitServiceImpl implements InitService {
         entity.setCreateTime(LocalDateTime.now());
         entity.setStatus(0);
         // 控制点保存方法有很多处理逻辑
-//        controlPointService.save(entity, null);
         controlPointService.saveEntity(entity);
         log.info("算法控制点保存完成");
 

+ 1 - 1
laser/src/main/resources/sh/startup.sh

@@ -2,7 +2,7 @@
 RESOURCE_NAME=indoor.jar
 APP_DEBUG=5005
 APP_PORT=9294
-APP_ACTIVE=pro
+APP_ACTIVE=sit
 rm -f tpid
 nohup java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${APP_DEBUG} $RESOURCE_NAME --spring.profiles.active=${APP_ACTIVE} --server.port=${APP_PORT} & echo $! > tpid
 echo Start Success!