123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782 |
- package com.example.demo.util;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.util.StringUtil;
- import java.io.*;
- import java.util.*;
- import java.util.concurrent.atomic.AtomicBoolean;
- public class ConvertCadKjl {
- // public String path = "G:\\javaProject\\baidu-master\\floor.json";
- // public String outpath = "G:\\javaProject\\baidu-master\\kjl.json";
- public JSONObject input = null;
- public JSONObject output = null;
- //重复的墙要删除,这是他们id的映射关系,key表示删除墙的id,value表示重复的且最终留下的墙的id
- public JSONObject wallMapping = new JSONObject();
- public final double minThickness = 0.01;
- //数据预处理,目前暂时处理点位坐标的吸附
- //1、坐标吸附
- public JSONObject preHandle(JSONObject json) {
- //坐标点
- JSONArray vertexs = json.getJSONArray("vertex-xy");
- for(int i=0;i<vertexs.size();++i) {
- JSONObject point1 = vertexs.getJSONObject(i);
- for(int j=i+1;j<vertexs.size();++j) {
- JSONObject point2 = vertexs.getJSONObject(j);
- double disc = getDistance(point1,point2);
- //这时候要合并点了。
- if(disc <= minThickness) {
- point2.put("x", point1.getDouble("x"));
- point2.put("y", point1.getDouble("y"));
- vertexs.set(j, point2);
- }
- }
- }
- json.put("vertex-xy", vertexs);
- return json;
- }
- //计算两点之间的距离
- //
- public double getDistance(JSONObject p1,JSONObject p2) {
- double x1 = p1.getDouble("x");
- double y1 = p1.getDouble("y");
- double x2 = p2.getDouble("x");
- double y2 = p2.getDouble("y");
- double disc = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- return disc;
- }
- public void init(JSONObject inputJson) {
- output = new JSONObject();
- output.put("communityName", "随心装");
- output.put("name", "随心装户型");
- output.put("province", "");
- output.put("height", "2.7");
- // readFile(floorPath); //读我们自己的floor.json
- input = inputJson;
- output.put("holes", new JSONArray());
- output.put("flues", new JSONArray());
- output.put("beams", new JSONArray());
- output.put("rooms", new JSONArray());
- output.put("walls", new JSONArray());
- }
- public static void writeBinary(byte[] buf,String filePath)throws Exception
- {
- File fout = new File(filePath);
- FileOutputStream fos = new FileOutputStream(fout);
- ByteArrayInputStream stream = new ByteArrayInputStream(buf);
- BufferedOutputStream bos = new BufferedOutputStream(fos);//设置输出路径
- BufferedInputStream bis = new BufferedInputStream(stream);
- int b = -1;
- while ((b = bis.read()) != -1) {
- bos.write(b);
- }
- bis.close();
- bos.close();
- }
- //获取酷家乐里,key是wall的值,其实对应我们的是segment字段
- public JSONArray getWalls() {
- if(input == null) {
- return null;
- }
- else if(input.getJSONArray("segment") == null) {
- return null;
- }
- else if(input.getJSONArray("segment").size() == 0) {
- return null;
- }
- else {
- JSONArray walls = input.getJSONArray("segment");
- JSONArray points = input.getJSONArray("vertex-xy");
- JSONArray result = new JSONArray();
- for(int i=0;i<walls.size();++i) {
- JSONObject wall = walls.getJSONObject(i);
- // if(wall.getInteger("id") == 30){
- // System.out.println(30);
- // }
- JSONObject startJson = getPoint(points,wall.getIntValue("a"));
- JSONObject endJson = getPoint(points,wall.getIntValue("b"));
- double x = startJson.getDouble("x");
- double y = startJson.getDouble("y");
- JSONObject start = new JSONObject();
- start.put("x", x );
- start.put("y", y );
- wall.put("start", start);
- x = endJson.getDouble("x");
- y = endJson.getDouble("y");
- JSONObject end = new JSONObject();
- end.put("x", x );
- end.put("y", y );
- wall.put("end", end);
- wall.put("thickness", 0.15f);
- wall.put("type", "LINE");
- wall.put("bulge", 0); //跟曲线有关,我们不是
- JSONObject control = new JSONObject();
- control.put("x", 0);
- control.put("y", 0);
- wall.put("control", control); //跟曲线有关,我们不是
- wall.put("height", 2.8 ); //默认高度
- //wall.remove("a");
- //wall.remove("b");
- //wall.remove("id");
- wall.remove("border");
- result.add(wall);
- }
- return result;
- }
- }
- public JSONObject getPoint(JSONArray points,int id) {
- for(int i=0;i<points.size();++i) {
- JSONObject point = points.getJSONObject(i);
- if(point.getIntValue("id") == id) {
- double x = point.getDouble("x");
- double y = point.getDouble("y");
- JSONObject p = new JSONObject();
- p.put("x", x);
- p.put("y", y);
- return p;
- }
- }
- return null;
- }
- //获取酷家乐里,key是rooms的值,其实对应我们的是tagging字段
- public JSONArray getRooms() {
- if(input == null) {
- return null;
- }
- if(input.containsKey("tagging")){
- if(input.getJSONArray("tagging") == null) {
- return null;
- }
- else if(input.getJSONArray("tagging").size() == 0) {
- return null;
- }
- else {
- JSONArray rooms = input.getJSONArray("tagging");
- JSONArray result = new JSONArray();
- for(int i=0;i<rooms.size();++i) {
- JSONObject item = new JSONObject();
- JSONObject room = rooms.getJSONObject(i);
- item.put("name", room.getString("title"));
- JSONObject position = new JSONObject();
- position.put("x", room.getJSONArray("pos").get(0));
- position.put("y", room.getJSONArray("pos").get(1));
- item.put("position", position);
- result.add(item);
- }
- return result;
- }
- }
- return null;
- }
- //柱子
- //获取酷家乐里,key是beams的值,其实对应我们的是furnFlue字段和furnColumn字段
- public JSONArray getBeams() {
- if(input == null) {
- return null;
- }
- JSONArray result = new JSONArray();
- if(input.containsKey("furnColumn") && input.getJSONArray("furnColumn") != null && input.getJSONArray("furnColumn").size()>0) {
- JSONArray furnColumns = input.getJSONArray("furnColumn"); //独立的柱子
- result = getColumnsModule(furnColumns);
- }
- if(input.containsKey("furnFlue") && input.getJSONArray("furnFlue") != null && input.getJSONArray("furnFlue").size()>0) {
- JSONArray furnFlues = input.getJSONArray("furnFlue"); //独立的柱子
- JSONArray columns = getColumnsModule(furnFlues);
- result.addAll(columns);
- }
- return result;
- }
- //柱子
- //获取酷家乐里,key是flues的值,其实对应我们的是column字段
- public JSONArray getFlues() {
- if(input == null) {
- return null;
- }
- //int id = 1;
- JSONArray result = new JSONArray();
- if(input.containsKey("column") && input.getJSONArray("column") != null && input.getJSONArray("column").size()>0) {
- JSONArray columns = input.getJSONArray("column"); //非独立的柱子
- for(int i=0;i<columns.size();++i) {
- JSONObject item = new JSONObject();
- JSONArray polygon = new JSONArray();
- JSONObject column = columns.getJSONObject(i);
- JSONArray pos = column.getJSONArray("pos");
- //item.put("id", id);
- JSONObject point1 = new JSONObject();
- point1.put("x", pos.getDouble(0));
- point1.put("y", pos.getDouble(1));
- polygon.add(point1);
- JSONObject point2 = new JSONObject();
- point2.put("x", pos.getDouble(2));
- point2.put("y", pos.getDouble(3));
- //polygon.add(point2);
- JSONObject point3 = new JSONObject();
- point3.put("x", pos.getDouble(4));
- point3.put("y", pos.getDouble(5));
- polygon.add(point3);
- JSONObject point4 = new JSONObject();
- point4.put("x", pos.getDouble(6));
- point4.put("y", pos.getDouble(7));
- polygon.add(point4);
- //4dkk的这个数据不是按照顺序来的。
- polygon.add(point2);
- item.put("id", column.getIntValue("line"));
- item.put("polygon", polygon);
- // ++id;
- result.add(item);
- }
- return result;
- }
- return null;
- }
- //门窗等等
- //注意:酷家乐对应的holes字段和我们的不一样,对应我们的是门,窗等等
- public JSONArray getHoles() {
- if(input == null) {
- return null;
- }
- JSONArray result = new JSONArray();
- if(input.containsKey("window") && input.getJSONArray("window") != null && input.getJSONArray("window").size()>0) {
- result = getItemsModule(input.getJSONArray("window"),"window");
- }
- if(input.containsKey("door") && input.getJSONArray("door") != null && input.getJSONArray("door").size()>0) {
- JSONArray doors = getItemsModule(input.getJSONArray("door"),"door");
- result.addAll(doors);
- }
- if(input.containsKey("slideDoor") && input.getJSONArray("slideDoor") != null && input.getJSONArray("slideDoor").size()>0) {
- JSONArray slideDoors = getItemsModule(input.getJSONArray("slideDoor"),"slideDoor");
- result.addAll(slideDoors);
- }
- if(input.containsKey("groundCase") && input.getJSONArray("groundCase") != null && input.getJSONArray("groundCase").size()>0) {
- JSONArray groundCases = getItemsModule(input.getJSONArray("groundCase"),"groundCase");
- result.addAll(groundCases);
- }
- if(input.containsKey("bayCase") && input.getJSONArray("bayCase") != null && input.getJSONArray("bayCase").size()>0) {
- JSONArray bayCases = getItemsModule(input.getJSONArray("bayCase"),"bayCase");
- result.addAll(bayCases);
- }
- JSONArray points = input.getJSONArray("vertex-xy");
- for(int i=0;i<result.size();++i) {
- JSONObject item = result.getJSONObject(i);
- int wallId = item.getIntValue("groundClearance");
- double _bottom = item.getDouble("bottom");
- //double bottom = getbottomForWallId(wallId);
- //double groundClearance = _bottom - bottom;
- item.put("groundClearance", _bottom);
- item.put("wallId", wallId);
- item.remove("bottom");
- }
- return result;
- }
- public double getbottomForWallId(int wallId) {
- JSONArray blocks = input.getJSONArray("block");
- JSONArray vertex_z = input.getJSONArray("vertex-z");
- int bottomId = -1;
- for(int i=0;i<blocks.size();++i) {
- JSONObject block = blocks.getJSONObject(i);
- JSONArray walls = block.getJSONArray("wall");
- for(int j=0;j<walls.size();++j) {
- int wid = walls.getIntValue(j);
- if(wid == wallId) {
- bottomId = block.getIntValue("bottom");
- break;
- }
- }
- if(bottomId>0) {
- for(int k=0;k<vertex_z.size();++k) {
- JSONObject z = vertex_z.getJSONObject(k);
- if(z.getIntValue("id") == bottomId) {
- return z.getDouble("z");
- }
- }
- }
- }
- return -999999;
- }
- public JSONArray getColumnsModule(JSONArray columns) {
- JSONArray result = new JSONArray();
- for(int i=0;i<columns.size();++i) {
- JSONObject item = new JSONObject();
- JSONArray polygon = new JSONArray();
- JSONObject furnColumn = columns.getJSONObject(i);
- JSONArray points = furnColumn.getJSONArray("pos");
- double x1 = points.getDouble(0);
- double y1 = points.getDouble(1);
- double x2 = points.getDouble(2);
- double y2 = points.getDouble(3);
- //double startX = (x1+x2)/2;
- //double startY = (y1+y2)/2;
- double x3 = points.getDouble(4);
- double y3 = points.getDouble(5);
- double x4 = points.getDouble(6);
- double y4 = points.getDouble(7);
- //double endX = (x3+x4)/2;
- //double endY = (y3+y4)/2;
- /*
- JSONObject start = new JSONObject();
- start.put("x", startX );
- start.put("y", startY );
- item.put("start", start);
- JSONObject end = new JSONObject();
- end.put("x", endX );
- end.put("y", endY );
- item.put("end", end);
- item.put("height", furnColumn.getDouble("bottom") );
- double _thickness = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- item.put("thickness", _thickness);
- result.add(item);
- */
- JSONObject p1 = new JSONObject();
- p1.put("x", x1 );
- p1.put("y", y1 );
- polygon.add(p1);
- JSONObject p2 = new JSONObject();
- p2.put("x", x2 );
- p2.put("y", y2 );
- polygon.add(p2);
- JSONObject p3 = new JSONObject();
- p3.put("x", x3 );
- p3.put("y", y3 );
- polygon.add(p3);
- JSONObject p4 = new JSONObject();
- p4.put("x", x4 );
- p4.put("y", y4 );
- polygon.add(p4);
- item.put("polygon", polygon);
- item.put("bottom", furnColumn.getDouble("bottom") );
- item.put("top", furnColumn.getDouble("top") );
- result.add(item);
- }
- return result;
- }
- //获取朝向
- //ctl表示跟样式相关的坐标点
- //可以通过三角形顶点的顺时针和逆时针来判断朝向
- public String getOpenSide(JSONObject start,JSONObject end,JSONArray ctl ){
- double x = ctl.getDoubleValue(0);
- double y = ctl.getDoubleValue(1);
- double result=(x-start.getDouble("x"))*(end.getDouble("y")-y)-(y-start.getDouble("y"))*(end.getDouble("x")-x);
- double dis1 = Math.sqrt((x-start.getDouble("x"))*(x-start.getDouble("x"))+(y-start.getDouble("y"))*(y-start.getDouble("y")));
- double dis2 = Math.sqrt((x-end.getDouble("x"))*(x-end.getDouble("x"))+(y-end.getDouble("y"))*(y-end.getDouble("y")));
- if(result>0){
- if(ctl.size()>0){
- return "LEFT";
- }
- //单开门
- else{
- if(dis1>dis2){
- return "RIGHT_INVERSE";
- }
- else{
- return "LEFT";
- }
- }
- }
- else{
- if(ctl.size()>0){
- return "RIGHT";
- }
- //单开门
- else{
- if(dis1>dis2){
- return "LEFT_INVERSE";
- }
- else{
- return "RIGHT";
- }
- }
- }
- }
- public JSONArray getItemsModule(JSONArray holes,String type) {
- JSONArray result = new JSONArray();
- for(int i=0;i<holes.size();++i) {
- JSONObject item = new JSONObject();
- JSONObject hole = holes.getJSONObject(i);
- JSONArray points = hole.getJSONArray("pos");
- double x1 = points.getDouble(0);
- double y1 = points.getDouble(1);
- double x2 = points.getDouble(2);
- double y2 = points.getDouble(3);
- JSONObject start = new JSONObject();
- start.put("x", x1 );
- start.put("y", y1 );
- item.put("start", start);
- JSONObject end = new JSONObject();
- end.put("x", x2 );
- end.put("y", y2 );
- item.put("end", end);
- double bottom = hole.getDouble("bottom");
- double top = hole.getDouble("top");
- item.put("height", (top-bottom) );
- item.put("openSide", "LEFT");
- JSONArray ctl = hole.getJSONArray("ctl");
- if(ctl!=null){
- String side = getOpenSide( start, end, ctl);
- item.put("openSide", side); //我们自己的暂时不分朝向
- }
- int wallId = hole.getIntValue("line");
- if(wallMapping.containsKey(wallId)){
- wallId = wallMapping.getIntValue(String.valueOf(wallId));
- }
- //这个值实际上应该是离地面的高度,但是我们在另一个地方再换,这里只保存墙的id
- item.put("groundClearance", wallId);
- item.put("bottom", bottom);
- switch(type){
- case "window" :
- item.put("type", "WINDOW");
- break;
- case "door" :
- item.put("type", "DOOR");
- break;
- case "slideDoor" :
- item.put("type", "SLIDE_DOOR");
- break;
- case "groundCase" :
- item.put("type", "FRENCH_WINDOW");
- break;
- case "bayCase" :
- item.put("type", "BAY_WINDOW");
- break;
- default :
- break;
- }
- result.add(item);
- }
- return result;
- }
- public static Map<String, Double> getAverageValue(String visionPath) throws Exception{
- Map<String, Double> map = new HashMap<>();
- JSONObject visionJson = JSONObject.parseObject(FileUtils.readFile(visionPath));
- JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
- double translationTotal = 0;
- double puckTotal = 0;
- for(int i = 0, len = sweepLocations.size(); i < len; i++){
- translationTotal += sweepLocations.getJSONObject(i).getJSONObject("pose").
- getJSONObject("translation").getDoubleValue("z");
- puckTotal += sweepLocations.getJSONObject(i).getJSONObject("puck").getDoubleValue("z");
- }
- map.put("translationAverage", translationTotal / sweepLocations.size());
- map.put("puckAverage", puckTotal / sweepLocations.size());
- return map;
- }
- public static Map<String, Double> getMaxOrMinValue(JSONObject visionJson) throws Exception{
- Map<String, Double> map = new HashMap<>();
- // JSONObject visionJson = JSONObject.parseObject(FileUtils.readFile(visionPath));
- JSONArray vertexZ = visionJson.getJSONArray("vertex-z");
- double[] vertexZArr = new double[vertexZ.size()];
- if(vertexZ != null){
- for(int i = 0, len = vertexZ.size(); i < len; i++){
- vertexZArr[i] = vertexZ.getJSONObject(i).getDoubleValue("z");
- }
- }
- map.put("translationAverage", getBubbleSortData(vertexZArr, 0));
- map.put("puckAverage", getBubbleSortData(vertexZArr, 1));
- // map.put("translationAverage", translationTotal / sweepLocations.size());
- // map.put("puckAverage", puckTotal / sweepLocations.size());
- return map;
- }
- /*
- public static JSONArray removeRepeat(JSONArray walls, AtomicBoolean removeAgain){
- JSONArray repeat = new JSONArray();
- JSONArray repeat2 = new JSONArray();
- JSONObject object1 = new JSONObject();
- JSONObject object2 = new JSONObject();
- removeAgain.compareAndSet(true, false);
- //完全重复不删除的id,只删除前面的,留着后面的
- Set<Long> ids = new HashSet<>();
- System.out.println("wallsSize:" + walls.size());
- for(int i = 0, len = walls.size(); i < len; i++){
- for (int j = 0, lem = walls.size(); j < lem; j++){
- if(i != j){
- object1 = walls.getJSONObject(i);
- object2 = walls.getJSONObject(j);
- if(ids.contains(object1.getLong("id"))){
- continue;
- }
- if(object1.getJSONObject("end").getDoubleValue("x") == object2.getJSONObject("end").getDoubleValue("x") &&
- object1.getJSONObject("end").getDoubleValue("y") == object2.getJSONObject("end").getDoubleValue("y") &&
- object1.getJSONObject("start").getDoubleValue("x") == object2.getJSONObject("start").getDoubleValue("x") &&
- object1.getJSONObject("start").getDoubleValue("y") == object2.getJSONObject("start").getDoubleValue("y") ){
- System.out.println("相同obj1:" + object1.toJSONString());
- System.out.println("相同obj2:" + object2.toJSONString());
- repeat.add(object1);
- ids.add(object2.getLong("id"));
- }
- if(object1.getJSONObject("end").getDoubleValue("x") == object2.getJSONObject("start").getDoubleValue("x") &&
- object1.getJSONObject("end").getDoubleValue("y") == object2.getJSONObject("start").getDoubleValue("y") &&
- object1.getJSONObject("start").getDoubleValue("x") == object2.getJSONObject("end").getDoubleValue("x") &&
- object1.getJSONObject("start").getDoubleValue("y") == object2.getJSONObject("end").getDoubleValue("y") ){
- System.out.println("相似obj1:" + object1.toJSONString());
- System.out.println("相似obj2:" + object2.toJSONString());
- if(!repeat2.contains(object1)){
- if(repeat.contains(object1)){
- removeAgain.set(true);
- }
- repeat.add(object1);
- repeat2.add(object2);
- }
- }
- // System.out.println("obj1:" + object1.toJSONString());
- // System.out.println("obj2:" + object2.toJSONString());
- }
- }
- }
- System.out.println("repeatSize: "+ repeat.size());
- System.out.println("repeat: "+ repeat.toJSONString());
- walls.removeAll(repeat);
- System.out.println("newWallsSize1: "+ walls.size());
- return walls;
- }
- */
- public JSONArray removeRepeat(JSONArray walls){
- JSONArray result = new JSONArray();
- for(int i=0;i<walls.size();++i){
- Boolean flag = true;
- JSONObject wall = walls.getJSONObject(i);
- for(int j=0;j<result.size();++j){
- JSONObject _wall = result.getJSONObject(j);
- if((_wall.getIntValue("a") == wall.getIntValue("a") && _wall.getIntValue("b") == wall.getIntValue("b")) ||
- (_wall.getIntValue("a") == wall.getIntValue("b")&&_wall.getIntValue("b") == wall.getIntValue("a"))){
- wallMapping.put(wall.getString("id"), _wall.getIntValue("id"));
- flag = false;
- break;
- }
- }
- if(flag){
- result.add(wall);
- }
- }
- // System.out.println(wallMapping.toJSONString());
- return result;
- }
- /**
- * 冒泡排序
- * @param arr
- * @param type 0是获取最小值,1是获取最大值
- * @return
- */
- public static double getBubbleSortData(double[] arr, int type){
- if(arr == null){
- return 0;
- }
- //冒泡排序
- for(int i = 0;i < arr.length-1; i++){
- for(int j = 0;j < arr.length-1-i; j++){
- if(arr[j] > arr[j+1]){
- double temp = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = temp;
- }
- }
- }
- if(type == 1){
- return arr[arr.length - 1];
- }
- return arr[0];
- }
- public static void main(String args[]) throws Exception {
- // Map<String, Double> map = getMaxOrMinValue("F:\\桌面\\c11m-T11-EA\\vision.txt");
- // System.out.println("bottom:" + map.get("translationAverage"));
- // System.out.println("top:" + map.get("puckAverage"));
- ConvertCadKjl cad = new ConvertCadKjl();
- String data = FileUtils.readFile("D:\\floor.json");
- JSONObject inputJson = null;
- JSONArray inputArray = null;
- Map<String, Double> map = null;
- if(StringUtil.isNotEmpty(data)){
- inputJson = JSON.parseObject(data);
- if(inputJson.containsKey("floors")){
- JSONObject resultJson = new JSONObject();
- JSONArray resultArray = new JSONArray();
- inputArray = inputJson.getJSONArray("floors");
- for(int i = 0, len = inputArray.size(); i < len; i++){
- cad = new ConvertCadKjl();
- cad.init(inputArray.getJSONObject(i));
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- walls = cad.removeRepeat(walls);
- //判断是否需要重复出去墙
- // AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- /*
- walls = removeRepeat(walls, removeAgain);
- while (removeAgain.get()){
- //再去除一遍重复的墙,防止有多次重复的墙剩下
- walls = removeRepeat(walls, removeAgain);
- }
- */
- // walls = removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- // if(map != null){
- // JSONObject scene = new JSONObject();
- // scene.put("bottom", map.get("puckAverage"));
- // scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage") + 2.7);
- // cad.output.put("scene", scene);
- // }
- map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- // cad.output.put("version", floorPublishVer);
- resultArray.add(cad.output);
- }
- resultJson.put("floors", resultArray);
- writeBinary(resultJson.toString().getBytes(), "F:\\文档\\WeChat Files\\Iove-bing\\FileStorage\\File\\2021-01\\kjl.json");
- }else {
- cad.init(inputJson);
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- walls = cad.removeRepeat(walls);
- //判断是否需要重复出去墙
- // AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- /*
- walls = removeRepeat(walls, removeAgain);
- while (removeAgain.get()){
- //再去除一遍重复的墙,防止有多次重复的墙剩下
- walls = removeRepeat(walls, removeAgain);
- }
- */
- // walls = removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- map = ConvertCadKjl.getMaxOrMinValue(inputJson);
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- writeBinary(cad.output.toString().getBytes(), "F:\\文档\\WeChat Files\\Iove-bing\\FileStorage\\File\\2021-01\\kjl.json");
- }
- }
- // ConvertCadKjl cad = new ConvertCadKjl();
- // cad.init("G:\\javaProject\\baidu-master\\floor.json");
- // cad.input = cad.preHandle(cad.input);
- // JSONArray walls = cad.getWalls();
- // System.out.println(walls.toJSONString());
- // double[] arr = new double[]{-12,3,2,34,5,8,1};
- // System.out.println(getBubbleSortData(arr, 1));
- }
- }
|