Skip to content

Commit 8bfd688

Browse files
author
tpat
committed
Fixed scaling on rings and disks
1 parent e2f9205 commit 8bfd688

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/Modules/Visualization/ShowFieldGlyphs.cc

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ namespace SCIRun {
118118
GlyphGeom& glyphs,
119119
int glyph_type,
120120
Point& p1,
121-
Point& p2,
121+
Vector& dir,
122122
double radius,
123+
double scale,
123124
double ratio,
124125
int resolution,
125126
ColorRGB& node_color,
@@ -159,15 +160,18 @@ void GlyphBuilder::addGlyph(
159160
GlyphGeom& glyphs,
160161
int glyph_type,
161162
Point& p1,
162-
Point& p2,
163+
Vector& dir,
163164
double radius,
165+
double scale,
164166
double ratio,
165167
int resolution,
166168
ColorRGB& node_color,
167169
bool use_lines,
168170
bool render_base1 = false,
169171
bool render_base2 = false)
170172
{
173+
Point p2 = p1 + dir * scale;
174+
double scaled_radius = scale * radius;
171175
switch (glyph_type)
172176
{
173177
case RenderState::GlyphType::LINE_GLYPH:
@@ -179,29 +183,26 @@ void GlyphBuilder::addGlyph(
179183
case RenderState::GlyphType::COMET_GLYPH:
180184
{
181185
static const double sphere_extrusion = 0.0625f;
182-
Vector dir = (p2 - p1);
183-
glyphs.addComet(p1-dir, p1, radius, resolution, node_color, node_color, sphere_extrusion);
186+
glyphs.addComet(p1-(dir*scale), p1, scaled_radius, resolution, node_color, node_color, sphere_extrusion);
184187
break;
185188
}
186189
case RenderState::GlyphType::CONE_GLYPH:
187-
glyphs.addCone(p1, p2, radius, resolution, render_base1, node_color, node_color);
190+
glyphs.addCone(p1, p2, scaled_radius, resolution, render_base1, node_color, node_color);
188191
break;
189192
case RenderState::GlyphType::ARROW_GLYPH:
190-
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
193+
glyphs.addArrow(p1, p2, scaled_radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
191194
break;
192195
case RenderState::GlyphType::DISK_GLYPH:
193196
{
194-
Vector dir = (p2 - p1);
195-
Point new_p2 = p1 + dir * radius * 2.0;
196-
glyphs.addDisk(p1, new_p2, dir.length()*0.5, resolution, node_color, node_color);
197+
Point new_p2 = p1 + dir.normal() * scaled_radius * 2.0;
198+
double new_radius = dir.length() * scale * 0.5;
199+
glyphs.addDisk(p1, new_p2, new_radius, resolution, node_color, node_color);
197200
break;
198201
}
199202
case RenderState::GlyphType::RING_GLYPH:
200203
{
201-
double length = (p2 - p1).length();
202-
double major_radius = length * 0.5;
203-
double minor_radius = length * radius * 2.0;
204-
glyphs.addTorus(p1, p2, major_radius, minor_radius, resolution, node_color, node_color);
204+
double major_radius = dir.length() * scale * 0.5;
205+
glyphs.addTorus(p1, p2, major_radius, scaled_radius, resolution, node_color, node_color);
205206
break;
206207
}
207208
case RenderState::GlyphType::SPRING_GLYPH:
@@ -211,7 +212,7 @@ void GlyphBuilder::addGlyph(
211212
if (use_lines)
212213
glyphs.addLine(p1, p2, node_color, node_color);
213214
else
214-
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
215+
glyphs.addArrow(p1, p2, scaled_radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
215216
}
216217
}
217218

@@ -545,17 +546,20 @@ void GlyphBuilder::renderVectors(
545546
pinputVector = portHandler.getPrimaryVector(indices[i]);
546547

547548
// Normalize/Scale
549+
Vector dir = pinputVector;
548550
if(normalizeGlyphs)
549-
v = pinputVector.normal() * scale;
550-
else
551-
v = pinputVector * scale;
551+
dir.normalize();
552+
// v = pinputVector.normal() * scale;
553+
// else
554+
// v = pinputVector * scale;
552555

553556
// Calculate points
554-
p2 = points[i] + v;
555-
p3 = points[i] - v;
557+
// p2 = points[i] + v;
558+
// p3 = points[i] - v;
556559

557560
// Get radius
558-
radius = scale * radiusWidthScale / 2.0;
561+
// radius = scale * radiusWidthScale / 2.0;
562+
radius = radiusWidthScale / 2.0;
559563
if(state->getValue(ShowFieldGlyphs::SecondaryVectorParameterScalingType).toInt() == SecondaryVectorParameterScalingTypeEnum::USE_INPUT)
560564
radius *= portHandler.getSecondaryVectorParameter(indices[i]);
561565

@@ -566,12 +570,15 @@ void GlyphBuilder::renderVectors(
566570
// No need to render cylinder base if arrow is bidirectional
567571
bool render_cylinder_base = renderBases && !renderBidirectionaly;
568572

569-
addGlyph(glyphs, renState.mGlyphType, points[i], p2, radius, arrowHeadRatio,
573+
addGlyph(glyphs, renState.mGlyphType, points[i], dir, radius, scale, arrowHeadRatio,
570574
resolution, node_color, useLines, render_cylinder_base, renderBases);
571575

572576
if(renderBidirectionaly)
573-
addGlyph(glyphs, renState.mGlyphType, points[i], p3, radius, arrowHeadRatio,
577+
{
578+
Vector neg_dir = -dir;
579+
addGlyph(glyphs, renState.mGlyphType, points[i], neg_dir, radius, scale, arrowHeadRatio,
574580
resolution, node_color, useLines, render_cylinder_base, renderBases);
581+
}
575582
}
576583
}
577584

@@ -833,9 +840,9 @@ void GlyphBuilder::renderTensors(
833840
dir = eigvec1 * eigvals[0];
834841
else if(vector_eig_x_0 && vector_eig_z_0)
835842
dir = eigvec2 * eigvals[1];
836-
Point p1 = points[i] - dir*scale;
837-
Point p2 = points[i] + dir*scale;
838-
addGlyph(tensor_line_glyphs, RenderState::GlyphType::LINE_GLYPH, p1, p2, scale, scale, resolution, node_color, true);
843+
// Point p1 = points[i];
844+
// Point p2 = points[i] + dir;
845+
addGlyph(tensor_line_glyphs, RenderState::GlyphType::LINE_GLYPH, points[i], dir, scale, scale, scale, resolution, node_color, true);
839846
}
840847
// Render as order 2 or 3 tensor
841848
else

0 commit comments

Comments
 (0)