Assignment Goals

The primary goals of this assignment are:

  1. Create a UE Plugin from scratch.
  2. Create a UE object importer.
  3. Get experience looking through other plugin code and engine source as a strategy for working with a large codebase.

For this assignment, you'll be creating an importer plugin to load a UVolumeTexture object from a file. The importer will load files in a subset of the MetaIO MHA/MHD format, created for and used by the ITK image processing toolkit. This is a simple uncompressed format supporting both image and volume files. It consists of an ASCII text header describing the file contents, coupled with an uncompressed binary array of data, either embedded in the same file (typically given the mha extension) or in a separate file in the same directory (typically given the mhd extension). Though there is a convention that detached header files use .mhd, the format does not distinguish between the two extensions. Similarly, there is a convention to use .raw or .dat for the binary data, but it can legally use any extension or none at all.

Volume Texture Pane for bucky.mhd Volume Texture Pane 3D viewfor bucky.mhd

Details

This is the contents of the bucky.mhd file, with an explanation of each one.

ObjectType = Image Always the first line, identifies this as a valid image file
NDims = 3 3 for volume textures, 2 for images
DimSize = 32 32 32 Size of each dimension (read this from the file, do not hard code)
ElementNumberOfChannels = 1 Number of color channels, 1=Grey, 2=Grey/Alpha, 3=RGB, 4=RGBA
ElementType = MET_UCHAR Data type for each element, in this case, unsigned byte
ElementDataFile = bucky.raw Must be last: file name in the same directory to find the data

You are writing your own mha/mhd importer code for this assignment, not linking to the ITK library. Your importer only needs to support one channel volumes with unsigned byte components and the data in a separate file (like this one). You should ignore header lines that your importer does not support, but report errors for header lines you do support (so if Dims is anything but 3, or if any of the dimensions are zero or negative). Report errors using UE_LOG with a new log category (not just LogTemp) so they will show up in the editor Output window.

This assignment provides only rough pointers to where to find examples and class declarations you will need. Part of the assignment is for you to get more comfortable searching through the source to find things like this.

I have pushed a data directory to your github repository with the bucky ball files to use for testing. You can find more files in the Stanford Volume Data Archive, TU Vienna archive, and Volume Library. To use any of these files, you will need to download the raw file and create your own mhd header to go with it.

Create a project

  1. Create a Blank C++ project with no starter content called proj5.
    • As usual, put the project at the top level of your git repository

Create the plugin

  1. This time you will start from a Blank code plugin.
    1. Edit the uplugin file to change it from a "Runtime" to "Editor" plugin
    2. Add an asset load class derived from UFactory to your plugin.
      • Add this in a new header and C++, not in the same files as the IModuleInterface class
      • The easiest way to do this is using "New C++ Class ..." in the editor Tools menu, using the "All Classes" tab to find the entry for UFactory, and making sure it puts the files in your plugin (navigate to PluginName/Source/PluginName).
      • To avoid undefined symbol errors, add the module for UFactory to your plugin's Build.cs. Follow the directory tree from the UFactory file to find its Build.cs file and find the module name.
  2. Dummy loader
    1. Declare that you load mha and mhd files to return a UVolumeTexture
      • Look in the cpp files for examples using Formats.Add, and also how those functions set SupportedClass.
    2. Create a load function
      • FactoryCreateFile has the file name (with path) as a parameter, and leaves you responsible for opening and loading the file data. You can use the path from that filename parameter to find the associated data file in the same directory.
      • The default FactoryCreateFile from UFactory loads the data for you, then uses the value of bText set in the constructor to call either FactoryCreateText or FactoryCreateBinary. Inside one of those functions, you could use the CurrentFilename member variable to get the file path to find the associated data file. You will still have to open and read that data file yourself
    3. Create a volume object
      • Look for examples calling NewObject<UVolumeTexture>
    4. Test
      • At this point, you should be able to hit the "Import" button in the Content window, navigate to a folder containing an mhd file, select it (not greyed out), and get an empty volume texture object to confirm that your format registration code is correct.
      • Delete the old imported asset before trying to import again. Assuming you have not actually used it for anything (added it to any materials or as a property on another object), it is safe to "Force Delete" when removing the object.
  3. Load and parse the mhd header file
    • Look at FFileHelper for file loading functions.
    • Look at FString and FCString for simple string matching and string-to-integer conversion functions.
    • I recommend reading the file by lines. A few options for parsing the lines: you could split the line into key and value at the "=", split into tokens on whitespace, or even just use sscanf
    • If things go wrong, use UE_LOG to send a message to the Editor Output window and return nullptr.
  4. Load the data
    • FPaths has some helpful functions for splitting a file name into the path, base, and extension, and to combine paths together (using "/" or "\" as appropriate). Since the data file resides in the same directory as the header, you will need to combine the path for the nhdr file with the data file name to get the full file path to open to read the data.
    • Load the data into the UVolumeTexture
      • Call UTexture::PreEditChange (see the comment in the UTexture header).
      • Set UTexture::MipGenSettings to TextureMipGenSettings::TMGS_NoMipmaps to avoid generating multiple resolution versions of the volume data (which may fail).
      • Texture.Source.Init will initialize the size, format, and data. In that function, SizeX, SizeY, and NumSlices are the X, Y, and Z dimensions.
      • Call UTexture::PostEditChange to update the UVolumeTexture object with the loaded data

Grad Students

Support at least two additional MHA/MHD features:

Create test files for any features you add. If they are small (under 100 MB) you can commit them directly to your repository. Any larger sample files should be stored on google drive (or similar) with a link included in your proj5.txt file. The easiest way to create test files this is to write a simple standalone program to write them. You do not need to submit any data generation programs, just the resulting test data files.

Submission

As always, for full credit, you must commit multiple times during your development.

Add a proj5.txt. Tell us what works and what doesn't, and anything else you think we should know for grading. For grad students, tell us what extensions you did, and where to find the test files for any extensions.

For the base assignment, include two screen shots of the UE editor pane for your VolumeTexture object. One should be with "3D View" unchecked, and the other with "3D View" checked. Use the "Scale to Fill" option for the zoom to scale to fill the editor pane window. Adjust the "Opacity" setting for your 3D view so you can see into the 3D volume box.

If you did the FScopedSlowTask progress meter extension, record video of you importing your file(s) so we can see the progress meter in action. Upload the video to google drive, youtube, or similar, and include a link to it in your proj5.txt file.

If you did any other extensions, include screen shots showing the import results, with a clear description of what is shown in each image.

Push to your repository, and tag your final commit with an proj5 tag. Make sure the images and video links are included in the commit that you tag for us to grade.