File Input/Output

As OpenSG user/developer you can always instantiate all your nodes, cores or whatever objects you need one by one in your application code.

In addition OpenSG also provides - as most scene-graph libraries - a set of loaders, which create a scene tree or image from a given file. The system creates singleton Handlers for both types (SceneFileHandler and ImageFileHandler), which handle all abstract requests. The concrete loaders are coded in mime/file type handlers (e.g. OSGTIFImageFileType.h/OSGTIFImageFileType.cpp) and are automatically registered.

The system architecture is designed to handle built-in types and to fetch loaders for a specific type on request. In the current version (1.0) only built-in types are provided since the meta interfaces may not be final yet. However the 1.0 version comes with a sufficient set of built-in loaders and you can always extend the library to handle you own file format.

Usage

You can always use a specific loader directly, but in most cases you would ask the Handler (e.g. SceneFileHandler) to load a file independent of the file type. There is always just one handler (it is a singleton object) you can access the object using the static the() method (e.g. osg::SceneFileType::the()). The Handler knows all the valid suffixes for every mime/file type and can pick the correct loader automatically.

If you would like to get a loader for a specific type or suffix you can just ask the handler to find it (e.g. SceneFileHandler::the().getFileType("wrl")).

Scene

The Scene Handler provides two interfaces to load a scene: read (returns a single root node or NullFC on failure) or readTopNodes (does not create an extra root but returns all top nodes ).

Just use the Handler to find and use the correct type for the given suffix: osg::NodePtr rootPtr = osg::SceneFileTypeSceneFileHandler::the().read("test.wrl") for example would pick the VRML loader (suffix is "wrl"), parse the file and return the result.

Image

The image loader works more or less the same way as the scene loader. Let the singleton handler pick the mime type and just check the return value: osg::ImageFileHandler::the().read("test.tif") for example would pick the tif loader (suffix "tif" ), start loading the file, and return the new Image or Null.

Generated on Mon Mar 17 11:10:26 2008 for OpenSG by  doxygen 1.5.5