Skip to content
Snippets Groups Projects
Commit 3f297cf6 authored by Alexander Rose's avatar Alexander Rose
Browse files

cleaned-up gaussian surface code

parent e8e8870b
No related branches found
No related tags found
No related merge requests found
......@@ -26,8 +26,8 @@ export interface StructureRepresentationComponentState {
flatShaded?: boolean
resolutionFactor?: number
probeRadius?: number
isoValue?: number
radiusOffset?: number
smoothness?: number
}
export class StructureRepresentationComponent extends React.Component<StructureRepresentationComponentProps, StructureRepresentationComponentState> {
......@@ -40,8 +40,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR
flatShaded: (this.props.representation.props as any).flatShaded,
resolutionFactor: (this.props.representation.props as any).resolutionFactor,
probeRadius: (this.props.representation.props as any).probeRadius,
isoValue: (this.props.representation.props as any).isoValue,
radiusOffset: (this.props.representation.props as any).radiusOffset,
smoothness: (this.props.representation.props as any).smoothness,
}
componentWillMount() {
......@@ -57,8 +57,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR
flatShaded: (repr.props as any).flatShaded,
resolutionFactor: (repr.props as any).resolutionFactor,
probeRadius: (repr.props as any).probeRadius,
isoValue: (repr.props as any).isoValue,
radiusOffset: (repr.props as any).probeRadius,
smoothness: (repr.props as any).smoothness,
})
}
......@@ -73,8 +73,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR
if (state.flatShaded !== undefined) (props as any).flatShaded = state.flatShaded
if (state.resolutionFactor !== undefined) (props as any).resolutionFactor = state.resolutionFactor
if (state.probeRadius !== undefined) (props as any).probeRadius = state.probeRadius
if (state.isoValue !== undefined) (props as any).isoValue = state.isoValue
if (state.radiusOffset !== undefined) (props as any).probeRadius = state.radiusOffset
if (state.smoothness !== undefined) (props as any).smoothness = state.smoothness
await repr.createOrUpdate(props).run(
progress => console.log(Progress.format(progress))
......@@ -161,25 +161,25 @@ export class StructureRepresentationComponent extends React.Component<StructureR
>
</input>
</div> : '' }
{ this.state.isoValue !== undefined ? <div>
<span>Iso Value </span>
{ this.state.smoothness !== undefined ? <div>
<span>Smoothness </span>
<input type='range'
defaultValue={this.state.isoValue.toString()}
defaultValue={this.state.smoothness.toString()}
min='1'
max='3'
step='0.1'
onInput={(e) => this.update({ isoValue: parseFloat(e.currentTarget.value) })}
onInput={(e) => this.update({ smoothness: parseFloat(e.currentTarget.value) })}
>
</input>
</div> : '' }
{ this.state.probeRadius !== undefined ? <div>
<span>Probe Radius </span>
{ this.state.radiusOffset !== undefined ? <div>
<span>Radius Offset </span>
<input type='range'
defaultValue={this.state.probeRadius.toString()}
defaultValue={this.state.radiusOffset.toString()}
min='0'
max='10'
step='0.1'
onInput={(e) => this.update({ probeRadius: parseFloat(e.currentTarget.value) })}
onInput={(e) => this.update({ radiusOffset: parseFloat(e.currentTarget.value) })}
>
</input>
</div> : '' }
......
......@@ -68,10 +68,10 @@ export async function StructureView(viewer: Viewer, models: ReadonlyArray<Model>
const active: { [k: string]: boolean } = {
cartoon: true,
point: false,
surface: true,
surface: false,
ballAndStick: false,
carbohydrate: false,
spacefill: true,
spacefill: false,
distanceRestraint: false,
symmetryAxes: false,
// polymerSphere: false,
......
......@@ -29,8 +29,8 @@ export const DefaultStructureMeshProps = {
export type StructureMeshProps = typeof DefaultStructureMeshProps
export const DefaultStructurePointProps = {
...Point.DefaultProps,
...DefaultStructureProps,
...Point.DefaultProps
}
export type StructurePointProps = typeof DefaultStructurePointProps
......
......@@ -38,7 +38,7 @@ export function SurfaceRepresentation(): SurfaceRepresentation {
currentProps = Object.assign({}, DefaultSurfaceProps, currentProps, props)
return Task.create('Creating SurfaceRepresentation', async ctx => {
await gaussianSurfaceRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
await gaussianPointRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
// await gaussianPointRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
})
},
getLoci: (pickingId: PickingId) => {
......
......@@ -10,36 +10,22 @@ import { UnitsVisual, VisualUpdateState } from '..';
import { StructureElementIterator } from './util/element';
import { EmptyLoci } from 'mol-model/loci';
import { Vec3 } from 'mol-math/linear-algebra';
import { SizeThemeProps } from 'mol-view/theme/size';
import { UnitsPointVisual, DefaultUnitsPointProps } from '../units-visual';
import { computeGaussianDensity } from './util/gaussian';
import { Color } from 'mol-util/color';
import { ColorThemeProps } from 'mol-view/theme/color';
import { computeGaussianDensity, DefaultGaussianDensityProps } from './util/gaussian';
import { Point } from '../../../geometry/point/point';
import { PointBuilder } from '../../../geometry/point/point-builder';
import { SizeThemeProps } from 'mol-view/theme/size';
export const DefaultGaussianDensityPointProps = {
...DefaultUnitsPointProps,
...DefaultGaussianDensityProps,
sizeTheme: { name: 'uniform', value: 1.5 } as SizeThemeProps,
colorTheme: { name: 'uniform', value: Color(0xAAAAAA) } as ColorThemeProps,
sizeTheme: { name: 'uniform', value: 1 } as SizeThemeProps,
pointSizeAttenuation: false,
resolutionFactor: 7,
probeRadius: 0,
isoValue: 1.5,
}
export type GaussianDensityPointProps = typeof DefaultGaussianDensityPointProps
export interface GaussianDensityProps {
sizeTheme: SizeThemeProps
resolutionFactor: number
probeRadius: number
isoValue: number
}
export async function createGaussianDensityPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityProps, point?: Point) {
export async function createGaussianDensityPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityPointProps, point?: Point) {
const { transform, field: { space, data } } = await computeGaussianDensity(unit, structure, props).runAsChild(ctx)
const { dimensions, get } = space
......@@ -77,7 +63,9 @@ export function GaussianDensityPointVisual(): UnitsVisual<GaussianDensityPointPr
getLoci: () => EmptyLoci,
mark: () => false,
setUpdateState: (state: VisualUpdateState, newProps: GaussianDensityPointProps, currentProps: GaussianDensityPointProps) => {
if (newProps.resolutionFactor !== currentProps.resolutionFactor) state.createGeometry = true
if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true
if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
}
})
}
\ No newline at end of file
......@@ -11,33 +11,17 @@ import { Mesh } from '../../../geometry/mesh/mesh';
import { UnitsMeshVisual, DefaultUnitsMeshProps } from '../units-visual';
import { StructureElementIterator, getElementLoci, markElement } from './util/element';
import { computeMarchingCubes } from '../../../util/marching-cubes/algorithm';
import { SizeThemeProps } from 'mol-view/theme/size';
import { Color } from 'mol-util/color';
import { computeGaussianDensity } from './util/gaussian';
import { ColorThemeProps } from 'mol-view/theme/color';
import { computeGaussianDensity, DefaultGaussianDensityProps } from './util/gaussian';
export interface GaussianSurfaceMeshProps {
sizeTheme: SizeThemeProps
resolutionFactor: number
probeRadius: number
isoValue: number
}
async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianSurfaceMeshProps, mesh?: Mesh): Promise<Mesh> {
const { isoValue } = props
console.time('surface density')
async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianSurfaceProps, mesh?: Mesh): Promise<Mesh> {
const { smoothness } = props
const { transform, field } = await computeGaussianDensity(unit, structure, props).runAsChild(ctx)
console.timeEnd('surface density')
console.time('surface mc')
const surface = await computeMarchingCubes({
isoLevel: Math.exp(-isoValue),
isoLevel: Math.exp(-smoothness),
scalarField: field,
oldSurface: mesh
}).runAsChild(ctx)
console.timeEnd('surface mc')
Mesh.transformImmediate(surface, transform)
Mesh.computeNormalsImmediate(surface)
......@@ -47,19 +31,9 @@ async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, struct
export const DefaultGaussianSurfaceProps = {
...DefaultUnitsMeshProps,
linearSegments: 8,
radialSegments: 12,
aspectRatio: 5,
arrowFactor: 1.5,
flipSided: true,
// flatShaded: true,
alpha: 0.7,
colorTheme: { name: 'uniform' as 'uniform', value: Color(0xDDDDDD) } as ColorThemeProps,
...DefaultGaussianDensityProps,
resolutionFactor: 7,
probeRadius: 0,
isoValue: 1.5,
flipSided: true, // TODO should not be required
}
export type GaussianSurfaceProps = typeof DefaultGaussianSurfaceProps
......@@ -72,8 +46,8 @@ export function GaussianSurfaceVisual(): UnitsVisual<GaussianSurfaceProps> {
mark: markElement,
setUpdateState: (state: VisualUpdateState, newProps: GaussianSurfaceProps, currentProps: GaussianSurfaceProps) => {
if (newProps.resolutionFactor !== currentProps.resolutionFactor) state.createGeometry = true
if (newProps.probeRadius !== currentProps.probeRadius) state.createGeometry = true
if (newProps.isoValue !== currentProps.isoValue) state.createGeometry = true
if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true
if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
}
})
}
\ No newline at end of file
......@@ -8,24 +8,21 @@ import { Unit, Structure, StructureElement } from 'mol-model/structure';
import { RuntimeContext, Task } from 'mol-task'
import { Tensor, Vec3, Mat4 } from 'mol-math/linear-algebra';
import { Box3D } from 'mol-math/geometry';
import { SizeThemeProps, SizeTheme } from 'mol-view/theme/size';
import { SizeTheme } from 'mol-view/theme/size';
export interface GaussianDensityProps {
sizeTheme: SizeThemeProps
resolutionFactor: number
probeRadius: number
isoValue: number
export const DefaultGaussianDensityProps = {
resolutionFactor: 7,
radiusOffset: 0,
smoothness: 1.5,
}
export type GaussianDensityProps = typeof DefaultGaussianDensityProps
function getDelta(box: Box3D, resolutionFactor: number) {
const extent = Vec3.sub(Vec3.zero(), box.max, box.min)
const n = Math.pow(Math.pow(2, resolutionFactor), 3)
const f = (extent[0] * extent[1] * extent[2]) / n
const s = Math.pow(f, 1 / 3)
const size = Vec3.zero()
// Vec3.scale(size, extent, s)
Vec3.ceil(size, Vec3.scale(size, extent, s))
const delta = Vec3.div(Vec3.zero(), extent, size)
return delta
......@@ -40,18 +37,18 @@ export function computeGaussianDensity(unit: Unit, structure: Structure, props:
}
export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityProps): Promise<Density> {
const { resolutionFactor, probeRadius, isoValue } = props
const { resolutionFactor, radiusOffset, smoothness } = props
const { elements } = unit;
const elementCount = elements.length;
const sizeTheme = SizeTheme(props.sizeTheme)
const sizeTheme = SizeTheme({ name: 'physical' })
const v = Vec3.zero()
const p = Vec3.zero()
const pos = unit.conformation.invariantPosition
const l = StructureElement.create(unit)
const pad = (probeRadius + 3) * 3 // TODO calculate max radius
const pad = (radiusOffset + 3) * 3 // TODO calculate max radius
const box = unit.lookup3d.boundary.box
const expandedBox = Box3D.expand(Box3D.empty(), box, Vec3.create(pad, pad, pad));
const extent = Vec3.sub(Vec3.zero(), expandedBox.max, expandedBox.min)
......@@ -67,9 +64,9 @@ export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure
const c = Vec3.zero()
const alpha = isoValue // smoothness
const alpha = smoothness
const _r2 = (probeRadius + 1.4 * 2)
const _r2 = (radiusOffset + 1.4 * 2)
const _radius2 = Vec3.create(_r2, _r2, _r2)
Vec3.mul(_radius2, _radius2, delta)
const updateChunk = Math.ceil(10000 / (_radius2[0] * _radius2[1] * _radius2[2]))
......@@ -84,10 +81,10 @@ export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure
Vec3.sub(v, v, min)
Vec3.mul(c, v, delta)
const radius = sizeTheme.size(l) + probeRadius
const radius = sizeTheme.size(l) + radiusOffset
const rSq = radius * radius
const r2 = (probeRadius + radius * 2)
const r2 = (radiusOffset + radius * 2)
const radius2 = Vec3.create(r2, r2, r2)
Vec3.mul(radius2, radius2, delta)
const r2sq = r2 * r2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment