Skip to content

Commit 77c45f0

Browse files
committed
show t value along edge for selection
1 parent a3c9dd0 commit 77c45f0

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

include/polyscope/curve_network.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct QuantityTypeHelper<CurveNetwork> {
3939
struct CurveNetworkPickResult {
4040
CurveNetworkElement elementType; // which kind of element did we click
4141
int64_t index; // index of the clicked element
42+
float tEdge = -1; // if the pick is an edge, the t-value in [0,1] along the edge
4243
};
4344

4445
class CurveNetwork : public QuantityStructure<CurveNetwork> {
@@ -191,8 +192,8 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {
191192
float computeRadiusMultiplierUniform();
192193

193194
// Pick helpers
194-
void buildNodePickUI(size_t nodeInd);
195-
void buildEdgePickUI(size_t edgeInd);
195+
void buildNodePickUI(const CurveNetworkPickResult& result);
196+
void buildEdgePickUI(const CurveNetworkPickResult& result);
196197

197198
// === Quantity adder implementations
198199
// clang-format off
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
2+
3+
#pragma once
4+
5+
#include <complex>
6+
#include <tuple>
7+
8+
#include <glm/glm.hpp>
9+
10+
namespace polyscope {
11+
12+
float computeTValAlongLine(glm::vec3 queryP, glm::vec3 lineStart, glm::vec3 lineEnd);
13+
14+
15+
}

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ SET(SRCS
187187
slice_plane.cpp
188188
weak_handle.cpp
189189
marching_cubes.cpp
190+
elementary_geometry.cpp
190191

191192
## Structures
192193

@@ -283,6 +284,7 @@ SET(HEADERS
283284
${INCLUDE_ROOT}/curve_network_vector_quantity.h
284285
${INCLUDE_ROOT}/disjoint_sets.h
285286
${INCLUDE_ROOT}/depth_render_image_quantity.h
287+
${INCLUDE_ROOT}/elementary_geometry.h
286288
${INCLUDE_ROOT}/file_helpers.h
287289
${INCLUDE_ROOT}/floating_quantity_structure.h
288290
${INCLUDE_ROOT}/floating_quantity.h

src/curve_network.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "polyscope/curve_network.h"
44

5+
#include "polyscope/elementary_geometry.h"
56
#include "polyscope/pick.h"
67
#include "polyscope/polyscope.h"
78
#include "polyscope/render/engine.h"
@@ -348,17 +349,18 @@ void CurveNetwork::buildPickUI(const PickResult& rawResult) {
348349
349350
switch (result.elementType) {
350351
case CurveNetworkElement::NODE: {
351-
buildNodePickUI(result.index);
352+
buildNodePickUI(result);
352353
break;
353354
}
354355
case CurveNetworkElement::EDGE: {
355-
buildEdgePickUI(result.index);
356+
buildEdgePickUI(result);
356357
break;
357358
}
358359
};
359360
}
360361
361-
void CurveNetwork::buildNodePickUI(size_t nodeInd) {
362+
void CurveNetwork::buildNodePickUI(const CurveNetworkPickResult& result) {
363+
int32_t nodeInd = result.index;
362364
363365
ImGui::TextUnformatted(("node #" + std::to_string(nodeInd) + " ").c_str());
364366
ImGui::SameLine();
@@ -379,12 +381,14 @@ void CurveNetwork::buildNodePickUI(size_t nodeInd) {
379381
ImGui::Indent(-20.);
380382
}
381383
382-
void CurveNetwork::buildEdgePickUI(size_t edgeInd) {
384+
void CurveNetwork::buildEdgePickUI(const CurveNetworkPickResult& result) {
385+
int32_t edgeInd = result.index;
386+
383387
ImGui::TextUnformatted(("edge #" + std::to_string(edgeInd) + " ").c_str());
384388
ImGui::SameLine();
385-
size_t n0 = edgeTailInds.getValue(edgeInd);
386-
size_t n1 = edgeTipInds.getValue(edgeInd);
387-
ImGui::TextUnformatted((" " + std::to_string(n0) + " -- " + std::to_string(n1)).c_str());
389+
int32_t n0 = edgeTailInds.getValue(edgeInd);
390+
int32_t n1 = edgeTipInds.getValue(edgeInd);
391+
ImGui::Text(" %d -- %d t_select = %.4f", n0, n1, result.tEdge);
388392
389393
ImGui::Spacing();
390394
ImGui::Spacing();
@@ -481,10 +485,10 @@ CurveNetworkPickResult CurveNetwork::interpretPickResult(const PickResult& rawRe
481485

482486
// compute the t \in [0,1] along the edge
483487
int32_t iStart = edgeTailInds.getValue(result.index);
484-
int32_t iEnd= edgeTipInds.getValue(result.index);
488+
int32_t iEnd = edgeTipInds.getValue(result.index);
485489
glm::vec3 pStart = nodePositions.getValue(iStart);
486490
glm::vec3 pEnd = nodePositions.getValue(iEnd);
487-
491+
result.tEdge = computeTValAlongLine(rawResult.position, pStart, pEnd);
488492
} else {
489493
exception("Bad pick index in curve network");
490494
}

src/elementary_geometry.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017-2023, Nicholas Sharp and the Polyscope contributors. https://polyscope.run
2+
3+
#include "polyscope/elementary_geometry.h"
4+
5+
6+
#include <cmath>
7+
#include <vector>
8+
9+
#include <glm/gtx/norm.hpp>
10+
11+
namespace polyscope {
12+
13+
float computeTValAlongLine(glm::vec3 queryP, glm::vec3 lineStart, glm::vec3 lineEnd) {
14+
glm::vec3 lineVec = lineEnd - lineStart;
15+
glm::vec3 queryVec = queryP - lineStart;
16+
float len2 = glm::length2(lineVec);
17+
float t = glm::dot(queryVec, lineVec) / len2;
18+
t = glm::clamp(t, 0.f, 1.f);
19+
return t;
20+
}
21+
22+
} // namespace polyscope

0 commit comments

Comments
 (0)