@labelbee/lb-components 1.23.0-alpha.63 → 1.23.0-alpha.65
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.
- package/dist/components/pointCloudView/PointCloudContext.js +1 -1
- package/dist/components/pointCloudView/hooks/useDataLinkSwitch.js +1 -1
- package/dist/components/pointCloudView/hooks/usePointCloudViews.js +1 -1
- package/dist/types/components/pointCloudView/hooks/usePointCloudViews.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/es/components/pointCloudView/PointCloudContext.js +1 -1
- package/es/components/pointCloudView/hooks/useDataLinkSwitch.js +1 -1
- package/es/components/pointCloudView/hooks/usePointCloudViews.js +1 -1
- package/es/utils/index.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),React=require("react"),ToolPointCloudBoxRenderHelper=require("../../utils/ToolPointCloudBoxRenderHelper.js"),lbAnnotation=require("@labelbee/lb-annotation"),ctx=require("../../store/ctx.js"),actionCreators=require("../../store/annotation/actionCreators.js"),index=require("../../store/annotatedBox/index.js"),_=require("lodash"),map=require("./utils/map.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var React__default=_interopDefaultLegacy(React),___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,o,a)=>o in r?__defProp(r,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[o]=a,__spreadValues=(r,o)=>{for(var a in o||(o={}))__hasOwnProp.call(o,a)&&__defNormalProp(r,a,o[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(o))__propIsEnum.call(o,a)&&__defNormalProp(r,a,o[a]);return r},__spreadProps=(r,o)=>__defProps(r,__getOwnPropDescs(o)),__async=(r,o,a)=>new Promise((w,D)=>{var A=c=>{try{P(a.next(c))}catch(x){D(x)}},j=c=>{try{P(a.throw(c))}catch(x){D(x)}},P=c=>c.done?w(c.value):Promise.resolve(c.value).then(A,j);P((a=a.apply(r,o)).next())});const pickRectObject=r=>___default.default.pick(r,["id","attribute","width","height","x","y","imageName"]),PointCloudContext=React__default.default.createContext({rectList:[],pointCloudBoxList:[],pointCloudSphereList:[],displayPointCloudList:[],displaySphereList:[],displayLineList:[],polygonList:[],lineList:[],selectedID:"",selectedIDs:[],highlightIDs:[],setHighlightIDs:()=>{},valid:!0,setSelectedIDs:()=>{},setPointCloudResult:()=>{},setPointCloudSphereList:()=>{},setPointCloudValid:()=>{},setTopViewInstance:()=>{},setSideViewInstance:()=>{},setBackViewInstance:()=>{},setMainViewInstance:()=>{},addSelectedID:()=>{},addHighlightID:()=>{},selectedAllBoxes:()=>{},addPointCloudBox:()=>[],addPointCloudSphere:()=>[],setPolygonList:()=>{},setRectList:()=>{},addRectIn2DView:()=>{},removeRectIn2DView:()=>{},updateRectIn2DView:()=>{},setLineList:()=>{},zoom:1,setZoom:()=>{},history:new lbAnnotation.ActionsHistory,hideAttributes:[],setHideAttributes:()=>{},toggleAttributesVisible:()=>{},reRender:()=>{},setAttrPanelLayout:()=>{},attrPanelLayout:"",syncAllViewPointCloudColor:()=>Promise.resolve(),defaultAttribute:"",setDefaultAttribute:()=>{},pointCloudPattern:lbAnnotation.EToolName.Rect,setPointCloudPattern:()=>{},selectSpecAttr:()=>{},globalPattern:lbUtils.EPointCloudPattern.Detection,setGlobalPattern:()=>{},setPtSegmentInstance:()=>{},segmentation:[],setSegmentation:()=>{},clearAllDetectionInstance:()=>{},highlight2DDataList:[],setHighlight2DDataList:()=>{},cuboidBoxIn2DView:!0,setCuboidBoxIn2DView:r=>{},imageSizes:{},cacheImageNodeSize:()=>{},addRectFromPointCloudBoxByImageName:r=>!1,removeRectBySpecifyId:(r,o,a)=>!1,removeRectByPointCloudBoxId:r=>!1,rectRotateSensitivity:2,setRectRotateSensitivity:()=>{},imageNamePointCloudBoxMap:new Map,linkageImageNameRectMap:new Map,updateRectListByReducer:()=>{}}),PointCloudProvider=({children:r})=>{const[o,a]=React.useState([]),[w,D]=React.useState([]),[A,j]=React.useState([]),[P,c]=React.useState([]),[x,be]=React.useState([]),[h,k]=React.useState([]),[B,q]=React.useState([]),[U,xe]=React.useState(!0),[J,ye]=React.useState(2),[K,Re]=React.useState(!0),[Q,we]=React.useState(1),[f,X]=React.useState(),[Y,$]=React.useState(),[ee,te]=React.useState(),[u,oe]=React.useState(),[ne,Le]=React.useState(""),[F,De]=React.useState(lbAnnotation.EToolName.Rect),T=React.useRef(new lbAnnotation.ActionsHistory).current,[p,z]=React.useState([]),[ie,Ae]=React.useState(""),[G,Be]=React.useState(lbUtils.EPointCloudPattern.Detection),[L,se]=React.useState(void 0),[W,_e]=React.useState([]),[Z,Ve]=React.useState([]),v=index(),[re,Ne]=React.useState({}),Me=ctx.useDispatch(),Oe=n=>{const{imgNode:i,path:t}=n;t&&i&&Ne(d=>__spreadProps(__spreadValues({},d),{[t]:{width:i.width,height:i.height}}))},le=React.useMemo(()=>h.length===1?h[0]:"",[h]),N=React.useCallback((n,i,t="extId")=>{const d=t||"id",l=new Set(i);return c(g=>{let y=!1;const R=g.filter(O=>{const E=O[d],H=E!==void 0||l.has(E)?O.imageName!==n:!0;return H||(y=!0),H});return y?R:g}),!0},[]),ae=React.useCallback(n=>{const i=o.map(t=>t.id);return N(n,i,"extId")},[o,N]),de=React.useCallback(n=>{if(!n)return!1;const i=o.filter(t=>Array.isArray(t.rects)).map(t=>{const{id:d,attribute:l,trackID:g}=t,y=t.rects.find(R=>R.imageName===n);if(y){const R=___default.default.pick(y,["width","height","x","y","imageName"]);return __spreadProps(__spreadValues({},R),{id:lbAnnotation.uuid(),attribute:l,order:g,extId:d,lineDash:[]})}return null}).filter(t=>t!==null);return i.length?(c(t=>{const d=new Set(t.filter(g=>n===g.imageName).map(g=>g.extId)),l=i.filter(g=>d.has(g.extId)===!1);return l.length?[...t,...l]:t}),!0):!1},[o]),ce=React.useMemo(()=>o.filter(i=>Array.isArray(i.rects)&&i.rects.length>0).reduce((i,t)=>{var d;return(d=t.rects)==null||d.forEach(l=>{const{imageName:g}=l;if(!g){console.warn("Missing image name"),console.trace(l,t);return}map.addMapIndirectWeakSetItem(i,g,t.id,t)}),i},new Map),[o]),ue=React.useCallback(n=>{c(i=>n(i,pickRectObject))},[pickRectObject]),ge=React.useMemo(()=>P.filter(n=>n.extId!==void 0&&n.id!==void 0).reduce((n,i)=>{const t=i.imageName;return t?(map.addMapIndirectWeakSetItem(n,t,i.extId,i),n):(console.warn("missing image name"),console.log(i,P),n)},new Map),[P]),M=React.useMemo(()=>{const n=o.find(e=>e.id===le),i=e=>{const s=o.concat(e);return a(s),s},t=e=>{const s=w.concat(e);return D(s),s},d=e=>{xe(e!==!1)},l=e=>{e===void 0&&k([]),typeof e=="string"&&k([e]),Array.isArray(e)&&k(Array.from(new Set(e)))},g=e=>{h.includes(e)?l(h.filter(s=>s!==e)):l([...h,e])},y=e=>{const s=pickRectObject(e);c(m=>[...m,s])},R=(e,s=!1)=>{const m=pickRectObject(e);c(I=>I.map(S=>S.id===e.id?s?__spreadValues(__spreadValues({},S),m):m:S))},O=e=>{c(s=>s.filter(m=>!e.find(I=>I.id===m.id)))},E=e=>{B.includes(e)?q([]):q([e])},H=()=>{if(F===lbAnnotation.EToolName.Rect){const e=o.map(s=>s.id);l(e),f==null||f.pointCloud2dOperation.setSelectedIDs(e)}},He=e=>{l(o.filter(s=>s.attribute===e).map(s=>s.id))},fe=o.filter(e=>!p.includes(e.attribute)),pe=w.filter(e=>!p.includes(e.attribute)),ve=x.filter(e=>e.attribute&&!p.includes(e.attribute)),je=e=>{if(p.includes(e))z(p.filter(s=>s!==e));else{const s=p.concat(e);z(s)}},ke=(e=fe,s=A,m=pe,I=ve,S=W)=>{var V;u==null||u.clearAllBox(),u==null||u.clearAllSphere(),f==null||f.updatePolygonList(e,s),f==null||f.updatePointList(m),f==null||f.updateLineList(I),u==null||u.generateBoxes(e),u==null||u.generateSpheres(m),(V=L==null?void 0:L.store)==null||V.updateCurrentSegment(S),me(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Default,e)},qe=()=>{X(void 0),$(void 0),te(void 0),oe(void 0)},me=(e,s,m)=>__async(void 0,null,function*(){var I,S,V;if(!u)return;const he=u.pointCloudObject;if(!he)return;let Pe=[],Ie=[];try{if(s&&T.record.length){const{record:C,recordIndex:b}=T;let Se=b;b>0&&(e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.SingleToggleValid||e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.SingleRotate||e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Single&&s.length===((I=C[b])==null?void 0:I.pointCloudBoxList.length))&&(Se=b-1);let Fe=(S=C[Se])==null?void 0:S.pointCloudBoxList;const Ce=ToolPointCloudBoxRenderHelper.calcResetAreasAndBoxIds(e,s,Fe);Pe=Ce.modifiedBoxIds,Ie=Ce.resetAreas}}catch(C){console.error("call calcResetAreasAndBoxIds error",C)}try{const C=yield u.getHighlightIndexByMappingImgList({mappingImgList:m!=null?m:Z,points:he.geometry.attributes.position.array}),b=yield u==null?void 0:u.highlightOriginPointCloud(s,C,{modifiedBoxIds:Pe,resetAreas:Ie});return b&&((V=f==null?void 0:f.pointCloudInstance)==null||V.updateColor(b)),b}catch(C){console.error("call highlightOriginPointCloud error",C)}});return{selectedID:le,pointCloudBoxList:o,pointCloudSphereList:w,displayPointCloudList:fe,displaySphereList:pe,displayLineList:ve,selectedIDs:h,setPointCloudResult:a,setSelectedIDs:l,addPointCloudBox:i,addPointCloudSphere:t,setPointCloudSphereList:D,valid:U,selectedPointCloudBox:n,setPointCloudValid:d,addSelectedID:g,addHighlightID:E,selectedAllBoxes:H,topViewInstance:f,setTopViewInstance:X,sideViewInstance:Y,setSideViewInstance:$,backViewInstance:ee,setBackViewInstance:te,mainViewInstance:u,setMainViewInstance:oe,polygonList:A,setPolygonList:j,rectList:P,setRectList:c,addRectIn2DView:y,removeRectIn2DView:O,updateRectIn2DView:R,lineList:x,setLineList:be,zoom:Q,setZoom:we,history:T,toggleAttributesVisible:je,hideAttributes:p,setHideAttributes:z,reRender:ke,attrPanelLayout:ie,setAttrPanelLayout:Ae,syncAllViewPointCloudColor:me,defaultAttribute:ne,setDefaultAttribute:Le,pointCloudPattern:F,setPointCloudPattern:De,selectSpecAttr:He,globalPattern:G,setGlobalPattern:e=>{G!==e&&(Me(actionCreators.ChangeSave),Be(e),e===lbUtils.EPointCloudPattern.Detection&&se(void 0))},ptSegmentInstance:L,setPtSegmentInstance:se,segmentation:W,setSegmentation:_e,clearAllDetectionInstance:qe,highlight2DDataList:Z,setHighlight2DDataList:Ve,cuboidBoxIn2DView:K,setCuboidBoxIn2DView:Re,imageSizes:re,cacheImageNodeSize:Oe,highlightIDs:B,setHighlightIDs:q,removeRectByPointCloudBoxId:ae,removeRectBySpecifyId:N,addRectFromPointCloudBoxByImageName:de,rectRotateSensitivity:J,setRectRotateSensitivity:ye,imageNamePointCloudBoxMap:ce,linkageImageNameRectMap:ge,updateRectListByReducer:ue}},[U,h,o,w,A,x,P,f,Y,ee,u,Q,p,ie,ne,F,G,L,W,Z,K,re,B,ae,N,de,J,ce,ge,ue]);React.useEffect(()=>{var n,i,t;(n=v==null?void 0:v.setPointCloudBoxList)==null||n.call(v,o),(i=v==null?void 0:v.setHighlightIDs)==null||i.call(v,B),(t=v==null?void 0:v.setSelectedIDs)==null||t.call(v,h)},[o,h,B]),React.useEffect(()=>{var n;(n=v==null?void 0:v.setPtCtx)==null||n.call(v,M)},[M]);const Ee=()=>{const n=o.filter(l=>p.includes(l.attribute)),{setSelectedIDs:i,reRender:t}=M,d=n.map(l=>l.id);d.length>0&&i(h.filter(l=>!d.includes(l))),t()};return React.useEffect(()=>{var n,i,t,d;Ee(),(i=(n=f==null?void 0:f.toolInstance)==null?void 0:n.setHiddenAttributes)==null||i.call(n,p),(d=(t=L==null?void 0:L.store)==null?void 0:t.setHiddenAttributes)==null||d.call(t,p)},[p]),React__default.default.createElement(PointCloudContext.Provider,{value:M},r)};exports.PointCloudContext=PointCloudContext,exports.PointCloudProvider=PointCloudProvider;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),React=require("react"),ToolPointCloudBoxRenderHelper=require("../../utils/ToolPointCloudBoxRenderHelper.js"),lbAnnotation=require("@labelbee/lb-annotation"),ctx=require("../../store/ctx.js"),actionCreators=require("../../store/annotation/actionCreators.js"),index=require("../../store/annotatedBox/index.js"),_=require("lodash"),map=require("./utils/map.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var React__default=_interopDefaultLegacy(React),___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,o,a)=>o in r?__defProp(r,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[o]=a,__spreadValues=(r,o)=>{for(var a in o||(o={}))__hasOwnProp.call(o,a)&&__defNormalProp(r,a,o[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(o))__propIsEnum.call(o,a)&&__defNormalProp(r,a,o[a]);return r},__spreadProps=(r,o)=>__defProps(r,__getOwnPropDescs(o)),__async=(r,o,a)=>new Promise((w,D)=>{var A=c=>{try{P(a.next(c))}catch(x){D(x)}},H=c=>{try{P(a.throw(c))}catch(x){D(x)}},P=c=>c.done?w(c.value):Promise.resolve(c.value).then(A,H);P((a=a.apply(r,o)).next())});const pickRectObject=r=>___default.default.pick(r,["id","attribute","width","height","x","y","imageName"]),PointCloudContext=React__default.default.createContext({rectList:[],pointCloudBoxList:[],pointCloudSphereList:[],displayPointCloudList:[],displaySphereList:[],displayLineList:[],polygonList:[],lineList:[],selectedID:"",selectedIDs:[],highlightIDs:[],setHighlightIDs:()=>{},valid:!0,setSelectedIDs:()=>{},setPointCloudResult:()=>{},setPointCloudSphereList:()=>{},setPointCloudValid:()=>{},setTopViewInstance:()=>{},setSideViewInstance:()=>{},setBackViewInstance:()=>{},setMainViewInstance:()=>{},addSelectedID:()=>{},addHighlightID:()=>{},selectedAllBoxes:()=>{},addPointCloudBox:()=>[],addPointCloudSphere:()=>[],setPolygonList:()=>{},setRectList:()=>{},addRectIn2DView:()=>{},removeRectIn2DView:()=>{},updateRectIn2DView:()=>{},setLineList:()=>{},zoom:1,setZoom:()=>{},history:new lbAnnotation.ActionsHistory,hideAttributes:[],setHideAttributes:()=>{},toggleAttributesVisible:()=>{},reRender:()=>{},setAttrPanelLayout:()=>{},attrPanelLayout:"",syncAllViewPointCloudColor:()=>Promise.resolve(),defaultAttribute:"",setDefaultAttribute:()=>{},pointCloudPattern:lbAnnotation.EToolName.Rect,setPointCloudPattern:()=>{},selectSpecAttr:()=>{},globalPattern:lbUtils.EPointCloudPattern.Detection,setGlobalPattern:()=>{},setPtSegmentInstance:()=>{},segmentation:[],setSegmentation:()=>{},clearAllDetectionInstance:()=>{},highlight2DDataList:[],setHighlight2DDataList:()=>{},cuboidBoxIn2DView:!0,setCuboidBoxIn2DView:r=>{},imageSizes:{},cacheImageNodeSize:()=>{},addRectFromPointCloudBoxByImageName:r=>!1,removeRectBySpecifyId:(r,o,a)=>!1,removeRectByPointCloudBoxId:r=>!1,rectRotateSensitivity:2,setRectRotateSensitivity:()=>{},imageNamePointCloudBoxMap:new Map,linkageImageNameRectMap:new Map,updateRectListByReducer:()=>{}}),PointCloudProvider=({children:r})=>{const[o,a]=React.useState([]),[w,D]=React.useState([]),[A,H]=React.useState([]),[P,c]=React.useState([]),[x,be]=React.useState([]),[h,j]=React.useState([]),[B,k]=React.useState([]),[U,xe]=React.useState(!0),[J,ye]=React.useState(2),[K,Re]=React.useState(!0),[Q,we]=React.useState(1),[f,X]=React.useState(),[Y,$]=React.useState(),[ee,te]=React.useState(),[u,oe]=React.useState(),[ne,Le]=React.useState(""),[q,De]=React.useState(lbAnnotation.EToolName.Rect),F=React.useRef(new lbAnnotation.ActionsHistory).current,[p,T]=React.useState([]),[ie,Ae]=React.useState(""),[z,Be]=React.useState(lbUtils.EPointCloudPattern.Detection),[L,se]=React.useState(void 0),[G,_e]=React.useState([]),[W,Ve]=React.useState([]),m=index(),[re,Ne]=React.useState({}),Me=ctx.useDispatch(),Oe=n=>{const{imgNode:i,path:t}=n;t&&i&&Ne(d=>__spreadProps(__spreadValues({},d),{[t]:{width:i.width,height:i.height}}))},le=React.useMemo(()=>h.length===1?h[0]:"",[h]),N=React.useCallback((n,i,t="extId")=>{const d=t||"id",l=new Set(i);return c(g=>{let y=!1;const R=g.filter(O=>{const Z=O[d],E=l.has(Z)?O.imageName!==n:!0;return E||(y=!0),E});return y?R:g}),!0},[]),ae=React.useCallback(n=>{const i=o.map(t=>t.id);return N(n,i,"extId")},[o,N]),de=React.useCallback(n=>{if(!n)return!1;const i=o.filter(t=>Array.isArray(t.rects)).map(t=>{const{id:d,attribute:l,trackID:g}=t,y=t.rects.find(R=>R.imageName===n);if(y){const R=___default.default.pick(y,["width","height","x","y","imageName"]);return __spreadProps(__spreadValues({},R),{id:lbAnnotation.uuid(),attribute:l,order:g,extId:d,lineDash:[]})}return null}).filter(t=>t!==null);return i.length?(c(t=>{const d=new Set(t.filter(g=>n===g.imageName).map(g=>g.extId)),l=i.filter(g=>d.has(g.extId)===!1);return l.length?[...t,...l]:t}),!0):!1},[o]),ce=React.useMemo(()=>o.filter(i=>Array.isArray(i.rects)&&i.rects.length>0).reduce((i,t)=>{var d;return(d=t.rects)==null||d.forEach(l=>{const{imageName:g}=l;if(!g){console.warn("Missing image name"),console.trace(l,t);return}map.addMapIndirectWeakSetItem(i,g,t.id,t)}),i},new Map),[o]),ue=React.useCallback(n=>{c(i=>n(i,pickRectObject))},[pickRectObject]),ge=React.useMemo(()=>P.filter(n=>n.extId!==void 0&&n.id!==void 0).reduce((n,i)=>{const t=i.imageName;return t?(map.addMapIndirectWeakSetItem(n,t,i.extId,i),n):(console.warn("missing image name"),console.log(i,P),n)},new Map),[P]),M=React.useMemo(()=>{const n=o.find(e=>e.id===le),i=e=>{const s=o.concat(e);return a(s),s},t=e=>{const s=w.concat(e);return D(s),s},d=e=>{xe(e!==!1)},l=e=>{e===void 0&&j([]),typeof e=="string"&&j([e]),Array.isArray(e)&&j(Array.from(new Set(e)))},g=e=>{h.includes(e)?l(h.filter(s=>s!==e)):l([...h,e])},y=e=>{const s=pickRectObject(e);c(v=>[...v,s])},R=(e,s=!1)=>{const v=pickRectObject(e);c(I=>I.map(S=>S.id===e.id?s?__spreadValues(__spreadValues({},S),v):v:S))},O=e=>{c(s=>s.filter(v=>!e.find(I=>I.id===v.id)))},Z=e=>{B.includes(e)?k([]):k([e])},E=()=>{if(q===lbAnnotation.EToolName.Rect){const e=o.map(s=>s.id);l(e),f==null||f.pointCloud2dOperation.setSelectedIDs(e)}},He=e=>{l(o.filter(s=>s.attribute===e).map(s=>s.id))},fe=o.filter(e=>!p.includes(e.attribute)),pe=w.filter(e=>!p.includes(e.attribute)),me=x.filter(e=>e.attribute&&!p.includes(e.attribute)),je=e=>{if(p.includes(e))T(p.filter(s=>s!==e));else{const s=p.concat(e);T(s)}},ke=(e=fe,s=A,v=pe,I=me,S=G)=>{var V;u==null||u.clearAllBox(),u==null||u.clearAllSphere(),f==null||f.updatePolygonList(e,s),f==null||f.updatePointList(v),f==null||f.updateLineList(I),u==null||u.generateBoxes(e),u==null||u.generateSpheres(v),(V=L==null?void 0:L.store)==null||V.updateCurrentSegment(S),ve(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Default,e)},qe=()=>{X(void 0),$(void 0),te(void 0),oe(void 0)},ve=(e,s,v)=>__async(void 0,null,function*(){var I,S,V;if(!u)return;const he=u.pointCloudObject;if(!he)return;let Pe=[],Ie=[];try{if(s&&F.record.length){const{record:C,recordIndex:b}=F;let Se=b;b>0&&(e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.SingleToggleValid||e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.SingleRotate||e===ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Single&&s.length===((I=C[b])==null?void 0:I.pointCloudBoxList.length))&&(Se=b-1);let Fe=(S=C[Se])==null?void 0:S.pointCloudBoxList;const Ce=ToolPointCloudBoxRenderHelper.calcResetAreasAndBoxIds(e,s,Fe);Pe=Ce.modifiedBoxIds,Ie=Ce.resetAreas}}catch(C){console.error("call calcResetAreasAndBoxIds error",C)}try{const C=yield u.getHighlightIndexByMappingImgList({mappingImgList:v!=null?v:W,points:he.geometry.attributes.position.array}),b=yield u==null?void 0:u.highlightOriginPointCloud(s,C,{modifiedBoxIds:Pe,resetAreas:Ie});return b&&((V=f==null?void 0:f.pointCloudInstance)==null||V.updateColor(b)),b}catch(C){console.error("call highlightOriginPointCloud error",C)}});return{selectedID:le,pointCloudBoxList:o,pointCloudSphereList:w,displayPointCloudList:fe,displaySphereList:pe,displayLineList:me,selectedIDs:h,setPointCloudResult:a,setSelectedIDs:l,addPointCloudBox:i,addPointCloudSphere:t,setPointCloudSphereList:D,valid:U,selectedPointCloudBox:n,setPointCloudValid:d,addSelectedID:g,addHighlightID:Z,selectedAllBoxes:E,topViewInstance:f,setTopViewInstance:X,sideViewInstance:Y,setSideViewInstance:$,backViewInstance:ee,setBackViewInstance:te,mainViewInstance:u,setMainViewInstance:oe,polygonList:A,setPolygonList:H,rectList:P,setRectList:c,addRectIn2DView:y,removeRectIn2DView:O,updateRectIn2DView:R,lineList:x,setLineList:be,zoom:Q,setZoom:we,history:F,toggleAttributesVisible:je,hideAttributes:p,setHideAttributes:T,reRender:ke,attrPanelLayout:ie,setAttrPanelLayout:Ae,syncAllViewPointCloudColor:ve,defaultAttribute:ne,setDefaultAttribute:Le,pointCloudPattern:q,setPointCloudPattern:De,selectSpecAttr:He,globalPattern:z,setGlobalPattern:e=>{z!==e&&(Me(actionCreators.ChangeSave),Be(e),e===lbUtils.EPointCloudPattern.Detection&&se(void 0))},ptSegmentInstance:L,setPtSegmentInstance:se,segmentation:G,setSegmentation:_e,clearAllDetectionInstance:qe,highlight2DDataList:W,setHighlight2DDataList:Ve,cuboidBoxIn2DView:K,setCuboidBoxIn2DView:Re,imageSizes:re,cacheImageNodeSize:Oe,highlightIDs:B,setHighlightIDs:k,removeRectByPointCloudBoxId:ae,removeRectBySpecifyId:N,addRectFromPointCloudBoxByImageName:de,rectRotateSensitivity:J,setRectRotateSensitivity:ye,imageNamePointCloudBoxMap:ce,linkageImageNameRectMap:ge,updateRectListByReducer:ue}},[U,h,o,w,A,x,P,f,Y,ee,u,Q,p,ie,ne,q,z,L,G,W,K,re,B,ae,N,de,J,ce,ge,ue]);React.useEffect(()=>{var n,i,t;(n=m==null?void 0:m.setPointCloudBoxList)==null||n.call(m,o),(i=m==null?void 0:m.setHighlightIDs)==null||i.call(m,B),(t=m==null?void 0:m.setSelectedIDs)==null||t.call(m,h)},[o,h,B]),React.useEffect(()=>{var n;(n=m==null?void 0:m.setPtCtx)==null||n.call(m,M)},[M]);const Ee=()=>{const n=o.filter(l=>p.includes(l.attribute)),{setSelectedIDs:i,reRender:t}=M,d=n.map(l=>l.id);d.length>0&&i(h.filter(l=>!d.includes(l))),t()};return React.useEffect(()=>{var n,i,t,d;Ee(),(i=(n=f==null?void 0:f.toolInstance)==null?void 0:n.setHiddenAttributes)==null||i.call(n,p),(d=(t=L==null?void 0:L.store)==null?void 0:t.setHiddenAttributes)==null||d.call(t,p)},[p]),React__default.default.createElement(PointCloudContext.Provider,{value:M},r)};exports.PointCloudContext=PointCloudContext,exports.PointCloudProvider=PointCloudProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),ahooks=require("ahooks"),PointCloudContext=require("../PointCloudContext.js"),icon_link=require("../../../assets/annotation/icon_link.svg.js"),icon_unlink=require("../../../assets/annotation/icon_unlink.svg.js"),BatchSwitchConnectIn2DView=require("../../../views/MainView/toolFooter/BatchSwitchConnectIn2DView/BatchSwitchConnectIn2DView.js"),lbAnnotation=require("@labelbee/lb-annotation"),usePointCloudViews=require("./usePointCloudViews.js");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React);const useShownIcon=e=>{const{imageNamePointCloudBoxMap:
|
|
1
|
+
"use strict";var React=require("react"),ahooks=require("ahooks"),PointCloudContext=require("../PointCloudContext.js"),icon_link=require("../../../assets/annotation/icon_link.svg.js"),icon_unlink=require("../../../assets/annotation/icon_unlink.svg.js"),BatchSwitchConnectIn2DView=require("../../../views/MainView/toolFooter/BatchSwitchConnectIn2DView/BatchSwitchConnectIn2DView.js"),lbAnnotation=require("@labelbee/lb-annotation"),usePointCloudViews=require("./usePointCloudViews.js");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React);const useShownIcon=e=>{const{imageNamePointCloudBoxMap:s,linkageImageNameRectMap:l}=React.useContext(PointCloudContext.PointCloudContext),a=React.useMemo(()=>e?s.has(e):(console.error("Missing image name"),!1),[e,s]),d=React.useMemo(()=>{var o,f;return e?((f=(o=l.get(e))==null?void 0:o.size)!=null?f:0)>0:!1},[l,e]),m=React.useMemo(()=>a||d,[a,d]),g=ahooks.useLatest(m);return{visible:m,visibleRef:g}},iconSize={width:16,height:16},useDataLinkSwitch=e=>{e.imageName||console.warn("missing imageName");const[s,l]=React.useState(!0),a=ahooks.useLatest(e.imageName),{addRectFromPointCloudBoxByImageName:d,removeRectByPointCloudBoxId:m,linkageImageNameRectMap:g,pointCloudBoxList:o,rectList:f,updateRectListByReducer:k}=React.useContext(PointCloudContext.PointCloudContext),{visible:v,visibleRef:x}=useShownIcon(e.imageName),{syncToPointCloudBoxList:b}=usePointCloudViews.useSyncRectPositionDimensionToPointCloudList(),R=ahooks.useLatest(d),L=ahooks.useLatest(m),B=ahooks.useLatest(()=>b()),h=React.useCallback(t=>{if(!x.current)return;const n=a.current;if(!n){console.warn("invalid image name");return}l(t),t?L.current(n):R.current(n)},[]),y=ahooks.useLatest(t=>{t&&B.current(),h(t)}),E=React.useMemo(()=>{var t;if(!e.is2DView||!v)return null;const i={zIndex:(t=e.zIndex)!=null?t:999,position:"absolute",top:16,right:16+28+12,background:"rgba(0, 0, 0, 0.74)",color:"white",borderRadius:2,padding:6,display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28};return React__default.default.createElement("div",{style:i},s&&React__default.default.createElement("img",{src:icon_link,style:iconSize}),!s&&React__default.default.createElement("img",{src:icon_unlink,style:iconSize}))},[s,e.is2DView,e.zIndex,v]),M=ahooks.useLatest(g),I=React.useCallback(()=>{var t,n;if(!e.is2DView)return;const i=a.current;if(!i){console.warn("invalid image name");return}const r=[...(n=(t=M.current.get(i))==null?void 0:t.keys())!=null?n:[]];let c=!0;r.length&&(c=!1),h(c)},[e.is2DView,h]);return React.useEffect(()=>{I()},[I,o,f]),React.useEffect(()=>{const t=o.map(i=>i.id),n=new Set(t);k((i,C)=>{const r=[],c=[];return i.forEach(u=>{const w=u.extId;w!==void 0&&n.has(w)===!1?r.push(u):c.push(u)}),r.length?[...r.map(u=>C(u)),...c]:i})},[o]),React.useEffect(()=>{const t=n=>{y.current(n)};return lbAnnotation.EventBus.on(BatchSwitchConnectIn2DView.EventBusEvent.switchConnect,t),()=>lbAnnotation.EventBus.unbind(BatchSwitchConnectIn2DView.EventBusEvent.switchConnect,t)},[]),{rendered:E,isLinking:s}};module.exports=useDataLinkSwitch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbAnnotation=require("@labelbee/lb-annotation"),lbUtils=require("@labelbee/lb-utils"),React=require("react"),PointCloudContext=require("../PointCloudContext.js"),useSingleBox=require("./useSingleBox.js"),useSphere=require("./useSphere.js"),_=require("lodash"),ctx=require("../../../store/ctx.js"),StepUtils=require("../../../utils/StepUtils.js"),ToolPointCloudBoxRenderHelper=require("../../../utils/ToolPointCloudBoxRenderHelper.js"),index=require("../../../utils/index.js"),actionCreators=require("../../../store/annotation/actionCreators.js"),useHistory=require("./useHistory.js"),usePolygon=require("./usePolygon.js"),ahooks=require("ahooks"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,s)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s,__spreadValues=(o,t)=>{for(var s in t||(t={}))__hasOwnProp.call(t,s)&&__defNormalProp(o,s,t[s]);if(__getOwnPropSymbols)for(var s of __getOwnPropSymbols(t))__propIsEnum.call(t,s)&&__defNormalProp(o,s,t[s]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t)),__async=(o,t,s)=>new Promise((c,e)=>{var p=d=>{try{u(s.next(d))}catch(f){e(f)}},P=d=>{try{u(s.throw(d))}catch(f){e(f)}},u=d=>d.done?c(d.value):Promise.resolve(d.value).then(p,P);u((s=s.apply(o,t)).next())});const DEFAULT_SCOPE=5,DEFAULT_RADIUS=90,INTELLIGENT_FIT_MARGIN=.01,PointCloudView={"3D":"3D",Top:"Top",Side:"Side",Back:"Back"},topViewPoint2PointCloud=(o,t,s,c,e)=>{const{x:p,y:P}=lbUtils.PointCloudUtils.transferCanvas2World(o,t),{defaultZ:u}=lbUtils.DEFAULT_SPHERE_PARAMS,d={center:{x:p,y:P,z:u},id:o.id},f=c?__spreadValues(__spreadValues({},c),d):__spreadProps(__spreadValues({},d),{attribute:"",valid:!0});return e&&Object.assign(f,e),f},topViewPolygon2PointCloud=(o,t,s,c,e,p)=>{let P=o.pointList.map(B=>lbUtils.PointCloudUtils.transferCanvas2World(B,t)),u=0,d=1,f={};if(s){const B=s.getSensesPointZAxisInPolygon(P,void 0,p);p&&B.fittedCoordinates.length>0&&(P=B.fittedCoordinates),u=(B.maxZ+B.minZ)/2,d=B.maxZ-B.minZ,f={count:B.zCount}}const[h,L,U]=P,S=lbAnnotation.MathUtils.getLineCenterPoint([h,U]),b=lbAnnotation.MathUtils.getLineLength(h,L),k=lbAnnotation.MathUtils.getLineLength(L,U),V=lbAnnotation.MathUtils.getRadiusFromQuadrangle(o.pointList);c&&(u=c.center.z,d=c.depth);const R={center:{x:S.x,y:S.y,z:u},width:p?k+INTELLIGENT_FIT_MARGIN:k,height:p?b+INTELLIGENT_FIT_MARGIN:b,depth:d,rotation:V,id:o.id},T=__spreadValues(c?__spreadValues(__spreadValues({},c),R):__spreadProps(__spreadValues({},R),{attribute:"",valid:!0}),f);e&&Object.assign(T,e);const A=P.map(B=>lbUtils.PointCloudUtils.transferWorld2Canvas(B,t));return{boxParams:T,newPointList:A}},sideViewPoint2PointCloud=(o,t,s)=>{const c={x:o.x-t.x,y:o.y-t.y};return __spreadProps(__spreadValues({},s),{center:{x:s.center.x-c.x,y:s.center.y,z:s.center.z-c.y}})},sideViewPolygon2PointCloud=(o,t,s,c)=>{const[e,p,P]=o.pointList,[u,d,f]=t.pointList,h=lbAnnotation.MathUtils.getLineCenterPoint([e,P]),L=lbAnnotation.MathUtils.getLineCenterPoint([u,f]),S={x:{x:h.x-L.x,y:h.y-L.y}.x,y:0,z:h.y-L.y},b=lbAnnotation.MathUtils.getLineLength(e,p),k=lbAnnotation.MathUtils.getLineLength(u,d),V=b-k,R=lbAnnotation.MathUtils.getLineLength(p,P),T=lbAnnotation.MathUtils.getLineLength(d,f),A=R-T,{newBoxParams:B}=c.getNewBoxBySideUpdate(S,A,V,s);return B},backViewPoint2PointCloud=(o,t,s)=>{const c={x:o.x-t.x,y:o.y-t.y};return __spreadProps(__spreadValues({},s),{center:{x:s.center.x,y:s.center.y-c.x,z:s.center.z-c.y}})},backViewPolygon2PointCloud=(o,t,s,c)=>{const[e,p,P]=o.pointList,[u,d,f]=t.pointList,h=lbAnnotation.MathUtils.getLineCenterPoint([e,P]),L=lbAnnotation.MathUtils.getLineCenterPoint([u,f]),S={x:{x:h.x-L.x,y:h.y-L.y}.x,y:0,z:h.y-L.y},b=lbAnnotation.MathUtils.getLineLength(e,p),k=lbAnnotation.MathUtils.getLineLength(u,d),V=b-k,R=lbAnnotation.MathUtils.getLineLength(p,P),T=lbAnnotation.MathUtils.getLineLength(d,f),A=R-T;let{newBoxParams:B}=c.getNewBoxByBackUpdate(S,A,V,s);return B},syncSideViewByPoint=(o,t,s,c,e)=>{var p;if(!s)return;const{toolInstance:P,pointCloudInstance:u}=s;u.loadPCDFile(c,(p=e==null?void 0:e.radius)!=null?p:DEFAULT_RADIUS);const{cameraPositionVector:d}=u.updateOrthoCameraBySphere(o,lbUtils.EPerspectiveView.Left);u.setInitCameraPosition(d);const{point2d:f,zoom:h}=u.getSphereSidePoint2DCoordinate(o);u.camera.zoom=h,u.camera.updateProjectionMatrix(),u.render(),P.initPosition(),P.zoomChangeOnCenter(h),P.setResult([__spreadProps(__spreadValues(__spreadValues({},t),f),{valid:o.valid,textAttribute:"",attribute:o.attribute})]),P.setSelectedID(t.id)},synchronizeSideView=(o,t,s,c)=>{if(!s)return;const{pointCloud2dOperation:e,pointCloudInstance:p}=s;p.loadPCDFileByBox(c,o,{width:DEFAULT_SCOPE,depth:DEFAULT_SCOPE});const{cameraPositionVector:P}=p.updateOrthoCamera(o,lbUtils.EPerspectiveView.Left);p.setInitCameraPosition(P);const{polygon2d:u,zoom:d}=p.getBoxSidePolygon2DCoordinate(o);p.camera.zoom=d,p.camera.updateProjectionMatrix(),p.render(),e.initPosition(),e.zoomChangeOnCenter(d),e.setResultAndSelectedID([{id:t.id,valid:o.valid,pointList:u,textAttribute:"",isRect:!0,attribute:o.attribute}],t.id)},syncBackViewByPoint=(o,t,s,c,e)=>{var p;if(!s)return;const{toolInstance:P,pointCloudInstance:u}=s;u.loadPCDFile(c,(p=e==null?void 0:e.radius)!=null?p:DEFAULT_RADIUS);const{cameraPositionVector:d}=u.updateOrthoCameraBySphere(o,lbUtils.EPerspectiveView.Back);u.setInitCameraPosition(d);const{point2d:f,zoom:h}=u.getSphereBackPoint2DCoordinate(o);u.camera.zoom=h,u.camera.updateProjectionMatrix(),u.render(),P.initPosition(),P.zoomChangeOnCenter(h),P.setResult([__spreadProps(__spreadValues(__spreadValues({},t),f),{valid:o.valid,textAttribute:"",attribute:o.attribute})]),P.setSelectedID(t.id)},synchronizeBackView=(o,t,s,c)=>{if(!s)return;const{pointCloud2dOperation:e,pointCloudInstance:p}=s;p.loadPCDFileByBox(c,o,{height:DEFAULT_SCOPE,depth:DEFAULT_SCOPE});const{cameraPositionVector:P}=p.updateOrthoCamera(o,lbUtils.EPerspectiveView.Back);p.setInitCameraPosition(P);const{polygon2d:u,zoom:d}=p.getBoxBackPolygon2DCoordinate(o);p.camera.zoom=d,p.camera.updateProjectionMatrix(),p.render(),e.initPosition(),e.zoomChangeOnCenter(d),e.setResultAndSelectedID([{id:t.id,valid:o.valid,pointList:u,textAttribute:"",isRect:!0,attribute:o.attribute}],t.id)},syncTopViewByPoint=(o,t,s,c)=>{if(!s||!c)return;c.generateSphere(o),c.updateCameraBySphere(o,lbUtils.EPerspectiveView.Top),c.render();const{toolInstance:e,pointCloudInstance:p}=s,{point2d:P}=p.getSphereTopPoint2DCoordinate(o),u=[...e.pointList].map(d=>d.id===t.id?__spreadProps(__spreadValues(__spreadValues({},t),P),{valid:o.valid,textAttribute:"",attribute:o.attribute}):d);e.setResult(u),e.setSelectedID(t.id)},synchronizeTopView=(o,t,s,c)=>{var e,p;if(!s||!c)return;c.generateBox(o,t.id),c.render();const{pointCloud2dOperation:P,pointCloudInstance:u}=s,{polygon2d:d}=u.getBoxTopPolygon2DCoordinate(o),f=[...P.polygonList],h=f.find(L=>L.id===t.id);h?(h.pointList=d,h.valid=(e=o.valid)!=null?e:!0):f.push({id:t.id,pointList:d,textAttribute:"",isRect:!0,valid:(p=o.valid)!=null?p:!0}),P.setResultAndSelectedID(f,t.id)},usePointCloudViews=()=>{const o=React.useContext(PointCloudContext.PointCloudContext),{topViewInstance:t,sideViewInstance:s,backViewInstance:c,mainViewInstance:e,addPointCloudBox:p,addPointCloudSphere:P,setSelectedIDs:u,selectedIDs:d,pointCloudBoxList:f,pointCloudSphereList:h,hideAttributes:L,setHighlight2DDataList:U,cuboidBoxIn2DView:S,imageSizes:b,history:k,linkageImageNameRectMap:V}=o,{addHistory:R,initHistory:T,pushHistoryUnderUpdatePolygon:A}=useHistory.useHistory(),{selectedPolygon:B}=usePolygon.usePolygon(),{getPointCloudSphereByID:ot,updatePointCloudSphere:Y,selectedSphere:q}=useSphere.useSphere(),{currentData:j,config:m}=ctx.useSelector(i=>{const{stepList:n,step:a,imgList:r,imgIndex:l}=i.annotation;return{currentData:r[l],config:index.jsonParser(StepUtils.getCurrentStepInfo(a,n).config)}}),z=ctx.useDispatch(),it=ahooks.useLatest(S),nt=React.useCallback(i=>i.filter(a=>{var r,l;return a&&((l=(r=V.get(a.imageName))==null?void 0:r.size)!=null?l:0)===0}),[V]),Z=i=>{const{enableAutoMap2DRect:n=!1}=m;if(!it.current||n){const{mappingImgList:a=[]}=j;index.generatePointCloudBoxRects({pointCloudBox:i,mappingImgList:a,imageSizes:b},{prepareRectsFn:nt})}},{selectedBox:I,updateSelectedBox:st,updateSelectedBoxes:G,getPointCloudByID:rt}=useSingleBox.useSingleBox({generateRects:Z}),K=I==null?void 0:I.info;if(!t||!s||!c)return{topViewAddSphere:()=>{},topViewAddBox:()=>{},topViewSelectedChanged:()=>{},sideViewUpdateBox:()=>{},backViewUpdateBox:()=>{}};const{pointCloudInstance:J}=t,lt=i=>{e==null||e.generateBox(i),e==null||e.controls.update(),e==null||e.render()},at=i=>{e==null||e.generateSphere(i),e==null||e.controls.update(),e==null||e.render()},dt=({newPoint:i,size:n,zoom:a,trackConfigurable:r})=>{var l;const g={attribute:(l=t.toolInstance.defaultAttribute)!=null?l:""};r===!0&&Object.assign(g,{trackID:lbUtils.PointCloudUtils.getNextTrackID({imgList:[],extraBoxList:[],extraSphereList:h})});const x=topViewPoint2PointCloud(i,n,J,void 0,g);u(i.id);const C=P(x);H(PointCloudView.Top,i,x,a,C,m),R({newSphereParams:x})},ut=({polygon:i,size:n,imgList:a,trackConfigurable:r,zoom:l,intelligentFit:g})=>{var x,C,v;const D={attribute:(x=t.toolInstance.defaultAttribute)!=null?x:""};r===!0&&Object.assign(D,{trackID:lbUtils.PointCloudUtils.getNextTrackID({imgList:[],extraBoxList:f,extraSphereList:h})});const M=t==null?void 0:t.toolInstance,w=__spreadValues({},i);let{boxParams:y,newPointList:O}=topViewPolygon2PointCloud(w,n,J,void 0,D,g);y=z(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:[y],stepConfig:m,action:"viewUpdateBox"}))[0],g&&(O==null?void 0:O.length)&&(w.pointList=O);const X=L.includes(w.attribute);Z(y);const E=p(y),F=(C=o==null?void 0:o.polygonList)!=null?C:[];y.subAttribute=lbAnnotation.TagUtils.getDefaultResultByConfig((m==null?void 0:m.secondaryAttributeConfigurable)?(v=m==null?void 0:m.inputList)!=null?v:[]:[]),t==null||t.updatePolygonList(E!=null?E:[],F),X?u([]):(u(y.id),M.selection.setSelectedIDs(w.id),N({omitView:PointCloudView.Top,polygon:w,boxParams:y,zoom:l,newPointCloudBoxList:E}),g&&synchronizeTopView(y,w,t,e)),R({newBoxParams:y})},ct=i=>{const{boxID:n,imageName:a,width:r,height:l,x:g,y:x}=i,C=f.find(y=>y.id===n);if(!(C==null?void 0:C.rects)||!C.rects.find(y=>y.imageName===a))return;const D=C.rects.map(y=>y.imageName===a?__spreadProps(__spreadValues({},y),{width:r,height:l,x:g,y:x}):y),M=__spreadProps(__spreadValues({},C),{rects:D}),w=f.map(y=>y.id===n?M:y);return t==null||t.updatePolygonList(w!=null?w:[]),w},pt=i=>{const{boxID:n,imageName:a}=i,r=f.find(C=>C.id===n);if(!(r==null?void 0:r.rects))return;const l=r.rects.filter(C=>C.imageName!==a),g=__spreadProps(__spreadValues({},r),{rects:l}),x=f.map(C=>C.id===n?g:C);return t==null||t.updatePolygonList(x!=null?x:[]),x},Pt=({newSelectedBox:i,newPointCloudList:n,newSelectedSphere:a,newSphereList:r})=>{var l;const g=t==null?void 0:t.toolInstance;if(!(d.length===0||!g)){if(i||(I==null?void 0:I.info)){const x=i!=null?i:I==null?void 0:I.info;(l=g==null?void 0:g.selection)==null||l.setSelectedIDs(d[0]);const C=g.selectedPolygon;if(d.length===1&&x){N({omitView:PointCloudView.Top,polygon:C,boxParams:x,newPointCloudBoxList:n});return}}if((a||q)&&d.length===1){const x=a!=null?a:q;g.setSelectedID(d[0]);const C=g.selectedPoint;x&&H(PointCloudView.Top,C,x,void 0,r,m)}}},$=(i,n,a)=>{if(K){let r,l;switch(a){case PointCloudView.Back:r=backViewPolygon2PointCloud;break;case PointCloudView.Side:r=sideViewPolygon2PointCloud;break;default:r=sideViewPolygon2PointCloud;break}if(l=r(i,n,K,s.pointCloudInstance),e){const{count:D}=e.getSensesPointZAxisInPolygon(lbAnnotation.getCuboidFromPointCloudBox(l).polygonPointList,[l.center.z-l.depth/2,l.center.z+l.depth/2]);l=__spreadProps(__spreadValues({},l),{count:D})}const x=z(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:[l],stepConfig:m,action:"viewUpdateBox"}))[0],C=l.valid!==x.valid;l=x;const v=st(l);return l=v.find(D=>D.id===l.id),N({omitView:C?void 0:a,polygon:i,boxParams:l,newPointCloudBoxList:v}),v}},tt=(i,n,a)=>{if(q){let r,l;switch(a){case PointCloudView.Back:r=backViewPoint2PointCloud;break;case PointCloudView.Side:r=sideViewPoint2PointCloud;break;default:r=sideViewPoint2PointCloud;break}l=r(i,n,q);const g=Y(l);return H(a,i,l,void 0,g,m),g}},gt=(i,n)=>{tt(i,n,PointCloudView.Side)},Ct=(i,n)=>{tt(i,n,PointCloudView.Back)},ft=(i,n)=>{$(i,n,PointCloudView.Side)},xt=(i,n)=>{$(i,n,PointCloudView.Back)},ht=(i,n)=>{const a=ot(i.id),r=topViewPoint2PointCloud(i,n,J,a),l=Y(r);H(PointCloudView.Top,i,r,void 0,l,m)},vt=(i,n)=>{if(B){const r=__spreadValues({},i[0].newPolygon);r.pointList=r.pointList.map(l=>lbUtils.PointCloudUtils.transferCanvas2World(l,n)),A(r);return}let a=i.map(({newPolygon:r})=>{const l=rt(r.id),{boxParams:g}=topViewPolygon2PointCloud(r,n,t.pointCloudInstance,l);return g});if(a=z(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:a,stepConfig:m,action:"viewUpdateBox"})),a.length===1){const{newPolygon:r}=i[0],l=G(a);N({polygon:r,boxParams:a[0],newPointCloudBoxList:l})}else{const r=G(a);r&&o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.MultiMove,r)}},yt=i=>{var n,a,r,l,g;if(I){const x=Number(i.widthDefault),C=Number(i.depthDefault),v=Number(i.heightDefault),D=I==null?void 0:I.info.trackID,w=((n=t==null?void 0:t.toolInstance)==null?void 0:n.polygonList).find(W=>(W==null?void 0:W.trackID)===D),y={width:(r=(a=t==null?void 0:t.toolInstance)==null?void 0:a.basicImgInfo)==null?void 0:r.width,height:(g=(l=t==null?void 0:t.toolInstance)==null?void 0:l.basicImgInfo)==null?void 0:g.height},O=w.pointList.map(W=>lbUtils.PointCloudUtils.transferCanvas2World(W,y)),Q=lbAnnotation.MathUtils.getModifiedRectangleCoordinates(O,v,x),X=Q[0],E=Q[2],F=lbAnnotation.MathUtils.getLineCenterPoint([X,E]),Lt=I.info.center.z-I.info.depth/2,et=__spreadProps(__spreadValues({},I.info),{center:{x:F.x,y:F.y,z:Lt+C/2},width:x,height:v,depth:C,valid:!0}),mt=G([et]);N({omitView:PointCloudView["3D"],polygon:w,boxParams:et,newPointCloudBoxList:mt})}},H=(i,n,a,r,l,g)=>__async(void 0,null,function*(){const x=j==null?void 0:j.url,C={[PointCloudView.Side]:()=>{syncSideViewByPoint(a,n,s,x,g)},[PointCloudView.Back]:()=>{c&&syncBackViewByPoint(a,n,c,x,g)},[PointCloudView.Top]:()=>{syncTopViewByPoint(a,n,t,e)}};Object.keys(C).forEach(v=>{v!==i&&C[v]()}),r&&(e==null||e.updateCameraZoom(r)),at(a)}),N=i=>__async(void 0,null,function*(){const{omitView:n,polygon:a,boxParams:r,zoom:l,newPointCloudBoxList:g}=i,x=j==null?void 0:j.url;g&&(yield o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Single,g));const C={[PointCloudView.Side]:()=>{synchronizeSideView(r,a,s,x)},[PointCloudView.Back]:()=>{c&&synchronizeBackView(r,a,c,x)},[PointCloudView.Top]:()=>{synchronizeTopView(r,a,t,e)}};Object.keys(C).forEach(v=>{v!==n&&C[v]()}),l&&(e==null||e.updateCameraZoom(l)),lt(r)});return{topViewAddSphere:dt,topViewAddBox:ut,topViewSelectedChanged:Pt,topViewUpdatePoint:ht,sideViewUpdatePoint:gt,backViewUpdatePoint:Ct,topViewUpdateBox:vt,sideViewUpdateBox:ft,backViewUpdateBox:xt,pointCloudBoxListUpdated:i=>{t.updatePolygonList(i),e==null||e.generateBoxes(i)},initPointCloud3d:i=>{if(!e)return;const n=lbUtils.PointCloudUtils.getDefaultOrthographicParams(i);e.initOrthographicCamera(n),e.initRenderer(),e.render()},updatePointCloudData:(...i)=>__async(void 0,[...i],function*(n=j){var a,r,l,g,x,C;if(!(n==null?void 0:n.url)||!e)return;U([]),actionCreators.SetPointCloudLoading(z,!0),actionCreators.SetLoadPCDFileLoading(z,!0),yield e.loadPCDFile(n.url,(a=m==null?void 0:m.radius)!=null?a:DEFAULT_RADIUS),e==null||e.clearAllBox(),e==null||e.clearAllSphere();let v=[],D=[],M=[],w=[];e.updateTopCamera();const y=(l=(r=index.jsonParser(n.result))==null?void 0:r.valid)!=null?l:!0;if(o.setPointCloudValid(y),(g=o.sideViewInstance)==null||g.clearAllData(),(x=o.backViewInstance)==null||x.clearAllData(),n.result){if(v=lbUtils.PointCloudUtils.getBoxParamsFromResultList(n.result),(v==null?void 0:v.length)>0&&n.isPreResult&&(m==null?void 0:m.lowerLimitPointsNumInBox)>0){v=yield e==null?void 0:e.filterPreResult(n.url,m,v);const O=index.jsonParser(n.result);O[lbUtils.POINT_CLOUD_DEFAULT_STEP].result=v,n.result=JSON.stringify(O),o.setPointCloudResult(v)}M=lbUtils.PointCloudUtils.getPolygonListFromResultList(n.result),D=lbUtils.PointCloudUtils.getLineListFromResultList(n.result),w=lbUtils.PointCloudUtils.getSphereParamsFromResultList(n.result),t.updateData(n.url,n.result,{radius:(C=m==null?void 0:m.radius)!=null?C:DEFAULT_RADIUS}),e==null||e.generateBoxes(v),e==null||e.generateSpheres(w),yield o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Default,v,[])}T({pointCloudBoxList:v,polygonList:M,lineList:D,pointCloudSphereList:w}),actionCreators.SetPointCloudLoading(z,!1),actionCreators.SetLoadPCDFileLoading(z,!1)}),updateViewsByDefaultSize:yt,generateRects:Z,update2DViewRect:ct,remove2DViewRect:pt}},useSyncRectPositionDimensionToPointCloudList=()=>{const{pointCloudBoxList:o,rectList:t,setPointCloudResult:s}=React.useContext(PointCloudContext.PointCloudContext),c=ahooks.useLatest(o),e=ahooks.useLatest(t);return{syncToPointCloudBoxList:React.useCallback(()=>{const P=c.current,u=e.current;if(u.length===0)return;const d=new Map,f=new Set;if(u.filter(h=>h.extId!==void 0).forEach(h=>{const L=h.extId,U=h.imageName,S=_.pick(h,["x","y","width","height"]);let b=d.get(L);b||(b=new Map,d.set(L,b)),b.set(U,S),f.add(L)}),d.size){const h=P.map(L=>{var U;const S=L.id;if(f.has(S)){const b=__spreadValues({},L);return(U=b.rects)==null||U.forEach(k=>{var V;const R=k.imageName;Object.assign(k,(V=d.get(S))==null?void 0:V.get(R))}),b}return L});s(h)}},[])}};exports.syncBackViewByPoint=syncBackViewByPoint,exports.syncSideViewByPoint=syncSideViewByPoint,exports.syncTopViewByPoint=syncTopViewByPoint,exports.synchronizeBackView=synchronizeBackView,exports.synchronizeSideView=synchronizeSideView,exports.synchronizeTopView=synchronizeTopView,exports.topViewPoint2PointCloud=topViewPoint2PointCloud,exports.topViewPolygon2PointCloud=topViewPolygon2PointCloud,exports.usePointCloudViews=usePointCloudViews,exports.useSyncRectPositionDimensionToPointCloudList=useSyncRectPositionDimensionToPointCloudList;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbAnnotation=require("@labelbee/lb-annotation"),lbUtils=require("@labelbee/lb-utils"),React=require("react"),PointCloudContext=require("../PointCloudContext.js"),useSingleBox=require("./useSingleBox.js"),useSphere=require("./useSphere.js"),_=require("lodash"),ctx=require("../../../store/ctx.js"),StepUtils=require("../../../utils/StepUtils.js"),ToolPointCloudBoxRenderHelper=require("../../../utils/ToolPointCloudBoxRenderHelper.js"),index=require("../../../utils/index.js"),actionCreators=require("../../../store/annotation/actionCreators.js"),useHistory=require("./useHistory.js"),usePolygon=require("./usePolygon.js"),ahooks=require("ahooks"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,s)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s,__spreadValues=(o,t)=>{for(var s in t||(t={}))__hasOwnProp.call(t,s)&&__defNormalProp(o,s,t[s]);if(__getOwnPropSymbols)for(var s of __getOwnPropSymbols(t))__propIsEnum.call(t,s)&&__defNormalProp(o,s,t[s]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t)),__async=(o,t,s)=>new Promise((c,e)=>{var p=a=>{try{u(s.next(a))}catch(x){e(x)}},g=a=>{try{u(s.throw(a))}catch(x){e(x)}},u=a=>a.done?c(a.value):Promise.resolve(a.value).then(p,g);u((s=s.apply(o,t)).next())});const DEFAULT_SCOPE=5,DEFAULT_RADIUS=90,INTELLIGENT_FIT_MARGIN=.01,PointCloudView={"3D":"3D",Top:"Top",Side:"Side",Back:"Back"},topViewPoint2PointCloud=(o,t,s,c,e)=>{const{x:p,y:g}=lbUtils.PointCloudUtils.transferCanvas2World(o,t),{defaultZ:u}=lbUtils.DEFAULT_SPHERE_PARAMS,a={center:{x:p,y:g,z:u},id:o.id},x=c?__spreadValues(__spreadValues({},c),a):__spreadProps(__spreadValues({},a),{attribute:"",valid:!0});return e&&Object.assign(x,e),x},topViewPolygon2PointCloud=(o,t,s,c,e,p)=>{let g=o.pointList.map(B=>lbUtils.PointCloudUtils.transferCanvas2World(B,t)),u=0,a=1,x={};if(s){const B=s.getSensesPointZAxisInPolygon(g,void 0,p);p&&B.fittedCoordinates.length>0&&(g=B.fittedCoordinates),u=(B.maxZ+B.minZ)/2,a=B.maxZ-B.minZ,x={count:B.zCount}}const[h,L,U]=g,I=lbAnnotation.MathUtils.getLineCenterPoint([h,U]),b=lbAnnotation.MathUtils.getLineLength(h,L),R=lbAnnotation.MathUtils.getLineLength(L,U),k=lbAnnotation.MathUtils.getRadiusFromQuadrangle(o.pointList);c&&(u=c.center.z,a=c.depth);const V={center:{x:I.x,y:I.y,z:u},width:p?R+INTELLIGENT_FIT_MARGIN:R,height:p?b+INTELLIGENT_FIT_MARGIN:b,depth:a,rotation:k,id:o.id},T=__spreadValues(c?__spreadValues(__spreadValues({},c),V):__spreadProps(__spreadValues({},V),{attribute:"",valid:!0}),x);e&&Object.assign(T,e);const A=g.map(B=>lbUtils.PointCloudUtils.transferWorld2Canvas(B,t));return{boxParams:T,newPointList:A}},sideViewPoint2PointCloud=(o,t,s)=>{const c={x:o.x-t.x,y:o.y-t.y};return __spreadProps(__spreadValues({},s),{center:{x:s.center.x-c.x,y:s.center.y,z:s.center.z-c.y}})},sideViewPolygon2PointCloud=(o,t,s,c)=>{const[e,p,g]=o.pointList,[u,a,x]=t.pointList,h=lbAnnotation.MathUtils.getLineCenterPoint([e,g]),L=lbAnnotation.MathUtils.getLineCenterPoint([u,x]),I={x:{x:h.x-L.x,y:h.y-L.y}.x,y:0,z:h.y-L.y},b=lbAnnotation.MathUtils.getLineLength(e,p),R=lbAnnotation.MathUtils.getLineLength(u,a),k=b-R,V=lbAnnotation.MathUtils.getLineLength(p,g),T=lbAnnotation.MathUtils.getLineLength(a,x),A=V-T,{newBoxParams:B}=c.getNewBoxBySideUpdate(I,A,k,s);return B},backViewPoint2PointCloud=(o,t,s)=>{const c={x:o.x-t.x,y:o.y-t.y};return __spreadProps(__spreadValues({},s),{center:{x:s.center.x,y:s.center.y-c.x,z:s.center.z-c.y}})},backViewPolygon2PointCloud=(o,t,s,c)=>{const[e,p,g]=o.pointList,[u,a,x]=t.pointList,h=lbAnnotation.MathUtils.getLineCenterPoint([e,g]),L=lbAnnotation.MathUtils.getLineCenterPoint([u,x]),I={x:{x:h.x-L.x,y:h.y-L.y}.x,y:0,z:h.y-L.y},b=lbAnnotation.MathUtils.getLineLength(e,p),R=lbAnnotation.MathUtils.getLineLength(u,a),k=b-R,V=lbAnnotation.MathUtils.getLineLength(p,g),T=lbAnnotation.MathUtils.getLineLength(a,x),A=V-T;let{newBoxParams:B}=c.getNewBoxByBackUpdate(I,A,k,s);return B},syncSideViewByPoint=(o,t,s,c,e)=>{var p;if(!s)return;const{toolInstance:g,pointCloudInstance:u}=s;u.loadPCDFile(c,(p=e==null?void 0:e.radius)!=null?p:DEFAULT_RADIUS);const{cameraPositionVector:a}=u.updateOrthoCameraBySphere(o,lbUtils.EPerspectiveView.Left);u.setInitCameraPosition(a);const{point2d:x,zoom:h}=u.getSphereSidePoint2DCoordinate(o);u.camera.zoom=h,u.camera.updateProjectionMatrix(),u.render(),g.initPosition(),g.zoomChangeOnCenter(h),g.setResult([__spreadProps(__spreadValues(__spreadValues({},t),x),{valid:o.valid,textAttribute:"",attribute:o.attribute})]),g.setSelectedID(t.id)},synchronizeSideView=(o,t,s,c)=>{if(!s)return;const{pointCloud2dOperation:e,pointCloudInstance:p}=s;p.loadPCDFileByBox(c,o,{width:DEFAULT_SCOPE,depth:DEFAULT_SCOPE});const{cameraPositionVector:g}=p.updateOrthoCamera(o,lbUtils.EPerspectiveView.Left);p.setInitCameraPosition(g);const{polygon2d:u,zoom:a}=p.getBoxSidePolygon2DCoordinate(o);p.camera.zoom=a,p.camera.updateProjectionMatrix(),p.render(),e.initPosition(),e.zoomChangeOnCenter(a),e.setResultAndSelectedID([{id:t.id,valid:o.valid,pointList:u,textAttribute:"",isRect:!0,attribute:o.attribute}],t.id)},syncBackViewByPoint=(o,t,s,c,e)=>{var p;if(!s)return;const{toolInstance:g,pointCloudInstance:u}=s;u.loadPCDFile(c,(p=e==null?void 0:e.radius)!=null?p:DEFAULT_RADIUS);const{cameraPositionVector:a}=u.updateOrthoCameraBySphere(o,lbUtils.EPerspectiveView.Back);u.setInitCameraPosition(a);const{point2d:x,zoom:h}=u.getSphereBackPoint2DCoordinate(o);u.camera.zoom=h,u.camera.updateProjectionMatrix(),u.render(),g.initPosition(),g.zoomChangeOnCenter(h),g.setResult([__spreadProps(__spreadValues(__spreadValues({},t),x),{valid:o.valid,textAttribute:"",attribute:o.attribute})]),g.setSelectedID(t.id)},synchronizeBackView=(o,t,s,c)=>{if(!s)return;const{pointCloud2dOperation:e,pointCloudInstance:p}=s;p.loadPCDFileByBox(c,o,{height:DEFAULT_SCOPE,depth:DEFAULT_SCOPE});const{cameraPositionVector:g}=p.updateOrthoCamera(o,lbUtils.EPerspectiveView.Back);p.setInitCameraPosition(g);const{polygon2d:u,zoom:a}=p.getBoxBackPolygon2DCoordinate(o);p.camera.zoom=a,p.camera.updateProjectionMatrix(),p.render(),e.initPosition(),e.zoomChangeOnCenter(a),e.setResultAndSelectedID([{id:t.id,valid:o.valid,pointList:u,textAttribute:"",isRect:!0,attribute:o.attribute}],t.id)},syncTopViewByPoint=(o,t,s,c)=>{if(!s||!c)return;c.generateSphere(o),c.updateCameraBySphere(o,lbUtils.EPerspectiveView.Top),c.render();const{toolInstance:e,pointCloudInstance:p}=s,{point2d:g}=p.getSphereTopPoint2DCoordinate(o),u=[...e.pointList].map(a=>a.id===t.id?__spreadProps(__spreadValues(__spreadValues({},t),g),{valid:o.valid,textAttribute:"",attribute:o.attribute}):a);e.setResult(u),e.setSelectedID(t.id)},synchronizeTopView=(o,t,s,c)=>{var e,p;if(!s||!c)return;c.generateBox(o,t.id),c.render();const{pointCloud2dOperation:g,pointCloudInstance:u}=s,{polygon2d:a}=u.getBoxTopPolygon2DCoordinate(o),x=[...g.polygonList],h=x.find(L=>L.id===t.id);h?(h.pointList=a,h.valid=(e=o.valid)!=null?e:!0):x.push({id:t.id,pointList:a,textAttribute:"",isRect:!0,valid:(p=o.valid)!=null?p:!0}),g.setResultAndSelectedID(x,t.id)},usePointCloudViews=()=>{const o=React.useContext(PointCloudContext.PointCloudContext),{topViewInstance:t,sideViewInstance:s,backViewInstance:c,mainViewInstance:e,addPointCloudBox:p,addPointCloudSphere:g,setSelectedIDs:u,selectedIDs:a,pointCloudBoxList:x,pointCloudSphereList:h,hideAttributes:L,setHighlight2DDataList:U,cuboidBoxIn2DView:I,imageSizes:b,history:R,linkageImageNameRectMap:k}=o,{addHistory:V,initHistory:T,pushHistoryUnderUpdatePolygon:A}=useHistory.useHistory(),{selectedPolygon:B}=usePolygon.usePolygon(),{getPointCloudSphereByID:ot,updatePointCloudSphere:Y,selectedSphere:q}=useSphere.useSphere(),{currentData:j,config:m}=ctx.useSelector(i=>{const{stepList:n,step:d,imgList:r,imgIndex:l}=i.annotation;return{currentData:r[l],config:index.jsonParser(StepUtils.getCurrentStepInfo(d,n).config)}}),M=ctx.useDispatch(),nt=ahooks.useLatest(I),it=ahooks.useLatest(k),st=React.useCallback((i,n)=>{const d=it.current,r=n.id;return i.filter(P=>{if(!P)return!1;const C=d.get(P.imageName);return C===void 0?!0:Boolean(C.get(r))})},[]),Z=i=>{const{enableAutoMap2DRect:n=!1}=m;if(!nt.current||n){const{mappingImgList:d=[]}=j;index.generatePointCloudBoxRects({pointCloudBox:i,mappingImgList:d,imageSizes:b},{prepareRectsFn:st})}},{selectedBox:D,updateSelectedBox:rt,updateSelectedBoxes:G,getPointCloudByID:lt}=useSingleBox.useSingleBox({generateRects:Z}),K=D==null?void 0:D.info;if(!t||!s||!c)return{topViewAddSphere:()=>{},topViewAddBox:()=>{},topViewSelectedChanged:()=>{},sideViewUpdateBox:()=>{},backViewUpdateBox:()=>{}};const{pointCloudInstance:J}=t,at=i=>{e==null||e.generateBox(i),e==null||e.controls.update(),e==null||e.render()},dt=i=>{e==null||e.generateSphere(i),e==null||e.controls.update(),e==null||e.render()},ut=({newPoint:i,size:n,zoom:d,trackConfigurable:r})=>{var l;const P={attribute:(l=t.toolInstance.defaultAttribute)!=null?l:""};r===!0&&Object.assign(P,{trackID:lbUtils.PointCloudUtils.getNextTrackID({imgList:[],extraBoxList:[],extraSphereList:h})});const C=topViewPoint2PointCloud(i,n,J,void 0,P);u(i.id);const f=g(C);H(PointCloudView.Top,i,C,d,f,m),V({newSphereParams:C})},ct=({polygon:i,size:n,imgList:d,trackConfigurable:r,zoom:l,intelligentFit:P})=>{var C,f,v;const S={attribute:(C=t.toolInstance.defaultAttribute)!=null?C:""};r===!0&&Object.assign(S,{trackID:lbUtils.PointCloudUtils.getNextTrackID({imgList:[],extraBoxList:x,extraSphereList:h})});const z=t==null?void 0:t.toolInstance,w=__spreadValues({},i);let{boxParams:y,newPointList:O}=topViewPolygon2PointCloud(w,n,J,void 0,S,P);y=M(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:[y],stepConfig:m,action:"viewUpdateBox"}))[0],P&&(O==null?void 0:O.length)&&(w.pointList=O);const X=L.includes(w.attribute);Z(y);const E=p(y),F=(f=o==null?void 0:o.polygonList)!=null?f:[];y.subAttribute=lbAnnotation.TagUtils.getDefaultResultByConfig((m==null?void 0:m.secondaryAttributeConfigurable)?(v=m==null?void 0:m.inputList)!=null?v:[]:[]),t==null||t.updatePolygonList(E!=null?E:[],F),X?u([]):(u(y.id),z.selection.setSelectedIDs(w.id),N({omitView:PointCloudView.Top,polygon:w,boxParams:y,zoom:l,newPointCloudBoxList:E}),P&&synchronizeTopView(y,w,t,e)),V({newBoxParams:y})},pt=i=>{const{boxID:n,imageName:d,width:r,height:l,x:P,y:C}=i,f=x.find(y=>y.id===n);if(!(f==null?void 0:f.rects)||!f.rects.find(y=>y.imageName===d))return;const S=f.rects.map(y=>y.imageName===d?__spreadProps(__spreadValues({},y),{width:r,height:l,x:P,y:C}):y),z=__spreadProps(__spreadValues({},f),{rects:S}),w=x.map(y=>y.id===n?z:y);return t==null||t.updatePolygonList(w!=null?w:[]),w},Pt=i=>{const{boxID:n,imageName:d}=i,r=x.find(f=>f.id===n);if(!(r==null?void 0:r.rects))return;const l=r.rects.filter(f=>f.imageName!==d),P=__spreadProps(__spreadValues({},r),{rects:l}),C=x.map(f=>f.id===n?P:f);return t==null||t.updatePolygonList(C!=null?C:[]),C},gt=({newSelectedBox:i,newPointCloudList:n,newSelectedSphere:d,newSphereList:r})=>{var l;const P=t==null?void 0:t.toolInstance;if(!(a.length===0||!P)){if(i||(D==null?void 0:D.info)){const C=i!=null?i:D==null?void 0:D.info;(l=P==null?void 0:P.selection)==null||l.setSelectedIDs(a[0]);const f=P.selectedPolygon;if(a.length===1&&C){N({omitView:PointCloudView.Top,polygon:f,boxParams:C,newPointCloudBoxList:n});return}}if((d||q)&&a.length===1){const C=d!=null?d:q;P.setSelectedID(a[0]);const f=P.selectedPoint;C&&H(PointCloudView.Top,f,C,void 0,r,m)}}},$=(i,n,d)=>{if(K){let r,l;switch(d){case PointCloudView.Back:r=backViewPolygon2PointCloud;break;case PointCloudView.Side:r=sideViewPolygon2PointCloud;break;default:r=sideViewPolygon2PointCloud;break}if(l=r(i,n,K,s.pointCloudInstance),e){const{count:S}=e.getSensesPointZAxisInPolygon(lbAnnotation.getCuboidFromPointCloudBox(l).polygonPointList,[l.center.z-l.depth/2,l.center.z+l.depth/2]);l=__spreadProps(__spreadValues({},l),{count:S})}const C=M(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:[l],stepConfig:m,action:"viewUpdateBox"}))[0],f=l.valid!==C.valid;l=C;const v=rt(l);return l=v.find(S=>S.id===l.id),N({omitView:f?void 0:d,polygon:i,boxParams:l,newPointCloudBoxList:v}),v}},tt=(i,n,d)=>{if(q){let r,l;switch(d){case PointCloudView.Back:r=backViewPoint2PointCloud;break;case PointCloudView.Side:r=sideViewPoint2PointCloud;break;default:r=sideViewPoint2PointCloud;break}l=r(i,n,q);const P=Y(l);return H(d,i,l,void 0,P,m),P}},Ct=(i,n)=>{tt(i,n,PointCloudView.Side)},ft=(i,n)=>{tt(i,n,PointCloudView.Back)},xt=(i,n)=>{$(i,n,PointCloudView.Side)},ht=(i,n)=>{$(i,n,PointCloudView.Back)},vt=(i,n)=>{const d=ot(i.id),r=topViewPoint2PointCloud(i,n,J,d),l=Y(r);H(PointCloudView.Top,i,r,void 0,l,m)},yt=(i,n)=>{if(B){const r=__spreadValues({},i[0].newPolygon);r.pointList=r.pointList.map(l=>lbUtils.PointCloudUtils.transferCanvas2World(l,n)),A(r);return}let d=i.map(({newPolygon:r})=>{const l=lt(r.id),{boxParams:P}=topViewPolygon2PointCloud(r,n,t.pointCloudInstance,l);return P});if(d=M(actionCreators.PreDataProcess({tool:lbAnnotation.EPointCloudName.PointCloud,dataList:d,stepConfig:m,action:"viewUpdateBox"})),d.length===1){const{newPolygon:r}=i[0],l=G(d);N({polygon:r,boxParams:d[0],newPointCloudBoxList:l})}else{const r=G(d);r&&o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.MultiMove,r)}},Lt=i=>{var n,d,r,l,P;if(D){const C=Number(i.widthDefault),f=Number(i.depthDefault),v=Number(i.heightDefault),S=D==null?void 0:D.info.trackID,w=((n=t==null?void 0:t.toolInstance)==null?void 0:n.polygonList).find(W=>(W==null?void 0:W.trackID)===S),y={width:(r=(d=t==null?void 0:t.toolInstance)==null?void 0:d.basicImgInfo)==null?void 0:r.width,height:(P=(l=t==null?void 0:t.toolInstance)==null?void 0:l.basicImgInfo)==null?void 0:P.height},O=w.pointList.map(W=>lbUtils.PointCloudUtils.transferCanvas2World(W,y)),Q=lbAnnotation.MathUtils.getModifiedRectangleCoordinates(O,v,C),X=Q[0],E=Q[2],F=lbAnnotation.MathUtils.getLineCenterPoint([X,E]),mt=D.info.center.z-D.info.depth/2,et=__spreadProps(__spreadValues({},D.info),{center:{x:F.x,y:F.y,z:mt+f/2},width:C,height:v,depth:f,valid:!0}),Bt=G([et]);N({omitView:PointCloudView["3D"],polygon:w,boxParams:et,newPointCloudBoxList:Bt})}},H=(i,n,d,r,l,P)=>__async(void 0,null,function*(){const C=j==null?void 0:j.url,f={[PointCloudView.Side]:()=>{syncSideViewByPoint(d,n,s,C,P)},[PointCloudView.Back]:()=>{c&&syncBackViewByPoint(d,n,c,C,P)},[PointCloudView.Top]:()=>{syncTopViewByPoint(d,n,t,e)}};Object.keys(f).forEach(v=>{v!==i&&f[v]()}),r&&(e==null||e.updateCameraZoom(r)),dt(d)}),N=i=>__async(void 0,null,function*(){const{omitView:n,polygon:d,boxParams:r,zoom:l,newPointCloudBoxList:P}=i,C=j==null?void 0:j.url;P&&(yield o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Single,P));const f={[PointCloudView.Side]:()=>{synchronizeSideView(r,d,s,C)},[PointCloudView.Back]:()=>{c&&synchronizeBackView(r,d,c,C)},[PointCloudView.Top]:()=>{synchronizeTopView(r,d,t,e)}};Object.keys(f).forEach(v=>{v!==n&&f[v]()}),l&&(e==null||e.updateCameraZoom(l)),at(r)});return{topViewAddSphere:ut,topViewAddBox:ct,topViewSelectedChanged:gt,topViewUpdatePoint:vt,sideViewUpdatePoint:Ct,backViewUpdatePoint:ft,topViewUpdateBox:yt,sideViewUpdateBox:xt,backViewUpdateBox:ht,pointCloudBoxListUpdated:i=>{t.updatePolygonList(i),e==null||e.generateBoxes(i)},initPointCloud3d:i=>{if(!e)return;const n=lbUtils.PointCloudUtils.getDefaultOrthographicParams(i);e.initOrthographicCamera(n),e.initRenderer(),e.render()},updatePointCloudData:(...i)=>__async(void 0,[...i],function*(n=j){var d,r,l,P,C,f;if(!(n==null?void 0:n.url)||!e)return;U([]),actionCreators.SetPointCloudLoading(M,!0),actionCreators.SetLoadPCDFileLoading(M,!0),yield e.loadPCDFile(n.url,(d=m==null?void 0:m.radius)!=null?d:DEFAULT_RADIUS),e==null||e.clearAllBox(),e==null||e.clearAllSphere();let v=[],S=[],z=[],w=[];e.updateTopCamera();const y=(l=(r=index.jsonParser(n.result))==null?void 0:r.valid)!=null?l:!0;if(o.setPointCloudValid(y),(P=o.sideViewInstance)==null||P.clearAllData(),(C=o.backViewInstance)==null||C.clearAllData(),n.result){if(v=lbUtils.PointCloudUtils.getBoxParamsFromResultList(n.result),(v==null?void 0:v.length)>0&&n.isPreResult&&(m==null?void 0:m.lowerLimitPointsNumInBox)>0){v=yield e==null?void 0:e.filterPreResult(n.url,m,v);const O=index.jsonParser(n.result);O[lbUtils.POINT_CLOUD_DEFAULT_STEP].result=v,n.result=JSON.stringify(O),o.setPointCloudResult(v)}z=lbUtils.PointCloudUtils.getPolygonListFromResultList(n.result),S=lbUtils.PointCloudUtils.getLineListFromResultList(n.result),w=lbUtils.PointCloudUtils.getSphereParamsFromResultList(n.result),t.updateData(n.url,n.result,{radius:(f=m==null?void 0:m.radius)!=null?f:DEFAULT_RADIUS}),e==null||e.generateBoxes(v),e==null||e.generateSpheres(w),yield o.syncAllViewPointCloudColor(ToolPointCloudBoxRenderHelper.EPointCloudBoxRenderTrigger.Default,v,[])}T({pointCloudBoxList:v,polygonList:z,lineList:S,pointCloudSphereList:w}),actionCreators.SetPointCloudLoading(M,!1),actionCreators.SetLoadPCDFileLoading(M,!1)}),updateViewsByDefaultSize:Lt,generateRects:Z,update2DViewRect:pt,remove2DViewRect:Pt}},useSyncRectPositionDimensionToPointCloudList=()=>{const{pointCloudBoxList:o,rectList:t,setPointCloudResult:s}=React.useContext(PointCloudContext.PointCloudContext),c=ahooks.useLatest(o),e=ahooks.useLatest(t);return{syncToPointCloudBoxList:React.useCallback(()=>{const g=c.current,u=e.current;if(u.length===0)return null;const a=new Map,x=new Set;if(u.filter(h=>h.extId!==void 0).forEach(h=>{const L=h.extId,U=h.imageName,I=_.pick(h,["x","y","width","height"]);let b=a.get(L);b||(b=new Map,a.set(L,b)),b.set(U,I),x.add(L)}),a.size){const h=g.map(L=>{var U;const I=L.id;if(x.has(I)){const b=__spreadValues({},L);return(U=b.rects)==null||U.forEach(R=>{var k;const V=R.imageName;Object.assign(R,(k=a.get(I))==null?void 0:k.get(V))}),b}return L});return s(h),h}return null},[])}};exports.syncBackViewByPoint=syncBackViewByPoint,exports.syncSideViewByPoint=syncSideViewByPoint,exports.syncTopViewByPoint=syncTopViewByPoint,exports.synchronizeBackView=synchronizeBackView,exports.synchronizeSideView=synchronizeSideView,exports.synchronizeTopView=synchronizeTopView,exports.topViewPoint2PointCloud=topViewPoint2PointCloud,exports.topViewPolygon2PointCloud=topViewPolygon2PointCloud,exports.usePointCloudViews=usePointCloudViews,exports.useSyncRectPositionDimensionToPointCloudList=useSyncRectPositionDimensionToPointCloudList;
|
|
@@ -112,5 +112,5 @@ export declare const usePointCloudViews: () => {
|
|
|
112
112
|
}) => IPointCloudBox[] | undefined;
|
|
113
113
|
};
|
|
114
114
|
export declare const useSyncRectPositionDimensionToPointCloudList: () => {
|
|
115
|
-
syncToPointCloudBoxList: () =>
|
|
115
|
+
syncToPointCloudBoxList: () => IPointCloudBox[] | null;
|
|
116
116
|
};
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),lbAnnotation=require("@labelbee/lb-annotation");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const jsonParser=(n,t={})=>{try{return typeof n=="string"?JSON.parse(n):___default.default.isObject(n)?n:t}catch(e){return t}},classnames=n=>{if(Array.isArray(n))return n.filter(t=>t).join(" ");if(___default.default.isObject(n)){const t=[];return Object.keys(n).forEach(e=>{n[e]&&t.push(e)}),t.join(" ")}return""},getBoundingRect=n=>{let t=Infinity,e=Infinity,r=-Infinity,o=-Infinity;for(const i of n)t=Math.min(t,i.x),e=Math.min(e,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y);return{x:t,y:e,width:r-t,height:o-e}},isBoundingRectInImage=(()=>{const n=(t,e)=>{const r=Math.max(t.x,e.x),o=Math.max(t.y,e.y),i=Math.min(t.x+t.width,e.x+e.width),c=Math.min(t.y+t.height,e.y+e.height),s=i-r,a=c-o;return s>=0&&a>=0?{x:r,y:o,width:s,height:a}:null};return(t,e,r)=>{if(r[e]){const o=r[e].width,i=r[e].height;return n(t,{x:0,y:0,width:o,height:i})!==null}return!1}})(),getRectPointCloudBox=n=>{var t;const{pointCloudBox:e,mappingData:r,imageSizes:o}=n,{transferViewData:i}=(t=lbAnnotation.pointCloudLidar2image(e,r.calib))!=null?t:{};if(!i)return;const c=i.reduce((u,p)=>p.type==="line"?[...u,...p.pointList]:u,[]),s=__spreadProps(__spreadValues({},getBoundingRect(c)),{imageName:r.path});if(isBoundingRectInImage(s,r.path,o))return s},generatePointCloudBoxRects=(n,t)=>{var e;const{pointCloudBox:r,mappingImgList:o,imageSizes:i}=n,s=o.map(a=>getRectPointCloudBox({pointCloudBox:r,mappingData:a,imageSizes:i})).filter(a=>a!==void 0);if(s.length>0){const a=(e=t==null?void 0:t.prepareRectsFn)!=null?e:void 0,u=a?a(s,r):s;Object.assign(r,{rects:u})}};exports.classnames=classnames,exports.generatePointCloudBoxRects=generatePointCloudBoxRects,exports.getBoundingRect=getBoundingRect,exports.getRectPointCloudBox=getRectPointCloudBox,exports.isBoundingRectInImage=isBoundingRectInImage,exports.jsonParser=jsonParser;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),lbAnnotation=require("@labelbee/lb-annotation");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const jsonParser=(n,t={})=>{try{return typeof n=="string"?JSON.parse(n):___default.default.isObject(n)?n:t}catch(e){return t}},classnames=n=>{if(Array.isArray(n))return n.filter(t=>t).join(" ");if(___default.default.isObject(n)){const t=[];return Object.keys(n).forEach(e=>{n[e]&&t.push(e)}),t.join(" ")}return""},getBoundingRect=n=>{let t=Infinity,e=Infinity,r=-Infinity,o=-Infinity;for(const i of n)t=Math.min(t,i.x),e=Math.min(e,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y);return{x:t,y:e,width:r-t,height:o-e}},isBoundingRectInImage=(()=>{const n=(t,e)=>{const r=Math.max(t.x,e.x),o=Math.max(t.y,e.y),i=Math.min(t.x+t.width,e.x+e.width),c=Math.min(t.y+t.height,e.y+e.height),s=i-r,a=c-o;return s>=0&&a>=0?{x:r,y:o,width:s,height:a}:null};return(t,e,r)=>{if(r[e]){const o=r[e].width,i=r[e].height;return n(t,{x:0,y:0,width:o,height:i})!==null}return!1}})(),getRectPointCloudBox=n=>{var t;const{pointCloudBox:e,mappingData:r,imageSizes:o}=n,{transferViewData:i}=(t=lbAnnotation.pointCloudLidar2image(e,r.calib))!=null?t:{};if(!i)return;const c=i.reduce((u,p)=>p.type==="line"?[...u,...p.pointList]:u,[]),s=__spreadProps(__spreadValues({},getBoundingRect(c)),{imageName:r.path});if(isBoundingRectInImage(s,r.path,o))return s},generatePointCloudBoxRects=(n,t)=>{var e;const{pointCloudBox:r,mappingImgList:o,imageSizes:i}=n,s=o.map(a=>getRectPointCloudBox({pointCloudBox:r,mappingData:a,imageSizes:i})).filter(a=>a!==void 0);if(s.length>0){const a=(e=t==null?void 0:t.prepareRectsFn)!=null?e:void 0,u=a?a(s,r):s;u.length>0&&Object.assign(r,{rects:u})}};exports.classnames=classnames,exports.generatePointCloudBoxRects=generatePointCloudBoxRects,exports.getBoundingRect=getBoundingRect,exports.getRectPointCloudBox=getRectPointCloudBox,exports.isBoundingRectInImage=isBoundingRectInImage,exports.jsonParser=jsonParser;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EPointCloudPattern as Y}from"@labelbee/lb-utils";import Be,{useState as r,useRef as it,useMemo as
|
|
1
|
+
import{EPointCloudPattern as Y}from"@labelbee/lb-utils";import Be,{useState as r,useRef as it,useMemo as j,useCallback as k,useEffect as $}from"react";import{EPointCloudBoxRenderTrigger as F,calcResetAreasAndBoxIds as st}from"../../utils/ToolPointCloudBoxRenderHelper.js";import{ActionsHistory as _e,EToolName as ee,uuid as rt}from"@labelbee/lb-annotation";import{useDispatch as lt}from"../../store/ctx.js";import{ChangeSave as at}from"../../store/annotation/actionCreators.js";import ct from"../../store/annotatedBox/index.js";import Ve from"lodash";import{addMapIndirectWeakSetItem as Ne}from"./utils/map.js";var dt=Object.defineProperty,ut=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,mt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,He=(a,o,c)=>o in a?dt(a,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[o]=c,E=(a,o)=>{for(var c in o||(o={}))mt.call(o,c)&&He(a,c,o[c]);if(Oe)for(var c of Oe(o))ft.call(o,c)&&He(a,c,o[c]);return a},Me=(a,o)=>ut(a,pt(o)),gt=(a,o,c)=>new Promise((L,A)=>{var B=u=>{try{P(c.next(u))}catch(C){A(C)}},G=u=>{try{P(c.throw(u))}catch(C){A(C)}},P=u=>u.done?L(u.value):Promise.resolve(u.value).then(B,G);P((c=c.apply(a,o)).next())});const z=a=>Ve.pick(a,["id","attribute","width","height","x","y","imageName"]),je=Be.createContext({rectList:[],pointCloudBoxList:[],pointCloudSphereList:[],displayPointCloudList:[],displaySphereList:[],displayLineList:[],polygonList:[],lineList:[],selectedID:"",selectedIDs:[],highlightIDs:[],setHighlightIDs:()=>{},valid:!0,setSelectedIDs:()=>{},setPointCloudResult:()=>{},setPointCloudSphereList:()=>{},setPointCloudValid:()=>{},setTopViewInstance:()=>{},setSideViewInstance:()=>{},setBackViewInstance:()=>{},setMainViewInstance:()=>{},addSelectedID:()=>{},addHighlightID:()=>{},selectedAllBoxes:()=>{},addPointCloudBox:()=>[],addPointCloudSphere:()=>[],setPolygonList:()=>{},setRectList:()=>{},addRectIn2DView:()=>{},removeRectIn2DView:()=>{},updateRectIn2DView:()=>{},setLineList:()=>{},zoom:1,setZoom:()=>{},history:new _e,hideAttributes:[],setHideAttributes:()=>{},toggleAttributesVisible:()=>{},reRender:()=>{},setAttrPanelLayout:()=>{},attrPanelLayout:"",syncAllViewPointCloudColor:()=>Promise.resolve(),defaultAttribute:"",setDefaultAttribute:()=>{},pointCloudPattern:ee.Rect,setPointCloudPattern:()=>{},selectSpecAttr:()=>{},globalPattern:Y.Detection,setGlobalPattern:()=>{},setPtSegmentInstance:()=>{},segmentation:[],setSegmentation:()=>{},clearAllDetectionInstance:()=>{},highlight2DDataList:[],setHighlight2DDataList:()=>{},cuboidBoxIn2DView:!0,setCuboidBoxIn2DView:a=>{},imageSizes:{},cacheImageNodeSize:()=>{},addRectFromPointCloudBoxByImageName:a=>!1,removeRectBySpecifyId:(a,o,c)=>!1,removeRectByPointCloudBoxId:a=>!1,rectRotateSensitivity:2,setRectRotateSensitivity:()=>{},imageNamePointCloudBoxMap:new Map,linkageImageNameRectMap:new Map,updateRectListByReducer:()=>{}}),ht=({children:a})=>{const[o,c]=r([]),[L,A]=r([]),[B,G]=r([]),[P,u]=r([]),[C,ke]=r([]),[v,T]=r([]),[_,Z]=r([]),[te,Fe]=r(!0),[oe,Ee]=r(2),[ne,ze]=r(!0),[ie,Ge]=r(1),[f,se]=r(),[re,le]=r(),[ae,ce]=r(),[p,de]=r(),[ue,Te]=r(""),[W,Ze]=r(ee.Rect),q=it(new _e).current,[g,J]=r([]),[pe,We]=r(""),[K,qe]=r(Y.Detection),[D,me]=r(void 0),[Q,Je]=r([]),[U,Ke]=r([]),h=ct(),[fe,Qe]=r({}),Ue=lt(),Xe=n=>{const{imgNode:i,path:t}=n;t&&i&&Qe(d=>Me(E({},d),{[t]:{width:i.width,height:i.height}}))},ge=j(()=>v.length===1?v[0]:"",[v]),N=k((n,i,t="extId")=>{const d=t||"id",l=new Set(i);return u(m=>{let R=!1;const x=m.filter(H=>{const X=H[d],M=l.has(X)?H.imageName!==n:!0;return M||(R=!0),M});return R?x:m}),!0},[]),he=k(n=>{const i=o.map(t=>t.id);return N(n,i,"extId")},[o,N]),Ie=k(n=>{if(!n)return!1;const i=o.filter(t=>Array.isArray(t.rects)).map(t=>{const{id:d,attribute:l,trackID:m}=t,R=t.rects.find(x=>x.imageName===n);if(R){const x=Ve.pick(R,["width","height","x","y","imageName"]);return Me(E({},x),{id:rt(),attribute:l,order:m,extId:d,lineDash:[]})}return null}).filter(t=>t!==null);return i.length?(u(t=>{const d=new Set(t.filter(m=>n===m.imageName).map(m=>m.extId)),l=i.filter(m=>d.has(m.extId)===!1);return l.length?[...t,...l]:t}),!0):!1},[o]),ve=j(()=>o.filter(i=>Array.isArray(i.rects)&&i.rects.length>0).reduce((i,t)=>{var d;return(d=t.rects)==null||d.forEach(l=>{const{imageName:m}=l;if(!m){console.warn("Missing image name"),console.trace(l,t);return}Ne(i,m,t.id,t)}),i},new Map),[o]),Pe=k(n=>{u(i=>n(i,z))},[z]),ye=j(()=>P.filter(n=>n.extId!==void 0&&n.id!==void 0).reduce((n,i)=>{const t=i.imageName;return t?(Ne(n,t,i.extId,i),n):(console.warn("missing image name"),console.log(i,P),n)},new Map),[P]),O=j(()=>{const n=o.find(e=>e.id===ge),i=e=>{const s=o.concat(e);return c(s),s},t=e=>{const s=L.concat(e);return A(s),s},d=e=>{Fe(e!==!1)},l=e=>{e===void 0&&T([]),typeof e=="string"&&T([e]),Array.isArray(e)&&T(Array.from(new Set(e)))},m=e=>{v.includes(e)?l(v.filter(s=>s!==e)):l([...v,e])},R=e=>{const s=z(e);u(I=>[...I,s])},x=(e,s=!1)=>{const I=z(e);u(y=>y.map(S=>S.id===e.id?s?E(E({},S),I):I:S))},H=e=>{u(s=>s.filter(I=>!e.find(y=>y.id===I.id)))},X=e=>{_.includes(e)?Z([]):Z([e])},M=()=>{if(W===ee.Rect){const e=o.map(s=>s.id);l(e),f==null||f.pointCloud2dOperation.setSelectedIDs(e)}},$e=e=>{l(o.filter(s=>s.attribute===e).map(s=>s.id))},Se=o.filter(e=>!g.includes(e.attribute)),be=L.filter(e=>!g.includes(e.attribute)),we=C.filter(e=>e.attribute&&!g.includes(e.attribute)),et=e=>{if(g.includes(e))J(g.filter(s=>s!==e));else{const s=g.concat(e);J(s)}},tt=(e=Se,s=B,I=be,y=we,S=Q)=>{var V;p==null||p.clearAllBox(),p==null||p.clearAllSphere(),f==null||f.updatePolygonList(e,s),f==null||f.updatePointList(I),f==null||f.updateLineList(y),p==null||p.generateBoxes(e),p==null||p.generateSpheres(I),(V=D==null?void 0:D.store)==null||V.updateCurrentSegment(S),Ce(F.Default,e)},ot=()=>{se(void 0),le(void 0),ce(void 0),de(void 0)},Ce=(e,s,I)=>gt(void 0,null,function*(){var y,S,V;if(!p)return;const Re=p.pointCloudObject;if(!Re)return;let xe=[],Le=[];try{if(s&&q.record.length){const{record:b,recordIndex:w}=q;let De=w;w>0&&(e===F.SingleToggleValid||e===F.SingleRotate||e===F.Single&&s.length===((y=b[w])==null?void 0:y.pointCloudBoxList.length))&&(De=w-1);let nt=(S=b[De])==null?void 0:S.pointCloudBoxList;const Ae=st(e,s,nt);xe=Ae.modifiedBoxIds,Le=Ae.resetAreas}}catch(b){console.error("call calcResetAreasAndBoxIds error",b)}try{const b=yield p.getHighlightIndexByMappingImgList({mappingImgList:I!=null?I:U,points:Re.geometry.attributes.position.array}),w=yield p==null?void 0:p.highlightOriginPointCloud(s,b,{modifiedBoxIds:xe,resetAreas:Le});return w&&((V=f==null?void 0:f.pointCloudInstance)==null||V.updateColor(w)),w}catch(b){console.error("call highlightOriginPointCloud error",b)}});return{selectedID:ge,pointCloudBoxList:o,pointCloudSphereList:L,displayPointCloudList:Se,displaySphereList:be,displayLineList:we,selectedIDs:v,setPointCloudResult:c,setSelectedIDs:l,addPointCloudBox:i,addPointCloudSphere:t,setPointCloudSphereList:A,valid:te,selectedPointCloudBox:n,setPointCloudValid:d,addSelectedID:m,addHighlightID:X,selectedAllBoxes:M,topViewInstance:f,setTopViewInstance:se,sideViewInstance:re,setSideViewInstance:le,backViewInstance:ae,setBackViewInstance:ce,mainViewInstance:p,setMainViewInstance:de,polygonList:B,setPolygonList:G,rectList:P,setRectList:u,addRectIn2DView:R,removeRectIn2DView:H,updateRectIn2DView:x,lineList:C,setLineList:ke,zoom:ie,setZoom:Ge,history:q,toggleAttributesVisible:et,hideAttributes:g,setHideAttributes:J,reRender:tt,attrPanelLayout:pe,setAttrPanelLayout:We,syncAllViewPointCloudColor:Ce,defaultAttribute:ue,setDefaultAttribute:Te,pointCloudPattern:W,setPointCloudPattern:Ze,selectSpecAttr:$e,globalPattern:K,setGlobalPattern:e=>{K!==e&&(Ue(at),qe(e),e===Y.Detection&&me(void 0))},ptSegmentInstance:D,setPtSegmentInstance:me,segmentation:Q,setSegmentation:Je,clearAllDetectionInstance:ot,highlight2DDataList:U,setHighlight2DDataList:Ke,cuboidBoxIn2DView:ne,setCuboidBoxIn2DView:ze,imageSizes:fe,cacheImageNodeSize:Xe,highlightIDs:_,setHighlightIDs:Z,removeRectByPointCloudBoxId:he,removeRectBySpecifyId:N,addRectFromPointCloudBoxByImageName:Ie,rectRotateSensitivity:oe,setRectRotateSensitivity:Ee,imageNamePointCloudBoxMap:ve,linkageImageNameRectMap:ye,updateRectListByReducer:Pe}},[te,v,o,L,B,C,P,f,re,ae,p,ie,g,pe,ue,W,K,D,Q,U,ne,fe,_,he,N,Ie,oe,ve,ye,Pe]);$(()=>{var n,i,t;(n=h==null?void 0:h.setPointCloudBoxList)==null||n.call(h,o),(i=h==null?void 0:h.setHighlightIDs)==null||i.call(h,_),(t=h==null?void 0:h.setSelectedIDs)==null||t.call(h,v)},[o,v,_]),$(()=>{var n;(n=h==null?void 0:h.setPtCtx)==null||n.call(h,O)},[O]);const Ye=()=>{const n=o.filter(l=>g.includes(l.attribute)),{setSelectedIDs:i,reRender:t}=O,d=n.map(l=>l.id);d.length>0&&i(v.filter(l=>!d.includes(l))),t()};return $(()=>{var n,i,t,d;Ye(),(i=(n=f==null?void 0:f.toolInstance)==null?void 0:n.setHiddenAttributes)==null||i.call(n,g),(d=(t=D==null?void 0:D.store)==null?void 0:t.setHiddenAttributes)==null||d.call(t,g)},[g]),Be.createElement(je.Provider,{value:O},a)};export{je as PointCloudContext,ht as PointCloudProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import v,{useState as T,useContext as p,useCallback as B,useMemo as h,useEffect as C}from"react";import{useLatest as s}from"ahooks";import{PointCloudContext as y}from"../PointCloudContext.js";import U from"../../../assets/annotation/icon_link.svg.js";import $ from"../../../assets/annotation/icon_unlink.svg.js";import{EventBusEvent as L}from"../../../views/MainView/toolFooter/BatchSwitchConnectIn2DView/BatchSwitchConnectIn2DView.js";import{EventBus as M}from"@labelbee/lb-annotation";import{useSyncRectPositionDimensionToPointCloudList as q}from"./usePointCloudViews.js";const A=e=>{const{imageNamePointCloudBoxMap:o,linkageImageNameRectMap:m}=p(y),r=h(()=>e?o.has(e):(console.error("Missing image name"),!1),[e,o]),d=h(()=>{var a,f;return e?((f=(a=m.get(e))==null?void 0:a.size)!=null?f:0)>0:!1},[m,e]),g=h(()=>r||d,[r,d]),I=s(g);return{visible:g,visibleRef:I}},N={width:16,height:16},G=e=>{e.imageName||console.warn("missing imageName");const[o,m]=T(!0),r=s(e.imageName),{addRectFromPointCloudBoxByImageName:d,removeRectByPointCloudBoxId:g,linkageImageNameRectMap:I,pointCloudBoxList:a,rectList:f,updateRectListByReducer:P}=p(y),{visible:R,visibleRef:D}=A(e.imageName),{syncToPointCloudBoxList:E}=q(),S=s(d),_=s(g),V=s(()=>E()),w=B(n=>{if(!D.current)return;const t=r.current;if(!t){console.warn("invalid image name");return}m(n),n?_.current(t):S.current(t)},[]),j=s(n=>{n&&V.current(),w(n)}),z=h(()=>{var n;if(!e.is2DView||!R)return null;const i={zIndex:(n=e.zIndex)!=null?n:999,position:"absolute",top:16,right:16+28+12,background:"rgba(0, 0, 0, 0.74)",color:"white",borderRadius:2,padding:6,display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28};return v.createElement("div",{style:i},o&&v.createElement("img",{src:U,style:N}),!o&&v.createElement("img",{src:$,style:N}))},[o,e.is2DView,e.zIndex,R]),F=s(I),k=B(()=>{var n,t;if(!e.is2DView)return;const i=r.current;if(!i){console.warn("invalid image name");return}const c=[...(t=(n=F.current.get(i))==null?void 0:n.keys())!=null?t:[]];let l=!0;c.length&&(l=!1),w(l)},[e.is2DView,w]);return C(()=>{k()},[k,a,f]),C(()=>{const n=a.map(i=>i.id),t=new Set(n);P((i,x)=>{const c=[],l=[];return i.forEach(u=>{const b=u.extId;b!==void 0&&t.has(b)===!1?c.push(u):l.push(u)}),c.length?[...c.map(u=>x(u)),...l]:i})},[a]),C(()=>{const n=t=>{j.current(t)};return M.on(L.switchConnect,n),()=>M.unbind(L.switchConnect,n)},[]),{rendered:z,isLinking:o}};export{G as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EPointCloudName as it,TagUtils as to,MathUtils as w,getCuboidFromPointCloudBox as oo}from"@labelbee/lb-annotation";import{EPerspectiveView as G,PointCloudUtils as O,POINT_CLOUD_DEFAULT_STEP as eo,DEFAULT_SPHERE_PARAMS as no}from"@labelbee/lb-utils";import{useContext as xt,useCallback as ht}from"react";import{PointCloudContext as Lt}from"../PointCloudContext.js";import{useSingleBox as io}from"./useSingleBox.js";import{useSphere as so}from"./useSphere.js";import{pick as ro}from"lodash";import{useSelector as lo,useDispatch as ao}from"../../../store/ctx.js";import co from"../../../utils/StepUtils.js";import{EPointCloudBoxRenderTrigger as st}from"../../../utils/ToolPointCloudBoxRenderHelper.js";import{jsonParser as rt,generatePointCloudBoxRects as uo}from"../../../utils/index.js";import{PreDataProcess as lt,SetPointCloudLoading as vt,SetLoadPCDFileLoading as yt}from"../../../store/annotation/actionCreators.js";import{useHistory as po}from"./useHistory.js";import{usePolygon as go}from"./usePolygon.js";import{useLatest as dt}from"ahooks";var fo=Object.defineProperty,Co=Object.defineProperties,Po=Object.getOwnPropertyDescriptors,Bt=Object.getOwnPropertySymbols,mo=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,bt=(e,t,s)=>t in e?fo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,v=(e,t)=>{for(var s in t||(t={}))mo.call(t,s)&&bt(e,s,t[s]);if(Bt)for(var s of Bt(t))xo.call(t,s)&&bt(e,s,t[s]);return e},k=(e,t)=>Co(e,Po(t)),at=(e,t,s)=>new Promise((u,o)=>{var p=a=>{try{c(s.next(a))}catch(P){o(P)}},g=a=>{try{c(s.throw(a))}catch(P){o(P)}},c=a=>a.done?u(a.value):Promise.resolve(a.value).then(p,g);c((s=s.apply(e,t)).next())});const q=5,K=90,wt=.01,B={"3D":"3D",Top:"Top",Side:"Side",Back:"Back"},ct=(e,t,s,u,o)=>{const{x:p,y:g}=O.transferCanvas2World(e,t),{defaultZ:c}=no,a={center:{x:p,y:g,z:c},id:e.id},P=u?v(v({},u),a):k(v({},a),{attribute:"",valid:!0});return o&&Object.assign(P,o),P},ut=(e,t,s,u,o,p)=>{let g=e.pointList.map(I=>O.transferCanvas2World(I,t)),c=0,a=1,P={};if(s){const I=s.getSensesPointZAxisInPolygon(g,void 0,p);p&&I.fittedCoordinates.length>0&&(g=I.fittedCoordinates),c=(I.maxZ+I.minZ)/2,a=I.maxZ-I.minZ,P={count:I.zCount}}const[x,y,A]=g,_=w.getLineCenterPoint([x,A]),S=w.getLineLength(x,y),z=w.getLineLength(y,A),T=w.getRadiusFromQuadrangle(e.pointList);u&&(c=u.center.z,a=u.depth);const U={center:{x:_.x,y:_.y,z:c},width:p?z+wt:z,height:p?S+wt:S,depth:a,rotation:T,id:e.id},j=v(u?v(v({},u),U):k(v({},U),{attribute:"",valid:!0}),P);o&&Object.assign(j,o);const E=g.map(I=>O.transferWorld2Canvas(I,t));return{boxParams:j,newPointList:E}},It=(e,t,s)=>{const u={x:e.x-t.x,y:e.y-t.y};return k(v({},s),{center:{x:s.center.x-u.x,y:s.center.y,z:s.center.z-u.y}})},Dt=(e,t,s,u)=>{const[o,p,g]=e.pointList,[c,a,P]=t.pointList,x=w.getLineCenterPoint([o,g]),y=w.getLineCenterPoint([c,P]),_={x:{x:x.x-y.x,y:x.y-y.y}.x,y:0,z:x.y-y.y},S=w.getLineLength(o,p),z=w.getLineLength(c,a),T=S-z,U=w.getLineLength(p,g),j=w.getLineLength(a,P),E=U-j,{newBoxParams:I}=u.getNewBoxBySideUpdate(_,E,T,s);return I},ho=(e,t,s)=>{const u={x:e.x-t.x,y:e.y-t.y};return k(v({},s),{center:{x:s.center.x,y:s.center.y-u.x,z:s.center.z-u.y}})},Lo=(e,t,s,u)=>{const[o,p,g]=e.pointList,[c,a,P]=t.pointList,x=w.getLineCenterPoint([o,g]),y=w.getLineCenterPoint([c,P]),_={x:{x:x.x-y.x,y:x.y-y.y}.x,y:0,z:x.y-y.y},S=w.getLineLength(o,p),z=w.getLineLength(c,a),T=S-z,U=w.getLineLength(p,g),j=w.getLineLength(a,P),E=U-j;let{newBoxParams:I}=u.getNewBoxByBackUpdate(_,E,T,s);return I},St=(e,t,s,u,o)=>{var p;if(!s)return;const{toolInstance:g,pointCloudInstance:c}=s;c.loadPCDFile(u,(p=o==null?void 0:o.radius)!=null?p:K);const{cameraPositionVector:a}=c.updateOrthoCameraBySphere(e,G.Left);c.setInitCameraPosition(a);const{point2d:P,zoom:x}=c.getSphereSidePoint2DCoordinate(e);c.camera.zoom=x,c.camera.updateProjectionMatrix(),c.render(),g.initPosition(),g.zoomChangeOnCenter(x),g.setResult([k(v(v({},t),P),{valid:e.valid,textAttribute:"",attribute:e.attribute})]),g.setSelectedID(t.id)},_t=(e,t,s,u)=>{if(!s)return;const{pointCloud2dOperation:o,pointCloudInstance:p}=s;p.loadPCDFileByBox(u,e,{width:q,depth:q});const{cameraPositionVector:g}=p.updateOrthoCamera(e,G.Left);p.setInitCameraPosition(g);const{polygon2d:c,zoom:a}=p.getBoxSidePolygon2DCoordinate(e);p.camera.zoom=a,p.camera.updateProjectionMatrix(),p.render(),o.initPosition(),o.zoomChangeOnCenter(a),o.setResultAndSelectedID([{id:t.id,valid:e.valid,pointList:c,textAttribute:"",isRect:!0,attribute:e.attribute}],t.id)},Rt=(e,t,s,u,o)=>{var p;if(!s)return;const{toolInstance:g,pointCloudInstance:c}=s;c.loadPCDFile(u,(p=o==null?void 0:o.radius)!=null?p:K);const{cameraPositionVector:a}=c.updateOrthoCameraBySphere(e,G.Back);c.setInitCameraPosition(a);const{point2d:P,zoom:x}=c.getSphereBackPoint2DCoordinate(e);c.camera.zoom=x,c.camera.updateProjectionMatrix(),c.render(),g.initPosition(),g.zoomChangeOnCenter(x),g.setResult([k(v(v({},t),P),{valid:e.valid,textAttribute:"",attribute:e.attribute})]),g.setSelectedID(t.id)},Vt=(e,t,s,u)=>{if(!s)return;const{pointCloud2dOperation:o,pointCloudInstance:p}=s;p.loadPCDFileByBox(u,e,{height:q,depth:q});const{cameraPositionVector:g}=p.updateOrthoCamera(e,G.Back);p.setInitCameraPosition(g);const{polygon2d:c,zoom:a}=p.getBoxBackPolygon2DCoordinate(e);p.camera.zoom=a,p.camera.updateProjectionMatrix(),p.render(),o.initPosition(),o.zoomChangeOnCenter(a),o.setResultAndSelectedID([{id:t.id,valid:e.valid,pointList:c,textAttribute:"",isRect:!0,attribute:e.attribute}],t.id)},Ot=(e,t,s,u)=>{if(!s||!u)return;u.generateSphere(e),u.updateCameraBySphere(e,G.Top),u.render();const{toolInstance:o,pointCloudInstance:p}=s,{point2d:g}=p.getSphereTopPoint2DCoordinate(e),c=[...o.pointList].map(a=>a.id===t.id?k(v(v({},t),g),{valid:e.valid,textAttribute:"",attribute:e.attribute}):a);o.setResult(c),o.setSelectedID(t.id)},pt=(e,t,s,u)=>{var o,p;if(!s||!u)return;u.generateBox(e,t.id),u.render();const{pointCloud2dOperation:g,pointCloudInstance:c}=s,{polygon2d:a}=c.getBoxTopPolygon2DCoordinate(e),P=[...g.polygonList],x=P.find(y=>y.id===t.id);x?(x.pointList=a,x.valid=(o=e.valid)!=null?o:!0):P.push({id:t.id,pointList:a,textAttribute:"",isRect:!0,valid:(p=e.valid)!=null?p:!0}),g.setResultAndSelectedID(P,t.id)},vo=()=>{const e=xt(Lt),{topViewInstance:t,sideViewInstance:s,backViewInstance:u,mainViewInstance:o,addPointCloudBox:p,addPointCloudSphere:g,setSelectedIDs:c,selectedIDs:a,pointCloudBoxList:P,pointCloudSphereList:x,hideAttributes:y,setHighlight2DDataList:A,cuboidBoxIn2DView:_,imageSizes:S,history:z,linkageImageNameRectMap:T}=e,{addHistory:U,initHistory:j,pushHistoryUnderUpdatePolygon:E}=po(),{selectedPolygon:I}=go(),{getPointCloudSphereByID:kt,updatePointCloudSphere:gt,selectedSphere:J}=so(),{currentData:H,config:b}=lo(n=>{const{stepList:i,step:d,imgList:r,imgIndex:l}=n.annotation;return{currentData:r[l],config:rt(co.getCurrentStepInfo(d,i).config)}}),M=ao(),At=dt(_),Tt=ht(n=>n.filter(d=>{var r,l;return d&&((l=(r=T.get(d.imageName))==null?void 0:r.size)!=null?l:0)===0}),[T]),$=n=>{const{enableAutoMap2DRect:i=!1}=b;if(!At.current||i){const{mappingImgList:d=[]}=H;uo({pointCloudBox:n,mappingImgList:d,imageSizes:S},{prepareRectsFn:Tt})}},{selectedBox:V,updateSelectedBox:Ut,updateSelectedBoxes:tt,getPointCloudByID:zt}=io({generateRects:$}),ft=V==null?void 0:V.info;if(!t||!s||!u)return{topViewAddSphere:()=>{},topViewAddBox:()=>{},topViewSelectedChanged:()=>{},sideViewUpdateBox:()=>{},backViewUpdateBox:()=>{}};const{pointCloudInstance:ot}=t,jt=n=>{o==null||o.generateBox(n),o==null||o.controls.update(),o==null||o.render()},Nt=n=>{o==null||o.generateSphere(n),o==null||o.controls.update(),o==null||o.render()},Et=({newPoint:n,size:i,zoom:d,trackConfigurable:r})=>{var l;const f={attribute:(l=t.toolInstance.defaultAttribute)!=null?l:""};r===!0&&Object.assign(f,{trackID:O.getNextTrackID({imgList:[],extraBoxList:[],extraSphereList:x})});const m=ct(n,i,ot,void 0,f);c(n.id);const C=g(m);Q(B.Top,n,m,d,C,b),U({newSphereParams:m})},Mt=({polygon:n,size:i,imgList:d,trackConfigurable:r,zoom:l,intelligentFit:f})=>{var m,C,h;const R={attribute:(m=t.toolInstance.defaultAttribute)!=null?m:""};r===!0&&Object.assign(R,{trackID:O.getNextTrackID({imgList:[],extraBoxList:P,extraSphereList:x})});const F=t==null?void 0:t.toolInstance,D=v({},n);let{boxParams:L,newPointList:N}=ut(D,i,ot,void 0,R,f);L=M(lt({tool:it.PointCloud,dataList:[L],stepConfig:b,action:"viewUpdateBox"}))[0],f&&(N==null?void 0:N.length)&&(D.pointList=N);const nt=y.includes(D.attribute);$(L);const Z=p(L),X=(C=e==null?void 0:e.polygonList)!=null?C:[];L.subAttribute=to.getDefaultResultByConfig((b==null?void 0:b.secondaryAttributeConfigurable)?(h=b==null?void 0:b.inputList)!=null?h:[]:[]),t==null||t.updatePolygonList(Z!=null?Z:[],X),nt?c([]):(c(L.id),F.selection.setSelectedIDs(D.id),W({omitView:B.Top,polygon:D,boxParams:L,zoom:l,newPointCloudBoxList:Z}),f&&pt(L,D,t,o)),U({newBoxParams:L})},Ft=n=>{const{boxID:i,imageName:d,width:r,height:l,x:f,y:m}=n,C=P.find(L=>L.id===i);if(!(C==null?void 0:C.rects)||!C.rects.find(L=>L.imageName===d))return;const R=C.rects.map(L=>L.imageName===d?k(v({},L),{width:r,height:l,x:f,y:m}):L),F=k(v({},C),{rects:R}),D=P.map(L=>L.id===i?F:L);return t==null||t.updatePolygonList(D!=null?D:[]),D},Ht=n=>{const{boxID:i,imageName:d}=n,r=P.find(C=>C.id===i);if(!(r==null?void 0:r.rects))return;const l=r.rects.filter(C=>C.imageName!==d),f=k(v({},r),{rects:l}),m=P.map(C=>C.id===i?f:C);return t==null||t.updatePolygonList(m!=null?m:[]),m},Wt=({newSelectedBox:n,newPointCloudList:i,newSelectedSphere:d,newSphereList:r})=>{var l;const f=t==null?void 0:t.toolInstance;if(!(a.length===0||!f)){if(n||(V==null?void 0:V.info)){const m=n!=null?n:V==null?void 0:V.info;(l=f==null?void 0:f.selection)==null||l.setSelectedIDs(a[0]);const C=f.selectedPolygon;if(a.length===1&&m){W({omitView:B.Top,polygon:C,boxParams:m,newPointCloudBoxList:i});return}}if((d||J)&&a.length===1){const m=d!=null?d:J;f.setSelectedID(a[0]);const C=f.selectedPoint;m&&Q(B.Top,C,m,void 0,r,b)}}},Ct=(n,i,d)=>{if(ft){let r,l;switch(d){case B.Back:r=Lo;break;case B.Side:r=Dt;break;default:r=Dt;break}if(l=r(n,i,ft,s.pointCloudInstance),o){const{count:R}=o.getSensesPointZAxisInPolygon(oo(l).polygonPointList,[l.center.z-l.depth/2,l.center.z+l.depth/2]);l=k(v({},l),{count:R})}const m=M(lt({tool:it.PointCloud,dataList:[l],stepConfig:b,action:"viewUpdateBox"}))[0],C=l.valid!==m.valid;l=m;const h=Ut(l);return l=h.find(R=>R.id===l.id),W({omitView:C?void 0:d,polygon:n,boxParams:l,newPointCloudBoxList:h}),h}},Pt=(n,i,d)=>{if(J){let r,l;switch(d){case B.Back:r=ho;break;case B.Side:r=It;break;default:r=It;break}l=r(n,i,J);const f=gt(l);return Q(d,n,l,void 0,f,b),f}},Zt=(n,i)=>{Pt(n,i,B.Side)},Gt=(n,i)=>{Pt(n,i,B.Back)},Jt=(n,i)=>{Ct(n,i,B.Side)},Qt=(n,i)=>{Ct(n,i,B.Back)},Xt=(n,i)=>{const d=kt(n.id),r=ct(n,i,ot,d),l=gt(r);Q(B.Top,n,r,void 0,l,b)},Yt=(n,i)=>{if(I){const r=v({},n[0].newPolygon);r.pointList=r.pointList.map(l=>O.transferCanvas2World(l,i)),E(r);return}let d=n.map(({newPolygon:r})=>{const l=zt(r.id),{boxParams:f}=ut(r,i,t.pointCloudInstance,l);return f});if(d=M(lt({tool:it.PointCloud,dataList:d,stepConfig:b,action:"viewUpdateBox"})),d.length===1){const{newPolygon:r}=n[0],l=tt(d);W({polygon:r,boxParams:d[0],newPointCloudBoxList:l})}else{const r=tt(d);r&&e.syncAllViewPointCloudColor(st.MultiMove,r)}},qt=n=>{var i,d,r,l,f;if(V){const m=Number(n.widthDefault),C=Number(n.depthDefault),h=Number(n.heightDefault),R=V==null?void 0:V.info.trackID,D=((i=t==null?void 0:t.toolInstance)==null?void 0:i.polygonList).find(Y=>(Y==null?void 0:Y.trackID)===R),L={width:(r=(d=t==null?void 0:t.toolInstance)==null?void 0:d.basicImgInfo)==null?void 0:r.width,height:(f=(l=t==null?void 0:t.toolInstance)==null?void 0:l.basicImgInfo)==null?void 0:f.height},N=D.pointList.map(Y=>O.transferCanvas2World(Y,L)),et=w.getModifiedRectangleCoordinates(N,h,m),nt=et[0],Z=et[2],X=w.getLineCenterPoint([nt,Z]),Kt=V.info.center.z-V.info.depth/2,mt=k(v({},V.info),{center:{x:X.x,y:X.y,z:Kt+C/2},width:m,height:h,depth:C,valid:!0}),$t=tt([mt]);W({omitView:B["3D"],polygon:D,boxParams:mt,newPointCloudBoxList:$t})}},Q=(n,i,d,r,l,f)=>at(void 0,null,function*(){const m=H==null?void 0:H.url,C={[B.Side]:()=>{St(d,i,s,m,f)},[B.Back]:()=>{u&&Rt(d,i,u,m,f)},[B.Top]:()=>{Ot(d,i,t,o)}};Object.keys(C).forEach(h=>{h!==n&&C[h]()}),r&&(o==null||o.updateCameraZoom(r)),Nt(d)}),W=n=>at(void 0,null,function*(){const{omitView:i,polygon:d,boxParams:r,zoom:l,newPointCloudBoxList:f}=n,m=H==null?void 0:H.url;f&&(yield e.syncAllViewPointCloudColor(st.Single,f));const C={[B.Side]:()=>{_t(r,d,s,m)},[B.Back]:()=>{u&&Vt(r,d,u,m)},[B.Top]:()=>{pt(r,d,t,o)}};Object.keys(C).forEach(h=>{h!==i&&C[h]()}),l&&(o==null||o.updateCameraZoom(l)),jt(r)});return{topViewAddSphere:Et,topViewAddBox:Mt,topViewSelectedChanged:Wt,topViewUpdatePoint:Xt,sideViewUpdatePoint:Zt,backViewUpdatePoint:Gt,topViewUpdateBox:Yt,sideViewUpdateBox:Jt,backViewUpdateBox:Qt,pointCloudBoxListUpdated:n=>{t.updatePolygonList(n),o==null||o.generateBoxes(n)},initPointCloud3d:n=>{if(!o)return;const i=O.getDefaultOrthographicParams(n);o.initOrthographicCamera(i),o.initRenderer(),o.render()},updatePointCloudData:(...n)=>at(void 0,[...n],function*(i=H){var d,r,l,f,m,C;if(!(i==null?void 0:i.url)||!o)return;A([]),vt(M,!0),yt(M,!0),yield o.loadPCDFile(i.url,(d=b==null?void 0:b.radius)!=null?d:K),o==null||o.clearAllBox(),o==null||o.clearAllSphere();let h=[],R=[],F=[],D=[];o.updateTopCamera();const L=(l=(r=rt(i.result))==null?void 0:r.valid)!=null?l:!0;if(e.setPointCloudValid(L),(f=e.sideViewInstance)==null||f.clearAllData(),(m=e.backViewInstance)==null||m.clearAllData(),i.result){if(h=O.getBoxParamsFromResultList(i.result),(h==null?void 0:h.length)>0&&i.isPreResult&&(b==null?void 0:b.lowerLimitPointsNumInBox)>0){h=yield o==null?void 0:o.filterPreResult(i.url,b,h);const N=rt(i.result);N[eo].result=h,i.result=JSON.stringify(N),e.setPointCloudResult(h)}F=O.getPolygonListFromResultList(i.result),R=O.getLineListFromResultList(i.result),D=O.getSphereParamsFromResultList(i.result),t.updateData(i.url,i.result,{radius:(C=b==null?void 0:b.radius)!=null?C:K}),o==null||o.generateBoxes(h),o==null||o.generateSpheres(D),yield e.syncAllViewPointCloudColor(st.Default,h,[])}j({pointCloudBoxList:h,polygonList:F,lineList:R,pointCloudSphereList:D}),vt(M,!1),yt(M,!1)}),updateViewsByDefaultSize:qt,generateRects:$,update2DViewRect:Ft,remove2DViewRect:Ht}},yo=()=>{const{pointCloudBoxList:e,rectList:t,setPointCloudResult:s}=xt(Lt),u=dt(e),o=dt(t);return{syncToPointCloudBoxList:ht(()=>{const g=u.current,c=o.current;if(c.length===0)return;const a=new Map,P=new Set;if(c.filter(x=>x.extId!==void 0).forEach(x=>{const y=x.extId,A=x.imageName,_=ro(x,["x","y","width","height"]);let S=a.get(y);S||(S=new Map,a.set(y,S)),S.set(A,_),P.add(y)}),a.size){const x=g.map(y=>{var A;const _=y.id;if(P.has(_)){const S=v({},y);return(A=S.rects)==null||A.forEach(z=>{var T;const U=z.imageName;Object.assign(z,(T=a.get(_))==null?void 0:T.get(U))}),S}return y});s(x)}},[])}};export{Rt as syncBackViewByPoint,St as syncSideViewByPoint,Ot as syncTopViewByPoint,Vt as synchronizeBackView,_t as synchronizeSideView,pt as synchronizeTopView,ct as topViewPoint2PointCloud,ut as topViewPolygon2PointCloud,vo as usePointCloudViews,yo as useSyncRectPositionDimensionToPointCloudList};
|
|
1
|
+
import{EPointCloudName as st,TagUtils as oo,MathUtils as w,getCuboidFromPointCloudBox as eo}from"@labelbee/lb-annotation";import{EPerspectiveView as G,PointCloudUtils as k,POINT_CLOUD_DEFAULT_STEP as no,DEFAULT_SPHERE_PARAMS as io}from"@labelbee/lb-utils";import{useContext as xt,useCallback as ht}from"react";import{PointCloudContext as Lt}from"../PointCloudContext.js";import{useSingleBox as so}from"./useSingleBox.js";import{useSphere as ro}from"./useSphere.js";import{pick as lo}from"lodash";import{useSelector as ao,useDispatch as co}from"../../../store/ctx.js";import uo from"../../../utils/StepUtils.js";import{EPointCloudBoxRenderTrigger as rt}from"../../../utils/ToolPointCloudBoxRenderHelper.js";import{jsonParser as lt,generatePointCloudBoxRects as po}from"../../../utils/index.js";import{PreDataProcess as dt,SetPointCloudLoading as vt,SetLoadPCDFileLoading as yt}from"../../../store/annotation/actionCreators.js";import{useHistory as go}from"./useHistory.js";import{usePolygon as fo}from"./usePolygon.js";import{useLatest as q}from"ahooks";var Co=Object.defineProperty,Po=Object.defineProperties,mo=Object.getOwnPropertyDescriptors,Bt=Object.getOwnPropertySymbols,xo=Object.prototype.hasOwnProperty,ho=Object.prototype.propertyIsEnumerable,bt=(e,t,s)=>t in e?Co(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,v=(e,t)=>{for(var s in t||(t={}))xo.call(t,s)&&bt(e,s,t[s]);if(Bt)for(var s of Bt(t))ho.call(t,s)&&bt(e,s,t[s]);return e},O=(e,t)=>Po(e,mo(t)),at=(e,t,s)=>new Promise((u,o)=>{var p=d=>{try{c(s.next(d))}catch(m){o(m)}},f=d=>{try{c(s.throw(d))}catch(m){o(m)}},c=d=>d.done?u(d.value):Promise.resolve(d.value).then(p,f);c((s=s.apply(e,t)).next())});const K=5,$=90,wt=.01,B={"3D":"3D",Top:"Top",Side:"Side",Back:"Back"},ct=(e,t,s,u,o)=>{const{x:p,y:f}=k.transferCanvas2World(e,t),{defaultZ:c}=io,d={center:{x:p,y:f,z:c},id:e.id},m=u?v(v({},u),d):O(v({},d),{attribute:"",valid:!0});return o&&Object.assign(m,o),m},ut=(e,t,s,u,o,p)=>{let f=e.pointList.map(I=>k.transferCanvas2World(I,t)),c=0,d=1,m={};if(s){const I=s.getSensesPointZAxisInPolygon(f,void 0,p);p&&I.fittedCoordinates.length>0&&(f=I.fittedCoordinates),c=(I.maxZ+I.minZ)/2,d=I.maxZ-I.minZ,m={count:I.zCount}}const[x,y,A]=f,R=w.getLineCenterPoint([x,A]),S=w.getLineLength(x,y),U=w.getLineLength(y,A),z=w.getRadiusFromQuadrangle(e.pointList);u&&(c=u.center.z,d=u.depth);const T={center:{x:R.x,y:R.y,z:c},width:p?U+wt:U,height:p?S+wt:S,depth:d,rotation:z,id:e.id},N=v(u?v(v({},u),T):O(v({},T),{attribute:"",valid:!0}),m);o&&Object.assign(N,o);const E=f.map(I=>k.transferWorld2Canvas(I,t));return{boxParams:N,newPointList:E}},It=(e,t,s)=>{const u={x:e.x-t.x,y:e.y-t.y};return O(v({},s),{center:{x:s.center.x-u.x,y:s.center.y,z:s.center.z-u.y}})},Dt=(e,t,s,u)=>{const[o,p,f]=e.pointList,[c,d,m]=t.pointList,x=w.getLineCenterPoint([o,f]),y=w.getLineCenterPoint([c,m]),R={x:{x:x.x-y.x,y:x.y-y.y}.x,y:0,z:x.y-y.y},S=w.getLineLength(o,p),U=w.getLineLength(c,d),z=S-U,T=w.getLineLength(p,f),N=w.getLineLength(d,m),E=T-N,{newBoxParams:I}=u.getNewBoxBySideUpdate(R,E,z,s);return I},Lo=(e,t,s)=>{const u={x:e.x-t.x,y:e.y-t.y};return O(v({},s),{center:{x:s.center.x,y:s.center.y-u.x,z:s.center.z-u.y}})},vo=(e,t,s,u)=>{const[o,p,f]=e.pointList,[c,d,m]=t.pointList,x=w.getLineCenterPoint([o,f]),y=w.getLineCenterPoint([c,m]),R={x:{x:x.x-y.x,y:x.y-y.y}.x,y:0,z:x.y-y.y},S=w.getLineLength(o,p),U=w.getLineLength(c,d),z=S-U,T=w.getLineLength(p,f),N=w.getLineLength(d,m),E=T-N;let{newBoxParams:I}=u.getNewBoxByBackUpdate(R,E,z,s);return I},St=(e,t,s,u,o)=>{var p;if(!s)return;const{toolInstance:f,pointCloudInstance:c}=s;c.loadPCDFile(u,(p=o==null?void 0:o.radius)!=null?p:$);const{cameraPositionVector:d}=c.updateOrthoCameraBySphere(e,G.Left);c.setInitCameraPosition(d);const{point2d:m,zoom:x}=c.getSphereSidePoint2DCoordinate(e);c.camera.zoom=x,c.camera.updateProjectionMatrix(),c.render(),f.initPosition(),f.zoomChangeOnCenter(x),f.setResult([O(v(v({},t),m),{valid:e.valid,textAttribute:"",attribute:e.attribute})]),f.setSelectedID(t.id)},Rt=(e,t,s,u)=>{if(!s)return;const{pointCloud2dOperation:o,pointCloudInstance:p}=s;p.loadPCDFileByBox(u,e,{width:K,depth:K});const{cameraPositionVector:f}=p.updateOrthoCamera(e,G.Left);p.setInitCameraPosition(f);const{polygon2d:c,zoom:d}=p.getBoxSidePolygon2DCoordinate(e);p.camera.zoom=d,p.camera.updateProjectionMatrix(),p.render(),o.initPosition(),o.zoomChangeOnCenter(d),o.setResultAndSelectedID([{id:t.id,valid:e.valid,pointList:c,textAttribute:"",isRect:!0,attribute:e.attribute}],t.id)},_t=(e,t,s,u,o)=>{var p;if(!s)return;const{toolInstance:f,pointCloudInstance:c}=s;c.loadPCDFile(u,(p=o==null?void 0:o.radius)!=null?p:$);const{cameraPositionVector:d}=c.updateOrthoCameraBySphere(e,G.Back);c.setInitCameraPosition(d);const{point2d:m,zoom:x}=c.getSphereBackPoint2DCoordinate(e);c.camera.zoom=x,c.camera.updateProjectionMatrix(),c.render(),f.initPosition(),f.zoomChangeOnCenter(x),f.setResult([O(v(v({},t),m),{valid:e.valid,textAttribute:"",attribute:e.attribute})]),f.setSelectedID(t.id)},Vt=(e,t,s,u)=>{if(!s)return;const{pointCloud2dOperation:o,pointCloudInstance:p}=s;p.loadPCDFileByBox(u,e,{height:K,depth:K});const{cameraPositionVector:f}=p.updateOrthoCamera(e,G.Back);p.setInitCameraPosition(f);const{polygon2d:c,zoom:d}=p.getBoxBackPolygon2DCoordinate(e);p.camera.zoom=d,p.camera.updateProjectionMatrix(),p.render(),o.initPosition(),o.zoomChangeOnCenter(d),o.setResultAndSelectedID([{id:t.id,valid:e.valid,pointList:c,textAttribute:"",isRect:!0,attribute:e.attribute}],t.id)},kt=(e,t,s,u)=>{if(!s||!u)return;u.generateSphere(e),u.updateCameraBySphere(e,G.Top),u.render();const{toolInstance:o,pointCloudInstance:p}=s,{point2d:f}=p.getSphereTopPoint2DCoordinate(e),c=[...o.pointList].map(d=>d.id===t.id?O(v(v({},t),f),{valid:e.valid,textAttribute:"",attribute:e.attribute}):d);o.setResult(c),o.setSelectedID(t.id)},pt=(e,t,s,u)=>{var o,p;if(!s||!u)return;u.generateBox(e,t.id),u.render();const{pointCloud2dOperation:f,pointCloudInstance:c}=s,{polygon2d:d}=c.getBoxTopPolygon2DCoordinate(e),m=[...f.polygonList],x=m.find(y=>y.id===t.id);x?(x.pointList=d,x.valid=(o=e.valid)!=null?o:!0):m.push({id:t.id,pointList:d,textAttribute:"",isRect:!0,valid:(p=e.valid)!=null?p:!0}),f.setResultAndSelectedID(m,t.id)},yo=()=>{const e=xt(Lt),{topViewInstance:t,sideViewInstance:s,backViewInstance:u,mainViewInstance:o,addPointCloudBox:p,addPointCloudSphere:f,setSelectedIDs:c,selectedIDs:d,pointCloudBoxList:m,pointCloudSphereList:x,hideAttributes:y,setHighlight2DDataList:A,cuboidBoxIn2DView:R,imageSizes:S,history:U,linkageImageNameRectMap:z}=e,{addHistory:T,initHistory:N,pushHistoryUnderUpdatePolygon:E}=go(),{selectedPolygon:I}=fo(),{getPointCloudSphereByID:Ot,updatePointCloudSphere:gt,selectedSphere:J}=ro(),{currentData:H,config:b}=ao(i=>{const{stepList:n,step:a,imgList:r,imgIndex:l}=i.annotation;return{currentData:r[l],config:lt(uo.getCurrentStepInfo(a,n).config)}}),M=co(),At=q(R),Tt=q(z),Ut=ht((i,n)=>{const a=Tt.current,r=n.id;return i.filter(g=>{if(!g)return!1;const C=a.get(g.imageName);return C===void 0?!0:Boolean(C.get(r))})},[]),tt=i=>{const{enableAutoMap2DRect:n=!1}=b;if(!At.current||n){const{mappingImgList:a=[]}=H;po({pointCloudBox:i,mappingImgList:a,imageSizes:S},{prepareRectsFn:Ut})}},{selectedBox:V,updateSelectedBox:zt,updateSelectedBoxes:ot,getPointCloudByID:Nt}=so({generateRects:tt}),ft=V==null?void 0:V.info;if(!t||!s||!u)return{topViewAddSphere:()=>{},topViewAddBox:()=>{},topViewSelectedChanged:()=>{},sideViewUpdateBox:()=>{},backViewUpdateBox:()=>{}};const{pointCloudInstance:et}=t,jt=i=>{o==null||o.generateBox(i),o==null||o.controls.update(),o==null||o.render()},Et=i=>{o==null||o.generateSphere(i),o==null||o.controls.update(),o==null||o.render()},Mt=({newPoint:i,size:n,zoom:a,trackConfigurable:r})=>{var l;const g={attribute:(l=t.toolInstance.defaultAttribute)!=null?l:""};r===!0&&Object.assign(g,{trackID:k.getNextTrackID({imgList:[],extraBoxList:[],extraSphereList:x})});const C=ct(i,n,et,void 0,g);c(i.id);const P=f(C);Q(B.Top,i,C,a,P,b),T({newSphereParams:C})},Ft=({polygon:i,size:n,imgList:a,trackConfigurable:r,zoom:l,intelligentFit:g})=>{var C,P,h;const _={attribute:(C=t.toolInstance.defaultAttribute)!=null?C:""};r===!0&&Object.assign(_,{trackID:k.getNextTrackID({imgList:[],extraBoxList:m,extraSphereList:x})});const F=t==null?void 0:t.toolInstance,D=v({},i);let{boxParams:L,newPointList:j}=ut(D,n,et,void 0,_,g);L=M(dt({tool:st.PointCloud,dataList:[L],stepConfig:b,action:"viewUpdateBox"}))[0],g&&(j==null?void 0:j.length)&&(D.pointList=j);const it=y.includes(D.attribute);tt(L);const Z=p(L),X=(P=e==null?void 0:e.polygonList)!=null?P:[];L.subAttribute=oo.getDefaultResultByConfig((b==null?void 0:b.secondaryAttributeConfigurable)?(h=b==null?void 0:b.inputList)!=null?h:[]:[]),t==null||t.updatePolygonList(Z!=null?Z:[],X),it?c([]):(c(L.id),F.selection.setSelectedIDs(D.id),W({omitView:B.Top,polygon:D,boxParams:L,zoom:l,newPointCloudBoxList:Z}),g&&pt(L,D,t,o)),T({newBoxParams:L})},Ht=i=>{const{boxID:n,imageName:a,width:r,height:l,x:g,y:C}=i,P=m.find(L=>L.id===n);if(!(P==null?void 0:P.rects)||!P.rects.find(L=>L.imageName===a))return;const _=P.rects.map(L=>L.imageName===a?O(v({},L),{width:r,height:l,x:g,y:C}):L),F=O(v({},P),{rects:_}),D=m.map(L=>L.id===n?F:L);return t==null||t.updatePolygonList(D!=null?D:[]),D},Wt=i=>{const{boxID:n,imageName:a}=i,r=m.find(P=>P.id===n);if(!(r==null?void 0:r.rects))return;const l=r.rects.filter(P=>P.imageName!==a),g=O(v({},r),{rects:l}),C=m.map(P=>P.id===n?g:P);return t==null||t.updatePolygonList(C!=null?C:[]),C},Zt=({newSelectedBox:i,newPointCloudList:n,newSelectedSphere:a,newSphereList:r})=>{var l;const g=t==null?void 0:t.toolInstance;if(!(d.length===0||!g)){if(i||(V==null?void 0:V.info)){const C=i!=null?i:V==null?void 0:V.info;(l=g==null?void 0:g.selection)==null||l.setSelectedIDs(d[0]);const P=g.selectedPolygon;if(d.length===1&&C){W({omitView:B.Top,polygon:P,boxParams:C,newPointCloudBoxList:n});return}}if((a||J)&&d.length===1){const C=a!=null?a:J;g.setSelectedID(d[0]);const P=g.selectedPoint;C&&Q(B.Top,P,C,void 0,r,b)}}},Ct=(i,n,a)=>{if(ft){let r,l;switch(a){case B.Back:r=vo;break;case B.Side:r=Dt;break;default:r=Dt;break}if(l=r(i,n,ft,s.pointCloudInstance),o){const{count:_}=o.getSensesPointZAxisInPolygon(eo(l).polygonPointList,[l.center.z-l.depth/2,l.center.z+l.depth/2]);l=O(v({},l),{count:_})}const C=M(dt({tool:st.PointCloud,dataList:[l],stepConfig:b,action:"viewUpdateBox"}))[0],P=l.valid!==C.valid;l=C;const h=zt(l);return l=h.find(_=>_.id===l.id),W({omitView:P?void 0:a,polygon:i,boxParams:l,newPointCloudBoxList:h}),h}},Pt=(i,n,a)=>{if(J){let r,l;switch(a){case B.Back:r=Lo;break;case B.Side:r=It;break;default:r=It;break}l=r(i,n,J);const g=gt(l);return Q(a,i,l,void 0,g,b),g}},Gt=(i,n)=>{Pt(i,n,B.Side)},Jt=(i,n)=>{Pt(i,n,B.Back)},Qt=(i,n)=>{Ct(i,n,B.Side)},Xt=(i,n)=>{Ct(i,n,B.Back)},Yt=(i,n)=>{const a=Ot(i.id),r=ct(i,n,et,a),l=gt(r);Q(B.Top,i,r,void 0,l,b)},qt=(i,n)=>{if(I){const r=v({},i[0].newPolygon);r.pointList=r.pointList.map(l=>k.transferCanvas2World(l,n)),E(r);return}let a=i.map(({newPolygon:r})=>{const l=Nt(r.id),{boxParams:g}=ut(r,n,t.pointCloudInstance,l);return g});if(a=M(dt({tool:st.PointCloud,dataList:a,stepConfig:b,action:"viewUpdateBox"})),a.length===1){const{newPolygon:r}=i[0],l=ot(a);W({polygon:r,boxParams:a[0],newPointCloudBoxList:l})}else{const r=ot(a);r&&e.syncAllViewPointCloudColor(rt.MultiMove,r)}},Kt=i=>{var n,a,r,l,g;if(V){const C=Number(i.widthDefault),P=Number(i.depthDefault),h=Number(i.heightDefault),_=V==null?void 0:V.info.trackID,D=((n=t==null?void 0:t.toolInstance)==null?void 0:n.polygonList).find(Y=>(Y==null?void 0:Y.trackID)===_),L={width:(r=(a=t==null?void 0:t.toolInstance)==null?void 0:a.basicImgInfo)==null?void 0:r.width,height:(g=(l=t==null?void 0:t.toolInstance)==null?void 0:l.basicImgInfo)==null?void 0:g.height},j=D.pointList.map(Y=>k.transferCanvas2World(Y,L)),nt=w.getModifiedRectangleCoordinates(j,h,C),it=nt[0],Z=nt[2],X=w.getLineCenterPoint([it,Z]),$t=V.info.center.z-V.info.depth/2,mt=O(v({},V.info),{center:{x:X.x,y:X.y,z:$t+P/2},width:C,height:h,depth:P,valid:!0}),to=ot([mt]);W({omitView:B["3D"],polygon:D,boxParams:mt,newPointCloudBoxList:to})}},Q=(i,n,a,r,l,g)=>at(void 0,null,function*(){const C=H==null?void 0:H.url,P={[B.Side]:()=>{St(a,n,s,C,g)},[B.Back]:()=>{u&&_t(a,n,u,C,g)},[B.Top]:()=>{kt(a,n,t,o)}};Object.keys(P).forEach(h=>{h!==i&&P[h]()}),r&&(o==null||o.updateCameraZoom(r)),Et(a)}),W=i=>at(void 0,null,function*(){const{omitView:n,polygon:a,boxParams:r,zoom:l,newPointCloudBoxList:g}=i,C=H==null?void 0:H.url;g&&(yield e.syncAllViewPointCloudColor(rt.Single,g));const P={[B.Side]:()=>{Rt(r,a,s,C)},[B.Back]:()=>{u&&Vt(r,a,u,C)},[B.Top]:()=>{pt(r,a,t,o)}};Object.keys(P).forEach(h=>{h!==n&&P[h]()}),l&&(o==null||o.updateCameraZoom(l)),jt(r)});return{topViewAddSphere:Mt,topViewAddBox:Ft,topViewSelectedChanged:Zt,topViewUpdatePoint:Yt,sideViewUpdatePoint:Gt,backViewUpdatePoint:Jt,topViewUpdateBox:qt,sideViewUpdateBox:Qt,backViewUpdateBox:Xt,pointCloudBoxListUpdated:i=>{t.updatePolygonList(i),o==null||o.generateBoxes(i)},initPointCloud3d:i=>{if(!o)return;const n=k.getDefaultOrthographicParams(i);o.initOrthographicCamera(n),o.initRenderer(),o.render()},updatePointCloudData:(...i)=>at(void 0,[...i],function*(n=H){var a,r,l,g,C,P;if(!(n==null?void 0:n.url)||!o)return;A([]),vt(M,!0),yt(M,!0),yield o.loadPCDFile(n.url,(a=b==null?void 0:b.radius)!=null?a:$),o==null||o.clearAllBox(),o==null||o.clearAllSphere();let h=[],_=[],F=[],D=[];o.updateTopCamera();const L=(l=(r=lt(n.result))==null?void 0:r.valid)!=null?l:!0;if(e.setPointCloudValid(L),(g=e.sideViewInstance)==null||g.clearAllData(),(C=e.backViewInstance)==null||C.clearAllData(),n.result){if(h=k.getBoxParamsFromResultList(n.result),(h==null?void 0:h.length)>0&&n.isPreResult&&(b==null?void 0:b.lowerLimitPointsNumInBox)>0){h=yield o==null?void 0:o.filterPreResult(n.url,b,h);const j=lt(n.result);j[no].result=h,n.result=JSON.stringify(j),e.setPointCloudResult(h)}F=k.getPolygonListFromResultList(n.result),_=k.getLineListFromResultList(n.result),D=k.getSphereParamsFromResultList(n.result),t.updateData(n.url,n.result,{radius:(P=b==null?void 0:b.radius)!=null?P:$}),o==null||o.generateBoxes(h),o==null||o.generateSpheres(D),yield e.syncAllViewPointCloudColor(rt.Default,h,[])}N({pointCloudBoxList:h,polygonList:F,lineList:_,pointCloudSphereList:D}),vt(M,!1),yt(M,!1)}),updateViewsByDefaultSize:Kt,generateRects:tt,update2DViewRect:Ht,remove2DViewRect:Wt}},Bo=()=>{const{pointCloudBoxList:e,rectList:t,setPointCloudResult:s}=xt(Lt),u=q(e),o=q(t);return{syncToPointCloudBoxList:ht(()=>{const f=u.current,c=o.current;if(c.length===0)return null;const d=new Map,m=new Set;if(c.filter(x=>x.extId!==void 0).forEach(x=>{const y=x.extId,A=x.imageName,R=lo(x,["x","y","width","height"]);let S=d.get(y);S||(S=new Map,d.set(y,S)),S.set(A,R),m.add(y)}),d.size){const x=f.map(y=>{var A;const R=y.id;if(m.has(R)){const S=v({},y);return(A=S.rects)==null||A.forEach(U=>{var z;const T=U.imageName;Object.assign(U,(z=d.get(R))==null?void 0:z.get(T))}),S}return y});return s(x),x}return null},[])}};export{_t as syncBackViewByPoint,St as syncSideViewByPoint,kt as syncTopViewByPoint,Vt as synchronizeBackView,Rt as synchronizeSideView,pt as synchronizeTopView,ct as topViewPoint2PointCloud,ut as topViewPolygon2PointCloud,yo as usePointCloudViews,Bo as useSyncRectPositionDimensionToPointCloudList};
|
package/es/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import f from"lodash";import{pointCloudLidar2image as y}from"@labelbee/lb-annotation";var _=Object.defineProperty,x=Object.defineProperties,O=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,h=(e,t,n)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w=(e,t)=>{for(var n in t||(t={}))P.call(t,n)&&h(e,n,t[n]);if(g)for(var n of g(t))v.call(t,n)&&h(e,n,t[n]);return e},b=(e,t)=>x(e,O(t));const I=(e,t={})=>{try{return typeof e=="string"?JSON.parse(e):f.isObject(e)?e:t}catch(n){return t}},j=e=>{if(Array.isArray(e))return e.filter(t=>t).join(" ");if(f.isObject(e)){const t=[];return Object.keys(e).forEach(n=>{e[n]&&t.push(n)}),t.join(" ")}return""},m=e=>{let t=Infinity,n=Infinity,r=-Infinity,o=-Infinity;for(const i of e)t=Math.min(t,i.x),n=Math.min(n,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y);return{x:t,y:n,width:r-t,height:o-n}},u=(()=>{const e=(t,n)=>{const r=Math.max(t.x,n.x),o=Math.max(t.y,n.y),i=Math.min(t.x+t.width,n.x+n.width),c=Math.min(t.y+t.height,n.y+n.height),s=i-r,a=c-o;return s>=0&&a>=0?{x:r,y:o,width:s,height:a}:null};return(t,n,r)=>{if(r[n]){const o=r[n].width,i=r[n].height;return e(t,{x:0,y:0,width:o,height:i})!==null}return!1}})(),d=e=>{var t;const{pointCloudBox:n,mappingData:r,imageSizes:o}=e,{transferViewData:i}=(t=y(n,r.calib))!=null?t:{};if(!i)return;const c=i.reduce((p,l)=>l.type==="line"?[...p,...l.pointList]:p,[]),s=b(w({},m(c)),{imageName:r.path});if(u(s,r.path,o))return s},R=(e,t)=>{var n;const{pointCloudBox:r,mappingImgList:o,imageSizes:i}=e,s=o.map(a=>d({pointCloudBox:r,mappingData:a,imageSizes:i})).filter(a=>a!==void 0);if(s.length>0){const a=(n=t==null?void 0:t.prepareRectsFn)!=null?n:void 0,p=a?a(s,r):s;Object.assign(r,{rects:p})}};export{j as classnames,R as generatePointCloudBoxRects,m as getBoundingRect,d as getRectPointCloudBox,u as isBoundingRectInImage,I as jsonParser};
|
|
1
|
+
import f from"lodash";import{pointCloudLidar2image as y}from"@labelbee/lb-annotation";var _=Object.defineProperty,x=Object.defineProperties,O=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,h=(e,t,n)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w=(e,t)=>{for(var n in t||(t={}))P.call(t,n)&&h(e,n,t[n]);if(g)for(var n of g(t))v.call(t,n)&&h(e,n,t[n]);return e},b=(e,t)=>x(e,O(t));const I=(e,t={})=>{try{return typeof e=="string"?JSON.parse(e):f.isObject(e)?e:t}catch(n){return t}},j=e=>{if(Array.isArray(e))return e.filter(t=>t).join(" ");if(f.isObject(e)){const t=[];return Object.keys(e).forEach(n=>{e[n]&&t.push(n)}),t.join(" ")}return""},m=e=>{let t=Infinity,n=Infinity,r=-Infinity,o=-Infinity;for(const i of e)t=Math.min(t,i.x),n=Math.min(n,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y);return{x:t,y:n,width:r-t,height:o-n}},u=(()=>{const e=(t,n)=>{const r=Math.max(t.x,n.x),o=Math.max(t.y,n.y),i=Math.min(t.x+t.width,n.x+n.width),c=Math.min(t.y+t.height,n.y+n.height),s=i-r,a=c-o;return s>=0&&a>=0?{x:r,y:o,width:s,height:a}:null};return(t,n,r)=>{if(r[n]){const o=r[n].width,i=r[n].height;return e(t,{x:0,y:0,width:o,height:i})!==null}return!1}})(),d=e=>{var t;const{pointCloudBox:n,mappingData:r,imageSizes:o}=e,{transferViewData:i}=(t=y(n,r.calib))!=null?t:{};if(!i)return;const c=i.reduce((p,l)=>l.type==="line"?[...p,...l.pointList]:p,[]),s=b(w({},m(c)),{imageName:r.path});if(u(s,r.path,o))return s},R=(e,t)=>{var n;const{pointCloudBox:r,mappingImgList:o,imageSizes:i}=e,s=o.map(a=>d({pointCloudBox:r,mappingData:a,imageSizes:i})).filter(a=>a!==void 0);if(s.length>0){const a=(n=t==null?void 0:t.prepareRectsFn)!=null?n:void 0,p=a?a(s,r):s;p.length>0&&Object.assign(r,{rects:p})}};export{j as classnames,R as generatePointCloudBoxRects,m as getBoundingRect,d as getRectPointCloudBox,u as isBoundingRectInImage,I as jsonParser};
|