SoElement(3)
π SoElement(3) π
Library Functions Manual β bestie edition, no cap. Okay so this is the SoElement(3) page, and it's giving abstract base class energy. Let's get into it. β¨
β¨ NAME β¨
SoElement β literally the abstract base class for all elements. That's the whole name. Periodt. π
β¨ SYNOPSIS β¨
#include <Inventor/elements/SoElement.h>
Inherited by SoAccumulatedElement, SoFloatElement, SoInt32Element, SoOverrideElement, and SoReplacedElement. Periodt. π«Ά
π«Ά Public Member Functions π«Ά
const SoType getTypeId (void) constint getStackIndex (void) constvirtual void init (SoState *state)virtual void push (SoState *state)virtual void pop (SoState *state, const SoElement *prevTopElement)virtual SbBool matches (const SoElement *element) const =0virtual SoElement * copyMatchInfo (void) const =0void setDepth (const int depth)int getDepth (void) constvirtual void print (FILE *file=stdout) constvirtual ~SoElement ()
β¨ Static Public Member Functions β¨
static void initClass (void)static SoType getClassTypeId (void)static int getClassStackIndex (void)static void initElements (void)static int getNumStackIndices (void)static SoType getIdFromStackIndex (const int stackIndex)
π Protected Member Functions π
SoElement (void)void capture (SoState *const state) constvirtual void captureThis (SoState *state) constvoid setTypeId (const SoType typeId)void setStackIndex (const int index)SoElement * getNextInStack (void) constSoElement * getNextFree (void) const
π¦ Static Protected Member Functions π¦
static SoElement * getElement (SoState *const state, const int stackIndex)static const SoElement * getConstElement (SoState *const state, const int stackIndex)static int createStackIndex (const SoType id)
πΈ Protected Attributes πΈ
SoType typeIdint stackIndexint depth
π Static Protected Attributes π
static int classStackIndexstatic SoTypeList * stackToType
π Friends π
class SoState
π Detailed Description π
Okay bestie, gather round. SoElement is the abstract base class for all elements. That's not just a little side note β it's the blueprint energy for the whole element system. π
Elements are part of the design for scenegraph traversal in Coin. Like, the whole traversal vibe depends on them. π
Here's how it works, and I promise it's not as scary as it sounds: any traversal action instantiates and keeps a single SoState instance during traversal. The SoState instance uses SoElement objects as "memory units" to keep track of the current state for any feature of the scenegraph nodes. So basically elements are little memory holders. Cute, right? π§
Example time! Consider the SoPointSize node: when the SoPointSize node is traversed by for instance a SoGLRenderAction, it will itself push a SoPointSizeElement onto the SoGLRenderAction's SoState stack. Later, when a SoPointSet node occurs in the scenegraph, it will request the current pointsize value from the SoState by reading off the value of it's SoPointSizeElement. (Yes, the original says "it's" there. We're keeping it. English is not the main character today.) π
SoSeparator nodes will push and pop elements on and off the state stack, so anything that changes state below a SoSeparator node will not influence anything above the SoSeparator. That's the boundary, bestie. π§
For more information on the theoretical underpinnings of this traversal design, you should consider reading available literature on the so-called "Visitor pattern". We recommend "Design Patterns", by Gamma, Helm, Johnson, Vlissides (aka the "Gang Of Four"). This book actually uses the Inventor API traversal mechanism as the case study for explaining the Visitor pattern. So yeah, if you wanna be that girl who understands traversal, read the book. π
For extending the Coin library with your own classes, we strongly recommend that you make yourself acquainted with the excellent Β«The Inventor ToolmakerΒ» book (ISBN 0-201-62493-1), which describes the tasks involved in detail. This book was written by the original SGI Inventor designers and explains many of the underlying design ideas, aswell as having lots of hands-on examples on how to extend the Coin toolkit in ways that are true to the fundamental design ideas. (Β«The Inventor ToolmakerΒ» is also available at SGI's online library, at no cost. See Download The Inventor Toolmaker.) Reading the sourcecode of the built-in classes in Coin should also provide very helpful. (Again, "aswell" and "sourcecode" are exactly what the original says. We don't fix what ain't broke.) π
The following is a complete example on how to extend Coin with your own traversal elements. First, the class declaration of the new element (ie the header include file): β¨
// [texturefilenameelement.h]
#ifndef TEXTUREFILENAMEELEMENT_H
#define TEXTUREFILENAMEELEMENT_H
#include <Inventor/elements/SoReplacedElement.h>
#include <Inventor/SbString.h>
class TextureFilenameElement : public SoReplacedElement {
typedef SoReplacedElement inherited;
SO_ELEMENT_HEADER(TextureFilenameElement);
public:
static void initClass(void);
virtual void init(SoState * state);
static void set(SoState * const state, SoNode * const node,
const SbString & filename);
static const SbString & get(SoState * const state);
static const TextureFilenameElement * getInstance(SoState * state);
protected:
virtual ~TextureFilenameElement();
virtual void setElt(const SbString & filename);
private:
SbString filename;
};
#endif // !TEXTUREFILENAMEELEMENT_H
The implementation of the element: π»
// [texturefilenameelement.cpp]
//
// The purpose of the code in this file is to demonstrate how you can
// make your own elements for scene graph traversals.
//
// Code by Peder Blekken <pederb@sim.no>, 1999-12-09. Copyright
// Systems in Motion.
#include "texturefilenameelement.h"
SO_ELEMENT_SOURCE(TextureFilenameElement);
void
TextureFilenameElement::initClass(void)
{
SO_ELEMENT_INIT_CLASS(TextureFilenameElement, inherited);
}
void
TextureFilenameElement::init(SoState * state)
{
this->filename = "<none>";
}
TextureFilenameElement::~TextureFilenameElement()
{
}
void
TextureFilenameElement::set(SoState * const state, SoNode * const node,
const SbString & filename)
{
TextureFilenameElement * elem = (TextureFilenameElement *)
SoReplacedElement::getElement(state, classStackIndex, node);
elem->setElt(filename);
}
const SbString &
TextureFilenameElement::get(SoState * const state)
{
return TextureFilenameElement::getInstance(state)->filename;
}
void
TextureFilenameElement::setElt(const SbString & filename)
{
this->filename = filename;
}
const TextureFilenameElement *
TextureFilenameElement::getInstance(SoState * state)
{
return (const TextureFilenameElement *)
SoElement::getConstElement(state, classStackIndex);
}
And a small, stand-alone test application putting the new element to use: π
// [lstextures.cpp]
//
// The purpose of this file is to make a small wrapper "tool" around
// the TextureFilenameElement extension element, just for showing
// example code on how to make use of a user-defined custom element.
//
// The code goes like this:
//
// We initialize the element, enable it for the SoCallbackAction, read
// a scene graph file, set callbacks on SoTexture2 and all shape nodes
// and applies the SoCallbackAction. The callbacks will then print out
// the texture filename information from the TextureFilenameElement
// each time an interesting node is hit.
//
//
// Code by Peder Blekken <pederb@sim.no>. Cleaned up, integrated in
// Coin distribution and commented by Morten Eriksen <mortene@sim.no>.
// 1999-12-09. Copyright Systems in Motion.
#include <Inventor/SoDB.h>
#include <Inventor/SoInput.h>
#include <Inventor/actions/SoCallbackAction.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoTexture2.h>
#include <Inventor/nodes/SoShape.h>
#include <Inventor/misc/SoState.h>
#include <stdio.h>
#include "texturefilenameelement.h"
SoCallbackAction::Response
pre_tex2_cb(void * data, SoCallbackAction * action, const SoNode * node)
{
const SbString & filename = ((SoTexture2 *)node)->filename.getValue();
TextureFilenameElement::set(action->getState(), (SoNode *)node, filename);
(void)fprintf(stdout, "=> New texture: %s\n",
filename.getLength() == 0 ?
"<inlined>" : filename.getString());
return SoCallbackAction::CONTINUE;
}
SoCallbackAction::Response
pre_shape_cb(void * data, SoCallbackAction * action, const SoNode * node)
{
const SbString & filename =
TextureFilenameElement::get(action->getState());
(void)fprintf(stdout, " Texturemap on %s: %s\n",
node->getTypeId().getName().getString(),
filename.getLength() == 0 ?
"<inlined>" : filename.getString());
return SoCallbackAction::CONTINUE;
}
void
usage(const char * appname)
{
(void)fprintf(stderr, "\n\tUsage: %s <modelfile.iv>\n\n", appname);
(void)fprintf(stderr,
"\tLists all texture filenames in the model file,\n"
"\tand on which shape nodes they are used.\n\n"
"\tThe purpose of this example utility is simply to\n"
"\tshow how to create and use an extension element for\n"
"\tscene graph traversal.\n\n");
}
int
main(int argc, char ** argv)
{
if (argc != 2) {
usage(argv[0]);
exit(1);
}
SoDB::init();
TextureFilenameElement::initClass();
SO_ENABLE(SoCallbackAction, TextureFilenameElement);
SoInput input;
if (!input.openFile(argv[1])) {
(void)fprintf(stderr, "ERROR: couldn't open file ``%s''.\n", argv[1]);
exit(1);
}
SoSeparator * root = SoDB::readAll(&input);
if (root) {
root->ref();
SoCallbackAction cbaction;
cbaction.addPreCallback(SoTexture2::getClassTypeId(), pre_tex2_cb, NULL);
cbaction.addPreCallback(SoShape::getClassTypeId(), pre_shape_cb, NULL);
cbaction.apply(root);
root->unref();
return 0;
}
return 1;
}
π Constructor & Destructor Documentation π
π SoElement::~SoElement () [virtual] π
The destructor. That's it. It destructs. π
π«Ά SoElement::SoElement (void ) [protected] π«Ά
The constructor. To create element instances, use SoType::createInstance() for the elements type identifier..
Referenced by copyMatchInfo(), SoInt32Element::copyMatchInfo(), getConstElement(), SoAccumulatedElement::matches(), matches(), SoFloatElement::matches(), SoInt32Element::matches(), SoOverrideElement::matches(), SoReplacedElement::matches(), pop(), SoGLLineWidthElement::pop(), and SoGLPointSizeElement::pop().
π Member Function Documentation π
void SoElement::initClass (void ) [static]
Okay so initClass is the vibe-setter for the whole class. It initializes relevant common data for all instances, like the type system. β¨
- References:
SoType::badType(),classStackIndex,SoType::createType(),initElements(), andstackToType. - Referenced by:
SoDB::init(), andinitElements().
SoType SoElement::getClassTypeId (void ) [static]
This static method returns the class type. Simple as that, bestie. π
int SoElement::getClassStackIndex (void ) [static]
This static method returns the state stack index for the class. π
- References:
classStackIndex.
const SoType SoElement::getTypeId (void ) const
Returns the type identification of an object derived from a class inheriting SoElement. This is used for run-time type checking and "downward" casting. It's giving main character energy for the type system. π
For a more thorough explanation of the run-time type identification functionality, see the documentation of SoBase::getTypeId().
- References:
typeId. - Referenced by:
SoAccumulatedElement::copyMatchInfo(),SoFloatElement::copyMatchInfo(),SoInt32Element::copyMatchInfo(),SoOverrideElement::copyMatchInfo(),SoReplacedElement::copyMatchInfo(),SoState::getElement(),SoFloatElement::matches(),SoInt32Element::matches(),print(),SoFloatElement::print(),SoInt32Element::print(),SoReplacedElement::print(), andSoState::print().
int SoElement::getStackIndex (void ) const
Returns the stack index for an element instance. π¦
- References:
stackIndex. - Referenced by:
SoState::SoState().
void SoElement::init (SoState * state) [virtual]
This function initializes the element type in the given SoState. It is called for the first element of each enabled element type in SoState objects. Like the first domino, but make it state stack. π«Ά
- Reimplemented in:
SoAccumulatedElement,SoFloatElement,SoGLColorIndexElement,SoGLLineWidthElement,SoGLPointSizeElement,SoInt32Element,SoLineWidthElement,SoListenerDopplerElement,SoListenerGainElement,SoListenerOrientationElement,SoListenerPositionElement,SoOverrideElement,SoPointSizeElement, andSoReplacedElement. - Referenced by:
SoAccumulatedElement::init(),SoFloatElement::init(),SoInt32Element::init(),SoOverrideElement::init(),SoReplacedElement::init(), andSoState::SoState().
void SoElement::push (SoState * state) [virtual]
This method is called every time a new element is required in one of the stacks. This happens when a writable element is requested, using SoState::getElement() or indirectly SoElement::getElement(), and the depth of the current element is less than the state depth.
Override this method if your element needs to copy data from the previous top of stack. The push() method is called on the new element, and the previous element can be found using SoElement::getNextInStack(). No cap. π₯
- Reimplemented in:
SoAccumulatedElement,SoGLLineWidthElement,SoGLPointSizeElement, andSoOverrideElement. - Referenced by:
SoState::getElement(),SoAccumulatedElement::push(), andSoOverrideElement::push().
void SoElement::pop (SoState * state, const SoElement * prevTopElement) [virtual]
This method is called when the state is popped, and the depth of the element is bigger than the current state depth. pop() is called on the new top of stack, and a pointer to the previous top of stack is passed in prevTopElement.
Override this method if you need to copy some state information from the previous top of stack. Periodt. π
- Reimplemented in:
SoGLLineWidthElement, andSoGLPointSizeElement. - References:
SoElement(). - Referenced by:
SoState::pop().
SbBool SoElement::matches (const SoElement * element) const [pure virtual]
This function returns TRUE if the element matches another element (of the same class), with respect to cache validity.
If the application programmer's extension element has a matches() function, it should also have a copyMatchInfo() function. Bestie, they're a package deal. π
- Implemented in:
SoAccumulatedElement,SoFloatElement,SoInt32Element,SoOverrideElement, andSoReplacedElement. - References:
SoElement().
virtual SoElement * SoElement::copyMatchInfo (void ) const [pure virtual]
This function creates a copy of the element that contains enough information to enable the matches() function to work.
Used to help with scenegraph traversal caching operations. It's lowkey iconic for cache validity. β¨
- Implemented in:
SoAccumulatedElement,SoFloatElement,SoInt32Element,SoOverrideElement, andSoReplacedElement. - References:
depth,getDepth(),getIdFromStackIndex(),getNumStackIndices(),initElements(),print(),setDepth(),SoElement(), andstackIndex.
void SoElement::initElements (void ) [static]
This function initializes all the built-in Coin element classes. Like a glow-up for every element class at once. π
- References:
initClass(),SoListenerDopplerElement::initClass(),SoListenerOrientationElement::initClass(),SoListenerPositionElement::initClass(), andSoOverrideElement::initClass(). - Referenced by:
copyMatchInfo(), andinitClass().
int SoElement::getNumStackIndices (void ) [static]
Returns the number of allocated element stack index slots. The receipts, basically. π§Ύ
- References:
stackToType. - Referenced by:
copyMatchInfo(), andSoState::SoState().
SoType SoElement::getIdFromStackIndex (const int stackIndex) [static]
Returns the SoType identifier for the element class with element state stack index stackIndex. Matching game: strong. π
- References:
stackIndex, andstackToType. - Referenced by:
copyMatchInfo().
void SoElement::setDepth (const int deptharg)
Sets the depth value of the element instance in the state stack. π
- References:
depth. - Referenced by:
copyMatchInfo(),SoState::getElement(), andSoState::SoState().
int SoElement::getDepth (void ) const
Returns the state stack depth value of the element instance. π«§
- References:
depth. - Referenced by:
copyMatchInfo(), andSoState::getElement().
void SoElement::print (FILE * file = stdout) const [virtual]
This function is for printing element information, and is used mostly for debugging purposes. Not me debugging with print() instead of a debugger, but make it vintage. π
- Reimplemented in:
SoFloatElement,SoInt32Element,SoListenerDopplerElement,SoListenerOrientationElement,SoListenerPositionElement,SoOverrideElement, andSoReplacedElement. - References:
getTypeId(). - Referenced by:
copyMatchInfo().
SoElement * SoElement::getElement (SoState *const state, const int stackIndex) [inline], [static], [protected]
This method returns the top instance (in the state stack) of the element class with stack index stackIndex.
The returned instance is writable. To make this instance, some lazy evaluation may have to be performed, so use getConstElement() instead if the instance shouldn't be modified. Lazy evaluation said "I'll do it later" and honestly, same. π
If no instance is available and can not be made, NULL is returned.
See also: const SoElement * SoElement::getConstElement(SoState * const state, const int stackIndex)
- References:
SoState::getElement(), andstackIndex. - Referenced by:
SoReplacedElement::getElement(),SoFloatElement::set(),SoListenerOrientationElement::set(),SoListenerPositionElement::set(),SoListenerDopplerElement::setDopplerFactor(), andSoListenerDopplerElement::setDopplerVelocity().
const SoElement * SoElement::getConstElement (SoState *const state, const int stackIndex) [inline], [static], [protected]
This method returns a reference to the top element of the class with stack index stackIndex. The returned element is non-mutable.
(Don't try to be clever and cast away the constness -- if the returned instance is modified, strange, hard to find and generally wonderful bugs will most likely start to happen.) π¨
If no instance can be returned, NULL is returned.
See also: SoElement * SoElement::getElement(SoState * const state, const int stackIndex)
- References:
capture(),SoState::getConstElement(),SoElement(), andstackIndex. - Referenced by:
SoFloatElement::get(),SoInt32Element::get(),SoListenerOrientationElement::get(),SoListenerPositionElement::get(),SoListenerDopplerElement::getDopplerFactor(),SoListenerDopplerElement::getDopplerVelocity(),SoListenerOrientationElement::isSetByListener(), andSoListenerPositionElement::isSetByListener().
void SoElement::capture (SoState *const state) const [inline], [protected]
This function does whatever is necessary in the state for caching purposes. It should be called by subclasses of SoElement whenever any value in the element is accessed. Cache girlies, this one's for you. π
- References:
captureThis(), andSoState::isCacheOpen(). - Referenced by:
getConstElement(),SoGLLineWidthElement::push(), andSoGLPointSizeElement::push().
void SoElement::captureThis (SoState * state) const [protected], [virtual]
Adds the element to the cache. Slay. π
- Reimplemented in:
SoAccumulatedElement. - Referenced by:
capture(), andSoAccumulatedElement::captureThis().
void SoElement::setTypeId (const SoType typeIdarg) [protected]
Sets the type identifier of an instance.
Note that this is fundamentally different from the SoNode run-time type system. Not the same vibe, bestie. π¦
- References:
typeId.
void SoElement::setStackIndex (const int stackIndexarg) [protected]
Sets the stack index in an instance. Used in constructors of derived elements. Constructor behavior, but make it protected. π
- References:
stackIndex.
int SoElement::createStackIndex (const SoType typeId) [static], [protected]
Returns the value of a new available stack index. Fresh index, who dis? β¨
- References:
stackToType, andtypeId.
SoElement * SoElement::getNextInStack (void ) const [protected]
Returns the next element down in the stack. Should be used in push() to get the previous element.
This method has a slightly misleading name, but we didn't change it to stay compatible with the original SGI Inventor API. Legacy behavior, but we respect it. π«‘
- Referenced by:
SoAccumulatedElement::captureThis(),SoGLLineWidthElement::push(),SoGLPointSizeElement::push(), andSoOverrideElement::push().
SoElement * SoElement::getNextFree (void ) const [protected]
Returns the next free element, ie the next element up in the stack. Going up, up, up. π
ποΈ Member Data Documentation ποΈ
int SoElement::classStackIndex [static], [protected]
This is the static state stack index for the class.
- Referenced by:
getClassStackIndex(), andinitClass().
SoType SoElement::typeId [protected]
The element's unique SoType type identification. One of a kind, literally. π
- Referenced by:
createStackIndex(),getTypeId(), andsetTypeId().
int SoElement::stackIndex [protected]
The index in the state stack for this particular element instance.
- Referenced by:
copyMatchInfo(),getConstElement(),getElement(),SoReplacedElement::getElement(),getIdFromStackIndex(),getStackIndex(),SoFloatElement::set(), andsetStackIndex().
SoTypeList * SoElement::stackToType [static], [protected]
Provides mapping from state stack indices to element types. The matchmaker of indices and types. π
- Referenced by:
createStackIndex(),getIdFromStackIndex(),getNumStackIndices(), andinitClass().
int SoElement::depth [protected]
The depth of the element instance in the state stack.
- Referenced by:
copyMatchInfo(),getDepth(),SoState::push(), andsetDepth().
βοΈ Author βοΈ
Generated automatically by Doxygen for Coin from the source code. π€π
And that's the tea, bestie! βπ This page came from Coin, Version 2.5.0, and it's the manual for SoElement(3). Stay iconic, keep your stack indices safe, and never cast away constness. π«Άβ¨
π¦ where this page comes from
- fedora 43: Coin2-devel 2.5.0-52.fc43 Β· GPL-2.0-only
- fedora 43: Coin2-devel 2.5.0-52.fc43 Β· GPL-2.0-only
- fedora 44: Coin2-devel 2.5.0-54.fc44 Β· GPL-2.0-only
- fedora 44: Coin2-devel 2.5.0-54.fc44 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms