本文整理匯總了TypeScript中neuroglancer/util/geom.vec3.str方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript vec3.str方法的具體用法?TypeScript vec3.str怎麽用?TypeScript vec3.str使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類neuroglancer/util/geom.vec3
的用法示例。
在下文中一共展示了vec3.str方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: decodeJpegStack
export function decodeJpegStack(data: Uint8Array, chunkDataSize: vec3, numComponents: number) {
let parser = new JpegDecoder();
parser.parse(data);
// Just check that the total number pixels matches the expected value.
if (parser.width * parser.height !== chunkDataSize[0] * chunkDataSize[1] * chunkDataSize[2]) {
throw new Error(
`JPEG data does not have the expected dimensions: ` +
`width=${parser.width}, height=${parser.height}, ` +
`chunkDataSize=${vec3.str(chunkDataSize)}`);
}
if (parser.numComponents !== numComponents) {
throw new Error(
`JPEG data does not have the expected number of components: ` +
`components=${parser.numComponents}, expected=${numComponents}`);
}
if (parser.numComponents === 1) {
return parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
} else if (parser.numComponents === 3) {
let output = parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
return transposeArray2d(output, parser.width * parser.height, 3);
} else {
throw new Error(
`JPEG data has an unsupported number of components: components=${parser.numComponents}`);
}
}
示例2: decodeJpegStack
export function decodeJpegStack(data: Uint8Array, chunkDataSize: Vec3) {
let parser = new JpegDecoder();
parser.parse(data);
if (parser.numComponents !== 1) {
throw new Error('JPEG data does not have the expected number of components');
}
// Just check that the total number pixels matches the expected value.
if (parser.width * parser.height !== chunkDataSize[0] * chunkDataSize[1] * chunkDataSize[2]) {
throw new Error(`JPEG data does not have the expected dimensions: width=${parser.width}, height=${parser.height}, chunkDataSize=${vec3.str(chunkDataSize)}`);
}
return parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
}
示例3: defineShader
defineShader(builder: ShaderBuilder) {
super.defineShader(builder);
let local = (x: string) => 'compressedSegmentationChunkFormat_' + x;
builder.addUniform('highp vec2', 'uCompressedSegmentationTextureAccessCoefficients');
builder.addUniform('highp vec3', 'uSubchunkGridSize');
builder.addUniform('highp vec3', 'uChunkDataSize');
builder.addFragmentCode(glsl_getFortranOrderIndexFromNormalized);
builder.addFragmentCode(glsl_uint64);
// We add 0.5 to avoid being right at a texel boundary.
let fragmentCode = `
vec4 ${local('readTextureValue')}(float offset) {
offset += 0.5;
return texture2D(uVolumeChunkSampler,
vec2(fract(offset * uCompressedSegmentationTextureAccessCoefficients.x),
offset * uCompressedSegmentationTextureAccessCoefficients.y));
}
uint64_t getDataValue () {
const vec3 uSubchunkSize = ${vec3.str(this.subchunkSize)};
vec3 chunkPosition = getSubscriptsFromNormalized(vChunkPosition, uChunkDataSize);
// TODO: maybe premultiply this and store as uniform.
vec3 subchunkGridPosition = floor(chunkPosition / uSubchunkSize);
float subchunkGridOffset = getFortranOrderIndex(subchunkGridPosition, uSubchunkGridSize);
// TODO: Maybe just combine this offset into subchunkGridStrides.
float subchunkHeaderOffset = subchunkGridOffset * 2.0;
vec4 subchunkHeader0 = ${local('readTextureValue')}(subchunkHeaderOffset);
vec4 subchunkHeader1 = ${local('readTextureValue')}(subchunkHeaderOffset + 1.0);
float outputValueOffset = dot(subchunkHeader0.xyz, vec3(255, 256 * 255, 256 * 256 * 255));
float encodingBits = subchunkHeader0[3] * 255.0;
if (encodingBits > 0.0) {
vec3 subchunkPosition = floor(min(chunkPosition - subchunkGridPosition * uSubchunkSize, uSubchunkSize - 1.0));
float subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);
highp float encodedValueBaseOffset = dot(subchunkHeader1.xyz, vec3(255.0, 256.0 * 255.0, 256.0 * 256.0 * 255.0));
highp float encodedValueOffset = floor(encodedValueBaseOffset + subchunkOffset * encodingBits / 32.0);
vec4 encodedValue = ${local('readTextureValue')}(encodedValueOffset);
float wordOffset = mod(subchunkOffset * encodingBits, 32.0);
// If the value is in the first byte, then 0 <= wordOffset < 8.
// We need to mod by 2**encodedBits
float wordShifter = pow(2.0, -wordOffset);
float encodedValueMod = pow(2.0, encodingBits);
float encodedValueShifted;
if (wordOffset < 16.0) {
encodedValueShifted = dot(encodedValue.xy, vec2(255.0, 255.0 * 256.0));
} else {
encodedValueShifted = dot(encodedValue.zw, vec2(255.0 * 256.0 * 256.0, 255.0 * 256.0 * 256.0 * 256.0));
}
encodedValueShifted = floor(encodedValueShifted * wordShifter);
float decodedValue = mod(encodedValueShifted, encodedValueMod);
outputValueOffset += decodedValue * ${this.dataType === DataType.UINT64 ? '2.0' : '1.0'};
}
uint64_t value;
value.low = ${local('readTextureValue')}(outputValueOffset);
`;
if (this.dataType === DataType.UINT64) {
fragmentCode += `
value.high = ${local('readTextureValue')}(outputValueOffset+1.0);
`;
} else {
fragmentCode += `
value.high = vec4(0.0, 0.0, 0.0, 0.0);
`;
}
fragmentCode += `
return value;
}
`;
builder.addFragmentCode(fragmentCode);
}