Skip to content

Commit

Permalink
Merge pull request #1714 from HEXRD/pinhole-mask-no-distortion
Browse files Browse the repository at this point in the history
Do not apply pinhole distortion to pinhole mask
  • Loading branch information
saransh13 authored Jul 5, 2024
2 parents 058a964 + f1d7f84 commit fdeb6ed
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
9 changes: 8 additions & 1 deletion hexrdgui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from hexrdgui.constants import OverlayType, PolarXAxisType, ViewType
from hexrdgui.create_hedm_instrument import create_view_hedm_instrument
from hexrdgui.hexrd_config import HexrdConfig
from hexrdgui.masking.constants import MaskType
from hexrdgui.masking.create_polar_mask import create_polar_line_data_from_raw
from hexrdgui.masking.mask_manager import MaskManager
from hexrdgui.snip_viewer_dialog import SnipViewerDialog
Expand Down Expand Up @@ -1668,7 +1669,13 @@ def draw_mask_boundaries(self, axis, det=None):
else:
verts = [v for k, v in mask.data if k == det]
elif self.mode == ViewType.polar or self.mode == ViewType.stereo:
verts = create_polar_line_data_from_raw(instr, mask.data)
# Do not apply tth distortion for the pinhole mask
apply_tth_distortion = mask.type != MaskType.pinhole
verts = create_polar_line_data_from_raw(
instr,
mask.data,
apply_tth_distortion=apply_tth_distortion,
)
if self.mode == ViewType.polar:
# Check for any major jumps in eta. That probably means
# the border is wrapping around.
Expand Down
24 changes: 18 additions & 6 deletions hexrdgui/masking/create_polar_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hexrdgui.utils.tth_distortion import apply_tth_distortion_if_needed


def convert_raw_to_polar(instr, det, line):
def convert_raw_to_polar(instr, det, line, apply_tth_distortion=True):
# This accepts an instrument rather than creating one for performance

# Make sure there at least 500 sample points so that the conversion
Expand All @@ -27,7 +27,10 @@ def convert_raw_to_polar(instr, det, line):
'tvec_s': instr.tvec
}
line = cart_to_angles(xys, panel, **kwargs)
line = apply_tth_distortion_if_needed(line, in_degrees=True)

if apply_tth_distortion:
line = apply_tth_distortion_if_needed(line, in_degrees=True)

return [line] if line.size else None


Expand Down Expand Up @@ -144,22 +147,31 @@ def _interpolate_split_coords_1d(coords1, coords2):
return coords1, coords2


def create_polar_line_data_from_raw(instr, value):
def create_polar_line_data_from_raw(instr, value, apply_tth_distortion=True):
# This accepts an instrument rather than creating one for performance
line_data = []
for det, data in value:
if polar := convert_raw_to_polar(instr, det, data):
if polar := convert_raw_to_polar(
instr,
det,
data,
apply_tth_distortion=apply_tth_distortion,
):
line_data.extend(polar)
return line_data


def create_polar_mask_from_raw(value, instr=None):
def create_polar_mask_from_raw(value, instr=None, apply_tth_distortion=True):
if instr is None:
# An instrument can be passed for improved performance.
# If one wasn't passed, create one.
instr = create_hedm_instrument()

line_data = create_polar_line_data_from_raw(instr, value)
line_data = create_polar_line_data_from_raw(
instr,
value,
apply_tth_distortion=apply_tth_distortion,
)
return create_polar_mask(line_data)


Expand Down
10 changes: 8 additions & 2 deletions hexrdgui/masking/mask_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def update_masked_arrays(self, view=ViewType.raw, instr=None):
if view == ViewType.raw:
self.masked_arrays = create_raw_mask(self._raw)
else:
self.masked_arrays = create_polar_mask_from_raw(self._raw, instr)
# Do not apply tth distortion for pinhole mask types
apply_tth_distortion = self.type != MaskType.pinhole
self.masked_arrays = create_polar_mask_from_raw(
self._raw,
instr,
apply_tth_distortion=apply_tth_distortion,
)

def get_masked_arrays(self, image_mode=ViewType.raw, instr=None):
if self.masked_arrays is None or self.masked_arrays_view_mode != image_mode:
Expand All @@ -100,7 +106,7 @@ def get_masked_arrays(self, image_mode=ViewType.raw, instr=None):
return self.masked_arrays

def update_border_visibility(self, visibility):
can_have_border = [MaskType.region, MaskType.polygon]
can_have_border = [MaskType.region, MaskType.polygon, MaskType.pinhole]
if self.type not in can_have_border:
# Only rectangle, ellipse and hand-drawn masks can show borders
visibility = False
Expand Down
3 changes: 2 additions & 1 deletion hexrdgui/masking/mask_manager_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def update_table(self):
if key in MaskManager().visible_masks:
idx = MaskStatus.visible
if (mask_type == MaskType.region or
mask_type == MaskType.polygon):
mask_type == MaskType.polygon or
mask_type == MaskType.pinhole):
presentation_combo.addItem('Boundary Only')
presentation_combo.addItem('Visible + Boundary')
if key in MaskManager().visible_boundaries:
Expand Down

0 comments on commit fdeb6ed

Please sign in to comment.