Skip to content

Commit 9978be2

Browse files
authored
Merge pull request #1806 from HEXRD/atlas-config
Atlas config
2 parents 9625e5e + 52a88d5 commit 9978be2

File tree

2 files changed

+175
-76
lines changed

2 files changed

+175
-76
lines changed

hexrdgui/llnl_import_tool_dialog.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from hexrd import resources as hexrd_resources
1515
from hexrd.instrument import HEDMInstrument
1616
from hexrd.rotations import (
17-
angleAxisOfRotMat, make_rmat_euler, angles_from_rmat_zxz
17+
angleAxisOfRotMat, make_rmat_euler, angles_from_rmat_zxz, rotMatOfExpMap
1818
)
1919

2020
import hexrdgui.resources.calibration
@@ -39,6 +39,65 @@
3939
from hexrdgui.utils.dialog import add_help_url
4040

4141

42+
class AtlasConfig:
43+
def __init__(self, atlas_coords, instr):
44+
self.coords = atlas_coords
45+
self.instr = instr
46+
47+
def _get_orientation(self, crds, det):
48+
"""vertex in 4x3 matrix of the
49+
4 vertices. we return the normal
50+
using a cross product
51+
"""
52+
vertex = self._get_vertices(crds)
53+
if det == 'CAMERA-05':
54+
xhat = -vertex[1, :] + vertex[0, :]
55+
yhat = vertex[3, :] - vertex[0, :]
56+
else:
57+
xhat = vertex[3, :] - vertex[0, :]
58+
yhat = vertex[1, :] - vertex[0, :]
59+
60+
xhat = xhat/np.linalg.norm(xhat)
61+
yhat = yhat/np.linalg.norm(yhat)
62+
63+
zhat = np.cross(xhat, yhat)
64+
zhat = zhat/np.linalg.norm(zhat)
65+
66+
xhat = np.cross(yhat, zhat)
67+
xhat = xhat/np.linalg.norm(xhat)
68+
69+
rmat = np.vstack((-xhat, yhat, -zhat)).T
70+
71+
RMAT_Z_180 = rotMatOfExpMap(np.pi*zhat)
72+
if det in ['CAMERA-02', 'CAMERA-03']:
73+
return np.dot(RMAT_Z_180, rmat)
74+
return rmat
75+
76+
def _get_center(self, vertex):
77+
"""return center of detector given
78+
the four vertex
79+
"""
80+
return np.mean(vertex, axis=0)
81+
82+
def _get_vertices(self, crds):
83+
# by default we will look up from TCC, so there is
84+
# flip in the x-component sign
85+
return crds[0:4, :]
86+
87+
def update_instrument(self, detector):
88+
v = self._get_vertices(self.coords[detector])
89+
# tvec sample is the position of the sample in NIF
90+
# chamber coordinates. the position of each detector
91+
# is measured from this point, so we need to take this
92+
# off
93+
tvec_sample= np.array([0, 0, 9.8])
94+
tvec = self._get_center(v) - tvec_sample
95+
rmat = self._get_orientation(self.coords[detector], detector)
96+
ang, ax = angleAxisOfRotMat(rmat)
97+
self.instr.detectors[detector].tvec = tvec
98+
self.instr.detectors[detector].tilt = ang * ax
99+
100+
42101
class LLNLImportToolDialog(QObject):
43102

44103
# Emitted when new config is loaded
@@ -77,6 +136,7 @@ def __init__(self, cmap=None, parent=None):
77136
self.loaded_images = []
78137
self.canvas = parent.image_tab_widget.active_canvas
79138
self.detector_images = {}
139+
self.atlas_coords = None
80140

81141
# Disable these by default.
82142
# If we disable these in Qt Designer, there are some weird bugs
@@ -100,6 +160,8 @@ def __init__(self, cmap=None, parent=None):
100160
self.ui.detector_raw_image,
101161
self.ui.instr_settings_label,
102162
self.ui.instr_settings,
163+
self.ui.load_atlas,
164+
self.ui.atlas_label,
103165
visible=False)
104166

105167
self.update_config_settings()
@@ -138,6 +200,7 @@ def setup_connections(self):
138200
self.ui.dark_load.clicked.connect(self.load_detector_images)
139201
self.ui.accept_detector.clicked.connect(
140202
self.manually_load_detector_images)
203+
self.ui.load_atlas.clicked.connect(self.load_atlas_coords)
141204

142205
def enable_widgets(self, *widgets, enabled):
143206
for w in widgets:
@@ -264,6 +327,8 @@ def instrument_selected(self, idx):
264327
self.ui.detector_raw_image,
265328
self.ui.instr_settings_label,
266329
self.ui.instr_settings,
330+
self.ui.load_atlas,
331+
self.ui.atlas_label,
267332
visible=is_fiddle)
268333

269334
has_ip = self.ui.instr_settings.currentIndex() == 0
@@ -353,6 +418,16 @@ def update_config_settings(self):
353418
if prev:
354419
combo.setCurrentText(prev)
355420

421+
def load_atlas_coords(self):
422+
file, filter = QFileDialog.getOpenFileName(
423+
self.ui, 'Select coordinates file', dir=HexrdConfig().working_dir)
424+
if not file:
425+
return
426+
with open(file, 'r') as f:
427+
coords = yaml.safe_load(f)
428+
self.atlas_coords = {d: np.array(c) for d, c in coords.items()}
429+
self.ui.atlas_label.setText(Path(file).name)
430+
356431
def load_instrument_config(self):
357432
temp = tempfile.NamedTemporaryFile(delete=False, suffix='.hexrd')
358433
self.config_file = temp.name
@@ -814,6 +889,7 @@ def reset_panel(self):
814889
self.clear_boundry()
815890
# Reset internal state
816891
self.completed = []
892+
self.atlas_coords = None
817893
self.defaults.clear()
818894
self.config_file = None
819895
self.import_in_progress = False
@@ -832,6 +908,7 @@ def reset_panel(self):
832908
self.ui.config_file_label.setText('No File Selected')
833909
self.ui.config_file_label.setToolTip(
834910
'Defaults to currently loaded configuration')
911+
self.ui.atlas_label.setText('No File Selected')
835912
# Reset widget states - disable/enable/show/hide as appropriate
836913
self.enable_widgets(
837914
self.ui.image_plate_raw_image,
@@ -855,6 +932,8 @@ def reset_panel(self):
855932
self.ui.detector_raw_image,
856933
self.ui.instr_settings_label,
857934
self.ui.instr_settings,
935+
self.ui.load_atlas,
936+
self.ui.atlas_label,
858937
visible=False)
859938
# We're all reset and ready to re-enable the main UI features
860939
HexrdConfig().enable_image_mode_widget.emit(True)
@@ -872,6 +951,12 @@ def import_complete(self):
872951

873952
instr = HEDMInstrument(
874953
instrument_config=self.ip_and_det_defaults['default_config'])
954+
955+
if self.atlas_coords is not None:
956+
atlas_config = AtlasConfig(self.atlas_coords, instr)
957+
for detector in self.detectors:
958+
atlas_config.update_instrument(detector)
959+
875960
for det in self.completed:
876961
panel = instr.detectors[det]
877962
# first need the zxz Euler angles from the panel rotation matrix.

hexrdgui/resources/ui/llnl_import_tool_dialog.ui

Lines changed: 89 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>565</width>
10-
<height>854</height>
10+
<height>883</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -24,6 +24,94 @@
2424
<string>Instrument</string>
2525
</property>
2626
<layout class="QGridLayout" name="gridLayout_7">
27+
<item row="1" column="0">
28+
<widget class="QFrame" name="config">
29+
<property name="enabled">
30+
<bool>true</bool>
31+
</property>
32+
<property name="frameShape">
33+
<enum>QFrame::NoFrame</enum>
34+
</property>
35+
<property name="frameShadow">
36+
<enum>QFrame::Raised</enum>
37+
</property>
38+
<layout class="QGridLayout" name="gridLayout_3">
39+
<item row="0" column="0">
40+
<widget class="QLabel" name="label">
41+
<property name="text">
42+
<string>Select Configuration</string>
43+
</property>
44+
</widget>
45+
</item>
46+
<item row="1" column="1" colspan="2">
47+
<widget class="QComboBox" name="config_settings"/>
48+
</item>
49+
<item row="3" column="0">
50+
<widget class="QPushButton" name="load_atlas">
51+
<property name="text">
52+
<string>Load ATLAS Coordinates</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item row="0" column="1" colspan="2">
57+
<widget class="QComboBox" name="config_selection">
58+
<item>
59+
<property name="text">
60+
<string>Default configuration</string>
61+
</property>
62+
</item>
63+
<item>
64+
<property name="text">
65+
<string>Currently loaded configuration</string>
66+
</property>
67+
</item>
68+
<item>
69+
<property name="text">
70+
<string>Load configuration from file</string>
71+
</property>
72+
</item>
73+
</widget>
74+
</item>
75+
<item row="2" column="0">
76+
<widget class="QPushButton" name="load_config">
77+
<property name="enabled">
78+
<bool>false</bool>
79+
</property>
80+
<property name="text">
81+
<string>Load Instrument Config</string>
82+
</property>
83+
</widget>
84+
</item>
85+
<item row="1" column="0">
86+
<widget class="QLabel" name="config_settings_label">
87+
<property name="text">
88+
<string>Configuration Settings:</string>
89+
</property>
90+
</widget>
91+
</item>
92+
<item row="2" column="1" colspan="2">
93+
<widget class="QLabel" name="config_file_label">
94+
<property name="enabled">
95+
<bool>false</bool>
96+
</property>
97+
<property name="toolTip">
98+
<string extracomment="Defaults to currently loaded configuration"/>
99+
</property>
100+
<property name="text">
101+
<string>No File Selected</string>
102+
</property>
103+
</widget>
104+
</item>
105+
<item row="3" column="1" colspan="2">
106+
<widget class="QLabel" name="atlas_label">
107+
<property name="text">
108+
<string>No File Selected</string>
109+
</property>
110+
</widget>
111+
</item>
112+
</layout>
113+
</widget>
114+
</item>
27115
<item row="0" column="0">
28116
<widget class="QFrame" name="instrument">
29117
<property name="enabled">
@@ -112,80 +200,6 @@
112200
</layout>
113201
</widget>
114202
</item>
115-
<item row="1" column="0">
116-
<widget class="QFrame" name="config">
117-
<property name="enabled">
118-
<bool>true</bool>
119-
</property>
120-
<property name="frameShape">
121-
<enum>QFrame::NoFrame</enum>
122-
</property>
123-
<property name="frameShadow">
124-
<enum>QFrame::Raised</enum>
125-
</property>
126-
<layout class="QGridLayout" name="gridLayout_3">
127-
<item row="0" column="1" colspan="2">
128-
<widget class="QComboBox" name="config_selection">
129-
<item>
130-
<property name="text">
131-
<string>Default configuration</string>
132-
</property>
133-
</item>
134-
<item>
135-
<property name="text">
136-
<string>Currently loaded configuration</string>
137-
</property>
138-
</item>
139-
<item>
140-
<property name="text">
141-
<string>Load configuration from file</string>
142-
</property>
143-
</item>
144-
</widget>
145-
</item>
146-
<item row="2" column="0">
147-
<widget class="QPushButton" name="load_config">
148-
<property name="enabled">
149-
<bool>false</bool>
150-
</property>
151-
<property name="text">
152-
<string>Load Instrument Config</string>
153-
</property>
154-
</widget>
155-
</item>
156-
<item row="0" column="0">
157-
<widget class="QLabel" name="label">
158-
<property name="text">
159-
<string>Select Configuration</string>
160-
</property>
161-
</widget>
162-
</item>
163-
<item row="2" column="1" colspan="2">
164-
<widget class="QLabel" name="config_file_label">
165-
<property name="enabled">
166-
<bool>false</bool>
167-
</property>
168-
<property name="toolTip">
169-
<string extracomment="Defaults to currently loaded configuration"/>
170-
</property>
171-
<property name="text">
172-
<string>No File Selected</string>
173-
</property>
174-
</widget>
175-
</item>
176-
<item row="1" column="0">
177-
<widget class="QLabel" name="config_settings_label">
178-
<property name="text">
179-
<string>Configuration Settings:</string>
180-
</property>
181-
</widget>
182-
</item>
183-
<item row="1" column="1" colspan="2">
184-
<widget class="QComboBox" name="config_settings"/>
185-
</item>
186-
</layout>
187-
</widget>
188-
</item>
189203
</layout>
190204
</widget>
191205
</item>

0 commit comments

Comments
 (0)