Skip to content

Commit 84d09e0

Browse files
author
tpat
committed
Added option to render bases for cones and arrows
1 parent 885e655 commit 84d09e0

File tree

6 files changed

+128
-62
lines changed

6 files changed

+128
-62
lines changed

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
207207
}
208208

209209
void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double ratio, int resolution,
210-
const ColorRGB& color1, const ColorRGB& color2)
210+
const ColorRGB& color1, const ColorRGB& color2, bool render_cylinder_base, bool render_cone_base)
211211
{
212212
Point mid((p1.x() * ratio + p2.x() * (1 - ratio)), (p1.y() * ratio + p2.y() * (1 - ratio)), (p1.z() * ratio + p2.z() * (1 - ratio)));
213213

214-
generateCylinder(p1, mid, radius / 6.0, radius / 6.0, resolution, color1, color2);
215-
generateCone(mid, p2, radius, resolution, false, color1, color2);
216-
// generateCylinder(mid, p2, radius, 0.0, resolution, color1, color2);
214+
generateCylinder(p1, mid, radius / 6.0, radius / 6.0, resolution, color1, color2, render_cylinder_base, false);
215+
generateCone(mid, p2, radius, resolution, render_cone_base, color1, color2);
217216
}
218217

219218
void GlyphGeom::addSphere(const Point& p, double radius, int resolution, const ColorRGB& color)
@@ -238,27 +237,29 @@ void GlyphGeom::addEllipsoid(const Point& p, Tensor& t, Vector& scaled_eigenvals
238237
}
239238

240239
void GlyphGeom::addCylinder(const Point& p1, const Point& p2, double radius, int resolution,
241-
const ColorRGB& color1, const ColorRGB& color2)
240+
const ColorRGB& color1, const ColorRGB& color2,
241+
bool renderBase1, bool renderBase2)
242242
{
243-
generateCylinder(p1, p2, radius, radius, resolution, color1, color2);
243+
generateCylinder(p1, p2, radius, radius, resolution, color1, color2, renderBase1, renderBase2);
244244
}
245245

246246
void GlyphGeom::addCylinder(const Point& p1, const Point& p2, double radius1, double radius2,
247-
int resolution, const ColorRGB& color1, const ColorRGB& color2)
247+
int resolution, const ColorRGB& color1, const ColorRGB& color2,
248+
bool renderBase1, bool renderBase2)
248249
{
249-
generateCylinder(p1, p2, radius1, radius2, resolution, color1, color2);
250+
generateCylinder(p1, p2, radius1, radius2, resolution, color1, color2, renderBase1, renderBase2);
250251
}
251252

252253
void GlyphGeom::addDisk(const Point& p1, const Point& p2, double radius, int resolution,
253254
const ColorRGB& color1, const ColorRGB& color2)
254255
{
255-
generateDisk(p1, p2, radius, radius, resolution, color1, color2);
256+
generateCylinder(p1, p2, radius, radius, resolution, color1, color2, true, true);
256257
}
257258

258259
void GlyphGeom::addCone(const Point& p1, const Point& p2, double radius, int resolution,
259-
bool renderBase, const ColorRGB& color1, const ColorRGB& color2)
260+
bool render_base, const ColorRGB& color1, const ColorRGB& color2)
260261
{
261-
generateCone(p1, p2, radius, resolution, renderBase, color1, color2);
262+
generateCone(p1, p2, radius, resolution, render_base, color1, color2);
262263
}
263264

264265
void GlyphGeom::addClippingPlane(const Point& p1, const Point& p2,
@@ -412,9 +413,9 @@ void GlyphGeom::generateCone(const Point& p1, const Point& p2, double radius,
412413
}
413414
}
414415

415-
void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
416-
double radius2, int resolution, const ColorRGB& color1,
417-
const ColorRGB& color2)
416+
void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius1,
417+
double radius2, int resolution, const ColorRGB& color1,
418+
const ColorRGB& color2, bool renderBase1, bool renderBase2)
418419
{
419420
resolution = resolution < 0 ? 20 : resolution;
420421
radius1 = radius1 < 0 ? 1.0 : radius1;
@@ -425,19 +426,26 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
425426
Vector crx = n.getArbitraryTangent();
426427
Vector u = Cross(crx, n).normal();
427428

428-
int points_per_loop = 4;
429+
int points_per_loop = 2 + renderBase1 + renderBase2;
429430

430431
// Add center points so flat sides can be drawn
431-
points_.push_back(Vector(p1));
432-
points_.push_back(Vector(p2));
433-
int p1_index = numVBOElements_;
434-
colors_.push_back(color1);
435-
normals_.push_back(n);
436-
numVBOElements_++;
437-
int p2_index = numVBOElements_;
438-
colors_.push_back(color2);
439-
normals_.push_back(-n);
440-
numVBOElements_++;
432+
int p1_index, p2_index;
433+
if(renderBase1)
434+
{
435+
points_.push_back(Vector(p1));
436+
p1_index = numVBOElements_;
437+
colors_.push_back(color1);
438+
normals_.push_back(n);
439+
numVBOElements_++;
440+
}
441+
if(renderBase2)
442+
{
443+
points_.push_back(Vector(p2));
444+
p2_index = numVBOElements_;
445+
colors_.push_back(color2);
446+
normals_.push_back(-n);
447+
numVBOElements_++;
448+
}
441449

442450
// Precalculate
443451
double length = (p2-p1).length();
@@ -460,13 +468,19 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
460468
normals_.push_back(normals);
461469

462470
// Points for base
463-
points_.push_back(radius1 * p + Vector(p1));
464-
colors_.push_back(color1);
465-
normals_.push_back(n);
466-
points_.push_back(radius2 * p + Vector(p2));
467-
colors_.push_back(color2);
468-
normals_.push_back(-n);
469-
numVBOElements_ += 4;
471+
if(renderBase1)
472+
{
473+
points_.push_back(radius1 * p + Vector(p1));
474+
colors_.push_back(color1);
475+
normals_.push_back(n);
476+
}
477+
if(renderBase2)
478+
{
479+
points_.push_back(radius2 * p + Vector(p2));
480+
colors_.push_back(color2);
481+
normals_.push_back(-n);
482+
}
483+
numVBOElements_ += points_per_loop;
470484
}
471485

472486
// Add indices
@@ -480,12 +494,19 @@ void GlyphGeom::generateDisk(const Point& p1, const Point& p2, double radius1,
480494
indices_.push_back(strips + points_per_loop + 1);
481495

482496
// Render base
483-
indices_.push_back(p1_index);
484-
indices_.push_back(strips + 2);
485-
indices_.push_back(strips + points_per_loop + 2);
486-
indices_.push_back(strips + 3);
487-
indices_.push_back(p2_index);
488-
indices_.push_back(strips + points_per_loop + 3);
497+
if(renderBase1)
498+
{
499+
indices_.push_back(p1_index);
500+
indices_.push_back(strips + 2);
501+
indices_.push_back(strips + points_per_loop + 2);
502+
}
503+
if(renderBase2)
504+
{
505+
// Increment 1 if base 1 is present
506+
indices_.push_back(strips + 2 + renderBase1);
507+
indices_.push_back(p2_index);
508+
indices_.push_back(strips + points_per_loop + 2 + renderBase1);
509+
}
489510
}
490511
}
491512

src/Graphics/Glyphs/GlyphGeom.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ namespace SCIRun {
5454
const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox);
5555

5656
void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double ratio, int resolution,
57-
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
57+
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2, bool render_cylinder_base, bool render_cone_base);
5858
void addSphere(const Core::Geometry::Point& p, double radius, int resolution, const Core::Datatypes::ColorRGB& color);
5959
void addBox(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, double scale, Core::Datatypes::ColorRGB& node_color);
6060
void addEllipsoid(const Core::Geometry::Point& p, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, int resolution, const Core::Datatypes::ColorRGB& color);
6161
void addCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
62-
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
62+
const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2,
63+
bool renderBase1 = false, bool renderBase2 = false);
6364
void addCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2,
64-
int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
65+
int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2,
66+
bool renderBase1 = false, bool renderBase2 = false);
67+
void generateCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1,
68+
double radius2, int resolution, const Core::Datatypes::ColorRGB& color1,
69+
const Core::Datatypes::ColorRGB& color2, bool renderBase1, bool renderBase2);
6570
void addCone(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
6671
bool renderBase, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
6772
void addDisk(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution,
@@ -106,7 +111,7 @@ namespace SCIRun {
106111
const Core::Geometry::Vector& normal, const Core::Datatypes::ColorRGB& node_color);
107112
void generateEllipsoid(const Core::Geometry::Point& center, Core::Geometry::Tensor& t, Core::Geometry::Vector& scaled_eigenvals, int resolution, const Core::Datatypes::ColorRGB& color, bool half);
108113
void generateCone(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, int resolution, bool renderBase, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
109-
void generateDisk(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
114+
/* void generateDisk(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2); */
110115
void generateLine(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2);
111116
void generatePoint(const Core::Geometry::Point& p, const Core::Datatypes::ColorRGB& color);
112117
void generatePlane(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2,

src/Interface/Modules/Visualization/ShowFieldGlyphs.ui

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<string>Dialog</string>
2727
</property>
2828
<layout class="QGridLayout" name="gridLayout_2">
29-
<item row="0" column="0" alignment="Qt::AlignLeft">
29+
<item row="0" column="0">
3030
<widget class="QGroupBox" name="groupBox">
3131
<property name="minimumSize">
3232
<size>
@@ -888,7 +888,7 @@
888888
<property name="geometry">
889889
<rect>
890890
<x>10</x>
891-
<y>210</y>
891+
<y>230</y>
892892
<width>291</width>
893893
<height>321</height>
894894
</rect>
@@ -1238,12 +1238,6 @@
12381238
</property>
12391239
</item>
12401240
</widget>
1241-
<zorder>secondaryVectorParameterScaleLabel</zorder>
1242-
<zorder>secondaryVectorParameterDoubleSpinBox_</zorder>
1243-
<zorder>secondaryVectorParameterUniformRButton_</zorder>
1244-
<zorder>secondaryVectorParameterPortRButton_</zorder>
1245-
<zorder>secondaryVectorParameterPortComboBox_</zorder>
1246-
<zorder>arrowsGroupBox_</zorder>
12471241
</widget>
12481242
<widget class="QGroupBox" name="arrowsGroupBox_">
12491243
<property name="enabled">
@@ -1643,6 +1637,33 @@
16431637
</widget>
16441638
</widget>
16451639
</widget>
1640+
<widget class="QCheckBox" name="renderWithBasesCheckBox_">
1641+
<property name="enabled">
1642+
<bool>true</bool>
1643+
</property>
1644+
<property name="geometry">
1645+
<rect>
1646+
<x>10</x>
1647+
<y>205</y>
1648+
<width>271</width>
1649+
<height>20</height>
1650+
</rect>
1651+
</property>
1652+
<property name="minimumSize">
1653+
<size>
1654+
<width>0</width>
1655+
<height>20</height>
1656+
</size>
1657+
</property>
1658+
<property name="font">
1659+
<font>
1660+
<strikeout>false</strikeout>
1661+
</font>
1662+
</property>
1663+
<property name="text">
1664+
<string>Render With Bases</string>
1665+
</property>
1666+
</widget>
16461667
<zorder>vectorsDisplayTypeComboBox_</zorder>
16471668
<zorder>vectorsResolutionSpinBox_</zorder>
16481669
<zorder>vectorResolutionLabel</zorder>
@@ -1651,6 +1672,7 @@
16511672
<zorder>vectorDisplayTypeLabel</zorder>
16521673
<zorder>vectorScalingGroupBox_</zorder>
16531674
<zorder>toolBox</zorder>
1675+
<zorder>renderWithBasesCheckBox_</zorder>
16541676
</widget>
16551677
<widget class="QWidget" name="tensorTab_">
16561678
<attribute name="title">

src/Interface/Modules/Visualization/ShowFieldGlyphsDialog.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,21 @@ void ShowFieldGlyphsDialog::setupVectorsTab()
169169
addRadioButtonGroupManager({ this->secondaryVectorParameterUniformRButton_, this->secondaryVectorParameterPortRButton_}, ShowFieldGlyphs::SecondaryVecParamScalingType);
170170
addComboBoxManager(this->secondaryVectorParameterPortComboBox_, ShowFieldGlyphs::SecondaryVecParamDataInput);
171171
addDoubleSpinBoxManager(this->secondaryVectorParameterDoubleSpinBox_, ShowFieldGlyphs::SecondaryVecParamScale);
172-
// Arrow Head Ratio
172+
// Arrow Settings
173173
addDoubleSpinBoxManager(this->arrowHeadRatioDoubleSpinBox_, ShowFieldGlyphs::ArrowHeadRatio);
174-
// Bidirectional
175174
addCheckableButtonManager(this->bidirectionalVectorsCheckBox_, ShowFieldGlyphs::RenderBidirectionaly);
176-
175+
addCheckableButtonManager(this->renderWithBasesCheckBox_, ShowFieldGlyphs::RenderBases);
176+
177177
// Execute if any changed
178178
connectButtonToExecuteSignal(this->showVectorsCheckBox_);
179179
connectButtonToExecuteSignal(this->vectorsTransparencyOffRButton_);
180180
connectButtonToExecuteSignal(this->vectorsUniformTransparencyRButton_);
181+
connectButtonToExecuteSignal(this->secondaryVectorParameterUniformRButton_);
182+
connectButtonToExecuteSignal(this->secondaryVectorParameterPortRButton_);
181183
connectButtonToExecuteSignal(this->normalizeVectorsCheckBox_);
182184
connectButtonToExecuteSignal(this->renderVectorsBelowThresholdCheckBox_);
183185
connectButtonToExecuteSignal(this->bidirectionalVectorsCheckBox_);
186+
connectButtonToExecuteSignal(this->renderWithBasesCheckBox_);
184187

185188
// Text Labels
186189
this->vectorColorTypeLabel->setStyleSheet("background-color: rgba(255, 255, 255, 0);");

src/Modules/Visualization/ShowFieldGlyphs.cc

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ namespace SCIRun {
123123
double ratio,
124124
int resolution,
125125
ColorRGB& node_color,
126-
bool use_lines);
126+
bool use_lines,
127+
bool render_base1,
128+
bool render_base2);
127129

128130
ColorScheme getColoringType(const RenderState& renState, VField* fld);
129131
};
@@ -162,7 +164,9 @@ void GlyphBuilder::addGlyph(
162164
double ratio,
163165
int resolution,
164166
ColorRGB& node_color,
165-
bool use_lines)
167+
bool use_lines,
168+
bool render_base1 = false,
169+
bool render_base2 = false)
166170
{
167171
switch (glyph_type)
168172
{
@@ -179,13 +183,13 @@ void GlyphBuilder::addGlyph(
179183
break;
180184
}
181185
case RenderState::GlyphType::CONE_GLYPH:
182-
glyphs.addCone(p1, p2, radius, resolution, false, node_color, node_color);
186+
glyphs.addCone(p1, p2, radius, resolution, render_base1, node_color, node_color);
183187
break;
184188
case RenderState::GlyphType::ARROW_GLYPH:
185-
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color);
189+
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
186190
break;
187191
case RenderState::GlyphType::DISK_GLYPH:
188-
glyphs.addCylinder(p1, p2, radius, resolution, node_color, node_color);
192+
glyphs.addDisk(p1, p2, radius, resolution, node_color, node_color);
189193
break;
190194
case RenderState::GlyphType::RING_GLYPH:
191195
BOOST_THROW_EXCEPTION(AlgorithmInputException() << ErrorMessage("Ring Geom is not supported yet."));
@@ -197,7 +201,7 @@ void GlyphBuilder::addGlyph(
197201
if (use_lines)
198202
glyphs.addLine(p1, p2, node_color, node_color);
199203
else
200-
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color);
204+
glyphs.addArrow(p1, p2, radius, ratio, resolution, node_color, node_color, render_base1, render_base2);
201205
}
202206
}
203207

@@ -237,6 +241,7 @@ void ShowFieldGlyphs::setStateDefaults()
237241
state->setValue(VectorsScale, 1.0);
238242
state->setValue(RenderVectorsBelowThreshold, true);
239243
state->setValue(VectorsThreshold, 0.0);
244+
state->setValue(RenderBases, false);
240245
state->setValue(RenderBidirectionaly, false);
241246
state->setValue(ArrowHeadRatio, 0.5);
242247
state->setValue(VectorsResolution, 5);
@@ -460,6 +465,7 @@ void GlyphBuilder::renderVectors(
460465

461466
bool normalizeGlyphs = state->getValue(ShowFieldGlyphs::NormalizeVectors).toBool();
462467
bool renderBidirectionaly = state->getValue(ShowFieldGlyphs::RenderBidirectionaly).toBool();
468+
bool renderBases = state->getValue(ShowFieldGlyphs::RenderBases).toBool();
463469
bool renderGlphysBelowThreshold = state->getValue(ShowFieldGlyphs::RenderVectorsBelowThreshold).toBool();
464470
float threshold = state->getValue(ShowFieldGlyphs::VectorsThreshold).toDouble();
465471

@@ -546,9 +552,15 @@ void GlyphBuilder::renderVectors(
546552

547553
if(renderGlphysBelowThreshold || pinputVector.length() >= threshold)
548554
{
549-
addGlyph(glyphs, renState.mGlyphType, points[i], p2, radius, arrowHeadRatio, resolution, node_color, useLines);
555+
// No need to render cylinder base if arrow is bidirectional
556+
bool render_cylinder_base = renderBases && !renderBidirectionaly;
557+
558+
addGlyph(glyphs, renState.mGlyphType, points[i], p2, radius, arrowHeadRatio,
559+
resolution, node_color, useLines, render_cylinder_base, renderBases);
560+
550561
if(renderBidirectionaly)
551-
addGlyph(glyphs, renState.mGlyphType, points[i], p3, radius, arrowHeadRatio, resolution, node_color, useLines);
562+
addGlyph(glyphs, renState.mGlyphType, points[i], p3, radius, arrowHeadRatio,
563+
resolution, node_color, useLines, render_cylinder_base, renderBases);
552564
}
553565
}
554566

@@ -558,7 +570,8 @@ void GlyphBuilder::renderVectors(
558570
std::string uniqueNodeID = id + "vector_glyphs" + ss.str();
559571

560572
glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENT_EDGES),
561-
state->getValue(ShowFieldGlyphs::VectorsUniformTransparencyValue).toDouble(), colorScheme, renState, primIn, mesh->get_bounding_box());
573+
state->getValue(ShowFieldGlyphs::VectorsUniformTransparencyValue).toDouble(),
574+
colorScheme, renState, primIn, mesh->get_bounding_box());
562575
}
563576

564577
void GlyphBuilder::renderScalars(
@@ -1053,6 +1066,7 @@ const AlgorithmParameterName ShowFieldGlyphs::SecondaryVecParamDataInput("Second
10531066
const AlgorithmParameterName ShowFieldGlyphs::SecondaryVecParamScale("SecondaryVecParamScale");
10541067
const AlgorithmParameterName ShowFieldGlyphs::ArrowHeadRatio("ArrowHeadRatio");
10551068
const AlgorithmParameterName ShowFieldGlyphs::RenderBidirectionaly("RenderBidirectionaly");
1069+
const AlgorithmParameterName ShowFieldGlyphs::RenderBases("RenderBases");
10561070
const AlgorithmParameterName ShowFieldGlyphs::VectorsResolution("VectorsResolution");
10571071
// Scalar Controls
10581072
const AlgorithmParameterName ShowFieldGlyphs::ShowScalarTab("ShowScalarTab");

src/Modules/Visualization/ShowFieldGlyphs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace SCIRun {
6969
static const Core::Algorithms::AlgorithmParameterName SecondaryVecParamScale;
7070
static const Core::Algorithms::AlgorithmParameterName ArrowHeadRatio;
7171
static const Core::Algorithms::AlgorithmParameterName RenderBidirectionaly;
72+
static const Core::Algorithms::AlgorithmParameterName RenderBases;
7273
static const Core::Algorithms::AlgorithmParameterName VectorsResolution;
7374
// Scalar Controls
7475
static const Core::Algorithms::AlgorithmParameterName ShowScalarTab;

0 commit comments

Comments
 (0)