Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 1x 1x 1x 1x 1x 18x 18x 18x 18x 18x 10x 2x 2x 1x 1x 43x 43x 43x 18x 18x 559x 18x 143x 461x 61x | import { getGPUTier } from 'detect-gpu'; import { SharedArrayBufferModes } from './enums'; import { getRenderingEngines } from './RenderingEngine/getRenderingEngine'; let csRenderInitialized = false; let useSharedArrayBuffer = true; let sharedArrayBufferMode = SharedArrayBufferModes.TRUE; import { deepMerge } from './utilities'; import { Cornerstone3DConfig } from './types'; // TODO: move sharedArrayBuffer into config. // TODO: change config into a class with methods to better control get/set const defaultConfig = { detectGPU: {}, rendering: { useCPURendering: false, // GPU rendering options preferSizeOverAccuracy: false, useNorm16Texture: false, // _hasNorm16TextureSupport(), strictZSpacingForVolumeViewport: true, }, // cache // ... }; let config = { detectGPU: {}, rendering: { useCPURendering: false, // GPU rendering options preferSizeOverAccuracy: false, useNorm16Texture: false, // _hasNorm16TextureSupport(), strictZSpacingForVolumeViewport: true, }, // cache // ... }; function _getGLContext(): RenderingContext { // Create canvas element. The canvas is not added to the // document itself, so it is never displayed in the // browser window. const canvas = document.createElement('canvas'); // Get WebGLRenderingContext from canvas element. const gl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); return gl; } // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example/Detect_WebGL function _hasActiveWebGLContext() { const gl = _getGLContext(); // Check if the context is either WebGLRenderingContext or WebGL2RenderingContext return ( gl instanceof WebGLRenderingContext || gl instanceof WebGL2RenderingContext ); } function hasSharedArrayBuffer() { try { /*eslint-disable no-constant-condition */ if (new SharedArrayBuffer(0)) { return true; } else { return false; } } catch { return false; } } // Todo: commenting this out until proper support for int16 textures // are added to browsers, current implementation is buggy // function _hasNorm16TextureSupport() { // const gl = _getGLContext(); // if (gl) { // const ext = (gl as WebGL2RenderingContext).getExtension( // 'EXT_texture_norm16' // ); // if (ext) { // return true; // } // } // return false; // } /** * Initialize the cornerstone-core. If the browser has a webgl context and * the detected gpu (by detect-gpu library) indicates the GPU is not low end we * will use webgl GPU rendering. Otherwise we will use cpu rendering. * * @param configuration - A configuration object * @returns A promise that resolves to true cornerstone has been initialized successfully. * @category Initialization */ async function init(configuration = {}I): Promise<boolean> { if (csRenderInitialized) { return csRenderInitialized; } // merge configs config = deepMerge(defaultConfig, configuration); // detectGPU const hasWebGLContext = _hasActiveWebGLContext(); if (!hasWebGLContext) { console.log('CornerstoneRender: GPU not detected, using CPU rendering'); config.rendering.useCPURendering = true; } else { const gpuTier = await getGPUTier(); config.detectGPU = gpuTier; console.log( 'CornerstoneRender: Using detect-gpu to get the GPU benchmark:', gpuTier ); if (gpuTier.tier < 1) { console.log( 'CornerstoneRender: GPU is not powerful enough, using CPU rendering' ); config.rendering.useCPURendering = true; } else { console.log('CornerstoneRender: using GPU rendering'); } } setUseSharedArrayBuffer(sharedArrayBufferMode); csRenderInitialized = true; return csRenderInitialized; } /** * It sets the useCPURenderingOnlyForDebugOrTests variable to the status value. * This only should be used for debugging or tests. DO NOT USE IT IF YOU ARE NOT * SURE WHAT YOU ARE DOING. * @param status - boolean * @category Initialization * */ function setUseCPURendering(status: boolean): void { config.rendering.useCPURendering = status; csRenderInitialized = true; _updateRenderingPipelinesForAllViewports(); } function setPreferSizeOverAccuracy(status: boolean): void { config.rendering.preferSizeOverAccuracy = status; csRenderInitialized = true; _updateRenderingPipelinesForAllViewports(); } /** * Resets the cornerstone-core init state if it has been manually * initialized to force use the cpu rendering (e.g., for tests) * @category Initialization * */ function resetUseCPURendering(): void { config.rendering.useCPURendering = !_hasActiveWebGLContext(); _updateRenderingPipelinesForAllViewports(); } /** * Returns whether or not we are using CPU rendering. * @returns true if we are using CPU rendering. * @category Initialization * */ function getShouldUseCPURendering(): boolean { return config.rendering.useCPURendering; } function setUseSharedArrayBuffer(mode: SharedArrayBufferModes | boolean): void { if (mode == SharedArrayBufferModes.AUTO) { sharedArrayBufferMode = SharedArrayBufferModes.AUTO; const hasSharedBuffer = hasSharedArrayBuffer(); if (!hasSharedBuffer) { useSharedArrayBuffer = false; console.warn( `CornerstoneRender: SharedArray Buffer not allowed, performance may be slower. Try ensuring page is cross-origin isolated to enable SharedArrayBuffer.` ); } else { useSharedArrayBuffer = true; // eslint-disable-next-line no-console console.log('CornerstoneRender: using SharedArrayBuffer'); } return; } if (mode == SharedArrayBufferModes.TRUE || mode == true) { sharedArrayBufferMode = SharedArrayBufferModes.TRUE; useSharedArrayBuffer = true; return; } if (mode == SharedArrayBufferModes.FALSE || mode == false) { sharedArrayBufferMode = SharedArrayBufferModes.FALSE; useSharedArrayBuffer = false; return; } } function resetUseSharedArrayBuffer(): void { setUseSharedArrayBuffer(sharedArrayBufferMode); } function getShouldUseSharedArrayBuffer(): boolean { return useSharedArrayBuffer; } /** * * Returns whether or not cornerstone-core has been initialized. * @returns true if the cornerstone render has been initialized. * @category Initialization * */ function isCornerstoneInitialized(): boolean { return csRenderInitialized; } /** * This function returns a copy of the config object. This is used to prevent the * config object from being modified by other parts of the program. * @returns A copy of the config object. */ function getConfiguration(): Cornerstone3DConfig { // return a copy // return JSON.parse(JSON.stringify(config)); return config; } function setConfiguration(c: Cornerstone3DConfig) { config = c; _updateRenderingPipelinesForAllViewports(); } /** * Update rendering pipelines for all viewports in all rendering engines. * @returns {void} * @category Initialization */ function _updateRenderingPipelinesForAllViewports(): void { getRenderingEngines().forEach((engine) => engine .getViewports() .forEach((viewport) => viewport.updateRenderingPipeline?.()) ); } export { init, getShouldUseCPURendering, getShouldUseSharedArrayBuffer, isCornerstoneInitialized, setUseCPURendering, setUseSharedArrayBuffer, setPreferSizeOverAccuracy, resetUseCPURendering, resetUseSharedArrayBuffer, getConfiguration, setConfiguration, }; |