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
418ad749
Commit
418ad749
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
wip, ply-to-shape groupId mapping
parent
7e56e704
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-model-formats/shape/ply.ts
+12
-8
12 additions, 8 deletions
src/mol-model-formats/shape/ply.ts
src/mol-util/array.ts
+6
-6
6 additions, 6 deletions
src/mol-util/array.ts
with
18 additions
and
14 deletions
src/mol-model-formats/shape/ply.ts
+
12
−
8
View file @
418ad749
...
@@ -13,8 +13,9 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
...
@@ -13,8 +13,9 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
import
{
Mesh
}
from
'
mol-geo/geometry/mesh/mesh
'
;
import
{
Mesh
}
from
'
mol-geo/geometry/mesh/mesh
'
;
import
{
Shape
}
from
'
mol-model/shape
'
;
import
{
Shape
}
from
'
mol-model/shape
'
;
import
{
ChunkedArray
}
from
'
mol-data/util
'
;
import
{
ChunkedArray
}
from
'
mol-data/util
'
;
import
{
arrayMax
}
from
'
mol-util/array
'
;
async
function
getPlyMesh
(
ctx
:
RuntimeContext
,
vertex
:
PlyTable
,
face
:
PlyList
,
mesh
?:
Mesh
)
{
async
function
getPlyMesh
(
ctx
:
RuntimeContext
,
vertex
:
PlyTable
,
face
:
PlyList
,
groupIds
:
ArrayLike
<
number
>
,
mesh
?:
Mesh
)
{
const
builderState
=
MeshBuilder
.
createState
(
face
.
rowCount
,
face
.
rowCount
,
mesh
)
const
builderState
=
MeshBuilder
.
createState
(
face
.
rowCount
,
face
.
rowCount
,
mesh
)
const
{
vertices
,
normals
,
indices
,
groups
}
=
builderState
const
{
vertices
,
normals
,
indices
,
groups
}
=
builderState
...
@@ -28,15 +29,12 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
...
@@ -28,15 +29,12 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
const
nz
=
vertex
.
getProperty
(
'
nz
'
)
const
nz
=
vertex
.
getProperty
(
'
nz
'
)
if
(
!
nx
||
!
ny
||
!
nz
)
throw
new
Error
(
'
missing normal properties
'
)
if
(
!
nx
||
!
ny
||
!
nz
)
throw
new
Error
(
'
missing normal properties
'
)
const
atomid
=
vertex
.
getProperty
(
'
atomid
'
)
if
(
!
atomid
)
throw
new
Error
(
'
missing atomid property
'
)
for
(
let
i
=
0
,
il
=
vertex
.
rowCount
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
vertex
.
rowCount
;
i
<
il
;
++
i
)
{
if
(
i
%
10000
===
0
&&
ctx
.
shouldUpdate
)
await
ctx
.
update
({
current
:
i
,
max
:
il
,
message
:
`adding vertex
${
i
}
`
})
if
(
i
%
10000
===
0
&&
ctx
.
shouldUpdate
)
await
ctx
.
update
({
current
:
i
,
max
:
il
,
message
:
`adding vertex
${
i
}
`
})
ChunkedArray
.
add3
(
vertices
,
x
.
value
(
i
),
y
.
value
(
i
),
z
.
value
(
i
))
ChunkedArray
.
add3
(
vertices
,
x
.
value
(
i
),
y
.
value
(
i
),
z
.
value
(
i
))
ChunkedArray
.
add3
(
normals
,
nx
.
value
(
i
),
ny
.
value
(
i
),
nz
.
value
(
i
));
ChunkedArray
.
add3
(
normals
,
nx
.
value
(
i
),
ny
.
value
(
i
),
nz
.
value
(
i
));
ChunkedArray
.
add
(
groups
,
atomid
.
value
(
i
)
)
ChunkedArray
.
add
(
groups
,
groupIds
[
i
]
)
}
}
for
(
let
i
=
0
,
il
=
face
.
rowCount
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
face
.
rowCount
;
i
<
il
;
++
i
)
{
...
@@ -57,6 +55,11 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape?
...
@@ -57,6 +55,11 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape?
const
atomid
=
vertex
.
getProperty
(
'
atomid
'
)
const
atomid
=
vertex
.
getProperty
(
'
atomid
'
)
if
(
!
atomid
)
throw
new
Error
(
'
missing atomid property
'
)
if
(
!
atomid
)
throw
new
Error
(
'
missing atomid property
'
)
const
groupIds
=
atomid
.
toArray
({
array
:
Int32Array
})
const
maxGroupId
=
arrayMax
(
groupIds
)
// assumes uint group ids
const
groupIdMap
=
new
Uint32Array
(
maxGroupId
+
1
)
for
(
let
i
=
0
,
il
=
groupIds
.
length
;
i
<
il
;
++
i
)
groupIdMap
[
groupIds
[
i
]]
=
i
const
red
=
vertex
.
getProperty
(
'
red
'
)
const
red
=
vertex
.
getProperty
(
'
red
'
)
const
green
=
vertex
.
getProperty
(
'
green
'
)
const
green
=
vertex
.
getProperty
(
'
green
'
)
const
blue
=
vertex
.
getProperty
(
'
blue
'
)
const
blue
=
vertex
.
getProperty
(
'
blue
'
)
...
@@ -65,15 +68,16 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape?
...
@@ -65,15 +68,16 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: {}, shape?
const
face
=
plyFile
.
getElement
(
'
face
'
)
as
PlyList
const
face
=
plyFile
.
getElement
(
'
face
'
)
as
PlyList
if
(
!
face
)
throw
new
Error
(
'
missing face element
'
)
if
(
!
face
)
throw
new
Error
(
'
missing face element
'
)
const
mesh
=
await
getPlyMesh
(
ctx
,
vertex
,
face
,
shape
&&
shape
.
geometry
)
const
mesh
=
await
getPlyMesh
(
ctx
,
vertex
,
face
,
groupIds
,
shape
&&
shape
.
geometry
)
return
shape
||
Shape
.
create
(
return
shape
||
Shape
.
create
(
'
test
'
,
plyFile
,
mesh
,
'
test
'
,
plyFile
,
mesh
,
(
groupId
:
number
)
=>
{
(
groupId
:
number
)
=>
{
return
Color
.
fromRgb
(
red
.
value
(
groupId
),
green
.
value
(
groupId
),
blue
.
value
(
groupId
))
const
idx
=
groupIdMap
[
groupId
]
return
Color
.
fromRgb
(
red
.
value
(
idx
),
green
.
value
(
idx
),
blue
.
value
(
idx
))
},
},
()
=>
1
,
// size: constant
()
=>
1
,
// size: constant
(
groupId
:
number
)
=>
{
(
groupId
:
number
)
=>
{
return
atomid
.
value
(
groupId
).
toString
()
return
atomid
.
value
(
groupId
Map
[
groupId
]
).
toString
()
}
}
)
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-util/array.ts
+
6
−
6
View file @
418ad749
/**
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018
-2019
mol* contributors, licensed under MIT, See LICENSE file for more info.
*
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
*/
...
@@ -9,7 +9,7 @@ import { NumberArray } from './type-helpers';
...
@@ -9,7 +9,7 @@ import { NumberArray } from './type-helpers';
// TODO move to mol-math as Vector???
// TODO move to mol-math as Vector???
/** Get the maximum value in an array */
/** Get the maximum value in an array */
export
function
arrayMax
(
array
:
NumberArray
)
{
export
function
arrayMax
(
array
:
ArrayLike
<
number
>
)
{
let
max
=
-
Infinity
let
max
=
-
Infinity
for
(
let
i
=
0
,
il
=
array
.
length
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
array
.
length
;
i
<
il
;
++
i
)
{
if
(
array
[
i
]
>
max
)
max
=
array
[
i
]
if
(
array
[
i
]
>
max
)
max
=
array
[
i
]
...
@@ -18,7 +18,7 @@ export function arrayMax(array: NumberArray) {
...
@@ -18,7 +18,7 @@ export function arrayMax(array: NumberArray) {
}
}
/** Get the minimum value in an array */
/** Get the minimum value in an array */
export
function
arrayMin
(
array
:
NumberArray
)
{
export
function
arrayMin
(
array
:
ArrayLike
<
number
>
)
{
let
min
=
Infinity
let
min
=
Infinity
for
(
let
i
=
0
,
il
=
array
.
length
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
array
.
length
;
i
<
il
;
++
i
)
{
if
(
array
[
i
]
<
min
)
min
=
array
[
i
]
if
(
array
[
i
]
<
min
)
min
=
array
[
i
]
...
@@ -27,7 +27,7 @@ export function arrayMin(array: NumberArray) {
...
@@ -27,7 +27,7 @@ export function arrayMin(array: NumberArray) {
}
}
/** Get the sum of values in an array */
/** Get the sum of values in an array */
export
function
arraySum
(
array
:
NumberArray
,
stride
=
1
,
offset
=
0
)
{
export
function
arraySum
(
array
:
ArrayLike
<
number
>
,
stride
=
1
,
offset
=
0
)
{
const
n
=
array
.
length
const
n
=
array
.
length
let
sum
=
0
let
sum
=
0
for
(
let
i
=
offset
;
i
<
n
;
i
+=
stride
)
{
for
(
let
i
=
offset
;
i
<
n
;
i
+=
stride
)
{
...
@@ -37,12 +37,12 @@ export function arraySum(array: NumberArray, stride = 1, offset = 0) {
...
@@ -37,12 +37,12 @@ export function arraySum(array: NumberArray, stride = 1, offset = 0) {
}
}
/** Get the mean of values in an array */
/** Get the mean of values in an array */
export
function
arrayMean
(
array
:
NumberArray
,
stride
=
1
,
offset
=
0
)
{
export
function
arrayMean
(
array
:
ArrayLike
<
number
>
,
stride
=
1
,
offset
=
0
)
{
return
arraySum
(
array
,
stride
,
offset
)
/
(
array
.
length
/
stride
)
return
arraySum
(
array
,
stride
,
offset
)
/
(
array
.
length
/
stride
)
}
}
/** Get the root mean square of values in an array */
/** Get the root mean square of values in an array */
export
function
arrayRms
(
array
:
NumberArray
)
{
export
function
arrayRms
(
array
:
ArrayLike
<
number
>
)
{
const
n
=
array
.
length
const
n
=
array
.
length
let
sumSq
=
0
let
sumSq
=
0
for
(
let
i
=
0
;
i
<
n
;
++
i
)
{
for
(
let
i
=
0
;
i
<
n
;
++
i
)
{
...
...
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