| Customize Help

Working with files

MIL provides several useful functions for working with files. Using MIL functions, you can import and export images, 3D data, and MIL contexts in various formats. You can also move. copy, delete, and search for files on the local computer in an operating-system independent way, and host files on the local computer using HTTP so that they can be accessed by a web browser on a remote computer. In a DMIL application, you can also share files (including DLLs) between computers, and execute programs on a remote computer.

Moving, sharing, and searching for files

You can move, copy, delete, and search for files using MappFileOperation(). This function is supported for both Windows and Linux, increasing the portability of your MIL application. You can also use this function to execute a program on the local computer.

MappFileOperation() is particularly useful to manage the files used by a simulated digitizer (which grabs images from a specified folder instead of a camera). You can use this function to confirm which files are present in the images folder, and to add or remove images at runtime. For more information about simulated digitizers, see the Simulated digitizer section of Chapter 25: Grabbing with your digitizer.

A local computer on the network can host files using a MIL HTTP server, allocated using MobjAlloc() with M_HTTP_SERVER. Hosted files can then be accessed in a web browser by remote computers and other devices (such as smart phones and tablets). For more information, see the Hosting files on a MIL HTTP server section of Chapter 49: Hosting files on a MIL HTTP server.

Additional functionality for DMIL

When developing a distributed application using DMIL, you might need to share files between computers. You can specify an application context on a remote computer as a source or destination for MappFileOperation(); this allows you to easily transfer files between MIL applications with a single function call. This function is particularly useful for copying custom MIL functions created using the Function Development module (Mfunc...()). For example, you can use MappFileOperation() with M_FILE_EXISTS_MIL_USER_DLL to confirm whether a remote computer has a required user DLL, and if not, you can copy that DLL to the remote computer using M_FILE_COPY_MIL_USER_DLL.

You can also use MappFileOperation() to execute a program on the remote computer.

The capability to execute programs on a remote computer has security implications. You are responsible for ensuring that the program executed by the remote DMIL application is in fact the program that you requested. MappFileOperation() cannot execute a program on a remote computer unless that computer is running a connected DMIL application.

Importing and exporting data

You can save and load most types of MIL objects to a file, using a function from the module that you used to allocate the object. For example, you can allocate a blob context using MblobAlloc(), save it using MblobSave(), and restore it using MblobRestore(). You can also save or restore the blob context to or from a memory stream using MblobStream().

You can save and load image buffers and 3D-processable containers to and from standard file formats that are supported by a wide variety of applications (for example, PNG and BMP files for images and PLY or STL files for 3D data). You can also save a buffer or container with all of its attributes and settings, using the MIL native file format. For more information about saving and loading buffers, see the Loading a data buffer subsection of the Managing data buffers section of Chapter 21: Data buffers. Most of the information in that section also applies to 3D-processable containers.

Typically, when saving and loading files with MIL, you should use the file extensions listed in the MIL file extension list section later in this chapter.