Skip to content

Commit

Permalink
Add STL reader for compatibility with STL shape files (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley authored Oct 20, 2023
1 parent 21431e9 commit 8a8bdb3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web/shapeworks/src/reader/image.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand All @@ -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()
Expand Down

0 comments on commit 8a8bdb3

Please sign in to comment.