Geometry: Reverte purge algorithme to previous version (modified).

scenarios
Pierre-Antoine 2025-09-11 10:01:18 +02:00
parent 4ba232a7e4
commit 37ea9e9083
2 changed files with 32 additions and 34 deletions

View File

@ -373,8 +373,8 @@ class PointXYZ(Point):
c = PointXYZ.distance(p3, p1) c = PointXYZ.distance(p3, p1)
s = float((a + b + c) / 2) s = float((a + b + c) / 2)
res = ( res = abs(
s * abs(s - a) * abs(s - b) * abs(s - c) s * (s - a) * (s - b) * (s - c)
) ** 0.5 ) ** 0.5
return res return res

View File

@ -1008,49 +1008,47 @@ class ProfileXYZ(Profile, SQLSubModel):
""" """
Remove points to keep at most np_purge points. Remove points to keep at most np_purge points.
""" """
if (self.nb_points <= np_purge): if self.nb_points <= np_purge:
return return
q_area = queue.PriorityQueue() nb_named = 0 # we consider the first and last point as named
deleted = [] area = []
for ind, point in enumerate(self.points): for i, p in enumerate(self.points):
if (ind == 0) or (ind == self.nb_points - 1): if p.is_named() or i == 0 or i == self.nb_points - 1:
continue area.append((9999999.999, p))
nb_named += 1
if not point.is_named(): else:
q_area.put(( area.append((
PointXYZ.areatriangle3d(
self.point(ind - 1),
point,
self.point(ind + 1)
),
ind, point
))
while self.nb_points > np_purge and not q_area.empty():
area, ind, point = q_area.get()
self.delete_points([point])
deleted.append(point)
# Recompute point neighbourhood
for i in [ind-1, ind]:
if (i <= 0) or (i >= self.nb_points - 1):
continue
point = self.point(i)
if not point.is_named():
q_area.put((
PointXYZ.areatriangle3d( PointXYZ.areatriangle3d(
self.point(i-1), self.point(i-1),
point, p,
self.point(i+1) self.point(i+1)
), i, point ),
p
)) ))
self.modified() while self.nb_points > max(np_purge, nb_named):
return deleted ind, (min_area, p) = min(
enumerate(area),
key=lambda t: t[1][0]
)
p.set_as_deleted()
area.pop(ind)
for i in [ind-1, ind]:
p = self.point(i)
if p.is_named() or i == 0 or i == self.nb_points - 1:
area[i] = (9999999.999, p)
else:
area[i] = (
PointXYZ.areatriangle3d(
self.point(i-1), p, self.point(i+1)
),
p
)
def shift(self, x, y, z): def shift(self, x, y, z):
for p in self._points: for p in self._points: