@cornerstonejs/core
Version:
Cornerstone3D Core
126 lines (125 loc) • 5.22 kB
JavaScript
import { RENDERING_DEFAULTS } from '../constants/index.js';
import { OrientationAxis, Events } from '../enums/index.js';
import cache from '../cache/cache.js';
import setDefaultVolumeVOI from './helpers/setDefaultVolumeVOI.js';
import triggerEvent from '../utilities/triggerEvent.js';
import { actorIsA } from '../utilities/actorCheck.js';
import BaseVolumeViewport from './BaseVolumeViewport.js';
class VolumeViewport3D extends BaseVolumeViewport {
constructor(props) {
super(props);
this.setSampleDistanceMultiplier = (multiplier) => {
const actors = this.getActors();
actors.forEach((actorEntry) => {
if (actorIsA(actorEntry, 'vtkVolume')) {
const actor = actorEntry.actor;
const mapper = actor.getMapper();
if (mapper && mapper.getInputData) {
const imageData = mapper.getInputData();
if (imageData) {
const spacing = imageData.getSpacing();
const defaultSampleDistance = (spacing[0] + spacing[1] + spacing[2]) / 6;
const sampleDistanceMultiplier = multiplier || 1;
let sampleDistance = defaultSampleDistance * sampleDistanceMultiplier;
if (sampleDistance !== undefined && mapper.setSampleDistance) {
const currentSampleDistance = mapper.getSampleDistance();
mapper.setSampleDistance(sampleDistance);
}
}
}
}
});
this.render();
};
this.getNumberOfSlices = () => {
return 1;
};
this.getRotation = () => 0;
this.getCurrentImageIdIndex = () => {
return 0;
};
this.getCurrentImageId = () => {
return null;
};
this.resetCameraForResize = () => {
return this.resetCamera({
resetPan: true,
resetZoom: true,
resetToCenter: true,
});
};
const { parallelProjection, orientation } = this.options;
const activeCamera = this.getVtkActiveCamera();
if (parallelProjection != null) {
activeCamera.setParallelProjection(parallelProjection);
}
if (orientation && orientation !== OrientationAxis.ACQUISITION) {
this.applyViewOrientation(orientation);
}
}
isInAcquisitionPlane() {
return false;
}
resetCamera({ resetPan = true, resetZoom = true, resetToCenter = true, } = {}) {
super.resetCamera({ resetPan, resetZoom, resetToCenter });
const activeCamera = this.getVtkActiveCamera();
if (activeCamera.getParallelProjection()) {
activeCamera.setClippingRange(-RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE, RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE);
}
else {
activeCamera.setClippingRange(RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS, RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE);
}
const renderer = this.getRenderer();
renderer.resetCameraClippingRange();
return true;
}
setSlabThickness(slabThickness, filterActorUIDs) {
return null;
}
setBlendMode(blendMode, filterActorUIDs, immediate) {
return null;
}
resetProperties(volumeId) {
const volumeActor = volumeId
? this.getActor(volumeId)
: this.getDefaultActor();
if (!volumeActor) {
throw new Error(`No actor found for the given volumeId: ${volumeId}`);
}
if (volumeActor.slabThickness) {
volumeActor.slabThickness = RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS;
this.viewportProperties.slabThickness = undefined;
this.updateClippingPlanesForActors(this.getCamera());
}
volumeId ||= this.getVolumeId();
const imageVolume = cache.getVolume(volumeId);
if (!imageVolume) {
throw new Error(`imageVolume with id: ${volumeId} does not exist in cache`);
}
setDefaultVolumeVOI(volumeActor.actor, imageVolume);
this._restoreVolumeRenderingDefaults(volumeActor, volumeId);
this.setCamera(this.initialCamera);
triggerEvent(this.element, Events.VOI_MODIFIED, super.getVOIModifiedEventDetail(volumeId));
}
getSliceIndex() {
return null;
}
setCamera(props) {
super.setCamera(props);
this.getRenderer().resetCameraClippingRange();
this.render();
}
setCameraClippingRange() {
const activeCamera = this.getVtkActiveCamera();
if (activeCamera.getParallelProjection()) {
activeCamera.setClippingRange(-RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE, RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE);
}
else {
activeCamera.setClippingRange(RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS, RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE);
}
}
resetSlabThickness() {
return null;
}
}
export default VolumeViewport3D;