Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/demo-app/demo_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ void callback() {
std::cout << " io.MousePos.x: " << io.MousePos.x << " io.MousePos.y: " << io.MousePos.y << std::endl;
std::cout << " screenCoords.x: " << screenCoords.x << " screenCoords.y: " << screenCoords.y << std::endl;
std::cout << " bufferInd.x: " << xInd << " bufferInd.y: " << yInd << std::endl;
std::cout << " depth: " << pickResult.depth << std::endl;
std::cout << " worldRay: ";
polyscope::operator<<(std::cout, worldRay) << std::endl;
std::cout << " worldPos: ";
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/camera_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CameraView : public QuantityStructure<CameraView> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct Context {
bool haveSelectionVal = false;
uint64_t nextPickBufferInd = 1;
std::unordered_map<Structure*, std::tuple<uint64_t, uint64_t>> structureRanges;
std::unordered_map<Quantity*, std::tuple<uint64_t, uint64_t>> quantityRanges;

// ======================================================
// === Internal globals from internal.h
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/curve_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CurveNetwork : public QuantityStructure<CurveNetwork> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;

virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/floating_quantity_structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FloatingQuantityStructure : public QuantityStructure<FloatingQuantityStruc
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual bool hasExtents() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
Expand Down
13 changes: 10 additions & 3 deletions include/polyscope/pick.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstdint>
#include <string>
#include <tuple>
#include <utility>

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

// Forward decls
class Structure;
class Quantity;

// == Main query

Expand All @@ -26,9 +28,11 @@ class Structure;
struct PickResult {
bool isHit = false;
Structure* structure = nullptr;
Quantity* quantity = nullptr;
WeakHandle<Structure> structureHandle; // same as .structure, but with lifetime tracking
std::string structureType = "";
std::string structureName = "";
std::string quantityName = "";
glm::vec2 screenCoords;
glm::ivec2 bufferInds;
glm::vec3 position;
Expand Down Expand Up @@ -60,18 +64,21 @@ namespace pick {
std::pair<Structure*, uint64_t> pickAtScreenCoords(glm::vec2 screenCoords); // takes screen coordinates
std::pair<Structure*, uint64_t> pickAtBufferCoords(int xPos, int yPos); // takes indices into the buffer
std::pair<Structure*, uint64_t> evaluatePickQuery(int xPos, int yPos); // old, badly named. takes buffer coordinates.
std::tuple<Structure*, Quantity*, uint64_t> evaluatePickQueryFull(int xPos,
int yPos); // badly named. takes buffer coordinates.


// == Helpers

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

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

// Convert indices to float3 color and back
// Structures will want to use these to fill their pick buffers
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PointCloud : public QuantityStructure<PointCloud> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
4 changes: 0 additions & 4 deletions include/polyscope/polyscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ Structure* getStructure(std::string type, std::string name = "");
// True if such a structure exists
bool hasStructure(std::string type, std::string name);

// Look up the string type and name for a structure from its pointer
// (performs a naive search over all structures for now, use sparingly)
std::tuple<std::string, std::string> lookUpStructure(Structure* structure);

// De-register a structure, of any type. Also removes any quantities associated with the structure
void removeStructure(Structure* structure, bool errorIfAbsent = false);
void removeStructure(std::string type, std::string name, bool errorIfAbsent = false);
Expand Down
4 changes: 4 additions & 0 deletions include/polyscope/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Quantity : public render::ManagedBufferRegistry {
virtual void draw();
virtual void drawDelayed(); // drawing that should happen after the main phase

// Draw pick buffers for the quantity
virtual void drawPick();
virtual void drawPickDelayed(); // drawing that should happen after the main phase

// Draw the ImGUI ui elements
virtual void buildUI(); // draws the tree node and enabled checkbox common to almost all quantities, and calls
// drawCustomUI() below. Can still be overidden in case something else is wanted.
Expand Down
8 changes: 6 additions & 2 deletions include/polyscope/render_image_quantity_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class RenderImageQuantityBase : public FloatingQuantity, public FullscreenArtist
const std::vector<float>& depthData, const std::vector<glm::vec3>& normalData,
ImageOrigin imageOrigin);

// virtual void draw() override;
// virtual void drawDelayed() override;
virtual void drawPickDelayed() override;

virtual void refresh() override;

Expand Down Expand Up @@ -73,9 +72,14 @@ class RenderImageQuantityBase : public FloatingQuantity, public FullscreenArtist
PersistentValue<float> transparency;
PersistentValue<bool> allowFullscreenCompositing;

// Picking is the same for all
std::shared_ptr<render::ShaderProgram> pickProgram;
glm::vec3 pickColor;

// Helpers
void prepareGeometryBuffers();
void addOptionsPopupEntries();
void preparePick();
};


Expand Down
1 change: 1 addition & 0 deletions include/polyscope/simple_triangle_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SimpleTriangleMesh : public QuantityStructure<SimpleTriangleMesh> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
6 changes: 4 additions & 2 deletions include/polyscope/structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class Structure : public render::ManagedBufferRegistry, public virtual WeakRefer

// == Render the the structure on screen
virtual void draw() = 0;
virtual void drawDelayed() = 0;
virtual void drawPick() = 0;
virtual void drawDelayed() = 0; // a second render pass
virtual void drawPickDelayed() = 0;

// == Add rendering rules
std::vector<std::string> addStructureRules(std::vector<std::string> initRules);
Expand All @@ -58,7 +59,8 @@ class Structure : public render::ManagedBufferRegistry, public virtual WeakRefer
virtual void buildPickUI(const PickResult& result) = 0; // Draw pick UI elements based on a selection result

// = Identifying data
const std::string name; // should be unique amongst registered structures with this type
const std::string name; // should be unique amongst registered structures with this type
const std::string subtypeName; // specific type name, like "Point Cloud"
std::string uniquePrefix();

std::string getName() { return name; }; // used by pybind to access the name property
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/surface_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SurfaceMesh : public QuantityStructure<SurfaceMesh> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/volume_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class VolumeGrid : public QuantityStructure<VolumeGrid> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/volume_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class VolumeMesh : public QuantityStructure<VolumeMesh> {
virtual void draw() override;
virtual void drawDelayed() override;
virtual void drawPick() override;
virtual void drawPickDelayed() override;
virtual void updateObjectSpaceBounds() override;
virtual std::string typeName() override;
virtual void refresh() override;
Expand Down
21 changes: 21 additions & 0 deletions src/camera_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ void CameraView::drawPick() {
pickFrameProgram->setUniform("u_vertPickRadius", 0.);

pickFrameProgram->draw();

for (auto& x : quantities) {
x.second->drawPick();
}
for (auto& x : floatingQuantities) {
x.second->drawPick();
}
}


void CameraView::drawPickDelayed() {
if (!isEnabled()) {
return;
}

for (auto& x : quantities) {
x.second->drawPickDelayed();
}
for (auto& x : floatingQuantities) {
x.second->drawPickDelayed();
}
}

void CameraView::prepare() {
Expand Down
20 changes: 20 additions & 0 deletions src/curve_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ void CurveNetwork::drawPick() {

edgePickProgram->draw();
nodePickProgram->draw();

for (auto& x : quantities) {
x.second->drawPick();
}
for (auto& x : floatingQuantities) {
x.second->drawPick();
}
}

void CurveNetwork::drawPickDelayed() {
if (!isEnabled()) {
return;
}

for (auto& x : quantities) {
x.second->drawPickDelayed();
}
for (auto& x : floatingQuantities) {
x.second->drawPickDelayed();
}
}

std::vector<std::string> CurveNetwork::addCurveNetworkNodeRules(std::vector<std::string> initRules) {
Expand Down
22 changes: 21 additions & 1 deletion src/floating_quantity_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,27 @@ void FloatingQuantityStructure::drawDelayed() {
}
}

void FloatingQuantityStructure::drawPick() {}
void FloatingQuantityStructure::drawPick() {
if (!isEnabled()) return;

for (auto& qp : quantities) {
qp.second->drawPick();
}
for (auto& qp : floatingQuantities) {
qp.second->drawPick();
}
}

void FloatingQuantityStructure::drawPickDelayed() {
if (!isEnabled()) return;

for (auto& qp : quantities) {
qp.second->drawPickDelayed();
}
for (auto& qp : floatingQuantities) {
qp.second->drawPickDelayed();
}
}

// override the structure UI, since this one is a bit different
void FloatingQuantityStructure::buildUI() {
Expand Down
Loading
Loading