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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 18170x 18170x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 232x 17742x 17742x 6416x 428x 6410x 12230x 428x 12230x | import { getRenderingEngines } from './RenderingEngine/getRenderingEngine'; let csRenderInitialized = false; import deepMerge from './utilities/deepMerge'; import type { Cornerstone3DConfig } from './types'; import CentralizedWebWorkerManager from './webWorkerManager/webWorkerManager'; import { getSupportedTextureFormats } from './utilities/textureSupport'; import { RenderingEngineModeEnum } from './enums'; // TODO: change config into a class with methods to better control get/set const defaultConfig: Cornerstone3DConfig = { gpuTier: { tier: 2 }, // Assume medium tier by default isMobile: false, // is mobile device rendering: { useCPURendering: false, // GPU rendering options preferSizeOverAccuracy: false, // Use new method by default for accurate full-width display useLegacyCameraFOV: false, strictZSpacingForVolumeViewport: true, /** * The rendering engine mode to use. * 'contextPool' is the a rendering engine that uses sequential rendering, pararllization and has enhanced support/performance for multi-monitor and high resolution displays. * 'tiled' is a rendering engine that uses tiled rendering. */ renderingEngineMode: RenderingEngineModeEnum.ContextPool, /** * The number of WebGL contexts to create. This is used for parallel rendering. * The default value is 7, which is suitable for mobile/desktop. */ webGlContextCount: 7, volumeRendering: { /** Multiplier for the calculated sample distance */ sampleDistanceMultiplier: 1, }, }, debug: { /** * Wether or not to show the stats overlay for debugging purposes, stats include: * - FPS Frames rendered in the last second. The higher the number the better. * - MS Milliseconds needed to render a frame. The lower the number the better. * - MB MBytes of allocated memory. (Run Chrome with --enable-precise-memory-info) */ statsOverlay: false, }, /** * Imports peer modules. * This may just fallback to the default import, but many packaging * systems don't deal with peer imports properly. */ peerImport: (moduleId) => null, }; let config: Cornerstone3DConfig = { ...defaultConfig, rendering: { ...defaultConfig.rendering }, }; let webWorkerManager: CentralizedWebWorkerManager | null = null; let canUseNorm16Texture = false; 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 _hasNorm16TextureSupport() { const supportedTextureFormats = getSupportedTextureFormats(); return supportedTextureFormats.norm16 && supportedTextureFormats.norm16Linear; } function isIOS() { Iif (/iPad|iPhone|iPod/.test(navigator.platform)) { return true; } else { return ( navigator.maxTouchPoints && navigator.maxTouchPoints > 2 && navigator.platform.includes('MacIntel') ); } } /** * Initialize the cornerstone-core. This function checks for WebGL context availability * to determine if GPU rendering is possible. By default, it assumes a medium GPU tier. * * It's the responsibility of the consumer application to provide accurate GPU tier information * if needed. Libraries like 'detect-gpu' can be used for this purpose, and the result can be * passed in the configuration object. * * If a WebGL context is available, GPU rendering will be used. Otherwise, it will fall back * to CPU rendering for supported operations. * * @param configuration - A configuration object, which can include GPU tier information * @returns A promise that resolves to true if cornerstone has been initialized successfully. * @category Initialization */ function init(configuration = config): boolean { Iif (csRenderInitialized) { return csRenderInitialized; } canUseNorm16Texture = _hasNorm16TextureSupport(); // merge configs config = deepMerge(defaultConfig, configuration); // mobile safe Iif (config.isMobile) { config.rendering.webGlContextCount = 1; } Iif (isIOS()) { if (configuration.rendering?.preferSizeOverAccuracy) { config.rendering.preferSizeOverAccuracy = true; } else { console.log( 'norm16 texture not supported, you can turn on the preferSizeOverAccuracy flag to use native data type, but be aware of the inaccuracy of the rendering in high bits' ); } } const hasWebGLContext = _hasActiveWebGLContext(); Iif (!hasWebGLContext) { console.log('CornerstoneRender: GPU not detected, using CPU rendering'); config.rendering.useCPURendering = true; } else { console.log('CornerstoneRender: using GPU rendering'); } csRenderInitialized = true; Iif (!webWorkerManager) { webWorkerManager = new CentralizedWebWorkerManager(); } return csRenderInitialized; } function getCanUseNorm16Texture(): boolean { return canUseNorm16Texture; } /** * 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, updateViewports = true): void { config.rendering.useCPURendering = status; csRenderInitialized = true; if (updateViewports) { _updateRenderingPipelinesForAllViewports(); } } function setPreferSizeOverAccuracy(status: boolean): void { config.rendering.preferSizeOverAccuracy = status; csRenderInitialized = true; _updateRenderingPipelinesForAllViewports(); } /** * Only IPhone IOS cannot render float textures right now due to the lack of support for OES_texture_float_linear. * So we should not use float textures on IOS devices. */ function canRenderFloatTextures(): boolean { Eif (!isIOS()) { return true; } return false; } /** * 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; } /** * * 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; } function resetInitialization(): void { csRenderInitialized = false; } /** * 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(); }); }); } function getWebWorkerManager() { if (!webWorkerManager) { webWorkerManager = new CentralizedWebWorkerManager(); } return webWorkerManager; } async function peerImport(moduleId: string) { return config.peerImport(moduleId); } export { init, getShouldUseCPURendering, isCornerstoneInitialized, setUseCPURendering, setPreferSizeOverAccuracy, resetUseCPURendering, getConfiguration, setConfiguration, getWebWorkerManager, canRenderFloatTextures, peerImport, resetInitialization, getCanUseNorm16Texture, }; |