Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone SpatialOrientation #44

Merged
merged 36 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ce8aa59
Remove spatial orientation data from DisplayShape
braden6521 Mar 20, 2024
ed615a8
Updated DisplayShape and SpatialOrientation io
braden6521 Mar 20, 2024
870766e
B
braden6521 Mar 20, 2024
058a260
Updating test_integration_undefined
braden6521 Mar 20, 2024
d8a1638
Updated calibrate screen shape example
braden6521 Mar 20, 2024
ac86782
Added saving io tests to DisplayShape
braden6521 Mar 21, 2024
d882d75
Updated CalibrateDisplayShape to return DisplayShape object directly and
braden6521 Mar 21, 2024
94348f4
Updated documentation in example-calibration-camera-pose
braden6521 Mar 21, 2024
1412cec
Deleted example-calibration-save-DisplayShape-file
braden6521 Mar 21, 2024
9f76a59
Deleted save_DisplayShape file
braden6521 Mar 21, 2024
b95fcdf
Updated test_CalibrateDisplayShape unit test
braden6521 Mar 21, 2024
7b217ce
Added IO test to calibrate display shape unit test
braden6521 Mar 21, 2024
48fed69
Updated HDF5 test data files to contain SpatialOrientation.
braden6521 Mar 21, 2024
d4cee69
Fixed test spatial orientation
braden6521 Mar 21, 2024
c92d96e
Updated test integration single facet
braden6521 Mar 21, 2024
efd2a6a
Updated test integration multifacet and assiciated data file
braden6521 Mar 21, 2024
ba17214
Updated test-spatial-processing and test-slopeSolver to use SpatialOr…
braden6521 Mar 21, 2024
e517170
Renamed sofast fringe example to spatial-orientation
braden6521 Mar 21, 2024
088caed
Added HDF5 IO Abstract class inheritance to SpatialOrientation
braden6521 Mar 21, 2024
645b5a7
Edited spatial orientation HDF IO.
braden6521 Mar 21, 2024
189abe9
Updated SO unit test
braden6521 Mar 21, 2024
5a446da
Updated unit test data
braden6521 Mar 21, 2024
16efbfb
Added the creation of save directories if needed in unit tests
braden6521 Mar 21, 2024
7856e29
Fixed unit tests, made save dirs when necessary, sorted glob lists.
braden6521 Mar 21, 2024
7389f32
Sorted all glob lists
braden6521 Mar 21, 2024
ea3da16
Formatted four files to be Black compliant.
braden6521 Mar 25, 2024
b248c0a
Added/removed sofast doc files to pass doc checks.
braden6521 Mar 25, 2024
e9fe47c
Updated CalibrateDisplayShape documentation.
braden6521 Mar 25, 2024
3c308a5
Changed as ht to as h5 in imports.
braden6521 Mar 25, 2024
c7a3cbd
Modified unit test functionalities.
braden6521 Mar 25, 2024
4fe084c
Updates to be black compliant.
braden6521 Mar 25, 2024
e724825
Added optic_oriented to spatial_orientation unit test data.
braden6521 Mar 29, 2024
cd8dbb3
Changed hf to h5 in test_ProcessSofastFixed
braden6521 Mar 29, 2024
f11738c
Changed how spatial orientation is saved in calculation data classes.
braden6521 Mar 29, 2024
358ed5a
Removed unnecessary save_data_as_hdf method from CalibrateDisplayShape
braden6521 Mar 29, 2024
de95ab2
Updated sofastFringe examples to use Spatial Orientation object.
braden6521 Mar 29, 2024
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
8 changes: 8 additions & 0 deletions doc/source/example/camera_calibration/config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
View Camera Distortion
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to learn what these .rst files do at some point.

======================

.. currentmodule:: example.camera_calibration.example_view_camera_distortion

.. automodule:: example.camera_calibration.example_view_camera_distortion
:members:
:show-inheritance:
11 changes: 11 additions & 0 deletions doc/source/example/camera_calibration/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Camera Calibration
==================

These are example files that provide examples on how to use OpenCSP for camera lens calibration.



.. toctree::
:maxdepth: 1

config.rst
1 change: 1 addition & 0 deletions doc/source/example/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This section describes the OpenCSP examples.
.. toctree::
:maxdepth: 1

camera_calibration/index.rst
csp/index.rst
mirror/index.rst
scene_reconstruction/index.rst
Expand Down
8 changes: 0 additions & 8 deletions doc/source/example/sofast/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ Undefined Facet Data Process
:members:
:show-inheritance:

View Camera Distortion
======================

.. currentmodule:: example.sofast_fringe.example_calibration_camera_pose

.. automodule:: example.sofast_fringe.example_calibration_camera_pose
:members:
:show-inheritance:
6 changes: 3 additions & 3 deletions doc/source/example/sofast/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SoFast
======
SOFAST Fringe
=============

These are example files that provide examples on how to use Sofast to collect data and process already collected data.
These are example files that provide examples on how to use Sofast Fringe to process collected data and perform system calibrations.



Expand Down
19 changes: 0 additions & 19 deletions doc/source/library_reference/app/sofast/calibration/config.rst

This file was deleted.

10 changes: 0 additions & 10 deletions doc/source/library_reference/app/sofast/calibration/index.rst

This file was deleted.

12 changes: 11 additions & 1 deletion doc/source/library_reference/app/sofast/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ opencsp.app.sofast.SofastGUI
.. automodule:: opencsp.app.sofast.SofastGUI
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:

opencsp.app.sofast.lib.CalibrateDisplayShape
=============================================================

.. currentmodule:: opencsp.app.sofast.lib.CalibrateDisplayShape

.. automodule:: opencsp.app.sofast.lib.CalibrateDisplayShape
:members:
:undoc-members:
:show-inheritance:
3 changes: 1 addition & 2 deletions doc/source/library_reference/app/sofast/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sofast
SOFAST
======

High-precision deflectometry measurement of CSP mirrors, including heliostat facets, full heliostats, and dishes.
Expand All @@ -7,4 +7,3 @@ High-precision deflectometry measurement of CSP mirrors, including heliostat fac
:maxdepth: 1

config.rst
calibration/index.rst
4 changes: 2 additions & 2 deletions example/camera_calibration/example_view_camera_distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from opencsp.common.lib.opencsp_path.opencsp_root_path import opencsp_code_dir


def example_driver():
def example_show_camera_distortion():
"""Example SOFAST script
Plots visualization of camera distortion given a saved Camera HDF file
Expand Down Expand Up @@ -38,4 +38,4 @@ def example_driver():


if __name__ == '__main__':
example_driver()
example_show_camera_distortion()

This file was deleted.

13 changes: 10 additions & 3 deletions example/sofast_fringe/example_calibration_screen_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@


def run_screen_shape_calibration(save_dir):
"""Runs screen shape calibration. Saves data to ./data/output/screen_shape"""
"""Runs screen shape calibration. Saves a DisplayShape HDF5 file
to ./data/output/screen_shape/display_shape.h5
"""
# Load output data from Scene Reconstruction (Aruco marker xyz points)
file_pts_data = join(
opencsp_code_dir(), 'common/lib/deflectometry/test/data/data_measurement', 'point_locations.csv'
Expand Down Expand Up @@ -56,8 +58,13 @@ def run_screen_shape_calibration(save_dir):
cal.make_figures = True
cal.run_calibration()

# Save screen shape data as HDF5 file
cal.save_data_as_hdf(join(save_dir, 'screen_distortion_data.h5'))
# Get screen shape data
display_shape = cal.as_DisplayShape('Example display shape')

# Save DisplayShape file
file = join(save_dir, 'display_shape.h5')
display_shape.save_to_hdf(file)
lt.info(f'Saved DisplayShape file to {file:s}')

# Save calibration figures
for fig in cal.figures:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from os.path import join, dirname

import numpy as np
from scipy.spatial.transform import Rotation

from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.common.lib.deflectometry.CalibrationCameraPosition import CalibrationCameraPosition
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.geometry.Vxyz import Vxyz
Expand All @@ -13,8 +15,8 @@

def run_camera_position_calibration(save_dir):
"""Calibrates the position of the Sofast camera. Saves the rvec/tvec that
define the relative pose of the camera/screen to a CSV file located
at ./data/output/camera_rvec_tvec.csv
define the relative pose of the camera/screen in a SpatialOrientation file
at ./data/output/spatial_orientation.h5
"""
# Define directory where screen shape calibration data is saved
base_dir_sofast_cal = join(opencsp_code_dir(), 'common/lib/deflectometry/test/data/data_measurement')
Expand All @@ -38,14 +40,26 @@ def run_camera_position_calibration(save_dir):
cal.make_figures = True
cal.run_calibration()

# Get orientation
r_screen_cam, v_cam_screen_screen = cal.get_data()
r_screen_cam = Rotation.from_rotvec(r_screen_cam)
v_cam_screen_screen = Vxyz(v_cam_screen_screen)

r_cam_screen = r_screen_cam.inv()
v_cam_screen_cam = v_cam_screen_screen.rotate(r_screen_cam)

# Create spatial orientation object
orientation = SpatialOrientation(r_cam_screen, v_cam_screen_cam)

# Save data
orientation.save_to_hdf(join(save_dir, 'spatial_orientation.h5'))

# Save figures
for fig in cal.figures:
file = join(save_dir, fig.get_label() + '.png')
lt.info(f'Saving figure to: {file:s}')
fig.savefig(file)

# Save data
cal.save_data_as_csv(join(save_dir, 'camera_rvec_tvec.csv'))


def example_driver():
# Define save dir
Expand Down
13 changes: 3 additions & 10 deletions example/sofast_fringe/example_process_facet_ensemble.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from os.path import join, dirname

import matplotlib

from opencsp.app.sofast.lib.DisplayShape import DisplayShape as Display
from opencsp.app.sofast.lib.DefinitionEnsemble import DefinitionEnsemble
from opencsp.app.sofast.lib.DefinitionFacet import DefinitionFacet
from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling
from opencsp.app.sofast.lib.MeasurementSofastFringe import MeasurementSofastFringe
from opencsp.app.sofast.lib.ProcessSofastFringe import ProcessSofastFringe as Sofast
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.app.sofast.lib.visualize_setup import visualize_setup
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.csp.FacetEnsemble import FacetEnsemble
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
Expand Down Expand Up @@ -39,13 +36,15 @@ def example(dir_save: str):
file_measurement = join(sample_data_dir, 'measurement_ensemble.h5')
file_camera = join(sample_data_dir, 'camera.h5')
file_display = join(sample_data_dir, 'display_distorted_2d.h5')
file_orientation = join(sample_data_dir, 'spatial_orientation.h5')
file_calibration = join(sample_data_dir, 'image_calibration.h5')
file_facet = join(sample_data_dir, 'Facet_lab_6x4.json')
file_ensemble = join(sample_data_dir, 'Ensemble_lab_6x4.json')

# Load data
camera = Camera.load_from_hdf(file_camera)
display = Display.load_from_hdf(file_display)
orientation = SpatialOrientation.load_from_hdf(file_orientation)
measurement = MeasurementSofastFringe.load_from_hdf(file_measurement)
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)
ensemble_data = DefinitionEnsemble.load_from_json(file_ensemble)
Expand All @@ -62,7 +61,7 @@ def example(dir_save: str):
measurement.calibrate_fringe_images(calibration)

# Instantiate sofast object
sofast = Sofast(measurement, camera, display)
sofast = Sofast(measurement, orientation, camera, display)

# Update search parameters
sofast.params.mask_hist_thresh = 0.83
Expand All @@ -88,12 +87,6 @@ def example(dir_save: str):
mirror_control = rcm.RenderControlMirror(centroid=True, surface_normals=True, norm_res=1)
axis_control_m = rca.meters()

# Visualize setup
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='')
spatial_ori: SpatialOrientation = sofast.data_geometry_facet[0].spatial_orientation
visualize_setup(display, camera, spatial_ori.v_screen_optic_screen, spatial_ori.r_optic_screen, ax=fig_record.axis)
fig_record.save(dir_save, 'physical_setup_layout', 'png')

# Plot scenario
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='Facet Ensemble')
ensemble.draw(fig_record.view, mirror_control)
Expand Down
13 changes: 3 additions & 10 deletions example/sofast_fringe/example_process_single_facet.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from os.path import join, dirname

import matplotlib

from opencsp.app.sofast.lib.DisplayShape import DisplayShape as Display
from opencsp.app.sofast.lib.DefinitionFacet import DefinitionFacet
from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling
from opencsp.app.sofast.lib.MeasurementSofastFringe import MeasurementSofastFringe
from opencsp.app.sofast.lib.ProcessSofastFringe import ProcessSofastFringe as Sofast
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.app.sofast.lib.visualize_setup import visualize_setup
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.csp.Facet import Facet
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
Expand Down Expand Up @@ -36,12 +33,14 @@ def example(dir_save: str):
file_measurement = join(sample_data_dir, 'measurement_facet.h5')
file_camera = join(sample_data_dir, 'camera.h5')
file_display = join(sample_data_dir, 'display_distorted_2d.h5')
file_orientation = join(sample_data_dir, 'spatial_orientation.h5')
file_calibration = join(sample_data_dir, 'image_calibration.h5')
file_facet = join(sample_data_dir, 'Facet_NSTTF.json')

# Load data
camera = Camera.load_from_hdf(file_camera)
display = Display.load_from_hdf(file_display)
orientation = SpatialOrientation.load_from_hdf(file_orientation)
measurement = MeasurementSofastFringe.load_from_hdf(file_measurement)
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)
facet_data = DefinitionFacet.load_from_json(file_facet)
Expand All @@ -53,7 +52,7 @@ def example(dir_save: str):
measurement.calibrate_fringe_images(calibration)

# Instantiate sofast object
sofast = Sofast(measurement, camera, display)
sofast = Sofast(measurement, orientation, camera, display)

# Process
sofast.process_optic_singlefacet(facet_data, surface)
Expand All @@ -70,12 +69,6 @@ def example(dir_save: str):
figure_control = rcfg.RenderControlFigure(tile_array=(1, 1), tile_square=True)
axis_control_m = rca.meters()

# Visualize setup
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='')
spatial_ori: SpatialOrientation = sofast.data_geometry_facet[0].spatial_orientation
visualize_setup(display, camera, spatial_ori.v_screen_optic_screen, spatial_ori.r_optic_screen, ax=fig_record.axis)
fig_record.save(dir_save, 'physical_setup_layout', 'png')

# Plot slope map
fig_record = fm.setup_figure(figure_control, axis_control_m, title='')
facet.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
Expand Down
Loading