Skip to content

Commit a3c9dd0

Browse files
committed
use new PickResult() and interpretPick() throughout
1 parent 8191b1e commit a3c9dd0

24 files changed

+428
-137
lines changed

include/polyscope/camera_view.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ struct QuantityTypeHelper<CameraView> {
2525
};
2626
*/
2727

28+
struct CameraViewPickResult {
29+
// currently nothing, just following the same pattern as other structures
30+
};
31+
2832
class CameraView : public QuantityStructure<CameraView> {
2933
public:
3034
// === Member functions ===
@@ -37,7 +41,7 @@ class CameraView : public QuantityStructure<CameraView> {
3741
// Build the imgui display
3842
virtual void buildCustomUI() override;
3943
virtual void buildCustomOptionsUI() override;
40-
virtual void buildPickUI(size_t localPickID) override;
44+
virtual void buildPickUI(const PickResult& result) override;
4145

4246
// Standard structure overrides
4347
virtual void draw() override;
@@ -71,6 +75,9 @@ class CameraView : public QuantityStructure<CameraView> {
7175
// Update the current viewer to look through this camer
7276
void setViewToThisCamera(bool withFlight = false);
7377

78+
// get data related to picking/selection
79+
CameraViewPickResult interpretPickResult(const PickResult& result);
80+
7481
// === Get/set visualization parameters
7582

7683
// Set focal length of the camera. This only effects how it the camera widget is rendered

include/polyscope/context.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <polyscope/types.h>
66
#include <polyscope/weak_handle.h>
7-
7+
#include <polyscope/pick.h>
88

99
#include <glm/glm.hpp>
1010
#include <glm/gtx/dual_quaternion.hpp>
@@ -101,11 +101,10 @@ struct Context {
101101
// === Picking globals from pick.h / pick.cpp
102102
// ======================================================
103103

104-
size_t currLocalPickInd = 0;
105-
Structure* currPickStructure = nullptr;
104+
PickResult currSelectionPickResult;
106105
bool haveSelectionVal = false;
107-
size_t nextPickBufferInd = 1;
108-
std::unordered_map<Structure*, std::tuple<size_t, size_t>> structureRanges;
106+
uint64_t nextPickBufferInd = 1;
107+
std::unordered_map<Structure*, std::tuple<uint64_t, uint64_t>> structureRanges;
109108

110109
// ======================================================
111110
// === Internal globals from internal.h

include/polyscope/curve_network.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct QuantityTypeHelper<CurveNetwork> {
3636
typedef CurveNetworkQuantity type;
3737
};
3838

39+
struct CurveNetworkPickResult {
40+
CurveNetworkElement elementType; // which kind of element did we click
41+
int64_t index; // index of the clicked element
42+
};
43+
3944
class CurveNetwork : public QuantityStructure<CurveNetwork> {
4045
public:
4146
// === Member functions ===
@@ -48,7 +53,7 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {
4853
// Build the imgui display
4954
virtual void buildCustomUI() override;
5055
virtual void buildCustomOptionsUI() override;
51-
virtual void buildPickUI(size_t localPickID) override;
56+
virtual void buildPickUI(const PickResult&) override;
5257

5358
virtual void draw() override;
5459
virtual void drawDelayed() override;
@@ -127,6 +132,9 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {
127132
template <class V>
128133
void updateNodePositions2D(const V& newPositions);
129134

135+
// get data related to picking/selection
136+
CurveNetworkPickResult interpretPickResult(const PickResult& result);
137+
130138
// === Get/set visualization parameters
131139

132140
// set the base color of the points

include/polyscope/elementary_geometry.h

Whitespace-only changes.

include/polyscope/floating_quantity_structure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FloatingQuantityStructure : public QuantityStructure<FloatingQuantityStruc
4444
// Build the imgui display
4545
virtual void buildUI() override;
4646
virtual void buildCustomUI() override;
47-
virtual void buildPickUI(size_t localPickID) override;
47+
virtual void buildPickUI(const PickResult& result) override;
4848
virtual void buildCustomOptionsUI() override;
4949

5050
// Standard structure overrides

include/polyscope/pick.h

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,59 @@
22

33
#pragma once
44

5-
#include "polyscope/structure.h"
6-
75
#include <cstdint>
6+
#include <string>
87
#include <utility>
98

9+
#include "polyscope/utilities.h"
10+
#include "polyscope/weak_handle.h"
11+
1012
namespace polyscope {
1113

14+
// Forward decls
15+
class Structure;
16+
1217
// == Main query
1318

1419
// Pick queries test a screen location in the rendered viewport, and return a variety of info about what is underneath
1520
// the pixel at that point, including what structure is under the cursor, and the scene depth and color.
1621
//
17-
// This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickQueryResult) to get
22+
// This information can be fed into structure-specific functions like SurfaceMesh::interpretPick(PickResult) to get
1823
// structure-specific info, like which vertex/face was clicked on.
1924

2025
// Return type for pick queries
21-
struct PickQueryResult {
22-
bool isHit;
23-
Structure* structure;
24-
std::string structureType;
25-
std::string structureName;
26+
struct PickResult {
27+
bool isHit = false;
28+
Structure* structure = nullptr;
29+
WeakHandle<Structure> structureHandle; // same as .structure, but with lifetime tracking
30+
std::string structureType = "";
31+
std::string structureName = "";
32+
glm::vec2 screenCoords;
33+
glm::ivec2 bufferCoords;
2634
glm::vec3 position;
2735
float depth;
36+
uint64_t localIndex = INVALID_IND_64;
2837
};
2938

3039
// Query functions to evaluate a pick.
3140
// Internally, these do a render pass to populate relevant information, then query the resulting buffers.
32-
PickQueryResult queryPickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
33-
PickQueryResult queryPickAtBufferCoords(int xPos, int yPos); // takes indices into render buffer
41+
PickResult queryPickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
42+
PickResult queryPickAtBufferCoords(int xPos, int yPos); // takes indices into render buffer
3443

3544
namespace pick {
3645

3746
// Old, deprecated picking API. Use the above functions instead.
3847
// Get the structure which was clicked on (nullptr if none), and the pick ID in local indices for that structure (such
3948
// that 0 is the first index as returned from requestPickBufferRange())
40-
std::pair<Structure*, size_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
41-
std::pair<Structure*, size_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
42-
std::pair<Structure*, size_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
49+
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
50+
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
51+
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
4352

4453
// == Stateful picking: track and update a current selection
4554

46-
// Get/Set the "selected" item, if there is one (output has same meaning as evaluatePickQuery());
47-
std::pair<Structure*, size_t> getSelection();
48-
void setSelection(std::pair<Structure*, size_t> newPick);
55+
// Get/Set the "selected" item, if there is one
56+
PickResult getSelection();
57+
void setSelection(PickResult newPick);
4958
void resetSelection();
5059
bool haveSelection();
5160
void resetSelectionIfStructure(Structure* s); // If something from this structure is selected, clear the selection
@@ -57,11 +66,11 @@ void resetSelectionIfStructure(Structure* s); // If something from this structur
5766
// Set up picking (internal)
5867
// Called by a structure to figure out what data it should render to the pick buffer.
5968
// Request 'count' contiguous indices for drawing a pick buffer. The return value is the start of the range.
60-
size_t requestPickBufferRange(Structure* requestingStructure, size_t count);
69+
uint64_t requestPickBufferRange(Structure* requestingStructure, uint64_t count);
6170

6271
// Convert between global pick indexing for the whole program, and local per-structure pick indexing
63-
std::pair<Structure*, size_t> globalIndexToLocal(size_t globalInd);
64-
size_t localIndexToGlobal(std::pair<Structure*, size_t> localPick);
72+
std::pair<Structure*, uint64_t> globalIndexToLocal(uint64_t globalInd);
73+
uint64_t localIndexToGlobal(std::pair<Structure*, uint64_t> localPick);
6574

6675
// Convert indices to float3 color and back
6776
// Structures will want to use these to fill their pick buffers

include/polyscope/point_cloud.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "polyscope/affine_remapper.h"
66
#include "polyscope/color_management.h"
77
#include "polyscope/persistent_value.h"
8+
#include "polyscope/pick.h"
89
#include "polyscope/point_cloud_quantity.h"
910
#include "polyscope/polyscope.h"
1011
#include "polyscope/render/engine.h"
@@ -37,6 +38,10 @@ struct QuantityTypeHelper<PointCloud> {
3738
typedef PointCloudQuantity type;
3839
};
3940

41+
struct PointCloudPickResult {
42+
int64_t index;
43+
};
44+
4045
class PointCloud : public QuantityStructure<PointCloud> {
4146
public:
4247
// === Member functions ===
@@ -49,7 +54,7 @@ class PointCloud : public QuantityStructure<PointCloud> {
4954
// Build the imgui display
5055
virtual void buildCustomUI() override;
5156
virtual void buildCustomOptionsUI() override;
52-
virtual void buildPickUI(size_t localPickID) override;
57+
virtual void buildPickUI(const PickResult& result) override;
5358

5459
// Standard structure overrides
5560
virtual void draw() override;
@@ -116,6 +121,9 @@ class PointCloud : public QuantityStructure<PointCloud> {
116121
size_t nPoints();
117122
glm::vec3 getPointPosition(size_t iPt);
118123

124+
// get data related to picking/selection
125+
PointCloudPickResult interpretPickResult(const PickResult& result);
126+
119127
// Misc data
120128
static const std::string structureTypeName;
121129

@@ -193,7 +201,6 @@ class PointCloud : public QuantityStructure<PointCloud> {
193201
PointCloudScalarQuantity& resolveTransparencyQuantity(); // helper
194202
};
195203

196-
197204
// Shorthand to add a point cloud to polyscope
198205
template <class T>
199206
PointCloud* registerPointCloud(std::string name, const T& points);

include/polyscope/simple_triangle_mesh.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class SimpleTriangleMesh;
2424
// typedef SimpleTriangleMeshQuantity type;
2525
// };
2626

27+
28+
struct SimpleTriangleMeshPickResult {
29+
// this does nothing for now, just matching pattern from other structures
30+
};
31+
2732
class SimpleTriangleMesh : public QuantityStructure<SimpleTriangleMesh> {
2833
public:
2934
// === Member functions ===
@@ -36,7 +41,7 @@ class SimpleTriangleMesh : public QuantityStructure<SimpleTriangleMesh> {
3641
// Build the imgui display
3742
virtual void buildCustomUI() override;
3843
virtual void buildCustomOptionsUI() override;
39-
virtual void buildPickUI(size_t localPickID) override;
44+
virtual void buildPickUI(const PickResult& result) override;
4045

4146
// Standard structure overrides
4247
virtual void draw() override;
@@ -63,6 +68,9 @@ class SimpleTriangleMesh : public QuantityStructure<SimpleTriangleMesh> {
6368
// Misc data
6469
static const std::string structureTypeName;
6570

71+
// get data related to picking/selection
72+
SimpleTriangleMeshPickResult interpretPickResult(const PickResult& result);
73+
6674
// === Get/set visualization parameters
6775

6876
// set the base color of the surface

include/polyscope/structure.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "glm/glm.hpp"
1111

1212
#include "polyscope/persistent_value.h"
13+
#include "polyscope/pick.h"
1314
#include "polyscope/render/engine.h"
1415
#include "polyscope/transformation_gizmo.h"
1516
#include "polyscope/weak_handle.h"
@@ -54,7 +55,7 @@ class Structure : public render::ManagedBufferRegistry, public virtual WeakRefer
5455
virtual void buildStructureOptionsUI(); // overridden by structure quantities to add to the options menu
5556
virtual void buildQuantitiesUI(); // build quantities, if they exist. Overridden by QuantityStructure.
5657
virtual void buildSharedStructureUI(); // Draw any UI elements shared between all instances of the structure
57-
virtual void buildPickUI(size_t localPickID) = 0; // Draw pick UI elements when index localPickID is selected
58+
virtual void buildPickUI(const PickResult& result) = 0; // Draw pick UI elements based on a selection result
5859

5960
// = Identifying data
6061
const std::string name; // should be unique amongst registered structures with this type

include/polyscope/surface_mesh.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ struct QuantityTypeHelper<SurfaceMesh> {
5151
typedef SurfaceMeshQuantity type;
5252
};
5353

54+
struct SurfaceMeshPickResult {
55+
MeshElement elementType; // which kind of element did we click
56+
int64_t index; // index of the clicked element
57+
};
5458

5559
// === The grand surface mesh class
5660

@@ -75,7 +79,7 @@ class SurfaceMesh : public QuantityStructure<SurfaceMesh> {
7579
// Build the imgui display
7680
virtual void buildCustomUI() override;
7781
virtual void buildCustomOptionsUI() override;
78-
virtual void buildPickUI(size_t localPickID) override;
82+
virtual void buildPickUI(const PickResult&) override;
7983

8084
// Render the the structure on screen
8185
virtual void draw() override;
@@ -166,8 +170,10 @@ class SurfaceMesh : public QuantityStructure<SurfaceMesh> {
166170
// special quantity-related methods
167171
SurfaceParameterizationQuantity* getParameterization(std::string name);
168172

173+
// get data related to picking/selection
174+
SurfaceMeshPickResult interpretPickResult(const PickResult& result);
169175

170-
// === Make a one-time selection
176+
// Make a one-time selection
171177
long long int selectVertex();
172178

173179
// === Mutate
@@ -381,11 +387,11 @@ class SurfaceMesh : public QuantityStructure<SurfaceMesh> {
381387
// Within each set, uses the implicit ordering from the mesh data structure
382388
// These starts are LOCAL indices, indexing elements only with the mesh
383389
size_t facePickIndStart, edgePickIndStart, halfedgePickIndStart, cornerPickIndStart;
384-
void buildVertexInfoGui(size_t vInd);
385-
void buildFaceInfoGui(size_t fInd);
386-
void buildEdgeInfoGui(size_t eInd);
387-
void buildHalfedgeInfoGui(size_t heInd);
388-
void buildCornerInfoGui(size_t cInd);
390+
void buildVertexInfoGui(const SurfaceMeshPickResult& result);
391+
void buildFaceInfoGui(const SurfaceMeshPickResult& result);
392+
void buildEdgeInfoGui(const SurfaceMeshPickResult& result);
393+
void buildHalfedgeInfoGui(const SurfaceMeshPickResult& result);
394+
void buildCornerInfoGui(const SurfaceMeshPickResult& result);
389395

390396
// Manage per-element transparency
391397
// which (scalar) quantity to set point size from

0 commit comments

Comments
 (0)