AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
DimensionState.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17
18#ifndef AGX_POWERLINE_PHYSICAL_DIMENSION_STATE_H
19#define AGX_POWERLINE_PHYSICAL_DIMENSION_STATE_H
20
21#include <agx/Real.h>
22#include <agx/Integer.h>
23#include <agx/Jacobian.h>
24#include <agx/RigidBody.h>
25#include <agx/Referenced.h>
26#include <agx/MergedBody.h>
27#include <agx/Logger.h>
28
31
32#include <agxModel/export.h>
33
35
36
37namespace agxPowerLine
38{
39 class SlotMapper;
40 class PhysicalDimension;
41 class PowerLine;
42}
43
44
45
46namespace agxPowerLine
47{
48 namespace detail
49 {
72 {
73 public:
74 virtual agx::Real getValue() const = 0;
75 virtual void setValue(agx::Real value) = 0;
76
77 virtual agx::Real getGradient() const = 0;
78 virtual void setGradient(agx::Real value) = 0;
79
80 virtual agx::Real getSecondGradient() const = 0;
81
82 virtual agx::Vec3 getLocalDirection() const = 0;
83 virtual agx::Vec3 getWorldDirection() const = 0;
84 virtual agx::Vec3 getDirection() const = 0;
86
87 virtual agx::Real getMassProperty() const = 0;
88 virtual bool setMassProperty(agx::Real massProperty) = 0;
89
90 virtual void addLoad(agx::Real load) = 0;
91
92 virtual void setVelocityDamping(float damping) = 0;
93 virtual float getVelocityDamping() = 0;
94
99 virtual bool isExternalBody() const = 0;
100
104 bool getAllowsPacking() const;
105
112 virtual void reserveBody() = 0;
113
121 virtual const agx::RigidBody* getReservedBody() const = 0;
122
123
130
135
136 virtual void calculateJacobian(agx::Jacobian6DOFElement* G, agx::Real ratio, size_t index) const = 0;
137
138 virtual void addNotification(agxPowerLine::PowerLine* powerLine) = 0;
139 virtual void removeNotification(agxPowerLine::PowerLine* powerLine) = 0;
140
141 virtual void postUpdate(agx::Real timeStep) = 0;
142
143 AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agxPowerLine::DimensionState)
144 virtual void store(agxStream::OutputArchive& out) const override;
145 virtual void restore(agxStream::InputArchive& in) override;
146
147 virtual bool store(agxStream::StorageStream& out) const;
148 virtual bool restore(agxStream::StorageStream& in);
149
150 protected:
151 DimensionState(agx::RigidBody* body, PhysicalDimension* dimension, bool allowPacking);
152
153 virtual ~DimensionState();
154
162 void disallowPacking();
163
164 agx::Vec3 getWorldPosition() const;
165
166 agx::Vec3 getWorldVelocity() const;
167
168 const agx::Frame* getBodyFrame() const;
169
170 void setBody(agx::RigidBody* newBody);
171
172 private:
173 agx::RigidBodyRef m_body;
174 agxPowerLine::PhysicalDimension* m_dimension;
175
176 bool m_allowsPacking;
177 };
178
180
181
182
183
184
185
186
193 {
194 public:
195 virtual agx::UInt8 getSlot() const = 0;
196
197 protected:
199 };
200
201
202
203
209 template<typename DimensionType>
211 {
212 public:
214
215 virtual agx::UInt8 getSlot() const override;
216
217 virtual agx::Real getValue() const override;
218
219 virtual void setValue(agx::Real value) override;
220
221 virtual agx::Real getGradient() const override;
222
223 virtual void setGradient(agx::Real gradient) override;
224
225 virtual agx::Real getSecondGradient() const override;
226
227 virtual agx::Vec3 getLocalDirection() const override;
228
229 virtual agx::Vec3 getWorldDirection() const override;
230
231 virtual agx::Vec3 getDirection() const override;
232
233 virtual agx::Real getMassProperty() const override;
234
235 virtual bool setMassProperty(agx::Real massProperty) override;
236
237 virtual void addLoad(agx::Real load) override;
238
239 virtual void setVelocityDamping(float damping) override;
240
241 virtual float getVelocityDamping() override;
242
244
245 virtual bool isExternalBody() const override;
246
247 virtual void calculateJacobian(agx::Jacobian6DOFElement* G, agx::Real ratio, size_t index) const override;
248
249 virtual void addNotification(agxPowerLine::PowerLine* powerLine) override;
250 virtual void removeNotification(agxPowerLine::PowerLine* powerLine) override;
251
252
259 virtual agx::RigidBody* getReservedBody() override;
260 virtual const agx::RigidBody* getReservedBody() const override;
261
269 virtual void reserveBody() override;
270
279 void split();
280
293 void move(agx::RigidBody* body, agx::UInt8 slot);
294
296
297 virtual void postUpdate(agx::Real timeStep) override;
298
299 virtual agxStream::StorageAgent* getStorageAgent() const override;
300 static const char* getConstructClassId();
301 friend class agxStream::DefStorageAgent<DimensionState1Dof<DimensionType>>;
302 virtual const char* getClassName() const override;
305
306 virtual void store(agxStream::OutputArchive& out) const override;
307 virtual void restore(agxStream::InputArchive& in) override;
308
309 virtual bool store(agxStream::StorageStream& out) const override;
310 virtual bool restore(agxStream::StorageStream& in) override;
311
312 private:
314
315
316 protected:
317 DimensionState1Dof(); // For serialization only.
320 void splitImpl();
321 void moveImpl(agx::RigidBody* newBody, agx::UInt8 newSlot);
322
323 private:
324 agx::UInt8 m_slot;
325 DimensionType m_storage;
326 };
327
328
329
337 {
338 public:
339 virtual void setLocalDirection(const agx::Vec3& direction) = 0;
340 virtual void setWorldDirection(const agx::Vec3& direction) = 0;
341
342 protected:
344 };
345
346
347
353 template<typename DimensionType>
355 {
356 public:
358 agx::RigidBody* body,
360 const agx::Vec3& direction,
361 DirectionReference directionReference);
362
364 agx::RigidBody* body,
366 const agx::Vec3& direction,
367 DirectionReference directionReference,
368 bool externalBody);
369
370 virtual agx::Real getValue() const override;
371
372 virtual void setValue(agx::Real value) override;
373
374 virtual agx::Real getGradient() const override;
375
376 virtual void setGradient(agx::Real gradient) override;
377
378 virtual agx::Real getSecondGradient() const override;
379
380 virtual agx::Vec3 getLocalDirection() const override;
381
382 virtual void setLocalDirection(const agx::Vec3& direction) override;
383
384 virtual agx::Vec3 getWorldDirection() const override;
385
386 virtual void setWorldDirection(const agx::Vec3& direction) override;
387
388 virtual agx::Vec3 getDirection() const override;
389
390 virtual agx::Real getMassProperty() const override;
391
392 virtual bool setMassProperty(agx::Real massProperty) override;
393
394 virtual void addLoad(agx::Real load) override;
395
396 virtual void setVelocityDamping(float damping) override;
397 virtual float getVelocityDamping() override;
398
400
401 virtual bool isExternalBody() const override;
402
403 virtual void reserveBody() override;
404 virtual agx::RigidBody* getReservedBody() override;
405 virtual const agx::RigidBody* getReservedBody() const override;
406
407 virtual void calculateJacobian(agx::Jacobian6DOFElement* G, agx::Real ratio, size_t index) const override;
408
409 virtual void addNotification(agxPowerLine::PowerLine* powerLine) override;
410 virtual void removeNotification(agxPowerLine::PowerLine* powerLine) override;
411
412 virtual void postUpdate(agx::Real /*timeStep*/) override;
413
414 virtual bool store(agxStream::StorageStream& out) const override;
415 virtual bool restore(agxStream::StorageStream& in) override;
416
417 virtual void store(agxStream::OutputArchive& out) const override;
418 virtual void restore(agxStream::InputArchive& in) override;
419
420 virtual agxStream::StorageAgent* getStorageAgent() const override;
421 static const char* getConstructClassId();
422 friend class agxStream::DefStorageAgent<DimensionState1Dof<DimensionType>>;
423 virtual const char* getClassName() const override;
426
427
428 protected:
430
431 private:
433
434 void calculateMergedBodyJacobian(
436 agx::Real /*ratio*/,
437 size_t /*index*/,
438 const agx::MergedBody* /*mergedBody*/) const;
439
440 void printInvalidDirectionReference() const;
441
442 private:
443 agx::Vec3 m_direction;
444 DirectionReference m_directionReference;
445 DimensionType m_storage;
446 bool m_externalBody; // Will this ever be false? When?
447 };
448
449 // Some human friendly names for the four possible combinations of degrees
450 // of freedom and storage location in the rigid body.
455 }
456}
457
458#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
#define AGXMODEL_EXPORT
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition PowerLine.h:66
The SlotMapper is reponsible for mapping one dimensional dimension states to slots in the RigidBodies...
Definition SlotMapper.h:51
Base class for the two one dimensional dimension state classes.
AbstractDimensionState1Dof(agx::RigidBody *body, agxPowerLine::PhysicalDimension *dimension, bool allowPacking)
Base class for the two three dimensional dimension state classes.
virtual void setLocalDirection(const agx::Vec3 &direction)=0
virtual void setWorldDirection(const agx::Vec3 &direction)=0
AbstractDimensionState3Dof(agx::RigidBody *body, agxPowerLine::PhysicalDimension *dimension)
Templated one dimensional dimension state.
static agxStream::Serializable * create()
virtual void reserveBody() override
Ensure that this DimensionState is the only state using this state's RigidBody.
void moveImpl(agx::RigidBody *newBody, agx::UInt8 newSlot)
virtual agxStream::StorageAgent * getStorageAgent() const override
virtual void removeNotification(agxPowerLine::PowerLine *powerLine) override
virtual agx::Real getValue() const override
static agxStream::Serializable * create(agxStream::InputArchive &)
virtual const agx::RigidBody * getReservedBody() const override
virtual void addLoad(agx::Real load) override
void move(agx::RigidBody *body, agx::UInt8 slot)
Make this dimension state use the given body for storage.
void split()
Move this DimensionState to a new RigidBody that is guaranteed to not be shared with any other Dimens...
virtual void setVelocityDamping(float damping) override
virtual bool isExternalBody() const override
virtual void setGradient(agx::Real gradient) override
virtual void restore(agxStream::InputArchive &in) override
virtual agx::Vec3 getLocalDirection() const override
virtual void setValue(agx::Real value) override
virtual agx::Vec3 getDirection() const override
virtual agx::Vec3 getWorldDirection() const override
virtual agx::UInt8 getSlot() const override
virtual void postUpdate(agx::Real timeStep) override
virtual void addNotification(agxPowerLine::PowerLine *powerLine) override
virtual agx::Real getSecondGradient() const override
virtual DirectionReference getDirectionReference() const override
virtual bool store(agxStream::StorageStream &out) const override
virtual void store(agxStream::OutputArchive &out) const override
DimensionState1Dof(agx::RigidBody *body, agxPowerLine::PhysicalDimension *dimension, agx::UInt8 slot)
virtual bool setMassProperty(agx::Real massProperty) override
virtual agx::Real getGradient() const override
virtual bool restore(agxStream::StorageStream &in) override
virtual const char * getClassName() const override
virtual agx::Real getMassProperty() const override
virtual float getVelocityDamping() override
virtual agx::RigidBody * getReservedBody() override
Returns a RigidBody that is guaranteed to not be shared with any other DimensionState.
virtual void calculateJacobian(agx::Jacobian6DOFElement *G, agx::Real ratio, size_t index) const override
Templated three dimensional dimension state.
virtual void setWorldDirection(const agx::Vec3 &direction) override
virtual const agx::RigidBody * getReservedBody() const override
virtual agx::Vec3 getDirection() const override
virtual void postUpdate(agx::Real) override
static agxStream::Serializable * create(agxStream::InputArchive &)
virtual agx::RigidBody * getReservedBody() override
Gives access to a RigidBody that is known to be used by this dimension state only.
DimensionState3Dof(agx::RigidBody *body, agxPowerLine::PhysicalDimension *dimension, const agx::Vec3 &direction, DirectionReference directionReference)
virtual bool store(agxStream::StorageStream &out) const override
virtual agx::Vec3 getWorldDirection() const override
virtual void addLoad(agx::Real load) override
static agxStream::Serializable * create()
DimensionState3Dof(agx::RigidBody *body, agxPowerLine::PhysicalDimension *dimension, const agx::Vec3 &direction, DirectionReference directionReference, bool externalBody)
virtual DirectionReference getDirectionReference() const override
virtual bool restore(agxStream::StorageStream &in) override
virtual void store(agxStream::OutputArchive &out) const override
virtual bool setMassProperty(agx::Real massProperty) override
virtual void setLocalDirection(const agx::Vec3 &direction) override
virtual void restore(agxStream::InputArchive &in) override
virtual void calculateJacobian(agx::Jacobian6DOFElement *G, agx::Real ratio, size_t index) const override
virtual agx::Real getGradient() const override
virtual agx::Real getValue() const override
virtual void addNotification(agxPowerLine::PowerLine *powerLine) override
virtual agx::Vec3 getLocalDirection() const override
virtual float getVelocityDamping() override
virtual void setVelocityDamping(float damping) override
virtual bool isExternalBody() const override
virtual void reserveBody() override
Reserve a body for this dimension state.
virtual const char * getClassName() const override
virtual agx::Real getSecondGradient() const override
virtual void setGradient(agx::Real gradient) override
virtual agx::Real getMassProperty() const override
virtual agxStream::StorageAgent * getStorageAgent() const override
virtual void setValue(agx::Real value) override
virtual void removeNotification(agxPowerLine::PowerLine *powerLine) override
A DimensionState is the data carrier of a PhysicalDimension.
virtual void setGradient(agx::Real value)=0
virtual bool isExternalBody() const =0
virtual const agx::RigidBody * getReservedBody() const =0
virtual agx::Real getMassProperty() const =0
virtual agx::RigidBody * getReservedBody()=0
Gives access to a RigidBody that is known to be used by this dimension state only.
virtual agx::Real getValue() const =0
virtual void calculateJacobian(agx::Jacobian6DOFElement *G, agx::Real ratio, size_t index) const =0
virtual agx::Vec3 getDirection() const =0
virtual void postUpdate(agx::Real timeStep)=0
virtual void setValue(agx::Real value)=0
virtual agx::Vec3 getLocalDirection() const =0
const agxPowerLine::PhysicalDimension * getDimension() const
agx::RigidBody * getCurrentBody()
Returns the body currently used by this dimension state.
virtual void addNotification(agxPowerLine::PowerLine *powerLine)=0
virtual void removeNotification(agxPowerLine::PowerLine *powerLine)=0
virtual agxPowerLine::DirectionReference getDirectionReference() const =0
virtual void setVelocityDamping(float damping)=0
virtual agx::Vec3 getWorldDirection() const =0
const agx::RigidBody * getCurrentBody() const
virtual agx::Real getSecondGradient() const =0
virtual bool setMassProperty(agx::Real massProperty)=0
virtual void reserveBody()=0
Reserve a body for this dimension state.
virtual agx::Real getGradient() const =0
virtual void addLoad(agx::Real load)=0
Class for reading a binary stream of serialized data.
Class for writing serialized data in binary format to a stream.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Abstract base class for storing/restoring a line/drums with version control.
Structure holding several "normal" rigid bodies.
Definition MergedBody.h:56
Base class providing referencing counted objects.
Definition Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
agxPowerLine contains a collection of connected components that transport power across a system.
Definition MotorUnit.h:24
DirectionReference
The DirectionReference specifies what the direction attribute of a DimensionState is relative to.
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition Real.h:42
uint8_t UInt8
Definition Integer.h:30