-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathcurve_network.cpp
More file actions
714 lines (567 loc) · 23.5 KB
/
curve_network.cpp
File metadata and controls
714 lines (567 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
#include "polyscope/curve_network.h"
#include "polyscope/elementary_geometry.h"
#include "polyscope/pick.h"
#include "polyscope/polyscope.h"
#include "polyscope/render/engine.h"
#include "imgui.h"
#include <fstream>
#include <iostream>
namespace polyscope {
// Initialize statics
const std::string CurveNetwork::structureTypeName = "Curve Network";
// Constructor
CurveNetwork::CurveNetwork(std::string name, std::vector<glm::vec3> nodes_, std::vector<std::array<size_t, 2>> edges_)
: // clang-format off
QuantityStructure<CurveNetwork>(name, typeName()),
nodePositions(this, uniquePrefix() + "nodePositions", nodePositionsData),
edgeTailInds(this, uniquePrefix() + "edgeTailInds", edgeTailIndsData),
edgeTipInds(this, uniquePrefix() + "edgeTipInds", edgeTipIndsData),
edgeCenters(this, uniquePrefix() + "edgeCenters", edgeCentersData, std::bind(&CurveNetwork::computeEdgeCenters, this)),
nodePositionsData(std::move(nodes_)),
color(uniquePrefix() + "#color", getNextUniqueColor()),
radius(uniquePrefix() + "#radius", relativeValue(0.005)),
material(uniquePrefix() + "#material", "clay")
// clang-format on
{
nodePositions.checkInvalidValues();
// Copy interleaved data in to tip and tails buffers below
edgeTailIndsData.resize(edges_.size());
edgeTipIndsData.resize(edges_.size());
// Compute node degrees; some quantities want them for visualizations
nodeDegrees = std::vector<size_t>(nNodes(), 0);
size_t maxInd = nodePositions.size();
for (size_t iE = 0; iE < edges_.size(); iE++) {
auto edge = edges_[iE];
size_t nA = std::get<0>(edge);
size_t nB = std::get<1>(edge);
edgeTailIndsData[iE] = nA;
edgeTipIndsData[iE] = nB;
// Make sure there are no out of bounds indices
if (nA >= maxInd || nB >= maxInd) {
exception("CurveNetwork [" + name + "] edge " + std::to_string(iE) + " has bad node indices { " +
std::to_string(nA) + " , " + std::to_string(nB) + " } but there are " + std::to_string(maxInd) +
" nodes.");
}
// Increment degree
nodeDegrees[nA]++;
nodeDegrees[nB]++;
}
updateObjectSpaceBounds();
}
float CurveNetwork::computeNodeRadiusMultiplierUniform() {
float scalarQScale = 1.;
if (nodeRadiusQuantityName != "") {
// node radius quantity only, or both
if (!nodeRadiusQuantityAutoscale) return 1.;
CurveNetworkNodeScalarQuantity& radQ = resolveNodeRadiusQuantity();
scalarQScale = std::max(0., radQ.getDataRange().second);
} else if (edgeRadiusQuantityName != "") {
// edge radius quantity
if (!edgeRadiusQuantityAutoscale) return 1.;
CurveNetworkEdgeScalarQuantity& radQ = resolveEdgeRadiusQuantity();
scalarQScale = std::max(0., radQ.getDataRange().second);
}
return getRadius() / scalarQScale;
}
float CurveNetwork::computeEdgeRadiusMultiplierUniform() {
float scalarQScale = 1.;
if (edgeRadiusQuantityName != "") {
// edge radius quantity only, or both
if (!edgeRadiusQuantityAutoscale) return 1.;
CurveNetworkEdgeScalarQuantity& radQ = resolveEdgeRadiusQuantity();
scalarQScale = std::max(0., radQ.getDataRange().second);
} else if (nodeRadiusQuantityName != "") {
// node radius quantity only
if (!nodeRadiusQuantityAutoscale) return 1.;
CurveNetworkNodeScalarQuantity& radQ = resolveNodeRadiusQuantity();
scalarQScale = std::max(0., radQ.getDataRange().second);
}
return getRadius() / scalarQScale;
}
// Helper to set uniforms
void CurveNetwork::setCurveNetworkNodeUniforms(render::ShaderProgram& p) {
glm::mat4 P = view::getCameraPerspectiveMatrix();
glm::mat4 Pinv = glm::inverse(P);
p.setUniform("u_invProjMatrix", glm::value_ptr(Pinv));
p.setUniform("u_viewport", render::engine->getCurrentViewport());
p.setUniform("u_pointRadius", computeNodeRadiusMultiplierUniform());
}
void CurveNetwork::setCurveNetworkEdgeUniforms(render::ShaderProgram& p) {
glm::mat4 P = view::getCameraPerspectiveMatrix();
glm::mat4 Pinv = glm::inverse(P);
p.setUniform("u_invProjMatrix", glm::value_ptr(Pinv));
p.setUniform("u_viewport", render::engine->getCurrentViewport());
p.setUniform("u_radius", computeNodeRadiusMultiplierUniform());
}
void CurveNetwork::draw() {
if (!isEnabled()) {
return;
}
// If there is no dominant quantity, then this class is responsible for drawing points
if (dominantQuantity == nullptr) {
// Ensure we have prepared buffers
if (edgeProgram == nullptr || nodeProgram == nullptr) {
prepare();
}
// Set program uniforms
setStructureUniforms(*edgeProgram);
setStructureUniforms(*nodeProgram);
setCurveNetworkEdgeUniforms(*edgeProgram);
setCurveNetworkNodeUniforms(*nodeProgram);
edgeProgram->setUniform("u_baseColor", getColor());
nodeProgram->setUniform("u_baseColor", getColor());
render::engine->setMaterialUniforms(*edgeProgram, getMaterial());
render::engine->setMaterialUniforms(*nodeProgram, getMaterial());
// Draw the actual curve network
edgeProgram->draw();
nodeProgram->draw();
}
// Draw the quantities
for (auto& x : quantities) {
x.second->draw();
}
for (auto& x : floatingQuantities) {
x.second->draw();
}
}
void CurveNetwork::drawDelayed() {
if (!isEnabled()) {
return;
}
for (auto& x : quantities) {
x.second->drawDelayed();
}
for (auto& x : floatingQuantities) {
x.second->drawDelayed();
}
}
void CurveNetwork::drawPick() {
if (!isEnabled()) {
return;
}
// Ensure we have prepared buffers
if (edgePickProgram == nullptr || nodePickProgram == nullptr) {
preparePick();
}
// Set uniforms
setStructureUniforms(*edgePickProgram);
setStructureUniforms(*nodePickProgram);
setCurveNetworkEdgeUniforms(*edgePickProgram);
setCurveNetworkNodeUniforms(*nodePickProgram);
edgePickProgram->draw();
nodePickProgram->draw();
}
std::vector<std::string> CurveNetwork::addCurveNetworkNodeRules(std::vector<std::string> initRules) {
initRules = addStructureRules(initRules);
if (nodeRadiusQuantityName != "" || edgeRadiusQuantityName != "") {
initRules.push_back("SPHERE_VARIABLE_SIZE");
}
if (wantsCullPosition()) {
initRules.push_back("SPHERE_CULLPOS_FROM_CENTER");
}
return initRules;
}
std::vector<std::string> CurveNetwork::addCurveNetworkEdgeRules(std::vector<std::string> initRules) {
initRules = addStructureRules(initRules);
// use node radius to blend cylinder radius
if (nodeRadiusQuantityName != "" || edgeRadiusQuantityName != "") {
initRules.push_back("CYLINDER_VARIABLE_SIZE");
}
if (wantsCullPosition()) {
initRules.push_back("CYLINDER_CULLPOS_FROM_MID");
}
return initRules;
}
void CurveNetwork::prepare() {
if (dominantQuantity != nullptr) {
return;
}
// It no quantity is coloring the network, draw with a default color
// clang-format off
nodeProgram = render::engine->requestShader("RAYCAST_SPHERE",
render::engine->addMaterialRules(getMaterial(),
addCurveNetworkNodeRules(
{"SHADE_BASECOLOR"}
)
)
);
edgeProgram = render::engine->requestShader("RAYCAST_CYLINDER",
render::engine->addMaterialRules(getMaterial(),
addCurveNetworkEdgeRules(
{"SHADE_BASECOLOR"}
)
)
);
// clang-format on
render::engine->setMaterial(*nodeProgram, getMaterial());
render::engine->setMaterial(*edgeProgram, getMaterial());
// Fill out the geometry data for the programs
fillNodeGeometryBuffers(*nodeProgram);
fillEdgeGeometryBuffers(*edgeProgram);
}
void CurveNetwork::preparePick() {
edgeTailInds.ensureHostBufferPopulated();
edgeTipInds.ensureHostBufferPopulated();
// Pick index layout (local indices):
// | --- nodes --- | --- edges --- |
// ^ ^
// 0 nNodes()
// Request pick indices
size_t totalPickElements = nNodes() + nEdges();
size_t pickStart = pick::requestPickBufferRange(this, totalPickElements);
{ // Set up node picking program
nodePickProgram =
render::engine->requestShader("RAYCAST_SPHERE", addCurveNetworkNodeRules({"SPHERE_PROPAGATE_COLOR"}),
render::ShaderReplacementDefaults::Pick);
// Fill color buffer with packed point indices
std::vector<glm::vec3> pickColors;
pickColors.reserve(nNodes());
for (size_t i = pickStart; i < pickStart + nNodes(); i++) {
glm::vec3 val = pick::indToVec(i);
pickColors.push_back(pick::indToVec(i));
}
// Store data in buffers
nodePickProgram->setAttribute("a_color", pickColors);
fillNodeGeometryBuffers(*nodePickProgram);
}
{ // Set up edge picking program
edgePickProgram =
render::engine->requestShader("RAYCAST_CYLINDER", addCurveNetworkEdgeRules({"CYLINDER_PROPAGATE_PICK"}),
render::ShaderReplacementDefaults::Pick);
// Fill color buffer with packed node/edge indices
std::vector<glm::vec3> edgePickTail(nEdges());
std::vector<glm::vec3> edgePickTip(nEdges());
std::vector<glm::vec3> edgePickEdge(nEdges());
// Fill posiiton and pick index buffers
for (size_t iE = 0; iE < nEdges(); iE++) {
size_t eTail = edgeTailInds.data[iE];
size_t eTip = edgeTipInds.data[iE];
glm::vec3 colorValTail = pick::indToVec(pickStart + eTail);
glm::vec3 colorValTip = pick::indToVec(pickStart + eTip);
glm::vec3 colorValEdge = pick::indToVec(pickStart + nNodes() + iE);
edgePickTail[iE] = colorValTail;
edgePickTip[iE] = colorValTip;
edgePickEdge[iE] = colorValEdge;
}
edgePickProgram->setAttribute("a_color_tail", edgePickTail);
edgePickProgram->setAttribute("a_color_tip", edgePickTip);
edgePickProgram->setAttribute("a_color_edge", edgePickEdge);
fillEdgeGeometryBuffers(*edgePickProgram);
}
}
void CurveNetwork::fillNodeGeometryBuffers(render::ShaderProgram& program) {
program.setAttribute("a_position", nodePositions.getRenderAttributeBuffer());
bool haveNodeRadiusQuantity = (nodeRadiusQuantityName != "");
bool haveEdgeRadiusQuantity = (edgeRadiusQuantityName != "");
if (haveNodeRadiusQuantity) {
// have just node, or have both
CurveNetworkNodeScalarQuantity& nodeRadQ = resolveNodeRadiusQuantity();
program.setAttribute("a_pointRadius", nodeRadQ.values.getRenderAttributeBuffer());
} else if (haveEdgeRadiusQuantity) {
// have just edge
CurveNetworkEdgeScalarQuantity& edgeRadQ = resolveEdgeRadiusQuantity();
edgeRadQ.updateNodeAverageValues();
program.setAttribute("a_pointRadius", edgeRadQ.nodeAverageValues.getRenderAttributeBuffer());
}
}
void CurveNetwork::fillEdgeGeometryBuffers(render::ShaderProgram& program) {
program.setAttribute("a_position_tail", nodePositions.getIndexedRenderAttributeBuffer(edgeTailInds));
program.setAttribute("a_position_tip", nodePositions.getIndexedRenderAttributeBuffer(edgeTipInds));
bool haveNodeRadiusQuantity = (nodeRadiusQuantityName != "");
bool haveEdgeRadiusQuantity = (edgeRadiusQuantityName != "");
if (haveEdgeRadiusQuantity) {
// have just edge or have both
CurveNetworkEdgeScalarQuantity& edgeRadQ = resolveEdgeRadiusQuantity();
program.setAttribute("a_tailRadius", edgeRadQ.values.getRenderAttributeBuffer());
program.setAttribute("a_tipRadius", edgeRadQ.values.getRenderAttributeBuffer());
} else if (haveNodeRadiusQuantity) {
// have just node
CurveNetworkNodeScalarQuantity& nodeRadQ = resolveNodeRadiusQuantity();
program.setAttribute("a_tailRadius", nodeRadQ.values.getIndexedRenderAttributeBuffer(edgeTailInds));
program.setAttribute("a_tipRadius", nodeRadQ.values.getIndexedRenderAttributeBuffer(edgeTipInds));
}
}
void CurveNetwork::computeEdgeCenters() {
nodePositions.ensureHostBufferPopulated();
edgeTailInds.ensureHostBufferPopulated();
edgeTipInds.ensureHostBufferPopulated();
edgeCenters.data.resize(nEdges());
for (size_t iE = 0; iE < nEdges(); iE++) {
size_t eTail = edgeTailInds.data[iE];
size_t eTip = edgeTipInds.data[iE];
glm::vec3 p = 0.5f * (nodePositions.data[eTail] + nodePositions.data[eTip]);
edgeCenters.data[iE] = p;
}
edgeCenters.markHostBufferUpdated();
}
void CurveNetwork::refresh() {
recomputeGeometryIfPopulated();
nodeProgram.reset();
edgeProgram.reset();
nodePickProgram.reset();
edgePickProgram.reset();
requestRedraw();
QuantityStructure<CurveNetwork>::refresh(); // call base class version, which refreshes quantities
}
void CurveNetwork::recomputeGeometryIfPopulated() { edgeCenters.recomputeIfPopulated(); }
void CurveNetwork::buildPickUI(const PickResult& rawResult) {
CurveNetworkPickResult result = interpretPickResult(rawResult);
switch (result.elementType) {
case CurveNetworkElement::NODE: {
buildNodePickUI(result);
break;
}
case CurveNetworkElement::EDGE: {
buildEdgePickUI(result);
break;
}
};
}
void CurveNetwork::buildNodePickUI(const CurveNetworkPickResult& result) {
int32_t nodeInd = result.index;
ImGui::TextUnformatted(("node #" + std::to_string(nodeInd) + " ").c_str());
ImGui::SameLine();
ImGui::TextUnformatted(to_string(nodePositions.getValue(nodeInd)).c_str());
ImGui::Spacing();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Indent(20.);
// Build GUI to show the quantities
ImGui::Columns(2);
ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() / 3);
for (auto& x : quantities) {
x.second->buildNodeInfoGUI(nodeInd);
}
ImGui::Indent(-20.);
}
void CurveNetwork::buildEdgePickUI(const CurveNetworkPickResult& result) {
int32_t edgeInd = result.index;
ImGui::TextUnformatted(("edge #" + std::to_string(edgeInd) + " ").c_str());
ImGui::SameLine();
int32_t n0 = edgeTailInds.getValue(edgeInd);
int32_t n1 = edgeTipInds.getValue(edgeInd);
ImGui::Text(" %d -- %d t_select = %.4f", n0, n1, result.tEdge);
ImGui::Spacing();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Indent(20.);
// Build GUI to show the quantities
ImGui::Columns(2);
ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() / 3);
for (auto& x : quantities) {
x.second->buildEdgeInfoGUI(edgeInd);
}
ImGui::Indent(-20.);
}
void CurveNetwork::buildCustomUI() {
ImGui::Text("nodes: %lld edges: %lld", static_cast<long long int>(nNodes()), static_cast<long long int>(nEdges()));
if (ImGui::ColorEdit3("Color", &color.get()[0], ImGuiColorEditFlags_NoInputs)) {
setColor(getColor());
}
ImGui::SameLine();
ImGui::PushItemWidth(100 * options::uiScale);
if (ImGui::SliderFloat("Radius", radius.get().getValuePtr(), 0.0, .1, "%.5f",
ImGuiSliderFlags_Logarithmic | ImGuiSliderFlags_NoRoundToFormat)) {
radius.manuallyChanged();
requestRedraw();
}
ImGui::PopItemWidth();
}
void CurveNetwork::buildCustomOptionsUI() {
if (ImGui::BeginMenu("Node Variable Radius")) {
if (ImGui::MenuItem("none", nullptr, nodeRadiusQuantityName == "")) clearNodeRadiusQuantity();
ImGui::Separator();
for (auto& q : quantities) {
CurveNetworkNodeScalarQuantity* scalarQ = dynamic_cast<CurveNetworkNodeScalarQuantity*>(q.second.get());
if (scalarQ != nullptr) {
if (ImGui::MenuItem(scalarQ->name.c_str(), nullptr, nodeRadiusQuantityName == scalarQ->name))
setNodeRadiusQuantity(scalarQ);
}
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edge Variable Radius")) {
if (ImGui::MenuItem("none", nullptr, edgeRadiusQuantityName == "")) clearEdgeRadiusQuantity();
ImGui::Separator();
for (auto& q : quantities) {
CurveNetworkEdgeScalarQuantity* scalarQ = dynamic_cast<CurveNetworkEdgeScalarQuantity*>(q.second.get());
if (scalarQ != nullptr) {
if (ImGui::MenuItem(scalarQ->name.c_str(), nullptr, edgeRadiusQuantityName == scalarQ->name))
setEdgeRadiusQuantity(scalarQ);
}
}
ImGui::EndMenu();
}
if (render::buildMaterialOptionsGui(material.get())) {
material.manuallyChanged();
setMaterial(material.get()); // trigger the other updates that happen on set()
}
}
void CurveNetwork::updateObjectSpaceBounds() {
nodePositions.ensureHostBufferPopulated();
// bounding box
glm::vec3 min = glm::vec3{1, 1, 1} * std::numeric_limits<float>::infinity();
glm::vec3 max = -glm::vec3{1, 1, 1} * std::numeric_limits<float>::infinity();
for (const glm::vec3& p : nodePositions.data) {
min = componentwiseMin(min, p);
max = componentwiseMax(max, p);
}
objectSpaceBoundingBox = std::make_tuple(min, max);
// length scale, as twice the radius from the center of the bounding box
glm::vec3 center = 0.5f * (min + max);
float lengthScale = 0.0;
for (const glm::vec3& p : nodePositions.data) {
lengthScale = std::max(lengthScale, glm::length2(p - center));
}
objectSpaceLengthScale = 2 * std::sqrt(lengthScale);
}
CurveNetworkPickResult CurveNetwork::interpretPickResult(const PickResult& rawResult) {
if (rawResult.structure != this) {
// caller must ensure that the PickResult belongs to this structure
// by checking the structure pointer or name
exception("called interpretPickResult(), but the pick result is not from this structure");
}
CurveNetworkPickResult result;
if (rawResult.localIndex < nNodes()) {
result.elementType = CurveNetworkElement::NODE;
result.index = rawResult.localIndex;
} else if (rawResult.localIndex < nNodes() + nEdges()) {
result.elementType = CurveNetworkElement::EDGE;
result.index = rawResult.localIndex - nNodes();
// compute the t \in [0,1] along the edge
int32_t iStart = edgeTailInds.getValue(result.index);
int32_t iEnd = edgeTipInds.getValue(result.index);
glm::vec3 pStart = nodePositions.getValue(iStart);
glm::vec3 pEnd = nodePositions.getValue(iEnd);
result.tEdge = computeTValAlongLine(rawResult.position, pStart, pEnd);
} else {
exception("Bad pick index in curve network");
}
return result;
}
CurveNetwork* CurveNetwork::setColor(glm::vec3 newVal) {
color = newVal;
polyscope::requestRedraw();
return this;
}
glm::vec3 CurveNetwork::getColor() { return color.get(); }
void CurveNetwork::setNodeRadiusQuantity(CurveNetworkNodeScalarQuantity* quantity, bool autoScale) {
setNodeRadiusQuantity(quantity->name, autoScale);
}
void CurveNetwork::setNodeRadiusQuantity(std::string name, bool autoScale) {
nodeRadiusQuantityName = name;
nodeRadiusQuantityAutoscale = autoScale;
resolveNodeRadiusQuantity(); // do it once, just so we fail fast if it doesn't exist
refresh();
}
void CurveNetwork::clearNodeRadiusQuantity() {
nodeRadiusQuantityName = "";
refresh();
};
void CurveNetwork::setEdgeRadiusQuantity(CurveNetworkEdgeScalarQuantity* quantity, bool autoScale) {
setEdgeRadiusQuantity(quantity->name, autoScale);
}
void CurveNetwork::setEdgeRadiusQuantity(std::string name, bool autoScale) {
edgeRadiusQuantityName = name;
edgeRadiusQuantityAutoscale = autoScale;
resolveEdgeRadiusQuantity(); // do it once, just so we fail fast if it doesn't exist
refresh();
}
void CurveNetwork::clearEdgeRadiusQuantity() {
edgeRadiusQuantityName = "";
refresh();
};
CurveNetwork* CurveNetwork::setRadius(float newVal, bool isRelative) {
radius = ScaledValue<float>(newVal, isRelative);
polyscope::requestRedraw();
return this;
}
float CurveNetwork::getRadius() { return radius.get().asAbsolute(); }
CurveNetwork* CurveNetwork::setMaterial(std::string m) {
material = m;
refresh(); // (serves the purpose of re-initializing everything, though this is a bit overkill)
requestRedraw();
return this;
}
std::string CurveNetwork::getMaterial() { return material.get(); }
std::string CurveNetwork::typeName() { return structureTypeName; }
// === Quantities
CurveNetworkQuantity::CurveNetworkQuantity(std::string name_, CurveNetwork& curveNetwork_, bool dominates_)
: QuantityS<CurveNetwork>(name_, curveNetwork_, dominates_) {}
void CurveNetworkQuantity::buildNodeInfoGUI(size_t nodeInd) {}
void CurveNetworkQuantity::buildEdgeInfoGUI(size_t edgeInd) {}
// === Quantity adders
CurveNetworkNodeColorQuantity* CurveNetwork::addNodeColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkNodeColorQuantity* q = new CurveNetworkNodeColorQuantity(name, colors, *this);
addQuantity(q);
return q;
}
CurveNetworkEdgeColorQuantity* CurveNetwork::addEdgeColorQuantityImpl(std::string name,
const std::vector<glm::vec3>& colors) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkEdgeColorQuantity* q = new CurveNetworkEdgeColorQuantity(name, colors, *this);
addQuantity(q);
return q;
}
CurveNetworkNodeScalarQuantity* CurveNetwork::addNodeScalarQuantityImpl(std::string name,
const std::vector<float>& data, DataType type) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkNodeScalarQuantity* q = new CurveNetworkNodeScalarQuantity(name, data, *this, type);
addQuantity(q);
return q;
}
CurveNetworkEdgeScalarQuantity* CurveNetwork::addEdgeScalarQuantityImpl(std::string name,
const std::vector<float>& data, DataType type) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkEdgeScalarQuantity* q = new CurveNetworkEdgeScalarQuantity(name, data, *this, type);
addQuantity(q);
return q;
}
CurveNetworkNodeVectorQuantity* CurveNetwork::addNodeVectorQuantityImpl(std::string name,
const std::vector<glm::vec3>& vectors,
VectorType vectorType) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkNodeVectorQuantity* q = new CurveNetworkNodeVectorQuantity(name, vectors, *this, vectorType);
addQuantity(q);
return q;
}
CurveNetworkEdgeVectorQuantity* CurveNetwork::addEdgeVectorQuantityImpl(std::string name,
const std::vector<glm::vec3>& vectors,
VectorType vectorType) {
checkForQuantityWithNameAndDeleteOrError(name);
CurveNetworkEdgeVectorQuantity* q = new CurveNetworkEdgeVectorQuantity(name, vectors, *this, vectorType);
addQuantity(q);
return q;
}
CurveNetworkNodeScalarQuantity& CurveNetwork::resolveNodeRadiusQuantity() {
CurveNetworkNodeScalarQuantity* sizeScalarQ = nullptr;
CurveNetworkQuantity* sizeQ = getQuantity(nodeRadiusQuantityName);
if (sizeQ != nullptr) {
sizeScalarQ = dynamic_cast<CurveNetworkNodeScalarQuantity*>(sizeQ);
if (sizeScalarQ == nullptr) {
exception("Cannot populate node size from quantity [" + nodeRadiusQuantityName +
"], it is not a scalar quantity");
}
} else {
exception("Cannot populate node size from quantity [" + nodeRadiusQuantityName + "], it does not exist");
}
return *sizeScalarQ;
}
CurveNetworkEdgeScalarQuantity& CurveNetwork::resolveEdgeRadiusQuantity() {
CurveNetworkEdgeScalarQuantity* sizeScalarQ = nullptr;
CurveNetworkQuantity* sizeQ = getQuantity(edgeRadiusQuantityName);
if (sizeQ != nullptr) {
sizeScalarQ = dynamic_cast<CurveNetworkEdgeScalarQuantity*>(sizeQ);
if (sizeScalarQ == nullptr) {
exception("Cannot populate edge size from quantity [" + edgeRadiusQuantityName +
"], it is not a scalar quantity");
}
} else {
exception("Cannot populate edge size from quantity [" + edgeRadiusQuantityName + "], it does not exist");
}
return *sizeScalarQ;
}
} // namespace polyscope