AGX Dynamics  2.37.3.2
ForceArrowRenderer.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 #include <agxOSG/export.h>
20 #include <agx/HashVector.h>
21 #include <agx/Constraint.h>
22 #include <agxUtil/Statistic.h>
23 #include <agxRender/Color.h>
24 
25 namespace agxOSG
26 {
39  {
40  public:
41 
46  {
47  MOTOR1D = 0x1,
48  RANGE1D = 0x2,
49  LOCK1D = 0x4,
50  ALL = MOTOR1D | RANGE1D | LOCK1D,
51  DEFAULT = MOTOR1D
52  };
53 
56 
64  bool add(agx::RigidBody* body, const agx::Vec3& localOffsetRelBody, const agxRender::Color& color = agxRender::Color::Red());
65 
71  agx::Bool remove(agx::RigidBody* body);
72 
73 
74  /*
75  Add a 1DOF constraint. The sum of the motor forces are visualized with one arrow.
76  \param constraint - The constraint that should be added.
77  \param localOffsetRelBody1 - the start point of the arrow relative the first rigid body of the first constraint.
78  \param color - Color of the arrow.
79  \param statisticsMask - Selects which forces that should be part of the calculation of the length of the force vector.
80  \return true if constraint is successfully added.
81  */
82  bool add(agx::Constraint1DOF* constraint, const agx::Vec3& localOffsetRelBody1, const agxRender::Color& color = agxRender::Color::Red(), ConstraintForceStatistics statisticsMask = DEFAULT);
83 
88  agx::Bool remove(agx::Constraint1DOF* constraint);
89 
96  agx::Bool setColor(agx::RigidBody* body, const agxRender::Color& color);
97 
104  agx::Bool setColor(agx::Constraint1DOF* constraint, const agxRender::Color& color);
105 
110  void setSmoothFactor(agx::Real smoothFactor);
111 
115  agx::Real getSmoothFactor() const;
116 
121  void setConeHeight(agx::Real height);
122 
124  agx::Real getConeHeight() const;
125 
130  void setArrowRadius(agx::Real radius);
131 
135  agx::Real getArrowRadius() const;
136 
141  void setScale(agx::Real scale);
142 
146  agx::Real getScale() const;
147 
148 
149  protected:
150  virtual void update(float x, float y);
151  virtual ~ForceArrowRenderer();
152 
153  void drawArrow(const agx::Vec3& start, const agx::Vec3& force, const agxRender::Color& color);
154 
160 
161 #ifndef SWIG
162 
166  {
167  NORMAL_X = 0,
173  NUM_FORCES
174  };
175 
176  template<typename T>
177  struct Statistic : public agx::Referenced, public T
178  {
179  using T::T;
180  };
181 
183 
185  public:
188  RendererStatistic* s,
189  const agx::Vec3& r,
190  const agxRender::Color& col,
191  ConstraintForceStatistics mask) : constraint(c),
192  statistic(s),
193  relative(r),
194  statisticsMask(mask),
195  color(col) {}
196 
197 
203  };
204 
205  class BodyData : public agx::Referenced {
206  public:
208  agx::Real smoothFactor,
209  const agx::Vec3& r,
210  const agxRender::Color& c) : body(b), relative(r), color(c)
211  {
212  for (int i = 0; i < NUM_FORCES; i++)
213  statistics.push_back(new RendererStatistic(smoothFactor));
214  }
215 
220  };
221 
224 
225  ConstraintHashVector m_constraints;
226  RigidBodyHashVector m_bodies;
227 #endif
228  };
229 
230 }
BodyData(agx::RigidBody *b, agx::Real smoothFactor, const agx::Vec3 &r, const agxRender::Color &c)
agx::Vector< agx::ref_ptr< RendererStatistic > > statistics
#define AGXOSG_EXPORT
bool Bool
Definition: Integer.h:48
Statistic< agxUtil::ExponentialMovingAverageStatistic > RendererStatistic
ConstraintForceStatistics
Specifies which secondary constraints that should be included in the statistics.
agx::HashVector< agx::RigidBody *, agx::ref_ptr< BodyData > > RigidBodyHashVector
Utility color class with "common colors".
Definition: Color.h:33
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:673
agx::HashVector< agx::Constraint1DOF *, agx::ref_ptr< ConstraintData > > ConstraintHashVector
Base class providing referencing counted objects.
Definition: Referenced.h:119
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
Templated vector class.
Definition: Vector.h:52
ConstraintData(agx::Constraint1DOF *c, RendererStatistic *s, const agx::Vec3 &r, const agxRender::Color &col, ConstraintForceStatistics mask)
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
Derive from this class to implement a listener for simulation GuiEvents.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
ConstraintHashVector m_constraints
double Real
Definition: Real.h:42
agx::ref_ptr< RendererStatistic > statistic
static agxRender::Color Red()
Definition: Color.h:153
Creates an arrow visualizing force, either contact force (for added bodies), or motor force for added...
ContactForceStatistics
Contact force directions.
RigidBodyHashVector m_bodies