test.java 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.fdkk.fdkkmeta.test;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.core.io.file.FileWriter;
  4. import cn.hutool.core.util.URLUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.fdkk.fdkkmeta.po.RoutePO;
  9. import com.fdkk.fdkkmeta.util.FileUtils;
  10. import java.io.BufferedReader;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13. import java.nio.charset.Charset;
  14. import java.text.SimpleDateFormat;
  15. import java.util.*;
  16. import java.util.stream.Collectors;
  17. /**
  18. * @author Xiewj
  19. * @date 2022/3/29
  20. */
  21. public class test {
  22. // public static void main(String[] args) throws IOException {
  23. // int d=6;
  24. // int fps=2 % d;
  25. // if (fps!=0){
  26. // fps=2/d+1;
  27. // }
  28. //
  29. // System.out.println(fps);
  30. //
  31. // }
  32. public static void main(String[] args) throws IOException {
  33. String path="C:\\Users\\4DAGE\\Downloads\\final_freespace(1).csv";
  34. createdPointsJson(path);
  35. creatTargetJson(path);
  36. }
  37. private static void createdPointsJson(String path) {
  38. List<String> list = FileUtils.readFileByLines2(path);
  39. JSONArray array=new JSONArray();
  40. FileWriter writer=new FileWriter("D:\\video\\points.json");
  41. for (int i = 0; i < list.size(); i++) {
  42. JSONObject jsonObject=new JSONObject();
  43. String[] s = list.get(i).split(" ");
  44. jsonObject.put("id",i );
  45. JSONObject position=new JSONObject();
  46. position.put("x",Double.valueOf(s[0]));
  47. position.put("y",Double.valueOf(s[1]));
  48. position.put("z",Double.valueOf(s[2]));
  49. jsonObject.put("position",position);
  50. JSONObject rotation=new JSONObject();
  51. rotation.put("x",0.0);
  52. rotation.put("y",0.0);
  53. rotation.put("z",0.0);
  54. rotation.put("w",1.0);
  55. jsonObject.put("rotation",rotation);
  56. List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
  57. List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
  58. return Integer.parseInt(a)-1;
  59. }).collect(Collectors.toList());
  60. jsonObject.put("contact",contact);
  61. array.add(jsonObject);
  62. }
  63. writer.write(array.toJSONString());
  64. }
  65. private static void creatTargetJson(String path) {
  66. List<String> list = FileUtils.readFileByLines2(path);
  67. List<String> collect = new ArrayList<>();
  68. FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
  69. for (int i = 0; i < list.size(); i++) {
  70. RoutePO po = new RoutePO();
  71. String[] s = list.get(i).split(" ");
  72. po.setId(i );
  73. if (s.length == 12) {
  74. double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
  75. po.setX(oldPoint[0]);
  76. po.setY(oldPoint[1]);
  77. po.setZ(oldPoint[2]);
  78. po.setWeight(Double.parseDouble(s[3]));
  79. List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
  80. List<Integer> contact = strings.stream().map(a->{
  81. if (Integer.parseInt(a)!=-1){
  82. return Integer.parseInt(a)-1;
  83. }
  84. return Integer.parseInt(a);
  85. }).collect(Collectors.toList());
  86. po.setIds(contact);
  87. }
  88. collect.add(JSON.toJSONString(po));
  89. }
  90. writer.writeLines(collect);
  91. }
  92. }