feat: flattening

This commit is contained in:
gdamms 2022-09-29 13:47:45 +02:00
parent a8a6733d7e
commit 29fd8e4549

View file

@ -1,3 +1,4 @@
from sympy import RisingFactorial
from obja import obja
import numpy as np
import itertools
@ -97,7 +98,7 @@ class MAPS(obja.Model):
return area_sum, curvature_sum, len(one_ring_vertices)
def compute_priority(self, lamb: float = 0.5, max_length: int = 12) -> list[float]:
""" Compute selection priority of vertices (0 -> hight priority 1 -> low priority)
""" Compute selection priority of vertices (0 -> hight priority ; 1 -> low priority)
Args:
lamb (float, optional): convex combination factor. Defaults to 0.5.
@ -163,6 +164,51 @@ class MAPS(obja.Model):
return selected_vertices
def project_polar(self, index: int) -> list[np.ndarray]:
""" Flatten the 1-ring to retriangulate
Args:
index (int): main vertex of the 1-ring
Returns:
list[np.ndarray]: list the cartesian coordinates of the flattened 1-ring projected in the plane
"""
ring = self.one_ring(index)
radius, angles = [], []
teta = 0.0 # cumulated angles
for index1, index2 in sliding_window(ring, 2):
r = np.linalg.norm(self.vertices[index], self.vertices[index1])
teta += self.compute_angle(index1, index, index2) # add new angle
radius.append(r)
angles.append(teta)
angles = [2 * np.pi * a / teta for a in angles] # normalize angles
coordinates = [np.array([r * np.cos(a), r * np.sin(a)])
for r, a in zip(radius, angles)] # parse polar to cartesian
return coordinates
def compute_angle(self, i: int, j: int, k: int) -> float:
""" Calculate the angle defined by three points
Args:
i (int): previous index
j (int): central index
k (int): next index
Returns:
float: angle defined by the three points
"""
a = self.vertices[i]
b = self.vertices[j]
c = self.vertices[k]
u = a - b
v = c - b
u /= np.linalg.norm(u)
v /= np.linalg.norm(v)
res = np.dot(u, v)
return np.arccos(res)
# def contract(self, output):
# """
# Decimates the model stupidly, and write the resulting obja in output.