GteNode.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteSpatial.h>
11 #include <memory>
12 
13 namespace gte
14 {
15 
16 // This class represents grouping nodes in a spatial hiearchy.
17 
18 class GTE_IMPEXP Node : public Spatial
19 {
20 public:
21  // Construction and destruction.
22  virtual ~Node();
23  Node();
24 
25  // This is the current number of elements in the child array. These
26  // elements are not all guaranteed to be non-null. Thus, when you
27  // iterate over the array and access children with GetChild(...), you
28  // should verify the child pointer is not null before dereferencing it.
29  int GetNumChildren() const;
30 
31  // Attach a child to this node. If the function succeeds, the return
32  // value is the index i of the array where the child was stored, in which
33  // case 0 <= i < GetNumChildren(). The first available empty slot of the
34  // child array is used for storage. If all slots are filled, the child
35  // is appended to the array (potentially causing a reallocation of the
36  // array).
37  //
38  // The function fails when 'child' is null or when 'child' already has a
39  // parent, in which case the return value is -1. The nodes form a tree,
40  // not a more general directed acyclic graph. A consequence is that a
41  // node cannot have more than one parent. For example,
42  // Node* node0 = <some node>;
43  // Spatial* child = <some child>;
44  // int index = node0->AttachChild(child);
45  // Node* node1 = <some node>;
46  //
47  // // This asserts because 'child' already has a parent (node0).
48  // node1->AttachChild(child);
49  //
50  // // The following is the correct way to give 'child' a new parent.
51  // node0->DetachChild(child); // or node0->DetachChildAt(index);
52  // node1->AttachChild(child);
53  //
54  // // In the last example before the DetachChild call, if 'child' is
55  // // referenced only by node0, the detach will cause 'child' to be
56  // // deleted (Node internally reference counts its children). If
57  // // you want to keep 'child' around for later use, do the following.
58  // Spatial::SP saveChild = SPCreate(node0->GetChild(0));
59  // node0->DetachChild(saveChild);
60  // node1->AttachChild(saveChild);
61  int AttachChild(std::shared_ptr<Spatial> const& child);
62 
63  // Detach a child from this node. If the 'child' is non-null and in the
64  // array, the return value is the index in the array that had stored the
65  // child. Otherwise, the function returns -1.
66  int DetachChild(std::shared_ptr<Spatial> const& child);
67 
68  // Detach a child from this node. If 0 <= i < GetNumChildren(), the
69  // return value is the child at index i; otherwise, the function returns
70  // null.
71  std::shared_ptr<Spatial> DetachChildAt(int i);
72 
73  // Detach all children from this node.
74  void DetachAllChildren();
75 
76  // The same comments for AttachChild apply here regarding the inability
77  // to have multiple parents. If 0 <= i < GetNumChildren(), the function
78  // succeeds and returns i. If i is out of range, the function *still*
79  // succeeds, appending the child to the end of the array. The return
80  // value is the previous child stored at index i.
81  std::shared_ptr<Spatial> SetChild(int i,
82  std::shared_ptr<Spatial> const& child);
83 
84  // Get the child at the specified index. If 0 <= i < GetNumChildren(),
85  // the function succeeds and returns the child at that index. Keep in
86  // mind that child[i] could very well be null. If i is out of range, the
87  // function returns null.
88  std::shared_ptr<Spatial> GetChild(int i);
89 
90 protected:
91  // Support for geometric updates.
92  virtual void UpdateWorldData(double applicationTime);
93  virtual void UpdateWorldBound();
94 
95  // Support for hierarchical culling.
96  virtual void GetVisibleSet(Culler& culler,
97  std::shared_ptr<Camera> const& camera, bool noCull);
98 
99  // Child pointers.
100  std::vector<std::shared_ptr<Spatial>> mChild;
101 };
102 
103 }
std::vector< std::shared_ptr< Spatial > > mChild
Definition: GteNode.h:100
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01