From 2d3eec9b9b6822938db25c1a3b64160eb6cd2c3b Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 23 Aug 2023 10:14:36 -0400 Subject: [PATCH] refactor(LineGlyphRepresentation): offset cylinder center With center offset, don't have to position glyph in center of segment, just position at state origin. --- .../LineGlyphRepresentation/index.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/Widgets/Representations/LineGlyphRepresentation/index.js b/Sources/Widgets/Representations/LineGlyphRepresentation/index.js index aaaf86a1ad9..bf8d20664b1 100644 --- a/Sources/Widgets/Representations/LineGlyphRepresentation/index.js +++ b/Sources/Widgets/Representations/LineGlyphRepresentation/index.js @@ -67,6 +67,8 @@ function vtkLineGlyphRepresentation(publicAPI, model) { source: publicAPI, glyph: vtkCylinderSource.newInstance({ direction: [1, 0, 0], + center: [0.5, 0, 0], + capping: false, }), mapper: vtkGlyph3DMapper.newInstance({ orientationArray: 'directions', @@ -111,13 +113,21 @@ function vtkLineGlyphRepresentation(publicAPI, model) { 3 ).getData(); - const pos = []; // scratch + const tempVector = []; // scratch for (let point = 1; point < lines.length - 1; point++) { + const glyph = (point - 1) * 3; // start of glyph's 3 components in the arrays + + // With cylinder glyph's offset center, position at state origins. + const origin = points[lines[point]]; + [ + glyphPositions[glyph], + glyphPositions[glyph + 1], + glyphPositions[glyph + 2], + ] = origin; + // Orient glyphs to next point. - const eye = points[lines[point]]; const target = points[lines[point + 1]]; - const direction = vtkMath.subtract(target, eye, pos); - const glyph = (point - 1) * 3; + const direction = vtkMath.subtract(target, origin, tempVector); [directions[glyph], directions[glyph + 1], directions[glyph + 2]] = direction; @@ -126,16 +136,6 @@ function vtkLineGlyphRepresentation(publicAPI, model) { lengths[glyph] = distance; lengths[glyph + 1] = 1; lengths[glyph + 2] = 1; - - // Position glyph at center of line segment. - vec3.normalize(pos, direction); - vec3.scale(pos, pos, distance / 2); - vec3.add(pos, eye, direction); - [ - glyphPositions[glyph], - glyphPositions[glyph + 1], - glyphPositions[glyph + 2], - ] = pos; } internalPolyData.getPoints().modified();