Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Images

Image node

"Note"

Example : An image using the SoImage node This example displays an image using the SoImage node. The program source code is available in:

$OIVHOME/src/Inventor/examples/Features/

Image/image.cxx.

C++ :

int
main( int argc, char** argv )
{
// Initialize Inventor and Xt
Widget myWindow = SoXt::init( argv[0] );
SoSeparator* root = new SoSeparator;
// Create the image node using
// the file "./sillyFace.rgb"
// as source.
SoImage* image = new SoImage;
image->filename = "sillyFace.rgb";
root->ref();
root->addChild( image );
// Create a viewer
SoXtExaminerViewer* myViewer = new SoXtExaminerViewer( myWindow );
// attach and show viewer
myViewer->setSceneGraph( root );
myViewer->viewAll();
myViewer->setTitle( "Image" );
myViewer->show();
// Loop forever
SoXt::show( myWindow );
SoXt::mainLoop();
return 0;
}

C# :

SoSeparator root = new SoSeparator();
// Create the image node using the file sillyFace.png as source.
SoImage Image = new SoImage();
string ImagePath = SbFileHelper.ExpandString( "$OIVNETHOME/src/Inventor/examples/data/sillyFace.png" );
Image.filename.Value = ImagePath;
root.AddChild( Image );
// Create a viewer
SoWinExaminerViewer myViewer = new SoWinExaminerViewer( this, "", true, SoWinFullViewer.BuildFlags.BUILD_ALL, SoWinViewer.Types.BROWSER );
// attach and show viewer
myViewer.SetSceneGraph( root );
myViewer.ViewAll();
myViewer.SetTitle( "Image" );
myViewer.Show();

Java :

SoRasterImageRW

figure_46817a2f-b9d3-4575-9af4-cfd44298da9c%* SoRasterImageRW

+ SoBMPImageRW
+ SoDDSImageRW
+ SoGIFImageRW
+ SoJP2ImageRW
+ SoJPEGImageRW
+ SoPGXImageRW
+ SoPNGImageRW
+ SoPNMImageRW
+ SoPSImageRW
+ SoSGIRGBImageRW
+ SoSUNImageRW
+ SoTIFFImageRW

Figure 5.31. Raster image classes

SoRasterImageRW allows you to read and write image buffers from/to a file. Subclasses are derived from this abstract class to support common graphic file formats such as BMP, DDS, GIF, JPEG2000, JPEG, PGX, PNG, PostScript, SGI (RGBA), RAS (Sun Raster), and TIFF. These classes dynamically load the format-specific libraries (libJPEG, libTIFF, libPNG...) only when needed.

Depending on the library capabilities, large UserGuide_Images are written using tiles two different ways: WRITE_SCANLINES or WRITE_FULL_IMAGE. For the WRITE_SCANLINES formats, the image can be written incrementally, some number of scanlines at a time. Therefore it is only necessary to allocate enough memory for a single tile, which at most will be the size of the maximum OpenGL viewport (typically 2048x2048). If it is WRITE_FULL_IMAGE, the whole image buffer must be allocated and tiles are copied into it; this is less efficient and requires more memory.

All of the classes dealing with image I/O in Open Inventor and its modules use this set of classes to read or write graphics files (SoImage, SoTexture2...) You can also create your own graphic file format import/export by deriving a subclass from SoRasterImageRW and implementing or overloading its methods:

C++ :

SbBool
open( SoRasterImageIO* rasterImageIO, OpenMode openMode ) void close() SbBool
write( SbRasterImage* rasterImage, unsigned int xPos = 0, unsigned int yPos = 0 ) SbBool writeHeader( SbVec2s& size ) SbBool writeFooter() SbBool
read( SbRasterImage* rasterImage, SbBool infoOnly = FALSE )

C# :

Java :

boolean
open( SoRasterImageIO rasterImageIO, OpenModes openMode ) void close() boolean write( SbRasterImage rasterImage, int xPos, int yPos ) boolean
writeHeader( SbVec2s size ) boolean writeHeader( SbVec2i32 size ) boolean writeFooter() boolean read( SbRasterImage rasterImage, boolean infoOnly )

An example program in the distribution shows how to create your own graphics file reader/writer (PPM format). It can be found at: $OIVHOME/Inventor/examples/Features/RasterRW.

SoSFImage