csv2buffer.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //#if 0
  2. #include "csv2buffer.h"
  3. #include "buffer.cpp"
  4. #define BUFFSIZE 100 // size of buffers
  5. void ultdata(Buffer<UltParkinglots> &buffer,QString &filePath)
  6. {
  7. // QString filePath = QDir::currentPath() + "/../data/UltParkinglots.csv";
  8. QList<QStringList> readData = QtCSV::Reader::readToList(filePath);
  9. unsigned dataIndex = 0;
  10. for(unsigned i = 0; i<BUFFSIZE; i++)
  11. {
  12. //qDebug() << readData.at(i).join(",");
  13. UltParkinglots ults;
  14. UltParkinglot ult;
  15. QStringList rowData = readData.at(dataIndex);
  16. unsigned j = rowData[0].toInt();
  17. ult.id = rowData[0].toInt();
  18. ult.low_time_stamp = rowData[1].toInt();
  19. ult.high_time_stamp = rowData[2].toInt();
  20. ult.valid_state = rowData[3].toInt();
  21. ult.park_type = rowData[4].toInt();
  22. ult.confidence = rowData[5].toDouble();
  23. ult.valid_state = rowData[6].toDouble();
  24. ult.park_length = rowData[7].toDouble();
  25. ult.park_width = rowData[8].toDouble();
  26. ult.park_direction = rowData[9].toDouble();
  27. Corners parkingPoints;
  28. parkingPoints.corners[0] = Point(rowData[10].toDouble(),rowData[11].toDouble());
  29. parkingPoints.corners[1] = Point(rowData[12].toDouble(),rowData[13].toDouble());
  30. parkingPoints.corners[2] = Point(rowData[14].toDouble(),rowData[15].toDouble());
  31. parkingPoints.corners[3] = Point(rowData[16].toDouble(),rowData[17].toDouble());
  32. ult.ParkingPoints = parkingPoints;
  33. ults.push_back(ult);
  34. j++;
  35. dataIndex ++;
  36. rowData = readData.at(dataIndex);
  37. j = rowData[0].toInt();
  38. //qDebug() <<"角点"<< ult.ParkingPoints.corners[0].x;
  39. while(j!=0)
  40. {
  41. //qDebug() << "进入while循环 ";
  42. // qDebug() << "while循环中的j "<<j;
  43. ult.id = rowData[0].toInt();
  44. ult.low_time_stamp = rowData[1].toInt();
  45. ult.high_time_stamp = rowData[2].toInt();
  46. ult.valid_state = rowData[3].toInt();
  47. ult.park_type = rowData[4].toInt();
  48. ult.confidence = rowData[5].toDouble();
  49. ult.valid_state = rowData[6].toDouble();
  50. ult.park_length = rowData[7].toDouble();
  51. ult.park_width = rowData[8].toDouble();
  52. ult.park_direction = rowData[9].toDouble();
  53. Corners parkingPoints;
  54. parkingPoints.corners[0] = Point(rowData[10].toDouble(),rowData[11].toDouble());
  55. parkingPoints.corners[1] = Point(rowData[12].toDouble(),rowData[13].toDouble());
  56. parkingPoints.corners[2] = Point(rowData[14].toDouble(),rowData[15].toDouble());
  57. parkingPoints.corners[3] = Point(rowData[16].toDouble(),rowData[17].toDouble());
  58. ult.ParkingPoints = parkingPoints;
  59. ults.push_back(ult);
  60. dataIndex++;
  61. rowData = readData.at(dataIndex);
  62. j = rowData[0].toInt();
  63. //qDebug() <<"while尾部j的值:"<< j;
  64. }
  65. buffer.add(ults);
  66. }
  67. //qDebug() << readData.size();
  68. }
  69. void surdata(Buffer<SurViewParkinglots> &buffer,QString &filePath)
  70. {
  71. QList<QStringList> readData =
  72. QtCSV::Reader::readToList(filePath);
  73. unsigned dataIndex = 0;
  74. for(unsigned i = 0; i<BUFFSIZE; i++)
  75. {
  76. // qDebug() << readData.at(i).join(",");
  77. SurViewParkinglots survs;
  78. SurViewParkinglot surv;
  79. QStringList rowData = readData.at(dataIndex);
  80. unsigned j = rowData[0].toInt();
  81. surv.id = rowData[0].toInt();
  82. surv.low_time_stamp = rowData[1].toInt();
  83. surv.high_time_stamp = rowData[2].toInt();
  84. surv.valid_state = rowData[3].toInt();
  85. surv.park_type = rowData[4].toInt();
  86. surv.confidence = rowData[5].toDouble();
  87. //qDebug() << surv.confidence;
  88. surv.park_length = rowData[6].toDouble();
  89. surv.park_width = rowData[7].toDouble();
  90. surv.park_direction = rowData[8].toDouble();
  91. Corners parkingPoints;
  92. parkingPoints.corners[0] = Point(rowData[9].toDouble(),rowData[10].toDouble());
  93. parkingPoints.corners[1] = Point(rowData[11].toDouble(),rowData[12].toDouble());
  94. parkingPoints.corners[2] = Point(rowData[13].toDouble(),rowData[14].toDouble());
  95. parkingPoints.corners[3] = Point(rowData[15].toDouble(),rowData[16].toDouble());
  96. surv.ParkingPoints = parkingPoints;
  97. survs.push_back(surv);
  98. j++;
  99. dataIndex++;
  100. rowData = readData.at(dataIndex);
  101. j = rowData[0].toInt();
  102. //qDebug() << j;
  103. while(j!=0)
  104. {
  105. //qDebug() << "进入while循环 ";
  106. surv.id = rowData[0].toInt();
  107. surv.low_time_stamp = rowData[1].toInt();
  108. surv.high_time_stamp = rowData[2].toInt();
  109. surv.valid_state = rowData[3].toInt();
  110. surv.park_type = rowData[4].toInt();
  111. surv.confidence = rowData[5].toDouble();
  112. surv.park_length = rowData[6].toDouble();
  113. surv.park_width = rowData[7].toDouble();
  114. surv.park_direction = rowData[8].toDouble();
  115. Corners parkingPoints;
  116. parkingPoints.corners[0] = Point(rowData[9].toDouble(),rowData[10].toDouble());
  117. parkingPoints.corners[1] = Point(rowData[11].toDouble(),rowData[12].toDouble());
  118. parkingPoints.corners[2] = Point(rowData[13].toDouble(),rowData[14].toDouble());
  119. parkingPoints.corners[3] = Point(rowData[15].toDouble(),rowData[16].toDouble());
  120. surv.ParkingPoints = parkingPoints;
  121. survs.push_back(surv);
  122. dataIndex++;
  123. rowData = readData.at(dataIndex);
  124. j = rowData[0].toInt();
  125. //qDebug() << "while循环结束 "<<j;
  126. }
  127. buffer.add(survs);
  128. }
  129. //qDebug() << readData.size();
  130. }
  131. void cardata(Buffer<CarState> &buffer, QString &filePath)
  132. {
  133. QList<QStringList> readData =
  134. QtCSV::Reader::readToList(filePath);
  135. unsigned dataIndex = 0;
  136. for(unsigned i = 0; i<BUFFSIZE; i++)
  137. {
  138. CarState carState;
  139. // SurViewParkinglots survs;
  140. // SurViewParkinglot surv;
  141. // QStringList rowData = readData.at(dataIndex);
  142. // unsigned j = rowData[0].toInt();
  143. // surv.id = rowData[0].toInt(.);
  144. QStringList rowData = readData.at(dataIndex);
  145. carState.x = rowData[0].toDouble();
  146. carState.y = rowData[1].toDouble();
  147. carState.speed = rowData[2].toDouble();
  148. carState.ins_heading_angle = rowData[3].toDouble();
  149. buffer.add(carState);
  150. dataIndex++;
  151. if(dataIndex>=readData.size())
  152. {
  153. break;
  154. }
  155. // qDebug() << readData.size();
  156. }
  157. }
  158. void obsdata(Buffer<Obstacles> &buffer, QString &filePath){
  159. QList<QStringList> readData =
  160. QtCSV::Reader::readToList(filePath);
  161. unsigned dataIndex = 0;
  162. for(unsigned i = 0; i<BUFFSIZE; i++){
  163. Obstacles obstacles;
  164. Obstacle obstacle;
  165. bool br = false;
  166. for(unsigned j = 0; j<3; j++){
  167. QStringList rowData = readData.at(dataIndex);
  168. obstacle.id = rowData[0].toInt();
  169. obstacle.type = rowData[1].toInt();
  170. obstacle.state = rowData[2].toInt();
  171. obstacle.confidence = rowData[3].toDouble();
  172. obstacle.valid_time = rowData[4].toDouble();
  173. obstacle.pos_x = rowData[5].toDouble();
  174. obstacle.pos_y = rowData[6].toDouble();
  175. obstacle.length = rowData[7].toDouble();
  176. obstacle.width = rowData[8].toDouble();
  177. obstacle.height = rowData[9].toDouble();
  178. obstacle.rel_speed_x = rowData[10].toDouble();
  179. obstacle.rel_speed_y = rowData[11].toDouble();
  180. obstacle.abs_speed_x = rowData[12].toDouble();
  181. obstacle.abs_speed_y = rowData[13].toDouble();
  182. obstacle.heading = rowData[14].toDouble();
  183. obstacles.push_back(obstacle);
  184. dataIndex++;
  185. if(dataIndex >= readData.size()){
  186. br = true;
  187. break;
  188. }
  189. }
  190. buffer.add(obstacles);
  191. if(br){
  192. break;
  193. }
  194. }
  195. }