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

Đang mở Phù hợp với người mới
#3,740 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
computer-graphics

Hướng nghiên cứu

Đọc Sources/Rendering/OpenGL/ImageCPRMapper/index.js quanh dòng 1230 và Sources/Rendering/WebGPU/ImageCPRMapper/index.js quanh dòng 682, sau đó lần theo vị trí CPU chuyển đổi các định dạng orientation thành quaternion. Kiểm tra các bài kiểm thử ImageCPRMapper hiện có để tìm chỗ bổ sung trường hợp cho đầu vào quaternion, mat4, mat3 và vec3. Hoàn thành khi mỗi định dạng orientation được hỗ trợ đều tạo ra cùng một hướng lấy mẫu trong cả hai mapper.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
1.5k
Fork
428
Merge trung bình
5 ngày 9 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Kitware/vtk-js

Tất cả issue của Kitware/vtk-js

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.