分享
查看: 3058|回复: 0

[分享] 电子围栏可视化,提高安全运维效率

[复制链接]

电子围栏可视化,提高安全运维效率

发表于 2021-8-19 14:04:43 来自 分享 阅读模式 倒序浏览
zzv_icon3058 zzr_icon0 查看全部
现代工业化的推进在极大加速现代化进程的同时也带来的相应的安全隐患,在传统的监控领域,一般都是基于Web前端技术来实现 2D 可视化监控,本文采用ThingJS来构造轻量化的 3D 可视化场景,该3D场景展示了一个现代化商场的数字孪生可视化场景,包括人员的实时位置、电子围栏的范围、现场的安全情况等等,帮助直观的了解当前人员的安全状况。

电子围栏又称周界防盗报警系统,监控防区工作状态,实景中的电子围栏系统用于农业、畜牧业,以及监狱、军事设施等安全敏感地区。ThingJS平台上,电子围栏指的是一个区域,使用PolygonRegion属性。创建物体对象或模型并开启移动功能,即可开始检测目标点是否进入电子围栏区域,判断true或false显示告警反应。

电子围栏可视化,提高安全运维效率



本篇文章通过对数字孪生可视化场景的搭建和模型的加载,人物实时定位代码的实现、电子围栏和轨迹图的实现进行阐述,了解如何通过使用ThingJS实现一个简单的3D电子围栏可视化。

  1. // 添加电子围栏
  2. new THING.widget.Button('添加电子围栏', function() {
  3. // 构成多边形的点(取世界坐标系下的坐标)
  4. points = [
  5. [81, 0.5, 63],
  6. [81, 0.5, 52],
  7. [72, 0.5, 52],
  8. [72, 0.5, 63]
  9. ];
  10. if (polygonMarker) { return; }
  11. // 创建电子围栏(区域)
  12. polygonMarker = app.create({
  13. type: 'PolygonRegion',
  14. points: points, // 传入世界坐标系下点坐标
  15. style: {
  16. regionOpacity: .6,
  17. regionColor: '#3CF9DF', // 区域颜色
  18. lineColor: '#3CF9DF' // 线框颜色
  19. }
  20. });
  21. // 设置永远在最上层显示
  22. polygonMarker.style.alwaysOnTop = false;
  23. })
复制代码


电子围栏可视化,提高安全运维效率



当人物或物体对象出发警报时,有2种方式提醒注意,一是踏足的禁区围栏颜色发生改变;二是展示面板显示报警信息,可视化监控目标点的移动范围。

完整代码如下:

  1. // 添加图片标注
  2. new THING.widget.Button('添加图片标注', function() {
  3. var coord = [83, 0.5, 61];
  4. if (marker1) { return; }
  5. // 创建目标点(marker)
  6. marker1 = app.create({
  7. type: "Marker",
  8. id: "marker1",
  9. url: "/guide/examples/images/navigation/user.png",
  10. position: coord,
  11. size: 1
  12. })
  13. })

  14. var point = [
  15. [81, 63],
  16. [81, 52],
  17. [72, 52],
  18. [72, 63]
  19. ];
  20. // 移动图片标注
  21. new THING.widget.Button('移动图片标注', function() {
  22. var markerEndPoint = [68, 0.5, 55];
  23. if (marker1 != null) {
  24. var moveState = marker1.getAttribute('moveState');
  25. if (moveState == 'complete') {
  26. marker1.off('update', null, '监控图片标注');
  27. return;
  28. }
  29. // 目标点移动
  30. marker1.moveTo({
  31. position: markerEndPoint, // 移动到终点位置
  32. time: 2 * 1000,
  33. orientToPath: true, // 沿路径方向
  34. complete: function(ev) {
  35. marker1.off('update', null, '监控图片标注');
  36. $('.warninfo1').css('display', 'none');
  37. $('.warninfo2').css('display', 'block');
  38. $('.warninfo3').css('display', 'none');
  39. marker1.setAttribute('moveState', 'complete');
  40. }
  41. })
  42. }
  43. if (points != null) {
  44. // 监控图片标注是否进入电子围栏区域
  45. if (marker1 != null) {
  46. marker1.on('update', function() {
  47. if (polygonMarker != null) {
  48. var intoPolygonMarker = isInPolygon([marker1.position[0], marker1.position[2]], point);
  49. if (intoPolygonMarker) {
  50. polygonMarker.regionColor = '#a94442';
  51. polygonMarker.lineColor = '#a94442'
  52. $('.warninfo1').css('display', 'block');
  53. $('.warninfo2').css('display', 'none');
  54. $('.warninfo3').css('display', 'none');
  55. } else {
  56. polygonMarker.regionColor = '#3CF9DF';
  57. polygonMarker.lineColor = '#3CF9DF'
  58. $('.warninfo1').css('display', 'none');
  59. $('.warninfo2').css('display', 'none');
  60. $('.warninfo3').css('display', 'block');
  61. }
  62. }
  63. }, '监控图片标注')
  64. }
  65. }
  66. })

  67. // 添加模型标注
  68. new THING.widget.Button('添加模型标注', function() {
  69. //创建目标点(Obj)
  70. people = app.query('#worker')[0];
  71. people.position = [83, 0.1, 56];
  72. people.visible = true;
  73. people.scale = [1.5, 1.5, 1.5];
  74. })

  75. // 移动模型标注
  76. new THING.widget.Button('移动模型标注', function() {
  77. var objEndPoint = [70, 0.1, 60];
  78. if (people != null) {
  79. var moveState = people.getAttribute('moveState');
  80. if (moveState == 'complete') {
  81. people.off('update', null, '监控图片标注');
  82. return;
  83. }
  84. // 播放模型动画
  85. people.playAnimation({
  86. name: '走',
  87. speed: 1,
  88. loopType: THING.LoopType.Repeat,
  89. });
  90. // 模型移动
  91. people.moveTo({
  92. position: objEndPoint, // 移动到终点位置
  93. orientToPath: true, // 沿路径方向
  94. time: 8 * 1000,
  95. complete: function(ev) {
  96. people.stopAnimation('走');
  97. people.off('update', null, '监控模型标注');
  98. $('.warninfo1').css('display', 'none');
  99. $('.warninfo2').css('display', 'block');
  100. $('.warninfo3').css('display', 'none');
  101.   people.setAttribute('moveState', 'complete');
  102. }
  103. })
  104. }
  105. if (points != null) {
  106. // 监控模型标注是否进入电子围栏区域
  107. if (people != null) {
  108. people.on('update', function() {
  109. if (polygonMarker != null) {
  110. var intoPolygonMarker = isInPolygon([people.position[0], people.position[2]], point);
  111. if (intoPolygonMarker) {
  112. polygonMarker.regionColor = '#a94442';
  113. polygonMarker.lineColor = '#a94442'
  114. $('.warninfo1').css('display', 'block');
  115. $('.warninfo2').css('display', 'none');
  116. $('.warninfo3').css('display', 'none');
  117. } else {
  118. polygonMarker.regionColor = '#3CF9DF';
  119. polygonMarker.lineColor = '#3CF9DF'
  120. $('.warninfo1').css('display', 'none');
  121. $('.warninfo2').css('display', 'none');
  122. $('.warninfo3').css('display', 'block');
  123. }
  124. }
  125. }, '监控模型标注')
  126. }
  127. }
  128. })

  129. // 重置
  130. new THING.widget.Button('重置', function() {
  131. if (polygonMarker) {
  132. polygonMarker.destroy();
  133. polygonMarker = null;
  134. }
  135. if (marker1) {
  136. marker1.destroy();
  137. marker1 = null;
  138. }
  139. if (people) {
  140. people.visible = false;
  141. people.setAttribute('moveState', null);
  142. }
  143. $('.warninfo1').css('display', 'none');
  144. $('.warninfo1').css('display', 'none');
  145. $('.warninfo1').css('display', 'block');
  146. })

  147. createTip(); // 创建提示面板
  148. });

  149. /**
  150. * 创建提示面板
  151. */
  152. function createTip() {
  153. var html =
  154. `<div class="fencing" style="width:200px;position: absolute;top: 50px;left: 50%;transform: translateX(-50%);z-index: 999;">
  155. <div class="alert alert-danger warninfo1" role="alert" style="padding: 15px;margin-bottom: 20px;color: #a94442;background-color: #f2dede;border-color: #ebccd1;border-radius: 4px;display:none;">目标已进入围栏</div>
  156. <div class="alert alert-info warninfo2" role="alert" style="padding: 15px;margin-bottom: 20px;color: #31708f;background-color: #d9edf7;border-color: #bce8f1;border-radius: 4px;display:none;">到达目的地</div>
  157. <div class="alert alert-warning warninfo3" role="alert" style="padding: 15px;margin-bottom: 20px;color: #8a6d3b;background-color: #fcf8e3;border-color: #faebcc;border-radius: 4px;">目标未进入围栏</div>

  158. <div onclick="fenClose()" style="cursor: pointer;position: absolute;top: -7px;right: -8px;width: 16px;height: 16px;border-radius: 50%;background-color: #777777;border: 3px solid #ffffff;">
  159. <div style="position: absolute;width: 10px;height: 2px;background-color: #fff;transform: rotate(45deg);top: 7px;left: 3px;"></div>
  160. <div style="position: absolute;width: 10px;height: 2px;background-color: #fff;transform: rotate(-45deg);top: 7px;left: 3px;"></div>
  161. </div>
  162. </div>`;
  163. $('#div2d').append($(html));
  164. }

  165. /**
  166. * 关闭提示面板
  167. */
  168. function fenClose() {
  169. $(".fencing").hide();
  170. }
  171. /**
  172. * 检测目标点是否进入电子围栏区域
  173. * @param {Array} checkPoint - 校验坐标
  174. * @param {Array} polygonPoints - 形成电子围栏的坐标
  175. * @returns {Boolean} true 或 false
  176. * @description 此方法仅判断处于同一个平面的目标点是否在区域内(只判断坐标x和z值),
  177. * 不考虑两者当前离地高度(坐标的y值)
  178. */
  179. function isInPolygon(checkPoint, polygonPoints) {
  180. var counter = 0;
  181. var i;
  182. var xinters;
  183. var p1, p2;
  184. var pointCount = polygonPoints.length;
  185. p1 = polygonPoints[0];
  186. for (i = 1; i <= pointCount; i++) {
  187. p2 = polygonPoints[i % pointCount];
  188. if (checkPoint[0] > Math.min(p1[0], p2[0]) && checkPoint[0] <= Math.max(p1[0], p2[0])) {
  189. if (checkPoint[1] <= Math.max(p1[1], p2[1])) {
  190. if (p1[0] != p2[0]) {
  191. xinters = (checkPoint[0] - p1[0]) * (p2[1] - p1[1]) / (p2[0] - p1[0]) + p1[1];
  192. if (p1[1] == p2[1] || checkPoint[1] <= xinters) {
  193. counter++;
  194. }
  195. }
  196. }
  197. }
  198. p1 = p2;
  199. }
  200. if (counter % 2 == 0) {
  201. return false;
  202. } else {
  203. return true;
  204. }
  205. }
复制代码


avatar
游客~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

130700ppkpl8x3t7tt1b1t