Skip to content

Commit 07b0621

Browse files
committed
update for new managed buffer setup
1 parent b4b266a commit 07b0621

6 files changed

Lines changed: 24 additions & 41 deletions

‎include/polyscope/simple_triangle_mesh.ipp‎

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,36 @@ SimpleTriangleMesh* registerSimpleTriangleMesh(std::string name, const V& vertex
2626
template <class V>
2727
void SimpleTriangleMesh::updateVertices(const V& newPositions) {
2828
validateSize(newPositions, vertices.size(), "newPositions");
29-
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
30-
vertices.resize(d.size());
31-
vertices.setDataHost(d);
32-
vertices.markHostBufferUpdated();
29+
vertices.setDataHost(standardizeVectorArray<glm::vec3, 3>(newPositions));
3330
}
3431

3532
template <class V, class F>
3633
void SimpleTriangleMesh::update(const V& newPositions, const F& newFaces) {
37-
{
38-
auto d = standardizeVectorArray<glm::vec3, 3>(newPositions);
39-
vertices.resize(d.size());
40-
vertices.setDataHost(d);
41-
}
42-
vertices.markHostBufferUpdated();
34+
auto vertsStd = standardizeVectorArray<glm::vec3, 3>(newPositions);
35+
vertices.resize(vertsStd.size()); // ManagedBuffer internally does amortized doubling to make this efficient
36+
vertices.setDataHost(vertsStd);
4337

44-
{
45-
auto d = standardizeVectorArray<glm::uvec3, 3>(newFaces);
46-
faces.resize(d.size());
47-
faces.setDataHost(d);
48-
}
49-
faces.markHostBufferUpdated();
38+
auto facesStd = standardizeVectorArray<glm::uvec3, 3>(newFaces);
39+
faces.resize(facesStd.size());
40+
faces.setDataHost(facesStd);
5041
}
5142

5243
template <class V>
5344
void SimpleTriangleMesh::updateVertexPositions(const V& newPositions) {
5445
validateSize(newPositions, nVertices(), "newPositions");
55-
verticesData = standardizeVectorArray<glm::vec3, 3>(newPositions);
56-
vertices.markHostBufferUpdated();
46+
vertices.setDataHost(standardizeVectorArray<glm::vec3, 3>(newPositions));
5747
updateObjectSpaceBounds();
5848
}
5949

6050
template <class V, class F>
6151
void SimpleTriangleMesh::updateMesh(const V& newVerts, const F& newFaces) {
62-
std::vector<glm::vec3> vertsStd = standardizeVectorArray<glm::vec3, 3>(newVerts);
63-
if (vertsStd.size() > verticesData.capacity()) {
64-
// amortized doubling on the CPU-side backing vectors.
65-
verticesData.reserve(std::max(vertsStd.size(), 2 * verticesData.capacity()));
66-
}
67-
verticesData = std::move(vertsStd);
68-
vertices.markHostBufferUpdated();
52+
auto vertsStd = standardizeVectorArray<glm::vec3, 3>(newVerts);
53+
vertices.resize(vertsStd.size()); // amortized doubling handled by ManagedBuffer
54+
vertices.setDataHost(vertsStd);
6955

70-
std::vector<glm::uvec3> facesStd = standardizeVectorArray<glm::uvec3, 3>(newFaces);
71-
if (facesStd.size() > facesData.capacity()) {
72-
facesData.reserve(std::max(facesStd.size(), 2 * facesData.capacity()));
73-
}
74-
facesData = std::move(facesStd);
75-
faces.markHostBufferUpdated();
56+
auto facesStd = standardizeVectorArray<glm::uvec3, 3>(newFaces);
57+
faces.resize(facesStd.size());
58+
faces.setDataHost(facesStd);
7659

7760
updateObjectSpaceBounds();
7861
}

‎include/polyscope/simple_triangle_mesh_color_quantity.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ class SimpleTriangleMeshColorQuantity : public SimpleTriangleMeshQuantity,
2929
// For same-size updates, prefer ColorQuantity::updateData() which validates the size.
3030
template <class V>
3131
void updateData(const V& newColors) {
32-
std::vector<glm::vec3> newData = standardizeVectorArray<glm::vec3, 3>(newColors);
33-
colors.resize(newData.size());
34-
colors.data.assign(newData.begin(), newData.end());
35-
colors.markHostBufferUpdated();
32+
auto newData = standardizeVectorArray<glm::vec3, 3>(newColors);
33+
colors.resize(newData.size()); // amortized doubling handled by ManagedBuffer
34+
colors.setDataHost(newData);
3635
}
3736

3837
const std::string definedOn;

‎include/polyscope/simple_triangle_mesh_scalar_quantity.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ class SimpleTriangleMeshScalarQuantity : public SimpleTriangleMeshQuantity,
3030
// For same-size updates, prefer ScalarQuantity::updateData() which validates the size.
3131
template <class V>
3232
void updateData(const V& newValues) {
33-
std::vector<float> newData = standardizeArray<float, V>(newValues);
34-
values.resize(newData.size());
35-
values.data.assign(newData.begin(), newData.end());
36-
values.markHostBufferUpdated();
33+
auto newData = standardizeArray<float, V>(newValues);
34+
values.resize(newData.size()); // amortized doubling handled by ManagedBuffer
35+
values.setDataHost(newData);
3736
}
3837

3938
const std::string definedOn;

‎src/simple_triangle_mesh.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ void SimpleTriangleMesh::updateObjectSpaceBounds() {
307307
}
308308

309309
void SimpleTriangleMesh::reserve(size_t nVerts, size_t nFaces) {
310-
verticesData.reserve(nVerts);
311-
facesData.reserve(nFaces);
310+
vertices.setCapacity(nVerts);
311+
faces.setCapacity(nFaces);
312312
}
313313

314314
SimpleTriangleMeshPickResult SimpleTriangleMesh::interpretPickResult(const PickResult& rawResult) {

‎src/simple_triangle_mesh_color_quantity.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ SimpleTriangleMeshFaceColorQuantity::SimpleTriangleMeshFaceColorQuantity(std::st
112112
const std::vector<glm::vec3>& colors_,
113113
SimpleTriangleMesh& mesh_)
114114
: SimpleTriangleMeshColorQuantity(name, colors_, "face", mesh_) {
115+
colors.setAsType(DeviceBufferType::Texture1d);
115116
colors.setTextureSize(parent.nFaces());
116117
}
117118

‎src/simple_triangle_mesh_scalar_quantity.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ SimpleTriangleMeshFaceScalarQuantity::SimpleTriangleMeshFaceScalarQuantity(std::
107107
SimpleTriangleMesh& mesh_,
108108
DataType dataType_)
109109
: SimpleTriangleMeshScalarQuantity(name, values_, "face", mesh_, dataType_) {
110+
values.setAsType(DeviceBufferType::Texture1d);
110111
values.setTextureSize(parent.nFaces());
111112
}
112113

0 commit comments

Comments
 (0)