Hi everyone, I’m trying to manipulate itk.js and I’m stuck trying to understand the MeshToPolyData.js file in Pipelines. Does it really allow to do the Mesh/Polydata conversion ? if true, how can I use it ?
Thanks.
dzenanz
(Dženan Zukić)
May 13, 2020, 1:39pm
2
It should be similar to any other ITK filter. Here is the basic usage:
const unsigned int Dimension = 3;
using PixelType = float;
using MeshType = itk::Mesh< PixelType, Dimension >;
using MeshReaderType = itk::MeshFileReader< MeshType >;
MeshReaderType::Pointer meshReader = MeshReaderType::New();
meshReader->SetFileName( inputMeshFileName );
meshReader->Update();
using FilterType = itk::MeshToPolyDataFilter< MeshType >;
FilterType::Pointer filter = FilterType::New();
ITK_EXERCISE_BASIC_OBJECT_METHODS( filter, MeshToPolyDataFilter, ProcessObject );
filter->SetInput( meshReader->GetOutput() );
ShowProgress::Pointer showProgress = ShowProgress::New();
filter->AddObserver( itk::ProgressEvent(), showProgress );
ITK_TRY_EXPECT_NO_EXCEPTION( filter->Update() );
The test is written in C++, but it should be easy to translate to JavaScript.
1 Like
Thanks for your answer I’ll try to translate your example to Js.
This is used to convert an itk.js itk/Mesh to a vtk.js vtkPolyData for visualization.
Here is an example usage:
const pipelinePath = 'MeshToPolyData'
const args = ['mesh.json', 'polyData.json']
const desiredOutputs = [
{ path: args[1], type: IOTypes.vtkPolyData },
]
const inputs = [
{ path: args[0], type: IOTypes.Mesh, data: itkMesh },
]
is3D = itkMesh.meshType.dimension === 3
convert0 = performance.now()
return runPipelineBrowser(
null,
pipelinePath,
args,
desiredOutputs,
inputs
)
})
.then(function({ outputs, webWorker }) {
const convert1 = performance.now()
This file has been truncated. show original
Here is the result:
2 Likes