Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions contrib/common/lib/cv/annotations/CircularAnnotations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import TYPE_CHECKING
import numpy as np
import scipy.spatial.transform

Expand All @@ -14,10 +13,6 @@
import opencsp.common.lib.render_control.RenderControlPointSeq as rcps
import opencsp.common.lib.tool.log_tools as lt

if TYPE_CHECKING:
# don't import at runtime in order to avoid cyclic dependencies
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable


class CircularAnnotations(AbstractAnnotations):
"""
Expand Down Expand Up @@ -82,13 +77,7 @@ def scale(self) -> list[float]:
)
return [d * self.meters_per_pixel for d in self.size]

def render_to_figure(
self,
fig: rcfr.RenderControlFigureRecord,
image: np.ndarray = None,
include_label=False,
operable: "SpotAnalysisOperable" = None,
):
def render_to_figure(self, fig: rcfr.RenderControlFigureRecord, image: np.ndarray = None, include_label=False):
label = self.get_label(include_label)

# draw the circles
Expand All @@ -104,8 +93,6 @@ def render_to_figure(
for seg in range(nverticies):
p = (np.sin(seg / nverticies * np.pi * 2) * r) + x
q = (np.cos(seg / nverticies * np.pi * 2) * r) + y
if operable is not None:
p, q = operable.transform_coordinates(p2.Pxy((p, q)))[1].astuple()
pq_list.append((p, q))

fig.view.draw_pq_list(pq_list, close=True, style=self.style, label=label)
Expand Down
17 changes: 3 additions & 14 deletions contrib/common/lib/cv/annotations/EnclosedEnergyAnnotations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import TYPE_CHECKING
import numpy as np
import scipy.spatial.transform

Expand All @@ -11,10 +10,6 @@
import opencsp.common.lib.render_control.RenderControlFigureRecord as rcfr
import opencsp.common.lib.render_control.RenderControlPointSeq as rcps

if TYPE_CHECKING:
# don't import at runtime in order to avoid cyclic dependencies
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable


class EnclosedEnergyAnnotations(AbstractAnnotations):
"""
Expand Down Expand Up @@ -89,17 +84,11 @@ def size(self) -> list[float]:
def scale(self) -> list[float]:
return self._representative_circle.scale

def render_to_figure(
self,
fig: rcfr.RenderControlFigureRecord,
image: np.ndarray = None,
include_label=False,
operable: "SpotAnalysisOperable" = None,
):
def render_to_figure(self, fig: rcfr.RenderControlFigureRecord, image: np.ndarray = None, include_label=False):
if self.enclosed_shape == "circle":
return self._representative_circle.render_to_figure(fig, image, include_label, operable)
return self._representative_circle.render_to_figure(fig, image, include_label)
elif self.enclosed_shape == "square":
return self._representative_square.render_to_figure(fig, image, include_label, operable)
return self._representative_square.render_to_figure(fig, image, include_label)
else:
raise RuntimeError(
"Error in EnclosedEnergyAnnotations.render_to_figure() "
Expand Down
21 changes: 2 additions & 19 deletions contrib/common/lib/cv/annotations/MomentsAnnotation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
from functools import cache, cached_property
from typing import TYPE_CHECKING

import numpy as np
import scipy.spatial.transform
Expand All @@ -16,10 +15,6 @@
import opencsp.common.lib.tool.image_tools as it
import opencsp.common.lib.tool.log_tools as lt

if TYPE_CHECKING:
# don't import at runtime in order to avoid cyclic dependencies
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable


class MomentsAnnotation(AbstractAnnotations):
def __init__(
Expand Down Expand Up @@ -257,18 +252,11 @@ def central_moment(self, p: int, q: int) -> float:
# other uses of moments...

def render_to_figure(
self,
fig_record: rcfr.RenderControlFigureRecord,
image: np.ndarray = None,
include_label: bool = False,
operable: "SpotAnalysisOperable" = None,
self, fig_record: rcfr.RenderControlFigureRecord, image: np.ndarray = None, include_label: bool = False
):
# draw the centroid marker
label = None if not include_label else "centroid"
cX, cY = self.cX, self.cY
if operable is not None:
cX, cY = operable.transform_coordinates(p2.Pxy((cX, cY)))[1].astuple()
fig_record.view.draw_pq(([cX], [cY]), self.style, label=label)
fig_record.view.draw_pq(([self.cX], [self.cY]), self.style, label=label)

# start by assuming that the plot is >= 30 pixels
height, width, rotation_arrow_dist = None, None, 30
Expand Down Expand Up @@ -301,11 +289,6 @@ def render_to_figure(
if len(intersections) > 0:
rotation_endpoints_list = [(intersections.x[i], intersections.y[i]) for i in range(len(intersections))]

# transform coordinates for the operable
if operable is not None:
for i, (p, q) in enumerate(rotation_endpoints_list):
rotation_endpoints_list[i] = operable.transform_coordinates(p2.Pxy((p, q)))[1].astuple()

# draw the rotation as an arrow
style = copy.deepcopy(self.rotation_style)
style.marker = "arrow"
Expand Down
15 changes: 1 addition & 14 deletions contrib/common/lib/cv/annotations/RectangleAnnotations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import TYPE_CHECKING
import numpy as np
import scipy.spatial.transform

Expand All @@ -14,10 +13,6 @@
import opencsp.common.lib.render_control.RenderControlPointSeq as rcps
import opencsp.common.lib.tool.log_tools as lt

if TYPE_CHECKING:
# don't import at runtime in order to avoid cyclic dependencies
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable


class RectangleAnnotations(AbstractAnnotations):
"""
Expand Down Expand Up @@ -87,13 +82,7 @@ def scale(self) -> list[float]:
)
return [self.size * self.meters_per_pixel]

def render_to_figure(
self,
fig: rcfr.RenderControlFigureRecord,
image: np.ndarray = None,
include_label=False,
operable: "SpotAnalysisOperable" = None,
):
def render_to_figure(self, fig: rcfr.RenderControlFigureRecord, image: np.ndarray = None, include_label=False):
label = self.get_label(include_label)

# get the corner vertices for each bounding box
Expand All @@ -103,8 +92,6 @@ def render_to_figure(
for loop in bbox.loops:
loop_verts = list(zip(loop.vertices.x, loop.vertices.y))
loop_verts = [(int(x), int(y)) for x, y in loop_verts]
if operable is not None:
loop_verts = [operable.transform_coordinates(p2.Pxy((x, y)))[1].astuple() for x, y in loop_verts]
draw_loops.append(loop_verts)

# draw the bounding boxes
Expand Down
30 changes: 4 additions & 26 deletions contrib/common/lib/cv/annotations/SpotWidthAnnotation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import TYPE_CHECKING
import matplotlib.patches
import numpy as np
import scipy.spatial.transform
Expand All @@ -11,10 +10,6 @@
import opencsp.common.lib.render_control.RenderControlFigureRecord as rcfr
import opencsp.common.lib.render_control.RenderControlSpotSize as rcss

if TYPE_CHECKING:
# don't import at runtime in order to avoid cyclic dependencies
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable


class SpotWidthAnnotation(AbstractAnnotations):
def __init__(
Expand Down Expand Up @@ -99,13 +94,7 @@ def rotation(self) -> scipy.spatial.transform.Rotation:
def size(self) -> list[float]:
raise NotImplementedError

def render_to_figure(
self,
fig: rcfr.RenderControlFigureRecord,
image: np.ndarray,
include_label=False,
operable: "SpotAnalysisOperable" = None,
):
def render_to_figure(self, fig: rcfr.RenderControlFigureRecord, image: np.ndarray, include_label=False):
label = self.get_label(include_label)

# draw the full-width boundary
Expand All @@ -120,23 +109,17 @@ def render_to_figure(
}
label = None
if self.spot_width_technique == "fwhm":
center = self.long_axis_center
if operable is not None:
center = operable.transform_coordinates(center)[1]
ellipse = matplotlib.patches.Ellipse(
xy=center.astuple(),
xy=self.long_axis_center.astuple(),
width=self.width,
height=self.orthogonal_axis_width,
angle=np.rad2deg(self.long_axis_rotation),
**style_params
)
fig.view.axis.add_patch(ellipse)
else:
center = self.centroid_loc
if operable is not None:
center = operable.transform_coordinates(center)[1]
ellipse = matplotlib.patches.Ellipse(
xy=center.astuple(), width=self.width, height=self.width, **style_params
xy=self.centroid_loc.astuple(), width=self.width, height=self.width, **style_params
)
fig.view.axis.add_patch(ellipse)

Expand All @@ -146,15 +129,10 @@ def render_to_figure(
for loop in bbox.loops:
loop_verts = list(zip(loop.vertices.x, loop.vertices.y))
loop_verts = [(int(x), int(y)) for x, y in loop_verts]
if operable is not None:
loop_verts = [operable.transform_coordinates(p2.Pxy((x, y)))[1].astuple() for x, y in loop_verts]
fig.view.draw_pq_list(loop_verts, close=True, style=self.style.bounding_box_style, label=label)
label = None

# draw the centroid
if self.style.center_style != "None":
xy = self.centroid_loc
if operable is not None:
xy = operable.transform_coordinates(xy)[1]
fig.view.draw_pq(xy.data, self.style.center_style, label=label)
fig.view.draw_pq(self.centroid_loc.data, self.style.center_style, label=label)
label = None

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,12 @@ def visualize_operable(

# initialize the figure
self.prepare_figure_records([self.figure], [image.shape])
tc = lambda x, y: operable.transform_coordinates(p2.Pxy((x, y)))[1].astuple()
(height, width), _ = it.dims_and_nchannels(image)
img_xy, img_xy2 = tc(0, 0), tc(width, height)
self.figure.view.draw_image(
base_image.nparray, img_xy, (img_xy2[0] - img_xy[0], img_xy2[1] - img_xy[1]), invert_ylim=True
)
self.figure.view.imshow(image)

# render
include_label = len(to_render) > 1
for fiducials in to_render:
fiducials.render_to_figure(self.figure, image, include_label, operable)
fiducials.render_to_figure(self.figure, image, include_label)

# show the legend
if include_label:
Expand Down
Loading