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

HW 05 Sajjad #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
38 changes: 38 additions & 0 deletions src/arap_precompute.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "arap_precompute.h"
#include <igl/min_quad_with_fixed.h>
#include <igl/cotmatrix.h>
#include <igl/cotmatrix_entries.h>
#include <iostream>

void arap_precompute(
const Eigen::MatrixXd & V,
Expand All @@ -8,4 +12,38 @@ void arap_precompute(
Eigen::SparseMatrix<double> & K)
{
// REPLACE WITH YOUR CODE
int num_vect = V.rows();;
std::cout << num_vect << std::endl;
typedef Eigen::Triplet<double> T;
Eigen::SparseMatrix<double> Aeq;
Eigen::SparseMatrix<double> L;
Eigen::MatrixXd C;
std::vector<T> tripletList;

igl::cotmatrix_entries(V, F, C);
igl::cotmatrix(V, F, L);
igl::min_quad_with_fixed_precompute(L, b, Aeq, false, data);
std::cout << C.rows() << std::endl;
std::cout << L.rows() << std::endl;
for (int i = 0; i < F.rows(); i++){
for (int j = 0; j < 3; j++){
int ka = (j + 1) % 3;
int kb = (j + 2) % 3;
int a = F(i,ka);
int b = F(i,kb);
std::cout << a << std::endl;
Eigen::RowVector3d e = C(i,j) * (V.row(a)-V.row(b));

for (int k = 0; k < 3; k++) {
tripletList.push_back(T(a, 3 * F(i,0) + k, e(k)));
tripletList.push_back(T(a, 3 * F(i,1) + k, e(k)));
tripletList.push_back(T(a, 3 * F(i,2) + k, e(k)));
tripletList.push_back(T(b, 3 * F(i,0) + k, e(k)));
tripletList.push_back(T(b, 3 * F(i,1) + k, e(k)));
tripletList.push_back(T(b, 3 * F(i,2) + k, e(k)));
}
}
}
K.resize(num_vect, 3 * num_vect);
K.setFromTriplets(tripletList.begin(), tripletList.end());
}
22 changes: 22 additions & 0 deletions src/arap_single_iteration.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "arap_single_iteration.h"
#include <igl/polar_svd3x3.h>
#include <igl/min_quad_with_fixed.h>
#include <iostream>

void arap_single_iteration(
const igl::min_quad_with_fixed_data<double> & data,
Expand All @@ -7,4 +10,23 @@ void arap_single_iteration(
Eigen::MatrixXd & U)
{
// REPLACE WITH YOUR CODE
int vetr_num = U.rows();
Eigen::MatrixXd C;
Eigen::MatrixXd R;
Eigen::Matrix3d C2;
Eigen::Matrix3d R2;
Eigen::MatrixXd B;
Eigen::MatrixXd Beq;

C = K.transpose() * U;
std::cout << C.rows() << std::endl;
for (int i = 0; i < vetr_num; i++) {
C2 = C.block(0, i*3, 3, 3);
igl::polar_svd3x3(C2, R2);

R.block(i*3, 0, 3, 3) = R2.transpose();
}
B = K * R;
std::cout << B << std::endl;
igl::min_quad_with_fixed_solve(data, B, bc, Beq, U);
}
25 changes: 23 additions & 2 deletions src/biharmonic_precompute.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "biharmonic_precompute.h"
#include <igl/min_quad_with_fixed.h>
#include <igl/massmatrix.h>
#include <igl/cotmatrix.h>
#include <iostream>


void biharmonic_precompute(
const Eigen::MatrixXd & V,
Expand All @@ -8,6 +12,23 @@ void biharmonic_precompute(
igl::min_quad_with_fixed_data<double> & data)
{
// REPLACE WITH YOUR CODE
data.n = V.rows();
}
int vetr_num = V.rows();
Eigen::SparseMatrix<double> A;
Eigen::SparseMatrix<double> L;
Eigen::SparseMatrix<double> M;
Eigen::SparseMatrix<double> Q;
Eigen::SparseMatrix<double> Aeq;

igl::cotmatrix(V, F, L);
igl::massmatrix(V, F, igl::MASSMATRIX_TYPE_DEFAULT, M);

Eigen::SparseMatrix<double> M2(vetr_num, vetr_num); ;
for (int i = 0; i < vetr_num; i++) {
M2.insert(i,i) = 1.0 / M.coeffRef(i,i);
}
std::cout << M2 << std::endl;
std::cout << "succes" << std::endl;
Q = L.transpose() * M2 * L;
igl::min_quad_with_fixed_precompute(Q, b, Aeq, false, data);

}
4 changes: 4 additions & 0 deletions src/biharmonic_solve.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "biharmonic_solve.h"
#include <igl/min_quad_with_fixed.h>
#include <iostream>

void biharmonic_solve(
const igl::min_quad_with_fixed_data<double> & data,
Expand All @@ -8,5 +9,8 @@ void biharmonic_solve(
{
// REPLACE WITH YOUR CODE
D = Eigen::MatrixXd::Zero(data.n,3);
Eigen::VectorXd B = Eigen::VectorXd::Zero(data.n);
Eigen::VectorXd Beq;
igl::min_quad_with_fixed_solve(data, B, bc, Beq, D);
}