本文整理汇总了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);
}