Skip to content

Commit 16139ad

Browse files
authored
Add quantity picking (#354)
* add additional skeleton methods for picking and delayed picking * generalize picking for quantities * add picking to render images * minor depth in demo app
1 parent e72ec23 commit 16139ad

29 files changed

+367
-60
lines changed

examples/demo-app/demo_app.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ void callback() {
821821
std::cout << " io.MousePos.x: " << io.MousePos.x << " io.MousePos.y: " << io.MousePos.y << std::endl;
822822
std::cout << " screenCoords.x: " << screenCoords.x << " screenCoords.y: " << screenCoords.y << std::endl;
823823
std::cout << " bufferInd.x: " << xInd << " bufferInd.y: " << yInd << std::endl;
824+
std::cout << " depth: " << pickResult.depth << std::endl;
824825
std::cout << " worldRay: ";
825826
polyscope::operator<<(std::cout, worldRay) << std::endl;
826827
std::cout << " worldPos: ";

include/polyscope/camera_view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CameraView : public QuantityStructure<CameraView> {
4747
virtual void draw() override;
4848
virtual void drawDelayed() override;
4949
virtual void drawPick() override;
50+
virtual void drawPickDelayed() override;
5051
virtual void updateObjectSpaceBounds() override;
5152
virtual std::string typeName() override;
5253
virtual void refresh() override;

include/polyscope/context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct Context {
107107
bool haveSelectionVal = false;
108108
uint64_t nextPickBufferInd = 1;
109109
std::unordered_map<Structure*, std::tuple<uint64_t, uint64_t>> structureRanges;
110+
std::unordered_map<Quantity*, std::tuple<uint64_t, uint64_t>> quantityRanges;
110111

111112
// ======================================================
112113
// === Internal globals from internal.h

include/polyscope/curve_network.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {
5959
virtual void draw() override;
6060
virtual void drawDelayed() override;
6161
virtual void drawPick() override;
62+
virtual void drawPickDelayed() override;
6263

6364
virtual void updateObjectSpaceBounds() override;
6465
virtual std::string typeName() override;

include/polyscope/floating_quantity_structure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class FloatingQuantityStructure : public QuantityStructure<FloatingQuantityStruc
5151
virtual void draw() override;
5252
virtual void drawDelayed() override;
5353
virtual void drawPick() override;
54+
virtual void drawPickDelayed() override;
5455
virtual bool hasExtents() override;
5556
virtual void updateObjectSpaceBounds() override;
5657
virtual std::string typeName() override;

include/polyscope/pick.h

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

55
#include <cstdint>
66
#include <string>
7+
#include <tuple>
78
#include <utility>
89

910
#include "polyscope/utilities.h"
@@ -13,6 +14,7 @@ namespace polyscope {
1314

1415
// Forward decls
1516
class Structure;
17+
class Quantity;
1618

1719
// == Main query
1820

@@ -26,9 +28,11 @@ class Structure;
2628
struct PickResult {
2729
bool isHit = false;
2830
Structure* structure = nullptr;
31+
Quantity* quantity = nullptr;
2932
WeakHandle<Structure> structureHandle; // same as .structure, but with lifetime tracking
3033
std::string structureType = "";
3134
std::string structureName = "";
35+
std::string quantityName = "";
3236
glm::vec2 screenCoords;
3337
glm::ivec2 bufferInds;
3438
glm::vec3 position;
@@ -60,18 +64,21 @@ namespace pick {
6064
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
6165
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
6266
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
67+
std::tuple<Structure*, Quantity*, uint64_t> evaluatePickQueryFull(int xPos,
68+
int yPos); // badly named. takes buffer coordinates.
6369

6470

6571
// == Helpers
6672

6773
// Set up picking (internal)
68-
// Called by a structure to figure out what data it should render to the pick buffer.
74+
// Called by a structure/quantity to figure out what data it should render to the pick buffer.
6975
// Request 'count' contiguous indices for drawing a pick buffer. The return value is the start of the range.
7076
uint64_t requestPickBufferRange(Structure* requestingStructure, uint64_t count);
77+
uint64_t requestPickBufferRange(Quantity* requestingQuantity, uint64_t count);
7178

7279
// Convert between global pick indexing for the whole program, and local per-structure pick indexing
73-
std::pair<Structure*, uint64_t> globalIndexToLocal(uint64_t globalInd);
74-
uint64_t localIndexToGlobal(std::pair<Structure*, uint64_t> localPick);
80+
std::tuple<Structure*, Quantity*, uint64_t> globalIndexToLocal(uint64_t globalInd);
81+
uint64_t localIndexToGlobal(std::tuple<Structure*, Quantity*, uint64_t> localPick);
7582

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

include/polyscope/point_cloud.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PointCloud : public QuantityStructure<PointCloud> {
6060
virtual void draw() override;
6161
virtual void drawDelayed() override;
6262
virtual void drawPick() override;
63+
virtual void drawPickDelayed() override;
6364
virtual void updateObjectSpaceBounds() override;
6465
virtual std::string typeName() override;
6566
virtual void refresh() override;

include/polyscope/polyscope.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ Structure* getStructure(std::string type, std::string name = "");
130130
// True if such a structure exists
131131
bool hasStructure(std::string type, std::string name);
132132

133-
// Look up the string type and name for a structure from its pointer
134-
// (performs a naive search over all structures for now, use sparingly)
135-
std::tuple<std::string, std::string> lookUpStructure(Structure* structure);
136-
137133
// De-register a structure, of any type. Also removes any quantities associated with the structure
138134
void removeStructure(Structure* structure, bool errorIfAbsent = false);
139135
void removeStructure(std::string type, std::string name, bool errorIfAbsent = false);

include/polyscope/quantity.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Quantity : public render::ManagedBufferRegistry {
3030
virtual void draw();
3131
virtual void drawDelayed(); // drawing that should happen after the main phase
3232

33+
// Draw pick buffers for the quantity
34+
virtual void drawPick();
35+
virtual void drawPickDelayed(); // drawing that should happen after the main phase
36+
3337
// Draw the ImGUI ui elements
3438
virtual void buildUI(); // draws the tree node and enabled checkbox common to almost all quantities, and calls
3539
// drawCustomUI() below. Can still be overidden in case something else is wanted.

include/polyscope/render_image_quantity_base.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class RenderImageQuantityBase : public FloatingQuantity, public FullscreenArtist
2626
const std::vector<float>& depthData, const std::vector<glm::vec3>& normalData,
2727
ImageOrigin imageOrigin);
2828

29-
// virtual void draw() override;
30-
// virtual void drawDelayed() override;
29+
virtual void drawPickDelayed() override;
3130

3231
virtual void refresh() override;
3332

@@ -73,9 +72,14 @@ class RenderImageQuantityBase : public FloatingQuantity, public FullscreenArtist
7372
PersistentValue<float> transparency;
7473
PersistentValue<bool> allowFullscreenCompositing;
7574

75+
// Picking is the same for all
76+
std::shared_ptr<render::ShaderProgram> pickProgram;
77+
glm::vec3 pickColor;
78+
7679
// Helpers
7780
void prepareGeometryBuffers();
7881
void addOptionsPopupEntries();
82+
void preparePick();
7983
};
8084

8185

0 commit comments

Comments
 (0)