PolyFEM
Loading...
Searching...
No Matches
PolyhedronQuadrature.cpp
Go to the documentation of this file.
1
3#include "TetQuadrature.hpp"
4#include <vector>
5#include <cassert>
6#include <iostream>
8
9namespace polyfem
10{
12
13 void tertrahedralize_star_shaped_surface(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
14 const Eigen::RowVector3d &kernel, Eigen::MatrixXd &OV, Eigen::MatrixXi &OF, Eigen::MatrixXi &OT)
15 {
16 assert(V.cols() == 3);
17 OV.resize(V.rows() + 1, V.cols());
18 OV.topRows(V.rows()) = V;
19 OV.bottomRows(1) = kernel;
20 OF = F;
21 OT.resize(OF.rows(), 4);
22 OT.col(0).setConstant(V.rows());
23 OT.rightCols(3) = F;
24 }
25
26 namespace quadrature
27 {
28 namespace
29 {
30
31 template <class TriMat>
32 double transform_pts(const TriMat &tri, const Eigen::MatrixXd &pts, Eigen::MatrixXd &transformed)
33 {
34 Eigen::Matrix3d matrix;
35 matrix.row(0) = tri.row(1) - tri.row(0);
36 matrix.row(1) = tri.row(2) - tri.row(0);
37 matrix.row(2) = tri.row(3) - tri.row(0);
38
39 transformed = pts * matrix;
40
41 transformed.col(0).array() += tri(0, 0);
42 transformed.col(1).array() += tri(0, 1);
43 transformed.col(2).array() += tri(0, 2);
44
45 return matrix.determinant();
46 }
47
48 } // anonymous namespace
49
51
52 void PolyhedronQuadrature::get_quadrature(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
53 const Eigen::RowVector3d &kernel, const int order, Quadrature &quadr)
54 {
55 std::string flags = "Qpq2.0";
56 Eigen::VectorXi J;
57 Eigen::MatrixXd VV, OV, TV;
58 Eigen::MatrixXi OF, TF, tets;
59
60 Quadrature tet_quadr_pts;
61 TetQuadrature tet_quadr;
62 tet_quadr.get_quadrature(4, tet_quadr_pts);
63 // assert(tet_quadr_pts.weights.minCoeff() >= 0);
64
65 tertrahedralize_star_shaped_surface(V, F, kernel, TV, TF, tets);
66
67 const long offset = tet_quadr_pts.weights.rows();
68 quadr.points.resize(tets.rows() * offset, 3);
69 quadr.weights.resize(tets.rows() * offset, 1);
70
71 Eigen::MatrixXd transformed_points;
72
73 for (long i = 0; i < tets.rows(); ++i)
74 {
75 Eigen::Matrix<double, 4, 3> tetra;
76 const auto &indices = tets.row(i);
77 tetra.row(0) = TV.row(indices(0));
78 tetra.row(1) = TV.row(indices(1));
79 tetra.row(2) = TV.row(indices(2));
80 tetra.row(3) = TV.row(indices(3));
81
82 // viewer.data.add_edges(triangle.row(0), triangle.row(1), Eigen::Vector3d(1,0,0).transpose());
83 // viewer.data.add_edges(triangle.row(0), triangle.row(2), Eigen::Vector3d(1,0,0).transpose());
84 // viewer.data.add_edges(triangle.row(2), triangle.row(1), Eigen::Vector3d(1,0,0).transpose());
85
86 const double det = transform_pts(tetra, tet_quadr_pts.points, transformed_points);
87 assert(det > 0);
88
89 quadr.points.block(i * offset, 0, transformed_points.rows(), transformed_points.cols()) = transformed_points;
90 quadr.weights.block(i * offset, 0, tet_quadr_pts.weights.rows(), tet_quadr_pts.weights.cols()) = tet_quadr_pts.weights * det;
91 }
92
93 // assert(quadr.weights.minCoeff() >= 0);
94 }
95 } // namespace quadrature
96} // namespace polyfem
int V
Quadrature quadrature
double J
static void get_quadrature(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::RowVector3d &kernel, const int order, Quadrature &quadr)
Gets the quadrature points & weights for a polyhedron.
void get_quadrature(const int order, Quadrature &quad)
void tertrahedralize_star_shaped_surface(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::RowVector3d &kernel, Eigen::MatrixXd &OV, Eigen::MatrixXi &OF, Eigen::MatrixXi &OT)
Tetrahedralize a star-shaped mesh, with a given point in its kernel.