Formatted filles

This commit is contained in:
Peter Yefi 2021-10-19 13:58:46 +00:00
parent ba72bd9043
commit 9c2b4ca7ef
3 changed files with 743 additions and 735 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,240 +14,240 @@ from helpers.configuration_helper import ConfigurationHelper
class Polyhedron: class Polyhedron:
""" """
Polyhedron class Polyhedron class
""" """
def __init__(self, polygons): def __init__(self, polygons):
self._polygons = polygons self._polygons = polygons
self._polyhedron = None self._polyhedron = None
self._triangulated_polyhedron = None self._triangulated_polyhedron = None
self._volume = None self._volume = None
self._faces = None self._faces = None
self._vertices = None self._vertices = None
self._trimesh = None self._trimesh = None
self._centroid = None self._centroid = None
self._max_z = None self._max_z = None
self._max_y = None self._max_y = None
self._max_x = None self._max_x = None
self._min_z = None self._min_z = None
self._min_y = None self._min_y = None
self._min_x = None self._min_x = None
def _position_of(self, point, face): def _position_of(self, point, face):
""" """
position of a specific point in the list of points that define a face position of a specific point in the list of points that define a face
:return: int :return: int
""" """
vertices = self.vertices vertices = self.vertices
for i in range(len(vertices)): for i in range(len(vertices)):
# ensure not duplicated vertex # ensure not duplicated vertex
power = 0 power = 0
vertex2 = vertices[i] vertex2 = vertices[i]
for dimension in range(0, 3): for dimension in range(0, 3):
power += math.pow(vertex2[dimension] - point[dimension], 2) power += math.pow(vertex2[dimension] - point[dimension], 2)
distance = math.sqrt(power) distance = math.sqrt(power)
if i not in face and distance == 0: if i not in face and distance == 0:
return i return i
return -1 return -1
@property @property
def vertices(self) -> np.ndarray: def vertices(self) -> np.ndarray:
""" """
Get polyhedron vertices Get polyhedron vertices
:return: np.ndarray(int) :return: np.ndarray(int)
""" """
if self._vertices is None: if self._vertices is None:
vertices, self._vertices = [], [] vertices, self._vertices = [], []
_ = [vertices.extend(s.coordinates) for s in self._polygons] _ = [vertices.extend(s.coordinates) for s in self._polygons]
for vertex_1 in vertices: for vertex_1 in vertices:
found = False found = False
for vertex_2 in self._vertices: for vertex_2 in self._vertices:
found = False found = False
power = 0 power = 0
for dimension in range(0, 3): for dimension in range(0, 3):
power += math.pow(vertex_2[dimension] - vertex_1[dimension], 2) power += math.pow(vertex_2[dimension] - vertex_1[dimension], 2)
distance = math.sqrt(power) distance = math.sqrt(power)
if distance == 0: if distance == 0:
found = True found = True
break break
if not found: if not found:
self._vertices.append(vertex_1) self._vertices.append(vertex_1)
self._vertices = np.asarray(self._vertices) self._vertices = np.asarray(self._vertices)
return self._vertices return self._vertices
@property @property
def faces(self) -> List[List[int]]: def faces(self) -> List[List[int]]:
""" """
Get polyhedron triangular faces Get polyhedron triangular faces
:return: [face] :return: [face]
""" """
if self._faces is None: if self._faces is None:
self._faces = [] self._faces = []
for polygon in self._polygons: for polygon in self._polygons:
face = [] face = []
points = polygon.coordinates points = polygon.coordinates
if len(points) != 3: if len(points) != 3:
sub_polygons = polygon.triangulate() sub_polygons = polygon.triangulate()
# todo: I modified this! To be checked @Guille # todo: I modified this! To be checked @Guille
if len(sub_polygons) >= 1: if len(sub_polygons) >= 1:
for sub_polygon in sub_polygons: for sub_polygon in sub_polygons:
face = [] face = []
points = sub_polygon.coordinates points = sub_polygon.coordinates
for point in points: for point in points:
face.append(self._position_of(point, face)) face.append(self._position_of(point, face))
self._faces.append(face) self._faces.append(face)
else: else:
for point in points: for point in points:
face.append(self._position_of(point, face)) face.append(self._position_of(point, face))
self._faces.append(face) self._faces.append(face)
return self._faces return self._faces
@property @property
def trimesh(self) -> Union[Trimesh, None]: def trimesh(self) -> Union[Trimesh, None]:
""" """
Get polyhedron trimesh Get polyhedron trimesh
:return: Trimesh :return: Trimesh
""" """
if self._trimesh is None: if self._trimesh is None:
for face in self.faces: for face in self.faces:
if len(face) != 3: if len(face) != 3:
sys.stderr.write('Not able to generate trimesh\n') sys.stderr.write('Not able to generate trimesh\n')
return None return None
self._trimesh = Trimesh(vertices=self.vertices, faces=self.faces) self._trimesh = Trimesh(vertices=self.vertices, faces=self.faces)
return self._trimesh return self._trimesh
@property @property
def volume(self): def volume(self):
""" """
Get polyhedron volume in cubic meters Get polyhedron volume in cubic meters
:return: float :return: float
""" """
if self._volume is None: if self._volume is None:
if self.trimesh is None: if self.trimesh is None:
self._volume = np.inf self._volume = np.inf
elif not self.trimesh.is_volume: elif not self.trimesh.is_volume:
self._volume = np.inf self._volume = np.inf
else: else:
self._volume = self.trimesh.volume self._volume = self.trimesh.volume
return self._volume return self._volume
@property @property
def max_z(self): def max_z(self):
""" """
Get polyhedron maximal z value in meters Get polyhedron maximal z value in meters
:return: float :return: float
""" """
if self._max_z is None: if self._max_z is None:
self._max_z = ConfigurationHelper().min_coordinate self._max_z = ConfigurationHelper().min_coordinate
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
self._max_z = max(self._max_z, point[2]) self._max_z = max(self._max_z, point[2])
return self._max_z return self._max_z
@property @property
def max_y(self): def max_y(self):
""" """
Get polyhedron maximal y value in meters Get polyhedron maximal y value in meters
:return: float :return: float
""" """
if self._max_y is None: if self._max_y is None:
self._max_y = ConfigurationHelper().min_coordinate self._max_y = ConfigurationHelper().min_coordinate
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
if self._max_y < point[1]: if self._max_y < point[1]:
self._max_y = point[1] self._max_y = point[1]
return self._max_y return self._max_y
@property @property
def max_x(self): def max_x(self):
""" """
Get polyhedron maximal x value in meters Get polyhedron maximal x value in meters
:return: float :return: float
""" """
if self._max_x is None: if self._max_x is None:
self._max_x = ConfigurationHelper().min_coordinate self._max_x = ConfigurationHelper().min_coordinate
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
self._max_x = max(self._max_x, point[0]) self._max_x = max(self._max_x, point[0])
return self._max_x return self._max_x
@property @property
def min_z(self): def min_z(self):
""" """
Get polyhedron minimal z value in meters Get polyhedron minimal z value in meters
:return: float :return: float
""" """
if self._min_z is None: if self._min_z is None:
self._min_z = self.max_z self._min_z = self.max_z
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
if self._min_z > point[2]: if self._min_z > point[2]:
self._min_z = point[2] self._min_z = point[2]
return self._min_z return self._min_z
@property @property
def min_y(self): def min_y(self):
""" """
Get polyhedron minimal y value in meters Get polyhedron minimal y value in meters
:return: float :return: float
""" """
if self._min_y is None: if self._min_y is None:
self._min_y = self.max_y self._min_y = self.max_y
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
if self._min_y > point[1]: if self._min_y > point[1]:
self._min_y = point[1] self._min_y = point[1]
return self._min_y return self._min_y
@property @property
def min_x(self): def min_x(self):
""" """
Get polyhedron minimal x value in meters Get polyhedron minimal x value in meters
:return: float :return: float
""" """
if self._min_x is None: if self._min_x is None:
self._min_x = self.max_x self._min_x = self.max_x
for polygon in self._polygons: for polygon in self._polygons:
for point in polygon.coordinates: for point in polygon.coordinates:
if self._min_x > point[0]: if self._min_x > point[0]:
self._min_x = point[0] self._min_x = point[0]
return self._min_x return self._min_x
@property @property
def centroid(self) -> Union[None, List[float]]: def centroid(self) -> Union[None, List[float]]:
""" """
Get polyhedron centroid Get polyhedron centroid
:return: [x,y,z] :return: [x,y,z]
""" """
if self._centroid is None: if self._centroid is None:
trimesh = self.trimesh trimesh = self.trimesh
if trimesh is None: if trimesh is None:
return None return None
self._centroid = self.trimesh.centroid self._centroid = self.trimesh.centroid
return self._centroid return self._centroid
def stl_export(self, full_path): def stl_export(self, full_path):
""" """
Export the polyhedron to stl given file Export the polyhedron to stl given file
:param full_path: str :param full_path: str
:return: None :return: None
""" """
self.trimesh.export(full_path, 'stl_ascii') self.trimesh.export(full_path, 'stl_ascii')
def obj_export(self, full_path): def obj_export(self, full_path):
""" """
Export the polyhedron to obj given file Export the polyhedron to obj given file
:param full_path: str :param full_path: str
:return: None :return: None
""" """
self.trimesh.export(full_path, 'obj') self.trimesh.export(full_path, 'obj')
def show(self): def show(self):
""" """
Auxiliary function to render the polyhedron Auxiliary function to render the polyhedron
:return: None :return: None
""" """
self.trimesh.show() self.trimesh.show()

View File

@ -9,130 +9,131 @@ from typing import Union, List
class Schedule: class Schedule:
""" """
Schedule class Schedule class
""" """
def __init__(self):
self._id = None
self._type = None
self._values = None
self._data_type = None
self._time_step = None
self._time_range = None
self._day_types = None
@property def __init__(self):
def id(self): self._id = None
""" self._type = None
self._values = None
self._data_type = None
self._time_step = None
self._time_range = None
self._day_types = None
@property
def id(self):
"""
Get schedule id, an universally unique identifier randomly generated Get schedule id, an universally unique identifier randomly generated
:return: str :return: str
""" """
if self._id is None: if self._id is None:
self._id = uuid.uuid4() self._id = uuid.uuid4()
return self._id return self._id
@property @property
def type(self) -> Union[None, str]: def type(self) -> Union[None, str]:
""" """
Get schedule type Get schedule type
:return: None or str :return: None or str
""" """
return self._type return self._type
@type.setter @type.setter
def type(self, value): def type(self, value):
""" """
Set schedule type Set schedule type
:param: str :param: str
""" """
if value is not None: if value is not None:
self._type = str(value) self._type = str(value)
@property @property
def values(self): def values(self):
""" """
Get schedule values Get schedule values
:return: [Any] :return: [Any]
""" """
return self._values return self._values
@values.setter @values.setter
def values(self, value): def values(self, value):
""" """
Set schedule values Set schedule values
:param: [Any] :param: [Any]
""" """
self._values = value self._values = value
@property @property
def data_type(self) -> Union[None, str]: def data_type(self) -> Union[None, str]:
""" """
Get schedule data type from: Get schedule data type from:
['any_number', 'fraction', 'on_off', 'temperature', 'humidity', 'control_type'] ['any_number', 'fraction', 'on_off', 'temperature', 'humidity', 'control_type']
:return: None or str :return: None or str
""" """
return self._data_type return self._data_type
@data_type.setter @data_type.setter
def data_type(self, value): def data_type(self, value):
""" """
Set schedule data type Set schedule data type
:param: str :param: str
""" """
if value is not None: if value is not None:
self._data_type = str(value) self._data_type = str(value)
@property @property
def time_step(self) -> Union[None, str]: def time_step(self) -> Union[None, str]:
""" """
Get schedule time step from: Get schedule time step from:
['second', 'minute', 'hour', 'day', 'week', 'month'] ['second', 'minute', 'hour', 'day', 'week', 'month']
:return: None or str :return: None or str
""" """
return self._time_step return self._time_step
@time_step.setter @time_step.setter
def time_step(self, value): def time_step(self, value):
""" """
Set schedule time step Set schedule time step
:param: str :param: str
""" """
if value is not None: if value is not None:
self._time_step = str(value) self._time_step = str(value)
@property @property
def time_range(self) -> Union[None, str]: def time_range(self) -> Union[None, str]:
""" """
Get schedule time range from: Get schedule time range from:
['minute', 'hour', 'day', 'week', 'month', 'year'] ['minute', 'hour', 'day', 'week', 'month', 'year']
:return: None or str :return: None or str
""" """
return self._time_range return self._time_range
@time_range.setter @time_range.setter
def time_range(self, value): def time_range(self, value):
""" """
Set schedule time range Set schedule time range
:param: str :param: str
""" """
if value is not None: if value is not None:
self._time_range = str(value) self._time_range = str(value)
@property @property
def day_types(self) -> Union[None, List[str]]: def day_types(self) -> Union[None, List[str]]:
""" """
Get schedule day types, as many as needed from: Get schedule day types, as many as needed from:
['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday', 'winter_design_day', ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'holiday', 'winter_design_day',
'summer_design_day'] 'summer_design_day']
:return: None or [str] :return: None or [str]
""" """
return self._day_types return self._day_types
@day_types.setter @day_types.setter
def day_types(self, value): def day_types(self, value):
""" """
Set schedule day types Set schedule day types
:param: [str] :param: [str]
""" """
if value is not None: if value is not None:
self._day_types = [str(i) for i in value] self._day_types = [str(i) for i in value]