daiquiri-ui 2025.12.5__py3-none-any.whl → 2026.2.0__py3-none-any.whl
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.
- daiquiri_ui/__init__.py +0 -1
- daiquiri_ui/static/assets/Anchor-0b4a3d33.js +1 -0
- daiquiri_ui/static/assets/AutoscaleOption-3cb99678.js +1 -0
- daiquiri_ui/static/assets/{BPMVideoStream-5e8c0121.js → BPMVideoStream-c3e09e8b.js} +1 -1
- daiquiri_ui/static/assets/{CanvasEnhancer-abaa5025.js → CanvasEnhancer-dd82c090.js} +1 -1
- daiquiri_ui/static/assets/ColorMap-be59ad21.js +1 -0
- daiquiri_ui/static/assets/CompositeMap-c93f5466.js +1 -0
- daiquiri_ui/static/assets/{ConnectUtils-bd734a4a.js → ConnectUtils-3923fa2f.js} +1 -1
- daiquiri_ui/static/assets/{Console-4f2397f7.js → Console-d0028912.js} +1 -1
- daiquiri_ui/static/assets/{Cross-80ee2b29.js → Cross-d5df0df3.js} +1 -1
- daiquiri_ui/static/assets/{CrossMarker-cc495eca.js → CrossMarker-71cd11cf.js} +2 -2
- daiquiri_ui/static/assets/DraggableRect-25d91c7d.js +1 -0
- daiquiri_ui/static/assets/DropdownButton-29cc265b.js +1 -0
- daiquiri_ui/static/assets/DropdownDetector-5016908a.js +1 -0
- daiquiri_ui/static/assets/{Editor-b897e35a.js → Editor-7b500b85.js} +9 -9
- daiquiri_ui/static/assets/EditorTree-7fc000d8.js +1 -0
- daiquiri_ui/static/assets/H5Viewer-d1305c58.js +1 -0
- daiquiri_ui/static/assets/{H5WebCurvePlot-acd3b964.js → H5WebCurvePlot-61b08211.js} +1 -1
- daiquiri_ui/static/assets/HSegment-8d2c001e.js +43 -0
- daiquiri_ui/static/assets/HardwareButton-af41c610.js +1 -0
- daiquiri_ui/static/assets/Hdf5Plot-bbffc65f.js +1 -0
- daiquiri_ui/static/assets/{HistogramDomainSlider-9c6d3e2d.js → HistogramDomainSlider-304bdab4.js} +1 -1
- daiquiri_ui/static/assets/Image-ee61818a.js +1 -0
- daiquiri_ui/static/assets/Label-9d8979b3.js +1 -0
- daiquiri_ui/static/assets/{LoadingMessage-072bb4e8.js → LoadingMessage-03b4fa4f.js} +1 -1
- daiquiri_ui/static/assets/NewScanButton-0051d220.js +1 -0
- daiquiri_ui/static/assets/NewScanButton-57cf0c17.js +1 -0
- daiquiri_ui/static/assets/OptionsProcess-da629bfb.js +1 -0
- daiquiri_ui/static/assets/ParametersList-2d01832f.js +1 -0
- daiquiri_ui/static/assets/RectRoi-3693cc65.js +1 -0
- daiquiri_ui/static/assets/RectRuler-1fee3fd8.js +543 -0
- daiquiri_ui/static/assets/RulerButton-a95a6035.js +139 -0
- daiquiri_ui/static/assets/SampleDCList-dce0bd2b.js +1 -0
- daiquiri_ui/static/assets/SampleRegistration-544aa4bd.js +1 -0
- daiquiri_ui/static/assets/SavingButton-c3efc92c.js +1 -0
- daiquiri_ui/static/assets/ScanDataService-16f29ecd.js +1 -0
- daiquiri_ui/static/assets/ScanPlot0d-67c76bfe.js +1 -0
- daiquiri_ui/static/assets/ScanPlot0dValue-c0dd01b5.js +1 -0
- daiquiri_ui/static/assets/ScanPlot1d-3c930b95.js +1 -0
- daiquiri_ui/static/assets/ScanPlot1d-ee33c98b.js +1 -0
- daiquiri_ui/static/assets/{ScanPlot2d-c857bbd7.js → ScanPlot2d-af57d8ad.js} +1 -1
- daiquiri_ui/static/assets/{ScanTable-11f74702.js → ScanTable-bc13760e.js} +1 -1
- daiquiri_ui/static/assets/ScanValue-00aab91b.js +1 -0
- daiquiri_ui/static/assets/SceneScale-e2a42af2.js +1 -0
- daiquiri_ui/static/assets/SchemaForm-7d897a32.js +1 -0
- daiquiri_ui/static/assets/{ScreenScale-fdd43179.js → ScreenScale-b2417934.js} +1 -1
- daiquiri_ui/static/assets/{SelectionPoint-7fbd4e1f.js → SelectionPoint-a2cb4dfc.js} +1 -1
- daiquiri_ui/static/assets/{StackedNameState-94be4a7b.js → StackedNameState-4e8dc742.js} +1 -1
- daiquiri_ui/static/assets/Statistics.worker-54a0d965.js +46 -0
- daiquiri_ui/static/assets/{Synoptic-d291a77a.js → Synoptic-8a3c67f3.js} +5 -5
- daiquiri_ui/static/assets/TomoAlign-b80a68c3.js +7 -0
- daiquiri_ui/static/assets/TomoBeamShaping-65a115e9.js +1 -0
- daiquiri_ui/static/assets/TomoDetector-500d46af.js +1 -0
- daiquiri_ui/static/assets/TomoDetector-e04a5a8b.js +1 -0
- daiquiri_ui/static/assets/TomoDetectorView-952499e6.js +64 -0
- daiquiri_ui/static/assets/TomoHolo-db2c8449.js +1 -0
- daiquiri_ui/static/assets/TomoPusherView-a50e2acd.js +1 -0
- daiquiri_ui/static/assets/TomoReconstructedSinogram-deee0779.js +191 -0
- daiquiri_ui/static/assets/TomoScanInfo-972a690b.js +1 -0
- daiquiri_ui/static/assets/{TomoScanList-66ecaec4.js → TomoScanList-ede05c2a.js} +1 -1
- daiquiri_ui/static/assets/TomoService-e9741d6a.js +1 -0
- daiquiri_ui/static/assets/TomoSinogram-dce5808e.js +1 -0
- daiquiri_ui/static/assets/TomoTiling-04701bb7.js +69 -0
- daiquiri_ui/static/assets/TwoD-fee9523f.js +3 -0
- daiquiri_ui/static/assets/TwoDObject-2f30deac.js +1 -0
- daiquiri_ui/static/assets/TwoDObjectList-458e4824.js +1 -0
- daiquiri_ui/static/assets/{UseMouseModeInteraction-9b6c111c.js → UseMouseModeInteraction-51c6269c.js} +1 -1
- daiquiri_ui/static/assets/VLineRoi-b38fe841.js +1 -0
- daiquiri_ui/static/assets/{VSegment-5d77576e.js → VSegment-f0d42c9a.js} +2 -2
- daiquiri_ui/static/assets/VSegmentRoi-d5e035cc.js +1 -0
- daiquiri_ui/static/assets/{VideoStream-b33f5afc.js → VideoStream-a5200b21.js} +1 -1
- daiquiri_ui/static/assets/{VisViewpointRestore-3a80fbce.js → VisViewpointRestore-4aa338ea.js} +3 -3
- daiquiri_ui/static/assets/{WorldScale-862ee5ba.js → WorldScale-23bd1dfb.js} +1 -1
- daiquiri_ui/static/assets/{ZoomPanCanvas-1365066d.js → ZoomPanCanvas-23b61dbb.js} +1 -1
- daiquiri_ui/static/assets/{colormap-0981f7dc.js → colormap-6e43299c.js} +1 -1
- daiquiri_ui/static/assets/fontawesomemore-webfont-6ae56ae3.woff2 +0 -0
- daiquiri_ui/static/assets/{geometry-252a228f.js → geometry-cd448ec1.js} +1 -1
- daiquiri_ui/static/assets/hooks-171c0765.js +1 -0
- daiquiri_ui/static/assets/{hooks-e8b12550.js → hooks-e0d9229c.js} +1 -1
- daiquiri_ui/static/assets/index-779a56ef.css +9 -0
- daiquiri_ui/static/assets/{index-19c84627.js → index-a9bb7636.js} +7 -7
- daiquiri_ui/static/assets/index-b3c0133a.js +3576 -0
- daiquiri_ui/static/assets/{plotly-basic-4f8b68a8.js → plotly-basic-ccc5794d.js} +1 -1
- daiquiri_ui/static/assets/{plotly-gl2d-14b9dcce.js → plotly-gl2d-345cb34a.js} +1 -1
- daiquiri_ui/static/assets/store-5d136a2c.js +1 -0
- daiquiri_ui/static/assets/{types-0be7083b.js → types-c366a377.js} +1 -1
- daiquiri_ui/static/index.html +2 -2
- daiquiri_ui/static/meta.json +1 -1
- {daiquiri_ui-2025.12.5.dist-info → daiquiri_ui-2026.2.0.dist-info}/METADATA +1 -1
- daiquiri_ui-2026.2.0.dist-info/RECORD +134 -0
- {daiquiri_ui-2025.12.5.dist-info → daiquiri_ui-2026.2.0.dist-info}/WHEEL +1 -1
- daiquiri_ui/static/assets/Anchor-f3716b7b.js +0 -1
- daiquiri_ui/static/assets/AutoscaleOption-e2ee098d.js +0 -1
- daiquiri_ui/static/assets/DraggableRect-8e897252.js +0 -1
- daiquiri_ui/static/assets/DropdownButton-9a594aef.js +0 -1
- daiquiri_ui/static/assets/DropdownDetector-705d3a9d.js +0 -1
- daiquiri_ui/static/assets/EditorTree-792b2d33.js +0 -1
- daiquiri_ui/static/assets/H5Viewer-6c3d85e4.js +0 -1
- daiquiri_ui/static/assets/HSegment-26c3fd51.js +0 -43
- daiquiri_ui/static/assets/HardwareButton-905ce384.js +0 -1
- daiquiri_ui/static/assets/Hdf5Plot-7b8f8e0f.js +0 -1
- daiquiri_ui/static/assets/Image-c1578ac2.js +0 -1
- daiquiri_ui/static/assets/Label-7daca8b6.js +0 -1
- daiquiri_ui/static/assets/NewScanButton-3ccc3031.js +0 -1
- daiquiri_ui/static/assets/NewScanButton-ed1679d8.js +0 -1
- daiquiri_ui/static/assets/OptionsProcess-9e8d1dd6.js +0 -1
- daiquiri_ui/static/assets/ParametersList-39837f0d.js +0 -1
- daiquiri_ui/static/assets/RectRoi-a627d206.js +0 -1
- daiquiri_ui/static/assets/RulerButton-ebbb7ca3.js +0 -139
- daiquiri_ui/static/assets/SampleDCList-03813f5f.js +0 -1
- daiquiri_ui/static/assets/SampleRegistration-6fad78fb.js +0 -1
- daiquiri_ui/static/assets/SavingButton-a220fa1e.js +0 -1
- daiquiri_ui/static/assets/ScanPlot0d-c78ff27c.js +0 -1
- daiquiri_ui/static/assets/ScanPlot0dValue-daa69216.js +0 -1
- daiquiri_ui/static/assets/ScanPlot1d-bdb2fdb1.js +0 -1
- daiquiri_ui/static/assets/ScanPlot1d-c0e49d26.js +0 -1
- daiquiri_ui/static/assets/ScanValue-a38a2ca1.js +0 -1
- daiquiri_ui/static/assets/SceneScale-47e8e288.js +0 -1
- daiquiri_ui/static/assets/SchemaForm-4a3d737e.js +0 -1
- daiquiri_ui/static/assets/TomoAlign-19546c0c.js +0 -5
- daiquiri_ui/static/assets/TomoBeamShaping-303f1af7.js +0 -1
- daiquiri_ui/static/assets/TomoDetector-42a6e14c.js +0 -1
- daiquiri_ui/static/assets/TomoDetectorView-bc556465.js +0 -64
- daiquiri_ui/static/assets/TomoHolo-dc83668f.js +0 -1
- daiquiri_ui/static/assets/TomoReconstructedSinogram-3aba7e83.js +0 -191
- daiquiri_ui/static/assets/TomoScanInfo-7235514b.js +0 -1
- daiquiri_ui/static/assets/TomoSinogram-3202ac53.js +0 -1
- daiquiri_ui/static/assets/TomoTiling-42ab8b24.js +0 -69
- daiquiri_ui/static/assets/TwoD-a488b0f5.js +0 -3
- daiquiri_ui/static/assets/TwoDObject-fbaffc6f.js +0 -1
- daiquiri_ui/static/assets/TwoDObjectList-7de7fa1d.js +0 -1
- daiquiri_ui/static/assets/VLineRoi-75cfdd39.js +0 -1
- daiquiri_ui/static/assets/colors-5bf0897d.js +0 -1
- daiquiri_ui/static/assets/fontawesomemore-webfont-97d0220a.woff2 +0 -0
- daiquiri_ui/static/assets/hooks-e7539055.js +0 -1
- daiquiri_ui/static/assets/index-4cf586ed.js +0 -3576
- daiquiri_ui/static/assets/index-f085dfca.css +0 -9
- daiquiri_ui/static/assets/store-2462c975.js +0 -1
- daiquiri_ui/static/resources/shaders/compare.frag.glsl +0 -386
- daiquiri_ui/static/resources/shaders/compare.vert.glsl +0 -11
- daiquiri_ui-2025.12.5.dist-info/RECORD +0 -128
- {daiquiri_ui-2025.12.5.dist-info → daiquiri_ui-2026.2.0.dist-info}/licenses/LICENSE +0 -0
- {daiquiri_ui-2025.12.5.dist-info → daiquiri_ui-2026.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,r as g,aw as I,aQ as P,aH as S,u as F,i as $,R as V,C as y,as as k,B as T,bk as J,bl as ee,b as ae,aR as te,aS as oe,A as se,bK as Y,bL as ne,H as B,ad as re,bo as ie}from"./index-b3c0133a.js";import{S as A,a as U,p as le,r as ce,F as de,t as ue}from"./index-a9bb7636.js";import{L as me,u as xe,a as fe,T as ge,D as pe,S as G}from"./UseMouseModeInteraction-51c6269c.js";import{V as K}from"./VSegment-f0d42c9a.js";import{L as N}from"./Label-9d8979b3.js";import{l as q}from"./hooks-171c0765.js";import{L as he}from"./LoadingMessage-03b4fa4f.js";import{W as ve}from"./WorldScale-23bd1dfb.js";import{V as je}from"./VLineRoi-b38fe841.js";import{D as ye}from"./DropdownButton-29cc265b.js";import{P as Ce}from"./SelectionPoint-a2cb4dfc.js";import{H as Se}from"./HSegment-8d2c001e.js";import{u as be}from"./ScanDataService-16f29ecd.js";import{a as Me}from"./TomoService-e9741d6a.js";import"./ScreenScale-b2417934.js";import"./DraggableRect-25d91c7d.js";import"./types-c366a377.js";const D=.1;function we(t,a){if(!t)return{translationrange:A([0,1024],D),rotationrange:A([0,360],D)};const{rotationrange:s,translationrange:o}=t;if(a==="marker")return{translationrange:A(o,D),rotationrange:A(s,D)};if(a==="solid"){const{rotationaxispoints:r}=t,n=Math.abs(s[1]-s[0])/r;return{translationrange:o,rotationrange:[s[0]-n/2,s[1]-n/2]}}throw new Error(`Expected "marker" or "solid" render mode. Got ${a}`)}function Re(t){return g.useMemo(()=>{if(t===void 0)return;const a=t instanceof Float32Array?t:Float32Array.from(t.data);return I(a,t.shape)},[t])}function Fe(t){const{vData:a,xRange:s,xAxisSize:o,yRange:r,yAxisSize:n,colorMap:i,scaleType:l,invertColorMap:c,domain:p}=t,d=g.useMemo(()=>{const f=(a==null?void 0:a.shape[0])??0;return(f-f%o)/o},[a,o]),h=g.useMemo(()=>{if(a===void 0||d===0)return;const f=a.data.subarray(0,d*o);return I(f,[d,o])},[d,o]),u=Re(h);if(u===void 0)return e.jsx(e.Fragment,{});const v=Math.abs(r[1]-r[0]),m=Math.abs(s[1]-s[0])/o,x=v/n;return e.jsx(ce,{position:[(s[0]+s[1])*.5,r[0]+v*(u.shape[0]/n)*.5,0],size:{width:u.shape[1],height:u.shape[0]},scale:[m,x,1],values:u,domain:p,colorMap:i,scaleType:l,invertColorMap:c})}function Ae(t){const{xData:a,yData:s,vData:o,domain:r,colorMap:n="Viridis",invertColorMap:i=!1,scaleType:l=U.Linear,markerSize:c=8,renderMode:p,...d}=t;return a===void 0||s===void 0||o===void 0?e.jsx(e.Fragment,{}):p==="marker"?e.jsx(ve,{children:e.jsx(le,{abscissas:a.data,ordinates:s.data,data:o.data,size:c,domain:r,scaleType:l,invertColorMap:!1,colorMap:n})}):e.jsx(Fe,{xData:a,yData:s,vData:o,domain:r,scaleType:l,invertColorMap:!1,colorMap:n,...d})}P("daiquiri.components.tomo.SinogramPlot");function De(t){const{datacollectionMeta:a}=t,s=a.requestedCor!==null&&a.requestedCor!==a.actualCor;return e.jsxs(e.Fragment,{children:[a.estimatedCor!==null&&a.estimatedCor!==a.actualCor&&e.jsxs(e.Fragment,{children:[e.jsx(K,{x:a.estimatedCor,y1:0,y2:360,color:"#505050",gapColor:"#909090",dashSize:10,gapSize:10}),e.jsx(N,{datapos:[a.estimatedCor,10],color:"#A0A0A0",text:"Estimated CoR"})]}),a.actualCor!==null&&e.jsxs(e.Fragment,{children:[e.jsx(je,{geometry:{x:a.requestedCor??a.actualCor},onGeometryChanged:(o,r)=>{t.setRequestedCor(o.x,r)}}),e.jsx(N,{datapos:[a.requestedCor??a.actualCor,s?40:25],color:"#FFFFFF",text:s?"Requested CoR":"Actual CoR"})]}),s&&a.actualCor!==null&&e.jsxs(e.Fragment,{children:[e.jsx(K,{x:a.actualCor,y1:0,y2:360,color:"#000000",gapColor:"#FFFFFF",dashSize:10,gapSize:10}),e.jsx(N,{datapos:[a.actualCor,25],color:"#FFFFFF",text:"Actual CoR"})]})]})}function Ne(t){var m,x;const{xdata:a,ydata:s,vdata:o,sinogram:r,renderMode:n,datacollectionMeta:i,mouseMode:l}=t,{translationrange:c,rotationrange:p}=we(r,n),d=de(o),h=Math.min(a.size,s.size,o.size),u=q(a,0,h),v=q(s,0,h),b=q(o,0,h);return e.jsxs("div",{style:{flex:"1 1 auto",display:"flex",margin:0,minHeight:0},children:[e.jsxs(me,{plotRef:t.plotRef,showAxes:((m=t.viewConfig)==null?void 0:m.displayAxes)??!0,title:"Sinogram",abscissaConfig:{visDomain:c,showGrid:!0,label:"Profile"},ordinateConfig:{visDomain:p,showGrid:!0,label:"Rotation",flip:!0},mouseMode:l,children:[r&&d&&e.jsx(Ae,{xData:u,yData:v,vData:b,domain:d,colorMap:"Viridis",xAxisSize:r.translationaxispoints,yAxisSize:r.rotationaxispoints,xRange:r.translationrange,yRange:r.rotationrange,renderMode:n}),i!==void 0&&e.jsx(De,{setRequestedCor:t.setRequestedCor,datacollectionMeta:i}),e.jsx(he,{...t.message}),t.children]}),(((x=t.viewConfig)==null?void 0:x.colorbarVisible)??!0)&&e.jsx(ue,{domain:d??[0,0],withBounds:!0,colorMap:"Viridis",invertColorMap:!1,scaleType:U.Linear})]})}function ze(t){const{onSelect:a,value:s}=t,o={marker:"Marker",solid:"Solid"},r=o[s];return e.jsxs(ye,{title:r,id:"bg-vertical-dropdown-4",variant:"secondary",onSelect:n=>{n!==null&&a(n)},children:[e.jsx(S.Item,{eventKey:"marker",children:o.marker}),e.jsx(S.Item,{eventKey:"solid",children:o.solid})]})}const L=P("daiquiri.components.tomo.sinogram.AxisRotationPositionInteraction");function Ve(t){const{operator:a,resetMouseMode:s}=t,o=xe(),{mouseMode:r,actions:n}=o??{},i=g.useCallback(l=>{const c=l.dataPt.x;s(),t.setRequestedCor(c)},[t.setRequestedCor,n]);return a?r!=="set-axis-rotation"?(L("disabled: mouseMode dont match"),e.jsx(e.Fragment,{})):(L("enabled"),e.jsx(Ce,{onClick:i})):(L("disabled: not operator"),e.jsx(e.Fragment,{}))}function ke(t){var n;const{rotationHardware:a,detectorWidth:s}=t,o=(n=a==null?void 0:a.properties)==null?void 0:n.position;if(o==null||s===void 0)return e.jsx(e.Fragment,{});const r=a==null?void 0:a.name;return e.jsxs(e.Fragment,{children:[e.jsx(Se,{y:o,x1:0,x2:s,color:"red",gapColor:"write",dashSize:10,gapSize:10,lineWidth:3}),e.jsx(N,{datapos:[10,o],color:"#FF0000",anchor:"top",vmargin:10,text:r??"srot"})]})}function qe(){const[t,a]=F("tomo/sinogramview/axes",!0),[s,o]=F("tomo/sinogramview/colorbar-visible",!1),[r,n]=F("tomo/sinogramview/crosshair",!1),[i,l]=F("tomo/sinogramview/displayed",!0);return{colorbarVisible:s,setColorbarVisible:o,displayAxes:t,setDisplayAxes:a,crossHair:r,setCrossHair:n,displayedSinogram:i,setDisplayedSinogram:l}}function Le(t,a,s){return t!==a?"secondary":s||"primary"}function C(t){return e.jsx(T,{variant:Le(t.var,t.value,t.variantWhenSelected),onClick:()=>{t.setter(t.value)},className:"text-nowrap",size:"sm",children:t.children})}function Te(t){const{as:a=void 0,variant:s="secondary",config:o}=t;return e.jsxs(S,{as:a,children:[e.jsx(S.Toggle,{id:"dropdown-basic",variant:s,className:"d-flex align-items-center",children:e.jsx("i",{className:"fa fa-sliders fa-fw fa-lg"})}),e.jsx(S.Menu,{className:"dropdown-menu-center",children:e.jsx("div",{className:"ms-1 me-1",style:{minWidth:"300px"},children:e.jsxs($,{children:[e.jsxs(V,{children:[e.jsx(y,{className:"my-auto",children:"Sinogram"}),e.jsx(y,{xs:7,children:e.jsxs(k,{children:[e.jsx(C,{var:o.displayedSinogram,value:!0,setter:o.setDisplayedSinogram,children:"Displayed"}),e.jsx(C,{var:o.displayedSinogram,value:!1,setter:o.setDisplayedSinogram,variantWhenSelected:"warning",children:"Hide"})]})})]}),e.jsxs(V,{className:"mt-1",children:[e.jsx(y,{className:"my-auto",children:"Display axes"}),e.jsx(y,{xs:7,children:e.jsxs(k,{children:[e.jsx(C,{var:o.displayAxes,value:!0,setter:o.setDisplayAxes,children:"Yes"}),e.jsx(C,{var:o.displayAxes,value:!1,setter:o.setDisplayAxes,children:"No"})]})})]}),e.jsxs(V,{className:"mt-1",children:[e.jsx(y,{className:"my-auto",children:"Color bar"}),e.jsx(y,{xs:7,children:e.jsxs(k,{children:[e.jsx(C,{var:o.colorbarVisible,value:!0,setter:o.setColorbarVisible,children:"Displayed"}),e.jsx(C,{var:o.colorbarVisible,value:!1,setter:o.setColorbarVisible,children:"Hide"})]})})]})]})})})]})}P("daiquiri.components.tomo.TomoSinogram");function Ie(t){var H,O;const{sinogram:a,selectedScan:s,options:o}=t,{tomoconfig:r}=o,{datacollectionid:n,datacollectionMeta:i}=J(o.datacollectionid),l=ee(),c=qe(),p=c.displayedSinogram?(a==null?void 0:a.actualnbpoints)??0:0,[d,h]=g.useState("solid"),u=ae(),v=te(r??""),b=oe(v);g.useEffect(()=>{n!==void 0&&l.updateDataCollectionMeta(n,{estimatedCor:null,requestedCor:null,actualCor:null})},[n]);const m=be({scanId:a!==void 0?s??void 0:void 0,channelNames:["sinogram","rotation","translation"],start:0,stop:p}),x=g.useRef(null),f=fe("zoom"),{mouseMode:E}=f,z=I(new Float32Array([]),[0]),M=m.data.translation,w=m.data.rotation,R=m.data.sinogram;function Q(){if(s===null)return{info:"No scan"};if(!a)return{info:"No sinogram defined"};if(!M||!w||!R){if(m.loading)return{warning:"Waiting for data..."};if(!M)return{danger:"Data for x-axis are missing"};if(!w)return{danger:"Data for y-axis are missing"};if(!R)return{danger:"Data for intensity are missing"}}return Math.min(M.size,w.size,R.size)===0?{warning:"Waiting for data..."}:{}}const X=Q(),Z=(O=(H=t.sinogram)==null?void 0:H.translationrange)==null?void 0:O[1],W=g.useCallback((j,_)=>{n!==void 0&&(_||Me({datacollectionid:n,axisposition:j,filename:(i==null?void 0:i.sourceFilename)??void 0}),l.updateDataCollectionMeta(n,{requestedCor:j}))},[n,i==null?void 0:i.sourceFilename]);return e.jsxs("div",{className:"plot2d-container w-100 h-100",style:{flex:"1 1 0%",display:"flex",flexDirection:"column"},children:[e.jsxs(ge,{align:"center",children:[e.jsx(pe,{mouseModeInteraction:f}),e.jsx(T,{title:"Reset zoom (sample stage overview)",variant:"secondary",onClick:()=>{var j;(j=x==null?void 0:x.current)==null||j.actions.resetZoom()},children:e.jsx("i",{className:"fa fa-expand fa-fw fa-lg"})}),e.jsx(G,{}),e.jsx(T,{title:u?"Select another center of rotation for the slice reconstruction":"You have to get the control on the session to set the center of rotation",disabled:!u,variant:E==="set-axis-rotation"?"warning":"secondary",onClick:()=>{f.setOrResetMouseMode("set-axis-rotation")},children:e.jsx("i",{className:"fad fam-tomo-cor fa-fw fa-lg"})}),e.jsx(G,{}),e.jsx(ze,{value:d,onSelect:h}),e.jsx(Te,{config:c})]}),!c.displayedSinogram&&e.jsx(se,{variant:"warning",children:"Sinogram was disabled by user"}),c.displayedSinogram&&e.jsxs(Ne,{viewConfig:c,message:X,mouseMode:E,xdata:M??z,ydata:w??z,vdata:R??z,sinogram:a,renderMode:d,plotRef:x,datacollectionMeta:i,setRequestedCor:W,children:[e.jsx(Ve,{operator:u,resetMouseMode:f.resetMouseMode,setRequestedCor:W}),e.jsx(ke,{rotationHardware:b.somega,detectorWidth:Z})]})]})}function Pe(){return Y(t=>{const a=t.scaninfo.lastgroup;return(a==null?void 0:a.sinogram)??void 0},ne)}function Ee(){return Y(t=>{const a=t.scaninfo.lastgroup;return(a==null?void 0:a.scanid)??null})}function We(t){const a=Pe(),s=Ee();return e.jsx(Ie,{...t,sinogram:a,selectedScan:s})}function sa(t){const{yamlNode:a,tomoconfig:s,datacollectionid:o,...r}=t;B(a,r),re(a,"tomoconfig",s),ie(a,"datacollectionid",o),B(a,r);const n={datacollectionid:o,tomoconfig:s};return e.jsx(We,{options:n})}export{sa as default};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import{bO as re,j as t,aH as F,i as ve,R as O,as as E,B as N,r as g,af as A,ag as w,aw as Ke,ah as fe,ai as qt,aj as et,aQ as W,l as Te,ak as T,bj as St,aG as k,C as L,L as ce,O as wt,aD as bt,u as G,aL as H,aU as Xt,aV as Qt,aW as Jt,aX as Kt,b5 as eo,aS as Fe,bP as to,b as zt,bQ as Re,a4 as de,e as V,aJ as Ee,aT as oo,bR as no,bS as so,av as io,bT as ao,bU as ro,bV as co,aR as lo,b1 as uo,bW as mo,b0 as xo,bJ as fo,bK as go,ad as ho,aF as tt,H as yo}from"./index-b3c0133a.js";import{a as ge,b as vo,Q as jo,O as po,j as So,u as wo,h as Le,w as ot,t as bo}from"./index-a9bb7636.js";import{u as Oe,L as zo,a as Co,T as Mo,D as Do,S as ie,V as nt}from"./UseMouseModeInteraction-51c6269c.js";import{A as ae,u as Ct,a as Ro}from"./colormap-6e43299c.js";import{L as st,S as No,a as Io,I as Po,A as ko}from"./AutoscaleOption-3cb99678.js";import{C as To,f as it,a as at,H as rt,L as Fo,V as ct}from"./VisViewpointRestore-4aa338ea.js";import{s as Eo,k as Lo,q as Oo,t as Ao}from"./hooks-171c0765.js";import{L as Y,c as _o}from"./Label-9d8979b3.js";import{p as K,a as X,f as te,r as he,t as Mt}from"./geometry-cd448ec1.js";import{H as lt}from"./HSegment-8d2c001e.js";import{V as ye}from"./VSegment-f0d42c9a.js";import{C as Vo}from"./CrossMarker-71cd11cf.js";import{R as je}from"./RectRoi-3693cc65.js";import{P as Ae}from"./SelectionPoint-a2cb4dfc.js";import{r as ke}from"./TomoService-e9741d6a.js";import{a as $o,R as Bo}from"./RulerButton-a95a6035.js";import{S as Dt}from"./StackedNameState-4e8dc742.js";import{g as Ho}from"./TomoScans-82e1e23b.js";import{N as _e}from"./NewScanButton-0051d220.js";import{D as Go}from"./DropdownButton-29cc265b.js";import{D as Yo}from"./DropdownDetector-5016908a.js";import{u as Uo,a as Zo,b as Wo}from"./TomoDetector-e04a5a8b.js";import{u as qo}from"./ColorMap-be59ad21.js";import{H as Xo}from"./HistogramDomainSlider-304bdab4.js";import{W as dt}from"./WorldScale-23bd1dfb.js";import"./Image-ee61818a.js";import"./ScreenScale-b2417934.js";import"./Anchor-0b4a3d33.js";import"./DraggableRect-25d91c7d.js";import"./VSegmentRoi-d5e035cc.js";import"./QtyHelper-8429914f.js";import"./types-c366a377.js";import"./ConnectUtils-3923fa2f.js";function Z(e,o,n,s){if(o)return re(e,o);if(n){const a=`${n}.${s}`;return re(e,a)}return null}function pe(e,o){const n=o.tomoconfig??"ACTIVE_TOMOCONFIG.ref",s=Z(e,o.sampleStageId,n,"sample_stage"),a=Z(e,o.syId,n,"sample_stage.sy"),i=Z(e,o.sampxId,n,"sample_stage.sampx"),l=Z(e,o.sampyId,n,"sample_stage.sampy"),r=Z(e,o.sampuId,n,"sample_stage.sampu"),c=Z(e,o.sampvId,n,"sample_stage.sampv"),u=Z(e,o.szId,n,"sample_stage.sz"),m=Z(e,o.somegaId,n,"sample_stage.somega"),d=Z(e,o.detectorId,n,"detectors.active_detector.detector"),x=Z(e,o.tomoDetectorId,n,"detectors.active_detector");return{sy:a,sampx:i,sampy:l,sampu:r,sampv:c,sz:u,somega:m,detector:d,tomoDetector:x,sampleStage:s}}function Qo(e){const{as:o=void 0,variant:n="secondary"}=e;function s(c,u){const d=e.lut===c?"primary":"secondary";return t.jsx(N,{variant:d,onClick:()=>{e.onSelectLut(c)},className:"text-nowrap",title:u,size:"sm",children:t.jsx(st,{name:c})})}function a(){const c=e.isInverted?"primary":"secondary";return t.jsxs(N,{variant:c,onClick:()=>{e.onSelectInvertion(!e.isInverted)},size:"sm",children:[t.jsx("i",{className:"fa fa-fw fa-arrows-alt-v"})," Inverted LUT"]})}function i(c,u){const d=e.norm===c?"primary":"secondary";return t.jsx(N,{variant:d,onClick:()=>{e.onSelectNorm(c)},size:"sm",children:u})}function l(c){const u=e.autoscaleMode===c,m=u&&e.autoscale?"primary":u?"warning":"secondary",x={[ae.Minmax]:"Minmax",[ae.StdDev3]:"3×std",[ae.None]:"Manual"}[c];return t.jsx(N,{variant:m,onClick:()=>{var h,f;(h=e.onSelectAutoscaleMode)==null||h.call(e,c),e.autoscale||(f=e.onSelectAutoscale)==null||f.call(e,!0)},size:"sm",children:x})}function r(){const c=e.autoscale?"primary":"secondary";return t.jsxs(N,{variant:c,onClick:()=>{var u;(u=e.onSelectAutoscale)==null||u.call(e,!e.autoscale)},size:"sm",children:[t.jsx("i",{className:"fa-solid fa-circle-half-stroke fa-fw fa-lg"})," Auto scale enabled"]})}return t.jsxs(F,{as:o,className:`${e.dropDirection==="up"?"dropup":""}`,children:[t.jsxs(F.Toggle,{id:"dropdown-basic",variant:n,className:"d-flex align-items-center",children:[t.jsx(st,{name:e.lut}),t.jsx(No,{scale:e.norm}),e.autoscale&&t.jsx(Io,{autoscale:e.autoscaleMode})]}),t.jsx(F.Menu,{className:"dropdown-menu-center",children:t.jsx("div",{className:"ms-1 me-1",children:t.jsxs(ve,{children:[t.jsx(O,{children:t.jsx("h6",{className:"flex-grow-1 text-center",children:"Lookup table"})}),t.jsx(O,{children:t.jsxs(E,{className:"flex-grow-1",children:[s("Greys","Gray"),s("Viridis","Viridis"),s("Cividis","Cividis"),s("Magma","Magma"),s("Inferno","Inferno"),s("Plasma","Plasma")]})}),t.jsx(O,{children:t.jsx(E,{className:"flex-grow-1 mt-1",children:a()})}),e.onSelectAutoscale&&t.jsxs(t.Fragment,{children:[t.jsx(O,{className:"mt-2",children:t.jsx("h6",{className:"flex-grow-1 text-center",children:"Autoscale"})}),t.jsx(O,{children:t.jsxs(E,{className:"flex-grow-1",children:[l(ae.Minmax),l(ae.StdDev3)]})}),t.jsx(O,{children:t.jsx(E,{className:"flex-grow-1 mt-1 mb-2",children:r()})})]}),t.jsx(O,{className:"mt-2",children:t.jsx("h6",{className:"flex-grow-1 text-center",children:"Normalization"})}),t.jsx(O,{children:t.jsxs(E,{className:"flex-grow-1",children:[i(ge.Linear,"Linear"),i(ge.Log,"Log"),i(ge.SymLog,"SymLog"),i(ge.Sqrt,"Sqrt")]})})]})})})]})}function Jo(e,o){const[n,s]=g.useState(!1),[a,i]=g.useState(!1),[l,r]=g.useState(void 0),[c,u]=g.useState(void 0),[m,d]=g.useState(),[x,h]=g.useState(new A(new w,new w(1,1))),[f,y]=g.useState(new A(new w,new w(1,1))),v=g.useCallback(()=>{r(void 0),u(void 0),d(void 0),h(new A(new w,new w(1,1))),y(new A(new w,new w(1,1)))},[r,u,d,h,y]);return g.useEffect(()=>{const b={width:256,height:256};if(e){if(e.defaults.baseURL==="mock"){const p=new To({width:2048,height:4096},b);r(p),u(p),d(void 0),h(new A(new w(-50,-100),new w(50,100))),y(new A(new w(-50,-100),new w(50,100)));return}if(!o){v();return}e.get(`/image_tiling/${o}`).then(p=>{const{status:j,output:M}=p.data;if(j!=="done"&&j!=="running")throw new Error("Status is not done");if(M.length!==2)throw new Error("Error in retrieve tiling information");const{location:S,hdf5_entry:C}=M[0],{location:D,hdf5_entry:I}=M[1];if(!S||!C)throw new Error("Error in retrieved tiling locations");return Promise.all([it(e,S,C),it(e,D,I),at(e,S,"/sequence/histogram/count"),at(e,S,"/sequence/histogram/bin_edges")])}).catch(p=>v()).then(p=>{if(!p){v();return}const{layers:j,yDomain:M,zDomain:S}=p[0];r(new rt(b,j)),h(new A(new w(M[0],S[0]),new w(M[1],S[1])));const{layers:C,yDomain:D,zDomain:I}=p[1];u(new rt(b,C)),y(new A(new w(D[0],I[0]),new w(D[1],I[1])));const R=Eo({values:p[2].data,bins:p[3].data});d({values:Ke(new Float64Array(R.values),[R.values.length]),bins:Ke(new Float64Array(R.bins),[R.bins.length])})})}},[o,e,n,v]),g.useEffect(()=>{if(!a)return()=>{};if(!c||!l)return v(),s(j=>!j),i(!1),()=>{};if(c.getPendingTilesCount()+l.getPendingTilesCount()===0)return v(),s(j=>!j),i(!1),()=>{};const p=setInterval(()=>{v(),s(j=>!j),i(!1)},1e3);return()=>{clearInterval(p)}},[c,l,a,v]),{apiFront:l,apiSide:c,histogram:m,tilingBoxFront:x,tilingBoxSide:f,invalidate:()=>{v(),s(b=>!b)},lazyRefresh:()=>{i(!0)}}}function Ko(e,o){const[n,s]=g.useState(void 0);return g.useEffect(()=>{if(!e&&!o){s(void 0);return}if(e==="mock"){s(()=>fe.create({baseURL:e}));return}s(o?()=>fe.create({baseURL:new URL(o,qt()).toString(),...et.getOptions()}):void 0),e&&fe.get("status",{baseURL:e,timeout:3e3}).then(a=>s(()=>fe.create({baseURL:e}))).catch(()=>{})},[e,o,et.token]),n}const ut=W("daiquiri.services.TomovisService");function en(e,o,n){const[s,a]=g.useState([]),[i,l]=g.useState(null),[r,c]=g.useState("UNKNOWN"),u=g.useCallback(f=>{let y=0;f.forEach(v=>{v.status!=="done"&&(y+=1),v.id===o&&(v.status==="done"||v.status==="running")&&l(o)}),c(y?"PROCESSING":"READY")},[o,i,c]),m=g.useCallback(()=>{e&&(e.defaults.baseURL==="mock"&&a([{id:"chessboard",status:"done",create_time:"1871-03-18"}]),e.get("/image_tiling/").then(f=>{const y=f.data.items;if(y===void 0)throw new Error("No items field received.");u(y),a(v=>Te.isEqual(v,y)?v:y)}).catch(f=>{f.response.status===404?c("OFFLINE"):(c("FAILED"),console.error("Error while reading available tomovis tiling",f))}))},[e,i,o,u,c]);g.useEffect(()=>{m()},[m]);const d=g.useCallback(f=>{e&&e.delete(`/image_tiling/${f}`).then(y=>{const v=s.filter(b=>b.id!==f);return a(v),null}).catch(y=>{console.error('Error while requesting tiling deletion: "%s"',f,y)})},[e,s]),[x,h]=g.useState(n);return g.useEffect(()=>{const f=setInterval(()=>{m()},x);return()=>clearInterval(f)},[m,x]),g.useEffect(()=>{o&&o!==i||r==="PROCESSING"?n>2e3&&(ut("Polling every %sms",2e3),h(2e3)):(ut("Polling every %sms",n),h(n))},[i,o,n,r]),{imageTilings:s,lastReadyImageTiling:i,updateImageTilings:m,deleteImageTiling:d,state:r}}function le(e){const{startPoint:o,endPoint:n,lineWidth:s=1,lineColor:a="black",gapColor:i,gapSize:l,dashSize:r,opacity:c=1,zIndex:u=1}=e;return t.jsxs(t.Fragment,{children:[t.jsx(lt,{y:o[1],x1:o[0],x2:n[0],zIndex:u,color:a,gapColor:i,gapSize:l,dashSize:r,opacity:c,lineWidth:s}),t.jsx(lt,{y:n[1],x1:o[0],x2:n[0],zIndex:u,color:a,gapColor:i,gapSize:l,dashSize:r,opacity:c,lineWidth:s}),t.jsx(ye,{x:o[0],y1:o[1],y2:n[1],zIndex:u,color:a,gapColor:i,gapSize:l,dashSize:r,opacity:c,lineWidth:s}),t.jsx(ye,{x:n[0],y1:o[1],y2:n[1],zIndex:u,color:a,gapColor:i,gapSize:l,dashSize:r,opacity:c,lineWidth:s})]})}const tn=W("daiquiri.components.tomo.tiling.ActualDetectorLocation");function on(e){const o=(e.rotation+e.projRotation)/180*Math.PI,{x:n,y:s,fov:a}=e,i=Math.abs(Math.cos(o)*a[0]*.5),l=a[1]*.5,r=[n-a[0]*.5,s-a[1]*.5],c=[n+a[0]*.5,s+a[1]*.5],u=t.jsx(t.Fragment,{children:t.jsx(le,{startPoint:r,endPoint:c,lineColor:T.danger,gapColor:T.light,dashSize:4,gapSize:4,lineWidth:1,zIndex:2})});return i<.001?t.jsxs(t.Fragment,{children:[u,t.jsx(ye,{x:n,y1:s-l,y2:s+l,color:T.danger,lineWidth:2,zIndex:2})]}):t.jsxs(t.Fragment,{children:[u,t.jsx(le,{startPoint:[n-i,s-l],endPoint:[n+i,s+l],lineColor:T.danger,lineWidth:2,zIndex:2})]})}function nn(e){const{xAxisDelta:o,y:n,fov:s,detectorX:a}=e,i=s?s[1]*.5:50;function l(h){const{startPoint:f,endPoint:y}=h;return t.jsx(ye,{x:f.x,y1:f.y,y2:y.y,dashSize:8,gapSize:4,color:T.danger,gapColor:T.light})}const r=a+o;if(s===null){const h=new k(r,n-i),f=new k(r,n+i);return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[r+1,n-i],color:T.danger,text:"Axis"}),t.jsx(l,{startPoint:h,endPoint:f})]})}if(Math.abs(o)*2>s[0]){const h=s[0]*.5,f=new k(r,n-h-i),y=new k(r,n+h+i);return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[r+1,n-i],color:T.danger,text:"Axis"}),t.jsx(l,{startPoint:f,endPoint:y})]})}const c=s[1]*.5,u=new k(r,n-c),m=new k(r,n-c-i),d=new k(r,n+c),x=new k(r,n+c+i);return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[r+1,n-c-i],color:T.danger,text:"Axis"}),t.jsx(l,{startPoint:u,endPoint:m}),t.jsx(l,{startPoint:d,endPoint:x})]})}function sn(e){const{tomoHardware:o}=e,{sy:n,sz:s,somega:a,sampu:i,sampv:l,tomoDetector:r,detector:c,sampleStage:u}=o;if(n===null||s===null)return tn("Skipped: one of sy, sz is missing."),t.jsx(t.Fragment,{});function m(I){if(I===null)return null;const{position:R}=I.properties;if(R===null)return R;const _=St(I)?1:-1;return R*_}const d=(u==null?void 0:u.properties.detector_center)??[0,0],x=d[0]??0,h=d[1]??0,f=K(s),y=X(i)??0,v=X(l)??0,b=K(n),p=m(a),j=te(r,c);function M(){const I=e.projRotation*Math.PI/180;return-Math.sin(I)*y+Math.cos(I)*v+b}const S=M()-x,C=f-h,D=b-x;return t.jsxs(t.Fragment,{children:[t.jsx(Vo,{x:S,y:C,color:T.danger,sizeInScreen:20,lineWidth:2,zIndex:2}),t.jsx(Y,{datapos:[S-(j?j[0]*.5:0)+1,C-(j?j[1]*.5:0)],color:T.danger,text:(c==null?void 0:c.name)??"Detector"}),p!==null&&j!==null&&t.jsx(on,{x:S,y:C,fov:j,rotation:p,projRotation:e.projRotation}),t.jsx(nn,{xAxisDelta:D,y:C,fov:j,detectorX:S})]})}function Ve(e,o){if(e===null||o===null)return null;const n=e.properties.sample_pixel_size,s=o.properties.size;if(s===null||n===null)return null;const a=n/1e3;return[s[0]*a,s[1]*a]}function Rt(e,o){const{sy:n,sz:s,sampu:a,sampv:i,tomoDetector:l,detector:r}=e;if(s===null)return{motorBox:new A,visibleBox:new A,maxBox:new A};const c=o*Math.PI/180,u=n?K(n):0,[m,d]=he(n),[x,h]=he(a),[f,y]=he(i),[v,b]=he(s),p=-Math.sin(c)*x+Math.cos(c)*f+u,j=-Math.sin(c)*h+Math.cos(c)*y+u,M=Ve(l,r),[S,C]=M||[0,0],{sampleStage:D}=e,I=(D==null?void 0:D.properties.detector_center)??[0,0],R=I[0]??0,_=I[1]??0,$=new A().setFromPoints([new w(p-R,v-_),new w(j-R,b-_)]),B=$.clone().expandByVector(new w(S*.5,C*.5)),z=new A().setFromPoints([new w(x+f+m-R,v-_),new w(h+y+d-R,b-_)]).expandByVector(new w(S*.5,C*.5));return{motorBox:$,visibleBox:B,maxBox:z}}function Se(e){const{sz:o,sampu:n,sampv:s}=e;if(o===null)return;const a=X(n)??0,i=X(s)??0,l=K(o),{sampleStage:r}=e,c=(r==null?void 0:r.properties.detector_center)??[0,0],u=c[0]??0,m=c[1]??0;return new k(a-u,i-u,l-m)}function an(e){const{projRotation:o,tomoHardware:n}=e,{motorBox:s,visibleBox:a}=Rt(n,o);return t.jsxs(t.Fragment,{children:[!s.isEmpty()&&t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:a.min,color:T.info,text:"Visible limit"}),t.jsx(le,{startPoint:[a.min.x,a.min.y],endPoint:[a.max.x,a.max.y],lineColor:T.info,dashSize:8,gapSize:4})]}),!a.isEmpty()&&t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:s.min,color:T.info,text:"Motor limit"}),t.jsx(le,{startPoint:[s.min.x,s.min.y],endPoint:[s.max.x,s.max.y],lineColor:T.info,dashSize:2,gapSize:2})]})]})}const rn=2;function Nt(e){return t.jsxs(O,{className:"flex-nowrap",xs:12,children:[t.jsx(L,{xs:3,children:e.title}),t.jsx(L,{className:"text-end",xs:6,children:e.value.toFixed(rn)}),t.jsx(L,{className:"text-start",xs:3,children:e.unit})]})}function Ne(e){const{motor:o}=e,[n,s]=Mt(o,e.position),a=(o==null?void 0:o.alias)??(o==null?void 0:o.name)??e.defaultName;return t.jsx(Nt,{title:a,value:n,unit:s})}function cn(e){const{tomoHardware:o,value:n}=e,{sampleStage:s}=o,a=(s==null?void 0:s.properties.detector_center)??[0,0],i=a[0]??0,l=a[1]??0,r=o.sy?K(o.sy):0;return t.jsxs(ve,{children:[e.x!==void 0&&t.jsx(Ne,{motor:o.sampu,position:e.x-r+i,defaultName:"sample-u-axis"}),e.y!==void 0&&t.jsx(Ne,{motor:o.sampv,position:e.y-r+i,defaultName:"sample-v-axis"}),e.z!==void 0&&t.jsx(Ne,{motor:o.sz,position:e.z+l,defaultName:"z-axis"}),t.jsx(Nt,{title:"intensity",value:n,unit:""})]})}function ln(e,o){return e.expandByVector(e.getSize(new w).multiplyScalar(o*.5))}function dn(e){return{x:[e.min.x,e.max.x],y:[e.min.y,e.max.y]}}function un(e){const{task:o,view:n,dragTomoScanRoi:s,readOnly:a=!1}=e,{active:i,roi:l}=o,{centerZ:r,width:c,height:u}=l,{x:m,y:d}=l.center,x=g.useCallback((v,b)=>{const p=(v.x1+v.x2)*.5,j=(v.y1+v.y2)*.5;s(o.id,n==="front"?p:m,n==="front"?d:p,j)},[n,s,m,d,r]);if(c===null||u===null||c===null||u===null)return null;const h=n==="front"?m:d,f=new w(h-c/2,r-u/2),y=new w(h+c/2,r+u/2);return t.jsx(je,{geometry:{x1:f.x,y1:f.y,x2:y.x,y2:y.y},color:T.info,lineWidth:2,readOnly:!i,onGeometryChanged:x})}function mt(e,o){return o[0]<o[1]?o[0]<=e&&e<=o[1]:o[1]<=e&&e<=o[0]}function mn(e,o){return mt(e.x,o.xVisibleDomain)&&mt(e.y,o.yVisibleDomain)}function xn(e,o){const n=e===null||o===null?null:new k(e,o),{dataToHtml:s,getVisibleDomains:a}=vo();return jo(i=>{if(n===null)return null;const l=a(i);return{isVisible:mn(n,l),displayedCoords:s(i,n)}},[e,o])}const fn=W("daiquiri.components.tomo.tiling.MotorMarker"),gn=g.forwardRef((e,o)=>{const{popper:n,children:s,show:a,displayed:i,displayedCoords:l,...r}=e;return g.useEffect(()=>{n&&n.scheduleUpdate()},[s,n]),g.useEffect(()=>{n&&n.scheduleUpdate()},[l,n]),t.jsx(ce,{ref:o,body:!0,...r,children:s})});function Ie(e){const{motor:n}=e,[s,a]=Mt(n,e.position),i=(n==null?void 0:n.alias)??(n==null?void 0:n.name)??e.defaultName;return t.jsxs(O,{className:"flex-nowrap text-nowrap",xs:12,children:[t.jsx(L,{xs:3,children:i}),t.jsx(L,{className:"text-end",xs:6,children:s.toFixed(2)}),t.jsx(L,{className:"text-start",xs:3,children:t.jsx("span",{className:"text-nowrap",children:a})})]})}function hn(e){const{tomoHardware:o,projRotation:n,variant:s="primary"}=e,[a,i]=g.useState(!1),l=g.useRef(null);function r(){if(n===0){const[M,S,C]=e.coords;return[S,C]}else if(n===-90){const[M,S,C]=e.coords;return[M,C]}return console.error(`Unimplemented projRotation ${n}`),[null,null]}const[c,u]=r(),m=xn(c,u);if(c===null||u===null)return fn("Skipped: projected pixel size is null."),t.jsx(t.Fragment,{});const[d,x,h]=e.coords,f=o.sy?K(o.sy):0,{sampleStage:y}=o,v=(y==null?void 0:y.properties.detector_center)??[0,0],b=v[0]??0,p=v[1]??0,j=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-end mb-2",children:t.jsx(N,{size:"sm",variant:"light",onClick:()=>{e.onDelete&&e.onDelete(s)},title:"Remove the marker",children:t.jsx("i",{className:"fa fa-fw fa-trash fa-lg"})})}),t.jsxs(ve,{children:[d!==null&&t.jsx(Ie,{motor:o.sampu,position:d-f+b,defaultName:"sample-u-axis"}),x!==null&&t.jsx(Ie,{motor:o.sampv,position:x-f+b,defaultName:"sample-v-axis"}),h!==null&&t.jsx(Ie,{motor:o.sz,position:h+p,defaultName:"z-axis"}),(e.onDelete||e.onMove)&&t.jsx(O,{className:"g-0 mt-2 justify-content-center",children:t.jsxs(E,{children:[t.jsx(N,{size:"sm",variant:"danger",title:"Move the sample stage at this location",onClick:()=>{e.onMove&&e.onMove(s)},children:"Move motors"}),t.jsx(N,{size:"sm",variant:"secondary",title:"Copy bliss command to clipboard",onClick:()=>{e.onCopyToClipboard&&e.onCopyToClipboard(s)},children:t.jsx("i",{className:"fa fa-fw fa-clipboard"})})]})})]})]});return t.jsx(t.Fragment,{children:t.jsx(po,{x:c,y:u,children:t.jsx(wt,{trigger:"click",rootClose:!0,overlay:t.jsx(gn,{id:"popover-contained",show:a&&!(m!=null&&m.isVisible),displayed:a,displayedCoords:(m==null?void 0:m.displayedCoords)??null,children:j}),children:t.jsx(bt,{bg:"none",onClick:()=>i(!a),style:{pointerEvents:"auto",top:"50%",left:"50%",position:"relative",transform:"translate(-100%, -100%)"},children:t.jsx("i",{ref:l,style:{cursor:"pointer"},className:`fa fa-map-marker fa-3x text-${s}`})})})})})}function yn(e){const{getCenter:o}=e,[n,s]=G("tomo/tiling/markers",{}),a=g.useCallback((i,l,r,c)=>{const u=o()??{x:null,y:null,z:null},m=n[i]??[null,null,null],d={...n},x=l===null&&r===null&&c===null;d[i]=x?[null,null,null]:[l??m[0]??u.x,r??m[1]??u.y,c??m[2]??u.z],s(d)},[s,n]);return[n,a]}function vn(e){return t.jsx(t.Fragment,{children:Te.map(e.markers,(o,n)=>t.jsx(hn,{projRotation:e.projRotation,tomoHardware:e.tomoHardware,variant:n,coords:o,onDelete:s=>{e.setMarker(s,null,null,null)},onMove:s=>{const a=e.markers[s],i=e.computeSampleStageAtPlotLocation(a[0],a[1],a[2]);ke(i)},onCopyToClipboard:s=>{const a=e.markers[s],i=e.computeSampleStageAtPlotLocation(a[0],a[1],a[2]);function l(c,u,m){if(m===void 0||u===null)return;const d=m.to(u.properties.unit).scalar;c.push(`${u.alias??u.name}`,`${d.toFixed(4)}`)}const r=[];l(r,e.tomoHardware.sz,i.sz),l(r,e.tomoHardware.sampu,i.sampu),l(r,e.tomoHardware.sampv,i.sampv),navigator.clipboard.writeText(`umv(${r.join(", ")})`)}},n))})}function jn(e){const{disabled:o,projRotation:n,selectedMarker:s,setMarker:a}=e,i=g.useCallback(l=>{if(o){console.error("Unexpected click action");return}n===0?a(s,null,l.dataPt.x,l.dataPt.y):n===-90?a(s,l.dataPt.x,null,l.dataPt.y):console.error(`Unexpected projRotation ${n}`)},[o,n,a,s]);return t.jsx(t.Fragment,{children:!o&&t.jsx(Ae,{onClick:i})})}const It=W("daiquiri.components.tomo.tiling.TilingInteraction");function pn(e){const{disabled:o,onActionRequested:n,projRotation:s,computeSampleStageAtPlotLocation:a,sampleStage:i}=e,{sy:l}=i,r=g.useCallback(c=>{if(n(),s===0){const u=c.dataPt.x,m=c.dataPt.y,d=a(null,u,m);ke(d)}else if(s===-90){const u=c.dataPt.x,m=c.dataPt.y,d=a(u,null,m);ke(d)}else console.error(`Unexpected projRotation ${s}`)},[l,a,n]);return o?(It("MoveMotorInteraction disabled."),t.jsx(t.Fragment,{})):t.jsx(Ae,{onClick:r})}function Sn(e){const{disabled:o,roiFov:n,projRotation:s,actions:a,onActionRequested:i}=e,l=g.useCallback((c,u,m)=>{n&&a.createScanTask({x:new H(c,"mm"),y:new H(u,"mm"),z:new H(m,"mm"),detector:n.detector,magnification:n.magnification,fov:[new H(n.fov[0],"mm"),new H(n.fov[1],"mm")],pixelSize:[new H(n.pixelSize[0],"um"),new H(n.pixelSize[1],"um")],active:!0})},[n,a]),r=g.useCallback(c=>{i(),s===0?l(c.dataPt.x,0,c.dataPt.y):s===-90?l(0,c.dataPt.x,c.dataPt.y):console.error(`Unexpected projRotation ${s}`)},[l,i,s]);return o||n===null?(It("CreateRoiInteraction disabled."),t.jsx(t.Fragment,{})):t.jsx(Ae,{onClick:r})}function wn(e){const{projRotation:o,mouseMode:n,resetMouseMode:s,actions:a,computeSampleStageAtPlotLocation:i,operator:l,sampleStage:r,roiFov:c,markerName:u,setMarker:m,mouseOverlay:d}=e;return t.jsxs(t.Fragment,{children:[t.jsx($o,{mouseMode:n,disabled:d!==void 0,plotUnit:"mm"}),t.jsx(Sn,{projRotation:o,disabled:d!==void 0||n!=="create",roiFov:c,actions:a,onActionRequested:()=>s()}),t.jsx(pn,{projRotation:o,disabled:d!==void 0||!l||n!=="move-motors",computeSampleStageAtPlotLocation:i,sampleStage:r,onActionRequested:()=>s()}),t.jsx(jn,{projRotation:o,disabled:d!==void 0||n!=="mark-position",selectedMarker:u,setMarker:m})]})}function bn(e){const{api:o,box:n,renderTooltip:s,...a}=e;if(!o||n.isEmpty())return null;const i=n.getSize(new w),l=n.getCenter(new w);return t.jsxs("group",{position:[l.x,l.y,0],children:[t.jsx(So,{api:o,size:{width:i.x,height:i.y},...a}),s&&t.jsx(wo,{size:i,renderTooltip:s})]})}class zn extends Qt{constructor(){super({uniforms:{color:{value:new Jt},size:{value:new w},nbCells:{value:new w},overlap:{value:new w},scaleX:{value:0},scaleY:{value:0},lineWidth:{value:0}},vertexShader:`
|
|
2
|
+
uniform float scaleX; // signed scale
|
|
3
|
+
uniform float scaleY; // signed scale
|
|
4
|
+
out vec2 pixelCoord;
|
|
5
|
+
// out vec2 dataCoord;
|
|
6
|
+
|
|
7
|
+
void main() {
|
|
8
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
9
|
+
vec2 pixelScale = abs(vec2(scaleX, scaleY));
|
|
10
|
+
// dataCoord = vec2(position.x, position.y);
|
|
11
|
+
pixelCoord = vec2(position.x, position.y) / pixelScale;
|
|
12
|
+
}
|
|
13
|
+
`,fragmentShader:`
|
|
14
|
+
uniform vec4 color;
|
|
15
|
+
uniform vec4 gapColor;
|
|
16
|
+
uniform float gapSize;
|
|
17
|
+
uniform float dashSize;
|
|
18
|
+
uniform float lineWidth;
|
|
19
|
+
uniform float scaleX; // signed scale
|
|
20
|
+
uniform float scaleY; // signed scale
|
|
21
|
+
uniform vec2 size;
|
|
22
|
+
uniform vec2 nbCells;
|
|
23
|
+
uniform vec2 overlap;
|
|
24
|
+
in vec2 pixelCoord;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param position: pixel position
|
|
28
|
+
* @param size: size of the rectangle
|
|
29
|
+
* @param nbCells: number of cells
|
|
30
|
+
* @param overlap: size of the overlap in ratio of a cell
|
|
31
|
+
* (0.5 means same size with the cell)
|
|
32
|
+
*/
|
|
33
|
+
float sdf_grid(in vec2 position, in vec2 size, in vec2 nbCells, in vec2 overlap) {
|
|
34
|
+
vec2 maxSize = size / (nbCells - overlap * (nbCells - 1.0));
|
|
35
|
+
vec2 tableDist = min(abs(abs(position) - size * 0.5), maxSize);
|
|
36
|
+
vec2 overlapSize = maxSize * overlap;
|
|
37
|
+
vec2 cellSize = maxSize - overlapSize;
|
|
38
|
+
vec2 p = position - cellSize * 0.5 * (1.0 - mod(nbCells, 2.0));
|
|
39
|
+
vec2 gridDist = abs(abs(mod(p, cellSize)) - cellSize * 0.5);
|
|
40
|
+
gridDist -= overlapSize * 0.5;
|
|
41
|
+
gridDist = max(gridDist, cellSize - tableDist);
|
|
42
|
+
return min(gridDist.x, gridDist.y);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void main() {
|
|
46
|
+
vec2 scale = abs(vec2(scaleX, scaleY));
|
|
47
|
+
float d = sdf_grid(pixelCoord, size / scale, nbCells, overlap);
|
|
48
|
+
|
|
49
|
+
//#define DEBUG_DIST
|
|
50
|
+
#ifdef DEBUG_DIST
|
|
51
|
+
vec2 n = size / nbCells / scale;
|
|
52
|
+
float c = d / min(n.x, n.y);
|
|
53
|
+
gl_FragColor = vec4(max(-c, 0.0), abs(c), max(c, 0.0), 1.0);
|
|
54
|
+
return;
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
if (d > lineWidth) {
|
|
58
|
+
discard;
|
|
59
|
+
}
|
|
60
|
+
float alpha;
|
|
61
|
+
if (lineWidth >= 1.0) {
|
|
62
|
+
alpha = smoothstep(1.0, 0.0, d - lineWidth * 0.5);
|
|
63
|
+
} else {
|
|
64
|
+
// simulate line thiner than 1px with alpha
|
|
65
|
+
alpha = lineWidth;
|
|
66
|
+
}
|
|
67
|
+
gl_FragColor = vec4(color.rgb, color.a * alpha);
|
|
68
|
+
}
|
|
69
|
+
`})}}Xt({GridDashMaterial:zn});function Pt(e){const{center:o,size:n,nbCells:s,overlap:a=[0,0],lineWidth:i=1,color:l="black",opacity:r=1,zIndex:c=0}=e,u=g.useRef(null),m=Lo();return g.useEffect(()=>{const d=_o(l,r);if(u.current){const x=u.current.uniforms;x.color.value=d,x.size.value=n,x.nbCells.value=s,x.overlap.value=a,x.lineWidth.value=i,Kt()}},[l,n,s,a,r,i]),eo(({camera:d})=>{if(u.current===null)return;const x=d.scale.x/m.sx,h=d.scale.y/m.sy,f=u.current.uniforms;f.scaleX.value=x,f.scaleY.value=h}),t.jsx("group",{position:[o[0],o[1],c],children:t.jsxs("mesh",{children:[t.jsx("ambientLight",{}),t.jsx("planeGeometry",{attach:"geometry",args:[n[0],n[1],1,1]}),t.jsx("gridDashMaterial",{attach:"material",transparent:!0,ref:u})]})})}const Cn=W("daiquiri.components.tomo.tiling.rois.CubeRoi");function xt(e,o){return o===0?new w(e.y,e.z):o===-90?new w(e.x,e.z):(console.error(`Unimplemented projRotation ${o}`),null)}function Mn(e,o){return o===void 0?{}:e===0?{nbRow:o.z,nbCol:o.y}:e===-90?{nbRow:o.z,nbCol:o.x}:{}}function Dn(e,o,n){if(e===null)return{box:new A};const s=xt(e.start,o),a=xt(e.stop,o);if(s===null||a===null)return{box:new A};const i=Mn(o,n);return{box:new A().setFromPoints([s,a]),...i}}function kt(e,o,n){function s(a,i,l){return l===0?new k((a==null?void 0:a.x)??0,i.x,i.y):l===-90?new k(i.x,(a==null?void 0:a.y)??0,i.y):(console.error(`Unexpected projRotation ${l}`),a)}return{start:s(e.start,new w(o.x1,o.y1),n),stop:s(e.stop,new w(o.x2,o.y2),n)}}function ft(e,o,n){const s={x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y};return kt(e,s,n)}function Rn(e){const o=Se(e),{tomoDetector:n,detector:s}=e,a=te(n,s)??[1,1];return o?{start:new k(o.x-a[0]*1.4,o.y-a[0]*1.4,o.z-a[1]*1.4),stop:new k(o.x+a[0]*1.4,o.y+a[0]*1.4,o.z+a[1]*1.4)}:(console.error("oups center",o),Cn("Roi reset skipped: center is undefined."),null)}function Nn(e){const{roi:o,projRotation:n,maxCellSize:s=[0,0]}=e,a=g.useCallback((x,h)=>{const f=kt(o,x,n);h?e.onDragMove&&e.onDragMove(f):e.onDragEnd&&e.onDragEnd(f)},[o,e.onDragMove,e.onDragEnd,n]),{box:i,nbRow:l,nbCol:r}=Dn(o,n,e.grid),c=new w;i.getSize(c);const u=new w;i.getCenter(u);function m(){if(e.readOnly)return;const[x,h]=s,f=Math.ceil(c.x/x),y=Math.ceil(c.y/h),v=(x*f-c.x)/(f-1),b=(h*y-c.y)/(y-1),p=f<=1?0:v/x,j=y<=1?0:b/h;return[p,j]}const d=m();return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[(i.min.x+i.max.x)*.5,i.min.y],text:e.label??"",color:e.color,anchor:"bottom"}),t.jsx(Pt,{center:[u.x,u.y],size:[c.x,c.y],color:e.color,opacity:.25,nbCells:[r??1,l??1],overlap:d,lineWidth:1,zIndex:.5}),t.jsx(je,{geometry:{x1:i.min.x,y1:i.min.y,x2:i.max.x,y2:i.max.y},readOnly:e.readOnly,onGeometryChanged:a,color:e.color})]})}function In(e,o,n){return g.useMemo(()=>{const s=te(o,n);if(s===null)return;const a=new k;return a.add(e.start),a.sub(e.stop),[new k(Math.ceil(Math.abs(a.x)/s[0]),Math.ceil(Math.abs(a.y)/s[0]),Math.ceil(Math.abs(a.z)/s[1])),s]},[e,o])}function Pn(e){const[o,n]=In(e.roi,e.tomoDetector,e.detector)??[void 0,void 0];return t.jsx(Nn,{roi:e.roi,grid:o,maxCellSize:n,onDragEnd:e.onDragEnd,onDragMove:e.onDragMove,projRotation:e.projRotation,color:T.success,label:"Tiling",readOnly:e.readOnly})}function kn(e){const{disabled:o,projRotation:n,geometry:s,onGeometryChanged:a,sampleStage:i,resetMouseMode:l}=e,r=Oe();return t.jsx(Le,{id:e.id,disabled:o||(r==null?void 0:r.overlayCursor)!==void 0,onSelectionStart:()=>{r==null||r.actions.captureMouseInteraction()},onSelectionEnd:()=>{r==null||r.actions.releaseMouseInteraction(),l()},onSelectionChange:c=>{if(c===void 0)return;function u(){return s||Rn(i)}const m=u();if(m===null)return;const d=ft(m,c.data,n);a(d)},onValidSelection:c=>{if(s===null)return;const u=ft(s,c.data,n);a(u)},children:c=>t.jsx(t.Fragment,{})})}W("daiquiri.components.tomo.tiling.FlatLocation");function Tn(e){const{x:o,y:n,fov:s}=e,a=s[0]*.5,i=s[1]*.5;return t.jsx(le,{startPoint:[o-a,n-i],endPoint:[o+a,n+i],lineColor:T.secondary,lineWidth:2,zIndex:2})}function gt(e,o){return g.useMemo(()=>{if(o===null||e===void 0)return null;for(const n of e){const s=n.axisRef.slice(9);if(s===o.alias||s===o.id||s===o.name)return n}return null},[e,o==null?void 0:o.alias,o==null?void 0:o.name,o==null?void 0:o.id])}function Fn(e){const{tomoHardware:o,tomoFlatMotion:n}=e,{sy:s,sz:a,sampu:i,sampv:l,tomoDetector:r,detector:c,sampleStage:u}=o,m=gt(n==null?void 0:n.properties.motion,s),d=gt(n==null?void 0:n.properties.motion,a);if(m===null&&d===null)return t.jsx(t.Fragment,{});const x=(u==null?void 0:u.properties.detector_center)??[0,0],h=x[0]??0,f=x[1]??0,y=X(a),v=X(i)??0,b=X(l)??0,p=X(s),j=te(r,c);if(j===null)return t.jsx(t.Fragment,{});function M(){const z=e.projRotation*Math.PI/180;return y===null||p===null?null:[-Math.sin(z)*v+Math.cos(z)*b+p-h,y-f]}const S=(d==null?void 0:d.absolute_position)??null,C=(d==null?void 0:d.relative_position)??null,D=(m==null?void 0:m.absolute_position)??null,I=(m==null?void 0:m.relative_position)??null;function R(){if(D!==null&&S!==null)return[D,S];const z=M();if(z===null)return null;const P=D??z[0]+(I??0),Q=S??z[1]+(C??0);return[P,Q]}const _=R();if(_===null)return t.jsx(t.Fragment,{});const[$,B]=_;return t.jsxs(t.Fragment,{children:[t.jsx(Y,{vmargin:0,hmargin:0,anchor:"center",datapos:[$,B],color:T.primary,text:"Flat"}),t.jsx(Tn,{x:$,y:B,fov:j})]})}const En=W("daiquiri.components.tomo.Point3DRoi");function Ln(e,o){return e===null?{x:0,y:0}:o===0?{x:e.y,y:e.z}:o===-90?{x:e.x,y:e.z}:(console.error(`Unimplemented projRotation ${o}`),{x:0,y:0})}function On(e,o,n){const s=(o.x1+o.x2)*.5,a=(o.y1+o.y2)*.5;return n===0?{x:e.x,y:s,z:a}:n===-90?{x:s,y:e.y,z:a}:(console.error(`Unimplemented projRotation ${n}`),{x:0,y:0,z:0})}function ht(e,o,n){const{x:s,y:a}=o[1];return n===0?{x:e.x,y:s,z:a}:n===-90?{x:s,y:e.y,z:a}:(console.error(`Unexpected projRotation ${n}`),e)}function An(e){const o=Se(e);return o?{x:o.x,y:o.y,z:o.z}:(En("Roi reset skipped: center is undefined."),null)}function _n(e){const{roi:o,projRotation:n,cellSize:s=[0,0]}=e,a=g.useCallback((l,r)=>{const c=On(o,l,n);r?e.onDragMove&&e.onDragMove(c):e.onDragEnd&&e.onDragEnd(c)},[o,e.onDragMove,e.onDragEnd,n]),i=Ln(o,n);return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[i.x,i.y-s[1]*.5],text:e.label??"",color:e.color,anchor:"bottom"}),t.jsx(je,{geometry:{x1:i.x-s[0]*.5,y1:i.y-s[1]*.5,x2:i.x+s[0]*.5,y2:i.y+s[1]*.5},readOnly:e.readOnly,onGeometryChanged:a,color:e.color})]})}function Vn(e){const o=g.useMemo(()=>te(e.tomoDetector,e.detector),[e.tomoDetector,e.detector]);return t.jsx(_n,{roi:e.roi,cellSize:o??void 0,onDragEnd:e.onDragEnd,onDragMove:e.onDragMove,projRotation:e.projRotation,color:T.success,label:"Tomo",readOnly:e.readOnly})}function $n(e){const{disabled:o,projRotation:n,geometry:s,onGeometryChanged:a,sampleStage:i,resetMouseMode:l}=e,r=Oe();return t.jsx(Le,{id:e.id,disabled:o||(r==null?void 0:r.overlayCursor)!==void 0,onSelectionStart:()=>{r==null||r.actions.captureMouseInteraction()},onSelectionEnd:()=>{r==null||r.actions.releaseMouseInteraction(),l()},onSelectionChange:c=>{if(c===void 0)return;function u(){return s||An(i)}const m=u();if(m===null)return;const d=ht(m,c.data,n);a(d)},onValidSelection:c=>{if(s===null)return;const u=ht(s,c.data,n);a(u)},children:c=>t.jsx(t.Fragment,{})})}const Bn=W("daiquiri.components.tomo.Point3DRoi");function Hn(e,o){return e===null?{x:0,ystart:0,ystop:0}:o===0?{x:e.y,ystart:e.zstart,ystop:e.zstop}:o===-90?{x:e.x,ystart:e.zstart,ystop:e.zstop}:(console.error(`Unimplemented projRotation ${o}`),{x:0,ystart:0,ystop:0})}function Gn(e,o,n){const s=(o.x1+o.x2)*.5;return(o.y1+o.y2)*.5,n===0?{x:e.x,y:s,zstart:o.y1,zstop:o.y2}:n===-90?{x:s,y:e.y,zstart:o.y1,zstop:o.y2}:(console.error(`Unimplemented projRotation ${n}`),{x:0,y:0,zstart:0,zstop:0})}function yt(e,o,n){const{x:s,y:a}=o[0];return n===0?{x:e.x,y:s,zstart:o[0].y,zstop:o[1].y}:n===-90?{x:s,y:e.y,zstart:o[0].y,zstop:o[1].y}:(console.error(`Unexpected projRotation ${n}`),e)}function Yn(e){const o=Se(e),{tomoDetector:n,detector:s}=e,a=Ve(n,s)??[1,1];return o?{x:o.x,y:o.y,zstart:o.z-a[0]*.5,zstop:o.z-a[0]*.5}:(Bn("Roi reset skipped: center is undefined."),null)}function Un(e){const{roi:o,projRotation:n,cellSize:s=[0,0]}=e,a=g.useCallback((x,h)=>{const f=Gn(o,x,n);h?e.onDragMove&&e.onDragMove(f):e.onDragEnd&&e.onDragEnd(f)},[o,e.onDragMove,e.onDragEnd,n]),i=Hn(o,n),l=Math.abs(i.ystop-i.ystart),r=(i.ystart+i.ystop)*.5,c=s[1],u=Math.ceil(l/c);function m(){if(e.readOnly)return;const x=(c*u-l)/(u-1);return[0,u<=1?0:x/c]}const d=m();return t.jsxs(t.Fragment,{children:[t.jsx(Y,{datapos:[i.x,Math.min(i.ystart,i.ystop)],text:e.label??"",color:e.color,anchor:"bottom"}),t.jsx(Y,{datapos:[i.x,i.ystart],text:"Start",color:e.color,anchor:"top"}),t.jsx(Y,{datapos:[i.x,i.ystop],text:"Stop",color:e.color,anchor:"top"}),t.jsx(Pt,{center:[i.x,r],size:[s[0],l],color:e.color,opacity:.25,nbCells:[1,u??1],overlap:d,lineWidth:1,zIndex:.5}),t.jsx(je,{geometry:{x1:i.x-s[0]*.5,y1:i.ystart,x2:i.x+s[0]*.5,y2:i.ystop},readOnly:e.readOnly,onGeometryChanged:a,color:e.color})]})}function Zn(e){const o=g.useMemo(()=>te(e.tomoDetector,e.detector),[e.tomoDetector,e.detector]);return t.jsx(Un,{roi:e.roi,cellSize:o??void 0,onDragEnd:e.onDragEnd,onDragMove:e.onDragMove,projRotation:e.projRotation,color:T.success,label:"Zseries",readOnly:e.readOnly})}function Wn(e){const{disabled:o,projRotation:n,geometry:s,onGeometryChanged:a,sampleStage:i,resetMouseMode:l}=e,r=Oe();return t.jsx(Le,{id:e.id,disabled:o||(r==null?void 0:r.overlayCursor)!==void 0,onSelectionStart:()=>{r==null||r.actions.captureMouseInteraction()},onSelectionEnd:()=>{r==null||r.actions.releaseMouseInteraction(),l()},onSelectionChange:c=>{if(c===void 0)return;function u(){return s||Yn(i)}const m=u();if(m===null)return;const d=yt(m,c.data,n);a(d)},onValidSelection:c=>{if(s===null)return;const u=yt(s,c.data,n);a(u)},children:c=>t.jsx(t.Fragment,{})})}function qn(e){const{color:o="black",domainX:n,domainY:s,zIndex:a=0}=e,i=Math.abs(n[1]-n[0]),l=(n[0]+n[1])*.5,r=Math.abs(s[1]-s[0]),c=(s[0]+s[1])*.5;return t.jsxs(t.Fragment,{children:[t.jsxs("mesh",{position:[l-i,c,a],children:[t.jsx("ambientLight",{}),t.jsx("planeGeometry",{attach:"geometry",args:[i,r*10,1,1]}),t.jsx("meshBasicMaterial",{attach:"material",color:o,opacity:1})]}),t.jsxs("mesh",{position:[l+i,c,a],children:[t.jsx("ambientLight",{}),t.jsx("planeGeometry",{attach:"geometry",args:[i,r*10,1,1]}),t.jsx("meshBasicMaterial",{attach:"material",color:o,opacity:1})]}),t.jsxs("mesh",{position:[l,c-r,a],children:[t.jsx("ambientLight",{}),t.jsx("planeGeometry",{attach:"geometry",args:[i*10,r,1,1]}),t.jsx("meshBasicMaterial",{attach:"material",color:o,opacity:1})]}),t.jsxs("mesh",{position:[l,c+r,a],children:[t.jsx("ambientLight",{}),t.jsx("planeGeometry",{attach:"geometry",args:[i*10,r,1,1]}),t.jsx("meshBasicMaterial",{attach:"material",color:o,opacity:1})]})]})}function Xn(e,o){const n=Fe(e);return g.useMemo(()=>{const{maxBox:s}=Rt(n,o);return dn(ln(s,.1))},[n])}function vt(e){const{projRotation:o,config:n,api:s,tilingBox:a,actions:i,tasks:l,computeSampleStageAtPlotLocation:r,operator:c,roiFov:u,markerName:m,children:d,mouseModeInteraction:x,setMarker:h,markers:f,editScanRoi:y,tomoFlatMotion:v,...b}=e,p=Xn(e.sampleStage,o),{mouseMode:j,resetMouseMode:M}=x,S=Fe(e.sampleStage),{tomoDetector:C,detector:D}=S,I=g.useCallback((P,Q,oe,ue)=>i.moveScanTaskRoi(P,new H(Q,"mm"),new H(oe,"mm"),new H(ue,"mm")),[]),R=o===0?"front":"side",_=g.useCallback(P=>(s==null?void 0:s.layerDType)===Fo.Float16?Oo(P):P,[s]),$=g.useMemo(()=>({"create-tiling-roi":"crosshair","move-motors":"crosshair",create:"crosshair","measure-distance":"crosshair","mark-position":"crosshair","edit-tiling-roi":"crosshair"}),[]),[B,z]=g.useState(void 0);return t.jsxs(zo,{abscissaConfig:{visDomain:p.x,flip:R==="front"},ordinateConfig:{visDomain:p.y,flip:!0},aspect:"equal",title:`${Te.capitalize(R)} (in mm)`,showAxes:n.displayAxes,mouseMode:j,onMouseInteractionOverlayChanged:z,cursors:$,children:[t.jsx(qn,{domainX:p.x,domainY:p.y,color:T.light}),e.tilingRoi&&t.jsx(Pn,{roi:e.tilingRoi,tomoDetector:C,detector:D,onDragMove:e.setTilingRoi,onDragEnd:e.setTilingRoi,projRotation:o,readOnly:y!=="tiling"}),e.scanRoi&&t.jsx(Vn,{roi:e.scanRoi,tomoDetector:C,detector:D,onDragMove:e.setScanRoi,onDragEnd:e.setScanRoi,projRotation:o,readOnly:y!=="scan"}),e.zseriesRoi&&t.jsx(Zn,{roi:e.zseriesRoi,tomoDetector:C,detector:D,onDragMove:e.setZseriesRoi,onDragEnd:e.setZseriesRoi,projRotation:o,readOnly:y!=="zseries"}),t.jsx(kn,{id:"tiling-roi-selection-tool",disabled:B!==void 0||j!=="create-tiling-roi"||y!=="tiling",geometry:e.tilingRoi,onGeometryChanged:e.setTilingRoi,projRotation:o,sampleStage:S,resetMouseMode:M}),t.jsx($n,{id:"scan-roi-selection-tool",disabled:B!==void 0||j!=="create-tiling-roi"||y!=="scan",geometry:e.scanRoi,onGeometryChanged:e.setScanRoi,projRotation:o,sampleStage:S,resetMouseMode:M}),t.jsx(Wn,{id:"zseries-roi-selection-tool",disabled:B!==void 0||j!=="create-tiling-roi"||y!=="zseries",geometry:e.zseriesRoi,onGeometryChanged:e.setZseriesRoi,projRotation:o,sampleStage:S,resetMouseMode:M}),t.jsx(wn,{mouseOverlay:B,projRotation:o,mouseMode:j,resetMouseMode:x.resetMouseMode,roiFov:u,actions:i,computeSampleStageAtPlotLocation:r,sampleStage:S,markerName:m,operator:c,setMarker:h}),t.jsx(bn,{api:s,box:a,renderTooltip:(P,Q,oe)=>t.jsx(cn,{projRotation:o,x:R==="side"?P:void 0,y:R==="front"?P:void 0,z:Q,tomoHardware:S,value:_(oe)}),...b}),l.map(P=>t.jsx(un,{task:P,view:R,readOnly:j!=="pan"&&j!=="zoom",dragTomoScanRoi:I},P.id)),S&&t.jsxs(t.Fragment,{children:[t.jsx(an,{projRotation:o,tomoHardware:S}),t.jsx(sn,{projRotation:o,tomoHardware:S}),t.jsx(Fn,{projRotation:o,tomoHardware:S,tomoFlatMotion:v})]}),t.jsx(vn,{projRotation:o,tomoHardware:S,markers:f,setMarker:h,computeSampleStageAtPlotLocation:r}),d]})}function Qn(e){const{tomovisRestService:o,tomovisService:n}=e;function s(){if(!o)return["secondary","UNDECLARED","Tomovis service not declared at the Daiquiri server config. No tiling can be retrieved"];const r=o.defaults.baseURL;return n?[{OFFLINE:"secondary",READY:"success",FAILED:"danger",UNKNOWN:"secondary",PROCESSING:"warning"}[n.state],n.state,`Tomovis service is declared at ${r}`]:["danger","OFFLINE",`Tomovis service can be setup at ${r}`]}const[a,i,l]=s();return t.jsx(Dt,{className:e.className,name:"Tomovis",state:i,stateVariant:a,description:l})}function Jn(e){const o=to()??{state:"NONE"},[n,s]=Ho(o.state);return t.jsx(Dt,{className:e.className,name:"Scan",state:n,stateVariant:s,description:"Tiling scan state"})}function Kn(e){const{as:o=void 0,onSelect:n,value:s,variant:a}=e,i=["primary","success","info","warning","danger","dark"];return t.jsx(E,{as:o,id:"bg-vertical-dropdown-3",variant:a,children:i.map((l,r)=>{const c=s!==null&&l===s;return t.jsx(N,{variant:c?"primary":"secondary",onClick:()=>{n(l)},children:t.jsx("i",{className:`fa fa-map-marker fa-lg text-${c&&l==="primary"?"secondary":l}`})},r)})})}function es(e){const{mouseModeInteraction:o,dropDirection:n="down",showRoiTools:s=!0}=e,{mouseMode:a,setOrResetMouseMode:i}=o,l=a==="mark-position",[r,c]=g.useState(!1),u=zt();g.useEffect(()=>{c(l)},[l]);const m=t.jsx(ce,{id:"popover-container",body:!0,children:t.jsx(Kn,{value:e.markerName,onSelect:e.onSelectMarkerName})});function d(x){return x==="up"?"top":"bottom"}return t.jsxs(t.Fragment,{children:[t.jsx(wt,{trigger:"click",placement:d(n),overlay:m,children:t.jsx(N,{variant:a==="mark-position"?"primary":"secondary",title:"Pin a position in the sample stage",onClick:()=>{i("mark-position")},children:t.jsx("i",{className:"fa fa-map-marker fa-fw fa-lg"})})}),t.jsx(N,{variant:a==="move-motors"?"danger":"secondary",title:"Click on the scene to move the active detector at a specific location",disabled:!u,onClick:()=>{i("move-motors")},size:"sm",children:t.jsx("i",{className:"fad fam-move-samplestage fa-fw fa-2x"})}),s&&t.jsx(N,{variant:a==="create"?"primary":"secondary",title:"Click on the scene to create a new scan ROI",onClick:()=>{i("create")},size:"sm",children:t.jsx("i",{className:"fa fam-roi-new fa-fw fa-lg"})})]})}function ts(e){const{tilingRoi:o,clearTilingRoi:n,mouseModeInteraction:s,tomoConfigId:a}=e,{mouseMode:i,setOrResetMouseMode:l}=s,r=i==="create-tiling-roi",c=g.useCallback(()=>{if(o===null)return;const m=de.getState().hardware,d=pe(m,a),{sampleStage:x}=d,h=(x==null?void 0:x.properties.detector_center)??[0,0],f=h[0]??0,y=h[1]??0;return{start_x:V(o.start.x+f,3),end_x:V(o.stop.x+f,3),start_y:V(o.start.y+f,3),end_y:V(o.stop.y+f,3),start_z:V(o.start.z+y,3),end_z:V(o.stop.z+y,3)}},[o,a]);return t.jsxs(Ee,{direction:"horizontal",children:[t.jsx("div",{className:"text-dark p-2",children:"Tiling:"}),t.jsxs(E,{className:e.className,children:[t.jsx(N,{variant:r?"primary":"secondary",title:"Initialize the location of the ROI",onClick:()=>{l("create-tiling-roi")},children:t.jsx("i",{className:"fa fam-roi-new fa-fw"})}),t.jsx(N,{variant:"secondary",title:"Initialize the location of the ROI",onClick:()=>{n()},disabled:o===null,children:t.jsx("i",{className:"fa fa-trash-can fa-fw"})}),t.jsx(_e,{button:t.jsxs("span",{className:"text-nowrap",children:[t.jsx("i",{className:"fa fa-plus",title:"Launch a new tiling scan"})," New Scan"]}),disabled:o===null,options:{tags:["tomo-tiling-roi"],providers:{metadata:{datacollections:{namespace:"tilingview"}}}},additionalFormData:c})]})]})}function os(e){const{scanRoi:o,clearScanRoi:n,mouseModeInteraction:s,tomoConfigId:a}=e,{mouseMode:i,setOrResetMouseMode:l}=s,r=i==="create-tiling-roi",c=g.useCallback(()=>{if(o===null)return;const m=de.getState().hardware,d=pe(m,a),{sampleStage:x}=d,h=(x==null?void 0:x.properties.detector_center)??[0,0],f=h[0]??0,y=h[1]??0;return{x:V(o.x+f,3),y:V(o.y+f,3),z:V(o.z+y,3)}},[o,a]);return t.jsxs(Ee,{direction:"horizontal",children:[t.jsx("div",{className:"text-dark p-2",children:"Tomo:"}),t.jsxs(E,{className:e.className,children:[t.jsx(N,{variant:r?"primary":"secondary",title:"Initialize the location of the ROI",onClick:()=>{l("create-tiling-roi")},children:t.jsx("i",{className:"fa fam-roi-new fa-fw"})}),t.jsx(N,{variant:"secondary",title:"Initialize the location of the ROI",onClick:()=>{n()},disabled:o===null,children:t.jsx("i",{className:"fa fa-trash-can fa-fw"})}),t.jsx(_e,{button:t.jsxs("span",{className:"text-nowrap",children:[t.jsx("i",{className:"fa fa-plus",title:"Launch a new tiling scan"})," New Scan"]}),disabled:o===null,options:{tags:["tomo-tomo-roi"],providers:{metadata:{datacollections:{namespace:"tilingview"}}}},additionalFormData:c})]})]})}function ns(e){const{zseriesRoi:o,clearZseriesRoi:n,mouseModeInteraction:s,tomoConfigId:a}=e,{mouseMode:i,setOrResetMouseMode:l}=s,r=i==="create-tiling-roi",c=g.useCallback(()=>{if(o===null)return;const m=de.getState().hardware,d=pe(m,a),{sampleStage:x,tomoDetector:h,detector:f}=d,y=(x==null?void 0:x.properties.detector_center)??[0,0],v=y[0]??0,b=y[1]??0,p=Math.sign(o.zstop-o.zstart),j=Ve(h,f);if(j===null)return;const M=j[1]*.5,S=o.zstart+b+p*M,C=o.zstop+b-p*M,D=C-S;return{x:V(o.x+v,3),y:V(o.y+v,3),z_start:V(S,3),z_stop:V(C,3),z_height:V(Math.abs(D)+j[1],3),z_direction:p>0?"Down":"Up"}},[o,a]);return t.jsxs(Ee,{direction:"horizontal",children:[t.jsx("div",{className:"text-dark p-2",children:"Zseries:"}),t.jsxs(E,{className:e.className,children:[t.jsx(N,{variant:r?"primary":"secondary",title:"Initialize the location of the ROI",onClick:()=>{l("create-tiling-roi")},children:t.jsx("i",{className:"fa fam-roi-new fa-fw"})}),t.jsx(N,{variant:"secondary",title:"Initialize the location of the ROI",onClick:()=>{n()},disabled:o===null,children:t.jsx("i",{className:"fa fa-trash-can fa-fw"})}),t.jsx(_e,{button:t.jsxs("span",{className:"text-nowrap",children:[t.jsx("i",{className:"fa fa-plus",title:"Launch a new tiling scan"})," New Scan"]}),disabled:o===null,options:{tags:["tomo-zseries-roi"],providers:{metadata:{datacollections:{namespace:"tilingview"}}}},additionalFormData:c})]})]})}function ss(e){const{editScanRoi:o,setEditScanRoi:n}=e,s=g.useRef(null),a=g.useRef(null),i=g.useRef(null);function l(r){n(c=>c===r?null:r)}return t.jsxs(t.Fragment,{children:[t.jsxs(E,{className:e.className,children:[t.jsx(N,{ref:s,variant:o==="tiling"?"primary":"secondary",title:"ROI for tiling scan",onClick:()=>{l("tiling")},children:t.jsx("i",{className:"fa fam-roi-rect-tile fa-fw fa-lg"})}),t.jsx(N,{ref:a,variant:o==="scan"?"primary":"secondary",title:"ROI for tomo scan",onClick:()=>{l("scan")},children:t.jsx("i",{className:"fa fam-roi-rect fa-fw fa-lg"})}),t.jsx(N,{ref:i,variant:o==="zseries"?"primary":"secondary",title:"ROI for zseries scan",onClick:()=>{l("zseries")},children:t.jsx("i",{className:"fa fam-roi-rect-tile-v fa-fw fa-lg"})})]}),t.jsx(Re,{show:o==="tiling",placement:"bottom",container:s.current,target:s.current,containerPadding:20,children:t.jsx(ce,{id:"popover-tiling-contained",children:t.jsx(ts,{...e,className:void 0})})}),t.jsx(Re,{show:o==="scan",placement:"bottom",container:a.current,target:a.current,containerPadding:20,children:t.jsx(ce,{id:"popover-scan-contained",children:t.jsx(os,{...e,className:void 0})})}),t.jsx(Re,{show:o==="zseries",placement:"bottom",container:i.current,target:i.current,containerPadding:20,children:t.jsx(ce,{id:"popover-zseries-contained",children:t.jsx(ns,{...e,className:void 0})})})]})}function is(e,o){if(o===void 0)return[];const n=[];return Object.keys(o).map(a=>[a,o[a].tomo_detector_id]).forEach(a=>{const[i,l]=a,r=re(e,l),c=re(e,`${l}.detector`);if(r===null||c===null){console.debug(`${l} not there`);return}if(!no(c)||!so(c)||!r.properties.state||!r.properties.sample_pixel_size_mode)return;function u(){return!r||!r.online||r.properties.state==="OFFLINE"?"DETECTOR_OFFLINE":"READY"}const m=u();if(r.properties.sample_pixel_size_mode==="USER")r.properties.user_sample_pixel_size!==null&&n.push({detector:i,state:m,size:c.properties.size,userPixelSize:r.properties.user_sample_pixel_size});else{const x=re(e,`${l}.optic`);if(x===null){console.debug(`${r.properties.optic} not there`);return}if(!x.properties.available_magnifications){console.debug(`${r.properties.optic} no magnifications`);return}x.properties.available_magnifications.forEach(h=>{n.push({detector:i,state:m,size:r.properties.actual_size,autoPixelSize:{magnification:h,cameraPixelSize:r.properties.camera_pixel_size}})})}}),n}function as(){const e=oo(),o=de(n=>n.hardware);return g.useMemo(()=>is(o,e),[o,e])}function Tt(e,o){return[o[0]*e.size[0]*.001,o[1]*e.size[1]*.001]}function Ft(e){if(e.userPixelSize!==void 0)return[e.userPixelSize,e.userPixelSize];if(e.autoPixelSize!==void 0){const o=e.autoPixelSize.magnification,n=e.autoPixelSize.cameraPixelSize;return[n[0]/o,n[1]/o]}throw new Error("Unsupported TomoAvailableFieldOfView state")}function rs(e){const{eventKey:o,isSelected:n,data:s}=e,a=Ft(s),i=Tt(s,a);function l(){if(s.userPixelSize!==void 0)return"user";if(s.autoPixelSize!==void 0)return`×${s.autoPixelSize.magnification}`;throw new Error("Unsupported TomoAvailableFieldOfView state")}return t.jsxs(F.Item,{eventKey:o,children:[t.jsxs("div",{children:[s.detector," ",l()]}),t.jsxs("div",{className:"fw-bold",children:[i[0],"mm ",a[0],"µm"]})]})}function cs(e){const{as:o=void 0,onSelect:n,value:s,variant:a}=e,i=as();function l(u){if(u===null)return"No detector/optic selected";function m(){return u===null?"":u.magnification===null?"user":`×${u.magnification}`}return`${u.detector} ${m()} ${u.pixelSize[0]}µm ${u.fov[0]}mm`}const r=l(s);function c(u){var y;if(u===null){n(null);return}const m=Number.parseInt(u),d=i[m];d.size;const x=Ft(d),h=Tt(d,x),f={detector:d.detector,magnification:((y=d.autoPixelSize)==null?void 0:y.magnification)??null,fov:h,pixelSize:x};n(f)}return t.jsx(Go,{as:o,title:r,id:"bg-vertical-dropdown-3",onSelect:c,variant:a,children:i.map((u,m)=>{var x;const d=s!==null&&u.detector===s.detector&&(((x=u.autoPixelSize)==null?void 0:x.magnification)??null)===s.magnification;return t.jsx(rs,{eventKey:m,isSelected:d,data:u},m)})})}function ls(e){return t.jsx(cs,{...e})}function Pe(e){return e<9?`0${e}`:e}function ds(e){const n=Date.now()-e.valueOf();if(n<50*1e3)return"Few seconds ago";if(n<80*1e3)return"1 minute ago";if(n<90*60*1e3)return`${Math.round(n/6e4)} minutes ago`;if(n<7*24*60*60*1e3){const s=new Date;if(e.getDate()===s.getDate())return`Today at ${e.getHours()}:${Pe(e.getMinutes())}`;const a=new Date(s);if(a.setDate(a.getDate()-1),e.getDate()===a.getDate())return`Yesterday at ${e.getHours()}:${Pe(e.getMinutes())}`;const i=new Date(s);if(i.setDate(i.getDate()-s.getDay()),i.setHours(0),i.setMinutes(0),i.setSeconds(0),i.setMilliseconds(0),e>=i)return`${e.toLocaleString("default",{weekday:"long"})} at ${e.getHours()}:${Pe(e.getMinutes())}`}return e.toLocaleDateString()}function us(e){const{imageTiling:o,isSelected:n}=e,s=n?"fa fa-fw fa-dot-circle-o":"fa fa-fw fa-circle-o",a=o.status==="done"?"success":"warning",i=new Date(Date.parse(o.create_time));return t.jsxs(F.Item,{className:"d-flex",style:{alignItems:"center"},eventKey:o.id,active:n,children:[t.jsx("i",{className:s})," ",t.jsx("span",{className:"ms-2 me-auto pr-2",title:i.toLocaleString(),children:ds(i)})," ",t.jsx(bt,{className:"me-2",bg:a,children:o.status.toUpperCase()})," ",t.jsx(N,{size:"sm",variant:"danger",onClick:l=>{l.stopPropagation(),e.onDelete(o.id)},children:t.jsx("i",{className:"fa fa-fw fa-trash"})})]})}function ms(e){const{as:o=void 0,onSelect:n,selected:s,variant:a,tomovisService:i}=e,l=i.imageTilings;return t.jsxs(F,{className:`me-1 ${e.dropDirection==="up"?"dropup":""}`,as:o,onSelect:r=>{n(r)},onToggle:r=>{r&&i.updateImageTilings()},children:[t.jsxs(F.Toggle,{id:"dropdown-basic",variant:a,title:s?`Tiling selected: ${s}`:"No tiling selected",children:[t.jsx("i",{className:"fa fa-th fa-fw"}),(s===null||l.length===0)&&t.jsx("div",{className:"indicator",children:t.jsx("i",{className:"fa fa-xs fa-circle text-warning",title:"No tiling selected"})})]}),t.jsxs(F.Menu,{className:"dropdown-menu-center",children:[l.length===0&&t.jsx(F.Item,{disabled:!0,children:"No tiling available"}),l.map((r,c)=>{const u=s===r.id;return t.jsx(us,{isSelected:u,imageTiling:r,onDelete:m=>{i.deleteImageTiling(m),u&&n(null)}},c)})]})]})}const jt=W("daiquiri.components.tomo.tiling.ActualDetectorLocation");function pt(e){var I;const{detectorConfig:o,projRotation:n,clockWiseRotation:s}=e;if(Ct({statistics:(I=e.detectorArray)==null?void 0:I.statistics,...o}),e.detectorArray===null)return t.jsx(t.Fragment,{});const{displayArray:a,imagePosition:i,detectorSize:l,imagePixelSize:r,szPosition:c,imageSomegaPosition:u,detectorCenterY:m,detectorCenterZ:d}=e.detectorArray;if(c===null||l===null||r===null||u===null)return jt("Skipped: one of imagePosition, szPosition, detectorSize, imagePixelSize, imageSomegaPosition is missing."),t.jsx(t.Fragment,{});const x=(m==null?void 0:m.to("mm").scalar)??0,h=(d==null?void 0:d.to("mm").scalar)??0,f=c.to("mm").scalar,y=i?i.to("mm").scalar:0,v=u.scalar*(s?1:-1),b=r.to("mm").scalar,p=.01;function j(R,_){const $=(R-_)%360;return $<0?360+$:$}const M=j(v,n),S=M<p||M>360-p,C=M>180-p&&M<180+p;if(!S&&!C)return jt(`Skipped: rot ${v} does not match to the projRotation ${n}.`),t.jsx(t.Fragment,{});const D=S?-1:1;return t.jsx(Po,{values:a,domain:o.scaleDomain,colorMap:o.colorMap,invertColorMap:o.invertColorMap,scaleType:o.scaleType,position:[-D*(y-x),f-h,2],scale:[D*b,b,1],size:l})}function xs(e){const{resetZoomEnabled:o,actions:n}=e;return t.jsxs(F,{as:E,children:[t.jsx(N,{title:"Reset zoom (sample stage overview)",variant:"secondary",disabled:!o,onClick:()=>{n.resetZoom()},children:t.jsx("i",{className:"fa fa-expand fa-fw fa-lg"})}),t.jsx(F.Toggle,{split:!0,id:"dropdown-split-basic",variant:"secondary"}),t.jsxs(F.Menu,{children:[t.jsx(F.Item,{onClick:()=>{n.setScale(1)},children:"×1 (overview)"}),t.jsx(F.Item,{onClick:()=>{n.setScale(2)},children:"×2"}),t.jsx(F.Item,{onClick:()=>{n.setScale(10)},children:"×10"}),t.jsx(F.Item,{onClick:()=>{n.setScale(100)},children:"×100"})]})]})}function fs(){const e=qo({name:"tomo/tilingcolormap",lut:"Greys"}),[o,n]=G("tomo/tilingview/layout-view","front-side"),[s,a]=G("tomo/tilingview/axes",!0),[i,l]=G("tomo/tilingview/colorbar-visible",!0),[r,c]=G("tomo/tilingview/crosshair",!1),[u,m]=G("tomo/tilingview/toolbarlocation","top"),[d,x]=G("tomo/tilingview/detectordisplayed",!1);return{layoutView:o,setLayoutView:n,colorbarVisible:i,setColorbarVisible:l,displayAxes:s,setDisplayAxes:a,crossHair:r,setCrossHair:c,toolbarLocation:u,setToolbarLocation:m,...e,isDetectorDisplayed:d,setDetectorDisplayed:x}}function gs(e,o){return e===o?"primary":"secondary"}function U(e){return t.jsx(N,{variant:gs(e.var,e.value),onClick:()=>{e.setter(e.value)},className:"text-nowrap",size:"sm",children:e.children})}function hs(e){const{as:o=void 0,variant:n="secondary",config:s}=e;return t.jsxs(F,{as:o,className:`${e.dropDirection==="up"?"dropup":""}`,children:[t.jsx(F.Toggle,{id:"dropdown-basic",variant:n,className:"d-flex align-items-center",children:t.jsx("i",{className:"fa fa-sliders fa-fw fa-lg"})}),t.jsx(F.Menu,{className:"dropdown-menu-center",children:t.jsx("div",{className:"ms-1 me-1",style:{minWidth:"300px"},children:t.jsxs(ve,{children:[t.jsxs(O,{children:[t.jsx(L,{className:"my-auto",children:"Display axes"}),t.jsx(L,{xs:7,children:t.jsxs(E,{children:[t.jsx(U,{var:s.displayAxes,value:!0,setter:s.setDisplayAxes,children:"Yes"}),t.jsx(U,{var:s.displayAxes,value:!1,setter:s.setDisplayAxes,children:"No"})]})})]}),t.jsxs(O,{className:"mt-1",children:[t.jsx(L,{className:"my-auto",children:"Layout"}),t.jsx(L,{xs:7,children:t.jsxs(E,{children:[t.jsx(U,{var:s.layoutView,value:"front",setter:s.setLayoutView,children:"Front"}),t.jsx(U,{var:s.layoutView,value:"side",setter:s.setLayoutView,children:"Side"}),t.jsx(U,{var:s.layoutView,value:"front-side",setter:s.setLayoutView,children:"Both"})]})})]}),t.jsxs(O,{className:"mt-1",children:[t.jsx(L,{className:"my-auto",children:"Color bar"}),t.jsx(L,{xs:7,children:t.jsxs(E,{children:[t.jsx(U,{var:s.colorbarVisible,value:!0,setter:s.setColorbarVisible,children:"Displayed"}),t.jsx(U,{var:s.colorbarVisible,value:!1,setter:s.setColorbarVisible,children:"Hide"})]})})]}),t.jsxs(O,{className:"mt-1",children:[t.jsx(L,{className:"my-auto",children:"Crosshair"}),t.jsx(L,{xs:7,children:t.jsxs(E,{children:[t.jsx(U,{var:s.crossHair,value:!0,setter:s.setCrossHair,children:"Yes"}),t.jsx(U,{var:s.crossHair,value:!1,setter:s.setCrossHair,children:"No"})]})})]}),t.jsxs(O,{className:"mt-1",children:[t.jsx(L,{className:"my-auto",children:"Toolbar"}),t.jsx(L,{xs:7,children:t.jsxs(E,{children:[t.jsx(U,{var:s.toolbarLocation,value:"top",setter:s.setToolbarLocation,children:"Top"}),t.jsx(U,{var:s.toolbarLocation,value:"bottom",setter:s.setToolbarLocation,children:"Bottom"})]})})]})]})})})]})}const ys=io()(ao(e=>({setFrontViewpoint:o=>{const{center:n,scale:s}=o;e({y:n.x,z:n.y,scale:s.x})},setSideViewpoint:o=>{const{center:n,scale:s}=o;e({x:n.x,z:n.y,scale:s.x})}}),{name:"tomotiling-viewpoint",storage:ro(()=>sessionStorage)}));function vs(){const{x:e,y:o,z:n,scale:s,setFrontViewpoint:a,setSideViewpoint:i}=ys();let l;Number.isFinite(o)&&Number.isFinite(n)&&Number.isFinite(s)&&(l={center:new k(o,n,0),scale:new k(s,s,1)});let r;return Number.isFinite(e)&&Number.isFinite(n)&&Number.isFinite(s)&&(r={center:new k(e,n,0),scale:new k(s,s,1)}),{frontViewpoint:l,setFrontViewpoint:a,sideViewpoint:r,setSideViewpoint:i}}function js(e){const{toolbarLocation:o}=e;return t.jsxs("div",{className:e.className,style:e.style,children:[o==="top"&&e.toolbar,e.children,o==="bottom"&&e.toolbar]})}W("daiquiri.components.tomo.TomoTilingtiling");function ps(){const e=g.useRef(null),o=g.useRef(null);function n(i,l){if(e.current){const{getCameraViewpoint:r,updateCameraViewpoint:c}=e.current,u=r();c({center:new k(u.center.x,i.y),scale:l})}}function s(i,l){if(o.current){const{getCameraViewpoint:r,updateCameraViewpoint:c}=o.current,u=r();c({center:new k(u.center.x,i.y),scale:l})}}const a=g.useMemo(()=>({resetZoom:()=>{var i,l;(i=e.current)==null||i.resetZoom(),(l=o.current)==null||l.resetZoom()},setScale:i=>{var l,r;(l=e.current)==null||l.setScale(1/i),(r=o.current)==null||r.setScale(1/i)}}),[e,o]);return{handleFrameFront:s,handleFrameSide:n,frontRef:e,sideRef:o,actions:a}}function Ss(e){const{actions:o,tasks:n,options:s}=e,{showrois:a=!0,showlaunchscan:i=!0,tomoconfig:l}=s,r=co(),[c,u]=g.useState(null),m=zt(),d=fs(),x=lo(l??""),[h,f]=G("tomo/tilingroi/roi",null),[y,v]=G("tomo/scanroi/roi",null),[b,p]=G("tomo/zseriesroi/roi",null),[j,M]=G("tomo/tilingview/refreshperiod",30),{frontViewpoint:S,setFrontViewpoint:C,sideViewpoint:D,setSideViewpoint:I}=vs(),R=uo(),{tomovis_url:_,tomovis_proxy_url:$}=R,B=Ko(_,$),z=Uo(),P=en(B,r,3e4),{apiFront:Q,apiSide:oe,histogram:ue,tilingBoxFront:Et,tilingBoxSide:Lt,invalidate:Ot,lazyRefresh:$e}=Jo(B,c),we=Ro(ue);Ct({statistics:we,...d}),g.useEffect(()=>{let q=null;return P.state==="READY"?$e():P.state==="PROCESSING"&&j&&(q=setInterval(()=>{$e()},j*1e3)),()=>{q&&clearInterval(q)}},[P.state,j]);const J=Co("zoom"),{mouseMode:be,resetMouseMode:At}=J,Be=Fe(x),_t=g.useCallback(()=>Se(Be),[Be]),He=mo(`${l}.flat_motion`),[Ge,Ye]=yn({getCenter:_t}),Vt=Zo({sampleStageRefs:x}),ze=Wo({detector:Vt,sampleStageRefs:x,profile:z.profile,normalization:z.scaleType,autoscale:z.autoscale,autoscaleMode:z.autoscaleMode,domain:z.scaleDomain,enabled:d.isDetectorDisplayed,minRefreshPeriod:.5}).data;g.useEffect(()=>{P.lastReadyImageTiling&&u(P.lastReadyImageTiling)},[P.lastReadyImageTiling]),g.useEffect(()=>{!m&&be==="move-motors"&&At()},[be,m]);const[me,$t]=G("tomo/tilingroi/fov",null),[Ce,Bt]=G("tomo/tilingmarker/selection","primary"),[Me,Ht]=g.useState(null),ne=ps(),Ue=g.useCallback((q,xe,qe)=>{const Gt=de.getState().hardware,se=pe(Gt,l),{sampleStage:De}=se,Xe=(De==null?void 0:De.properties.detector_center)??[0,0],Qe=Xe[0]??0,Yt=Xe[1]??0,Je=se.sy?K(se.sy):0;function Ut(){return se.sampu===null||se.sampv===null?[void 0,void 0]:[q===null?void 0:new H(q-Je+Qe,"mm"),xe===null?void 0:new H(xe-Je+Qe,"mm")]}const[Zt,Wt]=Ut();return{sz:qe===null?void 0:new H(qe+Yt,"mm"),sampu:Zt,sampv:Wt}},[]),ee=d.toolbarLocation==="top"?"down":"up",Ze=xo((x==null?void 0:x.somega)??null),We=Ze?St(Ze):!0;return t.jsx(js,{className:"w-100 h-100",style:{flex:"1 1 0%",display:"flex",flexDirection:"column"},toolbarLocation:d.toolbarLocation,toolbar:t.jsxs(Mo,{align:"center",style:{zIndex:1},children:[t.jsx(Do,{mouseModeInteraction:J}),t.jsx(xs,{resetZoomEnabled:!0,actions:ne.actions}),t.jsx(ie,{}),t.jsx(Bo,{mouseModeInteraction:J,dropDirection:ee}),t.jsx(es,{mouseModeInteraction:J,showRoiTools:a,markerName:Ce,onSelectMarkerName:Bt,dropDirection:ee}),t.jsx(Yo,{variant:d.isDetectorDisplayed?"primary":"secondary",isInverted:z.invertColorMap,onSelectInvertion:z.setInvertColorMap,isDisplayed:d.isDetectorDisplayed,onSelectDisplayed:d.setDetectorDisplayed,lut:z.colorMap,onSelectLut:z.setColorMap,norm:z.scaleType,onSelectNorm:z.setScaleType,autoscale:z.autoscale,onSelectAutoscale:z.setAutoscale,autoscaleMode:z.autoscaleMode,onSelectAutoscaleMode:z.setAutoscaleMode,profile:z.profile,onSelectProfile:z.setProfile,array:ze,dropDirection:ee}),a&&t.jsx(ls,{value:me,onSelect:$t,variant:be==="create"?me===null?"danger":"primary":"secondary"}),t.jsx(ie,{}),t.jsx(Jn,{className:"me-1 d-none d-lg-block"}),i&&t.jsx(ss,{className:"d-none d-lg-block",mouseModeInteraction:J,editScanRoi:Me,setEditScanRoi:Ht,tomoConfigId:l,tilingRoi:h,clearTilingRoi:()=>{f(null)},zseriesRoi:b,clearZseriesRoi:()=>{p(null)},scanRoi:y,clearScanRoi:()=>{v(null)}}),t.jsx(ie,{}),t.jsx(Qn,{className:"me-1 d-none d-lg-block",tomovisRestService:B,tomovisService:P}),t.jsx(ms,{variant:"secondary",tomovisService:P,selected:c,onSelect:u,dropDirection:ee}),t.jsx(N,{variant:"secondary",disabled:c===null,title:P.state==="PROCESSING"?`Auto refresh the tiling every ${j.toFixed(1)} seconds`:"Reload current tiling",onClick:Ot,children:t.jsx("i",{className:`fa fa-rotate-right fa-solid ${P.state==="PROCESSING"?"fa-spin":""}`})}),t.jsx(ie,{}),t.jsx(Qo,{lut:d.colorMap,onSelectLut:d.setColorMap,norm:Ao(d.scaleType),autoscale:d.autoscale,autoscaleMode:d.autoscaleMode,onSelectNorm:d.setScaleType,isInverted:d.invertColorMap,onSelectInvertion:d.setInvertColorMap,onSelectAutoscale:d.setAutoscale,onSelectAutoscaleMode:d.setAutoscaleMode,dropDirection:ee}),t.jsx(ko,{disabled:we===void 0,...d}),t.jsx(Xo,{disabled:we===void 0,histogram:ue,...d}),t.jsx(ie,{}),t.jsx(hs,{config:d,dropDirection:ee})]}),children:t.jsxs("div",{style:{flex:"1 1 auto",display:"flex",margin:0,minHeight:0},children:[(d.layoutView==="front"||d.layoutView==="front-side")&&t.jsxs(vt,{config:d,projRotation:0,api:Q,tilingBox:Et,actions:o,computeSampleStageAtPlotLocation:Ue,tasks:n,sampleStage:x,operator:m,domain:d.scaleDomain,colorMap:d.colorMap,invertColorMap:d.invertColorMap,scaleType:d.scaleType,roiFov:me,markerName:Ce,mouseModeInteraction:J,markers:Ge,setMarker:Ye,tilingRoi:h,setTilingRoi:f,scanRoi:y,setScanRoi:v,zseriesRoi:b,setZseriesRoi:p,editScanRoi:Me,tomoFlatMotion:He,children:[d.isDetectorDisplayed&&t.jsx(pt,{clockWiseRotation:We,projRotation:0,detectorArray:ze,detectorConfig:z}),t.jsx(nt,{ref:ne.frontRef,onVisViewpointChange:ne.handleFrameFront}),t.jsx(ct,{viewpoint:S,setViewpoint:C}),t.jsx(dt,{children:t.jsx(ot,{guides:d.crossHair?"both":void 0,renderTooltip:(q,xe)=>t.jsx(t.Fragment,{})})})]}),d.layoutView==="front-side"&&!d.displayAxes&&t.jsx("div",{style:{minWidth:"1em"},className:"p-2 bg-light"}),(d.layoutView==="side"||d.layoutView==="front-side")&&t.jsxs(vt,{config:d,projRotation:-90,api:oe,tilingBox:Lt,actions:o,computeSampleStageAtPlotLocation:Ue,tasks:n,sampleStage:x,operator:m,domain:d.scaleDomain,colorMap:d.colorMap,invertColorMap:d.invertColorMap,scaleType:d.scaleType,roiFov:me,markerName:Ce,mouseModeInteraction:J,markers:Ge,setMarker:Ye,tilingRoi:h,setTilingRoi:f,scanRoi:y,setScanRoi:v,zseriesRoi:b,setZseriesRoi:p,editScanRoi:Me,tomoFlatMotion:He,children:[d.isDetectorDisplayed&&t.jsx(pt,{clockWiseRotation:We,projRotation:-90,detectorArray:ze,detectorConfig:z}),t.jsx(nt,{ref:ne.sideRef,onVisViewpointChange:ne.handleFrameSide}),t.jsx(ct,{viewpoint:D,setViewpoint:I}),t.jsx(dt,{children:t.jsx(ot,{guides:d.crossHair?"both":void 0,renderTooltip:(q,xe)=>t.jsx(t.Fragment,{})})})]}),d.colorbarVisible&&t.jsx(bo,{domain:d.scaleDomain,scaleType:d.scaleType,colorMap:d.colorMap,invertColorMap:d.invertColorMap,withBounds:!0})]})})}function ws(){return go(e=>e.scanTasks)}function bs(e){const o=fo(),n=ws();return t.jsx(Ss,{...e,actions:o,tasks:n})}function ai(e){const{yamlNode:o,showrois:n,showlaunchscan:s,tomoconfig:a,...i}=e;ho(o,"tomoconfig",a),tt(o,"showrois",n),tt(o,"showlaunchscan",s),yo(o,i);const l={showrois:n,showlaunchscan:s,tomoconfig:a};return t.jsx(bs,{options:l})}export{ai as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var Te=Object.defineProperty;var Ie=(r,t,e)=>t in r?Te(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var w=(r,t,e)=>(Ie(r,typeof t!="symbol"?t+"":t,e),e);import{r as C,j as n,R as $,C as T,B as D,l as h,w as B,c as W,m as q,u as P,a as G,b as Re,d as Le,e as ee,f as H,g as I,N as ze,F as S,I as U,T as j,h as O,i as Q,k as ie,n as fe,o as Ee,t as f,p as J,X as _,q as A,A as me,s as ge,E as Ne,v as Pe,P as k,x as Ae,S as De,y as F,M as Ye,z as Xe,D as We,G as _e,H as Ue}from"./index-b3c0133a.js";import{D as V}from"./DropdownButton-29cc265b.js";import{T as X,B as $e,u as Fe,S as te}from"./store-5d136a2c.js";import{f as g,C as Qe}from"./CanvasEnhancer-dd82c090.js";import{J as Ve}from"./jsmpeg-player.esm-5b64ab36.js";import{S as He}from"./ScanPlot1d-3c930b95.js";import{M as Ze,C as Be}from"./CompositeMap-c93f5466.js";import"./types-c366a377.js";import"./index-a9bb7636.js";import"./H5WebCurvePlot-61b08211.js";function qe(r){const{hide:t=!1}=r,e=()=>{r.onChange({sampleimageid:r.sampleimageid,hide:!t})};return n.jsx(D,{className:"ms-auto",title:t?"Show":"Hide",size:"sm",onClick:e,variant:t?"secondary":"primary",children:n.jsx("i",{className:`fa fa-${t?"eye-slash":"eye"}`})})}function Ge(r){const[t,e]=C.useState(!0),s=()=>{h.each(r.images,i=>{r.actions.updateImage({sampleimageid:i.sampleimageid,hide:t})}),e(!t)};return n.jsx("div",{className:"d-grid gap-2 mb-1",children:n.jsxs(V,{align:"end",size:"sm",title:n.jsxs(n.Fragment,{children:[n.jsx("i",{className:"fa fa-eye me-1"}),"Visibility"]}),className:"image-selection",children:[n.jsxs($,{children:[n.jsx(T,{xs:10,children:"Show/Hide All Images"}),n.jsx(T,{xs:2,children:n.jsx(D,{size:"sm",onClick:s,variant:t?"secondary":"primary",className:"ms-auto d-inline-block",children:n.jsx("i",{className:`fa fa-${t?"eye-slash":"eye"}`})})})]}),h.map(r.images,i=>n.jsxs($,{children:[n.jsx(T,{xs:2,children:i.sampleimageid}),n.jsx(T,{xs:4,children:i.offsetx}),n.jsx(T,{xs:4,children:i.offsety}),n.jsx(T,{xs:2,children:n.jsx(qe,{...i,onChange:r.actions.updateImage})})]},i.sampleimageid))]})})}const Je=(r,t)=>({images:t.providers.metadata.images.selector("results",r)}),Ke=(r,t)=>({actions:{updateImage:e=>t.providers.metadata.images.updateLocal(e)}}),et=B({metadata:q})(W(Je,Ke)(Ge));function we(){const[r,t]=P("2dview/currentAction","pan"),[e,s]=P("2dview/disableOrigin",!1),[i,o]=P("2dview/clampOrigin",!0),[a,c]=P("2dview/clampTarget",""),[l,d]=P("2dview/sourceUrl",""),[p,m]=P("2dview/viewport",{}),[x,u]=P("2dview/zoom",1);return{currentAction:r,setAction:t,disableOrigin:e,setDisableOrigin:s,clampOrigin:i,setClampOrigin:o,clampTarget:a,setClampTarget:c,sourceUrl:l,setSourceUrl:d,viewport:p,setViewport:m,zoom:x,setZoom:u}}function tt(r){const t=C.useRef(null),e=C.useRef(null),s=C.useRef(),i=C.useRef(null),[o,a]=C.useState(!1),c=C.useCallback(()=>{var d,p,m,x;a(!0),(d=i.current)!=null&&d.checkValidity()&&t.current&&e.current&&(r.setQuantization([Number.parseFloat((p=t.current)==null?void 0:p.value)*1e3,Number.parseFloat((m=e.current)==null?void 0:m.value)*1e3]),(x=s.current)==null||x.close())},[]),l=C.useCallback(d=>{var p;i.current=d,(p=t.current)==null||p.focus()},[]);return n.jsx(ie,{id:"setQuantization",title:"Set Quantization",ref:s,buttonProps:{className:"me-1 d-inline",size:"sm"},buttons:n.jsx(D,{onClick:c,children:"Set Quantization"}),button:n.jsx(n.Fragment,{children:n.jsx("i",{className:"fa fa-plus"})}),children:n.jsx(S,{ref:l,validated:o,children:n.jsxs(S.Group,{as:$,children:[n.jsx(S.Label,{column:!0,sm:3,children:"Quantization"}),n.jsx(T,{children:n.jsxs(U,{children:[n.jsx(S.Control,{ref:t,type:"number",step:"0.001",required:!0,onKeyDown:d=>d.key==="Enter"&&c()}),n.jsx(U.Text,{children:"µm"}),n.jsx(S.Control.Feedback,{type:"invalid",children:"Please provide a quantization in X"})]})}),n.jsx(T,{xs:1,className:"text-center",children:"x"}),n.jsx(T,{children:n.jsxs(U,{children:[n.jsx(S.Control,{ref:e,type:"number",step:"0.001",required:!0,onKeyDown:d=>d.key==="Enter"&&c()}),n.jsx(U.Text,{children:"µm"}),n.jsx(S.Control.Feedback,{type:"invalid",children:"Please provide a quantization in Y"})]})})]})})})}function st(r){var le,he,de,pe;const{currentSampleId:t}=G();C.useEffect(()=>{r.actions.fetchOriginSettings()},[]);const{currentAction:e,setAction:s,disableOrigin:i,setDisableOrigin:o,clampOrigin:a,setClampOrigin:c,clampTarget:l,setClampTarget:d,sourceUrl:p,setSourceUrl:m}=we();function x(b){e===b?s(""):(s(b),["roi","loi","poi","measure","move"].includes(b)&&r.actions.toggleCursor(!1))}const u=Re(),y=Le();function v(){r.actions.saveImage({sampleid:t}).catch(b=>{var M,ue;r.actions.addToast({type:"error",title:"Could not save image",text:((ue=(M=b.response)==null?void 0:M.data)==null?void 0:ue.error)||b.message})})}function L(){c(!a)}function E(){o(!i)}function Y(){r.actions.toggleCentreOnClick(!r.centreOnClick)}function z(b){const M=Number.parseInt(b.target.value,10);r.actions.changeDrawQuantize([M,M])}function ve(){r.actions.toggleDrawSnap(!r.drawSnap)}function ye(){r.actions.toggleMultiROI(!r.multiROI)}function Se(){r.actions.toggleClampLOI(!r.clampLOI)}function Ce(){r.cursor&&r.actions.setSourceHover({}),r.actions.toggleCursor(!r.cursor)}function Oe(){r.actions.saveCanvas()}function je(){r.actions.autoFocusImage()}function ae(b){r.actions.updateOriginSettings({[b]:!r.originSettings[b]})}function ne(b){m(b.target.value)}function re(b){d(b.target.value)}const ce={5e4:"50µm",25e3:"25µm",2e4:"20µm",1e4:"10µm",5e3:"5µm",1e3:"1µm",500:"500nm",200:"200nm",...Object.fromEntries(((de=(he=(le=r.config)==null?void 0:le.options)==null?void 0:he.extra_quantizations)==null?void 0:de.map(b=>{const M=H(b*I.pixelSize);return[b,`${ee(M.scalar,12)}${M.prefix}m`]}))||[])};C.useEffect(()=>{if(!r.drawQuantize){const b=r.config.options.default_quantization||5e3;r.actions.changeDrawQuantize([b,b])}},[]);const ke=r.drawQuantize?r.drawQuantize[0]===r.drawQuantize[1]:!0,K=r.drawQuantize?r.drawQuantize[0]!==r.drawQuantize[1]||!Object.keys(ce).includes(String(r.drawQuantize[0])):!1,N=K?H(r.drawQuantize[0]*I.pixelSize):null,Me=K?"custom":r.drawQuantize?r.drawQuantize[0]:void 0,R=h.find(r.sources,{origin:!0});return n.jsxs(ze,{bg:"cyan",className:"p-2",children:[n.jsxs(S,{className:"text-nowrap",children:[n.jsxs(U,{className:"d-inline",children:[n.jsx(j,{tooltip:"Enable draw quantisation",children:n.jsxs(S.Control,{className:"d-inline",style:{width:"auto"},as:"select",size:"sm",value:Me,onChange:z,children:[h.map(ce,(b,M)=>n.jsx("option",{value:M,children:b})),r.drawQuantize&&K&&N&&n.jsxs("option",{value:"custom",children:[ke?ee(N.scalar,12):`${N.scalar}x${ee(r.drawQuantize[1]*N.multiplier*I.pixelSize,12)}`,N==null?void 0:N.prefix,"m"]})]})}),n.jsx(tt,{setQuantization:r.actions.changeDrawQuantize})]}),n.jsx(j,{tooltip:"Snap to nearest object",children:n.jsx(X,{type:"checkbox",value:r.drawSnap?["1"]:void 0,onChange:ve,children:n.jsxs(O,{value:"1",size:"sm",className:" me-2",id:"snap",children:[n.jsx("i",{className:"fa fa-object-ungroup me-1"}),"Snap"]})})})]}),n.jsx(S,{children:n.jsxs($e,{children:[n.jsxs(X,{type:"radio",name:"action",value:e,onChange:x,className:"me-1",children:[n.jsxs(O,{value:"",size:"sm",id:"off",children:[n.jsx("i",{className:"fa fa-power-off me-1"}),"Off"]}),n.jsxs(O,{value:"mosaic",id:"mosaic",size:"sm",disabled:!u||y||!t,children:[n.jsx("i",{className:"fa fa-th me-1"}),"Mosaic"]}),r.config.options.import_reference&&n.jsxs(O,{value:"reference",id:"reference",size:"sm",disabled:!u||y||!r.selectedSampleActionId,children:[n.jsx("i",{className:"fa fa-map-marker me-1"}),"Ref"]}),n.jsxs(O,{value:"poi",size:"sm",id:"poi",disabled:!t,children:[n.jsx("i",{className:"fa fa-map-pin me-1"}),"POI"]}),n.jsxs(O,{value:"roi",id:"roi",size:"sm",disabled:!t,children:[n.jsx("i",{className:"fa fa-square-o me-1"}),"ROI",n.jsx(j,{tooltip:"Draw multiple ROIs",children:n.jsx(S.Check,{className:"d-inline ms-1",type:"checkbox",checked:r.multiROI,value:"1",onChange:ye})})]}),n.jsxs(O,{value:"loi",id:"loi",size:"sm",disabled:!t,children:[n.jsx("i",{className:"fa fa-long-arrow-right me-1"}),"LOI",n.jsx(j,{tooltip:"Clamp LOIs",children:n.jsx(S.Check,{className:"d-inline ms-1",type:"checkbox",checked:r.clampLOI,value:"1",onChange:Se})})]}),n.jsxs(O,{value:"measure",id:"measure",size:"sm",children:[n.jsx("i",{className:"fa fa-expand me-1"}),"Measure"]}),n.jsxs(O,{value:"pan",id:"pan",size:"sm",children:[n.jsx("i",{className:"fa fa-arrows me-1"}),"Pan"]}),n.jsxs(O,{value:"move",id:"move",size:"sm",disabled:!u||y,children:[n.jsx("i",{className:"fa fa-map-marker me-1"}),"Move",(r.originSettings.fine_fixed||r.originSettings.coarse_fixed)&&r.originSettings.config.allow_fixed_axes&&n.jsx(j,{tooltip:"One axis is currently fixed",children:n.jsx("div",{className:"bg-warning px-1 ml-1 rounded text-dark",children:n.jsx("i",{className:"fa fa-warning"})})})]})]}),r.originSettings.has_fine&&r.originSettings.config.allow_fixed_axes&&n.jsx(V,{size:"sm",title:"",children:n.jsxs(Q,{className:"pl-2 pr-2",children:[n.jsx(S.Check,{type:"switch",id:"fine-switch",label:"Fix Fine Axes",checked:r.originSettings.fine_fixed,onChange:()=>ae("fine_fixed")}),n.jsx(S.Check,{type:"switch",id:"coarse-switch",label:"Fix Coarse Axes",className:"text-nowrap",checked:r.originSettings.coarse_fixed,onChange:()=>ae("coarse_fixed")})]})}),r.config.options.centre_selection&&n.jsx(j,{tooltip:"Centre object on selection",children:n.jsx(X,{className:"me-1",type:"checkbox",value:r.centreOnClick?["1"]:void 0,onChange:Y,children:n.jsxs(O,{id:"center-selection",value:"1",size:"sm",children:[n.jsx("i",{className:"fa fa-align-center me-1"}),"Centre"]})})}),n.jsx(j,{tooltip:"Toggle showing cursor values and click to show",children:n.jsx(X,{type:"checkbox",value:r.cursor?["1"]:void 0,onChange:Ce,className:"ms-1 me-1",children:n.jsxs(O,{value:"1",id:"cursor",size:"sm",className:"text-center",children:[n.jsx("i",{className:"fa fa-crosshairs me-1"}),"Cursor"]})})}),n.jsx(V,{size:"sm",title:n.jsxs(n.Fragment,{children:[n.jsx("i",{className:"fa fa-video-camera me-1"})," Video"]}),className:"me-1",children:n.jsxs(Q,{className:"pl-2 pr-2",children:[n.jsx("div",{className:"d-grid gap-2 mb-1",children:R&&Object.keys(R.polylines).length>0&&n.jsxs("div",{className:"d-grid gap-2 mb-1 border bg-primary rounded p-1 text-light",children:[n.jsx(j,{tooltip:`${a?"Un-clamp":"Clamp"} the viewport to the video source (unclamp to pan)`,children:n.jsx(X,{type:"checkbox",value:a?["1"]:void 0,onChange:L,children:n.jsxs(O,{value:"1",size:"sm",className:"text-start",id:"clamp-viewport",children:[n.jsx("i",{className:`fa fa-fw me-1 ${a?"fa-lock":"fa-unlock"}`}),a?"Un-clamp":"Clamp"]})})}),r.originSettings.has_fine&&n.jsxs("div",{className:"bg-light text-primary rounded p-1",style:{fontSize:"0.7875rem"},children:[n.jsx(S.Check,{name:"clampTarget",checked:l==="",type:"radio",value:"",label:"video",onChange:re,className:"mb-0"}),Object.keys(R.polylines).filter(b=>b!=="limits").map(b=>n.jsx(S.Check,{name:"clampTarget",type:"radio",checked:l===b,value:b,label:b,onChange:re,className:"mb-0"}))]})]})}),((pe=R==null?void 0:R.additional_urls)==null?void 0:pe.length)>0&&n.jsxs("div",{className:"d-grid gap-2 mb-1 border bg-primary rounded p-1 text-light",children:[n.jsxs("div",{className:"mx-1",style:{fontSize:"0.7875rem"},children:[n.jsx("i",{className:"fa fa-fw me-1 fa-film"}),"Stream"]}),n.jsxs("div",{className:"bg-light text-primary rounded p-1",style:{fontSize:"0.7875rem"},children:[n.jsx(S.Check,{name:"sourceUrl",checked:p==="",type:"radio",value:"",label:"default",onChange:ne,className:"mb-0"}),R==null?void 0:R.additional_urls.map(b=>n.jsxs(n.Fragment,{children:[n.jsx("hr",{style:{margin:"0.1rem"}}),n.jsx(S.Check,{name:"sourceUrl",type:"radio",checked:p===b.name,value:b.name,label:b.name,onChange:ne,className:"mb-0"})]}))]})]}),r.config.options.autofocus&&n.jsx("div",{className:"d-grid gap-2 mb-1",children:n.jsx(j,{tooltip:"Autofocus the video source",children:n.jsxs(D,{size:"sm",onClick:je,disabled:!u||y,className:"text-start",children:[n.jsx("i",{className:"fa fa-fw fa-eye me-1"})," Autofocus"]})})}),n.jsx("div",{className:"d-grid gap-2 mb-1",children:n.jsx(j,{tooltip:`${i?"Enable":"Disable"} the video source`,children:n.jsx(X,{type:"checkbox",value:i?["1"]:void 0,onChange:E,children:n.jsxs(O,{value:"1",size:"sm",className:"text-start",id:"disable-video",children:[n.jsx("i",{className:"fa fa-fw fa-power-off me-1"}),i?"Enable":"Disable"]})})})})]})}),n.jsx(V,{size:"sm",title:n.jsxs(n.Fragment,{children:[n.jsx("i",{className:"fa fa-picture-o me-1"})," Images"]}),children:n.jsxs(Q,{className:"pl-2 pr-2",children:[n.jsx("div",{className:"d-grid gap-2 mb-1",children:n.jsx(j,{tooltip:"Save the current sample image",children:n.jsxs(D,{size:"sm",onClick:v,disabled:!t||r.pendingSaveImage,className:"text-start",children:[n.jsx("i",{className:"me-1 fa fa-camera"}),r.pendingSaveImage&&n.jsxs(n.Fragment,{children:["Saving ",n.jsx("i",{className:"fa fa-spin fa-spinner"})]}),!r.pendingSaveImage&&n.jsx(n.Fragment,{children:"Save"})]})})}),n.jsx("div",{className:"d-grid gap-2 mb-1",children:n.jsx(j,{tooltip:"Save the current canvas",children:n.jsxs(D,{size:"sm",onClick:Oe,disabled:!t||r.pendingSaveCanvas,className:"text-start",children:[n.jsx("i",{className:"me-1 fa fa-picture-o"}),r.pendingSaveCanvas&&n.jsxs(n.Fragment,{children:["Saving ",n.jsx("i",{className:"fa fa-spin fa-spinner"})]}),!r.pendingSaveCanvas&&n.jsx(n.Fragment,{children:"Canvas"})]})})}),n.jsx(et,{})]})})]})})]})}function be(r,t="real"){return e=>{const{fetch:s,invalidateAll:i}=fe(),{selectedSampleActionId:o}=Fe(),a={sampleactionid:o,type:t},c=Ee(te.getList,o?a:null),l=C.useCallback(async({x:d,y:p})=>{const m=c.rows&&c.rows.length>0?Math.max(...c.rows.map(u=>u.id)):0,x=await s(te.getList.push,{posx:d,posy:p,sampleactionid:o,type:t,id:m+1});return i(te.getList),x},[c]);return n.jsx(r,{...e,selectedSampleActionId:o,sampleActionPositions:c.rows,addSampleActionPosition:l})}}const it=(r,t)=>({centreOnClick:f.selector("centreOnClick",r),drawQuantize:f.selector("drawQuantize",r),drawSnap:f.selector("drawSnap",r),multiROI:f.selector("multiROI",r),clampLOI:f.selector("clampLOI",r),cursor:f.selector("cursor",r),pendingSaveImage:f.selector("pendingSaveImage",r),pendingSaveCanvas:f.selector("saveCanvas",r),config:J.selector("config",r,"imageviewer"),originSettings:t.providers.twod.origin.selector("results",r),sources:t.providers.twod.sources.selector("results",r)}),ot=(r,t)=>({actions:{toggleCentreOnClick:e=>f.dispatch("CENTRE_ON_CLICK",e),changeDrawQuantize:e=>f.dispatch("CHANGE_DRAW_QUANTIZE",e),toggleDrawSnap:e=>f.dispatch("TOGGLE_DRAW_SNAP",e),toggleMultiROI:e=>f.dispatch("TOGGLE_MULTI_ROI",e),toggleClampLOI:e=>f.dispatch("TOGGLE_CLAMP_LOI",e),toggleCursor:e=>f.dispatch("TOGGLE_CURSOR",e),saveImage:e=>f.dispatch("SAVE_IMAGE",e),saveCanvas:()=>f.dispatch("SAVE_CANVAS"),addToast:e=>J.dispatch("ADD_TOAST",e),autoFocusImage:()=>f.dispatch("AUTOFOCUS_IMAGE"),setSourceHover:e=>f.dispatch("SET_SOURCE_HOVER",e),fetchOriginSettings:()=>t.providers.twod.origin.fetch(),updateOriginSettings:e=>t.providers.twod.origin.update(e)}}),at=be(B({metadata:q,twod:f})(W(it,ot)(st))),nt=g.fabric.util.createClass(g.fabric.Image,{initialize:function(r){this.callSuper("initialize",r),this.first=!0,this.firstRender=!0,this.readyCallback=r.readyCallback,this.mcanvas=document.createElement("canvas"),this.mplayer=new Ve.Player(r.url,{canvas:this.mcanvas,videoBufferSize:1024*1024*4,audio:!1,onVideoDecode:this.onVideoDecode.bind(this),protocols:[],disableGl:!0}),r.autoplay&&this.mplayer.play()},onVideoDecode:function(){this.first&&(console.log("first video decode",this.mcanvas.width,this.mcanvas.height),this.mcanvas.width&&this.mcanvas.height&&(this.setSrc(this.mcanvas.toDataURL()),this.width=this.mcanvas.width,this.height=this.mcanvas.height,this.setCoords(),this.first=!1,this.readyCallback&&this.readyCallback()))},play:function(){this.mplayer.play()},stop:function(){this.mplayer.stop()},_renderFill:function(r){this.firstRender&&(this.setCoords(),this.firstRender=!1);const t=this._element;if(!t)return;const e=this.width,s=this.height,i=Math.min(t.naturalWidth||t.width,e*this._filterScalingX),o=Math.min(t.naturalHeight||t.height,s*this._filterScalingY),a=-e/2,c=-s/2,l=Math.max(0,this.cropX*this._filterScalingX),d=Math.max(0,this.cropY*this._filterScalingY);t&&r.drawImage(this.mcanvas,l,d,i,o,a,c,e,s)},dispose:function(r){console.log("JSMpegImage dispose"),this.mplayer&&this.mplayer.destroy(),this.mplayer=null,this.callSuper("dispose",r)}});class Z extends HTMLElement{constructor(){super(),this.DISCONNECT_TIMEOUT=5e3,this.RECONNECT_TIMEOUT=15e3,this.CODECS=["avc1.640029","avc1.64002A","avc1.640033","hvc1.1.6.L153.B0","mp4a.40.2","mp4a.40.5","flac","opus"],this.mode="webrtc,mse,hls,mjpeg",this._isConnected=!0,this.media="video,audio",this.background=!1,this.visibilityThreshold=0,this.visibilityCheck=!0,this.pcConfig={bundlePolicy:"max-bundle",iceServers:[{urls:"stun:stun.l.google.com:19302"}],sdpSemantics:"unified-plan"},this.wsState=WebSocket.CLOSED,this.pcState=WebSocket.CLOSED,this.video=null,this.ws=null,this.wsURL="",this.pc=null,this.connectTS=0,this.mseCodecs="",this.disconnectTID=0,this.reconnectTID=0,this.ondata=null,this.onmessage=null}set src(t){let e=t;typeof e!="string"&&(e=t.toString()),e.startsWith("http")?e=`ws${e.substring(4)}`:t.startsWith("/")&&(e=`ws${window.location.origin.substring(4)}${e}`),this.wsURL=e,this.onconnect()}play(){this.video.play().catch(()=>{this.video.muted||(this.video.muted=!0,this.video.play().catch(t=>{console.warn(t)}))})}send(t){this.ws&&this.ws.send(JSON.stringify(t))}codecs(t){return this.CODECS.filter(e=>this.media.indexOf(e.indexOf("vc1")>0?"video":"audio")>=0).filter(e=>t(`video/mp4; codecs="${e}"`)).join(",")}connectedCallback(){if(this.disconnectTID&&(clearTimeout(this.disconnectTID),this.disconnectTID=0),this.video){const t=this.video.seekable;t.length>0&&(this.video.currentTime=t.end(t.length-1)),this.play()}else this.oninit();this.onconnect()}disconnectedCallback(){this.background||this.disconnectTID||this.wsState===WebSocket.CLOSED&&this.pcState===WebSocket.CLOSED||(this.disconnectTID=setTimeout(()=>{this.reconnectTID&&(clearTimeout(this.reconnectTID),this.reconnectTID=0),this.disconnectTID=0,this.ondisconnect()},this.DISCONNECT_TIMEOUT))}oninit(){console.log("VIDEO oninit"),this.video=document.createElement("video"),this.video.controls=!1,this.video.playsInline=!0,this.video.preload="auto",this.video.style.display="block",this.video.style.width="100%",this.video.style.height="100%",this.append(this.video),this.video.addEventListener("error",e=>{console.warn(e),this.ws&&this.ws.close()});const t=window.navigator.userAgent.match(/Version\/(\d+).+Safari/);if(t){const e=t[1]<"13"?"mp4a.40.2":t[1]<"14"?"flac":"opus";this.CODECS.splice(this.CODECS.indexOf(e))}this.background||("hidden"in document&&this.visibilityCheck&&document.addEventListener("visibilitychange",()=>{document.hidden?this.disconnectedCallback():this._isConnected&&this.connectedCallback()}),"IntersectionObserver"in window&&this.visibilityThreshold&&new IntersectionObserver(s=>{s.forEach(i=>{i.isIntersecting?this._isConnected&&this.connectedCallback():this.disconnectedCallback()})},{threshold:this.visibilityThreshold}).observe(this))}onconnect(){return!this._isConnected||!this.wsURL||this.ws||this.pc?!1:(this.wsState=WebSocket.CONNECTING,this.connectTS=Date.now(),this.ws=new WebSocket(this.wsURL),this.ws.binaryType="arraybuffer",this.ws.addEventListener("open",()=>this.onopen()),this.ws.addEventListener("close",()=>this.onclose()),!0)}ondisconnect(){this.wsState=WebSocket.CLOSED,this.ws&&(this.ws.close(),this.ws=null),this.pcState=WebSocket.CLOSED,this.pc&&(this.pc.getSenders().forEach(t=>{t.track&&t.track.stop()}),this.pc.close(),this.pc=null),this.video.src="",this.video.srcObject=null}onopen(){this.wsState=WebSocket.OPEN,this.ws.addEventListener("message",e=>{if(typeof e.data=="string"){const s=JSON.parse(e.data);Object.keys(this.onmessage).forEach(i=>{this.onmessage[i](s)})}else this.ondata(e.data)}),this.ondata=null,this.onmessage={};const t=[];return this.mode.indexOf("mse")>=0&&("MediaSource"in window||"ManagedMediaSource"in window)?(t.push("mse"),this.onmse()):this.mode.indexOf("hls")>=0&&this.video.canPlayType("application/vnd.apple.mpegurl")?(t.push("hls"),this.onhls()):this.mode.indexOf("mp4")>=0&&(t.push("mp4"),this.onmp4()),this.mode.indexOf("webrtc")>=0&&"RTCPeerConnection"in window&&(t.push("webrtc"),this.onwebrtc()),this.mode.indexOf("mjpeg")>=0&&(t.length?this.onmessage.mjpeg=e=>{e.type!=="error"||e.value.indexOf(t[0])!==0||this.onmjpeg()}:(t.push("mjpeg"),this.onmjpeg())),t}onclose(){if(this.wsState===WebSocket.CLOSED)return!1;this.wsState=WebSocket.CONNECTING,this.ws=null;const t=Math.max(this.RECONNECT_TIMEOUT-(Date.now()-this.connectTS),0);return this.reconnectTID=setTimeout(()=>{this.reconnectTID=0,this.onconnect()},t),!0}onmse(){let t;if("ManagedMediaSource"in window){const e=window.ManagedMediaSource;t=new e,t.addEventListener("sourceopen",()=>{this.send({type:"mse",value:this.codecs(e.isTypeSupported)})},{once:!0}),this.video.disableRemotePlayback=!0,this.video.srcObject=t}else t=new MediaSource,t.addEventListener("sourceopen",()=>{URL.revokeObjectURL(this.video.src),this.send({type:"mse",value:this.codecs(MediaSource.isTypeSupported)})},{once:!0}),this.video.src=URL.createObjectURL(t),this.video.srcObject=null;this.play(),this.mseCodecs="",this.onmessage.mse=e=>{if(e.type!=="mse")return;this.mseCodecs=e.value;const s=t.addSourceBuffer(e.value);s.mode="segments",s.addEventListener("updateend",()=>{if(!s.updating&&o>0)try{const a=i.slice(0,o);s.appendBuffer(a),o=0}catch{}if(!s.updating&&s.buffered&&s.buffered.length){const a=s.buffered.end(s.buffered.length-1),c=a-5,l=s.buffered.start(0);c>l&&(s.remove(l,c),t.setLiveSeekableRange(c,a)),this.video.currentTime<c&&(this.video.currentTime=c);const d=a-this.video.currentTime;this.video.playbackRate=d>.1?d:.1}});const i=new Uint8Array(2*1024*1024);let o=0;this.ondata=a=>{if(s.updating||o>0){const c=new Uint8Array(a);i.set(c,o),o+=c.byteLength}else try{s.appendBuffer(a)}catch{}}}}onwebrtc(){const t=new RTCPeerConnection(this.pcConfig);t.addEventListener("icecandidate",e=>{if(e.candidate&&this.mode.indexOf("webrtc/tcp")>=0&&e.candidate.protocol==="udp")return;const s=e.candidate?e.candidate.toJSON().candidate:"";this.send({type:"webrtc/candidate",value:s})}),t.addEventListener("connectionstatechange",()=>{if(t.connectionState==="connected"){const e=t.getTransceivers().filter(i=>i.currentDirection==="recvonly").map(i=>i.receiver.track),s=document.createElement("video");s.addEventListener("loadeddata",()=>this.onpcvideo(s),{once:!0}),s.srcObject=new MediaStream(e)}else(t.connectionState==="failed"||t.connectionState==="disconnected")&&(t.close(),this.pcState=WebSocket.CLOSED,this.pc=null,this.onconnect())}),this.onmessage.webrtc=e=>{switch(e.type){case"webrtc/candidate":if(this.mode.indexOf("webrtc/tcp")>=0&&e.value.indexOf(" udp ")>0)return;t.addIceCandidate({candidate:e.value,sdpMid:"0"}).catch(s=>{console.warn(s)});break;case"webrtc/answer":t.setRemoteDescription({type:"answer",sdp:e.value}).catch(s=>{console.warn(s)});break;case"error":if(e.value.indexOf("webrtc/offer")<0)return;t.close()}},this.createOffer(t).then(e=>{this.send({type:"webrtc/offer",value:e.sdp})}),this.pcState=WebSocket.CONNECTING,this.pc=t}async createOffer(t){try{this.media.indexOf("microphone")>=0&&(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(i=>{t.addTransceiver(i,{direction:"sendonly"})})}catch(s){console.warn(s)}for(const s of["video","audio"])this.media.indexOf(s)>=0&&t.addTransceiver(s,{direction:"recvonly"});const e=await t.createOffer();return await t.setLocalDescription(e),e}onpcvideo(t){if(this.pc){let e=0,s=0;const i=t.srcObject;i.getVideoTracks().length>0&&(e+=544),i.getAudioTracks().length>0&&(e+=258),this.mseCodecs.indexOf("hvc1.")>=0&&(s+=560),this.mseCodecs.indexOf("avc1.")>=0&&(s+=528),this.mseCodecs.indexOf("mp4a.")>=0&&(s+=257),e>=s?(this.video.srcObject=i,this.play(),this.pcState=WebSocket.OPEN,this.wsState=WebSocket.CLOSED,this.ws&&(this.ws.close(),this.ws=null)):(this.pcState=WebSocket.CLOSED,this.pc&&(this.pc.close(),this.pc=null))}t.srcObject=null}onmjpeg(){this.ondata=t=>{this.video.controls=!1,this.video.poster=`data:image/jpeg;base64,${Z.btoa(t)}`},this.send({type:"mjpeg"})}onhls(){this.onmessage.hls=t=>{if(t.type!=="hls")return;const e=`http${this.wsURL.substring(2,this.wsURL.indexOf("/ws"))}/hls/`,s=t.value.replace("hls/",e);this.video.src=`data:application/vnd.apple.mpegurl;base64,${btoa(s)}`,this.play()},this.send({type:"hls",value:this.codecs(t=>this.video.canPlayType(t))})}onmp4(){const t=document.createElement("canvas");let e;const s=document.createElement("video");s.autoplay=!0,s.playsInline=!0,s.muted=!0,s.addEventListener("loadeddata",()=>{e||(t.width=s.videoWidth,t.height=s.videoHeight,e=t.getContext("2d")),e.drawImage(s,0,0,t.width,t.height),this.video.controls=!1,this.video.poster=t.toDataURL("image/jpeg")}),this.ondata=i=>{s.src=`data:video/mp4;base64,${Z.btoa(i)}`},this.send({type:"mp4",value:this.codecs(this.video.canPlayType)})}static btoa(t){const e=new Uint8Array(t),s=e.byteLength;let i="";for(let o=0;o<s;o++)i+=String.fromCodePoint(e[o]);return window.btoa(i)}}customElements.define("video-stream",Z);const rt=g.fabric.util.createClass(g.fabric.Image,{initialize:function(r){this.callSuper("initialize",r),this.firstRender=!0,this.readyCallback=r.readyCallback,this.videoStream=document.createElement("video-stream"),this.videoStream.visibilityCheck=!1,this.videoStream.oninit(),this.videoStream.src=r.url,this.videoStream.video.addEventListener("loadedmetadata",this.onVideoMetadata.bind(this)),r.autoplay&&this.video.play()},onVideoMetadata:function(){const r=this.videoStream.video;r.width=r.videoWidth,r.height=r.videoHeight,this.width=r.videoWidth,this.height=r.videoHeight,this.setElement(r),this.setCoords(),this.readyCallback&&this.readyCallback()},play:function(){this.video.play()},stop:function(){this.video.stop()}});g.fabric.Object.prototype.objectCaching=!1;class ct{constructor(t){w(this,"annotationSize",14);w(this,"colors",{object:"blue",hasdata:"green",queued:"yellow",selected:"red",selectedGroup:"orange",scaleBar:"grey",marking:"yellow",markingInvert:"cyan",polyline:"purple",reference:"magenta"});this.pending={},this.pendingComposites={},this.pendingImages={},this.pendingSources={},this.fabric=t.fabric,this.width=t.width,this.addObject=t.addObject,this.x_dir=t.flip_x?-1:1,this.lastMarkingStroke=null,this.markingDebounce=1e3,this.lastMarkingTime=0,this.getSelectedObjects=t.getSelectedObjects,this.lastLum=0,this.lumDebounce=2e3,this.lastLumTime=0}select(t){this.setStroke({object:t.object,stroke:t.deselect?this.getStrokeColor(t.object.object):this.colors.selected})}getStrokeColor(t){const e=this.fabric.getActiveObject();return e&&e.object.subsampleid===t.subsampleid?this.colors.selected:this.getSelectedObjects().indexOf(t.subsampleid)>-1?this.colors.selectedGroup:t.queued?this.colors.queued:t.datacollections?this.colors.hasdata:this.colors.object}setStroke(t){t.object.type==="group"?h.each(t.object.getObjects(),e=>{e.type==="text"?e.set({fill:t.stroke,stroke:t.stroke}):e.set({stroke:t.stroke})}):t.object.set({stroke:t.stroke})}scaleStrokeWidth(t){let e=Math.round(1/this.fabric.getZoom());e<1&&(e=1),t.type==="group"?h.each(t.getObjects(),s=>{s.type!=="text"&&s.set({strokeWidth:e})}):t.set({strokeWidth:e})}drawCursor(t){if(this.cursor){this.updateCursor(t);return}this.cursor=new g.fabric.Text("",{fill:this.colors.scaleBar,left:10,top:10,fontSize:11,fontFamily:"Poppins",backgroundColor:t&&t.text?"#333":"transparent"}),this.fabric.add(this.cursor),this.updateCursor(t)}updateCursor(t){const e=1/this.fabric.getZoom();this.fabric.bringToFront(this.cursor),this.cursor.scaleX=e,this.cursor.scaleY=e,this.cursor.set({top:e*(10-this.fabric.viewportTransform[5]),left:e*(10-this.fabric.viewportTransform[4])}),t&&this.cursor.set({text:t.text,backgroundColor:t&&t.text?"#333":"transparent"}),this.cursor.setCoords()}drawScaleBar(t){if(this.scalebar){this.updateScale(t);return}const e=50,s=0,i=0,o=new g.fabric.Line([s,i,s,i+e],{stroke:this.colors.scaleBar,strokeWidth:2,originY:"bottom"}),a=new g.fabric.Line([s+e,i+e,s,i+e],{stroke:this.colors.scaleBar,strokeWidth:2,originY:"bottom"}),c=new g.fabric.Text("50um",{fill:this.colors.scaleBar,left:s+10,top:i+e-20,fontSize:11,fontFamily:"Poppins"});this.scalebar=new g.fabric.Group([o,a,c]),this.fabric.add(this.scalebar),this.updateScale(t)}updateScale(t){const e=1/this.fabric.getZoom(),s=e*I.pixelSize,i=H(s*50),o=i.scalar%parseInt(i.scalar,10),a=(i.scalar-o)/i.scalar;this.scalebar.getObjects()[1].scaleX=a,this.scalebar.getObjects()[0].scaleY=a,this.fabric.bringToFront(this.scalebar),this.scalebar.getObjects()[2].set({text:`${(i.scalar-o).toFixed(0)} ${i.prefix}m`}),this.scalebar.scaleX=e,this.scalebar.scaleY=e,this.scalebar.set({top:e*(t.height-70-this.fabric.viewportTransform[5]),left:e*(20-this.fabric.viewportTransform[4])}),this.scalebar.setCoords(),this.drawCursor()}selectionDefault(t,e=!1,s=!1){t.selectable=!0,t.lockScalingX=!s,t.lockScalingY=!s,t.hasRotatingPoint=!1,t.setControlsVisibility({mt:!1,mb:!1,ml:!1,mr:!1,bl:!1,br:!!s,tl:!1,tr:!1,mtr:!1}),t.lockMovementX=!e,t.lockMovementY=!e}drawROI(t,e,s){console.log("drawROI");const i=this.getStrokeColor(t),o=t.x+e.offsetx,a=t.y+e.offsety,c=t.x2-t.x,l=t.y2-t.y,d=new g.fabric.Rect({left:o,top:a,width:c,height:l,stroke:i,fill:null,strokeWidth:1,hasBorders:!1,hoverCursor:"pointer"}),p=new g.fabric.Text(`${s}`,{left:o+c,top:a+l,fontSize:this.annotationSize,fontFamily:"Poppins",fill:i}),m=new g.fabric.Group([d,p],{hasBorders:!1,hoverCursor:"pointer"});return this.selectionDefault(m,t.datacollections===0,t.datacollections===0),this.addObject({type:"rois",object:m}),this.updateROI(m,t,e),m}updateROI(t,e,s,i){let o=1/this.fabric.getZoom();o<1&&(o=1);const a=this.getStrokeColor(e),c=e.x2-e.x,l=e.y2-e.y,d=e.x+s.offsetx,p=e.y+s.offsety;t.getObjects()[0].set({stroke:a,left:-c/2,top:-l/2,width:c,height:l}),t.getObjects()[1].set({stroke:a,scaleX:o,scaleY:o,left:c/2,top:l/2}),t.set({left:d,top:p,width:c*t.scaleX,height:l*t.scaleY,scaleX:1,scaleY:1}),this.selectionDefault(t,e.datacollections===0&&i,e.datacollections===0&&i)}drawCrossText({x:t,y:e,annotationText:s,strokeColor:i}){const a=Math.round(10.5),c=new g.fabric.Line([0,-a,0,a],{stroke:i,strokeWidth:1,hasBorders:!1,originX:"center",originY:"center"}),l=new g.fabric.Line([-a,0,a,0],{stroke:i,strokeWidth:1,hasBorders:!1,originX:"center",originY:"center"}),d=new g.fabric.Text(`${s}`,{left:a,top:a,fontSize:this.annotationSize,fontFamily:"Poppins",fill:i});return new g.fabric.Group([c,l,d],{hasBorders:!1,hoverCursor:"pointer",left:t,top:e,originX:"center",originY:"center"})}updateCrossText({fobj:t,x:e,y:s,strokeColor:i}){let o=1/this.fabric.getZoom();o<1&&(o=1),t.set({left:e,top:s});const a=t.getObjects()[0];a.scaleY=o,a.stroke=i;const c=t.getObjects()[1];c.scaleX=o,c.stroke=i,t.getObjects()[2].set({stroke:i,left:a.left+a.width,top:a.top+a.height,scaleX:o,scaleY:o})}drawReference(t,e){const s=this.colors.reference,i=this.drawCrossText({x:t.posx,y:t.posy,annotationText:t.id,strokeColor:s});return this.selectionDefault(i,t.datacollections===0),this.addObject({type:"refs",object:i}),this.updateReference(i,t),i}updateReference(t,e){const s=this.colors.reference;this.updateCrossText({fobj:t,x:e.posx,y:e.posy,strokeColor:s})}drawPOI(t,e,s){const i=t.x+e.offsetx,o=t.y+e.offsety,a=this.getStrokeColor(t),c=this.drawCrossText({x:i,y:o,annotationText:s,strokeColor:a});return this.selectionDefault(c,t.datacollections===0),this.addObject({type:"pois",object:c}),this.updatePOI(c,t,e),c}updatePOI(t,e,s){const i=this.getStrokeColor(e);this.updateCrossText({fobj:t,x:e.x+s.offsetx,y:e.y+s.offsety,strokeColor:i})}drawLOI(t,e,s){const i=t.x+e.offsetx,o=t.y+e.offsety,a=t.x2+e.offsetx,c=t.y2+e.offsety,l=this.getStrokeColor(t),d=new g.fabric.Line([i,o,a,c],{stroke:l,strokeWidth:1,hasBorders:!1}),p=Math.atan2(c-o,a-i)*180/Math.PI,m=new g.fabric.Triangle({top:c,left:a,angle:p+90,width:10,height:10,stroke:l,fill:!1,originX:"center",originY:"center"}),x=new g.fabric.Text(`${s}`,{left:a,top:c,fontSize:this.annotationSize,fontFamily:"Poppins",fill:l}),u=new g.fabric.Group([d,m,x],{hasBorders:!1,hoverCursor:"pointer"});return this.selectionDefault(u,t.datacollections===0),this.addObject({type:"lois",object:u}),this.updateLOI(u,t,e),u}updateLOI(t,e,s,i){let o=1/this.fabric.getZoom();o<1&&(o=1),t.set({x1:e.x+s.offsetx,y1:e.y+s.offsety}),t.lockMovementX=i,t.lockMovementY=i;const a=this.getStrokeColor(e),c=t.getObjects()[0];c.scale=o,c.stroke=a,t.getObjects()[1].set({stroke:a,width:o*10,height:o*10}),t.getObjects()[2].set({stroke:a,scaleX:o,scaleY:o})}drawMarking(t){const e=this.toCanvasCoords(t.position),s=Math.round(80/2),i=this.colors.marking,o=new g.fabric.Line([0,-s,0,s],{stroke:i,strokeWidth:1,hasBorders:!1,originX:"center",originY:"center"}),a=new g.fabric.Line([-s,0,s,0],{stroke:i,strokeWidth:1,hasBorders:!1,originX:"center",originY:"center"}),c=new g.fabric.Ellipse({left:0,top:0,originX:"center",originY:"center",strokeWidth:1,stroke:this.colors.marking,fill:!1,rx:t.size[0]/2,ry:t.size[1]/2}),l=new g.fabric.Group([o,a,c],{hasBorders:!1,hoverCursor:"cursor",originX:"center",originY:"center",left:Math.round(e[0]),top:Math.round(e[1])});return this.addObject({type:"markings",object:l}),this.updateMarking(l,t),l}updateMarking(t,e){const s=this.toCanvasCoords(e.position);let i=1/this.fabric.getZoom();i<1&&(i=1);const o=t.getObjects()[0],a=t.getObjects()[1];o.scaleY=i,a.scaleX=i;const c=a.getScaledWidth(),l=o.getScaledHeight(),d=g.fabric.util.transformPoint({x:s[0],y:s[1]},this.fabric.viewportTransform),p=g.fabric.util.transformPoint({x:s[0]+c,y:s[1]+l},this.fabric.viewportTransform);if(Number.isNaN(p.x)||Number.isNaN(p.y))return;const m=Date.now();if(m-this.lastLumTime>this.lumDebounce){const y=(p.x-d.x)/3,v=this.fabric.contextContainer,L=window.devicePixelRatio,{data:E}=v.getImageData((d.x-y)*L,(d.y-y)*L,y*2*L,y*2*L),Y=[];for(let z=0;z<E.length;z+=4)Y.push(.299*E[z]+.587*E[z+1]+.114**E[z+2]*(E[z+3]/255));this.lastLum=Y.length?h.sum(Y)/Y.length:0,this.lastLumTime=m}const x=150,u=this.lastLum>x?this.colors.markingInvert:this.colors.marking;u!==this.lastMarkingStroke&&m-this.lastMarkingTime>this.markingDebounce&&(o.set({stroke:u}),a.set({stroke:u}),t.getObjects()[2].set({stroke:u}),this.lastMarkingTime=m,this.lastMarkingStroke=u),this.scaleStrokeWidth(t),t.set({left:Math.round(s[0]),top:Math.round(s[1])}),t.setCoords()}refreshImage(t,e){const s=Date.now(),i=new Image;i.onload=()=>{e.setElement(i),this.refreshThread=setTimeout(this.refreshImage.bind(this,t,e),100)},i.src=`${t.url}?${s}`}toCanvasCoords(t){return[t[0],-t[1]]}drawSource(t,e){if(t.sourceid in this.pendingSources)return null;this.pendingSources[t.sourceid]=1;let s=t.url,i=t.scale;if(e){const o=h.find(t.additional_urls,{name:e});o&&(s=o.url,i=o.scale)}return new Promise(o=>{const a=this.toCanvasCoords(t.center);if(s.startsWith("ws")||s.startsWith("rtc")){const c=s.startsWith("ws")?nt:rt,l=new c({url:s.replace("rtc:",""),readyCallback:()=>{l.set({left:a[0],top:a[1],hoverCursor:"default",originX:"center",originY:"center"}),l.setCoords();const d=this.toCanvasCoords(t.pixelsize);this.scaleObject(l,d,i),this.addObject({type:"sources",object:l}),o(l),delete this.pendingSources[t.sourceid]}})}else new g.fabric.Image.fromURL(s,c=>{c.set({left:a[0],top:a[1],hoverCursor:"default",width:c.width,height:c.height,originX:"center",originY:"center"});const l=this.toCanvasCoords(t.pixelsize);this.scaleObject(c,l,t.scale),this.addObject({type:"sources",object:c}),o(c),delete this.pendingSources[t.sourceid]},{crossOrigin:"Anonymous"})})}scaleObject(t,e,s=1){t.scaleToWidth(t.width*Math.abs(e[0]*s),!0),t.scaleY=Math.abs(e[1]*s),t.flipX=Math.sign(e[0])===-1,t.flipY=Math.sign(e[1])===-1}updateSource(t,e,s,i){const o=this.toCanvasCoords(e.center);t.set({left:o[0],top:o[1],opacity:i?0:1});const a=h.find(e.additional_urls,{name:s}),c=a?a.scale:e.scale,l=this.toCanvasCoords(e.pixelsize);this.scaleObject(t,l,c),t.setCoords()}drawImage(t,e,s=1){const i=this.fabric.vptCoords,o=this.toCanvasCoords([t.offsetx,t.offsety]),a=this.toCanvasCoords([t.scalex,t.scaley]),c=e.offsetx+o[0]-Math.abs(t.width*a[0])/2,l=e.offsetx+o[0]+Math.abs(t.width*a[0])/2,d=e.offsety+o[1]-Math.abs(t.height*a[1])/2,p=e.offsety+o[1]+Math.abs(t.height*a[1])/2;if(l>i.tl.x&&c<i.br.x&&p>i.tl.y&&d<i.br.y)return t.sampleimageid in this.pendingImages?null:(this.pendingImages[t.sampleimageid]=1,new Promise((m,x)=>{const u=new _;u.onerror=()=>{x()},u.onload=()=>{const y=u.width/t.width,v=new g.fabric.Image(u,{left:e.offsetx+o[0],top:e.offsety+o[1],hoverCursor:"default",width:u.width,height:u.height,originX:"center",originY:"center"});this.scaleObject(v,a,1/y),v.loadedScale=y,this.addObject({type:"images",object:v}),delete this.pendingImages[t.sampleimageid],m(v)},u.load(`${I.baseUrl+t.url}?scale=${s}`)}))}updateImage(t,e,s){const i=this.toCanvasCoords([e.offsetx,e.offsety]);t.set({left:s.offsetx+i[0],top:s.offsety+i[1],opacity:e.hide?0:1});const o=this.toCanvasCoords([e.scalex,e.scaley]);this.scaleObject(t,o,1/t.loadedScale),t.setCoords()}calcPoint(t){const e=this.toCanvasCoords(t);return{x:e[0],y:e[1]}}drawPolyline(t,e=!1){const s=e?null:this.colors.polyline,i=h.map(t,a=>this.calcPoint(a)),o=new g.fabric.Polyline(i,{stroke:s,strokeWidth:1,fill:null,hoverCursor:"default",originX:e?"center":null,originY:e?"center":null});return this.addObject({type:"polyline",object:o}),this.updatePolyline(o,t),o}updatePolyline(t,e){const s=h.map(e,o=>this.calcPoint(o));t.set({points:s}),this.scaleStrokeWidth(t);const i=t._calcDimensions();t.set({width:i.width,height:i.height,left:i.left,top:i.top,pathOffset:{x:i.width/2+i.left,y:i.height/2+i.top},dirty:!0}),t.setCoords()}drawMap(t,e){return t.mapid in this.pending?null:(this.pending[t.mapid]=1,new Promise((s,i)=>{const o=new _;o.onerror=()=>{i()},o.onload=()=>{const a=new g.fabric.Image(o,{left:e.left,top:e.top,width:o.width,height:o.height,hoverCursor:"default"});a.scaleToWidth(e.width),a.scaleY=e.height/a.height,this.addObject({type:"maps",object:a}),delete this.pending[t.mapid],s(a),a.lastMap=t},o.load(I.baseUrl+t.url)}))}updateMap(t,e,s){let i=!1;if(h.each(["min","max","points","colourmap","opacity","scale"],o=>{e[o]!==t.lastMap[o]&&(i=!0)}),t.set({left:s.left,top:s.top}),i){const o=new _;o.onload=()=>{t.setElement(o,a=>{a.set({hoverCursor:"default",selectable:!0})}),t.lastMap=e},o.load(I.baseUrl+e.url)}}drawComposite(t,e){return t.compositeid in this.pendingComposites?null:(this.pendingComposites[t.compositeid]=1,new Promise((s,i)=>{const o=new _;o.onerror=()=>{i()},o.onload=()=>{const a=new g.fabric.Image(o,{left:e.left,top:e.top,width:o.width,height:o.height,hoverCursor:"default"});a.scaleToWidth(e.width),a.scaleY=e.height/a.height,a.compositeMap=t,this.addObject({type:"composite",object:a}),delete this.pendingComposites[t.compositeid],s(a)},o.load(I.baseUrl+t.url)}))}updateComposite(t,e,s){let i=!1;if(h.each(["ropacity","gopacity","bopacity","opacity"],o=>{e[o]!==t.compositeMap[o]&&(i=!0)}),t.set({left:s.left,top:s.top}),i){const o=new _;o.onload=()=>{t.setElement(o,a=>{a.set({hoverCursor:"default",selectable:!0})}),t.compositeMap=e},o.load(I.baseUrl+e.url)}}}function lt(r){const{pointer:t={},actions:e,spectra:s,spectraFetching:i,spectraFetched:o,spectraError:a}=r,c=C.useRef(),{currentSampleId:l}=G(),{data:d,loading:p}=A(Ze.getList,{sampleid:l});C.useEffect(()=>{var v;t.point!==void 0?(m(),(v=c.current)==null||v.showModal()):e.setMapPointer()},[t]);function m(){e.fetchScanSpectra({scanid:t.scanid,point:t.point}).catch(()=>{console.log("Couldnt load spectra")})}const x=h.map(d.rows,v=>({type:"rect",xref:"x",yref:"paper",y0:0,y1:1,x0:v.start,x1:v.end,fillcolor:"#ccc",opacity:.5,line:{width:0}}));let u=0;const y=h.map(d.rows,v=>({xref:"x",yref:"paper",y:.8-u++*.06,x:v.start,text:`${v.element}-${v.edge}`,showarrow:!1}));return n.jsxs(ie,{id:"mca",ref:c,showButton:!1,title:"MCA",children:[i&&n.jsxs(me,{variant:"info",children:[n.jsx("i",{className:"fa fa-spin fa-spinner me-1"}),"Fetching point ",t.point," from scan ",t.scanid]}),a&&n.jsxs(me,{variant:"warning",children:["Scan number ",t.scanid," is no longer available"]}),!a&&o&&!i&&n.jsxs(Q,{children:[n.jsxs($,{children:["Point ",t.point??0+1,"/",s.npoints]}),n.jsx($,{style:{height:"40vh"},children:n.jsx(T,{children:n.jsx(He,{fetching:i,options:{},selectable:!1,spectra:s,scans:[],data:{},layout:{shapes:x,annotations:y,xaxis:{title:"Energy (eV)"},yaxis:{title:"Counts"}}})})})]})]})}const ht=(r,t)=>{const{spectra:e}=t.providers.scans;return{pointer:f.selector("mapPointer",r),spectra:e.selector("results",r),spectraError:e.selector("error",r),spectraFetched:e.selector("fetched",r),spectraFetching:e.selector("fetching",r)}},dt=(r,t)=>({actions:{fetchScanSpectra:e=>t.providers.scans.spectra.fetch(e),setMapPointer:()=>f.dispatch("SET_MAP_POINTER")}}),pt=B({scans:ge,metadata:q})(W(ht,dt)(lt));class ut{constructor(){w(this,"mapid");w(this,"value");w(this,"x");w(this,"y")}}class mt extends ut{constructor(){super(...arguments);w(this,"key","")}}class ft extends Ne(mt,{pk:"key",key:"MapValue"}){}const gt=new Pe({path:"/metadata/xrf/maps/value/:mapid",schema:ft,process(r,t){return r.key=t.x!==void 0?`${t.mapid}:${t.x}:${t.y}`:t.mapid,r},searchParams:{}});function wt(r){var o;const{actions:t,pointer:e={}}=r,{data:s,error:i}=A(gt,e.x!==void 0&&e.y!==void 0?{mapid:e.mapid,x:e.x,y:e.y}:null);return C.useEffect(()=>{(e.x===void 0||e.y===void 0)&&t.setMapHover()},[e]),e.x===void 0||!s&&!i?null:n.jsxs("div",{className:"tooltip-inner",style:{position:"absolute",top:e.py+30,left:e.px+30,zIndex:1070},children:[i&&n.jsxs("span",{children:["x: ",s==null?void 0:s.x," y: ",s==null?void 0:s.y," p: ",e.point+1," | Could not fetch value"]}),!i&&s&&n.jsxs("div",{className:"value-modal",children:["x: ",s.x," y: ",s.y," p: ",e.point+1," | v:"," ",(o=s.value)==null?void 0:o.toFixed(2)]})]})}const bt=(r,t)=>({pointer:f.selector("mapHover",r)}),xt=(r,t)=>({actions:{setMapHover:e=>f.dispatch("SET_MAP_HOVER",e)}}),vt=W(bt,xt)(wt);class se extends Qe{constructor(e){super(e);w(this,"zindexes",{images:0,sources:50,maps:200,composite:300,polyline:500,rois:1e3,pois:2e3,lois:2500,markings:3e3,refs:2800});w(this,"getSelectedObjects",()=>this.props.selectedObjects||[]);w(this,"startPan",e=>{e.which===2&&(this.lastAction=this.props.currentAction,this.props.actions.setClampOrigin(!1),this.props.actions.selectAction("pan"),this.moouseIsDown=!0,this.lastPosX=e.clientX,this.lastPosY=e.clientY)});w(this,"stopPan",e=>{e.which===2&&(this.props.actions.selectAction(this.lastAction),this.moouseIsDown=!1)});w(this,"requestAnimFrame",()=>{this.destroyed||(this.fabric.requestRenderAll(),clearTimeout(this.refreshThread),this.refreshThread=setTimeout(()=>{this.requestAnimFrame()},66))});w(this,"onFocusLost",()=>{this.props.currentAction==="move"&&this.props.config.options.disable_move_blur&&this.props.actions.selectAction("pan")});w(this,"objectScaling",e=>{const s=e.target,i=s.width*s.scaleX,o=s.height*s.scaleY;let a=i,c=o;if(this.props.drawQuantize){const l=i%this.props.drawQuantize[0],d=o%this.props.drawQuantize[1];a=i-l+(l>this.props.drawQuantize[0]/2?this.props.drawQuantize[0]:0),c=o-d+(d>this.props.drawQuantize[1]/2?this.props.drawQuantize[1]:0)}s.set({width:a,height:c,scaleX:1,scaleY:1}),s.getObjects()[0].set({left:-a/2,top:-c/2,width:a,height:c}),s.getObjects()[1].set({left:a/2,top:c/2})});w(this,"objectScaled",e=>{const s=e.target,i=s.width*s.scaleX,o=s.height*s.scaleY;s.set({width:i,height:o,scaleX:1,scaleY:1}),s.getObjects()[0].set({left:-i/2,top:-o/2,width:i,height:o}),s.getObjects()[1].set({left:i/2,top:o/2});const a=s.left,c=s.top;this.props.actions.updateObject({subsampleid:s.subsampleid,x:a,y:c,x2:a+i,y2:c+o})});w(this,"objectMoved",e=>{const s=e.target,i=this.props.objects[s.subsampleid],o=this.fabric.getZoom(),a=this.getNearest(s.left,s.top,o),c=a?a.left:s.left,l=a?a.top:s.top;this.props.actions.updateObject({subsampleid:s.subsampleid,x:Math.round(c),y:Math.round(l),x2:Math.round(c+(i.x2-i.x)),y2:Math.round(l+(i.y2-i.y))})});w(this,"selectionCreated",e=>{e.target&&(this.draw.select({object:e.target}),this.inExternalUpdate||(this.props.actions.resetSelection(),this.props.actions.addSelection({subsampleid:e.target.subsampleid}),e.target.object.datacollections===0&&this.props.currentAction==="pan"&&this.props.actions.selectAction("")))});w(this,"selectionUpdated",e=>{e.deselected&&(this.draw.select({object:e.deselected[0],deselect:!0}),this.inExternalUpdate||this.props.actions.resetSelection()),e.selected&&(this.draw.select({object:e.selected[0]}),this.inExternalUpdate||(this.props.actions.resetSelection(),this.props.actions.addSelection({subsampleid:e.target.subsampleid})),e.selected[0].object.datacollections===0&&this.props.currentAction==="pan"&&this.props.actions.selectAction(""))});w(this,"selectionCleared",e=>{e.deselected&&(this.draw.select({object:e.deselected[0],deselect:!0}),this.inExternalUpdate||this.props.actions.resetSelection()),e.deselected&&e.deselected[0].object.datacollections===0&&this.props.currentAction===""&&this.props.actions.selectAction("pan")});w(this,"roiMouseDown",({e,target:s,pointer:i})=>{if(!this.props.cursor)return;const o=this.getTopMap(e,i);if(o){const{x:a,y:c}=this.getMapPoint(e,s,o);this.props.actions.setMapPointer({point:c*o.w+a,mapid:o.mapid,scanid:o.datacollectionnumber})}});w(this,"roiMouseMove",({e,target:s,pointer:i})=>{if(!this.props.cursor)return;const o=this.getTopMap(e,i);if(o){const{x:a,y:c}=this.getMapPoint(e,s,o);this.props.actions.setMapHover({x:a,y:c,point:c*o.w+a,mapid:o.mapid,px:i.x,py:i.y})}});w(this,"roiMouseOut",()=>{this.props.cursor&&this.props.actions.setMapHover()});w(this,"sourceMouseMove",e=>{this.props.cursor&&h.each(this.objs.sources,s=>{const i=s.width*s.scaleX,o=s.height*s.scaleY;if(e.x>=s.left-i/2&&e.x<=s.left+i/2&&e.y>=s.top-o/2&&e.y<=s.top+o/2){const c=Math.round((e.x-s.left)/s.scaleX*10)/10,l=Math.round((e.y-s.top)/s.scaleY*10)/10,d=Math.round((e.x-(s.left-i/2))/s.scaleX*10)/10,p=Math.round((e.y-(s.top-o/2))/s.scaleY*10)/10,m=g.fabric.util.transformPoint({x:e.x,y:e.y},this.fabric.viewportTransform),x=this.fabric.contextContainer,u=window.devicePixelRatio,{data:y}=x.getImageData(m.x,m.y,1*u,1*u),v=Math.round(.299*y[0]+.587*y[1]+.114**y[2]*(y[3]/255));this.props.actions.setSourceHover({x:d,y:p,xCentre:c,yCentre:l,lum:v})}})});w(this,"onMouseWheel",e=>{const s=400/this.fabric.getZoom(),i=e.e.deltaMode===1?e.e.deltaY*18:e.e.deltaY,o=this.clampZoom(this.fabric.getZoom()+-1*i/s);this.setZoom(o,e.e.offsetX,e.e.offsetY),e.e.preventDefault(),e.e.stopPropagation()});w(this,"onMouseDown",e=>{this.moouseIsDown=!0;const s=this.fabric.getZoom(),i=this.fabric.getPointer(e.e);if(this.origX=i.x,this.origY=i.y,this.props.currentAction==="move"){if(this.props.runningScan)return;this.props.actions.moveToCoords({x:parseInt(i.x,10),y:parseInt(i.y,10)}).catch(o=>{this.props.actions.addToast({type:"error",title:"Could Not Move",text:o.response&&o.response.data&&o.response.data.error||o.message})})}if(this.props.currentAction==="roi"||this.props.currentAction==="mosaic"){const o=this.getNearest(this.origX,this.origY,s);this.newRect=new g.fabric.Rect({left:o?o.left:this.origX,top:o?o.top:this.origY,width:0,height:0,stroke:"green",strokeDashArray:[5/s,5/s],fill:null}),this.newRect.selectable=!0,this.fabric.add(this.newRect)}if(this.props.currentAction==="loi"&&(this.newLine=new g.fabric.Line([this.origX,this.origY,i.x,i.y],{stroke:"green",strokeDashArray:[5/s,5/s]}),this.newLine.selectable=!0,this.fabric.add(this.newLine)),this.props.currentAction==="measure"&&(this.newLineText=new g.fabric.Text("0m",{left:this.origX,top:this.origY,fontSize:14,fontFamily:"Poppins",fill:"purple"}),this.newLine=new g.fabric.Line([this.origX,this.origY,this.origX,this.origY],{stroke:"purple"}),this.fabric.add(this.newLine),this.fabric.add(this.newLineText)),this.props.currentAction==="pan"&&(console.log("scrolling mouseDown"),this.lastPosX=e.e.clientX,this.lastPosY=e.e.clientY),this.props.currentAction==="beam"){const o=h.find(this.objs.sources,{origin:!0}),a=h.find(this.objs.markings,{origin:!0}),c=Math.round((i.x-o.left)/o.scaleX),l=Math.round((i.y-o.top)/o.scaleY),d=h.find(this.props.sources,{sourceid:o.sourceid});this.props.actions.updateMarking({markingid:a.markingid,x:parseInt(c,10),y:parseInt(l,10),scalelabel:d.scalelabel})}if(this.props.currentAction==="calib"){const o=h.find(this.objs.sources,{origin:!0}),a=h.find(this.props.sources,{origin:!0}),c=(i.x-o.left)/o.scaleX,l=(i.y-o.top)/o.scaleY;console.log(i,c,l),this.calibStep===0?(this.calib={offsetx:a.offsetx,offsety:a.offsety,pointerx:c,pointery:l},this.calibStep+=1):this.calibStep=0}});w(this,"onMouseMove",e=>{const s=this.fabric.getPointer(e.e),i=this.fabric.getZoom()<1?this.fabric.getZoom():1;if(this.sourceMouseMove(s),!!this.moouseIsDown){if(this.props.currentAction==="roi"){this.origX>s.x&&this.newRect.set({left:s.x}),this.origY>s.y&&this.newRect.set({top:s.y});const o=Math.abs(this.origX-s.x),a=Math.abs(this.origY-s.y);let c=o,l=a;if(this.props.drawQuantize){const d=o%this.props.drawQuantize[0],p=a%this.props.drawQuantize[1];c=o-d+(d>this.props.drawQuantize[0]/2?this.props.drawQuantize[0]:0),l=a-p+(p>this.props.drawQuantize[1]/2?this.props.drawQuantize[1]:0)}this.newRect.set({width:c,height:l}),this.draw.scaleStrokeWidth(this.newRect)}if(this.props.currentAction==="loi"){let o=s.x,a=s.y;if(this.props.clampLOI&&(o-this.newLine.x1<50/i?o=this.newLine.x1:a=this.newLine.y1),this.props.drawQuantize){const c=o-this.origX,l=a-this.origY,d=Math.sqrt(c*c+l*l),p=Math.atan2(l,c),m=d%this.props.drawQuantize[0],x=d-m+(m>this.props.drawQuantize[0]/2?this.props.drawQuantize[0]:0);o=Math.cos(p)*x+this.origX,a=Math.sin(p)*x+this.origY}this.newLine.set({x2:o,y2:a}),this.draw.scaleStrokeWidth(this.newLine)}if(this.props.currentAction==="mosaic"){this.origX>s.x&&this.newRect.set({left:Math.abs(s.x)}),this.origY>s.y&&this.newRect.set({top:Math.abs(s.y)});const o=Math.abs(this.origX-s.x),a=Math.abs(this.origY-s.y),c=h.find(this.objs.sources,{origin:!0}),l=o%c.getScaledWidth(),d=a%c.getScaledHeight(),p=o-l+(l>c.getScaledWidth()/2?c.getScaledWidth():0),m=a-d+(d>c.getScaledHeight()/2?c.getScaledHeight():0);this.newRect.set({width:p,height:m}),this.draw.scaleStrokeWidth(this.newRect)}if(this.props.currentAction==="measure"){this.newLine.set({x2:s.x,y2:s.y});const o=Math.sqrt((s.x-this.newLine.x1)**2+(s.y-this.newLine.y1)**2),a=H(o*I.pixelSize);this.newLineText.set({left:this.origX+(s.x-this.origX)/2+20,top:this.origY+(s.y-this.origY)/2+20,fontFamily:"Poppins",text:`${a.scalar.toFixed(1)}${a.prefix}m`}),this.newLineText.scaleX=1/i,this.newLineText.scaleY=1/i,this.draw.scaleStrokeWidth(this.newLine)}this.props.currentAction==="pan"&&(this.setViewport({x:this.fabric.viewportTransform[4]+e.e.clientX-this.lastPosX,y:this.fabric.viewportTransform[5]+e.e.clientY-this.lastPosY}),this.clampViewPort(),this.lastPosX=e.e.clientX,this.lastPosY=e.e.clientY,this.draw.drawScaleBar({height:this.state.height}),this.debouncedPlotImages()),this.fabric.renderAll()}});w(this,"onMouseUp",e=>{this.moouseIsDown=!1;const s=h.find(this.props.sources,{origin:!0});if(this.props.currentAction==="roi"){let i=s.additional;if(this.props.disableOrigin){const o=this.findIntersectingImages(this.newRect);o.length?(i=o[o.length-1].positions,o.length>1&&this.props.actions.addToast({type:"warning",title:"Additional Positions",text:`Multiple images are visible, the most recent has been used.
|
|
2
|
+
${JSON.stringify(i,null,2)}`})):this.props.actions.addToast({type:"warning",title:"Additional Positions",text:`The origin is hidden but no images were found. Additional positions have been taken from the origin.
|
|
3
|
+
${JSON.stringify(i,null,2)}`})}if(this.newRect.width&&this.newRect.height){const o=parseInt(this.newRect.left,10),a=parseInt(this.newRect.top,10);this.props.actions.addObject({sampleid:this.props.currentSampleId,x:o,y:a,x2:o+parseInt(this.newRect.width,10),y2:a+parseInt(this.newRect.height,10),type:"roi",positions:i})}else if(this.props.drawQuantize){const o=parseInt(this.newRect.left-this.props.drawQuantize[0]/2,10),a=parseInt(this.newRect.top-this.props.drawQuantize[1]/2,10);this.props.actions.addObject({sampleid:this.props.currentSampleId,x:o,y:a,x2:o+parseInt(this.props.drawQuantize[0],10),y2:a+parseInt(this.props.drawQuantize[1],10),type:"roi",positions:s.additional})}this.fabric.remove(this.newRect),this.props.multiROI||this.props.actions.selectAction("")}if(this.props.currentAction==="loi"&&(this.newLine.x2&&this.newLine.y2&&this.props.actions.addObject({sampleid:this.props.currentSampleId,x:parseInt(this.newLine.x1,10),y:parseInt(this.newLine.y1,10),x2:parseInt(this.newLine.x2,10),y2:parseInt(this.newLine.y2,10),type:"loi",positions:s.additional}),this.fabric.remove(this.newLine),this.props.actions.selectAction("")),this.props.currentAction==="mosaic"&&this.mosaicRef.current.showModal(),this.props.currentAction==="poi"){const i=this.fabric.getPointer(e.e);this.props.actions.addObject({sampleid:this.props.currentSampleId,x:parseInt(i.x,10),y:parseInt(i.y,10),type:"poi",positions:s.additional})}if(this.props.currentAction==="reference"){const i=this.fabric.getPointer(e.e);this.props.addSampleActionPosition({x:parseInt(i.x,10),y:parseInt(i.y,10)}),this.props.actions.selectAction("")}this.props.currentAction==="measure"&&(this.measureTimeout=setTimeout(()=>{this.fabric.remove(this.newLine),this.fabric.remove(this.newLineText)},3e3))});w(this,"cancelMosaic",()=>{this.fabric.remove(this.newRect)});w(this,"startMosaic",()=>{const e=h.find(this.objs.sources,{origin:!0});this.newRect.width&&this.newRect.height&&(this.props.actions.mosaic({x1:parseInt(this.newRect.left+e.getScaledWidth()/2,10),y1:parseInt(this.newRect.top+e.getScaledHeight()/2,10),x2:parseInt(this.newRect.left+this.newRect.width-e.getScaledWidth()/2,10),y2:parseInt(this.newRect.top+this.newRect.height-e.getScaledHeight()/2,10),steps_x:this.newRect.width/e.getScaledWidth(),steps_y:this.newRect.height/e.getScaledHeight(),sampleid:this.props.currentSampleId}),this.fabric.remove(this.newRect),this.mosaicRef.current.close())});this.props.actions.setZoom=h.debounce(this.props.actions.setZoom,50),this.debouncedPlotImages=h.debounce(this.plotImages,50),this.props.actions.setViewport=h.debounce(this.props.actions.setViewport,50),this.mcaModal=C.createRef(),window.addEventListener("blur",this.onFocusLost)}render(){return n.jsxs(n.Fragment,{children:[n.jsx(ie,{id:"mosaic",ref:this.mosaicRef,showButton:!1,title:"Start Mosaic",onClose:this.cancelMosaic,buttons:n.jsx(D,{onClick:this.startMosaic,children:"Start"}),children:n.jsx("p",{children:"Are you sure you want to start this mosaic?"})}),n.jsx(vt,{}),n.jsx(pt,{providers:{scans:{spectra:{namespace:"mcamodal"}}}}),super.render()]})}addObject(e){this.objs[e.type].push(e.object)}initFabric(){this.mosaicRef=C.createRef(),this.inExternalUpdate=!1,this.objs={sources:[],images:[],maps:[],composite:[],rois:[],pois:[],lois:[],markings:[],polyline:[],refs:[]},super.initFabric();const e=this.canvasRef.current.getContext("2d");e.imageSmoothingEnabled=!1,this.draw=new ct({fabric:this.fabric,width:this.state.width,addObject:this.addObject.bind(this),flip_x:this.props.config.options.flip_x,getSelectedObjects:this.getSelectedObjects}),this.fabric.selection=!1,this.fabric.setZoom(.2),this.containerRef.current.addEventListener("mousedown",this.startPan),this.containerRef.current.addEventListener("mouseup",this.stopPan),this.fabric.on("mouse:wheel",this.onMouseWheel),this.fabric.on("mouse:down",this.onMouseDown),this.fabric.on("mouse:move",this.onMouseMove),this.fabric.on("mouse:up",this.onMouseUp),this.fabric.on("object:moved",this.objectMoved),this.fabric.on("object:scaled",this.objectScaled),this.fabric.on("object:scaling",this.objectScaling),this.fabric.on("selection:created",this.selectionCreated),this.fabric.on("selection:updated",this.selectionUpdated),this.fabric.on("selection:cleared",this.selectionCleared),this.props.actions.fetchSources().then(()=>{this.plotSources(),Object.keys(this.props.viewport).length!==0&&(this.dosetZoom(this.props.zoom),this.doSetViewport(this.props.viewport))}),this.calibStep=0,this.markingInterval=setInterval(()=>{this.plotMarkings()},500),this.roiMouseMove=h.debounce(this.roiMouseMove.bind(this),200),this.roiMouseOut=h.debounce(this.roiMouseOut.bind(this),500),this.sourceMouseMove=h.debounce(this.sourceMouseMove.bind(this),10),this.requestAnimFrame()}componentWillUnmount(){this.containerRef.current.removeEventListener("mousedown",this.startPan),this.containerRef.current.removeEventListener("mouseup",this.stopPan),clearTimeout(this.refreshThread),clearTimeout(this.markingInterval),clearTimeout(this.measureTimeout),this.destroyed=!0,this.fabric.dispose(),window.removeEventListener("blur",this.onFocusLost)}saveCanvas(){if(this.props.config.upload_canvas)this.props.actions.saveCanvasRemote({sampleid:this.props.currentSampleId,image:this.fabric.toDataURL()}).then(()=>{this.props.actions.clearSaveCanvas()}).catch(()=>{this.props.actions.clearSaveCanvas()});else{const e=document.createElement("a");e.href=this.fabric.toDataURL(),e.download=`${this.props.currentSample.name}_canvas.png`,e.click(),this.props.actions.clearSaveCanvas()}}updateSelectedObject(){this.inExternalUpdate=!0,this.plotObjects();const e=this.props.selectedObjects&&this.props.selectedObjects.slice(-1)[0];h.each(["rois","pois","lois"],s=>{h.each(this.objs[s],i=>{i.subsampleid===e&&(this.fabric.setActiveObject(i),this.props.centreOnClick&&this.zoomToObject(i))})}),this.inExternalUpdate=!1,!this.destroyed&&this.fabric.renderAll()}zoomToObject(e){let s=this.state.width/e.getScaledWidth()*.25;s>this.props.maxZoom&&(s=this.props.maxZoom),this.setZoom(s),this.setViewport({x:-(e.left+e.getScaledWidth()/2)*this.fabric.getZoom()+this.state.width/2,y:-(e.top+e.getScaledHeight()/2)*this.fabric.getZoom()+this.state.height/2}),this.draw.drawScaleBar({height:this.state.height})}getMapPoint(e,s,i){const o=s.getLocalPointer(e);return{x:Math.floor(i.w*o.x/s.width),y:Math.floor(i.h*o.y/s.height)}}getTopMap(e,s){const o=this.fabric.getObjects().filter(a=>this.fabric.containsPoint(e,a,s)&&this.objs.maps.indexOf(a)>-1&&!this.fabric.isTargetTransparent(a,s.x,s.y)).map(a=>a.mapid);return o.length?this.props.maps[o[o.length-1]]:null}plotObjects(){if(!this.props.currentSample){console.log("waiting for current sample");return}h.each(this.props.objects,(e,s)=>{let i;if(e.type==="roi"){const o=h.find(this.objs.rois,{subsampleid:e.subsampleid});if(o){this.draw.updateROI(o,e,this.props.currentSample,this.props.currentAction===""),this.draw.scaleStrokeWidth(o);return}i=this.draw.drawROI(e,this.props.currentSample,s),i.on("mousedown",this.roiMouseDown),i.on("mousemove",this.roiMouseMove),i.on("mouseout",this.roiMouseOut),this.fabric.add(i)}else if(e.type==="loi"){const o=h.find(this.objs.lois,{subsampleid:e.subsampleid});if(o){this.draw.updateLOI(o,e,this.props.currentSample,this.props.currentAction=="roi"||this.props.currentAction=="loi"),this.draw.scaleStrokeWidth(o);return}i=this.draw.drawLOI(e,this.props.currentSample,s),this.fabric.add(i)}else{const o=h.find(this.objs.pois,{subsampleid:e.subsampleid});if(o){this.draw.updatePOI(o,e,this.props.currentSample),this.draw.scaleStrokeWidth(o);return}i=this.draw.drawPOI(e,this.props.currentSample,s),this.fabric.add(i)}i.object=e,i.subsampleid=e.subsampleid,this.draw.scaleStrokeWidth(i),this.updateSelectedObject()}),h.each(["pois","rois","lois"],e=>{const s=[];h.each(this.objs[e],i=>{i.subsampleid in this.props.objects||(console.log("remove",i),s.push(i))}),h.each(s,i=>{this.fabric.remove(i),h.remove(this.objs[e],i)})}),this.zindex(),this.plotMaps()}plotReferences(){h.each(this.props.sampleActionPositions,e=>{const s=h.find(this.objs.refs,{sampleactionpositionid:e.sampleactionpositionid});if(s){this.draw.updateReference(s,e);return}const i=this.draw.drawReference(e);this.fabric.add(i),i.sampleactionpositionid=e.sampleactionpositionid}),this.zindex()}loadMap(e){const s=e<this.mapsToLoad.length?this.mapsToLoad[e]:null;if(s){const[i,o]=s,a=this.draw.drawMap(i,o,this.props.currentSample);a&&a.then(c=>{c.mapid=i.mapid,c.subsampleid=i.subsampleid,this.fabric.add(c),this.mapLoadStatus(e),this.loadMap(e+1)}).catch(c=>{console.log("could not load map",i.mapid,c),this.loadMap(e+1)})}}clearMapStatus(e){this.props.actions.setMessage({type:"mapProgress",message:{text:"",timeout:e||2e3}})}mapLoadStatus(e){if(this.mapsToLoad.length===0){this.clearMapStatus(100);return}e===this.mapsToLoad.length-1?(this.props.actions.setMessage({type:"mapProgress",message:{text:"Maps loaded"}}),this.clearMapStatus(),this.zindex(),this.plotComposites()):this.props.actions.setMessage({type:"mapProgress",message:{text:`Loading maps: ${e}/${this.mapsToLoad.length-1}`}})}plotMaps(){if(this.remObjs("maps","mapid","maps"),!h.values(this.props.objects).length){console.log("waiting for objects");return}this.mapsToLoad=[];const e={};h.eachRight(this.props.maps,s=>{const i=h.find(this.objs.rois,{subsampleid:s.subsampleid});if(!i){console.log("cant find object for map");return}const o=h.find(this.objs.maps,{mapid:s.mapid});if(s.opacity===0){o&&(h.remove(this.objs.maps,o),this.fabric.remove(o),e[o.subsampleid]===o.mapid&&delete e[o.subsampleid]);return}const a=e[s.subsampleid];if(a&&a!==s.mapid){o&&(h.remove(this.objs.maps,o),this.fabric.remove(o));return}if(e[s.subsampleid]=s.mapid,o){this.draw.updateMap(o,s,i,this.props.currentSample);return}this.mapsToLoad.push([s,i])}),this.mapsToLoad.length===0?(this.zindex(),this.plotComposites()):this.loadMap(0)}plotComposites(){if(this.remObjs("composite","compositeid","composites"),!h.values(this.props.maps).length){console.log("waiting for maps");return}const e=[];return h.each(this.props.composites,s=>{const i=h.find(this.objs.rois,{subsampleid:s.subsampleid});if(!i){console.log("cant find object for composite");return}const o=h.find(this.objs.composite,{compositeid:s.compositeid});if(o){this.draw.updateComposite(o,s,i,this.props.maps);return}const a=this.draw.drawComposite(s,i,this.props.maps);a&&e.push(a.then(c=>{c.compositeid=s.compositeid,this.fabric.add(c)}).catch(c=>{console.log("could not load composite map",s.compositeid,c)}))}),Promise.all(e).then(()=>this.zindex())}plotSources({updatedUrl:e}={}){const s=[];return h.each(this.props.sources,i=>{const o=h.find(this.objs.sources,{sourceid:i.sourceid});if(o){if((i.url.startsWith("ws")&&this.props.disableOrigin||e)&&(o.dispose(),delete this.obj,this.objs.sources.splice(this.objs.sources.indexOf(o),1),!e))return null;if(!e)return this.draw.updateSource(o,i,this.props.sourceUrl,this.props.disableOrigin),null}if(i.url.startsWith("ws")&&this.props.disableOrigin)return null;const a=this.draw.drawSource(i,this.props.sourceUrl);a&&!this.props.disableOrigin&&s.push(a.then(c=>{c.sourceid=i.sourceid,c.origin=i.origin,this.fabric.add(c)}))}),Promise.all(s).then(()=>{this.props.clampOrigin&&(this.fabric.setZoom(this.getMinZoom()),this.clampViewPort(),this.draw.drawScaleBar({height:this.state.height})),this.plotMarkings(),this.plotObjects(),this.plotReferences(),this.plotImages(),this.plotPolylines(),this.props.clampOrigin&&this.props.clampTarget&&this.clampViewPort()})}plotPolylines(){this.props.config.options.polylines&&(h.each(this.props.sources,e=>{h.each(e.polylines,(d,p)=>{const m=h.find(this.objs.polyline,{key:p});if(m){this.draw.updatePolyline(m,d);return}const x=this.draw.drawPolyline(d);x.key=p,this.fabric.add(x),this.draw.updatePolyline(x,d)});const s=e.markings.beam,i=1024*4*Math.abs(e.pixelsize[0]),o=768*4*Math.abs(e.pixelsize[1]),a=[[s.position[0],s.position[1]],[s.position[0]+i,s.position[1]],[s.position[0]+i,s.position[1]-o],[s.position[0],s.position[1]-o],[s.position[0],s.position[1]]],c=h.find(this.objs.polyline,{key:"fov"});if(c){this.draw.updatePolyline(c,a);return}const l=this.draw.drawPolyline(a,!0);l.key="fov",this.fabric.add(l),this.draw.updatePolyline(l,a)}),this.zindex())}loadImage(e){const s=h.values(this.props.images),i=e<s.length?s[e]:null;if(i){const o=i.width*Math.abs(i.scalex)*this.fabric.getZoom(),a=2**Math.round(Math.log2(Math.min(o/i.width,1))),c=Math.floor(i.width*a)/i.width,l=h.find(this.objs.images,{sampleimageid:i.sampleimageid});if(l){if(!l.isOnScreen()){console.log("removing",l.sampleimageid),this.fabric.remove(l),h.remove(this.objs.images,l),this.loadImage(e+1);return}if(l.loadedScale!==c&&l.isOnScreen())this.fabric.remove(l),h.remove(this.objs.images,l);else{this.draw.updateImage(l,i,this.props.currentSample),this.loadImage(e+1);return}}const d=this.draw.drawImage(i,this.props.currentSample,c);d?d.then(p=>{p.image=i,p.sampleimageid=i.sampleimageid,this.fabric.add(p),this.imageLoadStatus(e),this.loadImage(e+1)}).catch(p=>{console.log("Error loading image",p)}):this.loadImage(e+1)}else this.remObjs("images","sampleimageid","images"),this.zindex()}clearStatus(e){this.props.actions.setMessage({type:"imageProgress",message:{text:"",timeout:e||2e3}})}imageLoadStatus(e){const s=h.values(this.props.images);if(s.length===0){this.clearStatus(100);return}e===s.length-1?(this.props.actions.setMessage({type:"imageProgress",message:{text:"Sample images loaded"}}),this.clearStatus(),this.remObjs("images","sampleimageid","images"),this.zindex()):this.props.actions.setMessage({type:"imageProgress",message:{text:`Loading sample images: ${e}/${s.length-1}`}})}plotImages(){this.loadImage(0)}remObjs(e,s,i){const o=[];h.each(this.objs[e],a=>{h.find(this.props[i],{[s]:a[s]})||o.push(a)}),h.each(o,a=>{h.remove(this.objs[e],a),this.fabric.remove(a)})}plotMarkings(){h.each(this.props.sources,e=>{h.each(e.markings,(s,i)=>{const o=h.find(this.objs.markings,{key:i});if(o){this.draw.updateMarking(o,s);return}const a=this.draw.drawMarking(s);this.fabric.add(a),a.key=i,a.origin=s.origin})}),this.zindex()}zindex(){h.each(h.values(this.zindexes).sort((e,s)=>e-s),e=>{const s=h.invert(this.zindexes)[e];h.each(this.objs[s],i=>{i.bringToFront()})}),h.each(["newRect","newLine","newLineText"],e=>{this[e]&&this[e].canvas&&this[e].bringToFront()}),this.draw.drawScaleBar({height:this.state.height})}componentDidMount(){super.componentDidMount(),this.setCurrentSampleMessage(),this.destroyed&&(this.destroyed=!1,this.initFabric())}componentDidUpdate(e){super.componentDidUpdate(e),e.currentSampleId!==this.props.currentSampleId&&this.setCurrentSampleMessage(),e.objects!==this.props.objects&&this.plotObjects(),e.maps!==this.props.maps&&this.plotMaps(),e.composites!==this.props.composites&&this.plotComposites(),e.images!==this.props.images&&this.plotImages(),(e.sources!==this.props.sources||e.disableOrigin!==this.props.disableOrigin)&&this.plotSources(),e.sourceUrl!==this.props.sourceUrl&&this.plotSources({updatedUrl:!0}),e.sampleActionPositions!==this.props.sampleActionPositions&&this.plotReferences(),e.selectedObjects!==this.props.selectedObjects&&this.updateSelectedObject(e),(e.clampOrigin!==this.props.clampOrigin&&this.props.clampOrigin||e.clampTarget!==this.props.clampTarget&&this.props.clampOrigin)&&this.setZoom(this.getMinZoom()),e.saveCanvas!==this.props.saveCanvas&&this.props.saveCanvas&&this.saveCanvas(),e.sourceHover!==this.props.sourceHover&&this.draw.drawCursor({text:this.props.sourceHover.x!==void 0?`x: ${this.props.sourceHover.x} y: ${this.props.sourceHover.y} lum: ${this.props.sourceHover.lum} | cx: ${this.props.sourceHover.xCentre} cy: ${this.props.sourceHover.yCentre}`:""}),e.currentAction!==this.props.currentAction&&this.plotObjects()}setCurrentSampleMessage(){this.props.actions.setMessage({type:"currentSample",message:{text:this.props.currentSampleId?"":"No sample selected. Please create one from the samples sidebar",timeout:0}})}dosetZoom(e,s=null,i=null){s&&i?(this.fabric.zoomToPoint({x:s,y:i},e),this.props.actions.setViewport({x:this.fabric.viewportTransform[4],y:this.fabric.viewportTransform[5]})):this.fabric.setZoom(e),this.clampViewPort(),h.each(this.objs,(o,a)=>{h.each(o,c=>{c.setCoords(),a==="polyline"&&this.draw.scaleStrokeWidth(c)})}),this.newRect&&this.draw.scaleStrokeWidth(this.newRect),this.plotMarkings(),this.plotObjects(),this.plotReferences(),this.debouncedPlotImages(),this.plotPolylines(),this.draw.drawScaleBar({height:this.state.height})}setZoom(e,s=null,i=null){this.dosetZoom(e,s,i),this.props.actions.setZoom(e)}doSetViewport(e){this.fabric.viewportTransform[4]=e.x,this.fabric.viewportTransform[5]=e.y}setViewport(e){this.doSetViewport(e),this.props.actions.setViewport(e)}clampViewPort(){const e=this.getClampTarget();if(e&&this.props.clampOrigin){const s=this.fabric.getZoom(),i=e.getScaledWidth()*s,o=e.getScaledHeight()*s,a=e.left*s,c=e.top*s,{minX:l,minY:d,maxX:p,maxY:m}=this.getClampTargetMinMax(a,c,i,o);this.fabric.viewportTransform[4]<p&&(this.fabric.viewportTransform[4]=p),this.fabric.viewportTransform[4]>l&&(this.fabric.viewportTransform[4]=l),this.fabric.viewportTransform[5]<m&&(this.fabric.viewportTransform[5]=m),this.fabric.viewportTransform[5]>d&&(this.fabric.viewportTransform[5]=d)}}clampZoom(e){return Math.min(Math.max(e,this.getMinZoom()),this.props.maxZoom)}getClampTarget(){if(this.props.clampTarget)return h.find(this.objs.polyline,{key:this.props.clampTarget});const e=h.find(this.objs.sources,{origin:!0});return e||h.find(this.objs.polyline,{key:"fov"})}getClampTargetMinMax(e,s,i,o){const a=this.props.clampTarget===""?i/2:0,c=this.props.clampTarget===""?o/2:0,l=-(i+e-a-this.state.width),d=-(o+s-c-this.state.height),p=-e+a,m=-s+c;return{minX:p,minY:m,maxX:l,maxY:d}}getMinZoom(){const e=this.getClampTarget();if(e&&this.props.clampOrigin){const s=e.getScaledWidth()-e.strokeWidth,i=e.getScaledHeight()-e.strokeWidth,o=this.state.width/s,a=this.state.height/i;return o<a?this.state.width/s:this.state.height/i}return this.props.minZoom}getNearest(e,s,i){let o=null;return this.props.drawSnap&&h.each(this.objs.rois,a=>{const c={tr:{left:a.left+a.width,top:a.top},bl:{left:a.left,top:a.top+a.height}};h.each(c,l=>{Math.sqrt((e-l.left)**2+(s-l.top)**2)<30/i&&(o={left:l.left,top:l.top})})}),o}findIntersectingImages(e){const s=h.filter(h.filter(this.objs.images,i=>i.intersectsWithObject(e)),i=>!this.props.images[i.sampleimageid].hide);return h.map(s,i=>this.props.images[i.sampleimageid])}getMarkOffset(){const e=h.find(this.objs.markings,{origin:!0}),s=h.find(this.objs.sources,{origin:!0});return s&&e?{x:e.left-s.left,y:e.top-s.top}:{x:0,y:0}}}w(se,"defaultProps",{maxZoom:8,minZoom:2e-5}),w(se,"propTypes",{currentSampleId:k.number,currentAction:k.string,objects:k.objectOf(k.shape({subsampleid:k.number.isRequired,x:k.number.isRequired,y:k.number.isRequired}))});function yt(r){const{currentAction:t,setAction:e,disableOrigin:s,clampOrigin:i,clampTarget:o,sourceUrl:a,setClampOrigin:c,viewport:l,setViewport:d,zoom:p,setZoom:m}=we(),{currentSampleId:x}=G(),{subSampleSelection:u,addSubSampleSelection:y,removeSubSampleSelection:v,resetSubSampleSelection:L}=Ae();return n.jsx(se,{...r,selectedObjects:u,currentSampleId:x,currentAction:t,disableOrigin:s,clampOrigin:i,clampTarget:o,sourceUrl:a,viewport:l,zoom:p,actions:{...r.actions,selectAction:e,setClampOrigin:c,setViewport:d,setZoom:m,addSelection:y,removeSelection:v,resetSelection:L}})}function St(r){return t=>{const{currentSampleId:e}=G(),{fetch:s,invalidateAll:i}=fe(),{data:o}=A(De.get,e?{sampleid:e}:null),a=e?{sampleid:e}:null,{data:c}=A(F.getList,a),{data:l}=A(Ye.getList,a),{data:d}=A(Be.getList,a),{data:p}=A(Xe.getList,a);function m(u){s(F.getList.push,u).then(()=>{i(F.getList)})}function x(u){const{subsampleid:y,...v}=u;s(F.partialUpdate,{subsampleid:y},v)}return n.jsx(r,{...t,currentSample:o,objects:c&&h.keyBy(c.rows,u=>u.subsampleid),maps:l&&h.keyBy(l.rows,u=>u.mapid),composites:d&&h.keyBy(d.rows,u=>u.compositeid),images:p&&h.keyBy(p.rows,u=>u.sampleimageid),actions:{...t.actions,addObject:m,updateObject:x}})}}const Ct=(r,t)=>({runningScan:ge.selector("runningScanid",r),sources:t.providers.twod.sources.selector("results",r),centreOnClick:f.selector("centreOnClick",r),drawQuantize:f.selector("drawQuantize",r),drawSnap:f.selector("drawSnap",r),multiROI:f.selector("multiROI",r),clampLOI:f.selector("clampLOI",r),cursor:f.selector("cursor",r),config:J.selector("config",r,"imageviewer"),saveCanvas:f.selector("saveCanvas",r),sourceHover:f.selector("sourceHover",r)}),Ot=(r,t)=>({actions:{fetchSources:()=>t.providers.twod.sources.fetch(),moveToCoords:e=>f.dispatch("MOVE_TO_COORDS",e),updateMarking:e=>t.providers.twod.markings.update(e),mosaic:e=>f.dispatch("MOSAIC",e),setMapPointer:e=>f.dispatch("SET_MAP_POINTER",e),setMapHover:e=>f.dispatch("SET_MAP_HOVER",e),setSourceHover:e=>f.dispatch("SET_SOURCE_HOVER",e),setMessage:e=>f.dispatch("SET_MESSAGE",e),clearSaveCanvas:()=>f.dispatch("CLEAR_SAVE_CANVAS"),saveCanvasRemote:e=>f.dispatch("SAVE_CANVAS_REMOTE",e),addToast:e=>J.dispatch("ADD_TOAST",e)}}),jt=be(B({metadata:q,twod:f})(W(Ct,Ot)(St(yt))));class oe extends C.Component{constructor(e){super(oe.getDefaultedProps(e));w(this,"timeout1",null);w(this,"timeout2",null);this.state={children:null,emptyChildren:!1,class:null}}static getDefaultedProps(e){const{timeout:s=3e3,transition:i=1e3,children:o}=e;return{timeout:s,transition:i,children:o}}static getDerivedStateFromProps(e){return e.children?{children:e.children,emptyChildren:!1}:e.children?null:{emptyChildren:!0}}componentDidUpdate(e,s){s.emptyChildren!==this.state.emptyChildren&&this.state.emptyChildren&&(this.timeout1=setTimeout(()=>{this.setState({class:"transistion-children-out"}),this.timeout2=setTimeout(()=>{this.setState({children:null,emptyChildren:!1,class:null})},this.props.transition)},this.props.timeout))}componentWillUnmount(){this.timeout1&&clearTimeout(this.timeout1),this.timeout2&&clearTimeout(this.timeout2)}render(){return n.jsx("div",{className:We("transistion-children",this.state.class),children:this.state.children})}}function xe(r){const t=h.map(r.messages,(e,s)=>n.jsx(oe,{timeout:e.timeout,children:e.text},s));return n.jsx("div",{className:"overlay-messages",children:t})}xe.propTypes={messages:k.objectOf(k.shape({text:k.node.isRequired,timeout:k.number})).isRequired};let kt=class extends C.Component{render(){return n.jsx(_e,{children:n.jsxs("div",{className:"h-100-container twod",children:[n.jsx(at,{}),n.jsx(jt,{className:"overlay",providers:this.props.providers}),n.jsx(xe,{messages:this.props.messages})]})})}};function Mt(r){return{messages:f.selector("messages",r)}}function Tt(r){return{actions:{}}}const It=W(Mt,Tt)(kt);function Ut(r){const{providers:t,yamlNode:e,...s}=r;return Ue(e,s),n.jsx(It,{providers:t})}export{Ut as default};
|