|
| 1 | +import { TextureChannelMode } from 'vtk.js/Sources/Rendering/WebGPU/ImageMapper/Constants'; |
| 2 | + |
| 3 | +function textureSamplerMatches(textureView, options) { |
| 4 | + const sampler = textureView?.getSampler?.(); |
| 5 | + if (!sampler) { |
| 6 | + return false; |
| 7 | + } |
| 8 | + const current = sampler.getOptions(); |
| 9 | + return ( |
| 10 | + current.minFilter === options.minFilter && |
| 11 | + current.magFilter === options.magFilter && |
| 12 | + current.addressModeU === (options.addressModeU ?? 'clamp-to-edge') && |
| 13 | + current.addressModeV === (options.addressModeV ?? 'clamp-to-edge') && |
| 14 | + current.addressModeW === (options.addressModeW ?? 'clamp-to-edge') |
| 15 | + ); |
| 16 | +} |
| 17 | + |
| 18 | +function getTextureChannelMode(independentComponents, numberOfComponents) { |
| 19 | + if (independentComponents) { |
| 20 | + switch (numberOfComponents) { |
| 21 | + case 1: |
| 22 | + return TextureChannelMode.INDEPENDENT_1; |
| 23 | + case 2: |
| 24 | + return TextureChannelMode.INDEPENDENT_2; |
| 25 | + case 3: |
| 26 | + return TextureChannelMode.INDEPENDENT_3; |
| 27 | + default: |
| 28 | + return TextureChannelMode.INDEPENDENT_4; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + switch (numberOfComponents) { |
| 33 | + case 1: |
| 34 | + return TextureChannelMode.SINGLE; |
| 35 | + case 2: |
| 36 | + return TextureChannelMode.DEPENDENT_LA; |
| 37 | + case 3: |
| 38 | + return TextureChannelMode.DEPENDENT_RGB; |
| 39 | + default: |
| 40 | + return TextureChannelMode.DEPENDENT_RGBA; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +function getLUTRowCenterExpression(componentIndex, rowsVar = 'tfunRows') { |
| 45 | + return `${2 * componentIndex + 0.5} / ${rowsVar}`; |
| 46 | +} |
| 47 | + |
| 48 | +function getUseLabelOutline( |
| 49 | + property, |
| 50 | + independentComponents, |
| 51 | + numberOfComponents |
| 52 | +) { |
| 53 | + return ( |
| 54 | + property.getUseLabelOutline() && |
| 55 | + !independentComponents && |
| 56 | + numberOfComponents === 1 |
| 57 | + ); |
| 58 | +} |
| 59 | + |
| 60 | +function computeFnToString(property, fn, numberOfComponents) { |
| 61 | + const pwfun = fn.apply(property); |
| 62 | + if (pwfun) { |
| 63 | + const iComps = property.getIndependentComponents(); |
| 64 | + return `${property.getMTime()}-${iComps}-${numberOfComponents}`; |
| 65 | + } |
| 66 | + return '0'; |
| 67 | +} |
| 68 | + |
| 69 | +export { |
| 70 | + computeFnToString, |
| 71 | + getLUTRowCenterExpression, |
| 72 | + getTextureChannelMode, |
| 73 | + getUseLabelOutline, |
| 74 | + textureSamplerMatches, |
| 75 | +}; |
0 commit comments