Skip to content

Commit

Permalink
refactor(LineGlyphRepresentation): offset cylinder center
Browse files Browse the repository at this point in the history
With center offset, don't have to position glyph in center of segment,
just position at state origin.
  • Loading branch information
PaulHax committed Aug 23, 2023
1 parent 3af071b commit 2d3eec9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Sources/Widgets/Representations/LineGlyphRepresentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down

0 comments on commit 2d3eec9

Please sign in to comment.