From 784b292692dbd444bb96df575625f415abf87a6d Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Thu, 30 Nov 2017 09:06:34 -0500 Subject: [PATCH] fix(Rendering): fix two issues with glyph scaling 1) the bounds when using scale by magnitude were too small when there were mure than one component. 2) The scaleFactor was use din the bounds but not in the actual rendering. --- Sources/Rendering/Core/Glyph3DMapper/index.js | 42 ++++++++++++------- .../Core/Mapper/test/testVectorComponent.js | 4 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Sources/Rendering/Core/Glyph3DMapper/index.js b/Sources/Rendering/Core/Glyph3DMapper/index.js index 25a491814e9..a470515fc28 100644 --- a/Sources/Rendering/Core/Glyph3DMapper/index.js +++ b/Sources/Rendering/Core/Glyph3DMapper/index.js @@ -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 @@ -200,9 +212,9 @@ 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) { @@ -210,7 +222,7 @@ function vtkGlyph3DMapper(publicAPI, model) { 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; @@ -218,9 +230,9 @@ function vtkGlyph3DMapper(publicAPI, model) { 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: diff --git a/Sources/Rendering/Core/Mapper/test/testVectorComponent.js b/Sources/Rendering/Core/Mapper/test/testVectorComponent.js index 528a5e628b9..d00b8f971e7 100644 --- a/Sources/Rendering/Core/Mapper/test/testVectorComponent.js +++ b/Sources/Rendering/Core/Mapper/test/testVectorComponent.js @@ -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');