Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoPath.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 : 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-2023 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
57#include <Inventor/SoLists.h>
58#include <Inventor/lists/NodeIndex.h>
59#include <Inventor/STL/iostream>
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
361 friend std::ostream& operator << (std::ostream& os, const SoPath& path);
362
366 virtual SoType getTypeId() const;
367
372
381 static SoPath *getByName(const SbName &name);
390 static int getByName(const SbName &name, SoPathList &list);
391
392
393 private:
394 // Initializes path class
395 static void initClass();
396 static void exitClass();
397
399 SbEventHandler<SoPath*> m_onPathChange;
400
404 friend bool operator <(const SoPath &p1, const SoPath &p2);
405
406 // This is called when a node in the path chain has a child added.
407 // The passed index is the index of the new child
408 void insertIndex(SoNode *parent, int newIndex);
409
410 // This is called when a node in the path chain has a child removed.
411 // The passed index is the index of the child to be removed
412 void removeIndex(SoNode *parent, int oldIndex);
413
414 // This is called when a node in the path chain replaces a child.
415 // The passed index is the index of the child to be removed
416 void replaceIndex(SoNode *parent, int index, SoNode *newChild);
417
418 // Writes path using given write action
419 virtual void write(SoWriteAction *writeAction) const;
420
421 // Returns TRUE if the given notification list involves a change
422 // to a node that affects the path. It is assumed that the last
423 // (most recent) node in the list is the head node of the path.
424 SbBool isRelevantNotification(SoNotList *list) const;
425
426 void setNumPublic(int num);
427
428 // Appends the given node and index to the lists, updating
429 // numPublic as appropriate
430 void append(SoNode *node, int index);
431
432 // Appends the given node and index to the lists, updating
433 // numPublic as appropriate
434 void appendMI(SoNode *node, int index, int instanceIndex);
435
436 // like copy but let user copy path in a temp path (if temp == true)
437 SoPath *copy_(int startFromNodeIndex = 0, int numNodes = 0, bool createTempPath = false) const;
438
439 // Returns this path hash value
440 inline const size_t& getHash() const
441 {
442 if ( m_pathHash != static_cast< size_t >(-1) )
443 return m_pathHash; // No need to update... just return value.
444 return computeHash();
445 }
446
447 // Really does a truncate. Flag indicates whether to notify.
448 void truncate(int start, SbBool doNotify);
449
450 // Get nodes in a unsecured way: Only returns the found value without
451 // checking out-of-array access.
452 SoNode* u_getHead() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[0]); }
453 SoNode* u_getTail() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1]); }
454 SoNode* u_getNode(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[i]); }
455 SoNode* u_getNodeFromTail(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1 - i]); }
456 int u_getIndex(int i) const { return (int)indices[i].index; }
457 int u_getIndexFromTail(int i) const { return (int)indices[getLength() - 1 - i].index; }
458 int u_getInstanceIndex(int i) const { return (int)indices[i].instanceIndex; }
459
460 // Multiple instance API see SoMultipleInstance, SoMultipleCopy, SoArray
461
466 void setHeadMI(SoNode *node, int instanceIndex);
467
473 void appendMI(int childIndex, int instanceIndex);
474
481 void appendMI(SoNode *childNode, int instanceIndex);
482
487 void pushMI(int childIndex, int instanceIndex);
488
489 bool isForwardTraversing() const;
490
491 private:
492 // Allows internal SoTempPath subclass to forego auditor overhead
493 void auditPath(SbBool flag) { doAuditors = flag; }
494
495 // Reads stuff into instance of SoPath. Returns FALSE on error.
496 virtual SbBool readInstance(SoInput *in, unsigned short flags);
497
498 virtual ~SoPath();
499
500 private:
501 const size_t& computeHash() const;
502
503 SoNodeList nodes; // Pointers to nodes
504 std::vector<inventor::NodeIndex> indices; // Child indices
505 mutable int numPublic; // How many children are public
506 mutable int minNumPublic; // Minimum we KNOW are public
507 SbBool doAuditors; // TRUE if auditors to be maintained
508 static SoType classTypeId; // TypeId of paths
509
510 // Returns real length of path, including hidden children
511 int getFullLength() const
512 { return nodes.getLength(); }
513
514 // Returns new SoPath; called by SoType::createInstance()
515 static void* createInstance(SoType* dynamicType = NULL);
516
517 // This path hash value
518 mutable size_t m_pathHash;
519
520 friend class SoFullPath;
521 friend class SoTempPath;
522 friend class SoAction;
523 friend class SoPathNoRef;
525
526};
527
529//
530// Class: SoFullPath
531//
532// This
533// children in paths. SoPath allows access from the head node down to
534// the first node with hidden children, but no further. Casting an
535// SoPath to an SoFullPath (which is always guaranteed to be safe)
536// allows you to get at hidden children. SoFullPath overrides some of
537// the methods defined on paths to make this possible.
538//
540
604class SoFullPath : public SoPath {
605
606 public:
607 //
608 // Override methods that normally stop at last public child:
609 //
611 void pop()
612 { truncate(getFullLength() - 1); }
613
616 { return (nodes[getFullLength() - 1]); }
617
620 { return (nodes[getFullLength() - 1 - i]); }
621
623 int getIndexFromTail(int i) const
624 {
625 return indices[getFullLength() - 1 - i].index;
626 }
627
630 {
631 return indices[getFullLength() - 1 - i].instanceIndex;
632 }
633
635 int getLength() const
636 { return getFullLength(); }
637
638 private:
639 SoFullPath(int approxLength) : SoPath(approxLength) {}
640 virtual ~SoFullPath();
641
642 friend class SoTempPath;
643};
644
645#ifndef HIDDEN_FROM_DOC
646
648//
649// SoINTERNAL Class: SoLightPath
650//
651// A SoLightPath is a light-weight version of an SoTempPath, intended to
652// be used just to keep track of the current path during traversal.
653// Eventually it is intended to replace SoTempPath (when appropriate
654// modifications are made to SoDraggers).
655// Unlike SoPath, it keeps only a chain of childIndices and a headnode.
656// The methods implemented are only those needed for traversal.
657//
659
660
661class SoLightPath {
662
663 private:
664
665 // Constructor given approximate number of nodes in chain
666 SoLightPath(int approxLength=0);
667
668 SoLightPath(const SoLightPath& other);
669
670 // Sets head node (first node in chain)
671 // Resulting path has only one node.
672 void setHead(SoNode *node);
673
674 // Adds node specified by child index to end of chain.
675 void append(int childIndex)
676 { indices.push_back(inventor::NodeIndex(childIndex, inventor::NodeIndex::NODE));}
677
678 // Adds node specified by child index along with its instanceIndex to end of chain.
679 void appendMI(int childIndex, int instanceIndex)
680 { indices.push_back(inventor::NodeIndex(childIndex, instanceIndex)); }
681
682
683 // Allows path to be treated as a stack: push a node at the end of
684 // the chain and pop the last node off
685 void push(int childIndex) { append(childIndex); }
686 void pushMI(int childIndex, int instanceIndex) { appendMI(childIndex, instanceIndex); }
687 void push() { append(-1);}
688 void pop() { truncate(getFullLength() - 1); }
689
690 void setTail(int childIndex)
691 {
692 setTail(childIndex, inventor::NodeIndex::NODE);
693 }
694
695 void setTail(int childIndex, int instanceIndex)
696 {
697 setTail(inventor::NodeIndex(childIndex, instanceIndex));
698 }
699
700 void setTail(const inventor::NodeIndex& index)
701 {
702 size_t tailPos = (size_t)(getFullLength()-1);
703 if ( tailPos >= indices.size() )
704 indices.resize(tailPos+1);
705 indices[tailPos] = index;
706 }
707
708 SoNode * getTail(){
709 return getNode(getFullLength()-1);
710 }
711
712 // Returns the first node in a path chain.
713 SoNode * getHead() const { return headNode; }
714
715 // Returns pointer to ith node in chain
716 SoNode * getNode(int i) const;
717
718 // BA - added getIndex
719 // Returns index of ith node in chain
720 int getIndex(int i) const
721 {
722 return indices[i].index;
723 }
724
725 // Returns index of ith node in chain
726 int getInstanceIndex(int i) const
727 { return indices[i].instanceIndex; }
728
729
730 // Returns full length of path chain (number of nodes)
731 // note that public/private distinction is ignored.
732 int getFullLength() const {return (int) indices.size();}
733
734 // Removes all nodes from indexed node on
735 void truncate(int start)
736 {
737 indices.resize(start > 0 ? start : 0);
738 }
739
740
741 // fills in nodes for a TempPath that is represented by this
742 // SoLightPath. Called by SoAction::getCurPath();
743 void makeTempPath(SoTempPath *) const;
744
745 SoLightPath& operator=(const SoLightPath& other);
746
747 private:
748
749 ~SoLightPath();
750 SoNode * headNode; // Pointer to headnode
751 mutable std::vector<inventor::NodeIndex> indices; // Child indices
752
753
754 friend class SoAction;
755};
756
757#endif // HIDDEN_FROM_DOC
758
762 std::ostream& operator << (std::ostream& os, const SoPath& path);
763
764#endif /* _SO_PATH_ */
765
void append(int integer)
virtual void push(SoState *state)
Override push() method to keep GL up to date.
int getIndex(const SoEngine *engine, const SoEngineOutput *output) const
std::ostream & operator<<(std::ostream &os, const SoPath &path)
Writes the path to the specified output stream.
void start()
SoBaseContextCache * getHead() const
valueRef operator=(valueRef newValue)
Sets this field to newValue.
Definition SoSubField.h:242
SoNode * getNode() const
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:604
friend class SoTempPath
Definition SoPath.h:642
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:611
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:619
int getLength() const
Returns length of path chain (number of nodes).
Definition SoPath.h:635
int getInstanceIndexFromTail(int i) const
get instance Index from tail
Definition SoPath.h:629
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:623
SoNode * getTail() const
Returns the last node in a path chain.
Definition SoPath.h:615
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:523
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:521
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:524
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:520
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
void truncate(int start)
void pop()