H3D API  2.4.1
X3DGroupingNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __X3DGROUPINGNODE_H__
30 #define __X3DGROUPINGNODE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/X3DBoundedObject.h>
37 #include <H3D/ClipPlane.h>
38 #include <H3D/Profiling.h>
39 
40 namespace H3D {
41  class H3DRenderStateObject;
50  class H3DAPI_API X3DGroupingNode :
51  public X3DChildNode,
52  public X3DBoundedObject,
53  public H3DDisplayListObject{
54  public:
55 
61  class H3DAPI_API MFChild :
62  public DependentMFNode< X3DChildNode,
63  FieldRef< H3DDisplayListObject,
64  H3DDisplayListObject::DisplayList,
65  &H3DDisplayListObject::displayList >,
66  true > {
67  public:
69  typedef DependentMFNode<
74  true > MFChildBase;
75 
79  virtual ~MFChild() {
80  clear();
81  }
82 
84  virtual void onAdd( Node *n );
85 
87  virtual void onRemove( Node *n );
88 
89  private:
90  friend class X3DGroupingNode;
91  };
92 #ifdef __BORLANDC__
93  friend class MFChild;
94 #endif
95 
99  class H3DAPI_API AddChildren: public TypedMFNode< X3DChildNode > {
100  public:
101  virtual void onAdd( Node *n );
102  };
103 #ifdef __BORLANDC__
104  friend class AddChildren;
105 #endif
106 
110  class H3DAPI_API RemoveChildren: public TypedMFNode< X3DChildNode > {
111  public:
112  virtual void onAdd( Node *n );
113  };
114 #ifdef __BORLANDC__
115  friend class RemoveChildren;
116 #endif
117 
127  class H3DAPI_API SFBound:
128  public TypedField< X3DBoundedObject::SFBound,
129  void,
130  AnyNumber< X3DBoundedObject::SFBound > > {
133  virtual void update();
134  };
135 
137  X3DGroupingNode( Inst< AddChildren > _addChildren = 0,
138  Inst< RemoveChildren > _removeChildren = 0,
139  Inst< MFChild > _children = 0,
140  Inst< SFNode > _metadata = 0,
141  Inst< SFBound > _bound = 0,
142  Inst< SFVec3f > _bboxCenter = 0,
143  Inst< SFVec3f > _bboxSize = 0 );
144 
146  virtual ~X3DGroupingNode();
147 
153  virtual void initialize() {
154  const Vec3f &size = bboxSize->getValue();
155  if( size.x == -1 && size.y == -1 && size.z == -1 ) {
156  NodeVector children_nodes = children->getValue();
157  use_union_bound = true;
158  // set the values againg in order to run onNodeAdd again
159  // with use_union_bound set to true to set the routes.
160  children->setValue( children_nodes );
161  } else {
162  use_union_bound = false;
163  BoxBound *bb = new BoxBound();
164  bb->center->setValue( bboxCenter->getValue() );
165  bb->size->setValue( bboxSize->getValue() );
166  bound->setValue( bb );
167  }
169  }
170 
172  virtual void render();
173 
175  virtual void traverseSG( TraverseInfo &ti );
176 
184  virtual bool lineIntersect(
185  const Vec3f &from,
186  const Vec3f &to,
187  LineIntersectResult &result );
188 
195  virtual void closestPoint( const Vec3f &p,
196  NodeIntersectResult &result );
197 
206  virtual bool movingSphereIntersect( H3DFloat radius,
207  const Vec3f &from,
208  const Vec3f &to,
209  NodeIntersectResult &result );
210 
214 
222  H3DUniquePtr< AddChildren > addChildren;
223 
231  H3DUniquePtr< RemoveChildren > removeChildren;
232 
238  H3DUniquePtr< MFChild > children;
239 
242 
243 #ifdef HAVE_PROFILER
244  std::pair < H3DTime, H3DTime > getChildTimes ();
245 
246  H3DTime time_in_last_render;
247  H3DTime time_in_last_traverseSG;
248  H3DTime time_last_render;
249  H3DTime time_last_traverseSG;
250 #endif
251 
252  protected:
253  vector< X3DPointingDeviceSensorNode * > pt_dev_sensors;
254 
260 
262  vector< H3DRenderStateObject* > render_states;
263 
265  vector< ClipPlane * > clip_planes;
266  };
267 }
268 
269 #endif
Header file for ClipPlane, X3D scene-graph node.
Contains the DependentSFNode and DependentMFNode template classes.
Header file for H3DDisplayListObject.
Header file for .
Header file for X3DBoundedObject.
Header file for X3DChildNode, X3D scene-graph node.
Header file for X3DPointingDeviceSensorNode, X3D scene-graph node.
virtual void initialize()
The BoxBound is a Bound class that specifies the bound using an axis-aligned bounding box.
Definition: Bound.h:144
H3DUniquePtr< SFVec3f > center
The center point of the bounding box.
Definition: Bound.h:285
H3DUniquePtr< SFVec3f > size
The size of the bounding box.
Definition: Bound.h:287
DependentMFNode are modified TypedMFNode fields where the field dirty status is dependent on fields i...
Definition: DependentNodeFields.h:336
Class used for specifying a field member of a node in a DependentSFNode or DependentMFNode specificat...
Definition: DependentNodeFields.h:48
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
Template to make sure that the Nodes that are added to a MFNode are of a specified Node type.
Definition: MFNode.h:221
This X3D abstract interface type is basis for all X3D node types that have bounds specified as part o...
Definition: X3DBoundedObject.h:46
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
AddChildren is a class that adds any node added to it to the children field of its owner (X3DGrouping...
Definition: X3DGroupingNode.h:99
MFChild sets up a routes from the Nodes that are added and removed from the field to the owner of the...
Definition: X3DGroupingNode.h:66
virtual ~MFChild()
Destructor.
Definition: X3DGroupingNode.h:79
DependentMFNode< X3DChildNode, FieldRef< H3DDisplayListObject, H3DDisplayListObject::DisplayList, &H3DDisplayListObject::displayList >, true > MFChildBase
The base class of MFChild.
Definition: X3DGroupingNode.h:74
RemoveChildren is a class that removes any node added to it from the children field of its owner (X3D...
Definition: X3DGroupingNode.h:110
SFBound is specialized to update from the SFBound fields routed to it.
Definition: X3DGroupingNode.h:130
This abstract node type indicates that concrete node types derived from it contain children nodes and...
Definition: X3DGroupingNode.h:53
virtual void initialize()
Sets up the bound field using the bboxCenter and bboxSize fields.
Definition: X3DGroupingNode.h:153
H3DUniquePtr< AddChildren > addChildren
The addChildren event appends nodes to the children field of a grouping node.
Definition: X3DGroupingNode.h:222
H3DUniquePtr< MFChild > children
The nodes that are grouped together by this node.
Definition: X3DGroupingNode.h:238
vector< H3DRenderStateObject * > render_states
A vector of all the H3DRenderStatesObject within this X3DGroupingNode.
Definition: X3DGroupingNode.h:262
bool use_union_bound
if true a route will be set up between the bound field of the nodes in children and the bound field o...
Definition: X3DGroupingNode.h:213
vector< ClipPlane * > clip_planes
A vector of only ClipPlane children of this X3DGroupingNode.
Definition: X3DGroupingNode.h:265
H3DUniquePtr< RemoveChildren > removeChildren
The removeChildren event removes nodes from the children field of the grouping node .
Definition: X3DGroupingNode.h:231
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DGroupingNode.h:241
bool children_multi_pass_transparency
Will be set in traverseSG to indicate if any of the children enables multi-pass transparency.
Definition: X3DGroupingNode.h:259
float H3DFloat
double H3DTime
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194