neuray API Programmer's Manual

mi::neuraylib::IExport_api Class Reference

[Importer and Exporter]

Description

This interface is used to export files.

Export operations

virtual Sint32 export_bsdf_data( const char* uri, const IBsdf_isotropic_data* reflection, const IBsdf_isotropic_data* transmission) const =0
Exports BSDF data to a file on disk. More...
virtual Sint32 export_canvas( const char* uri, const ICanvas* canvas, Uint32 quality = 100) const =0
Exports a canvas to a file on disk. More...
virtual const IExport_resultexport_elements( ITransaction* transaction, const char* uri, const IArray* elements, const IMap* exporter_options = 0) const =0
Exports scene elements. More...
virtual const IExport_resultexport_elements_to_string( ITransaction* transaction, const IArray* elements, const char* file_extension, IString* result_string, const IMap* exporter_options = 0) const =0
Exports scene elements to string. More...
virtual const IExport_resultexport_scene( ITransaction* transaction, const char* uri, const char* rootgroup, const char* caminst = 0, const char* options = 0, const IMap* exporter_options = 0) const =0
Exports a scene. More...

Exporter introspection

virtual const IExporterget_exporter( Size index) const =0
Returns a registered exporter. More...
virtual Size get_exporter_length() const =0
Returns the number of registered exporters. More...
virtual IWriterget_writer( const char* uri) const =0
Returns a writer that can be used to export to the given resource. More...
virtual const IExporterselect_exporter_by_extension( const char* extension) const =0
Returns the exporter that would be used for a particular file name extension. More...

Utility methods

virtual const IStringconvert_filename_to_uri( const char* filename) const =0
Converts a filename into a URI. More...
virtual const IStringconvert_uri_to_filename( const char* uri) const =0
Converts a URI into a filename. More...

Member Functions

virtual const IString* mi::​neuraylib::​IExport_api::convert_filename_to_uri( const char* filename) const [pure virtual]

Converts a filename into a URI. Returns NULL if filename is NULL. Otherwise returns a URI without URI scheme and URI authority. The URI path is constructed from the filename according to the following rules.

On Linux and MacOS X, the URI path equals the filename. On Windows, slashes in relative URI paths are replaced by backslashes to obtain the filename. Absolute URI paths are mapped to file system paths according to the following table.

Filename

URI path

Comment

C:\dir1\dir2\file

/C:/dir1/dir2/file

-

\dir1\dir2\file

/dir1/dir2/file

-

\\share\dir1\dir2\file

//share/dir1/dir2/file

Note that an empty URI authority (//) is prepended since otherwise the share name is interpreted as URI authority.

Note:
  • There are no checks whether filename identifies an existing file, or whether that file is readable. The filename is simply converted to a URI according to some fixed rules.

  • This method does not understand the special variable "${shader}".

See also:

Importer and Exporter for general information about URIs.

virtual const IString* mi::​neuraylib::​IExport_api::convert_uri_to_filename( const char* uri) const [pure virtual]

Converts a URI into a filename. Returns NULL if

  • uri is NULL,

  • the URI scheme is non-empty and different from "file",

  • the URI authority is non-empty, or

  • the URI path is empty.

In all other cases the URI path is converted into a filename according to the following rules.

On Linux and MacOS X, the filename equals the URI path. On Windows, backslashes in relative filenames are converted to slashes to obtain the URI path. Absolute filenames are mapped to URI paths according to the following table.

URI path

Filename

Comment

/C:/dir1/dir2/file

C:\dir1\dir2\file

-

/C/dir1/dir2/file

C:\dir1\dir2\file

This mapping is supported in addition to the first one since a colon is a reserved character in URIs.

/dir1/dir2/file

\dir1\dir2\file

This mapping is only supported for top-level directory names not consisting of a single letter.

//share/dir1/dir2/file

\\share\dir1\dir2\file

This mapping requires an (otherwise optional) empty URI authority (//) since otherwise the share name is interpreted as URI authority.

Note:
  • There are no checks whether uri identifies an existing file, or whether that file is readable. The URI is simply converted to a filename according to some fixed rules.

  • This method does not understand the special variable "${shader}".

See also:

Importer and Exporter for general information about URIs.

virtual Sint32 mi::​neuraylib::​IExport_api::export_bsdf_data( const char* uri, const IBsdf_isotropic_data* reflection, const IBsdf_isotropic_data* transmission) const [pure virtual]

Exports BSDF data to a file on disk. See Importer and Exporter for the URI naming conventions supported for the uri parameter.

Parameters

uri
The URI of the resource to export the BSDF data to.
reflection
The BSDF data for reflection to export. Can be NULL.
transmission
The BSDF data for transmission to export. Can be NULL.

Returns

  • 0: Success.
  • -1: Invalid URI.
  • -4: Unspecified failure.
virtual Sint32 mi::​neuraylib::​IExport_api::export_canvas( const char* uri, const ICanvas* canvas, Uint32 quality = 100) const [pure virtual]

Exports a canvas to a file on disk. See Importer and Exporter for the URI naming conventions supported for the uri parameter.

If the image plugin that is selected for the export based on the uri parameter is not capable of handling the pixel type of canvas, the canvas is internally converted into one of the pixel types supported by that image plugin for export. If the image plugin supports multiple pixel types for export, the "best" of them (w.r.t. the pixel type of the canvas) is chosen.

The "best" pixel type is determined by attempting to apply the following conversions in the given order to the pixel type of the canvas:

  • use an equivalent pixel type ("Color" instead of "Float32<4>" and vice versa, similar for "Rgb_fp" / "Float32<3>" and "Rgba" / "Sint32"),

  • add an alpha channel (if not already present),

  • increase bits per channel (smaller increase preferred),

  • add additional channels (if possible),

  • decrease bits per channel (smaller decrease preferred), and

  • drop one or more channels.

Parameters

uri
The URI of the resource to export the canvas to. The ending of the URI determines the image format, e.g., ".jpg". Note that support for a given image format requires an image plugin capable of handling that format.
canvas
The canvas to export.
quality
The compression quality is an integer in the range from 0 to 100, where 0 is the lowest quality, and 100 is the highest quality.

Returns

  • 0: Success.
  • -1: Invalid URI.
  • -2: Invalid canvas.
  • -3: Invalid quality.
  • -4: Unspecified failure.
virtual const IExport_result* mi::​neuraylib::​IExport_api::export_elements( ITransaction* transaction, const char* uri, const IArray* elements, const IMap* exporter_options = 0) const [pure virtual]

Exports scene elements. This method is equivalent to export_scene(), except that all named elements in the string array elements are written to the file. If the recurse option is true, any elements referenced by those elements are written as well.

In addition to exporter specific options, every exporter supports the following standard options:

  • "strip_prefix" of type mi::IString: This prefix is stripped from the names of all exported elements if they have the same prefix. This option can be used to undo the effect of the "prefix" option for import operations. Default: the empty string.

  • "recurse" of type mi::IBoolean: If true, any elements referenced by the elements in the elements array are exported as well, similar to the automatic recursion applied by export_scene(). Default: true.

  • "time_stamp" of type mi::IString: If not empty only the passed list of elements along with elements referenced by those that have been changed or added since the time identified by the time stamp are written. Other elements are omitted from the file, but not from recursion: an old element referencing an edited sub-element is not written, but the sub-element is. You can use the method mi::neuraylib::ITransaction::get_time_stamp() to get a time stamp. Default: the empty string.

You can use export_elements() to write incremental changes to be appended to an existing file, which is for example supported with the .mi file format. The elements listed in the elements array are supposed to be independent entry points into the scene graph that need to be visited for the export. In the case that the "recurse" option is true, the export can handle duplicate entries and possible dependencies correctly. If the "recurse" option is false, the export cannot detect duplicates or dependencies automatically, in which case you should avoid duplicates and list in the elements array elements that are referenced before the elements that reference them.

If the file cannot be created or any of the elements cannot be found or written, an error code is set in the mi::neuraylib::IExport_result return value and the file is deleted if it was created.

Note:
  • For mental images scene file format .mi, the exported file will not contain a render statement.

  • The .mib file format is not supported.

The export result uses the following error codes.

  • 0: The export operation was successful.

  • 1: The passed URI is invalid (malformed).

  • 2: failed to create an instance of mi::neuraylib::IWriter for the given URI, most probably because it was unable to open the specified file, e.g., because the directory does not exist, or the user has insufficient permissions.

  • 3: There is no appropriate exporter for the requested file format.

  • 4: The exporter failed to create the instance of mi::neuraylib::IImpexp_state.

  • 5: The exporter did not return a valid instance of mi::neuraylib::IExport_result.

  • 6: The option '...' has an invalid type.

  • 7: The option '...' has an invalid value.

  • 8: The array elements is empty, contains elements that are not strings, or for at least one of the given names there is no DB element with that name.

  • 6000-7999: Reserved for exporter specific error codes.

The severity of all listed errors (excluding the exporter specific error codes) is mi::base::MESSAGE_SEVERITY_ERROR. There might be other undocumented error codes.

virtual const IExport_result* mi::​neuraylib::​IExport_api::export_elements_to_string( ITransaction* transaction, const IArray* elements, const char* file_extension, IString* result_string, const IMap* exporter_options = 0) const [pure virtual]

Exports scene elements to string. This method is equivalent to export_elements(), except that the exported elements are not written to a file, but to a string in memory. Since there is no URI the additional parameter file_extension is used to select the exporter (e.g. ".mdl" to export MDL modules containing presets). The result will be stored in the non-const parameter result_string.

virtual const IExport_result* mi::​neuraylib::​IExport_api::export_scene( ITransaction* transaction, const char* uri, const char* rootgroup, const char* caminst = 0, const char* options = 0, const IMap* exporter_options = 0) const [pure virtual]

Exports a scene. Writes the scene identified by the root group rootgroup, the camera instance caminst (if present), and the options options (if present), to the given file uri.

See Importer and Exporter for the URI naming conventions supported for the uri parameter.

If the file cannot be created or any of the elements cannot be found or written, an error code is set in the mi::neuraylib::IExport_result return value and the file is deleted if it was created.

Any elements referenced by the three argument elements are written as well, recursively, in an order that allows re-importing (for example, in the .mi file format, a referenced element must precede the reference).

In addition to exporter specific options, every exporter supports the following standard option:

  • "strip_prefix" of type mi::IString: This prefix is stripped from the names of all exported elements if they have the same prefix. This option can be used to undo the effect of the "prefix" option for import operations. Default: the empty string.

Note:

For mental images scene file format .mi and binary file format .mib, you have to provide valid caminst and options parameters. They are used in the render statement in the .mi and .mib file format, respectively.

The export result uses the following error codes.

  • 0: The export operation was successful.

  • 1: The passed URI is invalid (malformed).

  • 2: failed to create an instance of mi::neuraylib::IWriter for the given URI, most probably because it was unable to open the specified file, e.g., because the directory does not exist, or the user has insufficient permissions.

  • 3: There is no appropriate exporter for the requested file format.

  • 4: The exporter failed to create the instance of mi::neuraylib::IImpexp_state.

  • 5: The exporter did not return a valid instance of mi::neuraylib::IExport_result.

  • 6: The option '...' has an invalid type.

  • 7: The option '...' has an invalid value.

  • 6000-7999: Reserved for exporter specific error codes.

The severity of all listed errors (excluding the exporter specific error codes) is mi::base::MESSAGE_SEVERITY_ERROR. There might be other undocumented error codes.

virtual const IExporter* mi::​neuraylib::​IExport_api::get_exporter( Size index) const [pure virtual]

Parameters

index
The index of the requested exporter.

Returns

The requested exporter, or NULL if index is out of bounds.

virtual Size mi::​neuraylib::​IExport_api::get_exporter_length() const [pure virtual]

Returns

The number of registered exporters.

virtual IWriter* mi::​neuraylib::​IExport_api::get_writer( const char* uri) const [pure virtual]

Returns a writer that can be used to export to the given resource.

Parameters

uri
The URI of the resource to get the writer for.

Returns

A writer that can be used to export to the resource, or NULL in case of failures.

virtual const IExporter* mi::​neuraylib::​IExport_api::select_exporter_by_extension( const char* extension) const [pure virtual]

Returns the exporter that would be used for a particular file name extension. This method needs a writable directory for temporary files (see mi::neuraylib::IGeneral_configuration::set_temp_path()).

Parameters

extension
The file name extension of the resource to return an exporter for.

Returns

The exporter for the given file name extension, or NULL in case of failures (e.g. there is no exporter that is able to export files with the given file name extension, or the user data directory is not writable).