Kitware / vtk-js

Visualization Toolkit for the Web
https://kitware.github.io/vtk-js/
BSD 3-Clause "New" or "Revised" License
1.21k stars 370 forks source link

[Bug] vtkContourTriangulator seems like not working on the output of vtkCutter #2990

Closed sedghi closed 7 months ago

sedghi commented 7 months ago

Bug description

Initially, I experimented with the ContourTriangulator example. I increased the number of points, nbPoints, to 16000, and it performed efficiently. It did slow down a bit when I reached around 100,000 points, but that's not a concern at the moment.

However, when I obtain the points from the vtkCutter, which involves cutting through a surface, even if the resulting cut points are very small (~100), the vtkContourTriangulator remains inactive and fails silently, seems like.

Steps to reproduce

You can reproduce it two ways.

First: Here in the codesandbox Turn the flag on for the EnableContourTriangulator in line 18

Second: Run the vtkCutter example (the dragon) and add the following snippet at the end so that it runs after one second. This snippet will grab the output of the vtkCutter, create a polyData, and then feed it to the triangulator.

setTimeout(() => {
  const cutterOutput = cutter.getOutputData();
  const pointsRaw = cutterOutput.getPoints().getData();
  const linesRaw = cutterOutput.getLines().getData();

  const source = vtkPolyData.newInstance();
  const points = vtkPoints.newInstance({
    size: (pointsRaw.length / 3) * 3,
  });

  source.setPoints(points);
  const lines = vtkCellArray.newInstance();
  source.setLines(lines);

  let lineIndex = 1;
  let pointIndex = 0;
  for (let i = 0; i < pointsRaw.length / 3; i++) {
    points.setPoint(
      i,
      pointsRaw[pointIndex],
      pointsRaw[pointIndex + 1],
      pointsRaw[pointIndex + 2]
    );

    lines.insertNextCell([linesRaw[lineIndex], linesRaw[lineIndex + 1]]);
    lineIndex += 3;
    pointIndex += 3;
  }

  const triangulator = vtkContourTriangulator.newInstance();
  triangulator.setInputData(source);
  const triangulatorOutput = triangulator.getOutputData();

  const triangulatorMapper = vtkMapper.newInstance();
  triangulatorMapper.setInputData(triangulatorOutput);
  const triangulatorActor = vtkActor.newInstance();
  triangulatorActor.setMapper(triangulatorMapper);
  renderer.addActor(triangulatorActor);
}, 1000);

Detailed Behavior

Running vtkContourTriangulator does nothing (freezes the app) on the output of the vtkCutter

Expected Behavior

Should work similar to syntetic data

Environment

github-actions[bot] commented 7 months ago

:tada: This issue has been resolved in version 29.4.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

sedghi commented 7 months ago

@finetjul I tried it with a fix and this is what I see for my vtkCutter outputs (the code sandbox example), is this expected results?

CleanShot 2024-01-23 at 08 42 41

finetjul commented 7 months ago

I guess it is not what is expected...

What if you re-order the input points (and cells) so that they each follow each other ?

sedghi commented 7 months ago

I don't know how to order these points that are the output from the vtkCutter. Do you have any ideas?

finetjul commented 7 months ago

I meant to do it with your codesandbox example to see if the vtkContourTriangulator is performing better. There might still be a bug in the JS code...