Skip to content

Commit

Permalink
Merge pull request #439 from Kitware/glyph_scaling_fix
Browse files Browse the repository at this point in the history
fix(Rendering): fix two issues with glyph scaling
  • Loading branch information
martinken authored Nov 30, 2017
2 parents 888b445 + 784b292 commit f58cf3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
42 changes: 27 additions & 15 deletions Sources/Rendering/Core/Glyph3DMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,29 @@ function vtkGlyph3DMapper(publicAPI, model) {
}
if (sArray && model.scaleMode !== ScaleModes.SCALE_BY_CONSTANT) {
const numC = sArray.getNumberOfComponents();
let maxScale = 0.0;
for (let i = 0; i < numC; ++i) {
const srange = sArray.getRange(i);
if (-srange[0] > maxScale) {
maxScale = -srange[0];
if (model.scaleMode === ScaleModes.SCALE_BY_COMPONENTS) {
let maxScale = 0.0;
for (let i = 0; i < numC; ++i) {
const srange = sArray.getRange(i);
if (-srange[0] > maxScale) {
maxScale = -srange[0];
}
if (srange[1] > maxScale) {
maxScale = srange[1];
}
}
if (srange[1] > maxScale) {
maxScale = srange[1];
scale *= maxScale;
} else {
const maxScale = [];
for (let i = 0; i < numC; ++i) {
const srange = sArray.getRange(i);
maxScale[i] = -srange[0];
if (srange[1] > maxScale[i]) {
maxScale[i] = srange[1];
}
}
scale *= vtkMath.norm(maxScale, numC);
}
scale *= maxScale;
}

// if orienting then use the radius
Expand Down Expand Up @@ -200,27 +212,27 @@ function vtkGlyph3DMapper(publicAPI, model) {

// scale data if appropriate
if (model.scaling) {
scale[0] = 1.0;
scale[1] = 1.0;
scale[2] = 1.0;
scale[0] = model.scaleFactor;
scale[1] = model.scaleFactor;
scale[2] = model.scaleFactor;
// Get the scalar and vector data
if (sArray) {
switch (model.scaleMode) {
case ScaleModes.SCALE_BY_MAGNITUDE:
for (let t = 0; t < numSComp; ++t) {
tuple[t] = sData[(i * numSComp) + t];
}
scale[0] = vtkMath.norm(tuple, numSComp);
scale[0] *= vtkMath.norm(tuple, numSComp);
scale[1] = scale[0];
scale[2] = scale[0];
break;
case ScaleModes.SCALE_BY_COMPONENTS:
for (let t = 0; t < numSComp; ++t) {
tuple[t] = sData[(i * numSComp) + t];
}
scale[0] = tuple[0];
scale[1] = tuple[1];
scale[2] = tuple[2];
scale[0] *= tuple[0];
scale[1] *= tuple[1];
scale[2] *= tuple[2];
break;
case ScaleModes.SCALE_BY_CONSTANT:
default:
Expand Down
4 changes: 2 additions & 2 deletions Sources/Rendering/Core/Mapper/test/testVectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import vtkSphereSource from 'vtk.js/Sources/Filters/Sources/SphereSource';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';

const { GetArray } = vtkMapper;

import baseline from './testVectorComponent.png';

const { GetArray } = vtkMapper;

test.onlyIfWebGL('Test VectorComponent', (t) => {
const gc = testUtils.createGarbageCollector(t);
t.ok('rendering', 'vtkMapper Vector Component');
Expand Down

0 comments on commit f58cf3a

Please sign in to comment.