7#include <igl/barycentric_coordinates.h>
9#include <geogram/mesh/mesh_io.h>
14 using namespace utils;
27 const Eigen::Vector3d e0 = (v2 - v1).transpose();
28 const Eigen::Vector3d e1 = (v3 - v1).transpose();
30 return e0.cross(e1).norm() / 2;
36 p1.resize(p0.rows(), p0.cols());
38 for (std::size_t e = 0; e <
n_edges(); ++e)
43 p0.row(e) =
point(v0);
44 p1.row(e) =
point(v1);
48 void Mesh3D::get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1,
const std::vector<bool> &valid_elements)
const
51 for (
size_t i = 0; i < valid_elements.size(); ++i)
53 if (valid_elements[i])
64 for (
size_t i = 0; i < valid_elements.size(); ++i)
66 if (!valid_elements[i])
87 const double t = i / (n_new_nodes + 1.0);
89 return std::make_pair((1 - t) * v1 + t * v2, -1);
94 return std::make_pair(n.nodes.row(i - 1), n.nodes_ids[i - 1]);
96 return std::make_pair(n.nodes.row(n.nodes.rows() - i), n.nodes_ids[n.nodes_ids.size() - i]);
101 const int tmp = n_new_nodes == 2 ? 3 : n_new_nodes;
110 const double b2 = i / (n_new_nodes + 2.0);
111 const double b3 = j / (n_new_nodes + 2.0);
112 const double b1 = 1 - b3 - b2;
116 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
119 const int ii = i - 1;
120 const int jj = j - 1;
124 int lindex = jj * n_new_nodes + ii;
128 static const std::array<int, 3> remapping = {{0, 2, 1}};
133 lindex = remapping[lindex];
141 else if (n.v2 == index.
vertex)
146 lindex = remapping[lindex];
154 lindex = (lindex + 1) % 3;
156 else if (n.v3 == index.
vertex)
161 lindex = remapping[lindex];
169 lindex = (lindex + 2) % 3;
177 return std::make_pair(n.nodes.row(lindex), n.nodes_ids[lindex]);
189 const double b1 = i / (n_new_nodes + 1.0);
190 const double b2 = j / (n_new_nodes + 1.0);
192 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
203 assert(n_new_nodes == 1);
205 assert(n.nodes.rows() == 1);
206 return std::make_pair(n.nodes, n.nodes_ids[0]);
209 if (n_new_nodes == 1)
214 if (n_new_nodes == 1)
223 const double w1 = double(i) / (n_new_nodes + 3);
224 const double w2 = double(j) / (n_new_nodes + 3);
225 const double w3 = double(k) / (n_new_nodes + 3);
226 const double w4 = 1 - w1 - w2 - w3;
233 return std::make_pair(w4 * v1 + w1 * v2 + w2 * v3 + w3 * v4, -1);
252 const double b1 = i / (n_new_nodes + 1.0);
253 const double b2 = j / (n_new_nodes + 1.0);
255 const double b3 = k / (n_new_nodes + 1.0);
257 RowVectorNd blin1 = v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2;
258 RowVectorNd blin2 = v5 * (1 - b1) * (1 - b2) + v6 * b1 * (1 - b2) + v7 * b1 * b2 + v8 * (1 - b1) * b2;
260 return std::make_pair((1 - b3) * blin1 + b3 * blin2, -1);
324 assert(
is_cube(element_index));
326 std::array<int, 8> v;
330 for (
int i = 0; i < 8; ++i)
331 v[i] = to_vertex[i](idx).vertex;
349 std::array<int, 4> v;
351 for (
int lv = 0; lv < 3; ++lv)
394 auto &box = boxes[i];
395 box[0].setConstant(std::numeric_limits<double>::max());
396 box[1].setConstant(std::numeric_limits<double>::min());
401 for (
int d = 0; d < 3; ++d)
403 box[0][d] = std::min(box[0][d],
point(v_id)[d]);
404 box[1][d] = std::max(box[1][d],
point(v_id)[d]);
416 const auto A =
point(indices[0]);
417 const auto B =
point(indices[1]);
418 const auto C =
point(indices[2]);
419 const auto D =
point(indices[3]);
421 igl::barycentric_coordinates(p, A, B, C, D, coord);
430 const auto A =
point(indices[0]);
431 const auto B =
point(indices[1]);
432 const auto C =
point(indices[2]);
433 const auto D =
point(indices[3]);
435 Eigen::MatrixXd coords(4, 4);
436 coords << A, 1, B, 1, C, 1, D, 1;
437 coords.transposeInPlace();
439 jacobian = coords * reference_map;
441 assert(jacobian.determinant() > 0);
void to_vertex_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 8 > &to_vertex) const
virtual Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const =0
double tri_area(const int gid) const override
area of a tri face of a tet mesh
void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
virtual int n_cell_edges(const int c_id) const =0
virtual int cell_edge(const int c_id, const int le_id) const =0
void elements_boxes(std::vector< std::array< Eigen::Vector3d, 2 > > &boxes) const override
constructs a box around every element (3d cell, 2d face)
std::array< int, 8 > get_ordered_vertices_from_hex(const int element_index) const
std::pair< RowVectorNd, int > cell_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j, const int k) const
void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override
Get all the edges.
virtual Navigation3D::Index switch_edge(Navigation3D::Index idx) const =0
void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override
constructs barycentric coodiantes for a point p.
std::pair< RowVectorNd, int > face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const
std::pair< RowVectorNd, int > edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const
virtual std::array< int, 4 > get_ordered_vertices_from_tet(const int element_index) const
void to_edge_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 12 > &to_edge) const
virtual Navigation3D::Index next_around_face(Navigation3D::Index idx) const =0
virtual Navigation3D::Index switch_face(Navigation3D::Index idx) const =0
void to_face_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 6 > &to_face) const
virtual Navigation3D::Index switch_vertex(Navigation3D::Index idx) const =0
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
virtual int n_vertices() const =0
number of vertices
Eigen::MatrixXi orders_
list of geometry orders, one per cell
bool is_cube(const int el_id) const
checks if element is cube compatible
virtual RowVectorNd point(const int global_index) const =0
point coordinates
bool is_simplex(const int el_id) const
checks if element is simples compatible
std::vector< CellNodes > cell_nodes_
high-order nodes associates to cells
virtual int edge_vertex(const int e_id, const int lv_id) const =0
id of the edge vertex
std::vector< FaceNodes > face_nodes_
high-order nodes associates to faces
std::vector< EdgeNodes > edge_nodes_
high-order nodes associates to edges
virtual RowVectorNd cell_barycenter(const int c) const =0
cell barycenter
virtual int n_edges() const =0
number of edges
virtual int cell_vertex(const int f_id, const int lv_id) const =0
id of the vertex of a cell
virtual int n_face_vertices(const int f_id) const =0
number of vertices of a face
virtual int n_cell_vertices(const int c_id) const =0
number of vertices of a cell
virtual int face_vertex(const int f_id, const int lv_id) const =0
id of the face vertex
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd