|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "feature/core/common.h" |
| 4 | + |
| 5 | +namespace Penner { |
| 6 | +namespace Feature { |
| 7 | + |
| 8 | +/** |
| 9 | + * @brief Representation of a boundary edge path. If the boundary edge is unflipped and lies along |
| 10 | + * the symmetry line, then this is just a single halfedge in the primal mesh. If the edge is |
| 11 | + * flipped, then this is a path of halfedges in the mesh copy (type 2) homotopic to the symmetry |
| 12 | + * line segment between the two vertices on the boundary. |
| 13 | + * |
| 14 | + */ |
| 15 | +class BoundaryPath |
| 16 | +{ |
| 17 | +public: |
| 18 | + /** |
| 19 | + * @brief Construct a new Boundary Path object from the given boundary vertex |
| 20 | + * to the next ccw vertex on the boundary. |
| 21 | + * |
| 22 | + * @param m: underlying mesh |
| 23 | + * @param vertex_index: starting vertex index (must be on the boundary) |
| 24 | + */ |
| 25 | + BoundaryPath(const Mesh<Scalar>& m, int vertex_index); |
| 26 | + |
| 27 | + /** |
| 28 | + * @brief Compute the number of edges in the boundary path |
| 29 | + * |
| 30 | + * @return number of edges |
| 31 | + */ |
| 32 | + int size() const { return m_halfedge_path.size(); } |
| 33 | + |
| 34 | + /** |
| 35 | + * @brief Compute the length of the boundary path in the given mesh |
| 36 | + * |
| 37 | + * @param m: underlying mesh |
| 38 | + * @return length of the current path in the mesh |
| 39 | + */ |
| 40 | + Scalar compute_length(const Mesh<Scalar>& m) const; |
| 41 | + |
| 42 | + /** |
| 43 | + * @brief Compute the (doubled) log length of the boundary path in the given mesh |
| 44 | + * |
| 45 | + * @param m: underlying mesh |
| 46 | + * @return log length of the current path in the mesh |
| 47 | + */ |
| 48 | + Scalar compute_log_length(const Mesh<Scalar>& m) const; |
| 49 | + |
| 50 | + /** |
| 51 | + * @brief Compute the Jacobian of the length of the boundary path in the given mesh with |
| 52 | + * respect to the halfedge lengths |
| 53 | + * |
| 54 | + * The Jacobian is represented as a sparse vector with index, value pairs. |
| 55 | + * |
| 56 | + * @param m: underlying mesh |
| 57 | + * @return jacobian of length |
| 58 | + */ |
| 59 | + std::vector<std::pair<int, Scalar>> compute_length_jacobian(const Mesh<Scalar>& m) const; |
| 60 | + |
| 61 | + /** |
| 62 | + * @brief Compute the Jacobian of the log length of the boundary path in the given mesh with |
| 63 | + * respect to the halfedge lengths |
| 64 | + * |
| 65 | + * The Jacobian is represented as a sparse vector with index, value pairs. |
| 66 | + * |
| 67 | + * @param m: underlying mesh |
| 68 | + * @return jacobian of log length |
| 69 | + */ |
| 70 | + std::vector<std::pair<int, Scalar>> compute_log_length_jacobian(const Mesh<Scalar>& m) const; |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Check if the boundary path is valid |
| 74 | + * |
| 75 | + * @param m: underlying mesh |
| 76 | + * @return true if the path is valid |
| 77 | + * @return false otherwise |
| 78 | + */ |
| 79 | + bool is_valid_boundary_path(const Mesh<Scalar>& m) const; |
| 80 | + |
| 81 | + /** |
| 82 | + * @brief Get the start vertex of the path |
| 83 | + * |
| 84 | + * @return start vertex index |
| 85 | + */ |
| 86 | + int get_start_vertex() const { return m_start_vertex; } |
| 87 | + |
| 88 | + /** |
| 89 | + * @brief Get the ending vertex of the path, which is the next original boundary vertex |
| 90 | + * counterclockwise on the symmetry line. |
| 91 | + * |
| 92 | + * @return end vertex index |
| 93 | + */ |
| 94 | + int get_end_vertex() const { return m_end_vertex; } |
| 95 | + |
| 96 | + /** |
| 97 | + * @brief Get the representative path of halfedges from the start to end vertex; |
| 98 | + * |
| 99 | + * This is either a single primal halfedge or a path of doubled halfedges bounding |
| 100 | + * the facets crossing the symmetry line between the vertices. |
| 101 | + * |
| 102 | + * @return path from the start to end vertex |
| 103 | + */ |
| 104 | + const std::vector<int>& get_halfedge_path() const { return m_halfedge_path; } |
| 105 | + |
| 106 | + /** |
| 107 | + * @brief Get transverse halfedges crossing the line of symmetry. |
| 108 | + * |
| 109 | + * One halfedge per transverse edge is returned. |
| 110 | + * |
| 111 | + * @return transverse halfedges. |
| 112 | + */ |
| 113 | + const std::vector<int>& get_transverse_edges() const { return m_transverse_edges; } |
| 114 | + |
| 115 | +private: |
| 116 | + int m_start_vertex; |
| 117 | + int m_end_vertex; |
| 118 | + |
| 119 | + Scalar compute_tri_length(Scalar side_length, Scalar base_length) const; |
| 120 | + Scalar compute_quad_length( |
| 121 | + Scalar side_length, |
| 122 | + Scalar first_base_length, |
| 123 | + Scalar second_base_length) const; |
| 124 | + Scalar compute_tri_side_derivative(Scalar side_length, Scalar base_length) const; |
| 125 | + Scalar compute_tri_base_derivative(Scalar side_length, Scalar base_length) const; |
| 126 | + Scalar compute_quad_side_derivative( |
| 127 | + Scalar side_length, |
| 128 | + Scalar first_base_length, |
| 129 | + Scalar second_base_length) const; |
| 130 | + Scalar compute_quad_base_derivative( |
| 131 | + Scalar side_length, |
| 132 | + Scalar first_base_length, |
| 133 | + Scalar second_base_length) const; |
| 134 | + |
| 135 | + // Paths between boundary vertices contained in the primal mesh |
| 136 | + std::vector<int> m_halfedge_path; |
| 137 | + |
| 138 | + // Transverse edges crossing the symmetry line |
| 139 | + std::vector<int> m_transverse_edges; |
| 140 | +}; |
| 141 | + |
| 142 | +/** |
| 143 | + * @brief Build all boundary paths for a mesh and a map to the corresponding halfedges. |
| 144 | + * |
| 145 | + * @param m: underlying mesh |
| 146 | + * @return list of boundary paths |
| 147 | + * @return map from boundary path indices to halfedge indices |
| 148 | + */ |
| 149 | +std::tuple<std::vector<BoundaryPath>, MatrixX> build_boundary_paths(const Mesh<Scalar>& m); |
| 150 | + |
| 151 | +} // namespace Feature |
| 152 | +} // namespace Penner |
0 commit comments