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 | import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import cache from '../cache';
import { GeometryType } from '../enums';
import { IGeometry, PublicContourSetData, PublicSurfaceData } from '../types';
import { createContourSet } from './utils/contourSet/createContourSet';
import { createSurface } from './utils/surface/createSurface';
type GeometryOptions = {
type: GeometryType;
geometryData: PublicContourSetData | PublicSurfaceData;
};
/**
* Todo: currently we are not targeting loading geometry from a file.
* This is a placeholder for future work. For instance, separate loaders
* for .vti, .vtk, .obj, .dat etc. can be created and registered here.
*/
/**
* It creates a geometry object and caches it
* @param geometryId - A unique identifier for the geometry.
* @param options - GeometryOptions
* @returns A promise that resolves to a geometry object.
*/
async function createAndCacheGeometry(
geometryId: string,
options: GeometryOptions
): Promise<IGeometry> {
let geometry = cache.getGeometry(geometryId);
if (geometry) {
return geometry;
}
if (options.type === GeometryType.CONTOUR) {
geometry = createContourSet(
geometryId,
options.geometryData as PublicContourSetData
);
} else if (options.type === GeometryType.SURFACE) {
geometry = createSurface(
geometryId,
options.geometryData as PublicSurfaceData
);
} else {
throw new Error('Unknown geometry type, Only CONTOUR is supported');
}
const geometryLoadObject = {
promise: Promise.resolve(geometry),
};
await cache.putGeometryLoadObject(geometryId, geometryLoadObject);
return geometry;
}
export { createAndCacheGeometry };
|