Skip to content

Commit 784b292

Browse files
committed
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.
1 parent 2779ac0 commit 784b292

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

Sources/Rendering/Core/Glyph3DMapper/index.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,29 @@ function vtkGlyph3DMapper(publicAPI, model) {
9797
}
9898
if (sArray && model.scaleMode !== ScaleModes.SCALE_BY_CONSTANT) {
9999
const numC = sArray.getNumberOfComponents();
100-
let maxScale = 0.0;
101-
for (let i = 0; i < numC; ++i) {
102-
const srange = sArray.getRange(i);
103-
if (-srange[0] > maxScale) {
104-
maxScale = -srange[0];
100+
if (model.scaleMode === ScaleModes.SCALE_BY_COMPONENTS) {
101+
let maxScale = 0.0;
102+
for (let i = 0; i < numC; ++i) {
103+
const srange = sArray.getRange(i);
104+
if (-srange[0] > maxScale) {
105+
maxScale = -srange[0];
106+
}
107+
if (srange[1] > maxScale) {
108+
maxScale = srange[1];
109+
}
105110
}
106-
if (srange[1] > maxScale) {
107-
maxScale = srange[1];
111+
scale *= maxScale;
112+
} else {
113+
const maxScale = [];
114+
for (let i = 0; i < numC; ++i) {
115+
const srange = sArray.getRange(i);
116+
maxScale[i] = -srange[0];
117+
if (srange[1] > maxScale[i]) {
118+
maxScale[i] = srange[1];
119+
}
108120
}
121+
scale *= vtkMath.norm(maxScale, numC);
109122
}
110-
scale *= maxScale;
111123
}
112124

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

201213
// scale data if appropriate
202214
if (model.scaling) {
203-
scale[0] = 1.0;
204-
scale[1] = 1.0;
205-
scale[2] = 1.0;
215+
scale[0] = model.scaleFactor;
216+
scale[1] = model.scaleFactor;
217+
scale[2] = model.scaleFactor;
206218
// Get the scalar and vector data
207219
if (sArray) {
208220
switch (model.scaleMode) {
209221
case ScaleModes.SCALE_BY_MAGNITUDE:
210222
for (let t = 0; t < numSComp; ++t) {
211223
tuple[t] = sData[(i * numSComp) + t];
212224
}
213-
scale[0] = vtkMath.norm(tuple, numSComp);
225+
scale[0] *= vtkMath.norm(tuple, numSComp);
214226
scale[1] = scale[0];
215227
scale[2] = scale[0];
216228
break;
217229
case ScaleModes.SCALE_BY_COMPONENTS:
218230
for (let t = 0; t < numSComp; ++t) {
219231
tuple[t] = sData[(i * numSComp) + t];
220232
}
221-
scale[0] = tuple[0];
222-
scale[1] = tuple[1];
223-
scale[2] = tuple[2];
233+
scale[0] *= tuple[0];
234+
scale[1] *= tuple[1];
235+
scale[2] *= tuple[2];
224236
break;
225237
case ScaleModes.SCALE_BY_CONSTANT:
226238
default:

Sources/Rendering/Core/Mapper/test/testVectorComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import vtkSphereSource from 'vtk.js/Sources/Filters/Sources/SphereSource';
99
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
1010
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
1111

12-
const { GetArray } = vtkMapper;
13-
1412
import baseline from './testVectorComponent.png';
1513

14+
const { GetArray } = vtkMapper;
15+
1616
test.onlyIfWebGL('Test VectorComponent', (t) => {
1717
const gc = testUtils.createGarbageCollector(t);
1818
t.ok('rendering', 'vtkMapper Vector Component');

0 commit comments

Comments
 (0)