Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 1 #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -60,8 +67,19 @@ SparseMatrix<size_t> SimplicialComplexOperators::buildVertexEdgeAdjacencyMatrix(
// TODO
// Note: You can build an Eigen sparse matrix from triplets, then return it as a Geometry Central SparseMatrix.
// See <https://eigen.tuxfamily.org/dox/group__TutorialSparse.html> for documentation.

return identityMatrix<size_t>(1); // placeholder
int rows =mesh->nEdges();
int cols = mesh->nVertices();
SparseMatrix<size_t> 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
}

/*
Expand All @@ -73,19 +91,39 @@ SparseMatrix<size_t> SimplicialComplexOperators::buildVertexEdgeAdjacencyMatrix(
SparseMatrix<size_t> SimplicialComplexOperators::buildFaceEdgeAdjacencyMatrix() const {

// TODO
return identityMatrix<size_t>(1); // placeholder
int rows = mesh->nFaces();
int cols = mesh->nEdges();
SparseMatrix<size_t> 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
}

/*
* 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<size_t> SimplicialComplexOperators::buildVertexVector(const MeshSubset& subset) const {

// TODO
return Vector<size_t>::Zero(1);
Vector<size_t> 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;

}

/*
Expand All @@ -97,7 +135,16 @@ Vector<size_t> SimplicialComplexOperators::buildVertexVector(const MeshSubset& s
Vector<size_t> SimplicialComplexOperators::buildEdgeVector(const MeshSubset& subset) const {

// TODO
return Vector<size_t>::Zero(1);

Vector<size_t> 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;
}

/*
Expand All @@ -107,9 +154,15 @@ Vector<size_t> SimplicialComplexOperators::buildEdgeVector(const MeshSubset& sub
* Returns: Vector of length |F|, where |F| = # of faces in mesh.
*/
Vector<size_t> SimplicialComplexOperators::buildFaceVector(const MeshSubset& subset) const {

// TODO
return Vector<size_t>::Zero(1);
Vector<size_t> 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;
}

/*
Expand All @@ -119,9 +172,36 @@ Vector<size_t> 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
}


Expand All @@ -132,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
}

/*
Expand Down