Open Inventor Release 2024.1.2
 
Loading...
Searching...
No Matches
SoCallbackAction.h
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-2024 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>
55#include <Inventor/actions/SoSubAction.h>
56#include <Inventor/nodes/SoComplexity.h>
57#include <Inventor/nodes/SoDrawStyle.h>
58#include <Inventor/nodes/SoFont.h>
59#include <Inventor/nodes/SoLightModel.h>
60#include <Inventor/nodes/SoMaterialBinding.h>
61#include <Inventor/nodes/SoNormalBinding.h>
62#include <Inventor/nodes/SoPickStyle.h>
63#include <Inventor/nodes/SoShapeHints.h>
64#include <Inventor/nodes/SoTexture.h>
65#include <Inventor/nodes/SoTextureCoordinateBinding.h>
66#include <Inventor/nodes/SoUnits.h>
67#include <Inventor/elements/SoDecimationTypeElement.h>
68#include <Inventor/actions/SoGLRenderAction.h>
69
71class SoShape;
73
82typedef void SoTriangleCB(void *userData,
83 SoCallbackAction *action,
84 const SoPrimitiveVertex *v1,
85 const SoPrimitiveVertex *v2,
86 const SoPrimitiveVertex *v3);
95typedef void SoLineSegmentCB(void *userData,
96 SoCallbackAction *action,
97 const SoPrimitiveVertex *v1,
98 const SoPrimitiveVertex *v2);
107typedef void SoPointCB(void *userData,
108 SoCallbackAction *action,
109 const SoPrimitiveVertex *v);
110
111#ifdef _WIN32
112//JSG - Changed SoCallbackActionCB back to how it is done under unix,
113//SoCallbackActionCB2 is included for backward compatibility on Windows
114typedef int SoCallbackActionCB2(void *userData,
115 SoCallbackAction *action,
116 const SoNode *node);
117#endif
119//
120// Class: SoCallbackAction
121//
122// State accumulation action. This action performs a generic
123// traversal of a scene graph. The caller can register callback
124// functions to be called when specific types of nodes are traversed.
125//
127
306
307 SO_ACTION_HEADER(SoCallbackAction);
308
309 public:
310
326
335 typedef Response SoCallbackActionCB(void *userData,
336 SoCallbackAction *action,
337 const SoNode *node);
338
343
344 // Destructor
345#ifndef HIDDEN_FROM_DOC
346 virtual ~SoCallbackAction();
347#endif // HIDDEN_FROM_DOC
348
350 //
351 // Adding callback functions:
352 //
353
361 void addPreCallback(SoType type, SoCallbackActionCB *cb, void *data);
362
370 void addPostCallback(SoType type, SoCallbackActionCB *cb, void *data);
371
379
387
393 void addTriangleCallback(SoType type, SoTriangleCB *cb, void *data);
394
401 void addLineSegmentCallback(SoType type, SoLineSegmentCB *cb, void *data);
402
408 void addPointCallback(SoType type, SoPointCB *cb, void *data);
409
411 //
412 // Accessing state information from callbacks. Non-obvious return
413 // values are documented.
414 //
415
417
420 float getComplexity() const;
421
426
428
431 int32_t getNumCoordinates() const;
432
436 const SbVec3f &getCoordinate3(int index) const;
437
441 const SbVec4f &getCoordinate4(int index) const;
442
447
452
457
461 u_short getLinePattern() const;
462
467
471 float getLineWidth() const;
472
476 float getPointSize() const;
477
479
483 const SbString & getFontName() const;
484
488 float getFontSize() const;
489
494
496
500
505
507
512 void getMaterial(SbColor &ambient,
513 SbColor &diffuse,
514 SbColor &specular,
515 SbColor &emission,
516 float &shininess,
517 float &transparency,
518 int mtlIndex = 0) const;
519
524
525
530
532
535 int32_t getNumNormals() const;
536
540 const SbVec3f & getNormal(int index) const;
541
546
548
552
556 const SbVec2f &getProfileCoordinate2(int index) const;
557
561 const SbVec3f &getProfileCoordinate3(int index) const;
562
566 const SoNodeList & getProfile() const;
567
569
573
578
583
587 float getCreaseAngle() const;
588
590
595
599 const SbVec2f &getTextureCoordinate2(int index) const;
600
604 const SbVec4f &getTextureCoordinate4(int index) const;
605
610
611#ifdef _WIN32
615 const SbColor getTextureBlendColor() const;
616#else
618#endif
619
626 const unsigned char *getTextureImage(SbVec2i32 &size, int &numComps) const;
627
632
637
642
647
656
658
661 const SbMatrix & getModelMatrix() const;
662
667
669
672 float getFocalDistance() const;
673
678
683
688
690
694
698 int32_t getSwitch() const;
699
704 void setCallbackAll(SbBool flag) { callbackAll = flag; }
705
710 SbBool isCallbackAll() const { return callbackAll; }
711
712#if 1 SoDEPRECATED
720 const unsigned char *getTextureImage(SbVec2s &size, int &numComps) const;
721
722#endif
724private:
725#ifdef _WIN32
726 void addPreCallback(SoType type, SoCallbackActionCB2 *cb, void *data);
727 void addPostCallback(SoType type, SoCallbackActionCB2 *cb, void *data);
728 void addPreTailCallback(SoCallbackActionCB2 *cb, void *data);
729 void addPostTailCallback(SoCallbackActionCB2 *cb, void *data);
730#endif
731
732 // Returns the current response
733 Response getCurrentResponse() const { return response; }
734
735 // Call the pre-callbacks and post-callbacks
736 virtual void invokePreCallbacks(const SoNode *node);
737 virtual void invokePostCallbacks(const SoNode *node);
738
739 // Call the primitive callbacks
740 virtual void invokeTriangleCallbacks(const SoShape *shape,
741 const SoPrimitiveVertex *v1,
742 const SoPrimitiveVertex *v2,
743 const SoPrimitiveVertex *v3);
744 virtual void invokeLineSegmentCallbacks(const SoShape *shape,
745 const SoPrimitiveVertex *v1,
746 const SoPrimitiveVertex *v2);
747 virtual void invokePointCallbacks(const SoShape *shape,
748 const SoPrimitiveVertex *v);
749
750 // Should primitives be generated for this shape?
751 virtual SbBool shouldGeneratePrimitives(const SoShape *shape) const;
752
753 private:
754
755 // This flag is used by the SoSwitch etc. nodes which must return a
756 // different result from its 'affectsState' method when called
757 // during a CallbackAction that is doing the callback on all children.
758 static SbBool duringCallbackAll;
759 static void initClass();
760 static void exitClass();
761
762 // Returns the node that caused the callback:
763 virtual SoNode *getCurPathTail();
764
765 // Set the current node during traversal:
766 void setCurrentNode(SoNode *node)
767 { currentNode = node;}
768
769 void setStartTransparencyType( SoGLRenderAction::TransparencyType type) {
770 transpType = type;
771 };
772
780 bool removeTriangleCallback(SoType type, SoTriangleCB *cb);
781
789 bool removeLineSegmentCallback(SoType type, SoLineSegmentCB *cb);
790
798 bool removePointCallback(SoType type, SoPointCB *cb);
799
808 bool removePostCallback(SoType type, SoCallbackActionCB *cb);
809
818 bool removePreCallback(SoType type, SoCallbackActionCB *cb);
819
820 enum CBFuncTypes
821 {
822 NONE=0,
823 PRE =1,
824 POST=2,
825 PRE_TAIL=4,
826 POST_TAIL=8,
827 ANY=PRE|POST|PRE_TAIL|POST_TAIL,
828 };
829
830 // get the container for the given type
831 // for same type ambiguity is solved using type
832 template< class T, int N >
833 SbPList& getCallbackList( );
834
835 private:
836 // Initiates action on graph
837 virtual void beginTraversal(SoNode *node);
838
839 // transforms vertices with the given matrix.
840 // this is used to transform points during a forward traversal for callback actions
841 void transformForwardTraversedVertices(const SbMatrix& model, size_t numVertices, SoPrimitiveVertex** vertices);
842
843 // Response from last callback
844 Response response;
845
846 private:
847 SbBool callbackAll; // Callback all children or follow
848 // normal traversal rules.
849 // Callback lists
850 SbPList preCallbackList;
851 SbPList postCallbackList;
852
853 SbPList preTailCallbackList;
854 SbPList postTailCallbackList;
855
856 SbPList triangleCallbackList;
857 SbPList lineSegmentCallbackList;
858 SbPList pointCallbackList;
859
860 // Node where the callback occurs:
861 SoNode *currentNode;
862
863 SoGLRenderAction::TransparencyType transpType; // Transparency quality type
864};
865
866#endif /* _SO_CALLBACK_ACTION_ */
867
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.
void SoTriangleCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2, const SoPrimitiveVertex *v3)
Typedef for callback routine used with the callbacks for generating triangles primitives.
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.
void SoLineSegmentCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2)
Typedefs for callback routine used with the callbacks for generating line segments primitives.
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.
void SoPointCB(void *userData, SoCallbackAction *action, const SoPrimitiveVertex *v)
Typedefs for callback routine used with the callbacks for generating points primitives.
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.
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