Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
c1408cfa
Commit
c1408cfa
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
gaussian density api tweaks
parent
75425e7b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-math/geometry/gaussian-density.ts
+16
-1
16 additions, 1 deletion
src/mol-math/geometry/gaussian-density.ts
src/mol-math/geometry/gaussian-density/gpu.ts
+23
-14
23 additions, 14 deletions
src/mol-math/geometry/gaussian-density/gpu.ts
with
39 additions
and
15 deletions
src/mol-math/geometry/gaussian-density.ts
+
16
−
1
View file @
c1408cfa
...
@@ -11,6 +11,7 @@ import { PositionData, DensityData } from './common';
...
@@ -11,6 +11,7 @@ import { PositionData, DensityData } from './common';
import
{
GaussianDensityCPU
}
from
'
./gaussian-density/cpu
'
;
import
{
GaussianDensityCPU
}
from
'
./gaussian-density/cpu
'
;
import
{
WebGLContext
}
from
'
mol-gl/webgl/context
'
;
import
{
WebGLContext
}
from
'
mol-gl/webgl/context
'
;
import
{
Texture
}
from
'
mol-gl/webgl/texture
'
;
import
{
Texture
}
from
'
mol-gl/webgl/texture
'
;
import
{
GaussianDensityTexture2d
,
GaussianDensityTexture3d
}
from
'
./gaussian-density/gpu
'
;
// import { GaussianDensityGPU, GaussianDensityTexture } from './gaussian-density/gpu';
// import { GaussianDensityGPU, GaussianDensityTexture } from './gaussian-density/gpu';
const
GaussianDensityGPU
=
typeof
document
!==
'
undefined
'
const
GaussianDensityGPU
=
typeof
document
!==
'
undefined
'
...
@@ -58,8 +59,22 @@ export async function GaussianDensity(ctx: RuntimeContext, position: PositionDat
...
@@ -58,8 +59,22 @@ export async function GaussianDensity(ctx: RuntimeContext, position: PositionDat
}
}
export
function
computeGaussianDensityTexture
(
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
webgl
:
WebGLContext
,
texture
?:
Texture
)
{
export
function
computeGaussianDensityTexture
(
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
webgl
:
WebGLContext
,
texture
?:
Texture
)
{
return
_computeGaussianDensityTexture
(
webgl
.
isWebGL2
?
'
3d
'
:
'
2d
'
,
position
,
box
,
radius
,
props
,
webgl
,
texture
)
}
export
function
computeGaussianDensityTexture2d
(
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
webgl
:
WebGLContext
,
texture
?:
Texture
)
{
return
_computeGaussianDensityTexture
(
'
2d
'
,
position
,
box
,
radius
,
props
,
webgl
,
texture
)
}
export
function
computeGaussianDensityTexture3d
(
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
webgl
:
WebGLContext
,
texture
?:
Texture
)
{
return
_computeGaussianDensityTexture
(
'
2d
'
,
position
,
box
,
radius
,
props
,
webgl
,
texture
)
}
function
_computeGaussianDensityTexture
(
type
:
'
2d
'
|
'
3d
'
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
webgl
:
WebGLContext
,
texture
?:
Texture
)
{
if
(
!
GaussianDensityTexture
)
throw
'
GPU computation not supported on this platform
'
;
if
(
!
GaussianDensityTexture
)
throw
'
GPU computation not supported on this platform
'
;
return
Task
.
create
(
'
Gaussian Density
'
,
async
ctx
=>
{
return
Task
.
create
(
'
Gaussian Density
'
,
async
ctx
=>
{
return
await
GaussianDensityTexture
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
texture
);
return
type
===
'
2d
'
?
await
GaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
texture
)
:
await
GaussianDensityTexture3d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
texture
);
});
});
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-math/geometry/gaussian-density/gpu.ts
+
23
−
14
View file @
c1408cfa
...
@@ -57,34 +57,43 @@ export async function GaussianDensityGPU(ctx: RuntimeContext, position: Position
...
@@ -57,34 +57,43 @@ export async function GaussianDensityGPU(ctx: RuntimeContext, position: Position
// always use texture2d when the gaussian density needs to be downloaded from the GPU,
// always use texture2d when the gaussian density needs to be downloaded from the GPU,
// it's faster than texture3d
// it's faster than texture3d
// console.time('GaussianDensityTexture2d')
// console.time('GaussianDensityTexture2d')
const
{
scale
,
bbox
,
texture
,
dim
}
=
await
GaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
)
const
{
scale
,
bbox
,
texture
,
dim
}
=
await
calc
GaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
)
// console.timeEnd('GaussianDensityTexture2d')
// console.timeEnd('GaussianDensityTexture2d')
const
{
field
,
idField
}
=
await
fieldFromTexture2d
(
webgl
,
texture
,
dim
)
const
{
field
,
idField
}
=
await
fieldFromTexture2d
(
webgl
,
texture
,
dim
)
const
transform
=
Mat4
.
identity
()
return
{
field
,
idField
,
transform
:
getTransform
(
scale
,
bbox
)
}
Mat4
.
fromScaling
(
transform
,
scale
)
Mat4
.
setTranslation
(
transform
,
bbox
.
min
)
return
{
field
,
idField
,
transform
}
}
}
export
async
function
GaussianDensityTexture
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
oldTexture
?:
Texture
):
Promise
<
DensityTextureData
>
{
export
async
function
GaussianDensityTexture
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
oldTexture
?:
Texture
):
Promise
<
DensityTextureData
>
{
// console.time(`GaussianDensityTexture, ${webgl.isWebGL2 ? '3d' : '2d'}`)
return
webgl
.
isWebGL2
?
const
{
texture
,
scale
,
bbox
,
dim
}
=
webgl
.
isWebGL2
?
await
GaussianDensityTexture3d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
)
:
await
GaussianDensityTexture3d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
)
:
await
GaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
)
await
GaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
)
// console.timeEnd(`GaussianDensityTexture, ${webgl.isWebGL2 ? '3d' : '2d'}`)
}
export
async
function
GaussianDensityTexture2d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
oldTexture
?:
Texture
):
Promise
<
DensityTextureData
>
{
return
finalizeGaussianDensityTexture
(
await
calcGaussianDensityTexture2d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
))
}
export
async
function
GaussianDensityTexture3d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
oldTexture
?:
Texture
):
Promise
<
DensityTextureData
>
{
return
finalizeGaussianDensityTexture
(
await
calcGaussianDensityTexture3d
(
ctx
,
webgl
,
position
,
box
,
radius
,
props
,
oldTexture
))
}
function
finalizeGaussianDensityTexture
({
texture
,
scale
,
bbox
,
dim
}:
GaussianDensityTextureData
):
DensityTextureData
{
return
{
transform
:
getTransform
(
scale
,
bbox
),
texture
,
bbox
,
gridDimension
:
dim
}
}
function
getTransform
(
scale
:
Vec3
,
bbox
:
Box3D
)
{
const
transform
=
Mat4
.
identity
()
const
transform
=
Mat4
.
identity
()
Mat4
.
fromScaling
(
transform
,
scale
)
Mat4
.
fromScaling
(
transform
,
scale
)
Mat4
.
setTranslation
(
transform
,
bbox
.
min
)
Mat4
.
setTranslation
(
transform
,
bbox
.
min
)
return
transform
return
{
transform
,
texture
,
bbox
,
gridDimension
:
dim
}
}
}
//
//
async
function
GaussianDensityTexture2d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
texture
?:
Texture
)
{
type
GaussianDensityTextureData
=
{
texture
:
Texture
,
scale
:
Vec3
,
bbox
:
Box3D
,
dim
:
Vec3
}
async
function
calcGaussianDensityTexture2d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
texture
?:
Texture
):
Promise
<
GaussianDensityTextureData
>
{
const
{
smoothness
}
=
props
const
{
smoothness
}
=
props
const
{
drawCount
,
positions
,
radii
,
groups
,
delta
,
expandedBox
,
dim
}
=
await
prepareGaussianDensityData
(
ctx
,
position
,
box
,
radius
,
props
)
const
{
drawCount
,
positions
,
radii
,
groups
,
delta
,
expandedBox
,
dim
}
=
await
prepareGaussianDensityData
(
ctx
,
position
,
box
,
radius
,
props
)
...
@@ -144,7 +153,7 @@ async function GaussianDensityTexture2d(ctx: RuntimeContext, webgl: WebGLContext
...
@@ -144,7 +153,7 @@ async function GaussianDensityTexture2d(ctx: RuntimeContext, webgl: WebGLContext
return
{
texture
,
scale
:
Vec3
.
inverse
(
Vec3
.
zero
(),
delta
),
bbox
:
expandedBox
,
dim
}
return
{
texture
,
scale
:
Vec3
.
inverse
(
Vec3
.
zero
(),
delta
),
bbox
:
expandedBox
,
dim
}
}
}
async
function
GaussianDensityTexture3d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
texture
?:
Texture
)
{
async
function
calc
GaussianDensityTexture3d
(
ctx
:
RuntimeContext
,
webgl
:
WebGLContext
,
position
:
PositionData
,
box
:
Box3D
,
radius
:
(
index
:
number
)
=>
number
,
props
:
GaussianDensityGPUProps
,
texture
?:
Texture
)
:
Promise
<
GaussianDensityTextureData
>
{
const
{
smoothness
}
=
props
const
{
smoothness
}
=
props
const
{
drawCount
,
positions
,
radii
,
groups
,
delta
,
expandedBox
,
dim
}
=
await
prepareGaussianDensityData
(
ctx
,
position
,
box
,
radius
,
props
)
const
{
drawCount
,
positions
,
radii
,
groups
,
delta
,
expandedBox
,
dim
}
=
await
prepareGaussianDensityData
(
ctx
,
position
,
box
,
radius
,
props
)
...
@@ -340,7 +349,7 @@ async function fieldFromTexture2d(ctx: WebGLContext, texture: Texture, dim: Vec3
...
@@ -340,7 +349,7 @@ async function fieldFromTexture2d(ctx: WebGLContext, texture: Texture, dim: Vec3
// await ctx.readPixelsAsync(0, 0, width, height, image)
// await ctx.readPixelsAsync(0, 0, width, height, image)
ctx
.
readPixels
(
0
,
0
,
width
,
height
,
image
)
ctx
.
readPixels
(
0
,
0
,
width
,
height
,
image
)
//
debugTexture
(createImageData(image, width, height), 1/3)
//
printImageData
(createImageData(image, width, height), 1/3)
let
j
=
0
let
j
=
0
let
tmpCol
=
0
let
tmpCol
=
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment