[Bug] vtkImageCPRMapper: the shader receives the uniform orientation without conversion

Aperta Adatta ai principianti
#3,740 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript

Direzione di ricerca

Leggi Sources/Rendering/OpenGL/ImageCPRMapper/index.js intorno alla riga 1230 e Sources/Rendering/WebGPU/ImageCPRMapper/index.js intorno alla riga 682, poi segui il percorso per individuare dove la CPU converte i formati di orientamento in un quaternione. Controlla i test esistenti di ImageCPRMapper per trovare un punto in cui coprire gli input quaternion, mat4, mat3 e vec3. Il lavoro è completato quando ogni formato di orientamento supportato produce la stessa direzione di campionamento in entrambi i mapper.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type: bug 🐞
Bug description

The mapper accepts a uniform orientation as a quaternion, a mat4, a mat3 or a
vec3. The CPU side converts these values to a quaternion. But
Sources/Rendering/OpenGL/ImageCPRMapper/index.js:1230 sends
getUniformOrientation() to the vec4 shader uniform without conversion.
The WebGPU mapper (Sources/Rendering/WebGPU/ImageCPRMapper/index.js:682)
does the same. A mat4, mat3 or vec3 orientation gives a wrong sampling
direction.

Steps to reproduce
  1. Run this code:
import '@kitware/vtk.js/Rendering/Profiles/All';
import { mat4, quat } from 'gl-matrix';
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
import vtkImageCPRMapper from '@kitware/vtk.js/Rendering/Core/ImageCPRMapper';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
import vtkRenderWindow from '@kitware/vtk.js/Rendering/Core/RenderWindow';

// Render a CPR along z and return the red values of the middle row.
function renderMiddleRow(orientation) {
  // The value increases along y only.
  const values = new Float32Array(64);
  for (let i = 0; i < 64; i++) {
    values[i] = Math.floor(i / 4) % 4;
  }
  const image = vtkImageData.newInstance();
  image.setDimensions(4, 4, 4);
  image.getPointData().setScalars(vtkDataArray.newInstance({ values }));
  const centerline = vtkPolyData.newInstance();
  centerline.getPoints().setData(new Float32Array([1.5, 1.5, 0, 1.5, 1.5, 3]), 3);
  centerline.getLines().setData(new Uint16Array([2, 0, 1]));

  const mapper = vtkImageCPRMapper.newInstance();
  mapper.setUseUniformOrientation(true);
  mapper.setUniformOrientation(orientation);
  mapper.setImageData(image);
  mapper.setCenterlineData(centerline);
  mapper.setWidth(3);

  const actor = vtkImageSlice.newInstance();
  actor.setMapper(mapper);
  actor.getProperty().setColorWindow(3);
  actor.getProperty().setColorLevel(1.5);

  const renderer = vtkRenderer.newInstance();
  renderer.addActor(actor);
  const renderWindow = vtkRenderWindow.newInstance();
  renderWindow.addRenderer(renderer);
  const glWindow = renderWindow.newAPISpecificView('WebGL');
  glWindow.setContainer(document.body.appendChild(document.createElement('div')));
  glWindow.setSize(16, 16);
  renderWindow.addView(glWindow);
  renderer.resetCamera();
  renderWindow.render();
  return Array.from(glWindow.getPixelData(0, 8, 15, 8).filter((v, i) => i % 4 === 0));
}

// The same rotation of 90 degrees about z, as a quaternion and as a mat4.
const q = quat.setAxisAngle(quat.create(), [0, 0, 1], Math.PI / 2);
const m = mat4.fromRotation(mat4.create(), Math.PI / 2, [0, 0, 1]);
console.log('quat', renderMiddleRow(Array.from(q)).join(' '));
console.log('mat4', renderMiddleRow(Array.from(m)).join(' '));
Detailed Behavior

The output is:

quat 0 0 0 0 3 26 50 73 97 120 144 167 191 107 0 0
mat4 0 0 0 85 85 85 85 85 85 85 85 85 85 43 0 0

The quaternion samples along y and shows the gradient. The mat4 is the same
rotation, but the row is constant: the shader samples along a wrong direction.

Expected Behavior

The shader receives the converted quaternion. All the orientation formats
give the same image.

Environment
  • vtk.js version: master (67328bc3ef)
  • Browsers: Chromium (Playwright, Vitest 5 browser mode), WebGL2
  • OS: Windows 11
Lingua principale
JavaScript
Stelle
1.5k
Fork
428
Merge medio
5g 9h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Kitware/vtk-js

Tutte le issue di Kitware/vtk-js

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.