AGXDynamics  2.31.1.0
agxOSG::PressureRenderer Class Reference

An utility class for handling of pressure rendering and legend. More...

#include <PressureRenderer.h>

+ Inheritance diagram for agxOSG::PressureRenderer:

Classes

struct  MaxAvgData
 
struct  MaxAvgRecording
 

Public Member Functions

 PressureRenderer (osg::Group *root, agxOSG::SceneDecorator *decorator, agxSDK::Simulation *simulation, osgSim::ColorRange *colorRange=new osgSim::ColorRange(0.0f, 1.0e5f), const agx::Real texelsPerMeter=agx::Real(50), const agx::Real rangeFactor=agx::Real(2.0e-5), agxOSG::PressureFromContacts::ForceType forceType=agxOSG::PressureFromContacts::TOTAL_FORCE)
 Constructor using osg color range directly. More...
 
 PressureRenderer (osg::Group *root, agxOSG::SceneDecorator *decorator, agxSDK::Simulation *simulation, const agx::Real minPressure, const agx::Real maxPressure, const agxRender::ColorVector &colors, const agx::Real texelsPerMeter=agx::Real(50), const agx::Real rangeFactor=agx::Real(2.0e-5), agxOSG::PressureFromContacts::ForceType forceType=agxOSG::PressureFromContacts::TOTAL_FORCE)
 Constructor using agx data. More...
 
void addFilter (agxSDK::ExecuteFilter *filter)
 Add a contact filter. More...
 
bool addGeometry (agxCollide::Geometry *geometry, bool keepGeometryNode=false)
 Adds all shapes in a geometry to the pressure rendering. More...
 
bool addTrimesh (agxCollide::Trimesh *trimesh, bool keepGeometryNode=false)
 Adds a trimesh to the pressure rendering. More...
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
osgSim::ColorRange * getColorRange ()
 Gets the color range. More...
 
agx::Vec2 getLegendPosition () const
 Returns the legend center position in relative screen space (0 to 1). More...
 
size_t getNumRecordings ()
 
agxOSG::PressureAtlasManager * getPressureAtlasManager ()
 Gets the pressure atlas manager. More...
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
bool isRecording ()
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
bool renderAvgPressure (size_t recording)
 Replace the texture data for measured geometries with a recorded average pressure. More...
 
bool renderMaxPressure (size_t recording)
 Replace the texture data for measured geometries with a recorded maximum pressure. More...
 
bool restoreRendering ()
 Disable rendering of recorded maximum or average data. More...
 
void setEnableLegend (bool flag)
 Enables/disables legend in HUD. More...
 
void setLegendPosition (const agx::Vec2 &pos)
 Sets the legend center position in relative screen space (0 to 1). More...
 
bool startMaxAvgRecording ()
 Start recording of maximum and average pressure for each pressure atlas currently owned by this PressureRenderer. More...
 
size_t stopMaxAvgRecording ()
 Stop the current recording. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Protected Types

typedef agx::Vector< MaxAvgRecording > MaxAvgRecordingVector
 

Protected Member Functions

virtual ~PressureRenderer ()
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
bool renderPressure (size_t recording, bool useMax)
 
void unregisterRecorders ()
 
void updateTextureData ()
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

agxOSG::PressureAtlasManagerRef m_atlasManager
 
osg::ref_ptr< osgSim::ColorRange > m_colorRange
 
size_t m_currentRecording
 
osg::observer_ptr< agxOSG::SceneDecorator > m_decorator
 
agx::Vector< agxSDK::ExecuteFilterRef > m_filters
 
const agxOSG::PressureFromContacts::ForceType m_forceType
 
agx::Vec2 m_legendPosition
 
osg::ref_ptr< agxOSG::Transform > m_legendTransform
 
agx::Vector< MaxAvgData > m_maxAvgData
 
agx::Vector< MaxAvgRecordingVector > m_maxAvgRecordings
 
agx::Vector< agxCollide::TrimeshRef > m_meshes
 
Mutex m_mutex
 
ObserverContainer m_observers
 
agx::Real m_rangeFactor
 
AtomicValue m_refCount
 
osg::observer_ptr< osg::Group > m_root
 

Detailed Description

An utility class for handling of pressure rendering and legend.

Definition at line 50 of file PressureRenderer.h.

Member Typedef Documentation

◆ MaxAvgRecordingVector

Constructor & Destructor Documentation

◆ PressureRenderer() [1/2]

agxOSG::PressureRenderer::PressureRenderer ( osg::Group *  root,
agxOSG::SceneDecorator *  decorator,
agxSDK::Simulation *  simulation,
osgSim::ColorRange *  colorRange = new osgSim::ColorRange(0.0f, 1.0e5f),
const agx::Real  texelsPerMeter = agx::Real(50),
const agx::Real  rangeFactor = agx::Real(2.0e-5),
agxOSG::PressureFromContacts::ForceType  forceType = agxOSG::PressureFromContacts::TOTAL_FORCE 
)

Constructor using osg color range directly.

Parameters
rootThe scene root.
decoratorThe scene decorator, used here for the hud-legend.
simulationThe simulation
colorRangeThe color range, containing colors, and min and max pressure.
texelsPerMeterThe amount of texels per length unit (meter)
rangeFactorRelationship between a contact force and area of the pressure circle. In m/N.
forceTypeThe type of the force to add. Tangential (friction) only, normal only, or both.

◆ PressureRenderer() [2/2]

agxOSG::PressureRenderer::PressureRenderer ( osg::Group *  root,
agxOSG::SceneDecorator *  decorator,
agxSDK::Simulation *  simulation,
const agx::Real  minPressure,
const agx::Real  maxPressure,
const agxRender::ColorVector &  colors,
const agx::Real  texelsPerMeter = agx::Real(50),
const agx::Real  rangeFactor = agx::Real(2.0e-5),
agxOSG::PressureFromContacts::ForceType  forceType = agxOSG::PressureFromContacts::TOTAL_FORCE 
)

Constructor using agx data.

Parameters
rootThe scene root.
decoratorThe scene decorator, used here for the hud-legend.
simulationThe simulation
minPressureThe min pressure for texturing
maxPressureThe max pressure for texturing
colorsA vector of colors for coloring. See osgSim::ColorRange for details.
texelsPerMeterThe amount of texels per length unit (meter)
rangeFactorRelationship between a contact force and area of the pressure circle. In m/N.
forceTypeThe type of the force to add. Tangential (friction) only, normal only, or both.

◆ ~PressureRenderer()

virtual agxOSG::PressureRenderer::~PressureRenderer ( )
protectedvirtual

Member Function Documentation

◆ addFilter()

void agxOSG::PressureRenderer::addFilter ( agxSDK::ExecuteFilter *  filter)

Add a contact filter.

A contact will only contribute pressure if it is accepted by all filters. Filters will only affect meshes and geometries which have been added after the filter has been added.

Parameters
filter

◆ addGeometry()

bool agxOSG::PressureRenderer::addGeometry ( agxCollide::Geometry *  geometry,
bool  keepGeometryNode = false 
)

Adds all shapes in a geometry to the pressure rendering.

Note
: right now, only trimeshes are supported. The geometry has to be part of the simulation, and have an osg-node which is in the root's tree.
Parameters
geometryThe geometry.
keepGeometryNodeShould existing geometry nodes be kept? Interesting when blending render states.
Returns
True if successful, false otherwise

◆ addTrimesh()

bool agxOSG::PressureRenderer::addTrimesh ( agxCollide::Trimesh *  trimesh,
bool  keepGeometryNode = false 
)

Adds a trimesh to the pressure rendering.

The trimesh's geometry has to be part of the simulation, and have an osg-node which is in the root's tree.

Parameters
trimeshThe trimesh.
keepGeometryNodeShould existing geometry nodes be kept? Interesting when blending render states.
Returns
True if successful, false otherwise

◆ allocateObserverVector()

void agx::Referenced::allocateObserverVector ( ) const
protectedinherited

◆ as() [1/2]

template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), agx::InternalData::getOrCreate(), and agx::InternalData::hasData().

◆ as() [2/2]

template<typename T >
const T* agx::Referenced::as ( ) const
inherited

◆ asSafe() [1/2]

template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

◆ asSafe() [2/2]

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited

◆ deleteUsingDeleteHandler()

void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited

◆ getColorRange()

osgSim::ColorRange* agxOSG::PressureRenderer::getColorRange ( )

Gets the color range.

◆ getDeleteHandler()

static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.

◆ getLegendPosition()

agx::Vec2 agxOSG::PressureRenderer::getLegendPosition ( ) const

Returns the legend center position in relative screen space (0 to 1).

◆ getNumRecordings()

size_t agxOSG::PressureRenderer::getNumRecordings ( )
Returns
The number of finished recordings.

◆ getPressureAtlasManager()

agxOSG::PressureAtlasManager* agxOSG::PressureRenderer::getPressureAtlasManager ( )

Gets the pressure atlas manager.

◆ getReferenceCount()

int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.

◆ is()

template<typename T >
bool agx::Referenced::is ( ) const
inherited

◆ isRecording()

bool agxOSG::PressureRenderer::isRecording ( )
Returns
True if a currently recording. False otherwise.

◆ reference()

void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

◆ renderAvgPressure()

bool agxOSG::PressureRenderer::renderAvgPressure ( size_t  recording)

Replace the texture data for measured geometries with a recorded average pressure.

Each measured trimesh must be part of a geometry rendered using the OSG mesh created by the owning PressureAtlas, and the geometry must have an associated texture.

Will change the osg::Image object held by the osg::Texture2D object that is part of the OSG render tree.

Parameters
recordingThe recording ID from which the average pressure should be fetched.
Returns
True if the given recording was selected. False if the given recording ID is invalid.

◆ renderMaxPressure()

bool agxOSG::PressureRenderer::renderMaxPressure ( size_t  recording)

Replace the texture data for measured geometries with a recorded maximum pressure.

Each measured trimesh must be part of a geometry rendered using the OSG mesh created by the owning PressureAtlas, and the geometry must have an associated texture.

Will change the osg::Image object held by the osg::Texture2D object that is part of the OSG render tree.

Parameters
recordingThe recording ID from which the maximum pressure should be fetched.
Returns
True if the given recording was selected. False if the given recording ID is invalid.

◆ renderPressure()

bool agxOSG::PressureRenderer::renderPressure ( size_t  recording,
bool  useMax 
)
protected

◆ restoreRendering()

bool agxOSG::PressureRenderer::restoreRendering ( )

Disable rendering of recorded maximum or average data.

Each texture will be returned the osg::Image object it held when the recording started.

Returns
True if original texture data was restored, fase if currently not rendering maximum or average pressure.

◆ setDeleteHandler()

static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

◆ setEnableLegend()

void agxOSG::PressureRenderer::setEnableLegend ( bool  flag)

Enables/disables legend in HUD.

◆ setLegendPosition()

void agxOSG::PressureRenderer::setLegendPosition ( const agx::Vec2 &  pos)

Sets the legend center position in relative screen space (0 to 1).

◆ startMaxAvgRecording()

bool agxOSG::PressureRenderer::startMaxAvgRecording ( )

Start recording of maximum and average pressure for each pressure atlas currently owned by this PressureRenderer.

Should not be called while a recording is already in progress.

Returns
True is a recording was started. False if a recording was already taking place.

◆ stopMaxAvgRecording()

size_t agxOSG::PressureRenderer::stopMaxAvgRecording ( )

Stop the current recording.

An ID for the recording is returned. The recorded data can be rendered on the geometries using 'renderMaxPressure(ID)' or 'renderAvgPressure(ID)'.

Should only be called while recording.

Returns
A recording ID for the new recording, or agx::InvalidIndex if not currently recording.

◆ unreference()

void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

Referenced by agxData::EntityRef< ContactMaterialPtr >::~EntityRef().

◆ unreference_nodelete()

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

◆ unregisterRecorders()

void agxOSG::PressureRenderer::unregisterRecorders ( )
protected

◆ updateTextureData()

void agxOSG::PressureRenderer::updateTextureData ( )
protected

◆ ValidateCast()

template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

Member Data Documentation

◆ m_atlasManager

agxOSG::PressureAtlasManagerRef agxOSG::PressureRenderer::m_atlasManager
protected

Definition at line 235 of file PressureRenderer.h.

◆ m_colorRange

osg::ref_ptr<osgSim::ColorRange> agxOSG::PressureRenderer::m_colorRange
protected

Definition at line 236 of file PressureRenderer.h.

◆ m_currentRecording

size_t agxOSG::PressureRenderer::m_currentRecording
protected

Definition at line 287 of file PressureRenderer.h.

◆ m_decorator

osg::observer_ptr<agxOSG::SceneDecorator> agxOSG::PressureRenderer::m_decorator
protected

Definition at line 234 of file PressureRenderer.h.

◆ m_filters

agx::Vector<agxSDK::ExecuteFilterRef> agxOSG::PressureRenderer::m_filters
protected

Definition at line 240 of file PressureRenderer.h.

◆ m_forceType

const agxOSG::PressureFromContacts::ForceType agxOSG::PressureRenderer::m_forceType
protected

Definition at line 290 of file PressureRenderer.h.

◆ m_legendPosition

agx::Vec2 agxOSG::PressureRenderer::m_legendPosition
protected

Definition at line 238 of file PressureRenderer.h.

◆ m_legendTransform

osg::ref_ptr<agxOSG::Transform> agxOSG::PressureRenderer::m_legendTransform
protected

Definition at line 237 of file PressureRenderer.h.

◆ m_maxAvgData

agx::Vector<MaxAvgData> agxOSG::PressureRenderer::m_maxAvgData
protected

Definition at line 261 of file PressureRenderer.h.

◆ m_maxAvgRecordings

agx::Vector<MaxAvgRecordingVector> agxOSG::PressureRenderer::m_maxAvgRecordings
protected

Definition at line 284 of file PressureRenderer.h.

◆ m_meshes

agx::Vector<agxCollide::TrimeshRef> agxOSG::PressureRenderer::m_meshes
protected

Definition at line 232 of file PressureRenderer.h.

◆ m_mutex

Mutex agx::Referenced::m_mutex
mutableprotectedinherited

Definition at line 240 of file Referenced.h.

◆ m_observers

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

◆ m_rangeFactor

agx::Real agxOSG::PressureRenderer::m_rangeFactor
protected

Definition at line 239 of file PressureRenderer.h.

◆ m_refCount

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.

◆ m_root

osg::observer_ptr<osg::Group> agxOSG::PressureRenderer::m_root
protected

Definition at line 233 of file PressureRenderer.h.


The documentation for this class was generated from the following file: