Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoCallbackAction.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Dave Immel (MMM yyyy)
25** Modified by : Thad Beier (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_CALLBACK_ACTION_
52#define _SO_CALLBACK_ACTION_
53
54#include <Inventor/SbBox.h>
69
71class SoShape;
73
74//
75// Typedefs for callback routines used with the callbacks for
76// generating primitives.
77//
82typedef void SoTriangleCB(void *userData,
83 SoCallbackAction *action,
84 const SoPrimitiveVertex *v1,
85 const SoPrimitiveVertex *v2,
86 const SoPrimitiveVertex *v3);
91typedef void SoLineSegmentCB(void *userData,
92 SoCallbackAction *action,
93 const SoPrimitiveVertex *v1,
94 const SoPrimitiveVertex *v2);
99typedef void SoPointCB(void *userData,
100 SoCallbackAction *action,
101 const SoPrimitiveVertex *v);
102
103#ifdef _WIN32
104//JSG - Changed SoCallbackActionCB back to how it is done under unix,
105//SoCallbackActionCB2 is included for backward compatability on Windows
106typedef int SoCallbackActionCB2(void *userData,
107 SoCallbackAction *action,
108 const SoNode *node);
109#endif
111//
112// Class: SoCallbackAction
113//
114// State accumulation action. This action performs a generic
115// traversal of a scene graph. The caller can register callback
116// functions to be called when specific types of nodes are traversed.
117//
119
298
300
301 public:
302
318
327 typedef Response SoCallbackActionCB(void *userData,
328 SoCallbackAction *action,
329 const SoNode *node);
330
335
336 // Destructor
337#ifndef HIDDEN_FROM_DOC
338 virtual ~SoCallbackAction();
339#endif // HIDDEN_FROM_DOC
340
342 //
343 // Adding callback functions:
344 //
345
353 void addPreCallback(SoType type, SoCallbackActionCB *cb, void *data);
354
362 void addPostCallback(SoType type, SoCallbackActionCB *cb, void *data);
363
371
379
385 void addTriangleCallback(SoType type, SoTriangleCB *cb, void *data);
386
393 void addLineSegmentCallback(SoType type, SoLineSegmentCB *cb, void *data);
394
400 void addPointCallback(SoType type, SoPointCB *cb, void *data);
401
403 //
404 // Accessing state information from callbacks. Non-obvious return
405 // values are documented.
406 //
407
409
412 float getComplexity() const;
413
418
420
423 int32_t getNumCoordinates() const;
424
428 const SbVec3f &getCoordinate3(int index) const;
429
433 const SbVec4f &getCoordinate4(int index) const;
434
439
444
449
453 u_short getLinePattern() const;
454
459
463 float getLineWidth() const;
464
468 float getPointSize() const;
469
471
475 const SbString & getFontName() const;
476
480 float getFontSize() const;
481
486
488
492
497
499
504 void getMaterial(SbColor &ambient,
505 SbColor &diffuse,
506 SbColor &specular,
507 SbColor &emission,
508 float &shininess,
509 float &transparency,
510 int mtlIndex = 0) const;
511
516
517
522
524
527 int32_t getNumNormals() const;
528
532 const SbVec3f & getNormal(int index) const;
533
538
540
544
548 const SbVec2f &getProfileCoordinate2(int index) const;
549
553 const SbVec3f &getProfileCoordinate3(int index) const;
554
558 const SoNodeList & getProfile() const;
559
561
565
570
575
579 float getCreaseAngle() const;
580
582
587
591 const SbVec2f &getTextureCoordinate2(int index) const;
592
596 const SbVec4f &getTextureCoordinate4(int index) const;
597
602
603#ifdef _WIN32
607 const SbColor getTextureBlendColor() const;
608#else
610#endif
611
618 const unsigned char *getTextureImage(SbVec2i32 &size, int &numComps) const;
619
624
629
634
639
648
650
653 const SbMatrix & getModelMatrix() const;
654
659
661
664 float getFocalDistance() const;
665
670
675
680
682
686
690 int32_t getSwitch() const;
691
696 void setCallbackAll(SbBool flag) { callbackAll = flag; }
697
702 SbBool isCallbackAll() const { return callbackAll; }
703
704#if 1 SoDEPRECATED
712 const unsigned char *getTextureImage(SbVec2s &size, int &numComps) const;
713
714#endif
716private:
717#ifdef _WIN32
718 void addPreCallback(SoType type, SoCallbackActionCB2 *cb, void *data);
719 void addPostCallback(SoType type, SoCallbackActionCB2 *cb, void *data);
720 void addPreTailCallback(SoCallbackActionCB2 *cb, void *data);
721 void addPostTailCallback(SoCallbackActionCB2 *cb, void *data);
722#endif
723
724 // Returns the current response
725 Response getCurrentResponse() const { return response; }
726
727 // Call the pre-callbacks and post-callbacks
728 virtual void invokePreCallbacks(const SoNode *node);
729 virtual void invokePostCallbacks(const SoNode *node);
730
731 // Call the primitive callbacks
732 virtual void invokeTriangleCallbacks(const SoShape *shape,
733 const SoPrimitiveVertex *v1,
734 const SoPrimitiveVertex *v2,
735 const SoPrimitiveVertex *v3);
736 virtual void invokeLineSegmentCallbacks(const SoShape *shape,
737 const SoPrimitiveVertex *v1,
738 const SoPrimitiveVertex *v2);
739 virtual void invokePointCallbacks(const SoShape *shape,
740 const SoPrimitiveVertex *v);
741
742 // Should primitives be generated for this shape?
743 virtual SbBool shouldGeneratePrimitives(const SoShape *shape) const;
744
745 private:
746
747 // This flag is used by the SoSwitch etc. nodes which must return a
748 // different result from its 'affectsState' method when called
749 // during a CallbackAction that is doing the callback on all children.
750 static SbBool duringCallbackAll;
751 static void initClass();
752 static void exitClass();
753
754 // Returns the node that caused the callback:
755 virtual SoNode *getCurPathTail();
756
757 // Set the current node during traversal:
758 void setCurrentNode(SoNode *node)
759 { currentNode = node;}
760
761 void setStartTransparencyType( SoGLRenderAction::TransparencyType type) {
762 transpType = type;
763 };
764
772 bool removeTriangleCallback(SoType type, SoTriangleCB *cb);
773
781 bool removeLineSegmentCallback(SoType type, SoLineSegmentCB *cb);
782
790 bool removePointCallback(SoType type, SoPointCB *cb);
791
800 bool removePostCallback(SoType type, SoCallbackActionCB *cb);
801
810 bool removePreCallback(SoType type, SoCallbackActionCB *cb);
811
812 enum CBFuncTypes
813 {
814 NONE=0,
815 PRE =1,
816 POST=2,
817 PRE_TAIL=4,
818 POST_TAIL=8,
819 ANY=PRE|POST|PRE_TAIL|POST_TAIL,
820 };
821
822 // get the container for the given type
823 // for same type ambiguity is solved using type
824 template< class T, int N >
825 SbPList& getCallbackList( );
826
827 private:
828 // Initiates action on graph
829 virtual void beginTraversal(SoNode *node);
830
831 // transforms vertices with the given matrix.
832 // this is used to transform points during a forward traversal for callback actions
833 void transformForwardTraversedVertices(const SbMatrix& model, size_t numVertices, SoPrimitiveVertex** vertices);
834
835 // Response from last callback
836 Response response;
837
838 private:
839 SbBool callbackAll; // Callback all children or follow
840 // normal traversal rules.
841 // Callback lists
842 SbPList preCallbackList;
843 SbPList postCallbackList;
844
845 SbPList preTailCallbackList;
846 SbPList postTailCallbackList;
847
848 SbPList triangleCallbackList;
849 SbPList lineSegmentCallbackList;
850 SbPList pointCallbackList;
851
852 // Node where the callback occurs:
853 SoNode *currentNode;
854
855 SoGLRenderAction::TransparencyType transpType; // Transparency quality type
856};
857
858#endif /* _SO_CALLBACK_ACTION_ */
859
void SoTriangleCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2, const SoPrimitiveVertex *v3)
void SoLineSegmentCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2)
void SoPointCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v)
#define SO_ACTION_HEADER(className)
Definition SoSubAction.h:69
Color vector class.
Definition SbColor.h:82
4x4 matrix class.
Definition SbMatrix.h:309
Character string stored in a hash table.
Definition SbName.h:162
List of generic (void *) pointers.
Definition SbPList.h:77
Class for smart character strings.
Definition SbString.h:202
2D vector class.
Definition SbVec.h:76
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
3D vector class.
Definition SbVec.h:932
4D vector class.
Definition SbVec.h:2214
3D viewing volume class.
Abstract base class for all actions.
Definition SoAction.h:132
Performs a generic traversal of a scene graph or path.
float getFocalDistance() const
Returns the current camera and viewing information from the state.
Response
Possible responses from a pre or post callback.
@ PRUNE
Do not traverse node's children, but continue traversal.
@ CONTINUE
Continue traversal as if nothing happened.
@ ABORT
Abort traversal.
const SbName & getTextureFileName() const
Returns texture information from the state.
const SbString & getFontName() const
Returns the current font information from the state.
SoDrawStyle::Style getDrawStyle() const
Returns the current drawing style information from the state.
float getCreaseAngle() const
Returns the current shape hints from the state.
const SbVec4f & getCoordinate4(int index) const
Returns the current coordinates from the state.
SoDEPRECATED const unsigned char * getTextureImage(SbVec2s &size, int &numComps) const
Returns texture information from the state.
SoTexture::Model getTextureModel() const
Returns the current texture mapping information from the state.
float getDecimationPercentage() const
Returns the current decimation percentage from the state.
SbBool isCallbackAll() const
Returns whether the callback uses normal traversal (switches, etc.) or whether it traverses every sin...
const SbMatrix & getTextureMatrix() const
Returns the current texture mapping information from the state.
SoUnits::Units getUnits() const
Returns the current units from the state.
SoGLRenderAction::TransparencyType getTransparencyType() const
Returns the current Transparency Type information from the state.
int32_t getNumNormals() const
Returns the current normal information from the state.
float getFontSize() const
Returns the current font information from the state.
void addPreTailCallback(SoCallbackActionCB *cb, void *data)
Sets up a callback function to call when the action is applied to a path.
const SbColor & getTextureBlendColor() const
void getMaterial(SbColor &ambient, SbColor &diffuse, SbColor &specular, SbColor &emission, float &shininess, float &transparency, int mtlIndex=0) const
Returns the current material information from the state.
SoTexture::Wrap getTextureWrapT() const
Returns the current texture mapping information from the state.
const SbViewVolume & getViewVolume() const
Returns the current camera and viewing information from the state.
u_short getLinePattern() const
Returns the current drawing style information from the state.
void addPostTailCallback(SoCallbackActionCB *cb, void *data)
Sets up a callback function to call when the action is applied to a path.
float getPointSize() const
Returns the current drawing style information from the state.
SoMaterialBinding::Binding getMaterialBinding() const
Returns the current material information from the state.
SoShapeHints::ShapeType getShapeType() const
Returns the current shape hints from the state.
const SbMatrix & getProjectionMatrix() const
Returns the current camera and viewing information from the state.
int32_t getNumProfileCoordinates() const
Returns the current profiles and their coordinates from the state.
int32_t getNumCoordinates() const
Returns the current coordinates from the state.
int32_t getNumTextureCoordinates() const
Returns texture information from the state.
float getComplexity() const
Returns complexity information from the state.
void addPointCallback(SoType type, SoPointCB *cb, void *data)
Routine to add callbacks for generated primitives (points) for all shapes of the given type.
SoTextureCoordinateBinding::Binding getTextureCoordinateBinding() const
Returns texture information from the state.
float getLineWidth() const
Returns the current drawing style information from the state.
const SbVec2f & getTextureCoordinate2(int index) const
Returns texture information from the state.
SoLightModel::Model getLightModel() const
Returns the current lighting model information from the state.
Response SoCallbackActionCB(void *userData, SoCallbackAction *action, const SoNode *node)
The SoCallbackActionCB typedef is defined within the class, since it needs to refer to the Response e...
void addTriangleCallback(SoType type, SoTriangleCB *cb, void *data)
Routine to add callbacks for generated primitives (triangles) for all shapes of the given type.
const SbVec4f & getTextureCoordinate4(int index) const
Returns texture information from the state.
const SbVec3f & getNormal(int index) const
Returns the current normal information from the state.
SoPickStyle::Style getPickStyle() const
Returns the current picking style.
const SbMatrix & getModelMatrix() const
Returns the current modeling transformation from the state.
void addPreCallback(SoType type, SoCallbackActionCB *cb, void *data)
Adds a callback function to call when a node of the given type is encountered during traversal.
const SoTexture2Transform * getTextureTransformNode() const
Returns the current texture mapping information from the state.
void addLineSegmentCallback(SoType type, SoLineSegmentCB *cb, void *data)
Routine to add callbacks for generated primitives (line segments) for all shapes of the given type.
const SoNodeList & getProfile() const
Returns the current profiles and their coordinates from the state.
const unsigned char * getTextureImage(SbVec2i32 &size, int &numComps) const
Returns texture information from the state.
const SbVec2f & getProfileCoordinate2(int index) const
Returns the current profiles and their coordinates from the state.
void addPostCallback(SoType type, SoCallbackActionCB *cb, void *data)
Adds a callback function to call when a node of the given type is encountered during traversal.
const SbVec3f & getCoordinate3(int index) const
Returns the current coordinates from the state.
SoShapeHints::VertexOrdering getVertexOrdering() const
Returns the current shape hints from the state.
SoDecimationTypeElement::Type getDecimationType() const
Returns the current decimation type from the state.
const SbVec3f & getProfileCoordinate3(int index) const
Returns the current profiles and their coordinates from the state.
SoCallbackAction()
The constructor.
SoComplexity::Type getComplexityType() const
Returns complexity information from the state.
const SbMatrix & getViewingMatrix() const
Returns the current camera and viewing information from the state.
void setCallbackAll(SbBool flag)
Sets whether the callback uses normal traversal (switches, etc.) or whether it traverses every single...
SoTexture::Wrap getTextureWrapS() const
Returns the current texture mapping information from the state.
SoShapeHints::FaceType getFaceType() const
Returns the current shape hints from the state.
SoFont::RenderStyle getFontRenderStyle() const
Returns the current font information from the state.
const SbVec3f & getLightAttenuation() const
Returns the current lighting model information from the state.
int32_t getSwitch() const
Returns the current switch value.
SoNormalBinding::Binding getNormalBinding() const
Returns the current normal information from the state.
int getLinePatternScaleFactor() const
Returns the current drawing style information from the state.
Type
These are the available decimation types.
Style
Draw styles.
RenderStyle
Render style.
Definition SoFont.h:327
TransparencyType
Transparency rendering algorithm.
Model
Lighting model.
Abstract base class for all database nodes.
Definition SoNode.h:145
Maintains a list of pointers to nodes.
Definition SoNodeList.h:74
Style
Picking style.
Definition SoPickStyle.h:99
Represents a vertex of a generated primitive.
FaceType
Hints about faces of shape: if all faces are known to be convex or not.
VertexOrdering
Hints about ordering of face vertices: if ordering of all vertices of all faces is known to be consis...
ShapeType
Hints about entire shape: if shape is known to be a solid object, as opposed to a surface.
Abstract base class for all shape nodes.
Definition SoShape.h:115
2D texture transformation node.
Wrap
Texture wrap type.
Definition SoTexture.h:407
Model
Texture Combiner Functions.
Definition SoTexture.h:359
Stores runtime type information.
Definition SoType.h:98
Units
Units.
Definition SoUnits.h:109
int SbBool
Boolean type.
Definition SbBase.h:87
size_t size() const