Geometry: Fix some minor issues.

mesh
Pierre-Antoine Rouby 2023-04-17 10:56:29 +02:00
parent 5683adef2e
commit d22ab3bbd7
6 changed files with 35 additions and 139 deletions

View File

@ -6,6 +6,7 @@ from typing import List
from Model.Geometry.Profile import Profile from Model.Geometry.Profile import Profile
from Model.Geometry.PointXYZ import PointXYZ from Model.Geometry.PointXYZ import PointXYZ
from Model.Geometry.Vector_1d import Vector1d
class ProfileXYZ(Profile): class ProfileXYZ(Profile):
def __init__(self, num: int = 0, def __init__(self, num: int = 0,
@ -61,22 +62,22 @@ class ProfileXYZ(Profile):
return [point.name for point in self._points] return [point.name for point in self._points]
def x_max(self): def x_max(self):
return max(self.filter_isnan(self.x)) return max(self.filter_isnan(self.x()))
def x_min(self): def x_min(self):
return min(self.filter_isnan(self.x)) return min(self.filter_isnan(self.x()))
def y_max(self): def y_max(self):
return max(self.filter_isnan(self.y)) return max(self.filter_isnan(self.y()))
def y_min(self): def y_min(self):
return min(self.filter_isnan(self.y)) return min(self.filter_isnan(self.y()))
def z_max(self): def z_max(self):
return max(self.filter_isnan(self.z)) return max(self.filter_isnan(self.z()))
def z_min(self): def z_min(self):
return min(self.filter_isnan(self.z)) return min(self.filter_isnan(self.z()))
def import_points(self, list_points: list): def import_points(self, list_points: list):
"""Import a list of points to profile """Import a list of points to profile
@ -195,7 +196,7 @@ class ProfileXYZ(Profile):
first_point_not_nan = self._first_point_not_nan() first_point_not_nan = self._first_point_not_nan()
last_point_not_nan = self._last_point_not_nan() last_point_not_nan = self._last_point_not_nan()
for index, point in enumerate(self.points): for index, point in enumerate(self._points):
if point.point_is_named(): if point.point_is_named():
index_first_named_point = index index_first_named_point = index
first_named_point = point first_named_point = point
@ -209,8 +210,8 @@ class ProfileXYZ(Profile):
station = [] station = []
constant = 0.0 constant = 0.0
if ((first_named_point is not None) and if (first_named_point is not None and
(last_named_point is not None)): last_named_point is not None):
if (first_named_point != last_named_point and if (first_named_point != last_named_point and
first_named_point.x != last_named_point.x): first_named_point.x != last_named_point.x):
vector = Vector1d(first_named_point, last_named_point) vector = Vector1d(first_named_point, last_named_point)
@ -227,9 +228,9 @@ class ProfileXYZ(Profile):
normalized_direction_vec[1] * yi) normalized_direction_vec[1] * yi)
station.append(station_i) station.append(station_i)
station = np.array(station) ret = np.array(station)
constant = station[index_first_named_point] constant = ret[index_first_named_point]
elif first_named_point is None: elif first_named_point is None:
vector = Vector1d(first_point_not_nan, vector = Vector1d(first_point_not_nan,
last_point_not_nan) last_point_not_nan)
@ -242,23 +243,23 @@ class ProfileXYZ(Profile):
normalized_direction_vec[1] * yi) normalized_direction_vec[1] * yi)
station.append(station_i) station.append(station_i)
station = np.array(station) ret = np.array(station)
index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0] index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0]
constant = station[index_profile_z_min] constant = ret[index_profile_z_min]
return (station - constant) return (ret - constant)
else: else:
return np.array(np.nan) return np.array(np.nan)
def _first_point_not_nan(self): def _first_point_not_nan(self):
first_point = self._points[0] first_point = self._points[0]
for point in self.points: for point in self._points:
if not point.is_nan(): if not point.is_nan():
first_point = point first_point = point
break break
return first_point_not_nan return first_point
def _last_point_not_nan(self): def _last_point_not_nan(self):
last_point = self._points[-1] last_point = self._points[-1]

View File

@ -145,7 +145,7 @@ class Reach:
Returns: Returns:
List of z min for each profile List of z min for each profile
""" """
return [profile.z_min() for profile in self._data.profiles] return [profile.z_min() for profile in self.profiles]
def get_z_max(self): def get_z_max(self):
"""List of z max for each profile """List of z max for each profile
@ -153,7 +153,7 @@ class Reach:
Returns: Returns:
List of z max for each profile List of z max for each profile
""" """
return [profile.z_max() for profile in self._data.profiles] return [profile.z_max() for profile in self.profiles]
def get_kp(self): def get_kp(self):
"""List of profiles kp """List of profiles kp
@ -161,11 +161,10 @@ class Reach:
Returns: Returns:
List of profiles kp List of profiles kp
""" """
return [profile.kp for profile in self._data.profiles] return [profile.kp for profile in self.profiles]
##############
# GUIDELINES # # Guidelines
##############
def _compute_guidelines_cache(self, guide_set, named_points): def _compute_guidelines_cache(self, guide_set, named_points):
# Reset guide lines cache # Reset guide lines cache
@ -247,6 +246,7 @@ class Reach:
def get_guidelines_z(self): def get_guidelines_z(self):
return self._map_guidelines_points(lambda p: p.z) return self._map_guidelines_points(lambda p: p.z)
# Sort # Sort
def sort_ascending(self): def sort_ascending(self):
@ -265,6 +265,9 @@ class Reach:
""" """
self._sort(is_reversed=True) self._sort(is_reversed=True)
# Copy/Paste
def copy(self, index_list: List[int]): def copy(self, index_list: List[int]):
self.__list_copied_profiles.clear() self.__list_copied_profiles.clear()
index_list = list(set(index_list)) # delete duplicate index index_list = list(set(index_list)) # delete duplicate index
@ -280,6 +283,9 @@ class Reach:
for profile in self.__list_copied_profiles: for profile in self.__list_copied_profiles:
self._profiles.append(profile) self._profiles.append(profile)
# Import/Export
def import_geometry(self, file_path_name: str): def import_geometry(self, file_path_name: str):
"""Import a geometry from file (.ST or .st) """Import a geometry from file (.ST or .st)

View File

@ -3,7 +3,6 @@
import numpy as np import numpy as np
from Model.Geometry.PointXYZ import PointXYZ from Model.Geometry.PointXYZ import PointXYZ
class Vector1d: class Vector1d:
def __init__(self, a: PointXYZ, b: PointXYZ): def __init__(self, a: PointXYZ, b: PointXYZ):
self.A = a self.A = a

View File

@ -1,109 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import copy
import numpy as np
import pandas as pd
from time import time
from Model.Geometry import PointXYZ
from Model.Geometry.ProfileXYZ import ProfileXYZ
from Model.Geometry.vector_1d import Vector1d
def update_station(list_header, list_point_xyz):
profile = ProfileXYZ(list_header, list_point_xyz)
if profile.nb_points >= 3:
return get_station(profile)
else:
pass
def get_station(profile: ProfileXYZ) -> np.ndarray:
"""Projection of the points of the profile on a plane.
Args:
profile: The profile
Returns:
Projection of the points of the profile on a plane.
"""
if profile.nb_points >= 3:
first_named_point = None
index_first_named_point = None
last_named_point = None
for index, point in enumerate(profile.points):
if point.point_is_named():
index_first_named_point = index
first_named_point = point
break
for point in profile.points[::-1]:
if point.point_is_named():
last_named_point = point
break
station = []
constant = 0.0
if ((first_named_point is not None) and
(last_named_point is not None)):
if (first_named_point != last_named_point and
first_named_point.x != last_named_point.x):
vector = Vector1d(first_named_point, last_named_point)
normalized_direction_vec = vector.normalized_direction_vector()
else:
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
for point in profile.points:
xi = point.x - first_named_point.x
yi = point.y - first_named_point.y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
station = np.array(station)
constant = station[index_first_named_point]
elif first_named_point is None:
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
for point in profile.points:
xi = point.x - _first_point_not_nan(profile).x
yi = point.y - _first_point_not_nan(profile).y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
station = np.array(station)
index_profile_z_min = np.where(np.array(profile.z) == profile.z_min)[0][0]
constant = station[index_profile_z_min]
return (station - constant)
else:
return np.array(np.nan)
def _first_point_not_nan(profile: ProfileXYZ):
first_point_not_nan = profile.points[0]
for point in profile.points:
if not point.is_nan():
first_point_not_nan = point
break
return first_point_not_nan
def _last_point_not_nan(profile: ProfileXYZ):
last_point = profile.points[-1]
for point in profile.points[::-1]:
if not point.is_nan():
last_point = point
break
return last_point

View File

@ -389,8 +389,8 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.tableView.model().blockSignals(True) self.tableView.model().blockSignals(True)
selected_profile = 0 selected_profile = 0
station = self._reach.get_station(selected_profile) # L'abscisse en travers station = self._reach.profile(selected_profile).get_station()
station_plus_1 = self._reach.get_station(selected_profile + 1) station_plus_1 = self._reach.profile(selected_profile + 1).get_station()
elevation = self._reach.profile(selected_profile).z elevation = self._reach.profile(selected_profile).z
elevation_i_plus_1 = self._reach.profile(selected_profile + 1).z elevation_i_plus_1 = self._reach.profile(selected_profile + 1).z
ld = self._reach.profile(selected_profile).name ld = self._reach.profile(selected_profile).name
@ -495,8 +495,8 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.annotation_3[:] = [] self.annotation_3[:] = []
x = self.get_station(ind) x = self.profile(ind).get_station()
y = self.get_elevation(ind) y = self._reach.profile(ind).z()
ld = self._reach.profile(ind).name ld = self._reach.profile(ind).name
get_complete_list_ld = self._reach.get_complete_list_ld() get_complete_list_ld = self._reach.get_complete_list_ld()
get_incomplete_list_ld = self._reach.get_incomplete_list_ld() get_incomplete_list_ld = self._reach.get_incomplete_list_ld()
@ -552,10 +552,10 @@ class GeometryWindow(QMainWindow, WindowToolKit):
return colors return colors
def get_station(self, ind: int): def get_station(self, ind: int):
return self._reach.get_station(ind) return self._reach.profile(ind).get_station()
def get_elevation(self, ind: int): def get_elevation(self, ind: int):
return self._reach.profile(ind).z return self._reach.profile(ind).z()
def update_graphic_3(self, ind: int): def update_graphic_3(self, ind: int):
self.tableView.model().blockSignals(True) self.tableView.model().blockSignals(True)

View File

@ -7,7 +7,6 @@ from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import QModelIndex, Qt, QAbstractTableModel, QVariant, QCoreApplication from PyQt5.QtCore import QModelIndex, Qt, QAbstractTableModel, QVariant, QCoreApplication
from Model.Geometry.ProfileXYZ import ProfileXYZ from Model.Geometry.ProfileXYZ import ProfileXYZ
from Model.Geometry.projection_pointXYZ import *
_translate = QCoreApplication.translate _translate = QCoreApplication.translate