46 class LinkedStructure;
56 class DeformableObject;
355 virtual
void addNotification() override;
360 virtual
void removeNotification() override;
367 virtual
void step(
agx::Real dt ) override;
374 virtual
void fetchStepResults() override;
380 virtual
void updateGraphics( const
agxRender::RenderManager& renderManager ) override;
386 agx::VectorPOD<T*> getObjects() const;
392 T* findRootSystem() const;
398 agx::VectorPOD<T*> findRootSystems() const;
404 agx::VectorPOD<T*> findSystems() const;
413 INITIALIZED = 1 << 0,
415 SYNCHRONIZING_DATA = 1 << 2,
417 IS_SLEEPING = 1 << 4,
421 using Value = agx::AtomicState<Flag>;
428 static size_t& instanceCount();
440 template<
typename T,
typename InOutHelper>
442 InOutHelper& helper )
const;
444 template<
typename T,
typename InOutHelper>
447 bool callAddOnRestored );
455 SystemNodeRefVector m_systems;
456 std::thread m_thread;
457 RuntimeState m_runtimeData;
458 agx::ReferencedHandler m_refHandler;
460 MagneticFieldRef m_magneticField;
464 agx::VectorPOD<T*> Environment::getObjects()
const
467 m_refHandler.template visit<T>( [&objects](
const T& instance )
469 objects.
push_back(
const_cast<T*
>( &instance ) );
475 T* Environment::findRootSystem()
const
477 for (
const auto& system : m_systems )
478 if ( system->template is<T>() )
479 return system->template as<T>();
487 for (
const auto& system : m_systems )
488 if ( system->template is<T>() )
489 result.
push_back( system->template as<T>() );
497 for (
const auto& system : m_systems ) {
498 if ( system->template is<T>() )
499 result.
push_back( system->template as<T>() );
501 system->template visitChildrenOfType<T>( [&result]( T& child )
511 bool Environment::accept(
bool handled,
agx::Referenced& instance,
bool isAdded )
513 static_assert( std::is_base_of<agxStream::Serializable, T>::value,
514 "Unexpected that type doesn't suport serialization." );
516 agxAssert( !handled || instance.template is<T>() );
517 if ( handled && isAdded ) {
518 agxSensor::getOrCreateEnvData( instance.template asSafe<T>() )->environment =
this;
519 m_refHandler.template add<T>( instance );
521 else if ( handled ) {
522 agxSensor::getOrCreateEnvData( instance.template asSafe<T>() )->environment =
nullptr;
523 m_refHandler.template remove<T>( instance );
529 template<
typename T,
typename InOutHelper>
533 m_refHandler.template visit<T>( [&out, &helper](
const T& instance )
539 const EnvInternalData* envData = getEnvData( &instance );
541 if ( envData->rtData !=
nullptr ) {
542 envData->rtData->state.flags.store( out );
545 helper.store( out, envData->rtData->getMaterial() );
550 template<
typename T,
typename InOutHelper>
553 bool callAddOnRestored )
555 size_t numInstances = 0u;
557 for (
size_t i = 0u; i < numInstances; ++i ) {
558 T* instance =
nullptr;
560 if ( instance !=
nullptr ) {
561 bool hasRtData =
false;
564 RtInternalData* rtData = getOrCreateRtData( instance );
565 rtData->state.flags.restore( in );
568 rtData->setEntityId( (RtEntityId)rtEntityIndex );
570 RtMaterialInstance material{};
571 helper.restore( in, material );
572 rtData->setMaterial( material );
575 if ( callAddOnRestored )
576 this->add( instance );
577 this->
template accept<T>(
true, *instance,
true );
578 instance->setFinished();
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
The geometry representation used by the collision detection engine.
Interface to a cooperative sensor simulation assumed to be executed in a separate thread spawned in a...
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Sensor environment implementation where different sensors collects data given a set of added objects,...
bool add(agxSDK::LinkedStructure *linkedStructure)
Add agxCable::Cable, agxVehicle::Track, agxModel::Beam, ..., to be visible to sensors in this sensor ...
bool remove(agxCollide::Shape *shape)
Remove shape from this sensor environment.
bool remove(agxModel::DeformableObject *deformable)
Remove deformable object from this sensor environment.
void setMagneticField(MagneticField *magneticField)
Set environment magnetic field.
static Environment * get(agxSDK::Simulation *simulation)
bool add(agx::RigidBody *rb)
Add rigid body to be visible to sensors in this sensor environment.
bool add(agxCollide::Shape *shape)
Add shape to be visible to sensors in this sensor environment.
static Environment * getOrCreate(agxSDK::Simulation *simulation)
Returns an existing or creates and initializes a new instance of a sensor environment given a simulat...
bool remove(agxTerrain::TerrainPager *pager)
Remove terrain pager from this sensor environment.
RtSceneRef getScene() const
static const Environment * get(const agxSDK::Simulation *simulation)
bool add(SystemNode *system)
Add system root node (normally an implementation of a sensor) to this sensor environment.
bool remove(agxSDK::LinkedStructure *linkedStructure)
Remove linked structure (agxCable::Cable, agxVehicle::Track, agxModel::Beam, ...) from this sensor en...
bool remove(agxTerrain::Terrain *terrain)
Remove terrain from this sensor environment.
bool add(agxWire::Wire *wire)
Add wire to be visible to sensors in this sensor environment.
bool add(agxCollide::Geometry *geometry)
Add geometry to be visible to sensors in this sensor environment.
const MagneticField * getMagneticField() const
bool remove(agxWire::Wire *wire)
Remove wire from this sensor environment.
Environment()
Default constructor - the default sensor systems will be added.
bool add(agxTerrain::TerrainPager *pager)
Add terrain pager to be visible to sensors in this sensor environment.
bool add(agxTerrain::Terrain *terrain)
Add terrain to be visible to sensors in this sensor environment.
bool remove(agx::RigidBody *rb)
Remove the rigid body, and all its geometries, from this sensor environment.
bool add(agxModel::DeformableObject *deformable)
Add deformable object to be visible to sensors in this sensor environment.
MagneticField * getMagneticField()
bool remove(SystemNode *system)
Remove system root node (sensor) from this sensor environment.
virtual ~Environment()
Destructor.
bool remove(agxCollide::Geometry *geometry)
Remove geometry, and all its shapes, from this sensor environment.
Base type for the specification of the magnetic field in a sensor environment.
System node is a separate step/operation in an execution tree representing a sensor (or such) in a se...
Class for writing serialized data in binary format to a stream.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Interface and placeholder of controllers/helpers for wires.
Base class providing referencing counted objects.
The rigid body class, combining a geometric model and a frame of reference.
Vector containing 'raw' data.
void push_back(const T &value)
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Namespace containing classes for handling debug rendering of collision geometries,...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
The agxSensor namespace contains components to model real-time sensors connected to the physics of AG...
RtEntityIdIndex indexOf(RtEntityId entityId)
std::shared_ptr< RtScene > RtSceneRef
std::underlying_type_t< RtEntityId > RtEntityIdIndex
Index type of entity ids.
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Implements a Wire model with adaptive resolution.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.