AGX Dynamics  2.38.0.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 
227 #endif
228  };
229 
230 }
GuiEventListener.h
agx::Real
double Real
Definition: Real.h:42
agxOSG::ForceArrowRenderer::ConstraintData
Definition: ForceArrowRenderer.h:184
Statistic.h
agxSDK::GuiEventListener
Derive from this class to implement a listener for simulation GuiEvents.
Definition: agxSDK/GuiEventListener.h:51
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxOSG::ForceArrowRenderer::ConstraintData::statisticsMask
ConstraintForceStatistics statisticsMask
Definition: ForceArrowRenderer.h:201
agx::Constraint1DOF
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:673
agxOSG::ForceArrowRenderer::FRICTION_X
@ FRICTION_X
Definition: ForceArrowRenderer.h:170
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
HashVector.h
Constraint.h
agxOSG::ForceArrowRenderer::BodyData
Definition: ForceArrowRenderer.h:205
agxOSG::ForceArrowRenderer::m_bodies
RigidBodyHashVector m_bodies
Definition: ForceArrowRenderer.h:226
agxOSG::ForceArrowRenderer::m_enabled
agx::Bool m_enabled
Definition: ForceArrowRenderer.h:155
agxOSG::ForceArrowRenderer::BodyData::color
agxRender::Color color
Definition: ForceArrowRenderer.h:219
agxOSG::ForceArrowRenderer::ConstraintData::constraint
agx::Constraint1DOFObserver constraint
Definition: ForceArrowRenderer.h:198
agxOSG::ForceArrowRenderer::ConstraintData::statistic
agx::ref_ptr< RendererStatistic > statistic
Definition: ForceArrowRenderer.h:199
agxRender::Color::Red
static agxRender::Color Red()
Definition: Color.h:153
agx::observer_ptr< Constraint1DOF >
agxOSG::ForceArrowRenderer::m_smoothFactor
agx::Real m_smoothFactor
Definition: ForceArrowRenderer.h:156
agxOSG::ForceArrowRenderer::Statistic
Definition: ForceArrowRenderer.h:177
agxOSG::ForceArrowRenderer::RendererStatistic
Statistic< agxUtil::ExponentialMovingAverageStatistic > RendererStatistic
Definition: ForceArrowRenderer.h:182
agxOSG::ForceArrowRenderer::NORMAL_Y
@ NORMAL_Y
Definition: ForceArrowRenderer.h:168
agxOSG::ForceArrowRenderer::m_arrowRadius
agx::Real m_arrowRadius
Definition: ForceArrowRenderer.h:158
agxRender::Color
Utility color class with "common colors".
Definition: Color.h:33
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
agxOSG::ForceArrowRenderer::BodyData::relative
agx::Vec3 relative
Definition: ForceArrowRenderer.h:218
agxOSG::ForceArrowRenderer::FRICTION_Y
@ FRICTION_Y
Definition: ForceArrowRenderer.h:171
agxOSG::ForceArrowRenderer::RigidBodyHashVector
agx::HashVector< agx::RigidBody *, agx::ref_ptr< BodyData > > RigidBodyHashVector
Definition: ForceArrowRenderer.h:223
agxOSG::ForceArrowRenderer::BodyData::statistics
agx::Vector< agx::ref_ptr< RendererStatistic > > statistics
Definition: ForceArrowRenderer.h:217
agxOSG::ForceArrowRenderer::ContactForceStatistics
ContactForceStatistics
Contact force directions.
Definition: ForceArrowRenderer.h:165
agxOSG::ForceArrowRenderer::m_constraints
ConstraintHashVector m_constraints
Definition: ForceArrowRenderer.h:225
agxOSG::ForceArrowRenderer::ConstraintData::relative
agx::Vec3 relative
Definition: ForceArrowRenderer.h:200
agxOSG::ForceArrowRenderer::BodyData::BodyData
BodyData(agx::RigidBody *b, agx::Real smoothFactor, const agx::Vec3 &r, const agxRender::Color &c)
Definition: ForceArrowRenderer.h:207
agxOSG::ForceArrowRenderer::m_scale
agx::Real m_scale
Definition: ForceArrowRenderer.h:159
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
agxOSG::ForceArrowRenderer::ConstraintForceStatistics
ConstraintForceStatistics
Specifies which secondary constraints that should be included in the statistics.
Definition: ForceArrowRenderer.h:45
agxOSG::ForceArrowRenderer
Creates an arrow visualizing force, either contact force (for added bodies), or motor force for added...
Definition: ForceArrowRenderer.h:38
agx::Bool
bool Bool
Definition: Integer.h:40
agxOSG::ForceArrowRenderer::FRICTION_Z
@ FRICTION_Z
Definition: ForceArrowRenderer.h:172
export.h
Color.h
agx::Vec3T< Real >
agxOSG::ForceArrowRenderer::BodyData::body
agx::RigidBodyObserver body
Definition: ForceArrowRenderer.h:216
agxOSG::ForceArrowRenderer::ConstraintData::color
agxRender::Color color
Definition: ForceArrowRenderer.h:202
agxOSG::ForceArrowRenderer::NORMAL_Z
@ NORMAL_Z
Definition: ForceArrowRenderer.h:169
agxOSG::ForceArrowRenderer::m_coneHeight
agx::Real m_coneHeight
Definition: ForceArrowRenderer.h:157
agx::HashVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
agxOSG::ForceArrowRenderer::ConstraintHashVector
agx::HashVector< agx::Constraint1DOF *, agx::ref_ptr< ConstraintData > > ConstraintHashVector
Definition: ForceArrowRenderer.h:222
AGXOSG_EXPORT
#define AGXOSG_EXPORT
agxOSG::ForceArrowRenderer::ConstraintData::ConstraintData
ConstraintData(agx::Constraint1DOF *c, RendererStatistic *s, const agx::Vec3 &r, const agxRender::Color &col, ConstraintForceStatistics mask)
Definition: ForceArrowRenderer.h:186