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 | 290x 290x 290x 243323x 243323x 243323x 243323x 290x 50398x 290x 618x 128x 290x 290x 290x 290x 128x | import macro from '@kitware/vtk.js/macros';
import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
import { getProjectionScaleMatrix } from '../helpers/getProjectionScaleMatrix';
import { getNormalizedAspectRatio } from '../../utilities/getNormalizedAspectRatio';
import { mat4 } from 'gl-matrix';
interface ICameraInitialValues {
position?: number[];
focalPoint?: number[];
viewUp?: number[];
directionOfProjection?: number[];
parallelProjection?: boolean;
useHorizontalViewAngle?: boolean;
viewAngle?: number;
parallelScale?: number;
clippingRange?: number[];
windowCenter?: number[];
viewPlaneNormal?: number[];
useOffAxisProjection?: boolean;
screenBottomLeft?: number[];
screenBottomRight?: number[];
screenTopRight?: number[];
freezeFocalPoint?: boolean;
physicalTranslation?: number[];
physicalScale?: number;
physicalViewUp?: number[];
physicalViewNorth?: number[];
aspectRatio?: number[];
}
declare module '@kitware/vtk.js/Rendering/Core/Camera' {
export interface vtkCamera {
/**
* Get the aspectRatio of the viewport
* @defaultValue [1, 1]
*/
getAspectRatio(): [x: number, y: number];
/**
* Sets the viewport aspect ratio used for canvas-space stretching.
* The aspect ratio is applied along the canvas X and Y axes,
* independent of the image orientation.
*
* @param aspectRatio - [scaleX, scaleY] stretch factors applied along the canvas X and Y axes
*/
setAspectRatio(aspectRatio: [x: number, y: number]): boolean;
}
}
export type extendedVtkCamera = vtkCamera;
/**
* extendedVtkCamera - A derived class of the core vtkCamera class
*
* This customization is necessary because when need to handle stretched viewport
*
* @param {*} publicAPI The public API to extend
* @param {*} model The private model to extend.
*/
function extendedVtkCamera(publicAPI, model) {
model.classHierarchy.push('extendedVtkCamera');
// Keep original
const superGetProjectionMatrix = publicAPI.getProjectionMatrix;
/**
* getProjectionMatrix - A fork of vtkCamera's getProjectionMatrix method.
* This fork performs most of the same actions, but added handling for stretched viewport.
*/
publicAPI.getProjectionMatrix = (aspect, nearZ, farZ) => {
const matrix = superGetProjectionMatrix(aspect, nearZ, farZ);
const [sx, sy] = getNormalizedAspectRatio(model.aspectRatio);
Iif (sx !== 1.0 || sy !== 1.0) {
const scaleMatrix = getProjectionScaleMatrix([sx, sy]);
mat4.multiply(matrix, scaleMatrix, matrix);
}
return matrix;
};
publicAPI.getAspectRatio = () => {
return model.aspectRatio;
};
publicAPI.setAspectRatio = (aspectRatio) => {
model.aspectRatio = aspectRatio;
};
}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
aspectRatio: [1, 1],
};
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
vtkCamera.extend(publicAPI, model, initialValues);
macro.setGet(publicAPI, model, ['aspectRatio']);
// Object methods
extendedVtkCamera(publicAPI, model);
}
// ----------------------------------------------------------------------------
export const newInstance: (
initialValues?: ICameraInitialValues
) => extendedVtkCamera = macro.newInstance(extend, 'extendedVtkCamera');
// ----------------------------------------------------------------------------
export default { newInstance, extend };
|