Skip to content

Commit

Permalink
moved method Pxyz.draw_point() -> Vxyz.draw_points(), moved method Vx…
Browse files Browse the repository at this point in the history
…yz.draw_list() -> Vxyz.draw_line()
  • Loading branch information
bbean23 committed Sep 6, 2024
1 parent 4ebc096 commit 345bc3e
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 55 deletions.
6 changes: 3 additions & 3 deletions example/raytrace/example_RayTraceOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,14 @@ def fn_5w1(x, y):
def _draw_helper(view: View3d) -> None:
sf1.draw(view, solar_field_style)
trace.draw(view, trace_control)
aimpoint_xyz.draw_point(view, style=rcps.marker(color='tab:orange'))
aimpoint_xyz.draw_points(view, style=rcps.marker(color='tab:orange'))

# debug
heliostat_origin = sf1.heliostats[0].self_to_global_tranformation.apply(Pxyz.origin())
pointing_vector = st.tracking_surface_normal_xyz(
heliostat_origin, aimpoint_xyz, lln.NSTTF_ORIGIN, when_ymdhmsz
)
Vxyz.merge([heliostat_origin, heliostat_origin + pointing_vector * 10]).draw_list(view)
Vxyz.merge([heliostat_origin, heliostat_origin + pointing_vector * 10]).draw_line(view)
# debug

self.show_save_and_check_figure(fig_record)
Expand Down Expand Up @@ -770,7 +770,7 @@ def example_partial_field_trace(self) -> None:
trace = rt.trace_scene(scene, Resolution.center(), verbose=False)
trace.draw(view, RenderControlRayTrace(RenderControlLightPath(15, 200)))

aimpoint_xyz.draw_point(view, rcps.RenderControlPointSeq(color='orange', marker='.'))
aimpoint_xyz.draw_points(view, rcps.RenderControlPointSeq(color='orange', marker='.'))

self.show_save_and_check_figure(fig_record)

Expand Down
12 changes: 6 additions & 6 deletions example/solarfield/example_SolarFieldOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def example_solar_field_h_outlines(self) -> None:
code_tag=self.code_tag,
)
solar_field.draw(fig_record.view, solar_field_style)
aimpoint_xyz.draw_list(fig_record.view, style=rcps.marker(color='tab:orange'), label='aimpoint_xyz')
aimpoint_xyz.draw_line(fig_record.view, style=rcps.marker(color='tab:orange'), label='aimpoint_xyz')

# Output.
self.show_save_and_check_figure(fig_record)
Expand Down Expand Up @@ -763,7 +763,7 @@ def example_heliostat_vector_field(self) -> None:
comments=comments,
code_tag=self.code_tag,
)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
solar_field.draw(fig_record.view, solar_field_style)
self.show_save_and_check_figure(fig_record)

Expand All @@ -781,7 +781,7 @@ def example_heliostat_vector_field(self) -> None:
comments=comments,
code_tag=self.code_tag,
)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
solar_field.draw(fig_record.view, solar_field_style)
self.show_save_and_check_figure(fig_record)

Expand All @@ -799,7 +799,7 @@ def example_heliostat_vector_field(self) -> None:
comments=comments,
code_tag=self.code_tag,
)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
solar_field.draw(fig_record.view, solar_field_style)
self.show_save_and_check_figure(fig_record)

Expand All @@ -817,7 +817,7 @@ def example_heliostat_vector_field(self) -> None:
comments=comments,
code_tag=self.code_tag,
)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
solar_field.draw(fig_record.view, solar_field_style)
self.show_save_and_check_figure(fig_record)

Expand Down Expand Up @@ -868,7 +868,7 @@ def example_dense_vector_field(self) -> None:
code_tag=self.code_tag,
)
solar_field.draw(fig_record.view, solar_field_style)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')

# Draw dense vector field.
grid_xy = solar_field.heliostat_field_regular_grid_xy(40, 20)
Expand Down
8 changes: 4 additions & 4 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:
Pxyz(origin).draw_point(view, style=facet_style.centroid_style)
origin.draw_points(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]])
transform.apply(border).draw_list(view, close=True, style=facet_style.outline_style)
transform.apply(border).draw_line(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.
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)
origin.draw_points(view, style=facet_style.surface_normal_base_style)
Vxyz.merge([origin, surface_normal_ray]).draw_line(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
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:
Pxyz(origin).draw_point(view)
origin.draw_points(view)

# pointing vector of the facet ensemble
if facet_ensemble_style.draw_normal_vector:
Vxyz.merge([origin, normal_vector]).draw_list(view, style=facet_ensemble_style.normal_vector_style)
Vxyz.merge([origin, normal_vector]).draw_line(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)
corners_moved.draw_list(view, close=True, style=facet_ensemble_style.outline_style)
corners_moved.draw_line(view, close=True, style=facet_ensemble_style.outline_style)

# debug function
def set_facet_transform_list(self, transformations: list[TransformXYZ]):
Expand Down
4 changes: 2 additions & 2 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:
Pxyz(origin).draw_point(view, style=heliostat_style.centroid_style)
origin.draw_points(view, style=heliostat_style.centroid_style)

# # Outline.
# if heliostat_style.draw_outline:
Expand Down Expand Up @@ -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)
Vxyz.merge([origin + DOWN, origin]).draw_list(view)
Vxyz.merge([origin + DOWN, origin]).draw_line(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
edge_values_lifted.draw_list(view, style=mirror_style.point_styles)
edge_values_lifted.draw_line(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
p_space.draw_point(view, style=mirror_style.point_styles)
p_space.draw_points(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
edge_values_lifted.draw_list(view, style=edge_style)
edge_values_lifted.draw_line(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:
Pxyz(origin).draw_point(view)
origin.draw_points(view)

# Heliostats.
if solar_field_style.draw_heliostats:
Expand Down
4 changes: 2 additions & 2 deletions opencsp/common/lib/geometry/Intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +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()
self.intersection_points.draw_point(view, style)
self.intersection_points.draw_points(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)):
p = Pxyz(self.intersection_points[int(i)])
p.draw_point(view)
p.draw_points(view)
16 changes: 0 additions & 16 deletions opencsp/common/lib/geometry/Pxyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,3 @@ 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)
24 changes: 22 additions & 2 deletions opencsp/common/lib/geometry/Vxyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,38 @@ def origin(cls):
# zs.append(func(x, y))
# return cls([xs, ys, zs])

def draw_list(
def draw_line(
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."""
"""
Calls figure.draw_xyz_list(self.data.T) to draw all xyz points in a
single series. Uses the default arguments for draw_xyz_list in place of
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)

def draw_points(
self,
figure: rcfr.RenderControlFigureRecord | v3d.View3d,
style: rcps.RenderControlPointSeq = None,
labels: list[str] = None,
):
"""
Calls figure.draw_xyz(p) to draw all xyz points in this instance
individually. Uses the default arguments in place for any None's.
"""
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: 15 additions & 4 deletions opencsp/common/lib/render/View3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,24 @@ def draw_xyz_list(
style: rcps.RenderControlPointSeq = None,
label: str = None,
) -> None:
"""Draw lines or closed polygons.
"""
Draw lines or closed polygons.
Parameters
----------
input_xyz_list: List of xyz three vectors (eg [[0,0,0], [1,1,1]])
close: Draw as a closed polygon (ignored if input_xyz_list < 3 points)"""

input_xyz_list : Iterable[tuple[float, float, float]]
List of xyz three vectors (eg [[0,0,0], [1,1,1]]). The vectors must
be indexable, such as with input_xyz_list[0][0].
close : bool, optional
True to draw as a closed polygon (ignored if input_xyz_list < 3
points), or False to draw as given. By default False.
style : rcps.RenderControlPointSeq, optional
The style with which to render, or None for
RenderControlPointSeq.default(). By default None.
label : str, optional
The label to assign to this plot to be used in the legend, or None
for no label. By default None.
"""
if style == None:
style = rcps.default()

Expand Down
6 changes: 3 additions & 3 deletions opencsp/common/lib/test/test_FluxMaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def square(z: float):
mirror.draw(fig_record.view, mirror_style)
trace_style = rcrt.init_current_lengths(current_len=6)
trace.draw(fig_record.view, trace_style)
square(4).draw_list(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='b', marker=','))
square(5).draw_list(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='g', marker=','))
square(6).draw_list(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='r', marker=','))
square(4).draw_line(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='b', marker=','))
square(5).draw_line(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='g', marker=','))
square(6).draw_line(fig_record.view, close=True, style=rcps.RenderControlPointSeq(color='r', marker=','))
self.show_save_and_check_figure(fig_record)

# Draw z=4
Expand Down
6 changes: 3 additions & 3 deletions opencsp/common/lib/test/test_RayTraceOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@ def fn_5w1(x, y):
def _draw_helper(view: View3d) -> None:
sf1.draw(view, solar_field_style)
trace.draw(view, trace_control)
aimpoint_xyz.draw_point(view, style=rcps.marker(color='tab:orange'))
aimpoint_xyz.draw_points(view, style=rcps.marker(color='tab:orange'))

# debug
heliostat_origin = sf1.heliostats[0].self_to_global_tranformation.apply(Pxyz.origin())
pointing_vector = st.tracking_surface_normal_xyz(
heliostat_origin, aimpoint_xyz, lln.NSTTF_ORIGIN, when_ymdhmsz
)
Vxyz.merge([heliostat_origin, heliostat_origin + pointing_vector * 10]).draw_list(view)
Vxyz.merge([heliostat_origin, heliostat_origin + pointing_vector * 10]).draw_line(view)
# debug

self.show_save_and_check_figure(fig_record)
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_partial_field_trace(self) -> None:
trace = rt.trace_scene(scene, Resolution.center(), verbose=False)
trace.draw(view, RenderControlRayTrace(RenderControlLightPath(15, 200)))

aimpoint_xyz.draw_point(view, rcps.RenderControlPointSeq(color='orange', marker='.'))
aimpoint_xyz.draw_points(view, rcps.RenderControlPointSeq(color='orange', marker='.'))

self.show_save_and_check_figure(fig_record)

Expand Down
6 changes: 3 additions & 3 deletions opencsp/common/lib/test/test_SolarFieldOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def old_solar_field_h_outlines(self) -> None:
code_tag=self.code_tag,
)
solar_field.draw(fig_record.view, solar_field_style)
aimpoint_xyz.draw_list(fig_record.view, style=rcps.marker(color='tab:orange'), label='aimpoint_xyz')
aimpoint_xyz.draw_line(fig_record.view, style=rcps.marker(color='tab:orange'), label='aimpoint_xyz')

# Output.
self.show_save_and_check_figure(fig_record)
Expand Down Expand Up @@ -779,7 +779,7 @@ def test_heliostat_vector_field(self) -> None:
comments=comments,
code_tag=self.code_tag,
)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
solar_field.draw(fig_record.view, solar_field_style)
self.show_save_and_check_figure(fig_record)

Expand Down Expand Up @@ -838,7 +838,7 @@ def test_dense_vector_field(self) -> None:
code_tag=self.code_tag,
)
solar_field.draw(fig_record.view, solar_field_style)
aimpoint_xyz.draw_point(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')
aimpoint_xyz.draw_points(fig_record.view, style=rcps.marker(color='tab:orange'), labels='aimpoint_xyz')

# Draw dense vector field.
grid_xy = solar_field.heliostat_field_regular_grid_xy(40, 20)
Expand Down

0 comments on commit 345bc3e

Please sign in to comment.