From df38169af99b2c472273283d488c57fa9939a508 Mon Sep 17 00:00:00 2001 From: bbean Date: Fri, 9 Aug 2024 18:42:36 -0600 Subject: [PATCH] move class-specific draw methods out of View3d and into Vxyz and Pxyz --- opencsp/common/lib/csp/Facet.py | 12 ++++++------ opencsp/common/lib/csp/FacetEnsemble.py | 6 +++--- opencsp/common/lib/csp/HeliostatAbstract.py | 8 ++++---- opencsp/common/lib/csp/MirrorAbstract.py | 2 +- opencsp/common/lib/csp/MirrorPoint.py | 4 ++-- opencsp/common/lib/csp/SolarField.py | 2 +- opencsp/common/lib/geometry/Intersection.py | 5 +++-- opencsp/common/lib/geometry/Pxyz.py | 19 +++++++++++++++++++ opencsp/common/lib/geometry/Vxyz.py | 19 +++++++++++++++++++ opencsp/common/lib/render/View3d.py | 14 -------------- 10 files changed, 58 insertions(+), 33 deletions(-) diff --git a/opencsp/common/lib/csp/Facet.py b/opencsp/common/lib/csp/Facet.py index bd9753aac..942cee32f 100644 --- a/opencsp/common/lib/csp/Facet.py +++ b/opencsp/common/lib/csp/Facet.py @@ -158,7 +158,7 @@ def draw(self, view: View3d, facet_style: RenderControlFacet = None, transform: # Centroid. if facet_style.draw_centroid: - view.draw_single_Pxyz(origin, style=facet_style.centroid_style) + Pxyz(origin).draw_point(view, style=facet_style.centroid_style) # Outline. if facet_style.draw_outline: @@ -169,15 +169,15 @@ def draw(self, view: View3d, facet_style: RenderControlFacet = None, transform: # view.draw_xyz_list(corners, close=True, style=facet_style.outline_style) left, right, bottom, top = self.axis_aligned_bounding_box border = Pxyz([[left, left, right, right], [top, bottom, bottom, top], [0, 0, 0, 0]]) - view.draw_Vxyz(transform.apply(border), close=True, style=facet_style.outline_style) + transform.apply(border).draw_list(view, close=True, style=facet_style.outline_style) # Surface normal. if facet_style.draw_surface_normal: # Construct ray. surface_normal_ray = transform.apply(UP * facet_style.surface_normal_length) # Draw ray and its base. - view.draw_single_Pxyz(origin, style=facet_style.surface_normal_base_style) - view.draw_Vxyz(Vxyz.merge([origin, surface_normal_ray]), style=facet_style.surface_normal_style) + Pxyz(origin).draw_point(view, style=facet_style.surface_normal_base_style) + Vxyz.merge([origin, surface_normal_ray]).draw_list(view, style=facet_style.surface_normal_style) # # Surface normal drawn at corners. # # (Not the surface normal at the corner. Facet curvature is not shown.) @@ -209,7 +209,7 @@ def draw(self, view: View3d, facet_style: RenderControlFacet = None, transform: # pass # end function - ### POINTING FUNCTION METHODS + # POINTING FUNCTION METHODS # TODO TJL: Pointing Function methods are not tested with the updated base classes. # There will need to be an addition to `Facet` that allows users to specify the ways # a facet mounts the mirror it contains. Defining some function might @@ -271,4 +271,4 @@ def pointing_function(rotation: Rotation) -> TransformXYZ: return facet - ### END POINTING FUNCTION METHODS + # END POINTING FUNCTION METHODS diff --git a/opencsp/common/lib/csp/FacetEnsemble.py b/opencsp/common/lib/csp/FacetEnsemble.py index ef138ab3c..3d91aa4f0 100644 --- a/opencsp/common/lib/csp/FacetEnsemble.py +++ b/opencsp/common/lib/csp/FacetEnsemble.py @@ -182,17 +182,17 @@ def draw( # origin of the facet ensemble if facet_ensemble_style.draw_centroid: - view.draw_single_Pxyz(origin) + Pxyz(origin).draw_point(view) # pointing vector of the facet ensemble if facet_ensemble_style.draw_normal_vector: - view.draw_Vxyz(Vxyz.merge([origin, normal_vector]), style=facet_ensemble_style.normal_vector_style) + Vxyz.merge([origin, normal_vector]).draw_list(view, style=facet_ensemble_style.normal_vector_style) if facet_ensemble_style.draw_outline: left, right, top, bottom = self.axis_aligned_bounding_box corners = Pxyz([[left, left, right, right], [top, bottom, bottom, top], [0, 0, 0, 0]]) corners_moved = transform.apply(corners) - view.draw_Vxyz(corners_moved, close=True, style=facet_ensemble_style.outline_style) + corners_moved.draw_list(view, close=True, style=facet_ensemble_style.outline_style) # debug function def set_facet_transform_list(self, transformations: list[TransformXYZ]): diff --git a/opencsp/common/lib/csp/HeliostatAbstract.py b/opencsp/common/lib/csp/HeliostatAbstract.py index 9eec7645f..781fbc50f 100644 --- a/opencsp/common/lib/csp/HeliostatAbstract.py +++ b/opencsp/common/lib/csp/HeliostatAbstract.py @@ -309,7 +309,7 @@ def draw(self, view: View3d, heliostat_style: RenderControlHeliostat = None, tra # Centroid. if heliostat_style.draw_centroid: - view.draw_single_Pxyz(origin, style=heliostat_style.centroid_style) + Pxyz(origin).draw_point(view, style=heliostat_style.centroid_style) # # Outline. # if heliostat_style.draw_outline: @@ -318,7 +318,7 @@ def draw(self, view: View3d, heliostat_style: RenderControlHeliostat = None, tra # [top, bottom, bottom, top], # [0, 0, 0, 0]]) # corners_moved = transform.apply(corners) - # view.draw_Vxyz(corners_moved, close=True, style=heliostat_style.outline_style) + # corners_moved.draw_list(view, close=True, style=heliostat_style.outline_style) # # Surface normal. # if heliostat_style.draw_surface_normal: @@ -326,7 +326,7 @@ def draw(self, view: View3d, heliostat_style: RenderControlHeliostat = None, tra # self.facet_ensemble. # surface_normal_ray = transform.apply(UP * heliostat_style.corner_normal_length) # # Draw ray and its base. - # view.draw_Vxyz(Vxyz.merge([origin, surface_normal_ray]), + # Vxyz.merge([origin, surface_normal_ray]).draw_list(view, # close=False, # style=heliostat_style.surface_normal_style) @@ -339,7 +339,7 @@ def draw(self, view: View3d, heliostat_style: RenderControlHeliostat = None, tra if heliostat_style.post != 0: DOWN = Vxyz([0, 0, -heliostat_style.post]) direction = transform.apply(DOWN) - view.draw_Vxyz(Vxyz.merge([origin + DOWN, origin])) + Vxyz.merge([origin + DOWN, origin]).draw_list(view) # Name. if heliostat_style.draw_name: diff --git a/opencsp/common/lib/csp/MirrorAbstract.py b/opencsp/common/lib/csp/MirrorAbstract.py index c47bfca84..a2b9647fe 100644 --- a/opencsp/common/lib/csp/MirrorAbstract.py +++ b/opencsp/common/lib/csp/MirrorAbstract.py @@ -307,7 +307,7 @@ def draw( # Draw surface boundary if mirror_style.point_styles is not None: mirror_style.point_styles.markersize = 0 - view.draw_Vxyz(edge_values_lifted, style=mirror_style.point_styles) + edge_values_lifted.draw_list(view, style=mirror_style.point_styles) # Draw surface normals if mirror_style.surface_normals: diff --git a/opencsp/common/lib/csp/MirrorPoint.py b/opencsp/common/lib/csp/MirrorPoint.py index afea7799f..a3f66dc73 100644 --- a/opencsp/common/lib/csp/MirrorPoint.py +++ b/opencsp/common/lib/csp/MirrorPoint.py @@ -176,7 +176,7 @@ def draw(self, view: View3d, mirror_style: RenderControlMirror, transform: Trans p_space = self.location_in_space(domain) # Draw sample points - view.draw_single_Pxyz(p_space, style=mirror_style.point_styles) + p_space.draw_point(view, style=mirror_style.point_styles) # Calculate z height of boundary to draw (lowest z value) min_val = min(self.surface_displacement_at(domain)) @@ -189,7 +189,7 @@ def draw(self, view: View3d, mirror_style: RenderControlMirror, transform: Trans if mirror_style.point_styles is not None: edge_style = mirror_style.point_styles edge_style.markersize = 0 - view.draw_Vxyz(edge_values_lifted, style=edge_style) + edge_values_lifted.draw_list(view, style=edge_style) # Draw surface normals if mirror_style.surface_normals: diff --git a/opencsp/common/lib/csp/SolarField.py b/opencsp/common/lib/csp/SolarField.py index afbaeeb39..6c28cb13a 100644 --- a/opencsp/common/lib/csp/SolarField.py +++ b/opencsp/common/lib/csp/SolarField.py @@ -318,7 +318,7 @@ def draw( # Draw Origin if solar_field_style.draw_origin: - view.draw_single_Pxyz(origin) + Pxyz(origin).draw_point(view) # Heliostats. if solar_field_style.draw_heliostats: diff --git a/opencsp/common/lib/geometry/Intersection.py b/opencsp/common/lib/geometry/Intersection.py index 6cbb1b10d..ee6041b0a 100644 --- a/opencsp/common/lib/geometry/Intersection.py +++ b/opencsp/common/lib/geometry/Intersection.py @@ -284,8 +284,9 @@ def _Pxy_to_flux_map(points: Pxy, bins: int, resolution_type: str = "pixelX") -> def draw(self, view: View3d, style: RenderControlPointSeq = None): if style is None: style = RenderControlPointSeq() - view.draw_single_Pxyz(self.intersection_points, style) + self.intersection_points.draw_point(view, style) def draw_subset(self, view: View3d, count: int, points_style: RenderControlPointSeq = None): for i in np.floor(np.linspace(0, len(self.intersection_points) - 1, count)): - view.draw_single_Pxyz(self.intersection_points[int(i)]) + p = Pxyz(self.intersection_points[int(i)]) + p.draw_point(view) diff --git a/opencsp/common/lib/geometry/Pxyz.py b/opencsp/common/lib/geometry/Pxyz.py index bb4844d3a..c647954d3 100644 --- a/opencsp/common/lib/geometry/Pxyz.py +++ b/opencsp/common/lib/geometry/Pxyz.py @@ -1,4 +1,7 @@ from opencsp.common.lib.geometry.Vxyz import Vxyz +import opencsp.common.lib.render.View3d as v3d +import opencsp.common.lib.render_control.RenderControlFigureRecord as rcfr +import opencsp.common.lib.render_control.RenderControlPointSeq as rcps class Pxyz(Vxyz): @@ -20,3 +23,19 @@ def as_Vxyz(self): @classmethod def empty(cls): return Pxyz([[], [], []]) + + def draw_point( + self, + figure: rcfr.RenderControlFigureRecord | v3d.View3d, + style: rcps.RenderControlPointSeq = None, + labels: list[str] = None, + ): + """Calls figure.draw_xyz(p) for all points in this instance, and with + the default arguments in place for any None's.""" + if style is None: + style = rcps.default(markersize=2) + if labels is None: + labels = [None] * len(self) + view = figure if isinstance(figure, v3d.View3d) else figure.view + for x, y, z, label in zip(self.x, self.y, self.z, labels): + view.draw_xyz((x, y, z), style, label) diff --git a/opencsp/common/lib/geometry/Vxyz.py b/opencsp/common/lib/geometry/Vxyz.py index a7edbc903..d50da7767 100644 --- a/opencsp/common/lib/geometry/Vxyz.py +++ b/opencsp/common/lib/geometry/Vxyz.py @@ -8,6 +8,9 @@ from scipy.spatial.transform import Rotation from opencsp.common.lib.geometry.Vxy import Vxy +import opencsp.common.lib.render.View3d as v3d +import opencsp.common.lib.render_control.RenderControlFigureRecord as rcfr +import opencsp.common.lib.render_control.RenderControlPointSeq as rcps class Vxyz: @@ -494,3 +497,19 @@ def origin(cls): # for x, y in zip(xs, ys): # zs.append(func(x, y)) # return cls([xs, ys, zs]) + + def draw_list( + self, + figure: rcfr.RenderControlFigureRecord | v3d.View3d, + close: bool = None, + style: rcps.RenderControlPointSeq = None, + label: str = None, + ) -> None: + """Calls figure.draw_xyz_list(self.data.T) with the default arguments in place for any None's.""" + kwargs = dict() + for key, val in [('close', close), ('style', style), ('label', label)]: + if val is not None: + kwargs[key] = val + + view = figure if isinstance(figure, v3d.View3d) else figure.view + view.draw_xyz_list(self.data.T, **kwargs) diff --git a/opencsp/common/lib/render/View3d.py b/opencsp/common/lib/render/View3d.py index 77300da01..91941e355 100644 --- a/opencsp/common/lib/render/View3d.py +++ b/opencsp/common/lib/render/View3d.py @@ -23,8 +23,6 @@ from PIL import Image import scipy.ndimage -from opencsp.common.lib.geometry.Pxyz import Pxyz -from opencsp.common.lib.geometry.Vxyz import Vxyz import opencsp.common.lib.render.axis_3d as ax3d import opencsp.common.lib.render.view_spec as vs import opencsp.common.lib.render_control.RenderControlPointSeq as rcps @@ -648,14 +646,6 @@ def draw_xyz( self.draw_xyz_list(lval, style=style, label=label) - def draw_single_Pxyz(self, p: Pxyz, style: rcps.RenderControlPointSeq = None, labels: list[str] = None): - if labels == None: - labels = [None] * len(p) - if style == None: - style = rcps.default(markersize=2) - for x, y, z, label in zip(p.x, p.y, p.z, labels): - self.draw_xyz((x, y, z), style, label) - def draw_xyz_list( self, input_xyz_list: Iterable[tuple[float, float, float]], @@ -769,10 +759,6 @@ def draw_xyz_list( + "' encountered.", ) - def draw_Vxyz(self, V: Vxyz, close=False, style=None, label=None) -> None: - """Alternative to View3d.drawxyz_list that used the Vxyz class instead""" - self.draw_xyz_list(list(V.data.T), close, style, label) - # TODO TJL: only implemented for 3d views, should extend def draw_xyz_surface( self,