Browse Source

take ply property type into account for ui

Alexander Rose 6 years ago
parent
commit
ddaa970f8d

+ 4 - 0
src/mol-io/reader/ply/parser.ts

@@ -154,6 +154,7 @@ function parseTableElement(state: State, spec: TableElementSpec) {
     const { count, properties } = spec
     const propertyCount = properties.length
     const propertyNames: string[] = []
+    const propertyTypes: PlyType[] = []
     const propertyTokens: Tokens[] = []
     const propertyColumns = new Map<string, Column<number>>()
 
@@ -175,6 +176,7 @@ function parseTableElement(state: State, spec: TableElementSpec) {
         const { type, name } = properties[i]
         const column = TokenColumn(propertyTokens[i], getColumnSchema(type))
         propertyNames.push(name)
+        propertyTypes.push(type)
         propertyColumns.set(name, column)
     }
 
@@ -182,6 +184,7 @@ function parseTableElement(state: State, spec: TableElementSpec) {
         kind: 'table',
         rowCount: count,
         propertyNames,
+        propertyTypes,
         getProperty: (name: string) => propertyColumns.get(name)
     })
 }
@@ -225,6 +228,7 @@ function parseListElement(state: State, spec: ListElementSpec) {
         kind: 'list',
         rowCount: count,
         name: property.name,
+        type: property.dataType,
         value: (row: number) => {
             const start = offsets[row]
             const end = offsets[row + 1]

+ 2 - 0
src/mol-io/reader/ply/schema.ts

@@ -61,6 +61,7 @@ export interface PlyTable {
     readonly kind: 'table'
     readonly rowCount: number
     readonly propertyNames: ReadonlyArray<string>
+    readonly propertyTypes: ReadonlyArray<PlyType>
     getProperty(name: string): Column<number> | undefined
 }
 
@@ -73,5 +74,6 @@ export interface PlyList {
     readonly kind: 'list'
     readonly rowCount: number,
     readonly name: string,
+    readonly type: PlyType,
     value: (row: number) => PlyListValue
 }

+ 13 - 6
src/mol-model-formats/shape/ply.ts

@@ -22,12 +22,19 @@ import { deepClone } from 'mol-util/object';
 // TODO support 'edge' and 'material' elements, see https://www.mathworks.com/help/vision/ug/the-ply-format.html
 
 function createPlyShapeParams(vertex?: PlyTable) {
-    const options: [string, string][] = [['', '']]
+    const groupOptions: [string, string][] = [['', '']]
+    const colorOptions: [string, string][] = [['', '']]
     const defaultValues = { group: '', red: '', green: '', blue: '' }
     if (vertex) {
         for (let i = 0, il = vertex.propertyNames.length; i < il; ++i) {
             const name = vertex.propertyNames[i]
-            options.push([ name, name ])
+            const type = vertex.propertyTypes[i]
+            if (
+                type === 'uchar' || type === 'uint8' ||
+                type === 'ushort' || type === 'uint16' ||
+                type === 'uint' || type === 'uint32'
+            ) groupOptions.push([ name, name ])
+            if (type === 'uchar' || type === 'uint8') colorOptions.push([ name, name ])
         }
 
         // TODO hardcoded as convenience for data provided by MegaMol
@@ -43,9 +50,9 @@ function createPlyShapeParams(vertex?: PlyTable) {
 
         coloring: PD.MappedStatic(defaultValues.red && defaultValues.green && defaultValues.blue ? 'vertex' : 'uniform', {
             vertex: PD.Group({
-                red: PD.Select(defaultValues.red, options, { label: 'Red Property' }),
-                green: PD.Select(defaultValues.green, options, { label: 'Green Property' }),
-                blue: PD.Select(defaultValues.blue, options, { label: 'Blue Property' }),
+                red: PD.Select(defaultValues.red, colorOptions, { label: 'Red Property' }),
+                green: PD.Select(defaultValues.green, colorOptions, { label: 'Green Property' }),
+                blue: PD.Select(defaultValues.blue, colorOptions, { label: 'Blue Property' }),
             }, { isFlat: true }),
             uniform: PD.Group({
                 color: PD.Color(ColorNames.grey)
@@ -53,7 +60,7 @@ function createPlyShapeParams(vertex?: PlyTable) {
         }),
         grouping: PD.MappedStatic(defaultValues.group ? 'vertex' : 'none', {
             vertex: PD.Group({
-                group: PD.Select(defaultValues.group, options, { label: 'Group Property' }),
+                group: PD.Select(defaultValues.group, groupOptions, { label: 'Group Property' }),
             }, { isFlat: true }),
             none: PD.Group({ })
         }),