Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoPath.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 : Paul S. Strauss (MMM yyyy)
25** Modified by : Nick Thompson (MMM yyyy)
26** Modified by : Alan Norton (MMM yyyy)
27**=======================================================================*/
28/*=======================================================================
29 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
30 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
31 *** ***
32 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
33 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
34 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
35 *** ***
36 *** RESTRICTED RIGHTS LEGEND ***
37 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
38 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
39 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
40 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
41 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
42 *** ***
43 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
44 *** BORDEAUX, FRANCE ***
45 *** ALL RIGHTS RESERVED ***
46**=======================================================================*/
47/*=======================================================================
48** Modified by : VSG (MMM YYYY)
49**=======================================================================*/
50
51
52#ifndef _SO_PATH_
53#define _SO_PATH_
54
55#include <Inventor/misc/SoBase.h>
56#include <Inventor/nodes/SoNode.h>
57#include <Inventor/SoLists.h>
58#include <Inventor/lists/NodeIndex.h>
59#include <Inventor/STL/iostream>
60#include <Inventor/SbEventHandler.h>
61
62class SoTempPath;
63
65//
66// Class: SoPath
67//
68// A SoPath represents a scene graph or subgraph. It contains
69// pointers to a chain of nodes, each of which is a child of the
70// previous. The child index of each node is also stored, to
71// disambiguate cases where a node appears more than once as a child
72// of the same group.
73//
74// The graph defined by the path consists of all of the nodes in the
75// path, all nodes below the last node in the chain, and any other
76// nodes that have an effect on these nodes.
77//
79
80class SoPathList;
81class SoWriteAction;
82
187class SoPath : public SoBase {
188
189 public:
190
195
199 SoPath(int approxLength);
200
205
210 void setHead(SoNode *node);
211
216 void append(int childIndex);
217
223 void append(SoNode *childNode);
224
229 void append(const SoPath *fromPath);
230
235 void push(int childIndex);
236
241 void pop();
242
246 SoNode* getHead() const { return (SoNode*)(nodes.get(0)); }
247
251 SoNode* getTail() const;
252
259 SoNode* getNode(int i) const;
260
267 SoNode* getNode(const SoType type, int &i) const;
268
269
276 SoNode* getNodeFromTail(int i) const;
277
282 int getIndex(int i) const;
283
288 int getInstanceIndex(int i) const;
289
296 int getIndexFromTail(int i) const;
297
305 int getInstanceIndexFromTail(int i) const;
306
311 int getLength() const;
312
318 void truncate(int start);
319
323 SbBool containsNode(const SoNode *node) const;
324
329 SbBool containsNode(const SoType type) const;
330
335 SbBool containsPath(const SoPath *path) const;
336
342 int findFork(const SoPath *path) const;
343
351 SoPath *copy(int startFromNodeIndex = 0, int numNodes = 0) const;
352
356 friend int operator ==(const SoPath &p1, const SoPath &p2);
357
364 friend int operator !=(const SoPath &p1, const SoPath &p2);
365
369 friend std::ostream& operator << (std::ostream& os, const SoPath& path);
370
374 virtual SoType getTypeId() const;
375
380
389 static SoPath *getByName(const SbName &name);
398 static int getByName(const SbName &name, SoPathList &list);
399
400
401 private:
402 // Initializes path class
403 static void initClass();
404 static void exitClass();
405
407 SbEventHandler<SoPath*> m_onPathChange;
408
412 friend bool operator <(const SoPath &p1, const SoPath &p2);
413
414 // This is called when a node in the path chain has a child added.
415 // The passed index is the index of the new child
416 void insertIndex(SoNode *parent, int newIndex);
417
418 // This is called when a node in the path chain has a child removed.
419 // The passed index is the index of the child to be removed
420 void removeIndex(SoNode *parent, int oldIndex);
421
422 // This is called when a node in the path chain replaces a child.
423 // The passed index is the index of the child to be removed
424 void replaceIndex(SoNode *parent, int index, SoNode *newChild);
425
426 // Writes path using given write action
427 virtual void write(SoWriteAction *writeAction) const;
428
429 // Returns TRUE if the given notification list involves a change
430 // to a node that affects the path. It is assumed that the last
431 // (most recent) node in the list is the head node of the path.
432 SbBool isRelevantNotification(SoNotList *list) const;
433
434 void setNumPublic(int num);
435
436 // Appends the given node and index to the lists, updating
437 // numPublic as appropriate
438 void append(SoNode *node, int index);
439
440 // Appends the given node and index to the lists, updating
441 // numPublic as appropriate
442 void appendMI(SoNode *node, int index, int instanceIndex);
443
444 // like copy but let user copy path in a temp path (if temp == true)
445 SoPath *copy_(int startFromNodeIndex = 0, int numNodes = 0, bool createTempPath = false) const;
446
447 // Returns this path hash value
448 inline const size_t& getHash() const
449 {
450 if ( m_pathHash != static_cast< size_t >(-1) )
451 return m_pathHash; // No need to update... just return value.
452 return computeHash();
453 }
454
455 // Really does a truncate. Flag indicates whether to notify.
456 void truncate(int start, SbBool doNotify);
457
458 // Get nodes in a unsecured way: Only returns the found value without
459 // checking out-of-array access.
460 SoNode* u_getHead() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[0]); }
461 SoNode* u_getTail() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1]); }
462 SoNode* u_getNode(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[i]); }
463 SoNode* u_getNodeFromTail(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1 - i]); }
464 int u_getIndex(int i) const { return (int)indices[i].index; }
465 int u_getIndexFromTail(int i) const { return (int)indices[getLength() - 1 - i].index; }
466 int u_getInstanceIndex(int i) const { return (int)indices[i].instanceIndex; }
467
468 // Multiple instance API see SoMultipleInstance, SoMultipleCopy, SoArray
469
474 void setHeadMI(SoNode *node, int instanceIndex);
475
481 void appendMI(int childIndex, int instanceIndex);
482
489 void appendMI(SoNode *childNode, int instanceIndex);
490
495 void pushMI(int childIndex, int instanceIndex);
496
497 bool isForwardTraversing() const;
498
499 private:
500 // Allows internal SoTempPath subclass to forego auditor overhead
501 void auditPath(SbBool flag) { doAuditors = flag; }
502
503 // Reads stuff into instance of SoPath. Returns FALSE on error.
504 virtual SbBool readInstance(SoInput *in, unsigned short flags);
505
506 virtual ~SoPath();
507
508 private:
509 const size_t& computeHash() const;
510
511 SoNodeList nodes; // Pointers to nodes
512 std::vector<inventor::NodeIndex> indices; // Child indices
513 mutable int numPublic; // How many children are public
514 mutable int minNumPublic; // Minimum we KNOW are public
515 SbBool doAuditors; // TRUE if auditors to be maintained
516 static SoType classTypeId; // TypeId of paths
517
518 // Returns real length of path, including hidden children
519 int getFullLength() const
520 { return nodes.getLength(); }
521
522 // Returns new SoPath; called by SoType::createInstance()
523 static void* createInstance(SoType* dynamicType = NULL);
524
525 // This path hash value
526 mutable size_t m_pathHash;
527
528 friend class SoFullPath;
529 friend class SoTempPath;
530 friend class SoAction;
531 friend class SoPathNoRef;
533
534};
535
537//
538// Class: SoFullPath
539//
540// This
541// children in paths. SoPath allows access from the head node down to
542// the first node with hidden children, but no further. Casting an
543// SoPath to an SoFullPath (which is always guaranteed to be safe)
544// allows you to get at hidden children. SoFullPath overrides some of
545// the methods defined on paths to make this possible.
546//
548
612class SoFullPath : public SoPath {
613
614 public:
615 //
616 // Override methods that normally stop at last public child:
617 //
619 void pop()
620 { truncate(getFullLength() - 1); }
621
624 { return (nodes[getFullLength() - 1]); }
625
628 { return (nodes[getFullLength() - 1 - i]); }
629
631 int getIndexFromTail(int i) const
632 {
633 return indices[getFullLength() - 1 - i].index;
634 }
635
638 {
639 return indices[getFullLength() - 1 - i].instanceIndex;
640 }
641
643 int getLength() const
644 { return getFullLength(); }
645
646 private:
647 SoFullPath(int approxLength) : SoPath(approxLength) {}
648 virtual ~SoFullPath();
649
650 friend class SoTempPath;
651};
652
653#ifndef HIDDEN_FROM_DOC
654
656//
657// SoINTERNAL Class: SoLightPath
658//
659// A SoLightPath is a light-weight version of an SoTempPath, intended to
660// be used just to keep track of the current path during traversal.
661// Eventually it is intended to replace SoTempPath (when appropriate
662// modifications are made to SoDraggers).
663// Unlike SoPath, it keeps only a chain of childIndices and a headnode.
664// The methods implemented are only those needed for traversal.
665//
667
668
669class SoLightPath {
670
671 private:
672
673 // Constructor given approximate number of nodes in chain
674 SoLightPath(int approxLength=0);
675
676 SoLightPath(const SoLightPath& other);
677
678 // Sets head node (first node in chain)
679 // Resulting path has only one node.
680 void setHead(SoNode *node);
681
682 // Adds node specified by child index to end of chain.
683 void append(int childIndex)
684 { indices.push_back(inventor::NodeIndex(childIndex, inventor::NodeIndex::NODE));}
685
686 // Adds node specified by child index along with its instanceIndex to end of chain.
687 void appendMI(int childIndex, int instanceIndex)
688 { indices.push_back(inventor::NodeIndex(childIndex, instanceIndex)); }
689
690
691 // Allows path to be treated as a stack: push a node at the end of
692 // the chain and pop the last node off
693 void push(int childIndex) { append(childIndex); }
694 void pushMI(int childIndex, int instanceIndex) { appendMI(childIndex, instanceIndex); }
695 void push() { append(-1);}
696 void pop() { truncate(getFullLength() - 1); }
697
698 void setTail(int childIndex)
699 {
700 setTail(childIndex, inventor::NodeIndex::NODE);
701 }
702
703 void setTail(int childIndex, int instanceIndex)
704 {
705 setTail(inventor::NodeIndex(childIndex, instanceIndex));
706 }
707
708 void setTail(const inventor::NodeIndex& index)
709 {
710 size_t tailPos = (size_t)(getFullLength()-1);
711 if ( tailPos >= indices.size() )
712 indices.resize(tailPos+1);
713 indices[tailPos] = index;
714 }
715
716 SoNode * getTail(){
717 return getNode(getFullLength()-1);
718 }
719
720 // Returns the first node in a path chain.
721 SoNode * getHead() const { return headNode; }
722
723 // Returns pointer to ith node in chain
724 SoNode * getNode(int i) const;
725
726 // BA - added getIndex
727 // Returns index of ith node in chain
728 int getIndex(int i) const
729 {
730 return indices[i].index;
731 }
732
733 // Returns index of ith node in chain
734 int getInstanceIndex(int i) const
735 { return indices[i].instanceIndex; }
736
737
738 // Returns full length of path chain (number of nodes)
739 // note that public/private distinction is ignored.
740 int getFullLength() const {return (int) indices.size();}
741
742 // Removes all nodes from indexed node on
743 void truncate(int start)
744 {
745 indices.resize(start > 0 ? start : 0);
746 }
747
748
749 // fills in nodes for a TempPath that is represented by this
750 // SoLightPath. Called by SoAction::getCurPath();
751 void makeTempPath(SoTempPath *) const;
752
753 SoLightPath& operator=(const SoLightPath& other);
754
755 private:
756
757 ~SoLightPath();
758 SoNode * headNode; // Pointer to headnode
759 mutable std::vector<inventor::NodeIndex> indices; // Child indices
760
761
762 friend class SoAction;
763};
764
765#endif // HIDDEN_FROM_DOC
766
770 std::ostream& operator << (std::ostream& os, const SoPath& path);
771
772#endif /* _SO_PATH_ */
773
Class representing an event.
Character string stored in a hash table.
Definition SbName.h:162
int getLength() const
Returns number of pointers in list.
Definition SbPList.h:125
Abstract base class for all actions.
Definition SoAction.h:132
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Path that allows access to hidden children.
Definition SoPath.h:612
friend class SoTempPath
Definition SoPath.h:650
void pop()
The push() and pop() methods allow a path to be treated as a stack; they push a node at the end of th...
Definition SoPath.h:619
SoNode * getNodeFromTail(int i) const
Returns the i'th node (within its parent) in the chain, counting backward from the tail node.
Definition SoPath.h:627
int getLength() const
Returns length of path chain (number of nodes).
Definition SoPath.h:643
int getInstanceIndexFromTail(int i) const
get instance Index from tail
Definition SoPath.h:637
int getIndexFromTail(int i) const
Returns the index of the i'th node (within its parent) in the chain, counting backward from the tail ...
Definition SoPath.h:631
SoNode * getTail() const
Returns the last node in a path chain.
Definition SoPath.h:623
Used to read Open Inventor data files.
Definition SoInput.h:363
Abstract base class for all database nodes.
Definition SoNode.h:145
Maintains a list of pointers to nodes.
Definition SoNodeList.h:74
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
friend class SoPathNoRef
Definition SoPath.h:531
int getInstanceIndexFromTail(int i) const
Returns the index of the i'th node instance (within its parent, if it is a SoMultipleInstance,...
SoPath()
Constructs an empty path.
friend std::ostream & operator<<(std::ostream &os, const SoPath &path)
Writes the path to the specified output stream.
SoPath(int approxLength)
Constructs a path with a hint to length (number of nodes in chain).
SoPath * copy(int startFromNodeIndex=0, int numNodes=0) const
Creates and returns a new path that is a copy of some or all of this path.
friend int operator==(const SoPath &p1, const SoPath &p2)
Returns TRUE if all nodes in the two path chains are identical.
SoPath(SoNode *node)
Constructs a path and sets the head node to the given node.
static int getByName(const SbName &name, SoPathList &list)
Method to return paths with a given name.
friend class SoTempPath
Definition SoPath.h:529
void pop()
The push() and pop() methods allow a path to be treated as a stack; they push a node at the end of th...
int getInstanceIndex(int i) const
Returns the index of the instance inside the parent SoMultipleInstance, SoMultipleCopy or SoArray gro...
SbBool containsNode(const SoNode *node) const
Returns TRUE if the node is found anywhere in the path chain.
SoNode * getNode(const SoType type, int &i) const
Returns the first node and its index, from the head of the given type in the chain.
void append(int childIndex)
Adds node to end of chain; the node is the childIndex'th child of the current tail node.
SoNode * getHead() const
Returns the first node in a path chain.
Definition SoPath.h:246
friend class SoTraversalPassImpl
Definition SoPath.h:532
int getLength() const
Returns length of path chain (number of nodes).
void setHead(SoNode *node)
Sets head node (first node in chain).
void append(SoNode *childNode)
Adds node to end of chain; uses the first occurrence of childNode as child of current tail node.
static SoType getClassTypeId()
Returns type identifier for SoPath class.
void truncate(int start)
Truncates the path chain, removing all nodes from index start on.
friend bool operator<(const SoPath &p1, const SoPath &p2)
Returns TRUE is p1 strictly less than p2: to provide a total order operation for SoPath.
SoNode * getNode(int i) const
Returns the i'th node (within its parent) in the chain.
int getIndex(int i) const
Returns the index of the i'th node (within its parent) in the chain.
SbBool containsPath(const SoPath *path) const
Returns TRUE if the nodes in the chain in the passed path are contained (in consecutive order) in thi...
int findFork(const SoPath *path) const
If the two paths have different head nodes, this returns -1.
void push(int childIndex)
The push() and pop() methods allow a path to be treated as a stack; they push a node at the end of th...
SoNode * getNodeFromTail(int i) const
Returns the i'th node (within its parent) in the chain, counting backward from the tail node.
int getIndexFromTail(int i) const
Returns the index of the i'th node (within its parent) in the chain, counting backward from the tail ...
virtual SoType getTypeId() const
Returns type identifier for path instance.
friend class SoFullPath
Definition SoPath.h:528
friend int operator!=(const SoPath &p1, const SoPath &p2)
Not equal operator.
static SoPath * getByName(const SbName &name)
Method to return a path with a given name.
SbBool containsNode(const SoType type) const
Returns TRUE if the node type is found anywhere in the path chain.
SoNode * getTail() const
Returns the last node in a path chain.
void append(const SoPath *fromPath)
Adds all nodes in fromPath's chain to end of chain; the head node of fromPath must be the same as or ...
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Stores runtime type information.
Definition SoType.h:98
Writes a scene graph to a file.
int SbBool
Boolean type.
Definition SbBase.h:87