element-point.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Unit, Structure } from 'mol-model/structure';
  7. import { RuntimeContext } from 'mol-task'
  8. import { UnitsVisual, VisualUpdateState } from '..';
  9. import { getElementLoci, StructureElementIterator, markElement } from './util/element';
  10. import { Vec3 } from 'mol-math/linear-algebra';
  11. import { SizeThemeOptions, SizeThemeName } from 'mol-canvas3d/theme/size';
  12. import { UnitsPointsVisual, UnitsPointsParams } from '../units-visual';
  13. import { Points } from '../../../geometry/points/points';
  14. import { PointsBuilder } from '../../../geometry/points/points-builder';
  15. import { SelectParam, NumberParam, BooleanParam, paramDefaultValues } from 'mol-util/parameter';
  16. export const ElementPointParams = {
  17. ...UnitsPointsParams,
  18. sizeTheme: SelectParam<SizeThemeName>('Size Theme', '', 'uniform', SizeThemeOptions),
  19. sizeValue: NumberParam('Size Value', '', 3, 0, 20, 0.1),
  20. pointSizeAttenuation: BooleanParam('Point Size Attenuation', '', false),
  21. }
  22. export const DefaultElementPointProps = paramDefaultValues(ElementPointParams)
  23. export type ElementPointProps = typeof DefaultElementPointProps
  24. // TODO size
  25. export async function createElementPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: ElementPointProps, points: Points) {
  26. const elements = unit.elements
  27. const n = elements.length
  28. const builder = PointsBuilder.create(n, n / 10, points)
  29. const pos = unit.conformation.invariantPosition
  30. const p = Vec3.zero()
  31. for (let i = 0; i < n; ++i) {
  32. pos(elements[i], p)
  33. builder.add(p[0], p[1], p[2], i)
  34. if (i % 10000 === 0 && ctx.shouldUpdate) {
  35. await ctx.update({ message: 'Creating points', current: i, max: n });
  36. }
  37. }
  38. return builder.getPoints()
  39. }
  40. export function ElementPointVisual(): UnitsVisual<ElementPointProps> {
  41. return UnitsPointsVisual<ElementPointProps>({
  42. defaultProps: DefaultElementPointProps,
  43. createGeometry: createElementPoint,
  44. createLocationIterator: StructureElementIterator.fromGroup,
  45. getLoci: getElementLoci,
  46. mark: markElement,
  47. setUpdateState: (state: VisualUpdateState, newProps: ElementPointProps, currentProps: ElementPointProps) => {
  48. }
  49. })
  50. }