diff --git a/src/mol-io/reader/ply/parse_data/data-model.ts b/src/mol-io/reader/ply/parse_data/data-model.ts index e02c061bb01f1f6a7d5d1b4c50138ccefd4c7ba9..d66ba1d36120ec6856ce8ed91804845244333959 100644 --- a/src/mol-io/reader/ply/parse_data/data-model.ts +++ b/src/mol-io/reader/ply/parse_data/data-model.ts @@ -1,6 +1,7 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * + * @author Schäfer, Marco <marco.schaefer@uni-tuebingen.de> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ @@ -27,17 +28,11 @@ export interface ply_form { readonly vertices: number[], readonly colors: number[], readonly normals: number[], - readonly faces: number[], + readonly faces: number[], } export function PlyStructure(vertexCount: number, faceCount: number, propertyCount: number, initialHead: string[], propertyNames: string[], properties: number[], vertices: number[], colors: number[], normals: number[], faces: number[]): ply_form { return {vertexCount, faceCount, propertyCount, initialHead: [...initialHead], propertyNames: [...propertyNames], properties: [...properties], vertices: [...vertices], colors: [...colors], normals: [...normals], faces: [...faces]}; } -export type PlyColumns = { [name: string]: PlyColumn } - -// export namespace CsvTable { -// export function empty(name: string): Table { -// return { rowCount: 0, name, fieldNames: [], getColumn(name: string) { return void 0; } }; -// }; -// } \ No newline at end of file +export type PlyColumns = { [name: string]: PlyColumn } \ No newline at end of file diff --git a/src/mol-io/reader/ply/read_data/data-source.ts b/src/mol-io/reader/ply/read_data/data-source.ts deleted file mode 100644 index 9a80b93640f5fc64f9b695fb74dc4ca46f1a2c21..0000000000000000000000000000000000000000 --- a/src/mol-io/reader/ply/read_data/data-source.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. - * - * @author David Sehnal <david.sehnal@gmail.com> - * - * Adapted from LiteMol - */ - -import { Task, RuntimeContext } from 'mol-task'; - -export function readFromFile(file: File) { - return <Task<number | string>>readFromFileInternal(file); -} - - -async function processFile(ctx: RuntimeContext, e: any) { - const data = (e.target as FileReader).result; - return data as string; -} - -function readData(ctx: RuntimeContext, action: string, data: XMLHttpRequest | FileReader): Promise<any> { - return new Promise<any>((resolve, reject) => { - data.onerror = (e: any) => { - const error = (<FileReader>e.target).error; - reject(error ? error : 'Failed.'); - }; - - data.onabort = () => reject(Task.Aborted('')); - - data.onprogress = (e: ProgressEvent) => { - if (e.lengthComputable) { - ctx.update({ message: action, isIndeterminate: false, current: e.loaded, max: e.total }); - } else { - ctx.update({ message: `${action} ${(e.loaded / 1024 / 1024).toFixed(2)} MB`, isIndeterminate: true }); - } - } - data.onload = (e: any) => resolve(e); - }); -} - -function readFromFileInternal(file: File): Task<string | number> { - let reader: FileReader | undefined = void 0; - return Task.create('Read File', async ctx => { - try { - reader = new FileReader(); - reader.readAsBinaryString(file); - - ctx.update({ message: 'Opening file...', canAbort: true }); - const e = await readData(ctx, 'Reading...', reader); - const result = processFile(ctx, e); - return result; - } finally { - reader = void 0; - } - }, () => { - if (reader) reader.abort(); - }); -} diff --git a/src/mol-io/reader/ply/read_data/data.ts b/src/mol-io/reader/ply/read_data/data.ts deleted file mode 100644 index d251173b54aee9ac9f65c1e388a7272ce91e4faf..0000000000000000000000000000000000000000 --- a/src/mol-io/reader/ply/read_data/data.ts +++ /dev/null @@ -1,60 +0,0 @@ -// /** -// * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. -// * -// * @author David Sehnal <david.sehnal@gmail.com> -// */ - -// import { PluginStateTransform } from '../../../../mol-plugin/state/objects'; -// import { PluginStateObject as SO } from '../../../../mol-plugin/state/objects'; -// import { Task } from 'mol-task'; -// import PLY from 'mol-io/reader/ply/parse_data/ply_parser' -// import { ParamDefinition as PD } from 'mol-util/param-definition'; -// import { Transformer } from 'mol-state'; -// import { readFromFile } from './data-source'; - -// export { ReadFile_ascii } -// type ReadFile_ascii = typeof ReadFile_ascii -// const ReadFile_ascii = PluginStateTransform.BuiltIn({ -// name: 'ReadFile_ascii', -// display: { name: 'ReadFile_ascii', description: 'Read string data from the specified file' }, -// from: SO.Root, -// to: [SO.Data.String], -// params: { -// file: PD.File(), -// label: PD.Optional(PD.Text('')), -// isBinary: PD.Optional(PD.Boolean(false, { description: 'If true, open file as as binary (string otherwise)' })) -// } -// })({ -// apply({ params: p }) { -// return Task.create('Open File', async ctx => { -// const data = await readFromFile(p.file).runInContext(ctx); -// return new SO.Data.String(data as string, { label: p.label ? p.label : p.file.name }); -// }); -// }, -// update({ oldParams, newParams, b }) { -// if (oldParams.label !== newParams.label) { -// (b.label as string) = newParams.label || oldParams.file.name; -// return Transformer.UpdateResult.Updated; -// } -// return Transformer.UpdateResult.Unchanged; -// }, -// isSerializable: () => ({ isSerializable: false, reason: 'Cannot serialize user loaded files.' }) -// }); - - -// export { ParsePLY } -// type ParsePLY = typeof ParsePLY -// const ParsePLY = PluginStateTransform.BuiltIn({ -// name: 'parse-ply', -// display: { name: 'Parse PLY', description: 'Parse PLY from String' }, -// from: [SO.Data.String], -// to: SO.Format.Ply -// })({ -// apply({ a }) { -// return Task.create('Parse PLY', async ctx => { -// const parsed = await (PLY(a.data).runInContext(ctx)); -// if (parsed.isError) throw new Error(parsed.message); -// return new SO.Format.Ply(parsed.result); -// }); -// } -// }); \ No newline at end of file diff --git a/src/mol-model/shape/formarts/ply/plyData_to_shape.ts b/src/mol-model/shape/formarts/ply/plyData_to_shape.ts index b93d38dc0879f56545ec88d2d7ce6b0e1da8203d..60194f2101916c8779455dcef6d0bbd6561166d7 100644 --- a/src/mol-model/shape/formarts/ply/plyData_to_shape.ts +++ b/src/mol-model/shape/formarts/ply/plyData_to_shape.ts @@ -1,3 +1,10 @@ +/** + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Schäfer, Marco <marco.schaefer@uni-tuebingen.de> + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + import {ply_form, PlyFile} from '../../../../mol-io/reader/ply/parse_data/data-model'; import {RuntimeContext, Task} from 'mol-task'; import {Mesh} from '../../../../mol-geo/geometry/mesh/mesh'; @@ -13,7 +20,6 @@ export interface MyData { faces: number[], colors: Color[], labels: string[], - transforms: number[] } function collectData_for_Shape(parsedData: ply_form): MyData { @@ -26,13 +32,12 @@ function collectData_for_Shape(parsedData: ply_form): MyData { faces: faces, colors: [], labels: [], - transforms: [] } for (let i = 0; i<parsedData.faceCount; i++) { data.colors[i] = Color.fromRgb(colors[faces[4*i+1]*3+0], colors[faces[4*i+1]*3+1], colors[faces[4*i+1]*3+2]); data.labels[i] = parsedData.properties[parsedData.propertyCount * faces[4*i+1] + 10].toString(); - //i.toString(); + // i.toString(); // data.transforms[i] = 0; } console.log('data', data); @@ -55,8 +60,8 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], normals: nu triangle_normals = [ normals[faces[4*i+1]*3], normals[faces[4*i+1]*3+1], normals[faces[4*i+1]*3+2], normals[faces[4*i+2]*3], normals[faces[4*i+2]*3+1], normals[faces[4*i+2]*3+2], normals[faces[4*i+3]*3], normals[faces[4*i+3]*3+1], normals[faces[4*i+3]*3+2]]; - triangle_indices = [0,1,2]; - //console.log(triangle_vertices) + triangle_indices = [0, 1, 2]; + // console.log(triangle_vertices) addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices) } let a = MeshBuilder.getMesh(builderState);