SoAction(3)
π SoAction(3) β the Coin manual, but make it make sense π
okay bestie, pull up a chair, grab a boba π§, because today we're talking about SoAction β the base class for all traversal actions. she's the blueprint, the blueprint-est blueprint, the mom of the whole action family. no cap.
β¨ NAME β¨
SoAction β the SoAction class is the base class for all traversal actions.
π SYNOPSIS π
#include <Inventor/actions/SoAction.h>
Inherited by SoAudioRenderAction, SoCallbackAction, SoGLRenderAction, SoGetBoundingBoxAction, SoGetMatrixAction, SoGetPrimitiveCountAction, SoHandleEventAction, SoIntersectionDetectionAction, SoPickAction, SoSearchAction, SoSimplifyAction, SoToVRMLAction, and SoWriteAction.
π Public Types
enum AppliedCodeβ{ NODE = 0, PATH = 1, PATH_LIST = 2 }enum PathCodeβ{ NO_PATH = 0, IN_PATH = 1, BELOW_PATH = 2, OFF_PATH = 3 }
π¦ Public Member Functions
virtual ~SoAction (void)virtual SoType getTypeId (void) const =0virtual SbBool isOfType (SoType type) constvirtual void apply (SoNode *root)virtual void apply (SoPath *path)virtual void apply (const SoPathList &pathlist, SbBool obeysrules=FALSE)void apply (SoAction *beingApplied)virtual void invalidateState (void)AppliedCode getWhatAppliedTo (void) constSoNode * getNodeAppliedTo (void) constSoPath * getPathAppliedTo (void) constconst SoPathList * getPathListAppliedTo (void) constconst SoPathList * getOriginalPathListAppliedTo (void) constSbBool isLastPathListAppliedTo (void) constPathCode getPathCode (int &numindices, const int *&indices)void traverse (SoNode *const node)SbBool hasTerminated (void) constconst SoPath * getCurPath (void)SoState * getState (void) constPathCode getCurPathCode (void) constvirtual SoNode * getCurPathTail (void)void usePathCode (int &numindices, const int *&indices)void pushCurPath (const int childindex, SoNode *node=NULL)void popCurPath (const PathCode prevpathcode)void pushCurPath (void)void popPushCurPath (const int childindex, SoNode *node=NULL)void popCurPath (void)void switchToPathTraversal (SoPath *path)void switchToNodeTraversal (SoNode *node)
β Static Public Member Functions
static void initClass (void)static void initClasses (void)static SoType getClassTypeId (void)static void nullAction (SoAction *action, SoNode *node)
π Protected Member Functions
SoAction (void)virtual void beginTraversal (SoNode *node)virtual void endTraversal (SoNode *node)void setTerminated (const SbBool flag)virtual const SoEnabledElementsList & getEnabledElements (void) constvirtual SbBool shouldCompactPathList (void) const
π§ Static Protected Member Functions
static SoEnabledElementsList * getClassEnabledElements (void)static SoActionMethodList * getClassActionMethods (void)
πΈ Protected Attributes
SoState * stateSoActionMethodList * traversalMethods
π Detailed Description π
the SoAction class is the base class for all traversal actions. periodt.
Applying actions is the basic mechanism in Coin for executing various operations on scene graphs or paths within scene graphs, including search operations, rendering, interaction through picking, etc.
The basic operation is to instantiate an action, set it up with miscellaneous parameters if necessary, then call its apply() method on the root node of the scene graph (or subgraph of a scene graph). The action then traverses the scene graph from the root node, depth-first and left-to-right, applying its specific processing at the nodes where it is applicable.
(The SoAction and its derived classes in Coin is an implementation of the design pattern commonly known as the "Visitor" pattern.) β yes bestie, she's a design pattern girlie π«Ά
Here's a simple example that shows how to use the SoWriteAction to dump a scene graph in the Inventor format to a file:
int write_scenegraph(const char * filename, SoNode * root)
{
SoOutput output;
if (!output.openFile(filename)) return 0;
// This is where the action is. ;-)
SoWriteAction wa(&output);
wa.apply(root);
return 1;
}
After traversal, some action types have stored information about the (sub-)scene graph that was traversed, which you can then inquire about through methods like SoGetBoundingBoxAction::getBoundingBox(), SoRayPickAction::getPickedPoint(), SoGetPrimitiveCountAction::getTriangleCount(), etc.
See the various built-in actions for further information (i.e. the subclasses of this class), or look at the example code applications of the Coin library to see how actions are generally used.
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, as well 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 source code of the built-in classes in Coin should also prove very helpful. π
The following example shows the basic outline on how to set up your own extension action class:
// This is sample code on how you can get progress indication on Coin
// export operations by extending the library with your own action
// class. The new class inherits SoWriteAction. The code is presented
// as a standalone example.
//
// The general technique is to inherit SoWriteAction and override its
// "entry point" into each node of the scene graph. The granularity of
// the progress callbacks is on a per node basis, which should usually
// be good enough.
#include <Inventor/SoDB.h>
#include <Inventor/actions/SoWriteAction.h>
#include <Inventor/nodes/SoSeparator.h>
class MyWriteAction : public SoWriteAction {
SO_ACTION_HEADER(SoWriteAction);
public:
MyWriteAction(SoOutput * out);
virtual ~MyWriteAction();
static void initClass(void);
protected:
virtual void beginTraversal(SoNode * node);
private:
static void actionMethod(SoAction *, SoNode *);
int nrnodes;
int totalnrnodes;
};
SO_ACTION_SOURCE(MyWriteAction);
MyWriteAction::MyWriteAction(SoOutput * out)
: SoWriteAction(out)
{
SO_ACTION_CONSTRUCTOR(MyWriteAction);
}
MyWriteAction::~MyWriteAction()
{
}
void
MyWriteAction::initClass(void)
{
SO_ACTION_INIT_CLASS(MyWriteAction, SoWriteAction);
SO_ACTION_ADD_METHOD(SoNode, MyWriteAction::actionMethod);
}
void
MyWriteAction::beginTraversal(SoNode * node)
{
this->nrnodes = 0;
this->totalnrnodes = 0;
SoWriteAction::beginTraversal(node);
}
void
MyWriteAction::actionMethod(SoAction * a, SoNode * n)
{
// To abort the export process in mid-writing, we could just avoid
// calling in to the SoNode::writeS() method.
SoNode::writeS(a, n);
MyWriteAction * mwa = (MyWriteAction *)a;
SoOutput * out = mwa->getOutput();
if (out->getStage() == SoOutput::COUNT_REFS) {
mwa->totalnrnodes++;
}
else { // (out->getStage() == SoOutput::WRITE)
mwa->nrnodes++;
SbString s;
s.sprintf(" # wrote node %p (%d/%d) \n", n, mwa->nrnodes, mwa->totalnrnodes);
out->write(s.getString());
}
}
int
main(int argc, char ** argv)
{
if (argc < 2) {
(void)fprintf(stderr, "\n\nUsage: %s <filename>\n\n", argv[0]);
exit(1);
}
SoDB::init();
MyWriteAction::initClass();
SoInput in;
if (!in.openFile(argv[1])) { exit(1); }
SoSeparator * root = SoDB::readAll(&in);
if (!root) { exit(1); }
root->ref();
SoOutput out;
MyWriteAction mwa(&out);
mwa.apply(root);
root->unref();
return 0;
}
π Member Enumeration Documentation π
π enum SoAction::AppliedCode
Enumerated values for what the action was applied to.
π enum SoAction::PathCode
Enumerated values for how the action is applied to a scene graph.
πΌ Constructor & Destructor Documentation πΌ
SoAction::~SoAction (void ) [virtual]
Destructor, free resources. bye babe, releasing everything, iconic π
SoAction::SoAction (void ) [protected]
Default constructor, does all necessary top level initialization.
π Member Function Documentation π
void SoAction::initClass (void ) [static]
Initializes the runtime type system for this class, and sets up the enabled elements and action method list.
void SoAction::initClasses (void ) [static]
Initialize all the SoAction subclasses. Automatically called from SoAction::initClass().
SoType SoAction::getClassTypeId (void ) [static]
Returns the runtime type object associated with instances of this class.
virtual SoType SoAction::getTypeId (void ) const [pure virtual]
Returns the type identification of an action derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.
Usage example:
void bar(SoAction * action)
{
if (action->getTypeId() == SoGLRenderAction::getClassTypeId()) {
// safe downward cast, know the type
SoGLRenderAction * glrender = (SoGLRenderAction *)action;
}
return; // ignore if not render action
}
For application programmers wanting to extend the library with new actions: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the predefined macros available through Inventor/nodes/SoSubAction.h: SO_ACTION_SOURCE, SO_ACTION_INIT_CLASS and SO_ACTION_CONSTRUCTOR.
For more information on writing Coin extensions, see the SoAction class documentation.
Returns the actual type id of an object derived from a class inheriting SoAction. Needs to be overridden in all subclasses.
Implemented in SoAudioRenderAction, SoBoxHighlightRenderAction, SoCallbackAction, SoGetBoundingBoxAction, SoGetMatrixAction, SoGetPrimitiveCountAction, SoGlobalSimplifyAction, SoGLRenderAction, SoHandleEventAction, SoIntersectionDetectionAction, SoLineHighlightRenderAction, SoPickAction, SoRayPickAction, SoReorganizeAction, SoSearchAction, SoShapeSimplifyAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, SoVectorizeAction, SoVectorizePSAction, and SoWriteAction.
SbBool SoAction::isOfType (SoType type) const [virtual]
Returns TRUE if the type of this object is either of the same type or a subclass of type.
void SoAction::apply (SoNode * root) [virtual]
Applies the action to the scene graph rooted at root.
β οΈ note bestie: you should not apply an action to a node with a zero reference count. The behavior in that case is undefined. fr fr, don't do it. π
π and yeah, before we move on β that last one? Reimplemented inSoBoxHighlightRenderAction,SoIntersectionDetectionAction,SoLineHighlightRenderAction,SoReorganizeAction,SoSimplifyAction,SoToVRML2Action,SoToVRMLAction, andSoVectorizeAction. iconic lineup honestly.
void SoAction::apply (SoPath * path) [virtual]
Bestie, this one applies the action to the parts of the graph defined by path. π
okay so heads up: an SoPath will also contain all the nodes that may influence, like, the geometry nodes in the path. so for instance, if you apply an SoGLRenderAction on an SoPath, it'll render that path as expected in the view β where the geometry gets its materials, textures, and other appearance settings correctly. slay. β¨
and if the path ends in an SoGroup node? the action will also traverse the tail node's children. π«Ά
π Reimplemented inSoBoxHighlightRenderAction,SoIntersectionDetectionAction,SoLineHighlightRenderAction,SoReorganizeAction,SoSimplifyAction,SoToVRML2Action,SoToVRMLAction, andSoVectorizeAction.
void SoAction::apply (const SoPathList & pathlist, SbBool obeysrules = FALSE) [virtual]
Applies the action to the graphs defined by pathlist. π
If obeysrules is set to TRUE, then pathlist must obey these four conditions (which, fun fact, is the case for path lists returned from search actions for non-group nodes, and path lists returned from picking actions):
- All paths must start at the same head node. π
- All paths must be sorted in traversal order. π
- The paths must be unique. π
- No path can continue through the end point of another path. π«
See also
SoAction::apply(SoPath * path)
π Reimplemented inSoBoxHighlightRenderAction,SoIntersectionDetectionAction,SoLineHighlightRenderAction,SoReorganizeAction,SoSimplifyAction,SoToVRML2Action,SoToVRMLAction, andSoVectorizeAction.
void SoAction::apply (SoAction * beingApplied)
Applies this action object to the same thing that beingApplied is being applied to. twin energy fr fr. π―
π This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.
Since
- Coin
2.1
void SoAction::invalidateState (void) [virtual]
Invalidates the state, forcing it to be recreated at the next apply() invocation. like hitting refresh on your whole vibe. π
π Reimplemented in SoGLRenderAction.
void SoAction::nullAction (SoAction * action, SoNode * node) [static]
This method is used for filling up the lookup tables with void methods. nothing to see here, it's just doing its little job. π
SoAction::AppliedCode SoAction::getWhatAppliedTo (void) const
Returns a code telling you what (node, path, or path list) the action instance is currently being applied to. π
SoNode * SoAction::getNodeAppliedTo (void) const
Returns a pointer to the node the action is being applied to. πΈ
If the action is not being applied to a node (but a path or a path list instead), the method returns NULL.
SoPath * SoAction::getPathAppliedTo (void) const
Returns the pointer to the path the action is being applied to. π€οΈ
β οΈ The path is managed by the action instance and should not be destroyed or modified by the caller. hands off, bestie.
If the action is not being applied to a path (but a node or a path list), the method returns NULL.
const SoPathList * SoAction::getPathListAppliedTo (void) const
Returns the pointer to the path list the action is currently being applied to. π
β οΈ The path list is managed by the action instance and should not be destroyed or modified by the caller.
If the action is not being applied to a path list (but a node or a path), the method returns NULL.
also lowkey important: the returned path list pointer need not be equal to the list apply() was called with, because the action may have reorganized the path list for efficiency reasons. it does a little glow-up mid-flight, it's fine. β¨
See also
void SoAction::apply(const SoPathList &, SbBool)
const SoPathList * SoAction::getOriginalPathListAppliedTo (void) const
Returns a pointer to the original path list the action is being applied to. ποΈ the before picture, not the after.
If the action is not being applied to a path list (but a node or a path), the method returns NULL.
SbBool SoAction::isLastPathListAppliedTo (void) const
This method is not supported in Coin. it should probably have been private in OIV. π we said what we said.
SoAction::PathCode SoAction::getPathCode (int & numindices, const int *& indices)
Returns a code that indicates where the current node lies with respect to the path(s) the action is being applied to. π§
The arguments indices and numindices are only set if the method returns IN_PATH. no IN_PATH, no indices, periodt.
void SoAction::traverse (SoNode *const node)
Traverses a scene graph rooted at node, invoking the action methods of the nodes in the graph. π³ go little nodes go.
SbBool SoAction::hasTerminated (void) const
Returns TRUE if the action was prematurely terminated. π
Note that the termination flag will be FALSE if the action simply completed its run over the scene graph in the "ordinary" fashion β i.e. it was not explicitly aborted from any of the nodes in the graph. finishing normally β getting stopped, bestie, keep them separate. π
See also
setTerminated()
const SoPath * SoAction::getCurPath (void)
Returns a pointer to the path generated during traversal β from the root of the traversed graph all the way to the current node. π main character path energy.
SoState * SoAction::getState (void) const
Returns a pointer to the state of the action instance. π§Ί the state contains the current set of elements used during traversal.
SoAction::PathCode SoAction::getCurPathCode (void) const [inline]
Returns the current traversal path code. β
SoNode * SoAction::getCurPathTail (void) [virtual]
This API member is considered internal to the library β it's not likely to be of interest to the application programmer. iykyk. π€«
π Reimplemented in SoCallbackAction.
void SoAction::usePathCode (int & numindices, const int *& indices)
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. π
void SoAction::pushCurPath (const int childindex, SoNode * node = NULL)
Get ready to traverse the childindex'th child. π§Έ Use this method if the path code might change as a result of this.
β οΈ This method is very internal. Do not use unless you know what you're doing. fr fr.
void SoAction::popCurPath (const PathCode prevpathcode)
Pops the current path, and sets the path code to prevpathcode. π«§
β οΈ This method is very internal. Do not use unless you know what you're doing.
void SoAction::pushCurPath (void)
Pushes a NULL node onto the current path. π³οΈ Use this before traversing all children when you know that the path code will not change while traversing children.
β οΈ This method is very internal. Do not use unless you know what you're doing.
void SoAction::popPushCurPath (const int childindex, SoNode * node = NULL)
Get ready to traverse the childindex'th child. π§Έ Use this method if you know the path code will not change as a result of this.
β οΈ This method is very internal. Do not use unless you know what you're doing.
void SoAction::popCurPath (void)
Pops off the last child in the current path. π Use this if you know the path code hasn't changed since the current path was pushed.
β οΈ This method is very internal. Do not use unless you know what you're doing.
void SoAction::switchToPathTraversal (SoPath * path)
Store our state, traverse the given path, restore our state, and continue traversal. π it's giving save-point-then-go.
void SoAction::switchToNodeTraversal (SoNode * node)
Store our state, traverse the subgraph rooted at the given node, restore our state, and continue traversal. πΏ same deal, different shape.
void SoAction::beginTraversal (SoNode * node) [protected], [virtual]
This virtual method is called from SoAction::apply(), and it's the entry point for the actual scene graph traversal. πͺβ¨
It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.
The default method just calls traverse() β and any overridden implementation of the method must do that too (or call SoAction::beginTraversal()) to trigger the scene graph traversal. no skipping, bestie, or nothing renders. π€
π Reimplemented inSoAudioRenderAction,SoCallbackAction,SoGetBoundingBoxAction,SoGetMatrixAction,SoGetPrimitiveCountAction,SoGlobalSimplifyAction,SoGLRenderAction,SoHandleEventAction,SoPickAction,SoRayPickAction,SoReorganizeAction,SoSearchAction,SoShapeSimplifyAction,SoSimplifyAction,SoToVRML2Action,SoToVRMLAction, andSoWriteAction.
void SoAction::endTraversal (SoNode * node) [protected], [virtual]
This virtual method can be overridden to execute code after the scene graph traversal. π The default method does nothing. it's the chill one.
π Reimplemented in SoGLRenderAction.
void SoAction::setTerminated (const SbBool flag) [protected]
Set the termination flag. π©
Typically set to TRUE from nodes upon special conditions being met during scene graph traversal β like the correct node being found when doing an SoSearchAction traversal, or when grabbing the event from an SoHandleEventAction. found it, we're done here. π
See also
hasTerminated()
const SoEnabledElementsList & SoAction::getEnabledElements (void) const [protected], [virtual]
Returns a list of the elements used by action instances of this class upon traversal operations. π§Ύβ¨
π Reimplemented inSoAudioRenderAction,SoBoxHighlightRenderAction,SoCallbackAction,SoGetBoundingBoxAction,SoGetMatrixAction,SoGetPrimitiveCountAction,SoGlobalSimplifyAction,SoGLRenderAction,SoHandleEventAction,SoIntersectionDetectionAction,SoLineHighlightRenderAction,SoPickAction,SoRayPickAction,SoReorganizeAction,SoSearchAction,SoShapeSimplifyAction,SoSimplifyAction,SoToVRML2Action,SoToVRMLAction,SoVectorizeAction,SoVectorizePSAction, andSoWriteAction.
SbBool SoAction::shouldCompactPathList (void) const [protected], [virtual]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. π nothing for you here, babe.
SoEnabledElementsList * SoAction::getClassEnabledElements (void) [static], [protected]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. π€«
π This method is not available in the original OIV API β see SoSubAction.h for explanation.
SoActionMethodList * SoAction::getClassActionMethods (void) [static], [protected]
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer. π€«
π This method is not available in the original OIV API β see SoSubAction.h for explanation.
πΎ MEMBER DATA DOCUMENTATION πΎ
SoState* SoAction::state [protected]
Pointer to the traversal state instance of the action. π§
SoActionMethodList* SoAction::traversalMethods [protected]
Stores the list of "nodetype to actionmethod" mappings for the particular action instance. πΊοΈ the whole little matchmaking service, honestly.
βοΈ AUTHOR βοΈ
Generated automatically by Doxygen for Coin from the source code. π€β¨ not a human wrote this one, she's a machine and she ate.
and that's a wrap on SoAction(3) bestie!! π this page is Version 4.0.10, dated Thu Jun 25 2026 00:00:00, and you made it all the way to the bottom, which is genuinely main character behavior. go take a break, hydrate, and remember: don't touch the very internal methods unless you know what you're doing. π«Άπ slay π
π¦ where this page comes from
- fedora 43: Coin4-devel 4.0.10-1.fc43 Β· BSD-3-Clause AND GPL-3.0-or-later
- fedora 43: Coin4-devel 4.0.10-1.fc43 Β· BSD-3-Clause AND GPL-3.0-or-later
- fedora 44: Coin4-devel 4.0.10-1.fc44 Β· BSD-3-Clause AND GPL-3.0-or-later
- fedora 44: Coin4-devel 4.0.10-1.fc44 Β· BSD-3-Clause AND GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms