Files and Functions - radiantlab/HDRICalibrationTool GitHub Wiki

Notes on some files used to implement the application and their functions.


src/progress_window.py

This is the class object that is created when the pipeline has enough info to send to Radiance, and is created when the MainWindow "GO" button is clicked. It creates a RadianceData object (see Radiance Pipeline submodule in Wiki sidebar) and fills it with the user input. It opens a window to show the progress of the process, and updates it over time.

init( MainWindow )

This function creates the widgets and sets their styling and properties. It then calls the startRadiancePipeline() function. It creates a QTimer that calls the updateProgress() function every 1 second.

cancelPipeline()

This event function is called when the cancelButton is clicked. It sets the button text to "Cancelling..." to imply that the cancellation of the active pipeline may not be instantaneous, as the current step must finish first. The cancellation gets "queued" after the current pipeline step. It calls the cancel_pipeline() function in radiance_pipeline.py and sets the statusLabel text.

updateProgress()

This function is called from a QTimer every 1 second, and updates the progressBar value, which it retrieves from the radiance_pipeline thread. When the progress reaches 100, or the pipeline gets cancelled, it stops the QTimer which calls update(), and sets the proper styling.

startRadiancePipeline( MainWindow )

This function creates a RadianceData class object and fills all the apprpriate attributes given the user-uploaded input. It starts a Thread to begin the Radiance pipeline.

closeWindow()

This function closes the ProgressWindow window.

setWidgetProperties()

This function calls the setWidgetVisibility(), setWidgetStates(), and setWidgetStyling() functions to set the region's widget properties.

setWidgetVisibility()

Logic to set the visibilty of object widgets based on flag values.

setWidgetStates()

Sets the enabled states of the widgets.

setWidgetStyle()

Uses the setProperty function to set attributes on region widgets based on flags, then applies styling based on the src/styles/progress_window_styles.css stylesheet.


User Interface Files

src/user_interface/upload_file_region.py

This is a class for a creating region to insert into the application that has the ability to upload a single file to via drag and drop or a click-to-browse button.

It contains functions to perform simple validation on the uploaded file, based on the 4 types of calibration files (vignetting, fisheye correction, calibration factor, ND filter) and the camera response function. These parse the uploaded file and depending on the type of file it is expecting, will set a flag 'fileIsValid', which can be accessed from the main window object for further validation logic.

The class stores the file path of the uploaded file into the filePathLabel attribute, and sets the object's appropriate file path property in the main window through the validateFile() function.

init( regionName, regionSize, fileType )

  • regionSize expects a numeric list in the format [regionWidth, regionHeight]
    • default size is 128x128
  • fileType expects a single integer to denote the type of file, which determines what basic validation will be used on the uploaded file:
    • fileType = 0 : Any file type (default)
    • fileType = 1 : .cal
    • fileType = 2 : .rsp

This function defines the widgets and sets file QPixmaps, and sets default flag values. The create() funcion is then called.

create()

This function uses the setObjectName function to apply names to the widgets. It also applies the specifed region size to the layout, passed in from init. Button and checkbox click events are connected here. Checkbox label text is set here based on the upload refion file type define in init. The function then sets the widget properties and initializes the layout.

initRegionLayout()

This function sets up the layout of the region object.

dragEnterEvent( event )

This is the drag event for when an entity is dragged over the region. It only accepts the drag event if:

  • There is not already a file uploaded, determined by the 'hasFile' flag
  • There are multiple files being drug into the region (1 max for the upload_file_region object)
  • The file type is not in the following list:
    • .txt
    • .cal
    • .rsp

dropEvent( event )

This function occurs when a drug file that is accepted is dropped onto the region, after a mouse release event. It retrieves the filepath for the file and sets the filePathLabel attribute of the upload_file_region object.

removeButtonClicked()

This event function happens when the 'Remove' button is clicked, which appears on the upload_file_region object when there is an uploaded file. It resets the widget's properties to the default, empty state.

swapRegionInUse()

This checkbox click event function swaps the state of the upload_file_region object. This is for the functionality of "opting-out" of including a specific file from the overall pipeline process (e.g. a user does not have a vignetting correction calibration file). The function will set the 'isEnabled' flag on the upload_file_region object, and based on that flag value, updates the styling. It resets the filePathLabel attribute to empty string "" when it is re-enabled.

resetWidgetProperties()

This function resets the object flags, clears label text to empty string"", and calls the setWidgetProperties() function to help change styling based on the new flag values.

getFileNameFromPath( path )

This function parses the filename path and extracts just the filename and type, used for displaying the file name to the user after they upload a file.

browseFiles()

This function opens the file dialog box so the user can select 1, multiple, or no files to upload. This is the event function for the region's browse button. It has logic to handle accepting file types of the specified region file type.

fileUploadedEvent()

This event function occurs when a file is uploaded. It will validate the file by calling validateFile(), and then set the widget properties so the styling reflects the change.

setWidgetVisibility()

Logic to set the visibilty of object widgets based on flag values.

setWidgetStyle()

Uses the setProperty function to set attributes on region widgets based on flags, then applies styling based on the src/styles/upload_file_region_styles.css stylesheet.

setWidgetStates()

Sets the enabled property of region widgets based on the isEnabled flag. Also sets the setAcceptDrops property.

setWidgetProperties()

This function calls the setWidgetVisibility(), setWidgetStates(), and setWidgetStyling() functions to set the region's widget properties.

getFileType()

This function returns the type of file the region is used for as a string. Does NOT return the file extension (.cal, .rsp, .txt, etc.).

For example, for a file region used for uploading a vignetting calibration file, it will return "Vignetting".

validateFile()

This function performs basic validation on the uploaded file. Based on the object name used to denote the tyoe of file the region is for, it calls the appropriate file validation function. If it returns true, the MainWindow object's Radiance data variables are filled with the appropriate filePath attribute.

vc_validation()

The function to validate vignetting correction files. Parses and checks if the following variables are defined:

  • r
  • sf
  • ro
  • go
  • bo

Returns a boolean value if all of these exist or not. Formatting should not matter, as all whitespace is removed before checking.

fc_validation()

The function to validate fisheye correction files. Parses and checks if the following variables are defined:

  • map_inverse
  • inp_r
  • mapped_r
  • rmult
  • xoff
  • yoff
  • ro
  • go
  • bo
  • rad(r)

Returns a boolean value if all of these exist or not. Formatting should not matter, as all whitespace is removed before checking.

cf_validation()

The function to validate calibration factor files. Parses and checks if the following variables are defined:

  • ro
  • go
  • bo

Returns a boolean value if all of these exist or not. Formatting should not matter, as all whitespace is removed before checking.

nd_validation()

The function to validate Neutral Density (ND) filter files. Parses and checks if the following variables are defined:

  • ro
  • go
  • bo

Returns a boolean value if all of these exist or not. Formatting should not matter, as all whitespace is removed before checking.

rsp_validation()

The function to validate response function files. Parses and checks if the formatting matches the following:

  • A function definition per R,G,B value, where the function is defined below

  • Starts with a single integer 'n', whose value represents the order of the response function

  • n + 1 numeric values, representing the factor of each term in the function, decreasing

    • Example: Input file:

      4 2.48363666666666 -2.57911666666665 1.00832766666665 0.0852399666666787 0.00191103299999811

      4 2.60823999999999 -2.7528533333333 1.0657643333333 0.0769006000000161 0.0019504099999977

      4 3.17448333333332 -3.61331666666663 1.40380333333329 0.0321496266666864 0.00287970333333048

    This first line translates to the function: Red f(x)= 2.48x^4 - 2.57x^3 + 1x^2 + 0.08x^1 + 0x^0

formatRspAsFunction( tokenizedList)

Not actually called by the app. Performs the function translation like in the rsp_validation() example above: ingests the passed-in tokenized list, returns the result formatted.

clearMainWindowObjFilePath()

Checks which fileType the region is using getFileType(), and clears the correct MainWindow object path to empty string "".

For example, in the case the upload region is for uploading a Vignetting calibration file, the 'path_vignetting' attribute in ui_main.py class object will be cleared to "".


src/user_interface/upload_image_region.py

This is a class for a creating region to insert into the application that has the ability to upload images to via drag and drop or a click to browse button.

It is similar to the upload_file_region.py class, except that it stores a list of file paths to the various images that are uploaded instead of 1. The control for removing files from the list is handled in image_preview.py. The display of the image previews is handled by image_uploader.py.

The class stores the file paths of the uploaded file into the filePathLabel attribute, and sets the object's appropriate file path property in the main window through the validateFile() function.

init( regionName, regionSize )

  • regionSize expects a numeric list in the format [regionWidth, regionHeight]
    • default size is 128x128

This function defines the widgets and sets file QPixmaps, and sets default flag values. The create() funcion is then called.

create()

This function uses the setObjectName function to apply names to the widgets. It also applies the specifed region size to the layout, passed in from init. Button click events are connected here. The function then sets the widget properties and initializes the layout.

initRegionLayout()

This function sets up the layout of the region object.

dragEnterEvent( event )

This is the drag event for when an entity is dragged over the region.

dropEvent( event )

This function occurs when a drug file that is accepted is dropped onto the region, after a mouse release event. It retrieves the filepath for each image and calls the fileUploadedEvent() function. It handles single or multiple images being uploaded at once.

getFileNameFromPath( path )

This function parses the filename path and extracts just the filename and type, used for displaying the file name to the user after they upload a file.

browseFiles()

This function opens the file dialog box so the user can select 1, multiple, or no images to upload. This is the event function for the region's browse button.

fileUploadedEvent()

This event function is for when an image(s) is uploaded. It appends the image file path to the list of uplaoded images in 'imagePaths' attribute. It then calls addImageToList( filename ) to add a visual preview to the image_uploader class object region.

setWidgetVisibility()

Logic to set the visibilty of object widgets based on flag values.

setWidgetStyle()

Uses the setProperty function to set attributes on region widgets based on flags, then applies styling based on the src/styles/upload_image_region_styles.css stylesheet.

setWidgetStates()

Sets the enabled property of region widgets based on the isEnabled flag. Also sets the setAcceptDrops property.

setWidgetProperties()

This function calls the setWidgetVisibility(), setWidgetStates(), and setWidgetStyling() functions to set the region's widget properties.


src/user_interface/image_uploader.py

This class helps display the images in the list stored in the upload_image_region class object in a QScrollArea widget. It displays objects of image_preview.py class objects, which have the control for removing an image from the list.

init()

This function defines the widgets and sets up the QScrollArea widget. It updates its total image count. Initializes the imagePaths list.

addImageToList( imagePath )

This function creates an ImagePreview class object and adds it to the list. Updates the total image count, and updates the Radiance object paths attribute with updatePathsLDR().

updateTotalImagesCount()

This function retrives the number of images uploaded, and sets the toatl image count label.

getTotalImageCount()

This function counts how many images are uploaded.

updatePathsLDR()

This function updates the Radiance object 'paths_ldr' attribute. It sets that attribute to this class object's imagePaths list.


src/user_interface/image_preview.py

This class is to create a visual preview of an uploaded image, and give it a remove button to remove itself from the uploaded list.

init()

This function defines the widgets and sets up the QPixmaps, buttons, and labels.

removeSelf()

This event function is for when the object's 'remove' button is clicked. It removes itself from the ImageUploader class object's imagePaths list, and then deletes itself from the layout.

setWidgetStyle()

This function applies styling based on the src/styles/image_preview_styles.css stylesheet.


src/user_interface/ui_main.py

This class is the primary interface for the directory.

setupUi()

This function creates the mainwindow, loads the parameters from the cache, sets the stylesheets, routes the buttons, creates the frame, and then sets up each page.

retranslateUi()

This function sets the text for the buttons and labels of the UI.

setActivePage()

Upon activation, changes the page to whichever was input. Used as a click event function.

setButtonStyling()

Sets the stylesheet for each button in the sidebar.

setCroppingValues()

Takes the input field for diameter and crop dimensions and puts them into the parameter values that we will pass to the radiance application when Go is pressed.

setLensValues()

Takes the input field for view angles and puts them into the parameter values that we will pass to the radiance application when Go is pressed.

setOutputDimensionValues()

Takes the output X res and Y res from the input fields and puts them into the parameter values that we will pass to the radiance application when Go is pressed.

goButtonClicked()

Event function to verify that all the files are right, cache them, and create a progress window to call radiance pipeline

openProgressWindow()

Opens progress window.

ingestCameraSettingsFormData()

Calls the above setCroppingValues, setLensValues, and setOutputDimensionValues functions

validateImages()

Checks that the image count is correct

validateCameraSettings()

Checks for empty or missing files, sets error messages if they are invalid.

validateCalibration()

Checks for missing, invalid, or empty files and sets error messages if any are invalid.

goButtonErrorDialogOpen()

Blocks the go button and displays a message with all the errors.

recoverCache()

Loads the cache.json file into the parameters that will be input into the radiance application.

saveCache()

Generates a cache file by saving the current parameters.

openWikiInBrowser()

Tries to open the wiki when the help button is pressed.