17 int64_t collapse_type)
19 , m_coordinate_handle(coordinate)
20 , m_energy_handle(energy)
21 , m_collapse_type(collapse_type)
31 if (
mesh().top_simplex_type() ==
PT) {
36 double old_energy_max = std::numeric_limits<double>::lowest();
37 double new_energy_max = std::numeric_limits<double>::lowest();
48 const auto& v0_incident_tets =
50 const auto& v1_incident_tets =
54 for (
const auto& t : v1_incident_tets) {
56 assert(lv.size() == 4);
60 std::max(old_energy_max, amips_accessor.const_scalar_attribute(t.tuple()));
63 bool incident_both =
false;
64 for (
int i = 0; i < 4; ++i) {
73 if (incident_both)
continue;
76 std::array<Eigen::Vector<double, 3>, 4> lv_pos = {
77 {position_accessor.const_vector_attribute(lv[0]),
78 position_accessor.const_vector_attribute(lv[1]),
79 position_accessor.const_vector_attribute(lv[2]),
80 position_accessor.const_vector_attribute(lv[3])}};
82 for (
int i = 0; i < 4; ++i) {
88 lv_pos[i] = position_accessor.const_vector_attribute(v0);
113 new_energy_max = std::max(new_energy_max, new_energy);
117 for (
const auto& t : v0_incident_tets) {
121 bool incident_both =
false;
122 for (
int i = 0; i < 4; ++i) {
127 incident_both =
true;
131 if (incident_both)
continue;
134 const double energy = amips_accessor.const_scalar_attribute(t.tuple());
135 old_energy_max = std::max(old_energy_max, energy);
138 new_energy_max = std::max(new_energy_max, energy);
151 const auto& v0_incident_tets =
153 const auto& v1_incident_tets =
157 for (
const auto& t : v0_incident_tets) {
159 assert(lv.size() == 4);
163 std::max(old_energy_max, amips_accessor.const_scalar_attribute(t.tuple()));
167 bool incident_both =
false;
168 for (
int i = 0; i < 4; ++i) {
173 incident_both =
true;
177 if (incident_both)
continue;
180 std::array<Eigen::Vector<double, 3>, 4> lv_pos = {
181 {position_accessor.const_vector_attribute(lv[0]),
182 position_accessor.const_vector_attribute(lv[1]),
183 position_accessor.const_vector_attribute(lv[2]),
184 position_accessor.const_vector_attribute(lv[3])}};
186 for (
int i = 0; i < 4; ++i) {
192 lv_pos[i] = position_accessor.const_vector_attribute(v1);
216 new_energy_max = std::max(new_energy_max, new_energy);
220 for (
const auto& t : v1_incident_tets) {
224 bool incident_both =
false;
225 for (
int i = 0; i < 4; ++i) {
230 incident_both =
true;
234 if (incident_both)
continue;
237 const double energy = amips_accessor.const_scalar_attribute(t.tuple());
238 old_energy_max = std::max(old_energy_max, energy);
241 new_energy_max = std::max(new_energy_max, energy);
248 throw std::runtime_error(
"not implemented");
251 default:
throw std::runtime_error(
"Invalid collapse type");
255 return new_energy_max <= old_energy_max;
257 }
else if (
mesh().top_simplex_type() ==
PF) {
virtual std::vector< Tuple > orient_vertices(const Tuple &t) const =0
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
CollapseEnergyBeforeInvariantDouble(const Mesh &m, const attribute::TypedAttributeHandle< double > &coordinate, const attribute::TypedAttributeHandle< double > &energy, int64_t collapse_type=0)
const attribute::TypedAttributeHandle< double > m_energy_handle
const attribute::TypedAttributeHandle< double > m_coordinate_handle
const int64_t m_collapse_type
bool before(const simplex::Simplex &s) const override
const Mesh & mesh() const
const Tuple & tuple() const
static Simplex vertex(const Mesh &m, const Tuple &t)
static bool equal(const Mesh &m, const Simplex &s0, const Simplex &s1)
constexpr wmtk::PrimitiveType PT
constexpr wmtk::PrimitiveType PF
double Tet_AMIPS_energy(const std::array< double, 12 > &T)
void top_dimension_cofaces(const Simplex &simplex, SimplexCollection &simplex_collection, const bool sort_and_clean)
Get all top dimension cofaces of the given simplex.
int wmtk_orient3d(const Eigen::Ref< const Eigen::Vector3< Rational >> &p0, const Eigen::Ref< const Eigen::Vector3< Rational >> &p1, const Eigen::Ref< const Eigen::Vector3< Rational >> &p2, const Eigen::Ref< const Eigen::Vector3< Rational >> &p3)
constexpr PrimitiveType PV
constexpr PrimitiveType PE