SoOutput Class Reference
[General]

Used to write Open Inventor data files. More...

#include <Inventor/SoOutput.h>

List of all members.

Classes

struct  SoOutputEntry
 This structure holds the name and offset of a output in an SoEngineOutputData && SoVRMLInterpOutputData.

Public Types

enum  FileProperty {
  DefaultProperty = 0,
  CompressedZlib = 1
}

Public Member Functions

 SoOutput ()
virtual ~SoOutput ()
virtual void setFileProperty (const FileProperty properties)
FileProperty getFileProperty () const
virtual void setFilePointer (FILE *newFP)
virtual FILE * getFilePointer () const
size_t fileWrite (void *buffer, size_t elemSize, size_t count)
int filePuts (const char *)
int filePutc (int)
virtual SoNONUNICODE SbBool openFile (const char *fileName)
virtual SbBool openFile (const SbString &fileName)
virtual void closeFile ()
virtual void setBuffer (void *bufPointer, size_t initSize, SoOutputReallocCB *reallocFunc, int32_t offset=0)
virtual SbBool getBuffer (void *&bufPointer, size_t &nBytes) const
virtual size_t getBufferSize () const
virtual void resetBuffer ()
virtual void setBinary (SbBool flag)
virtual SbBool isBinary () const
SbBool isWritingForScaleViz () const
virtual void setHeaderString (const SbString &str)
virtual void resetHeaderString ()
virtual void setFloatPrecision (int precision)
virtual void setDoublePrecision (int precision)

Static Public Member Functions

static SbString getDefaultASCIIHeader ()
static SbString getDefaultBinaryHeader ()

Friends

class SoBase
class SoDB

Detailed Description

Used to write Open Inventor data files.

This class is used for writing Open Inventor data files. It supports both ASCII (default) and binary formats and provides some convenience functions for opening and closing files. See SbFileHelper for more convenience functions. It can write to a buffer in memory as well as to a file. Since Open Inventor 8.1, SoOutput can write compressed data in the lossless Zlib (aka gzip) format. Both ASCII and binary format files may be compressed.

An instance of SoOutput is automatically created by SoWriteAction and can be queried using the getOutput() method in that class.

This is typically the only instance needed. For example:

     SoWriteAction writeAction;
     writeAction.getOutput()->openFile( "output.iv" );
     writeAction.apply( scene );
     writeAction.getOutput()->closeFile();

Note that file properties (binary, compression, header string, etc) should be set before calling openFile() or setFilePointer().

File extensions
The recommended file extension for Open Inventor format files, both ASCII and binary is ".iv". Open Inventor will automatically detect if the file is ASCII or binary based on the file header string. Compressed Open Inventor files may be given the extension ".ivz" for convenience, but it is not required. Open Inventor automatically detects compressed files.

File Header
Open Inventor writes a human readable file header as the first line of both ASCII and binary format files. Since Open Inventor 8.0, the default file header looks like this:
ASCII : "#Inventor V8.0 ascii"
Binary: "#Inventor V8.0 binary LE"
The two character code at the end of the binary header indicates if the file was written on a little-endian (LE) or big-endian (BE) machine. The version number string may change again in the future if incompatible changes are made to the file format.

You can always query the current default headers using static methods getDefaultASCIIHeader() and getDefaultBinaryHeader().

All versions of Open Inventor from version 2.1 through version 7.x, wrote the version number string "V2.1" by default and did not append "LE" (or "BE") to the binary header. Open Inventor cannot, in general, load files containing a file header from a newer version. However all versions of Open Inventor can load files written by older versions and can load files containing the V2.1 file header. We recommend always using the default file header because newer versions enable performance enhancing features in the file format. If you need to write a file compatible with older versions, call setHeaderString() with "#Inventor V2.1 ascii" or "#Inventor V2.1 binary".

SEE ALSO

SoInput, SoWriteAction, SoTranSender, SbFileHelper


Member Enumeration Documentation

This enum defines the properties used when data are written to a file.

The function setFileProperty uses this enum.

Since Open Inventor 8.1

Enumerator:
DefaultProperty 

Regular ascii or binary output.

This is the default property value.

CompressedZlib 

Compressed ascii or binary output using the zlib module.


Constructor & Destructor Documentation

SoOutput::SoOutput (  ) 

Constructor.

The default SoOutput writes to stdout.

virtual SoOutput::~SoOutput (  )  [virtual]

Destructor.

The destructor closes any files opened by the SoOutput.


Member Function Documentation

virtual void SoOutput::closeFile (  )  [virtual]

Closes current file if opened with openFile().

int SoOutput::filePutc ( int   ) 

Write a byte to the currently open file.


If the file is compressed the byte is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns the byte value specified if successful.

Since Open Inventor 8.1

int SoOutput::filePuts ( const char *   ) 

Write a string to the currently open file.


If the file is compressed the string is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns a non-negative value if successful (same as fputs).

Since Open Inventor 8.1

size_t SoOutput::fileWrite ( void *  buffer,
size_t  elemSize,
size_t  count 
)

Write a buffer to the currently open file.


If the file is compressed the buffer is compressed on the fly. Returns -1 if no file is currently open, else returns total number of elements successfully written (same as fwrite).

Since Open Inventor 8.1

virtual SbBool SoOutput::getBuffer ( void *&  bufPointer,
size_t &  nBytes 
) const [virtual]

Returns memory buffer being written to and the new size of the buffer.

Returns FALSE if not writing into a buffer.

virtual size_t SoOutput::getBufferSize (  )  const [inline, virtual]

The total number of bytes allocated to a memory buffer may be larger than the number of bytes written.

This returns that total number.

static SbString SoOutput::getDefaultASCIIHeader (  )  [static]

Returns the string representing the default ASCII header.

static SbString SoOutput::getDefaultBinaryHeader (  )  [static]

Returns the string representing the default binary header.

virtual FILE* SoOutput::getFilePointer (  )  const [virtual]

Returns the file pointer in use, or NULL if using a buffer.

Using this function can be dangerous, for example when the output is compressed! In such case the compressed file can be corrupt!

FileProperty SoOutput::getFileProperty (  )  const

Returns the current properties used by SoOutput. Since Open Inventor 8.1

virtual SbBool SoOutput::isBinary (  )  const [inline, virtual]

Returns current state of binary flag.

SbBool SoOutput::isWritingForScaleViz (  )  const

Returns TRUE if ScaleViz is currently writing data for synchronization.

virtual SbBool SoOutput::openFile ( const SbString fileName  )  [virtual]

Opens named file, sets current file to result.

This returns FALSE on error. If the file extension is .ivz the file is compressed so the compression module is initialized during the call to openFile.

virtual SoNONUNICODE SbBool SoOutput::openFile ( const char *  fileName  )  [virtual]

Opens named file, sets current file to result.

This returns FALSE on error.

Non Unicode List:
This function should not be used in a Unicode application.
virtual void SoOutput::resetBuffer (  )  [virtual]

Resets buffer for output again.

Output starts over at beginning of buffer.

virtual void SoOutput::resetHeaderString (  )  [virtual]

Resets the header for output files to be the default header.

virtual void SoOutput::setBinary ( SbBool  flag  )  [virtual]

Sets whether output should be ASCII (default) or binary.

virtual void SoOutput::setBuffer ( void *  bufPointer,
size_t  initSize,
SoOutputReallocCB reallocFunc,
int32_t  offset = 0 
) [virtual]

Sets up memory buffer to write to, initial size, reallocation function (which is called if there is not enough room in the buffer), and offset in the buffer at which to begin writing.

If the reallocation function returns NULL, writing will be disabled.

virtual void SoOutput::setDoublePrecision ( int  precision  )  [virtual]

Sets the precision for writing floating point numbers (type double), i.e. the number of significant digits.

Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.

virtual void SoOutput::setFilePointer ( FILE *  newFP  )  [virtual]

Sets file pointer to write to.

virtual void SoOutput::setFileProperty ( const FileProperty  properties  )  [virtual]

Sets a combination of properties for the current file.

The function must be called before the output of any data. It can be called before the openFile or setFilePointer functions.

The default property is DefaultProperty when the SoOutput object is created.

Since Open Inventor 8.1

virtual void SoOutput::setFloatPrecision ( int  precision  )  [virtual]

Sets the precision for writing floating point numbers (type float), i.e. the number of significant digits.

Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.

virtual void SoOutput::setHeaderString ( const SbString str  )  [virtual]

Sets the header for output files.

This is useful, for example, if you have a file format that is a superset of the Open Inventor file format and you want Open Inventor to read the files. It is highly recommend that in your new header you simply append to the header of the Open Inventor file format you are extending. For example, if a new file format is based on the Open Inventor 2.1 file format, register a header similar to: "#Inventor V2.1 ascii MY FILE FORMAT EXTENSION". Then all Open Inventor 2.1 applications (and later) can read the file.


Friends And Related Function Documentation

friend class SoBase [friend]
friend class SoDB [friend]

The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 4 Sep 2023
Copyright © Thermo Fisher Scientific All rights reserved.
https://www.openinventor.com/