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
6 changes: 6 additions & 0 deletions include/polyscope/render/managed_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ class ManagedBuffer : public virtual WeakReferrable {
// same view will be returned repeatedly at no additional cost.
std::shared_ptr<render::AttributeBuffer> getIndexedRenderAttributeBuffer(ManagedBuffer<uint32_t>& indices);

// Get a copy of the data viewed through an index, such that view[i] = data[indices[i]].
//
// This follows the same logic as above, but rather than returning a render buffer it simply returns a host-side
// copy (which is not cached).
std::vector<T> getIndexedView(ManagedBuffer<uint32_t>& indices);

// ========================================================================
// == Direct access to the GPU (device-side) render texture buffer
// ========================================================================
Expand Down
3 changes: 3 additions & 0 deletions include/polyscope/surface_parameterization_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SurfaceParameterizationQuantity : public SurfaceMeshQuantity,
void createProgram();
size_t nFaces(); // works around an incomplete def of the parent mesh
virtual void fillCoordBuffers(render::ShaderProgram& p) = 0;
virtual std::vector<glm::vec2> getCornerCoords() = 0;
};


Expand All @@ -66,6 +67,7 @@ class SurfaceCornerParameterizationQuantity : public SurfaceParameterizationQuan

protected:
virtual void fillCoordBuffers(render::ShaderProgram& p) override;
virtual std::vector<glm::vec2> getCornerCoords() override;
};


Expand All @@ -84,6 +86,7 @@ class SurfaceVertexParameterizationQuantity : public SurfaceParameterizationQuan

protected:
virtual void fillCoordBuffers(render::ShaderProgram& p) override;
virtual std::vector<glm::vec2> getCornerCoords() override;
};


Expand Down
8 changes: 8 additions & 0 deletions src/render/managed_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ ManagedBuffer<T>::getIndexedRenderAttributeBuffer(ManagedBuffer<uint32_t>& indic
return newBuffer;
}

template <typename T>
std::vector<T> ManagedBuffer<T>::getIndexedView(ManagedBuffer<uint32_t>& indices) {
checkDeviceBufferTypeIs(DeviceBufferType::Attribute);
ensureHostBufferPopulated();
indices.ensureHostBufferPopulated();
return gather(data, indices.data);
}

template <typename T>
void ManagedBuffer<T>::updateIndexedViews() {
checkDeviceBufferTypeIs(DeviceBufferType::Attribute);
Expand Down
18 changes: 14 additions & 4 deletions src/surface_parameterization_quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ CurveNetwork* SurfaceParameterizationQuantity::createCurveNetworkFromSeams(std::
}

// Populate data on the host
coords.ensureHostBufferPopulated();
parent.triangleCornerInds.ensureHostBufferPopulated();
parent.triangleVertexInds.ensureHostBufferPopulated();
parent.edgeIsReal.ensureHostBufferPopulated();
parent.vertexPositions.ensureHostBufferPopulated();

// expand out the coords buffer based on how the quantity is indexed
std::vector<glm::vec2> cornerCoords = getCornerCoords();

// helper to canonicalize edge direction
auto canonicalizeEdge = [](std::pair<int32_t, int32_t>& inds, std::pair<glm::vec2, glm::vec2>& coords)
{
Expand All @@ -141,7 +143,7 @@ CurveNetwork* SurfaceParameterizationQuantity::createCurveNetworkFromSeams(std::
int32_t iC_tail = parent.triangleCornerInds.data[3*iT + (k+0)%3];
int32_t iC_tip = parent.triangleCornerInds.data[3*iT + (k+1)%3];
std::pair<int32_t, int32_t> eInd (iV_tail, iV_tip);
std::pair<glm::vec2, glm::vec2> eC (coords.data[iC_tail], coords.data[iC_tip]);
std::pair<glm::vec2, glm::vec2> eC (cornerCoords[iC_tail], cornerCoords[iC_tip]);
canonicalizeEdge(eInd, eC); // make sure ordering is consistent

// increment the count
Expand Down Expand Up @@ -178,7 +180,7 @@ CurveNetwork* SurfaceParameterizationQuantity::createCurveNetworkFromSeams(std::
for(const std::pair<int32_t, int32_t>& edge: seamEdges) {
int32_t vA = edge.first;
int32_t vB = edge.second;

// get unique vertices for the edges
if(vertexIndToDense.find(vA) == vertexIndToDense.end()) {
vertexIndToDense[vA] = seamEdgeNodes.size();
Expand All @@ -196,7 +198,6 @@ CurveNetwork* SurfaceParameterizationQuantity::createCurveNetworkFromSeams(std::
}

// add the curve network

return registerCurveNetwork(structureName, seamEdgeNodes, seamEdgeInds);
}

Expand Down Expand Up @@ -227,6 +228,11 @@ void SurfaceCornerParameterizationQuantity::fillCoordBuffers(render::ShaderProgr
p.setAttribute("a_value2", coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds));
}


std::vector<glm::vec2> SurfaceCornerParameterizationQuantity::getCornerCoords() {
return coords.getIndexedView(parent.triangleCornerInds);
}

void SurfaceCornerParameterizationQuantity::buildCornerInfoGUI(size_t cInd) {

glm::vec2 coord = coords.getValue(cInd);
Expand Down Expand Up @@ -254,6 +260,10 @@ void SurfaceVertexParameterizationQuantity::fillCoordBuffers(render::ShaderProgr
p.setAttribute("a_value2", coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds));
}

std::vector<glm::vec2> SurfaceVertexParameterizationQuantity::getCornerCoords() {
return coords.getIndexedView(parent.triangleVertexInds);
}

void SurfaceVertexParameterizationQuantity::buildVertexInfoGUI(size_t vInd) {

glm::vec2 coord = coords.getValue(vInd);
Expand Down
8 changes: 8 additions & 0 deletions test/src/curve_network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ TEST_F(PolyscopeTest, ShowCurveNetwork) {
EXPECT_FALSE(polyscope::hasCurveNetwork("test1"));
}

TEST_F(PolyscopeTest, EmptyCurveNetwork) {
std::vector<glm::vec3> points;
std::vector<std::array<size_t, 2>> edges;
polyscope::registerCurveNetwork("empty", points, edges);
polyscope::show(3);
polyscope::removeAllStructures();
}

TEST_F(PolyscopeTest, CurveNetworkAppearance) {
auto psCurve = registerCurveNetwork();

Expand Down
4 changes: 4 additions & 0 deletions test/src/surface_mesh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ TEST_F(PolyscopeTest, SurfaceMeshVertexParam) {
q1->setStyle(polyscope::ParamVizStyle::LOCAL_RAD);
polyscope::show(3);

// create the curve network
q1->createCurveNetworkFromSeams();
polyscope::show(3);

polyscope::removeAllStructures();
}

Expand Down
Loading