Skip to content

Commit

Permalink
move class-specific draw methods out of View3d and into Vxyz and Pxyz
Browse files Browse the repository at this point in the history
  • Loading branch information
bbean23 committed Aug 10, 2024
1 parent 455d425 commit df38169
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 33 deletions.
12 changes: 6 additions & 6 deletions opencsp/common/lib/csp/Facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -271,4 +271,4 @@ def pointing_function(rotation: Rotation) -> TransformXYZ:

return facet

### END POINTING FUNCTION METHODS
# END POINTING FUNCTION METHODS
6 changes: 3 additions & 3 deletions opencsp/common/lib/csp/FacetEnsemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
8 changes: 4 additions & 4 deletions opencsp/common/lib/csp/HeliostatAbstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -318,15 +318,15 @@ 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:
# # Construct ray.
# 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)

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion opencsp/common/lib/csp/MirrorAbstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions opencsp/common/lib/csp/MirrorPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion opencsp/common/lib/csp/SolarField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions opencsp/common/lib/geometry/Intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions opencsp/common/lib/geometry/Pxyz.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
19 changes: 19 additions & 0 deletions opencsp/common/lib/geometry/Vxyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
14 changes: 0 additions & 14 deletions opencsp/common/lib/render/View3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]],
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit df38169

Please sign in to comment.