AGX Dynamics  2.37.3.2
RigidBodyRenderCache.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxOSG/export.h>
20 #include <agx/Math.h>
21 #include <agx/Referenced.h>
22 #include <agx/RigidBody.h>
23 #include <agxOSG/GeometryNode.h>
24 
25 
26 namespace agxOSG
27 {
37  {
38  public:
45  {
46  public:
47 
49  m_group(nullptr) { }
50 
51  RigidBodyVisualGroup(osg::Group* group, std::vector<size_t> geometryIndex) :
52  m_group(group), m_geometryIndices(geometryIndex) { }
53 
54  agxCollide::GeometryRef getGeometry(agx::RigidBody* newBody, size_t visualIndex) const;
55 
56  bool isValid() const { return m_group != nullptr; }
57 
58  size_t getNumChildren() const { return isValid() ? m_group->getNumChildren() : 0; }
59 
60  osg::Group* getGroup() const { return m_group; }
61 
62  private:
63  osg::ref_ptr<osg::Group> m_group;
64  // a list with indices linking each visual node (child in m_group) to a geometry in the rigid body
65  std::vector<size_t> m_geometryIndices;
66  };
67 
68  public:
74  RigidBodyRenderCache(bool onlyAddEmittedBodies=true);
75 
80  void addToCache(osg::Group* rootNode);
81 
86  osg::Group* getNode(agx::RigidBody* body);
87 
91  bool getOnlyAddEmittedBodies() const;
92 
96  void setOnlyAddEmittedBodies( bool enable );
97 
104  const RigidBodyRenderCache::RigidBodyVisualGroup& addTemplateBodyToVisualCache( agx::RigidBody* body );
105 
111  const RigidBodyRenderCache::RigidBodyVisualGroup& getCachedTemplateBodyVisual( agx::RigidBody* body );
112 
122  const RigidBodyRenderCache::RigidBodyVisualGroup& getOrCreateCachedTemplateBodyNode( agx::RigidBody* body );
123 
130  bool bodyIsTemplateEmitted( agx::RigidBody* body );
131 
135  void clear();
136 
137  protected:
138  virtual ~RigidBodyRenderCache();
139  void traverseAndInsert(osg::Group* rootNode);
140  bool shouldAddBody(agx::RigidBody* body) const;
141 
142  private:
145 
146  BodyToGroupNodeTable m_bodiesToGroupNodes;
147  BodyToRenderGroupTable m_bodiesToRenderGroups;
148  bool m_onlyAddEmittedBodies;
149  // A placeholder for an empty visualization group
151  };
152 }
AGXTERRAIN_EXPORT void clear()
#define AGXOSG_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Base class providing referencing counted objects.
Definition: Referenced.h:119
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition: WireUtils.h:392
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
A help class to store all information we need to copy a rigid body visualization to duplicate the rig...
RigidBodyRenderCache is used to cache generated visuals and lookup mappings of RigidBodies cloned fro...
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Inheritance with partial specialization due to bug with ref_ptr containers.
RigidBodyVisualGroup(osg::Group *group, std::vector< size_t > geometryIndex)