Skip to content
Open
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
9 changes: 8 additions & 1 deletion examples/demo-app/demo_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void processFileOBJ(std::string filename) {
}
auto psMesh = polyscope::registerSurfaceMesh(niceName, vertexPositionsGLM, faceIndices);

auto psSimpleMesh = polyscope::registerSimpleTriangleMesh(niceName, vertexPositionsGLM, faceIndices);
auto psSimpleMesh = polyscope::registerSimpleTriangleMesh(niceName + " (simple)", vertexPositionsGLM, faceIndices);
psSimpleMesh->setEnabled(false);

// Useful data
Expand Down Expand Up @@ -154,6 +154,10 @@ void processFileOBJ(std::string filename) {
polyscope::getSurfaceMesh(niceName)->addVertexScalarQuantity("categorical vert", valCat,
polyscope::DataType::CATEGORICAL);

// Simple triangle mesh quantities
psSimpleMesh->addVertexScalarQuantity("cY", valY);
psSimpleMesh->addVertexColorQuantity("vColor", randColor);

polyscope::getSurfaceMesh(niceName)->addVertexDistanceQuantity("cY_dist", valY);
polyscope::getSurfaceMesh(niceName)->addVertexSignedDistanceQuantity("cY_signeddist", valY);

Expand Down Expand Up @@ -186,6 +190,9 @@ void processFileOBJ(std::string filename) {
polyscope::getSurfaceMesh(niceName)->addFaceScalarQuantity("categorical face", fCat,
polyscope::DataType::CATEGORICAL);

psSimpleMesh->addFaceScalarQuantity("face area", fArea, polyscope::DataType::MAGNITUDE);
psSimpleMesh->addFaceColorQuantity("fColor", fColor);


// size_t nEdges = psMesh->nEdges();

Expand Down
2 changes: 0 additions & 2 deletions include/polyscope/color_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ColorImageQuantity : public ImageQuantity {


protected:
std::vector<glm::vec4> colorsData;

PersistentValue<bool> isPremultiplied;

// rendering internals
Expand Down
2 changes: 0 additions & 2 deletions include/polyscope/color_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class ColorQuantity {
// === ~DANGER~ experimental/unsupported functions

protected:
std::vector<glm::vec3> colorsData;

// === Visualization parameters

// Parameters
Expand Down
6 changes: 4 additions & 2 deletions include/polyscope/color_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace polyscope {

template <typename QuantityT>
ColorQuantity<QuantityT>::ColorQuantity(QuantityT& quantity_, const std::vector<glm::vec3>& colors_)
: quantity(quantity_), colors(&quantity, quantity.uniquePrefix() + "colors", colorsData), colorsData(colors_) {
: quantity(quantity_), colors(&quantity, quantity.uniquePrefix() + "colors", std::vector<glm::vec3>(colors_)) {
colors.checkInvalidValues();
}

Expand All @@ -27,7 +27,9 @@ template <typename QuantityT>
template <class V>
void ColorQuantity<QuantityT>::updateData(const V& newColors) {
validateSize(newColors, colors.size(), "color quantity");
colors.data = standardizeVectorArray<glm::vec3, 3>(newColors);
auto d = standardizeVectorArray<glm::vec3, 3>(newColors);
colors.resize(d.size());
colors.setDataHost(d);
colors.markHostBufferUpdated();
}

Expand Down
5 changes: 1 addition & 4 deletions include/polyscope/color_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class ColorRenderImageQuantity : public RenderImageQuantityBase {
protected:
// === Visualization parameters

// Store the raw data
std::vector<glm::vec3> colorsData;

// === Render data
std::shared_ptr<render::ShaderProgram> program;

Expand All @@ -60,7 +57,7 @@ void ColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& norm
std::vector<glm::vec3> standardNormal(standardizeVectorArray<glm::vec3, 3>(normalData));
std::vector<glm::vec3> standardColor(standardizeVectorArray<glm::vec3, 3>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
7 changes: 0 additions & 7 deletions include/polyscope/curve_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ class CurveNetwork : public Structure {


private:
// Storage for the managed buffers above. You should generally interact with these through the managed buffers, not
// these members.
std::vector<glm::vec3> nodePositionsData;
std::vector<uint32_t> edgeTailIndsData;
std::vector<uint32_t> edgeTipIndsData;
std::vector<glm::vec3> edgeCentersData;

void computeEdgeCenters();

// === Visualization parameters
Expand Down
4 changes: 3 additions & 1 deletion include/polyscope/curve_network.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ CurveNetwork* registerCurveNetworkLoop2D(std::string name, const P& nodes) {
template <class V>
void CurveNetwork::updateNodePositions(const V& newPositions) {
validateSize(newPositions, nNodes(), "newPositions");
nodePositions.data = standardizeVectorArray<glm::vec3, 3>(newPositions);
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
nodePositions.resize(d.size());
nodePositions.setDataHost(d);
nodePositions.markHostBufferUpdated();
recomputeGeometryIfPopulated();
}
Expand Down
3 changes: 0 additions & 3 deletions include/polyscope/curve_network_color_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class CurveNetworkEdgeColorQuantity : public CurveNetworkColorQuantity {

render::ManagedBuffer<glm::vec3> nodeAverageColors;
void updateNodeAverageColors();

private:
std::vector<glm::vec3> nodeAverageColorsData;
};

} // namespace polyscope
3 changes: 0 additions & 3 deletions include/polyscope/curve_network_scalar_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class CurveNetworkEdgeScalarQuantity : public CurveNetworkScalarQuantity {

render::ManagedBuffer<float> nodeAverageValues;
void updateNodeAverageValues();

private:
std::vector<float> nodeAverageValuesData;
};


Expand Down
3 changes: 0 additions & 3 deletions include/polyscope/parameterization_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ class ParameterizationQuantity {
void setParameterizationUniforms(render::ShaderProgram& p);

protected:
// Raw storage for the data. You should only interact with this via the managed buffer above
std::vector<glm::vec2> coordsData;
std::vector<float> islandLabelsData;
bool islandLabelsPopulated = false;

// === Visualization parameters
Expand Down
9 changes: 5 additions & 4 deletions include/polyscope/parameterization_quantity.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ ParameterizationQuantity<QuantityT>::ParameterizationQuantity(QuantityT& quantit
: quantity(quantity_),

// buffers
coords(&quantity, quantity.uniquePrefix() + "#coords", coordsData),
islandLabels(&quantity, quantity.uniquePrefix() + "#islandLabels", islandLabelsData), coordsType(type_),
coordsData(coords_),
coords(&quantity, quantity.uniquePrefix() + "#coords", std::vector<glm::vec2>(coords_)),
islandLabels(&quantity, quantity.uniquePrefix() + "#islandLabels", std::vector<float>{}), coordsType(type_),

// options
checkerSize(quantity.uniquePrefix() + "#checkerSize", 0.02),
Expand Down Expand Up @@ -227,7 +226,9 @@ template <typename QuantityT>
template <class V>
void ParameterizationQuantity<QuantityT>::updateCoords(const V& newCoords) {
validateSize(newCoords, coords.size(), "parameterization quantity " + quantity.name);
coords.data = standardizeVectorArray<glm::vec2, 2>(newCoords);
auto d = standardizeVectorArray<glm::vec2, 2>(newCoords);
coords.resize(d.size());
coords.setDataHost(d);
coords.markHostBufferUpdated();
}

Expand Down
50 changes: 50 additions & 0 deletions include/polyscope/pick.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const uint64_t bitsForPickPacking = 22;

inline glm::vec3 indToVec(size_t globalInd) {

// NOTE: there is a duplicate version of this logic in a macro below, which must be kept in sync.

// Can comfortably fit a 22 bit integer exactly in a single precision float
uint64_t factor = 1 << bitsForPickPacking;
uint64_t mask = factor - 1;
Expand Down Expand Up @@ -48,5 +50,53 @@ inline uint64_t vecToInd(glm::vec3 vec) {
return ind;
}


// == Weird alternate implementation of indToVec()
// This is here because sometimes we want to evaluate the indToVec() bit-bashing logic in a shader, and get exactly
// the same result as the C++ version above. A GLSL implementation is not too bad, but it's hard to test to ensure
// it really matches.
//
// The solution here is a funky macro'd implementation, that compiles as C++ or GLSL. We compile it as C++ in the tests
// and verify it matches the usual indToVec() implementation, then compile it as GLSL in shaders.
//
// All of the macro stuff you see below is just boilerplate to make that possible.

#define POLYSCOPE_PICK_STR_H(...) #__VA_ARGS__
#define POLYSCOPE_PICK_STR(...) POLYSCOPE_PICK_STR_H(__VA_ARGS__)

// See note above. This is logic that is meant to be identical to indToVec().
// clang-format off
#define POLYSCOPE_PICK_INDEX_COLOR_BODY \
POLYSCOPE_PICK_UINT idxLow = pickStartLow + primID; \
POLYSCOPE_PICK_UINT carry = (idxLow < pickStartLow) ? 1u : 0u; \
POLYSCOPE_PICK_UINT idxHigh = pickStartHigh + carry; \
POLYSCOPE_PICK_UINT low22 = idxLow & 0x3FFFFFu; \
POLYSCOPE_PICK_UINT med22 = ((idxLow >> 22u) | (idxHigh << 10u)) & 0x3FFFFFu; \
POLYSCOPE_PICK_UINT high22 = (idxHigh >> 12u) & 0x3FFFFFu; \
return POLYSCOPE_PICK_VEC3(float(low22), float(med22), float(high22)) / 4194304.0f;
// clang-format on

// C++ version: compile the body with C++ types.
#define POLYSCOPE_PICK_UINT uint32_t
#define POLYSCOPE_PICK_VEC3 glm::vec3
inline glm::vec3 pickIndexToColorImpl(uint32_t pickStartLow, uint32_t pickStartHigh, uint32_t primID) {
POLYSCOPE_PICK_INDEX_COLOR_BODY
}
#undef POLYSCOPE_PICK_UINT
#undef POLYSCOPE_PICK_VEC3

// Convenience wrapper for C++ callers that have a combined uint64_t pickStart.
inline glm::vec3 pickIndexToColor(uint64_t pickStart, uint32_t primID) {
return pickIndexToColorImpl(static_cast<uint32_t>(pickStart & 0xFFFFFFFFull), static_cast<uint32_t>(pickStart >> 32),
primID);
}

// GLSL string macro. Stringifies POLYSCOPE_PICK_INDEX_COLOR_BODY using GLSL type names.
// REQUIRES: POLYSCOPE_PICK_UINT must equal "uint" and POLYSCOPE_PICK_VEC3 must equal "vec3"
// at the point of expansion (see common.cpp for the usage pattern).
#define POLYSCOPE_PICK_INDEX_TO_COLOR_GLSL \
"vec3 pickIndexToColor(uint pickStartLow, uint pickStartHigh, uint primID) { " POLYSCOPE_PICK_STR( \
POLYSCOPE_PICK_INDEX_COLOR_BODY) " }"

} // namespace pick
} // namespace polyscope
2 changes: 0 additions & 2 deletions include/polyscope/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class PointCloud : public Structure {


private:
// Storage for the managed buffers above. You should generally interact with this directly through them.
std::vector<glm::vec3> pointsData;

// === Visualization parameters
PersistentValue<std::string> pointRenderMode;
Expand Down
4 changes: 3 additions & 1 deletion include/polyscope/point_cloud.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ PointCloud* registerPointCloud2D(std::string name, const T& points) {
template <class V>
void PointCloud::updatePointPositions(const V& newPositions) {
validateSize(newPositions, nPoints(), "point cloud updated positions " + name);
points.data = standardizeVectorArray<glm::vec3, 3>(newPositions);
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
points.resize(d.size());
points.setDataHost(d);
points.markHostBufferUpdated();
}

Expand Down
1 change: 1 addition & 0 deletions include/polyscope/polyscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void drawStructuresDelayed();
// need to call this directly.
void processLazyProperties();
void processLazyPropertiesOutsideOfImGui();
void forceRecomputeAllStructureBounds();


} // namespace polyscope
5 changes: 1 addition & 4 deletions include/polyscope/raw_color_alpha_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class RawColorAlphaRenderImageQuantity : public RenderImageQuantityBase {
bool getIsPremultiplied();

protected:
// Store the raw data
std::vector<glm::vec4> colorsData;

// === Visualization parameters
PersistentValue<bool> isPremultiplied;

Expand All @@ -59,7 +56,7 @@ void RawColorAlphaRenderImageQuantity::updateBuffers(const T1& depthData, const
std::vector<glm::vec3> standardNormal;
std::vector<glm::vec4> standardColor(standardizeVectorArray<glm::vec4, 4>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
5 changes: 1 addition & 4 deletions include/polyscope/raw_color_render_image_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class RawColorRenderImageQuantity : public RenderImageQuantityBase {
protected:
// === Visualization parameters

// Store the raw data
std::vector<glm::vec3> colorsData;

// === Render data
std::shared_ptr<render::ShaderProgram> program;

Expand All @@ -56,7 +53,7 @@ void RawColorRenderImageQuantity::updateBuffers(const T1& depthData, const T2& c
std::vector<glm::vec3> standardNormal;
std::vector<glm::vec3> standardColor(standardizeVectorArray<glm::vec3, 3>(colorsData));

colors.data = standardColor;
colors.setDataHost(standardColor);
colors.markHostBufferUpdated();

updateBaseBuffers(standardDepth, standardNormal);
Expand Down
19 changes: 17 additions & 2 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

namespace polyscope {

// Forward declarations for ManagedBuffer integration
namespace render {
class ManagedBufferBase;
template <typename T> class ManagedBuffer;
} // namespace render

// == A few enums that control behavior
// public enums are in the outer namespace to keep the typing burden down

Expand Down Expand Up @@ -96,6 +102,10 @@ class AttributeBuffer {
virtual void setData(const std::vector<std::array<glm::vec3, 3>>& data) = 0;
virtual void setData(const std::vector<std::array<glm::vec3, 4>>& data) = 0;

// Pre-allocate GPU memory for n elements without uploading any data. Subsequent setData()
// calls with size <= n will not need to reallocate the underlying buffer.
virtual void reserveCapacity(size_t n) = 0;

virtual uint32_t getNativeBufferID() = 0; // used to interop with external things, e.g. ImGui

// == Getters
Expand Down Expand Up @@ -391,7 +401,7 @@ class ShaderProgram {
virtual bool hasAttribute(std::string name) = 0;
virtual bool attributeIsSet(std::string name) = 0;
virtual std::shared_ptr<AttributeBuffer> getAttributeBuffer(std::string name) = 0;
virtual void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer) = 0;
virtual void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer, ManagedBufferBase* source = nullptr) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec2>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec3>& data) = 0;
virtual void setAttribute(std::string name, const std::vector<glm::vec4>& data) = 0;
Expand All @@ -414,8 +424,13 @@ class ShaderProgram {
bool withAlpha = true, bool useMipMap = false, bool repeat = false) = 0;
virtual void setTextureFromColormap(std::string name, const std::string& colorMap, bool allowUpdate = false) = 0;
// TODO make this one take a shared pointer and have the same semantics as the attribute version
virtual void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer) = 0;
virtual void setTextureFromBuffer(std::string name, TextureBuffer* textureBuffer, ManagedBufferBase* source = nullptr) = 0;


// Convenience overloads for ManagedBuffer — set the buffer AND record the source for lazy sync.
// Defined in managed_buffer.h after ManagedBuffer<T> is fully declared.
template <typename T> void setAttribute(std::string name, ManagedBuffer<T>& buf);
template <typename T> void setTextureFromBuffer(std::string name, ManagedBuffer<T>& buf);

// Indices
virtual void setIndex(std::shared_ptr<AttributeBuffer> externalBuffer) = 0;
Expand Down
Loading
Loading