Skip to content

Commit

Permalink
Merge pull request #44 from braden6521/spatial_orientation
Browse files Browse the repository at this point in the history
Implemented a standalone SpatialOrientation object in Sofast Fixed and Fringe.
  • Loading branch information
braden6521 authored Mar 29, 2024
2 parents 316c72a + de95ab2 commit fee821d
Show file tree
Hide file tree
Showing 45 changed files with 375 additions and 444 deletions.
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
======================

.. 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

0 comments on commit fee821d

Please sign in to comment.