Skip to content

Commit 2d3eec9

Browse files
committed
refactor(LineGlyphRepresentation): offset cylinder center
With center offset, don't have to position glyph in center of segment, just position at state origin.
1 parent 3af071b commit 2d3eec9

File tree

1 file changed

+14
-14
lines changed
  • Sources/Widgets/Representations/LineGlyphRepresentation

1 file changed

+14
-14
lines changed

Sources/Widgets/Representations/LineGlyphRepresentation/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function vtkLineGlyphRepresentation(publicAPI, model) {
6767
source: publicAPI,
6868
glyph: vtkCylinderSource.newInstance({
6969
direction: [1, 0, 0],
70+
center: [0.5, 0, 0],
71+
capping: false,
7072
}),
7173
mapper: vtkGlyph3DMapper.newInstance({
7274
orientationArray: 'directions',
@@ -111,13 +113,21 @@ function vtkLineGlyphRepresentation(publicAPI, model) {
111113
3
112114
).getData();
113115

114-
const pos = []; // scratch
116+
const tempVector = []; // scratch
115117
for (let point = 1; point < lines.length - 1; point++) {
118+
const glyph = (point - 1) * 3; // start of glyph's 3 components in the arrays
119+
120+
// With cylinder glyph's offset center, position at state origins.
121+
const origin = points[lines[point]];
122+
[
123+
glyphPositions[glyph],
124+
glyphPositions[glyph + 1],
125+
glyphPositions[glyph + 2],
126+
] = origin;
127+
116128
// Orient glyphs to next point.
117-
const eye = points[lines[point]];
118129
const target = points[lines[point + 1]];
119-
const direction = vtkMath.subtract(target, eye, pos);
120-
const glyph = (point - 1) * 3;
130+
const direction = vtkMath.subtract(target, origin, tempVector);
121131
[directions[glyph], directions[glyph + 1], directions[glyph + 2]] =
122132
direction;
123133

@@ -126,16 +136,6 @@ function vtkLineGlyphRepresentation(publicAPI, model) {
126136
lengths[glyph] = distance;
127137
lengths[glyph + 1] = 1;
128138
lengths[glyph + 2] = 1;
129-
130-
// Position glyph at center of line segment.
131-
vec3.normalize(pos, direction);
132-
vec3.scale(pos, pos, distance / 2);
133-
vec3.add(pos, eye, direction);
134-
[
135-
glyphPositions[glyph],
136-
glyphPositions[glyph + 1],
137-
glyphPositions[glyph + 2],
138-
] = pos;
139139
}
140140

141141
internalPolyData.getPoints().modified();

0 commit comments

Comments
 (0)