from numpy import linalg as LA
import ddg.datastructures.halfedge.get as get
from ddg.optimize.he.functional import HalfEdgeFunctional
[docs]class DirichletEnergy(HalfEdgeFunctional):
"""
Computes the combinatorial Dirchlet energy of a half-edge surface.
"""
def __init__(self, surface, attr_name, attr_dimension=None, boundary_cells=set()):
super().__init__(
surface,
attr_name,
"verts",
attr_dimension=attr_dimension,
boundary_cells=boundary_cells,
)
[docs] def evaluate(self, x):
E = 0
half_edges = get.single_edges(self.surface)
for e in half_edges:
i = e.tail
j = e.head
x_i = (
x[i.interior_cell_index]
if i.interior_cell_index is not None
else getattr(i, self.attr_name)
)
x_j = (
x[j.interior_cell_index]
if j.interior_cell_index is not None
else getattr(j, self.attr_name)
)
E += LA.norm(x_i - x_j) ** 2
return E