How to smooth STL blob?

Here is my code. It is almost identical to this example

function StlModal(props: { ohifDicomSegBlob: any }) {
  const vtkContainer = useRef(null);

  async function getStl() {
    const stlRequest = await fetch('http://localhost:3004/orthanc/get-stl-from-dicom-seg', {
      method: "POST",
      body: ohifDicomSegBlob,
    });
    const stlBlob = await stlRequest.blob();

    const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({
      background: [0, 0, 0],
      rootContainer: vtkContainer.current,
    });
    const renderer = fullScreenRenderer.getRenderer();
    const renderWindow = fullScreenRenderer.getRenderWindow();

    const actor = vtkActor.newInstance();
    renderer.addActor(actor);

    const mapper = vtkMapper.newInstance({ interpolateScalarBeforeMapping: true });
    actor.setMapper(mapper);

    const cam = vtkCamera.newInstance();
    renderer.setActiveCamera(cam);
    cam.setFocalPoint(0, 0, 0);
    cam.setPosition(0, 0, 10);
    cam.setClippingRange(0.1, 50.0);

    const stlReader = vtkSTLReader.newInstance();

    const smoothFilter = vtkWindowedSincPolyDataFilter.newInstance({
      nonManifoldSmoothing: 0,
      numberOfIterations: 100,    
      passBand: 0.001,            
    });

    const arrayBuffer = await stlBlob.arrayBuffer();
    stlReader.parseAsArrayBuffer(arrayBuffer);

    smoothFilter.setInputConnection(stlReader.getOutputPort());
    mapper.setInputConnection(smoothFilter.getOutputPort());

    renderer.resetCamera();
    renderWindow.render();
  }

  return (
    <div>
      <div>
        <button onClick={() => getStl()}>preview</button>
        <button onClick={() => {}}>download</button>
      </div>

      <div ref={vtkContainer}></div>
    </div>
  );
}

but instead of vtkHttpDataSetReader i use vtkSTLReader.
In this component i get dicom-seg blob generated by OHIF. make request to get STL blob and render it using VTK.

But numberOfIterations: 100 and passBand: 0.001 has no effect. With them or without i see this
non-smooth result

I expected something like this

Did you try to merge coincident points before smoothing ?
Look at that option on the STL reader.

1 Like

i made these changes:

    const stlReader = vtkSTLReader.newInstance();
    const normals = vtkPolyDataNormals.newInstance();
    stlReader.setRemoveDuplicateVertices(1)

    const smoothFilter = vtkWindowedSincPolyDataFilter.newInstance({
      nonManifoldSmoothing: 0,
      numberOfIterations: 100,    
      passBand: 0.001,            
    });

    const arrayBuffer = await stlBlob.arrayBuffer();
    stlReader.parseAsArrayBuffer(arrayBuffer);

    smoothFilter.setInputConnection(stlReader.getOutputPort());
    mapper.setInputConnection(normals.getOutputPort());
    normals.setInputConnection(smoothFilter.getOutputPort());

and now it’s smooth. But very laggy, little mouse movement takes 10s, is it expected? from this point all depends on my cpu power?

i enabled these flags and it’s less laggy, but still unusable.
chrome://flags/#enable-unsafe-webgpu
chrome://flags/#enable-vulkan

In this example it’s not laggy after changing properties

Are you using WebGL or WebGPU ?
How many points does your STL file has ? How many after smoothing it ?

never mind.

i made these changes and its not laggy at all.

    smoothFilter.setInputConnection(stlReader.getOutputPort());
    mapper.setInputConnection(normals.getOutputPort());
    normals.setInputConnection(smoothFilter.getOutputPort());

    smoothFilter.setInputData(stlReader.getOutputData());
    mapper.setInputData(normals.getOutputData());
    normals.setInputData(smoothFilter.getOutputData());

so i just added setInputData after setInputConnection. I have no idea why it helped

What if you try the following ?

smoothFilter.setInputConnection(stlReader.getOutputPort());
normals.setInputConnection(smoothFilter.getOutputPort());
mapper.setInputConnection(normals.getOutputPort());
normals.update();