|
@@ -5,7 +5,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
|
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
|
-import { UnitsMeshParams, UnitsTextureMeshParams, UnitsVisual, UnitsMeshVisual, UnitsTextureMeshVisual } from '../units-visual';
|
|
|
|
|
|
+import { UnitsMeshParams, UnitsTextureMeshParams, UnitsVisual, UnitsMeshVisual, UnitsTextureMeshVisual, StructureGroup } from '../units-visual';
|
|
import { GaussianDensityParams, computeUnitGaussianDensity, computeUnitGaussianDensityTexture2d, GaussianDensityProps, computeStructureGaussianDensity, computeStructureGaussianDensityTexture2d } from './util/gaussian';
|
|
import { GaussianDensityParams, computeUnitGaussianDensity, computeUnitGaussianDensityTexture2d, GaussianDensityProps, computeStructureGaussianDensity, computeStructureGaussianDensityTexture2d } from './util/gaussian';
|
|
import { VisualContext } from '../../visual';
|
|
import { VisualContext } from '../../visual';
|
|
import { Unit, Structure } from '../../../mol-model/structure';
|
|
import { Unit, Structure } from '../../../mol-model/structure';
|
|
@@ -18,14 +18,15 @@ import { TextureMesh } from '../../../mol-geo/geometry/texture-mesh/texture-mesh
|
|
import { extractIsosurface } from '../../../mol-gl/compute/marching-cubes/isosurface';
|
|
import { extractIsosurface } from '../../../mol-gl/compute/marching-cubes/isosurface';
|
|
import { Sphere3D } from '../../../mol-math/geometry';
|
|
import { Sphere3D } from '../../../mol-math/geometry';
|
|
import { ComplexVisual, ComplexMeshParams, ComplexMeshVisual, ComplexTextureMeshVisual, ComplexTextureMeshParams } from '../complex-visual';
|
|
import { ComplexVisual, ComplexMeshParams, ComplexMeshVisual, ComplexTextureMeshVisual, ComplexTextureMeshParams } from '../complex-visual';
|
|
-import { getUnitExtraRadius, getStructureExtraRadius } from './util/common';
|
|
|
|
|
|
+import { getUnitExtraRadius, getStructureExtraRadius, getVolumeSliceInfo } from './util/common';
|
|
import { WebGLContext } from '../../../mol-gl/webgl/context';
|
|
import { WebGLContext } from '../../../mol-gl/webgl/context';
|
|
|
|
|
|
const SharedParams = {
|
|
const SharedParams = {
|
|
...GaussianDensityParams,
|
|
...GaussianDensityParams,
|
|
ignoreHydrogens: PD.Boolean(false),
|
|
ignoreHydrogens: PD.Boolean(false),
|
|
- useGpu: PD.Boolean(false),
|
|
|
|
|
|
+ useGpu: PD.Boolean(true, { label: 'Try Use GPU' }),
|
|
};
|
|
};
|
|
|
|
+type SharedParams = typeof SharedParams
|
|
|
|
|
|
export const GaussianSurfaceMeshParams = {
|
|
export const GaussianSurfaceMeshParams = {
|
|
...UnitsMeshParams,
|
|
...UnitsMeshParams,
|
|
@@ -45,23 +46,36 @@ function gpuSupport(webgl: WebGLContext) {
|
|
return webgl.extensions.colorBufferFloat && webgl.extensions.textureFloat && webgl.extensions.blendMinMax && webgl.extensions.drawBuffers;
|
|
return webgl.extensions.colorBufferFloat && webgl.extensions.textureFloat && webgl.extensions.blendMinMax && webgl.extensions.drawBuffers;
|
|
}
|
|
}
|
|
|
|
|
|
-export function GaussianSurfaceVisual(materialId: number, props?: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) {
|
|
|
|
- return props?.useGpu && webgl && gpuSupport(webgl)
|
|
|
|
- ? GaussianSurfaceTextureMeshVisual(materialId)
|
|
|
|
- : GaussianSurfaceMeshVisual(materialId);
|
|
|
|
|
|
+function suitableForGpu(structure: Structure, props: PD.Values<SharedParams>, webgl: WebGLContext) {
|
|
|
|
+ // lower resolutions are about as fast on CPU vs integrated GPU,
|
|
|
|
+ // very low resolutions have artifacts when calculated on GPU
|
|
|
|
+ if (props.resolution > 1) return false;
|
|
|
|
+ // the GPU is much more memory contraint, especially true for integrated GPUs,
|
|
|
|
+ // being conservative here still allows for small and medium sized assemblies
|
|
|
|
+ const d = webgl.maxTextureSize / 3;
|
|
|
|
+ const { areaCells, maxAreaCells } = getVolumeSliceInfo(structure.boundary.box, props.resolution, d * d);
|
|
|
|
+ return areaCells < maxAreaCells;
|
|
}
|
|
}
|
|
|
|
|
|
-export function StructureGaussianSurfaceVisual(materialId: number, props?: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) {
|
|
|
|
- return props?.useGpu && webgl && gpuSupport(webgl)
|
|
|
|
- ? StructureGaussianSurfaceTextureMeshVisual(materialId)
|
|
|
|
- : StructureGaussianSurfaceMeshVisual(materialId);
|
|
|
|
|
|
+export function GaussianSurfaceVisual(materialId: number, structure: Structure, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) {
|
|
|
|
+ if (props.useGpu && webgl && gpuSupport(webgl) && suitableForGpu(structure, props, webgl)) {
|
|
|
|
+ return GaussianSurfaceTextureMeshVisual(materialId);
|
|
|
|
+ }
|
|
|
|
+ return GaussianSurfaceMeshVisual(materialId);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function StructureGaussianSurfaceVisual(materialId: number, structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) {
|
|
|
|
+ if (props.useGpu && webgl && gpuSupport(webgl) && suitableForGpu(structure, props, webgl)) {
|
|
|
|
+ return StructureGaussianSurfaceTextureMeshVisual(materialId);
|
|
|
|
+ }
|
|
|
|
+ return StructureGaussianSurfaceMeshVisual(materialId);
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
async function createGaussianSurfaceMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
|
|
async function createGaussianSurfaceMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
|
|
const { smoothness } = props;
|
|
const { smoothness } = props;
|
|
- const { transform, field, idField, radiusFactor } = await computeUnitGaussianDensity(structure, unit, props, ctx.webgl).runInContext(ctx.runtime);
|
|
|
|
|
|
+ const { transform, field, idField, radiusFactor } = await computeUnitGaussianDensity(structure, unit, props).runInContext(ctx.runtime);
|
|
|
|
|
|
const params = {
|
|
const params = {
|
|
isoLevel: Math.exp(-smoothness) / radiusFactor,
|
|
isoLevel: Math.exp(-smoothness) / radiusFactor,
|
|
@@ -94,8 +108,8 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
|
|
if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
|
|
},
|
|
},
|
|
- mustRecreate: (props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
- return props.useGpu && !!webgl;
|
|
|
|
|
|
+ mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
+ return props.useGpu && !!webgl && suitableForGpu(structureGroup.structure, props, webgl);
|
|
}
|
|
}
|
|
}, materialId);
|
|
}, materialId);
|
|
}
|
|
}
|
|
@@ -104,7 +118,7 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss
|
|
|
|
|
|
async function createStructureGaussianSurfaceMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
|
|
async function createStructureGaussianSurfaceMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
|
|
const { smoothness } = props;
|
|
const { smoothness } = props;
|
|
- const { transform, field, idField, radiusFactor } = await computeStructureGaussianDensity(structure, props, ctx.webgl).runInContext(ctx.runtime);
|
|
|
|
|
|
+ const { transform, field, idField, radiusFactor } = await computeStructureGaussianDensity(structure, props).runInContext(ctx.runtime);
|
|
|
|
|
|
const params = {
|
|
const params = {
|
|
isoLevel: Math.exp(-smoothness) / radiusFactor,
|
|
isoLevel: Math.exp(-smoothness) / radiusFactor,
|
|
@@ -136,8 +150,8 @@ export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexV
|
|
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
|
|
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
},
|
|
},
|
|
- mustRecreate: (props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
- return props.useGpu && !!webgl;
|
|
|
|
|
|
+ mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
+ return props.useGpu && !!webgl && suitableForGpu(structure, props, webgl);
|
|
}
|
|
}
|
|
}, materialId);
|
|
}, materialId);
|
|
}
|
|
}
|
|
@@ -190,8 +204,8 @@ export function GaussianSurfaceTextureMeshVisual(materialId: number): UnitsVisua
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
|
|
if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
|
|
},
|
|
},
|
|
- mustRecreate: (props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
- return !props.useGpu || !webgl;
|
|
|
|
|
|
+ mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
+ return !props.useGpu || !webgl || !suitableForGpu(structureGroup.structure, props, webgl);
|
|
},
|
|
},
|
|
dispose: (geometry: TextureMesh) => {
|
|
dispose: (geometry: TextureMesh) => {
|
|
geometry.vertexTexture.ref.value.destroy();
|
|
geometry.vertexTexture.ref.value.destroy();
|
|
@@ -246,8 +260,8 @@ export function StructureGaussianSurfaceTextureMeshVisual(materialId: number): C
|
|
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
|
|
if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
|
|
},
|
|
},
|
|
- mustRecreate: (props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
- return !props.useGpu || !webgl;
|
|
|
|
|
|
+ mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
|
|
|
|
+ return !props.useGpu || !webgl || !suitableForGpu(structure, props, webgl);
|
|
},
|
|
},
|
|
dispose: (geometry: TextureMesh) => {
|
|
dispose: (geometry: TextureMesh) => {
|
|
geometry.vertexTexture.ref.value.destroy();
|
|
geometry.vertexTexture.ref.value.destroy();
|