Commit 51648919 authored by Theophile Terraz's avatar Theophile Terraz
Browse files

add purge

No related merge requests found
Pipeline #55237 passed with stages
in 3 minutes and 24 seconds
Showing with 41 additions and 0 deletions
+41 -0
......@@ -204,3 +204,11 @@ class PointXYZ(Point, SQLSubModel):
Euclidean distance between the two points
"""
return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z))
@staticmethod
def areatriangle3d(p1, p2, p3):
a = PointXYZ.distance(p1, p2)
b = PointXYZ.distance(p2, p3)
c = PointXYZ.distance(p3, p1)
s = (a + b + c) / 2
return (s*(s-a) * (s-b)*(s-c)) ** 0.5
......@@ -530,3 +530,36 @@ class ProfileXYZ(Profile, SQLSubModel):
pt_right = self.point(self.number_points - 1)
return pt_left, pt_right
def purge(self, np_purge):
"""
Remove points to keep at most np_purge points.
"""
if (self.nb_points <= np_purge): return
nb_named = 2 # we consider the first and last point as named
area = [0.0]
for i in range(1, self.nb_points-1):
if self.point(i).point_is_named():
area.append(9999999.999)
nb_named += 1
print(self.point(i).name.strip())
else:
area.append(PointXYZ.areatriangle3d(self.point(i-1),self.point(i),self.point(i+1)))
area.append(0.0)
print(area)
while (self.nb_points > max(np_purge, nb_named)):
to_rm = np.argmin(area[1:self.nb_points-1])+1
print('to rm = ', to_rm)
self.delete_i([to_rm])
area.pop(to_rm)
for i in [to_rm-1, to_rm]:
if (i == 0): continue
if (i == self.nb_points - 1): continue
if self.point(i).point_is_named():
area[i] = 9999999.999
else:
area[i] = PointXYZ.areatriangle3d(self.point(i-1),self.point(i),self.point(i+1))
#self._study.river.edges()[0].reach.profile(0).purge(5)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment