Class SoOutput
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 = new SoWriteAction() ; writeAction.getOutput().openFile( "output.iv" ); writeAction.apply( root ); 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThis enum defines the properties used when data are written to a file.static enumNested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand -
Field Summary
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses current file if opened withopenFile().voidCalls decrementIndent((int)1).voiddecrementIndent(int amount) intfilePutc(int name_18234) Write a byte to the currently open file.intWrite a string to the currently open file.voidlongThe total number of bytes allocated to a memory buffer may be larger than the number of bytes written.static StringReturns the string representing the default ASCII header.static StringReturns the string representing the default binary header.Returns the current properties used bySoOutput.intgetStage()voidCalls incrementIndent((int)1).voidincrementIndent(int amount) voidindent()booleanisBinary()Returns current state of binary flag.booleanReturns true if ScaleViz is currently writing data for synchronization.booleanOpens named file, sets current file to result.voidResets buffer for output again.voidResets the header for output files to be the default header.voidsetBinary(boolean flag) Sets whether output should be ASCII (default) or binary.voidsetDoublePrecision(int precision) Sets the precision for writing floating point numbers (type double), i.e.voidsetFileProperty(SoOutput.FileProperties properties) Sets a combination of properties for the current file.voidsetFloatPrecision(int precision) Sets the precision for writing floating point numbers (type float), i.e.voidsetHeaderString(String str) Sets the header for output files.voidsetStage(SoOutput.Stages stage) voidwrite(boolean b) voidwrite(byte c) voidwrite(double d) voidwrite(float f) voidwrite(int i) voidwrite(long i) voidwrite(short s) voidMethods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
Constructor Details
-
SoOutput
public SoOutput()Constructor. The defaultSoOutputwrites to stdout.
-
-
Method Details
-
decrementIndent
public void decrementIndent()Calls decrementIndent((int)1). -
incrementIndent
public void incrementIndent()Calls incrementIndent((int)1). -
resetHeaderString
public void resetHeaderString()Resets the header for output files to be the default header. -
setFileProperty
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
SoOutputobject is created.- Since:
- Open Inventor 8.1
-
getFileProperty
Returns the current properties used bySoOutput.- Since:
- Open Inventor 8.1
-
filePuts
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
-
resetBuffer
public void resetBuffer()Resets buffer for output again. Output starts over at beginning of buffer. -
setBinary
public void setBinary(boolean flag) Sets whether output should be ASCII (default) or binary. -
getBufferSize
public long getBufferSize()The total number of bytes allocated to a memory buffer may be larger than the number of bytes written. This returns that total number. -
isBinary
public boolean isBinary()Returns current state of binary flag. -
isWritingForScaleViz
public boolean isWritingForScaleViz()Returns true if ScaleViz is currently writing data for synchronization. -
openFile
Opens named file, sets current file to result. This returns false on error. -
filePutc
public int filePutc(int name_18234) 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
-
closeFile
public void closeFile()Closes current file if opened withopenFile(). -
setHeaderString
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. -
write
-
incrementIndent
public void incrementIndent(int amount) -
getStage
-
setStage
-
write
public void write(int i) -
write
public void write(byte c) -
write
public void write(boolean b) -
getIndentLevel
public int getIndentLevel() -
decrementIndent
public void decrementIndent(int amount) -
indent
public void indent() -
getDefaultASCIIHeader
Returns the string representing the default ASCII header. -
setDoublePrecision
public void setDoublePrecision(int precision) 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. -
setFloatPrecision
public void setFloatPrecision(int precision) 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. -
write
public void write(double d) -
flushFile
public void flushFile() -
write
public void write(long i) -
write
public void write(short s) -
getDefaultBinaryHeader
Returns the string representing the default binary header. -
write
public void write(float f)
-