@labelbee/lb-annotation 1.27.0-alpha.40 → 1.27.0-alpha.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js"),omniCamera=require("./omniCamera.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),i=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),f=createThreeMatrix4(i),a=createThreeMatrix4(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const i=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),o=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function isMatrixValid(e,t,r){return!(e.length!==t||e.some(n=>n.length!==r))}const isMatrixValidByArr=(e,t)=>t.some(r=>isMatrixValid(e,r[0],r[1])),isFisheyeCalibValid=e=>{var t;return!!(((t=e.fisheyeDistortion)==null?void 0:t.length)>0&&isMatrixValidByArr(e.P,[[3,4],[4,4]])&&isMatrixValidByArr(e.T,[[3,4],[4,4]]))},oCamFisheyeTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i)),f=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=o.applyMatrix4(l),x=__pow(__pow(a.x,2)+__pow(a.y,2),.5),p=Math.atan(a.z/x),s=n.reduce((c,u,h)=>c+u*__pow(p,h),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)},omniCamera11VTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=omniCamera.transformPointCloudToImage([[e.x,e.y,e.z]],i,r,n);return new THREE__namespace.Vector4(o[0][0],o[0][1],1)},kbCamFisheyeTransfer=(e,t)=>{const{P:r,T:n,fisheyeDistortion:i}=t,o=[e.x,e.y,e.z,1],l=n.map(g=>g.reduce((M,v,_)=>M+v*o[_],0)),f=l[0],a=l[1],x=l[2];if(!(x>=.01&&isFinite(x)))return;const p=[[r[0][0],r[0][1]],[r[1][0],r[1][1]]],s=r[0][2],y=r[1][2],c=Math.sqrt(f*f+a*a),u=Math.atan2(c,x),h=u+i.reduce((g,M,v)=>g+M*Math.pow(u,2*v+3),0);let m,d;c!==0?(m=f*h/c,d=a*h/c):(m=0,d=0);const T=p[0][0]*m+p[0][1]*d,P=p[1][0]*m+p[1][1]*d;return{x:T+s,y:P+y}},lidar2FisheyeImage=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera)return oCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.KannalaBrandt)return kbCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera11V)return omniCamera11VTransfer(e,t)};function lidar2image(e,t){const n=new THREE__namespace.Vector4(e.x,e.y,e.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new THREE__namespace.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function getCuboidFromPointCloudBox(e){const{center:t,width:r,height:n,depth:i,rotation:o}=e,l=[{x:t.x+r/2,y:t.y-n/2},{x:t.x+r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y-n/2}].map(x=>{const p=rotatePoint(x,t,o);return{x:p.x,y:p.y}}),f=t.z+i/2,a=t.z-i/2;return __spreadProps(__spreadValues({},e),{polygonPointList:l,zMax:f,zMin:a})}function sortPoints(e){const t=e.slice();return t.sort((r,n)=>r.x===n.x?n.y-r.y:r.x-n.x),t}function crossProduct(e,t,r){const n=t.x-e.x,i=t.y-e.y,o=r.x-e.x,l=r.y-e.y;return n*l-o*i}function buildConvexHull(e){const t=sortPoints(e),r=[];for(let o=0;o<t.length;o++){for(;r.length>=2&&crossProduct(r[r.length-2],r[r.length-1],t[o])<=0;)r.pop();r.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&crossProduct(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return r.pop(),n.pop(),r.concat(n)}const point3DLidar2Image=(e,t)=>{var r;if(isFisheyeCalibValid(t))return lidar2FisheyeImage(e,t);const{P:n,R:i,T:o}=t,{composeMatrix4:l}=(r=transferKitti2Matrix(n,i,o))!=null?r:{};if(!!l)return lidar2image(e,l)},isInImage=({point:e,calib:t,width:r,height:n})=>{if(!t)return!1;const i=point3DLidar2Image(e,t);return i?i.x>=0&&i.x<=r&&i.y>=0&&i.y<=n:!1},getHighlightIndexByPoints=({points:e,calib:t,width:r,height:n})=>{const i=[];for(let o=0;o<e.length;o+=3){const l=e[o],f=e[o+1],a=e[o+2];isInImage({point:{x:l,y:f,z:a},calib:t,width:r,height:n})?i.push(1):i.push(0)}return i},mergeHighlightList=e=>{if(e.length===0)return[];const t=[];for(let r=0;r<e[0].length;r++){for(let n=0;n<e.length;n++)if(e[n][r]===1){t.push(1);break}t.length===r&&t.push(0)}return t};function pointCloudLidar2image(e,t,r={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:i}=r,o=lbUtils.PointCloudUtils.getAllViewData(e),l=isFisheyeCalibValid(t),{P:f,R:a,T:x}=t;let p;if(l===!1){const{composeMatrix4:c}=(n=transferKitti2Matrix(f,a,x))!=null?n:{};if(!c)return;p=c}const s=o.map(c=>({type:c.type,pointList:c.pointList.map(u=>rotatePoint(u,e.center,e.rotation)).map(u=>l?lidar2FisheyeImage(u,t):p&&lidar2image(u,p)).map(u=>{if(!!u)return{id:uuid(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(c=>c.pointList.length!==0);s[0]&&s[0].pointList&&
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js"),omniCamera=require("./omniCamera.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),i=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),f=createThreeMatrix4(i),a=createThreeMatrix4(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const i=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),o=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function isMatrixValid(e,t,r){return!(e.length!==t||e.some(n=>n.length!==r))}const isMatrixValidByArr=(e,t)=>t.some(r=>isMatrixValid(e,r[0],r[1])),isFisheyeCalibValid=e=>{var t;return!!(((t=e.fisheyeDistortion)==null?void 0:t.length)>0&&isMatrixValidByArr(e.P,[[3,4],[4,4]])&&isMatrixValidByArr(e.T,[[3,4],[4,4]]))},oCamFisheyeTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i)),f=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=o.applyMatrix4(l),x=__pow(__pow(a.x,2)+__pow(a.y,2),.5),p=Math.atan(a.z/x),s=n.reduce((c,u,h)=>c+u*__pow(p,h),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)},omniCamera11VTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=omniCamera.transformPointCloudToImage([[e.x,e.y,e.z]],i,r,n);return new THREE__namespace.Vector4(o[0][0],o[0][1],1)},kbCamFisheyeTransfer=(e,t)=>{const{P:r,T:n,fisheyeDistortion:i}=t,o=[e.x,e.y,e.z,1],l=n.map(g=>g.reduce((M,v,_)=>M+v*o[_],0)),f=l[0],a=l[1],x=l[2];if(!(x>=.01&&isFinite(x)))return;const p=[[r[0][0],r[0][1]],[r[1][0],r[1][1]]],s=r[0][2],y=r[1][2],c=Math.sqrt(f*f+a*a),u=Math.atan2(c,x),h=u+i.reduce((g,M,v)=>g+M*Math.pow(u,2*v+3),0);let m,d;c!==0?(m=f*h/c,d=a*h/c):(m=0,d=0);const T=p[0][0]*m+p[0][1]*d,P=p[1][0]*m+p[1][1]*d;return{x:T+s,y:P+y}},lidar2FisheyeImage=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera)return oCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.KannalaBrandt)return kbCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera11V)return omniCamera11VTransfer(e,t)};function lidar2image(e,t){const n=new THREE__namespace.Vector4(e.x,e.y,e.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new THREE__namespace.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function getCuboidFromPointCloudBox(e){const{center:t,width:r,height:n,depth:i,rotation:o}=e,l=[{x:t.x+r/2,y:t.y-n/2},{x:t.x+r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y-n/2}].map(x=>{const p=rotatePoint(x,t,o);return{x:p.x,y:p.y}}),f=t.z+i/2,a=t.z-i/2;return __spreadProps(__spreadValues({},e),{polygonPointList:l,zMax:f,zMin:a})}function sortPoints(e){const t=e.slice();return t.sort((r,n)=>r.x===n.x?n.y-r.y:r.x-n.x),t}function crossProduct(e,t,r){const n=t.x-e.x,i=t.y-e.y,o=r.x-e.x,l=r.y-e.y;return n*l-o*i}function buildConvexHull(e){const t=sortPoints(e),r=[];for(let o=0;o<t.length;o++){for(;r.length>=2&&crossProduct(r[r.length-2],r[r.length-1],t[o])<=0;)r.pop();r.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&crossProduct(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return r.pop(),n.pop(),r.concat(n)}const point3DLidar2Image=(e,t)=>{var r;if(isFisheyeCalibValid(t))return lidar2FisheyeImage(e,t);const{P:n,R:i,T:o}=t,{composeMatrix4:l}=(r=transferKitti2Matrix(n,i,o))!=null?r:{};if(!!l)return lidar2image(e,l)},isInImage=({point:e,calib:t,width:r,height:n})=>{if(!t)return!1;const i=point3DLidar2Image(e,t);return i?i.x>=0&&i.x<=r&&i.y>=0&&i.y<=n:!1},getHighlightIndexByPoints=({points:e,calib:t,width:r,height:n})=>{const i=[];for(let o=0;o<e.length;o+=3){const l=e[o],f=e[o+1],a=e[o+2];isInImage({point:{x:l,y:f,z:a},calib:t,width:r,height:n})?i.push(1):i.push(0)}return i},mergeHighlightList=e=>{if(e.length===0)return[];const t=[];for(let r=0;r<e[0].length;r++){for(let n=0;n<e.length;n++)if(e[n][r]===1){t.push(1);break}t.length===r&&t.push(0)}return t};function pointCloudLidar2image(e,t,r={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:i}=r,o=lbUtils.PointCloudUtils.getAllViewData(e),l=isFisheyeCalibValid(t),{P:f,R:a,T:x}=t;let p;if(l===!1){const{composeMatrix4:c}=(n=transferKitti2Matrix(f,a,x))!=null?n:{};if(!c)return;p=c}const s=o.map(c=>({type:c.type,pointList:c.pointList.map(u=>rotatePoint(u,e.center,e.rotation)).map(u=>l?lidar2FisheyeImage(u,t):p&&lidar2image(u,p)).map(u=>{if(!!u)return{id:uuid(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(c=>c.pointList.length!==0);s[0]&&s[0].pointList&&(s[0].pointList=s[0].pointList.map(c=>__spreadProps(__spreadValues({},c),{specialEdge:!0})));let y=[];if(s.length===6&&i===!0){const c=s[0].pointList,u=s[1].pointList;y=buildConvexHull([...c,...u])}return{transferViewData:s,viewRangePointList:y}}function pointMappingLidar2image(e,t,r){var n;const i=isFisheyeCalibValid(t),{P:o,R:l,T:f}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(o,l,f))!=null?n:{};if(!s)return;a=s}const x=e.length/3,p={};for(let s=0;s<x;s++){const y={x:e[s*3],y:e[s*3+1],z:e[s*3+2]};let c;if(i?c=lidar2FisheyeImage(y,t):c=a&&lidar2image({x:e[s*3],y:e[s*3+1],z:e[s*3+2]},a),c){const u=Math.floor(c.x),h=Math.floor(c.y);if(u>r.width||h>r.height||u<0||h<0)continue;p[s]={x:u,y:h}}}return{pcdMapping:p}}function pointListLidar2Img(e,t,r){var n;if(!t||!r)return;const i=isFisheyeCalibValid(t),{P:o,R:l,T:f}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(o,l,f))!=null?n:{};if(!s)return;a=s}const x=[];if(e.forEach(s=>{let y;if(i?y=lidar2FisheyeImage(s,t):y=a&&lidar2image(s,a),y){const{x:c,y:u}=y;x.push({x:c,y:u})}}),x.some(s=>s.x>0&&s.x<r.width&&s.y>0&&s.y<r.height))return x}exports.createThreeMatrix4=createThreeMatrix4,exports.getCuboidFromPointCloudBox=getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=getHighlightIndexByPoints,exports.isFisheyeCalibValid=isFisheyeCalibValid,exports.isInImage=isInImage,exports.isMatrixValid=isMatrixValid,exports.isMatrixValidByArr=isMatrixValidByArr,exports.lidar2FisheyeImage=lidar2FisheyeImage,exports.lidar2image=lidar2image,exports.mergeHighlightList=mergeHighlightList,exports.oCamFisheyeTransfer=oCamFisheyeTransfer,exports.omniCamera11VTransfer=omniCamera11VTransfer,exports.point3DLidar2Image=point3DLidar2Image,exports.pointCloudLidar2image=pointCloudLidar2image,exports.pointListLidar2Img=pointListLidar2Img,exports.pointMappingLidar2image=pointMappingLidar2image,exports.rotatePoint=rotatePoint,exports.transferKitti2Matrix=transferKitti2Matrix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as p from"three";import{MatrixUtils as M,ECameraType as V,PointCloudUtils as G}from"@labelbee/lb-utils";import J from"../../utils/uuid.js";import{transformPointCloudToImage as Q}from"./omniCamera.js";var W=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,C=Math.pow,D=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))$.call(t,e)&&D(r,e,t[e]);if(R)for(var e of R(t))S.call(t,e)&&D(r,e,t[e]);return r},A=(r,t)=>X(r,Y(t));function g(r){return new p.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),s=M.transferMatrix33FromKitti2Three(t),o=M.transferMatrix34FromKitti2Three(e),c=g(n),f=g(s),a=g(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(c),PM:c,RM:f,TM:a}}catch(n){console.error(n)}}function F(r,t,e){var n;const s=new p.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new p.Matrix4().makeRotationZ(e),c=new p.Matrix4().makeTranslation(t.x,t.y,t.z),f=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return s.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(c)}function H(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const O=(r,t)=>t.some(e=>H(r,e[0],e[1])),d=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&O(r.P,[[3,4],[4,4]])&&O(r.T,[[3,4],[4,4]]))},j=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=new p.Vector4(r.x,r.y,r.z),c=g(M.transferMatrix34FromKitti2Three(s)),f=g(M.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(c),y=C(C(a.x,2)+C(a.y,2),.5),h=Math.atan(a.z/y),i=n.reduce((l,u,m)=>l+u*C(h,m),0);return a.x=a.x/y*i,a.y=a.y/y*i,a.z=1,a.applyMatrix4(f)},K=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=Q([[r.x,r.y,r.z]],s,e,n);return new p.Vector4(o[0][0],o[0][1],1)},b=(r,t)=>{const{P:e,T:n,fisheyeDistortion:s}=t,o=[r.x,r.y,r.z,1],c=n.map(z=>z.reduce((I,L,Z)=>I+L*o[Z],0)),f=c[0],a=c[1],y=c[2];if(!(y>=.01&&isFinite(y)))return;const h=[[e[0][0],e[0][1]],[e[1][0],e[1][1]]],i=e[0][2],x=e[1][2],l=Math.sqrt(f*f+a*a),u=Math.atan2(l,y),m=u+s.reduce((z,I,L)=>z+I*Math.pow(u,2*L+3),0);let P,_;l!==0?(P=f*m/l,_=a*m/l):(P=0,_=0);const q=h[0][0]*P+h[0][1]*_,N=h[1][0]*P+h[1][1]*_;return{x:q+i,y:N+x}},T=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===V.OmniCamera)return j(r,t);if((t==null?void 0:t.cameraType)===V.KannalaBrandt)return b(r,t);if((t==null?void 0:t.cameraType)===V.OmniCamera11V)return K(r,t)};function w(r,t){const n=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const s=1/n.z,o=new p.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}function tt(r){const{center:t,width:e,height:n,depth:s,rotation:o}=r,c=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(y=>{const h=F(y,t,o);return{x:h.x,y:h.y}}),f=t.z+s/2,a=t.z-s/2;return A(E({},r),{polygonPointList:c,zMax:f,zMin:a})}function rt(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function k(r,t,e){const n=t.x-r.x,s=t.y-r.y,o=e.x-r.x,c=e.y-r.y;return n*c-o*s}function et(r){const t=rt(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&k(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&k(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const B=(r,t)=>{var e;if(d(t))return T(r,t);const{P:n,R:s,T:o}=t,{composeMatrix4:c}=(e=v(n,s,o))!=null?e:{};if(!!c)return w(r,c)},U=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const s=B(r,t);return s?s.x>=0&&s.x<=e&&s.y>=0&&s.y<=n:!1},nt=({points:r,calib:t,width:e,height:n})=>{const s=[];for(let o=0;o<r.length;o+=3){const c=r[o],f=r[o+1],a=r[o+2];U({point:{x:c,y:f,z:a},calib:t,width:e,height:n})?s.push(1):s.push(0)}return s},ot=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function st(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:s}=e,o=G.getAllViewData(r),c=d(t),{P:f,R:a,T:y}=t;let h;if(c===!1){const{composeMatrix4:l}=(n=v(f,a,y))!=null?n:{};if(!l)return;h=l}const i=o.map(l=>({type:l.type,pointList:l.pointList.map(u=>F(u,r.center,r.rotation)).map(u=>c?T(u,t):h&&w(u,h)).map(u=>{if(!!u)return{id:J(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(l=>l.pointList.length!==0);i[0]&&i[0].pointList&&
|
|
1
|
+
import*as p from"three";import{MatrixUtils as M,ECameraType as V,PointCloudUtils as G}from"@labelbee/lb-utils";import J from"../../utils/uuid.js";import{transformPointCloudToImage as Q}from"./omniCamera.js";var W=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,C=Math.pow,D=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))$.call(t,e)&&D(r,e,t[e]);if(R)for(var e of R(t))S.call(t,e)&&D(r,e,t[e]);return r},A=(r,t)=>X(r,Y(t));function g(r){return new p.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),s=M.transferMatrix33FromKitti2Three(t),o=M.transferMatrix34FromKitti2Three(e),c=g(n),f=g(s),a=g(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(c),PM:c,RM:f,TM:a}}catch(n){console.error(n)}}function F(r,t,e){var n;const s=new p.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new p.Matrix4().makeRotationZ(e),c=new p.Matrix4().makeTranslation(t.x,t.y,t.z),f=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return s.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(c)}function H(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const O=(r,t)=>t.some(e=>H(r,e[0],e[1])),d=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&O(r.P,[[3,4],[4,4]])&&O(r.T,[[3,4],[4,4]]))},j=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=new p.Vector4(r.x,r.y,r.z),c=g(M.transferMatrix34FromKitti2Three(s)),f=g(M.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(c),y=C(C(a.x,2)+C(a.y,2),.5),h=Math.atan(a.z/y),i=n.reduce((l,u,m)=>l+u*C(h,m),0);return a.x=a.x/y*i,a.y=a.y/y*i,a.z=1,a.applyMatrix4(f)},K=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=Q([[r.x,r.y,r.z]],s,e,n);return new p.Vector4(o[0][0],o[0][1],1)},b=(r,t)=>{const{P:e,T:n,fisheyeDistortion:s}=t,o=[r.x,r.y,r.z,1],c=n.map(z=>z.reduce((I,L,Z)=>I+L*o[Z],0)),f=c[0],a=c[1],y=c[2];if(!(y>=.01&&isFinite(y)))return;const h=[[e[0][0],e[0][1]],[e[1][0],e[1][1]]],i=e[0][2],x=e[1][2],l=Math.sqrt(f*f+a*a),u=Math.atan2(l,y),m=u+s.reduce((z,I,L)=>z+I*Math.pow(u,2*L+3),0);let P,_;l!==0?(P=f*m/l,_=a*m/l):(P=0,_=0);const q=h[0][0]*P+h[0][1]*_,N=h[1][0]*P+h[1][1]*_;return{x:q+i,y:N+x}},T=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===V.OmniCamera)return j(r,t);if((t==null?void 0:t.cameraType)===V.KannalaBrandt)return b(r,t);if((t==null?void 0:t.cameraType)===V.OmniCamera11V)return K(r,t)};function w(r,t){const n=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const s=1/n.z,o=new p.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}function tt(r){const{center:t,width:e,height:n,depth:s,rotation:o}=r,c=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(y=>{const h=F(y,t,o);return{x:h.x,y:h.y}}),f=t.z+s/2,a=t.z-s/2;return A(E({},r),{polygonPointList:c,zMax:f,zMin:a})}function rt(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function k(r,t,e){const n=t.x-r.x,s=t.y-r.y,o=e.x-r.x,c=e.y-r.y;return n*c-o*s}function et(r){const t=rt(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&k(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&k(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const B=(r,t)=>{var e;if(d(t))return T(r,t);const{P:n,R:s,T:o}=t,{composeMatrix4:c}=(e=v(n,s,o))!=null?e:{};if(!!c)return w(r,c)},U=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const s=B(r,t);return s?s.x>=0&&s.x<=e&&s.y>=0&&s.y<=n:!1},nt=({points:r,calib:t,width:e,height:n})=>{const s=[];for(let o=0;o<r.length;o+=3){const c=r[o],f=r[o+1],a=r[o+2];U({point:{x:c,y:f,z:a},calib:t,width:e,height:n})?s.push(1):s.push(0)}return s},ot=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function st(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:s}=e,o=G.getAllViewData(r),c=d(t),{P:f,R:a,T:y}=t;let h;if(c===!1){const{composeMatrix4:l}=(n=v(f,a,y))!=null?n:{};if(!l)return;h=l}const i=o.map(l=>({type:l.type,pointList:l.pointList.map(u=>F(u,r.center,r.rotation)).map(u=>c?T(u,t):h&&w(u,h)).map(u=>{if(!!u)return{id:J(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(l=>l.pointList.length!==0);i[0]&&i[0].pointList&&(i[0].pointList=i[0].pointList.map(l=>A(E({},l),{specialEdge:!0})));let x=[];if(i.length===6&&s===!0){const l=i[0].pointList,u=i[1].pointList;x=et([...l,...u])}return{transferViewData:i,viewRangePointList:x}}function it(r,t,e){var n;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=r.length/3,h={};for(let i=0;i<y;i++){const x={x:r[i*3],y:r[i*3+1],z:r[i*3+2]};let l;if(s?l=T(x,t):l=a&&w({x:r[i*3],y:r[i*3+1],z:r[i*3+2]},a),l){const u=Math.floor(l.x),m=Math.floor(l.y);if(u>e.width||m>e.height||u<0||m<0)continue;h[i]={x:u,y:m}}}return{pcdMapping:h}}function at(r,t,e){var n;if(!t||!e)return;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=[];if(r.forEach(i=>{let x;if(s?x=T(i,t):x=a&&w(i,a),x){const{x:l,y:u}=x;y.push({x:l,y:u})}}),y.some(i=>i.x>0&&i.x<e.width&&i.y>0&&i.y<e.height))return y}export{g as createThreeMatrix4,tt as getCuboidFromPointCloudBox,nt as getHighlightIndexByPoints,d as isFisheyeCalibValid,U as isInImage,H as isMatrixValid,O as isMatrixValidByArr,T as lidar2FisheyeImage,w as lidar2image,ot as mergeHighlightList,j as oCamFisheyeTransfer,K as omniCamera11VTransfer,B as point3DLidar2Image,st as pointCloudLidar2image,at as pointListLidar2Img,it as pointMappingLidar2image,F as rotatePoint,v as transferKitti2Matrix};
|