From 8a8bdb3c306e58e246fae9a2a08653c3b3427ecf Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Fri, 20 Oct 2023 16:43:37 -0400 Subject: [PATCH] Add STL reader for compatibility with STL shape files (#343) --- web/shapeworks/src/reader/image.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/web/shapeworks/src/reader/image.ts b/web/shapeworks/src/reader/image.ts index 277aa12c..a725973e 100644 --- a/web/shapeworks/src/reader/image.ts +++ b/web/shapeworks/src/reader/image.ts @@ -1,8 +1,8 @@ import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkPLYReader from 'vtk.js/Sources/IO/Geometry/PLYReader'; +import vtkSTLReader from 'vtk.js/Sources/IO/Geometry/STLReader'; import vtkPolyDataReader from 'vtk.js/Sources/IO/Legacy/PolyDataReader'; -import vtkStringArray from 'vtk.js/Sources/Common/Core/StringArray' import readImageArrayBuffer from 'itk/readImageArrayBuffer'; import ITKHelper from 'vtk.js/Sources/Common/DataModel/ITKHelper'; import axios from 'axios'; @@ -23,8 +23,7 @@ export default async function ( responseType: 'arraybuffer' })).data; - if( - filename.toLowerCase().endsWith('ply')){ + if(filename.toLowerCase().endsWith('ply')){ const reader = vtkPLYReader.newInstance(); await reader.parseAsArrayBuffer(arrayBuffer) shape = reader.getOutputData(); @@ -41,6 +40,10 @@ export default async function ( const reader = vtkPolyDataReader.newInstance(); await reader.setUrl(url) shape = reader.getOutputData(); + } else if (filename.toLowerCase().endsWith('stl')) { + const reader = vtkSTLReader.newInstance(); + await reader.parseAsArrayBuffer(arrayBuffer) + shape = reader.getOutputData(); } else { console.log('Unknown file type for', filename) shape = vtkPolyData.newInstance()