Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoSFImage Class Reference

The SoSFImage class is used to store pixel images. More...

#include <Inventor/fields/SoSFImage.h>

Inheritance diagram for SoSFImage:
SoSField SoField

Public Types

enum  CopyPolicy { COPY , NO_COPY , NO_COPY_AND_DELETE , NO_COPY_AND_FREE }
 
- Public Types inherited from SoField
enum  FieldType { NORMAL_FIELD = 0 , EVENTIN_FIELD , EVENTOUT_FIELD , EXPOSED_FIELD }
 

Public Member Functions

virtual void copyFrom (const SoField &field)
 
void finishEditing (void)
 
unsigned char * getSubTexture (int idx, SbVec2s &dims, SbVec2s &offset) const
 
virtual SoType getTypeId (void) const
 
const SbImagegetValue () const
 
const unsigned char * getValue (SbVec2s &size, int &nc) const
 
SbBool hasSubTextures (int &numsubtextures)
 
SbBool hasTransparency (void) const
 
SbBool isNeverWrite (void) const
 
virtual SbBool isSame (const SoField &field) const
 
int operator!= (const SoSFImage &field) const
 
const SoSFImageoperator= (const SoSFImage &field)
 
int operator== (const SoSFImage &field) const
 
void setNeverWrite (SbBool flag)
 
void setSubValue (const SbVec2s &dims, const SbVec2s &offset, unsigned char *pixels)
 
void setSubValues (const SbVec2s *dims, const SbVec2s *offsets, int num, unsigned char **pixelblocks)
 
void setValue (const SbVec2s &size, const int nc, const unsigned char *pixels, CopyPolicy copypolicy=COPY)
 
unsigned char * startEditing (SbVec2s &size, int &nc)
 
- Public Member Functions inherited from SoSField
virtual ~SoSField ()
 
- Public Member Functions inherited from SoField
virtual ~SoField ()
 
void addAuditor (void *f, SoNotRec::Type type)
 
SbBool appendConnection (SoEngineOutput *master, SbBool notnotify=FALSE)
 
SbBool appendConnection (SoField *master, SbBool notnotify=FALSE)
 
SbBool connectFrom (SoEngineOutput *master, SbBool notnotify=FALSE, SbBool append=FALSE)
 
SbBool connectFrom (SoField *master, SbBool notnotify=FALSE, SbBool append=FALSE)
 
virtual void connectionStatusChanged (int numconnections)
 
void copyConnection (const SoField *fromfield)
 
virtual void countWriteRefs (SoOutput *out) const
 
void disconnect (SoEngineOutput *engineoutput)
 
void disconnect (SoField *field)
 
void disconnect (void)
 
void enableConnection (SbBool flag)
 
SbBool enableNotify (SbBool on)
 
void evaluate (void) const
 
virtual void fixCopy (SbBool copyconnections)
 
void get (SbString &valuestring)
 
SbBool getConnectedEngine (SoEngineOutput *&master) const
 
SbBool getConnectedField (SoField *&master) const
 
int getConnections (SoFieldList &masterlist) const
 
SoFieldContainergetContainer (void) const
 
SbBool getDirty (void) const
 
int getFieldType (void) const
 
int getForwardConnections (SoFieldList &slavelist) const
 
int getNumConnections (void) const
 
SbBool isConnected (void) const
 
SbBool isConnectedFromEngine (void) const
 
SbBool isConnectedFromField (void) const
 
SbBool isConnectionEnabled (void) const
 
SbBool isDefault (void) const
 
SbBool isIgnored (void) const
 
SbBool isNotifyEnabled (void) const
 
SbBool isOfType (const SoType type) const
 
SbBool isReadOnly (void) const
 
virtual void notify (SoNotList *nlist)
 
int operator!= (const SoField &f) const
 
int operator== (const SoField &f) const
 
virtual SbBool read (SoInput *input, const SbName &name)
 
virtual SbBool referencesCopy (void) const
 
void removeAuditor (void *f, SoNotRec::Type type)
 
SbBool set (const char *valuestring)
 
void setContainer (SoFieldContainer *cont)
 
void setDefault (SbBool defaultVal)
 
void setDirty (SbBool dirty)
 
void setFieldType (int type)
 
void setIgnored (SbBool ignore)
 
SbBool shouldWrite (void) const
 
virtual void startNotify (void)
 
virtual void touch (void)
 
virtual void write (SoOutput *out, const SbName &name) const
 

Static Public Member Functions

static voidcreateInstance (void)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoSField
static void atexit_cleanup (void)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoField
static void cleanupClass (void)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
static void initClasses (void)
 

Additional Inherited Members

- Protected Member Functions inherited from SoSField
 SoSField (void)
 
- Protected Member Functions inherited from SoField
 SoField (void)
 
virtual SoNotRec createNotRec (SoBase *cont)
 
virtual void evaluateConnection (void) const
 
SbBool isDestructing (void) const
 
virtual SbBool readConnection (SoInput *in)
 
void valueChanged (SbBool resetdefault=TRUE)
 
virtual void writeConnection (SoOutput *out) const
 

Detailed Description

The SoSFImage class is used to store pixel images.

The SoSFImage class provides storage for inline 2D image maps. Images in Coin are mainly used for texture mapping support.

SoSFImage instances can be exported and imported as any other field class in Coin.

The components of an SoSFImage is: its image dimensions (width and height), the number of bytes used for describing each pixel (number of components) and an associated pixel buffer. The size of the pixel buffer will be width*height*components.

For texture maps, the components / bytes-per-pixel setting translates as follows: use 1 for a grayscale imagemap, 2 for grayscale + opacity (i.e. alpha value), 3 for RGB (1 byte each for red, green and blue) and 4 components means 3 bytes for RGB + 1 byte opacity value (aka RGBA).

This field is serializable into the Inventor / Coin file format in the following manner:

FIELDNAME X Y C 0xRRGGBBAA 0xRRGGBBAA ...
The SbList class is a template container class for lists.
Definition SbList.h:70

"X" and "Y" are the image dimensions along the given axes, "C" is the number of components in the image. The number of 0xRRGGBBAA pixel color specifications needs to equal the exact number of pixels, which of course is given by X*Y. Each part of the pixel color value is in the range 0x00 to 0xff (hexadecimal, 0 to 255 decimal).

For 3-component images, the pixel-format is 0xXXRRGGBB, where the byte in the pixel color value marked as "XX" is ignored and can be left out.

For 2-component images, the pixel-format is 0xXXXXGGAA, where the bytes in the pixel color values marked as "XX" are ignored and can be left out. "GG" is the part which gives a grayscale value and "AA" is for opacity.

For 1-component images, the pixel-format is 0xXXXXXXGG, where the bytes in the pixel color values marked as "XX" are ignored and can be left out.

The pixels are read as being ordered in rows along X (width) and columns along Y (height, bottom to top).

Here's a simple example of the file format serialization, for a 2x2 RGB-image inside an SoTexture2 node, as mapped onto an SoCube:

Complexity { textureQuality 0.1 } # set low to avoid smoothing
image 2 2 4
0xffffffff 0x00ff0088 # white semi-transparent green
0xff0000ff 0xffff00ff # red yellow
}
Cube { }
SbBool set(const char *valuestring)
Definition SoField.cpp:1350

The mini-scene graph above results in the following mapping on the cube:

Rendering of Example Scenegraph

The cube has only been slightly rotated, so as you can see from the snapshot, the Y-rows are mapped from bottom to top, while the X-column pixels are mapped onto the cube from left to right.

See also
SoTexture2, SoSFImage3

Member Function Documentation

◆ copyFrom()

void SoSFImage::copyFrom ( const SoField & f)
virtual

Copy value(s) from f into this field. f must be of the same type as this field.

Implements SoField.

◆ createInstance()

void * SoSFImage::createInstance ( void )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Creates a new instance of the class type corresponding to the SoType object.

◆ finishEditing()

void SoSFImage::finishEditing ( void )

Notify the field's auditors that the image data have been modified.

◆ getClassTypeId()

SoType SoSFImage::getClassTypeId ( void )
static

This static method returns the SoType object associated with objects of this class.

◆ getSubTexture()

unsigned char * SoSFImage::getSubTexture ( int idx,
SbVec2s & dims,
SbVec2s & offset ) const

Not yet implemented for Coin. Get in touch if you need this method.

Since
Coin 2.0
TGS Inventor 3.0

◆ getTypeId()

SoType SoSFImage::getTypeId ( void ) const
virtual

Returns the type identification of an object derived from a class inheriting SoField. This is used for runtime type checking and "downward" casting.

Implements SoField.

◆ getValue() [1/2]

const SbImage & SoSFImage::getValue ( ) const
Return values
SbImagecontained by this SoSFImage

◆ getValue() [2/2]

const unsigned char * SoSFImage::getValue ( SbVec2s & size,
int & nc ) const

Return pixel buffer, set size to contain the image dimensions and nc to the number of components in the image.

◆ hasSubTextures()

SbBool SoSFImage::hasSubTextures ( int & numsubtextures)

Returns whether or not sub textures was set up for this field.

If TRUE is returned, the numsubtextures argument will be set to the number of sub textures in this image. This number can be used for iterating over all textures with the SoSFImage::getSubTextures() method.

Since
Coin 2.0
TGS Inventor 3.0

◆ hasTransparency()

SbBool SoSFImage::hasTransparency ( void ) const

Returns TRUE if at least one pixel of the image in this field is not completely opaque, otherwise FALSE.

Since
Coin 2.0
TGS Inventor ?.?

◆ initClass()

void SoSFImage::initClass ( void )
static

Internal method called upon initialization of the library (from SoDB::init()) to set up the type system.

◆ isNeverWrite()

SbBool SoSFImage::isNeverWrite ( void ) const

Returns value of "never write texture data" flag.

See also
SoSFImage::setNeverWrite()
Since
Coin 2.0
TGS Inventor ?.?

◆ isSame()

SbBool SoSFImage::isSame ( const SoField & f) const
virtual

Check for equal type and value(s).

Implements SoField.

◆ operator!=()

int SoSFImage::operator!= ( const SoSFImage & field) const
inline

Compare image of field with the image in this field and return FALSE if they are equal.

◆ operator==()

int SoSFImage::operator== ( const SoSFImage & field) const

Compare image of field with the image in this field and return TRUE if they are equal.

◆ setNeverWrite()

void SoSFImage::setNeverWrite ( SbBool flag)

Set this flag to true to avoid writing out the texture to file. This can save a lot on file size.

Default value is FALSE (i.e. write texture data to file.)

(Note: yet unimplemented for Coin.)

Since
Coin 2.0
TGS Inventor ?.?

◆ setSubValue()

void SoSFImage::setSubValue ( const SbVec2s & dims,
const SbVec2s & offset,
unsigned char * pixels )

Not yet implemented for Coin. Get in touch if you need this method.

Since
Coin 2.0
TGS Inventor 3.0

◆ setSubValues()

void SoSFImage::setSubValues ( const SbVec2s * dims,
const SbVec2s * offsets,
int num,
unsigned char ** pixelblocks )

Not yet implemented for Coin. Get in touch if you need this method.

Since
Coin 2.0
TGS Inventor 3.0

◆ setValue()

void SoSFImage::setValue ( const SbVec2s & size,
const int nc,
const unsigned char * pixels,
SoSFImage::CopyPolicy copypolicy = COPY )

Initialize this field to size and nc.

If pixels is not NULL, the image data is copied from pixels into this field. If pixels is NULL, the image data is cleared by setting all bytes to 0 (note that the behavior on passing a NULL pointer is specific for Coin, Open Inventor will crash if you try it).

The image dimensions is given by the size argument, and the nc argument specifies the number of bytes-pr-pixel. A 24-bit RGB image would for instance have an nc equal to 3.

The copypolicy argument makes it possible to share image data with SoSFImage without the data being copied (thereby using less memory resources). The default is to copy image data from the pixels source into an internal copy.

Important note: if you call this with copypolicy as either NO_COPY_AND_DELETE or NO_COPY_AND_FREE, and your application is running on Microsoft Windows, be aware that you will get mysterious crashes if your application is not using the same C library runtime as the Coin library.

The cause of this is that a memory block would then be allocated by the application on the memory heap of one C library runtime (say, for instance MSVCRT.LIB), but attempted deallocated in the memory heap of another C library runtime (e.g. MSVCRTD.LIB), which typically leads to hard-to-debug crashes.

Since
The CopyPolicy argument was added in Coin 2.0.
CopyPolicy was added to TGS Inventor 3.0.

◆ startEditing()

unsigned char * SoSFImage::startEditing ( SbVec2s & size,
int & nc )

Return pixel buffer. Return the image size and components in size and nc.

You cannot use this method to set a new image size. Use setValue() to change the size of the image buffer.

The field's container will not be notified about the changes until you call finishEditing().


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