xzw vor 1 Jahr
Ursprung
Commit
f8bd5b5c52
1 geänderte Dateien mit 88 neuen und 94 gelöschten Zeilen
  1. 88 94
      service/PanoBoxFrame.js

+ 88 - 94
service/PanoBoxFrame.js

@@ -15,7 +15,7 @@ const convertTool = {
 }
 
 //----------------------复制以下内容--------------------------------- 
-  
+
 let player,
     skyBoxTight,
     meshGroup,
@@ -32,6 +32,9 @@ let player,
 
 const MinBoxInitialScore = 0.68 //找不到匹配时,若box分数低于该值,不createSinglePano
 
+
+
+
 let standards = {
     cabinet: {
         widthNormal: { min: 0.55, max: 1.05 /* max: 0.65  */ }, //widthNormal是不计宽还是厚度的平均宽度  //个别场景如S9yepREK8Jl 宽0.8米
@@ -509,24 +512,25 @@ let getOtherPos = box => {
     }
 }
 
-let getUVs = (box,imageWidth,imageHeight) => {
+let getUVs = (box, imageWidth, imageHeight) => {
     if (box.bbox2) return
     let uvs = []
-    if(!imageWidth){
+    if (!imageWidth) {
         imageWidth = boxFrame.datas[box.pano.id].imageWidth
         imageHeight = boxFrame.datas[box.pano.id].imageHeight
-    } 
-    if(imageWidth != imageWidth || imageHeight != imageHeight){
-        console.log(imageWidth,imageHeight)
     }
-    box.bbox2 = box.bbox.map((e, i) => {    //(x1,y1,x2,y2)
+    if (imageWidth != imageWidth || imageHeight != imageHeight) {
+        console.log(imageWidth, imageHeight)
+    }
+    box.bbox2 = box.bbox.map((e, i) => {
+        //(x1,y1,x2,y2)
         return i % 2 == 0 ? e / imageWidth /*   + 0.25 */ : e / imageHeight
     })
 }
 
-let getBoxBase = (box,imageWidth,imageHeight) => {
+let getBoxBase = (box, imageWidth, imageHeight) => {
     getBoxType(box)
-    getUVs(box,imageWidth,imageHeight)
+    getUVs(box, imageWidth, imageHeight)
     getCenterDir(box)
     getOtherPos(box)
 }
@@ -712,7 +716,7 @@ let getBoxPos = info => {
     )
 }
 
-let isType = (category, type) => { 
+let isType = (category, type) => {
     return type == category || typeNames[type] instanceof Array ? typeNames[type].includes(category) : typeNames[type] == category
 }
 
@@ -731,13 +735,11 @@ let getBoxType = info => {
                 type = i
                 break //type = typeNamesReverse[type]
             } */
-            
-            
-            if (isType(category,i)){
+
+            if (isType(category, i)) {
                 type = i
                 break
             }
-            
         }
         /* if(type == 'ac' || type == 'dc'){
             type = 'electric'  //合并
@@ -1263,49 +1265,50 @@ let getLeftRight = boxArr => {
     }
 }
 
+;(global.searchCount1 = 0), (global.escapeCount1 = 0)
 
-window.searchCount1 = 0, window.escapeCount1 = 0
-
-let searchPair = (beginItem, group0_, group1_, parentPairs, resultPairs, evaluateFun, minScore) => {//配对结果个数为n!,其中n是每组的元素个数。注意当n=10时,已经有40320个,非常恐怖。
-    let pair = [] , parentExit = !!parentPairs
-    let removeParent = ()=>{ //元结点裂变出多个,来装新的pair
-        if(parentExit){
+let searchPair = (beginItem, group0_, group1_, parentPairs, resultPairs, evaluateFun, minScore) => {
+    //配对结果个数为n!,其中n是每组的元素个数。注意当n=10时,已经有40320个,非常恐怖。
+    let pair = [],
+        parentExit = !!parentPairs
+    let removeParent = () => {
+        //元结点裂变出多个,来装新的pair
+        if (parentExit) {
             let i = resultPairs.indexOf(parentPairs)
             resultPairs.splice(i, 1)
             parentExit = false
         }
-        
-    } 
-    if (!parentPairs) {//首次
-        if(group0_.length == 0 || group1_.length == 0 )return 
+    }
+    if (!parentPairs) {
+        //首次
+        if (group0_.length == 0 || group1_.length == 0) return
         //保证第一个的个数<=第二个,否则第一组多出来的永远匹配不上
         if (group0_.length > group1_.length) {
             let t = group0_
             group0_ = group1_
             group1_ = t
-        }  
-        beginItem = group0_[0]  
-        let complex = Object.keys(boxFrame.datas).length 
-        if(complex < 10) evaluateFun = null 
-        else  minScore = math.linearClamp(complex, 10, 80,  -4000, -500) 
-         
+        }
+        beginItem = group0_[0]
+        let complex = Object.keys(boxFrame.datas).length
+        if (complex < 10) evaluateFun = null
+        else minScore = math.linearClamp(complex, 10, 80, -4000, -500)
+
         //console.log('searchPair length',group0_.length,group1_.length)
-        
     }
-    searchCount1 ++
+    searchCount1++
     for (let j = 0; j < group1_.length; j++) {
         pair = [beginItem, group1_[j]]
         //if(pair[0].sid == 'void' || pair[1].sid == 'void')continue
         let evaluate
-        if(evaluateFun/*  && !(pair[0].sid == 'void' || pair[1].sid == 'void') */){
-            evaluate = evaluateFun(pair[0],pair[1]); 
-            if(evaluate == void 0 || evaluate.score<=minScore){
+        if (evaluateFun /*  && !(pair[0].sid == 'void' || pair[1].sid == 'void') */) {
+            evaluate = evaluateFun(pair[0], pair[1])
+            if (evaluate == void 0 || evaluate.score <= minScore) {
                 //console.log('因为评估出匹配可能性低所以跳过',pair[0],pair[1],evaluate)
-                escapeCount1 ++
+                escapeCount1++
                 continue
             }
-        } 
-         
+        }
+
         let newPairs //用来存放该组pair
         if (parentPairs) {
             removeParent()
@@ -1324,22 +1327,12 @@ let searchPair = (beginItem, group0_, group1_, parentPairs, resultPairs, evaluat
         newGroup1.splice(index, 1)
 
         if (newGroup0.length > 0 && newGroup1.length > 0) {
-            searchPair(newGroup0[0], newGroup0, newGroup1, newPairs, resultPairs, evaluateFun, minScore )
+            searchPair(newGroup0[0], newGroup0, newGroup1, newPairs, resultPairs, evaluateFun, minScore)
         }
     }
 }
 //如果第一个元素就和后面所有的都不匹配,就直接返回了怎么办?
 
-
-
-
-
- 
-
-
-
-
-
 export default class PanoBoxFrame extends THREE.Group {
     constructor(player_, ifAnalyze, dataList) {
         super()
@@ -1368,7 +1361,7 @@ export default class PanoBoxFrame extends THREE.Group {
         this.datasMixed = {}
         this.boxesSolid = boxesSolid
 
-        let metadata = await player.$app.resource.metadata()
+        let metadata = player.$app.store.getValue('metadata') //await player.$app.resource.metadata()
         isLaser = metadata.sceneFrom == 'laser'
 
         let compu = 0
@@ -2108,14 +2101,14 @@ export default class PanoBoxFrame extends THREE.Group {
                             if (searchType == 'second') rowBigBoxes_1 = rowBigBoxes_1.filter(e => !matchGroups.some(u => u.includes(e)))
 
                             let pano1 = groups[j][0].pano
-if(pano0.id == 54 && pano1.id == 56){
-    console.log(2)
-}
-                            let resultPairs = [] 
-                            let evaluateFun = (row0, row1)=>{
+                            if (pano0.id == 54 && pano1.id == 56) {
+                                console.log(2)
+                            }
+                            let resultPairs = []
+                            let evaluateFun = (row0, row1) => {
                                 return getRowMatchInfo(row0, row1, ignoreCountMatch)
-                            } 
-                            searchPair(null/* bigBoxes_0[0] */, rowBigBoxes_0.slice(), rowBigBoxes_1.slice(), null, resultPairs,  evaluateFun)
+                            }
+                            searchPair(null /* bigBoxes_0[0] */, rowBigBoxes_0.slice(), rowBigBoxes_1.slice(), null, resultPairs, evaluateFun)
 
                             resultPairs = resultPairs.map(pairs => {
                                 let infos = pairs.map(pair => (pair.some(e => e.sid == 'void') ? null : getRowMatchInfo(pair[0], pair[1], ignoreCountMatch)))
@@ -2138,27 +2131,28 @@ if(pano0.id == 54 && pano1.id == 56){
                                 console.log(111)
                             } */
 
-                            resultPairs[0] && resultPairs[0].pairs.forEach((pair, i) => {
-                                let info = resultPairs[0].infos[i]
-                                if (info && info.score > minScore) {
-                                    allRelations.push(info)
-                                    let items = pair.filter(e => e.sid != 'void')
-                                    common.pushToGroupAuto(items, matchGroups, null, atGroup => {
-                                        //需要朝向一致才行
-                                        if (!info.k) return true //(box识别的宽高识别不准所以不需要)
-                                        let onePair = atGroup.relationships[0]
-                                        let name = onePair[0].sid + '&' + onePair[1].sid
-                                        if (!rowInfos[name].k) return true //不过不应该有这种情况,否则匹配不到一起才对
-
-                                        if ((rowInfos[name].k < 1 && info.k < 1) || (rowInfos[name].k > 1 && info.k > 1)) {
-                                            return true
-                                        } else {
-                                            console.log('k不一致无法匹配', info, atGroup)
-                                        }
-                                    })
-                                    //根据目前的规则应该是有端点的和有端点的匹配,box和box匹配
-                                }
-                            })
+                            resultPairs[0] &&
+                                resultPairs[0].pairs.forEach((pair, i) => {
+                                    let info = resultPairs[0].infos[i]
+                                    if (info && info.score > minScore) {
+                                        allRelations.push(info)
+                                        let items = pair.filter(e => e.sid != 'void')
+                                        common.pushToGroupAuto(items, matchGroups, null, atGroup => {
+                                            //需要朝向一致才行
+                                            if (!info.k) return true //(box识别的宽高识别不准所以不需要)
+                                            let onePair = atGroup.relationships[0]
+                                            let name = onePair[0].sid + '&' + onePair[1].sid
+                                            if (!rowInfos[name].k) return true //不过不应该有这种情况,否则匹配不到一起才对
+
+                                            if ((rowInfos[name].k < 1 && info.k < 1) || (rowInfos[name].k > 1 && info.k > 1)) {
+                                                return true
+                                            } else {
+                                                console.log('k不一致无法匹配', info, atGroup)
+                                            }
+                                        })
+                                        //根据目前的规则应该是有端点的和有端点的匹配,box和box匹配
+                                    }
+                                })
 
                             //console.log(resultPairs[0])
                         }
@@ -2854,7 +2848,7 @@ if(pano0.id == 54 && pano1.id == 56){
                         waitFindRest.push({ type, args: [groups, 0] }) //等待最后检查遗漏
                         return
                     }
-                } 
+                }
 
                 //零散匹配。
                 let match2Group = (group0, group1, { fake }) => {
@@ -2879,9 +2873,9 @@ if(pano0.id == 54 && pano1.id == 56){
                     /* while (newGroup1.length < newGroup0.length) {
                         newGroup1.push({ sid: 'void' }) //为了使排列正确,补个空,使左右两边个数相等,过后和void匹配的不会计算box
                     } */
-                    
+
                     let evaluateFun = getMatchScore.bind(this)
-                    searchPair(/* group0[0] */null, newGroup0, newGroup1, null, resultPairs, evaluateFun)
+                    searchPair(/* group0[0] */ null, newGroup0, newGroup1, null, resultPairs, evaluateFun)
 
                     /* console.log(
                         'resultPairs',
@@ -3096,10 +3090,10 @@ if(pano0.id == 54 && pano1.id == 56){
                             let r1 = math.linearClamp(box.pano.position.distanceTo(p2), 3, 20, 1, 5) //距离远的话识别、计算都会更不准确,给一定的容错. 远的尽量不findRest,即尽量>0
 
                             let ra = (solidBox.boxType == box.boxType ? 1 : 0.5) * r0 * r1 //数字越小限制越大
-                
-if(box.sid == 'pano48-5'){
-    console.log(1)
-}
+
+                            if (box.sid == 'pano48-5') {
+                                console.log(1)
+                            }
                             /* let a = maxWidth * maxWidth * ra - p1_.distanceToSquared(p2_)
                             let b = -dis * dis * 0.7  
                             let c = a + b*/
@@ -3480,7 +3474,7 @@ if(box.sid == 'pano48-5'){
 
             let createSinglePano = (box, minScorePercent = 1) => {
                 //仅用一个pano中的data来创建。  悬挂于墙上的准确性依赖于墙的准确性。
- 
+
                 if (box.score < MinBoxInitialScore) {
                     //如Xszq2fv03b的电池pano8-0其实是纸箱、 WZQoMbNmNTu的pano14-0分数0.649
                     return console.error('取消createSinglePano: 线框识别分数低,可能错误', box.sid, box)
@@ -3657,7 +3651,7 @@ if(box.sid == 'pano48-5'){
             if (browser.urlHasValue('ext')) {
                 //利用算好的toJson的数据展示框
                 //console.log('box8',data.data)
-                data.data.box8.boxes.boxes.forEach(e => {
+                data.data.box8.dataSet.boxes.forEach(e => {
                     let point1 = math.convertVisionVector(new THREE.Vector3().fromArray(e.points[0]))
                     let point2 = math.convertVisionVector(new THREE.Vector3().fromArray(e.points[1]))
                     let point3 = math.convertVisionVector(new THREE.Vector3().fromArray(e.points[2]))
@@ -3718,9 +3712,9 @@ if(box.sid == 'pano48-5'){
         for (let panoId in this.datas) {
             if (!this.datas[panoId]) continue
             let { imageWidth, imageHeight } = this.datas[panoId]
-                
-            this.datas[panoId].shapes.forEach((box) => {
-                getBoxBase(box, imageWidth, imageHeight )
+
+            this.datas[panoId].shapes.forEach(box => {
+                getBoxBase(box, imageWidth, imageHeight)
                 if (box.sid == 'pano2-10') {
                     console.log(4)
                 }
@@ -3958,7 +3952,7 @@ if(box.sid == 'pano48-5'){
             this.load(player.currentPano.id)
         })
 
-        window.boxFrame = this
+        global.boxFrame = this
         if (this.ifAnalyze) {
             setTimeout(() => {
                 {
@@ -4040,9 +4034,9 @@ if(box.sid == 'pano48-5'){
             let labelShift = (shape.boxType == 'fire' ? 0 : -0.2) / dis
             let name = shape.category + '-' + shape.sid
             //if(shape.score < MinBoxInitialScore){
-                name = [name, 'sc: '+math.toPrecision(shape.score,3)]
+            name = [name, 'sc: ' + math.toPrecision(shape.score, 3)]
             //}
-            
+
             this.showSignalFrom2d(
                 name,
                 shape.bbox2,
@@ -4153,4 +4147,4 @@ if(box.sid == 'pano48-5'){
         //清除上一次的结果
         ;(skyBoxTight = null), (meshGroup = null), (modelBound = new THREE.Box3()), (groundY = null), (safeBound = null), (boundConfirmed = null), (hue = 0), (boxesSolid = [])
     }
-}
+}