From 9392774a32f682a91ccf925373c21bc5a4e5b104 Mon Sep 17 00:00:00 2001 From: Ratna Jagadeesh <35951109+Ratnajagadeesharava@users.noreply.github.com> Date: Tue, 23 Apr 2024 00:29:52 +0530 Subject: [PATCH 1/3] #completed 2 test cases --- .../src/simplicial-complex-operators.cpp | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp index 7da20e8..855b852 100644 --- a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp +++ b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp @@ -19,19 +19,25 @@ void SimplicialComplexOperators::assignElementIndices() { geometry->requireEdgeIndices(); geometry->requireFaceIndices(); + // You can set the index field of a vertex via geometry->vertexIndices[v], where v is a Vertex object (or an // integer). Similarly you can do edges and faces via geometry->edgeIndices, geometry->faceIndices, like so: size_t idx = 0; for (Vertex v : mesh->vertices()) { idx = geometry->vertexIndices[v]; + idx++; } + idx= 0; for (Edge e : mesh->edges()) { idx = geometry->edgeIndices[e]; + idx++; } + idx = 0; for (Face f : mesh->faces()) { idx = geometry->faceIndices[f]; + idx++; } // You can more easily get the indices of mesh elements using the function getIndex(), albeit less efficiently and @@ -40,9 +46,10 @@ void SimplicialComplexOperators::assignElementIndices() { // v.getIndex() // // where v can be a Vertex, Edge, Face, Halfedge, etc. For example: - + idx = 0; for (Vertex v : mesh->vertices()) { idx = v.getIndex(); // == geometry->vertexIndices[v]) + idx++; } // Geometry Central already sets the indices for us, though, so this function is just here for demonstration. @@ -60,8 +67,19 @@ SparseMatrix SimplicialComplexOperators::buildVertexEdgeAdjacencyMatrix( // TODO // Note: You can build an Eigen sparse matrix from triplets, then return it as a Geometry Central SparseMatrix. // See for documentation. - - return identityMatrix(1); // placeholder + int rows =mesh->nEdges(); + int cols = mesh->nVertices(); + SparseMatrix vertexEdgeMatrix(rows,cols); + for (auto edge : mesh->edges()) { + int eidx = edge.getIndex(); + int v1idx = edge.firstVertex().getIndex(); + int v2idx = edge.secondVertex().getIndex(); + + vertexEdgeMatrix.insert(eidx,v1idx) = 1; + vertexEdgeMatrix.insert(eidx,v2idx) = 1; + + } + return vertexEdgeMatrix; // placeholder } /* @@ -73,7 +91,17 @@ SparseMatrix SimplicialComplexOperators::buildVertexEdgeAdjacencyMatrix( SparseMatrix SimplicialComplexOperators::buildFaceEdgeAdjacencyMatrix() const { // TODO - return identityMatrix(1); // placeholder + int rows = mesh->nFaces(); + int cols = mesh->nEdges(); + SparseMatrix edgeFaceMatrix(rows,cols); + for (auto face : mesh->faces()) { + int fidx = face.getIndex(); + for (auto edge : face.adjacentEdges()) { + int eidx = edge.getIndex(); + edgeFaceMatrix.insert(fidx,eidx) = 1; + } + } + return edgeFaceMatrix; // placeholder } /* From 1289f9356a057cc5fffe69de96ef8c408eb923c9 Mon Sep 17 00:00:00 2001 From: Ratna Jagadeesh <35951109+Ratnajagadeesharava@users.noreply.github.com> Date: Wed, 24 Apr 2024 00:53:39 +0530 Subject: [PATCH 2/3] completed star --- .../src/simplicial-complex-operators.cpp | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp index 855b852..07af189 100644 --- a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp +++ b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp @@ -101,19 +101,29 @@ SparseMatrix SimplicialComplexOperators::buildFaceEdgeAdjacencyMatrix() edgeFaceMatrix.insert(fidx,eidx) = 1; } } + return edgeFaceMatrix; // placeholder } /* * Construct a vector encoding the vertices in the selected subset of simplices. * - * Input: Selected subset of simplices. + * we need to find if what vertices of this subset + * Input: Selected subset buildVertexVector simplices. * Returns: Vector of length |V|, where |V| = # of vertices in the mesh. */ Vector SimplicialComplexOperators::buildVertexVector(const MeshSubset& subset) const { - // TODO - return Vector::Zero(1); + Vector v(mesh->nVertices()); + for (int i = 0; i < mesh->nVertices(); i++) { + if (subset.vertices.count(i)) { + v[i] = 1; + } else { + v[i] = 0; + } + } + return v; + } /* @@ -125,7 +135,16 @@ Vector SimplicialComplexOperators::buildVertexVector(const MeshSubset& s Vector SimplicialComplexOperators::buildEdgeVector(const MeshSubset& subset) const { // TODO - return Vector::Zero(1); + + Vector edgeVectors(mesh->nEdges()); + for (int i = 0; i < mesh->nEdges(); i++) { + if (subset.edges.count(i)) { + edgeVectors[i] = 1; + } else { + edgeVectors[i] = 0; + } + } + return edgeVectors; } /* @@ -135,9 +154,15 @@ Vector SimplicialComplexOperators::buildEdgeVector(const MeshSubset& sub * Returns: Vector of length |F|, where |F| = # of faces in mesh. */ Vector SimplicialComplexOperators::buildFaceVector(const MeshSubset& subset) const { - - // TODO - return Vector::Zero(1); + Vector faceVectors(mesh->nFaces()); + for (int i = 0; i < mesh->nFaces(); i++) { + if (subset.edges.count(i)) { + faceVectors[i] = 1; + } else { + faceVectors[i] = 0; + } + } + return faceVectors; } /* @@ -147,9 +172,36 @@ Vector SimplicialComplexOperators::buildFaceVector(const MeshSubset& sub * Returns: The star of the given subset. */ MeshSubset SimplicialComplexOperators::star(const MeshSubset& subset) const { + + + //current set is already part of star + MeshSubset starSet(subset); + + //outerSize --> columns + //innerSize --> rows + + int cols = A0.outerSize(); + int rows = A0.innerSize(); + for (auto vertex : subset.vertices) { + + /*starSet.addVertex(vertex);*/ + for (int e = 0; e < mesh->nEdges(); e++) { + if (A0.coeff(e, vertex)) { + starSet.addEdge(e); + } + } + + } + for (auto edge : starSet.edges) { + for (int f = 0; f < mesh->nFaces(); f++) { + if (A1.coeff(f, edge)) { + starSet.addFace(f); + } + } + } // TODO - return subset; // placeholder + return starSet; // placeholder } From 1f93b45c4cec515a4821a0ce1f8f3bf64156761a Mon Sep 17 00:00:00 2001 From: ratnajagadeesh arava Date: Wed, 24 Apr 2024 11:45:59 +0530 Subject: [PATCH 3/3] added closureSet --- .../src/simplicial-complex-operators.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp index 07af189..3bb4281 100644 --- a/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp +++ b/projects/simplicial-complex-operators/src/simplicial-complex-operators.cpp @@ -212,9 +212,24 @@ MeshSubset SimplicialComplexOperators::star(const MeshSubset& subset) const { * Returns: The closure of the given subset. */ MeshSubset SimplicialComplexOperators::closure(const MeshSubset& subset) const { + MeshSubset closureSet(subset); + for (auto face : subset.faces) { + for (int i = 0; i < mesh->nEdges(); i++) { + if (A1.coeff(face, i)) { + closureSet.addEdge(i); + } + } + } + for (auto edge : closureSet.edges) { + for (int i = 0; i < mesh->nVertices(); i++) { + if (A0.coeff(edge, i)) { + closureSet.addVertex(i); + } + } + } // TODO - return subset; // placeholder + return closureSet; // placeholder } /*