17 #ifndef AGXMODEL_TREE_H
18 #define AGXMODEL_TREE_H
301 void setTree(
Tree* tree );
347 enum State { INITIALIZED = (1<<0), STATIC = (1<<1), WAKE_ON_CONTACT = (1<<2) };
708 : m_tree( tree ) { setMask( IMPACT ); }
725 : m_tree( tree ) { setMask( PRE_COLLIDE | PRE_STEP | POST_STEP ); }
756 template<
typename T >
759 agx::Real oldLength = shape->getHeight();
760 newBelowLength =
agx::Real( 0.5 ) * oldLength + position;
761 newAboveLength = oldLength - newBelowLength;
762 if ( newBelowLength < 0 || newAboveLength < 0 )
764 shape->setHeight( newBelowLength );
765 return new T( shape->getRadius(), newAboveLength );
The geometry representation used by the collision detection engine.
BranchEventListener handles certain events happening to a Tree.
virtual void onHighLoad(agxModel::Tree::Branch *branch)
Event when branch branch connection is under high load.
virtual ~BranchEventListener()
virtual void onCreate(agxModel::Tree::Branch *branch)
Event when branch branch has been configured with position, orientation and constraint to parent (if ...
BranchEventListener()
Construct branch event listener to listen to certain events happening in a Tree.
virtual agxModel::Tree::BranchEventListener * clone()=0
Clone method used by cut.
Branch is a part of the Tree, with a body and a constraint to its parent.
agx::ConstraintRef m_constraint
Branch(const agx::Vec3 &start, const agx::Vec3 &end)
Construct branch given start- and end point in world.
agx::Referenced * getCustomData() const
agx::RigidBody * getRigidBody() const
agx::ref_ptr< agx::Referenced > m_customData
virtual agx::ConstraintRef createConstraintWithParent() const
Creates the constraint with this branch's parent.
agxModel::Tree::Branch * getParent() const
agx::Real getCurrentTranslationalLoad() const
agx::Vec2 getCurrentLoad() const
agx::Real getMaxRotationalLoad() const
virtual agx::Real getLength(const agxCollide::Geometry *geometry) const
Calculates and returns an estimated length of this branch.
void setParent(agxModel::Tree::Branch *parent)
Assign parent to this branch.
Branch(const agx::AffineMatrix4x4 &transform)
Construct branch given transform.
bool removeBranch(size_t index)
Remove child given index.
void setMaxLoad(agx::Real translational, agx::Real rotational)
Assign max load for this branch (connection at start).
agx::Vec3 getLocalDirection() const
agx::Vec3 getDirection() const
virtual agxModel::Tree::Branch * clone()
void setCustomData(agx::Referenced *customData)
Assign custom/user data of any type.
virtual agxCollide::Shape * splitShape(agxCollide::Shape *shapeInBranch, agx::Real shapePosition, agxModel::Tree::Branch *newBranch, agx::Real &newBelowLength, agx::Real &newAboveLength)
This branch is about to be divided into two branches (cut)!
BranchContainer m_branches
bool removeBranch(agxModel::Tree::Branch *branch)
Remove a child branch.
agx::Real getMaxTranslationalLoad() const
agx::Real getCurrentRotationalLoad() const
agxModel::Tree::Branch * getBranch(size_t i) const
void setMaxTranslationalLoad(agx::Real maxLoad)
Assign translational max load for this branch.
agx::Vec2 getMaxLoad() const
size_t getNumBranches() const
void setConstraint(agx::Constraint *constraint)
Assign constraint attached at start point of this branch.
agx::Constraint * getConstraint() const
bool addBranch(agxModel::Tree::Branch *branch)
Add child branch to this branch.
void setMaxRotationalLoad(agx::Real maxLoad)
Assign rotational max load for this branch.
TreeExecuteFilter allows to catch contacts with the Tree.
virtual agxModel::Tree::TreeExecuteFilter * clone()
Clone method of the TreeExecuteFilter.
agx::UInt32 getTreeID() const
virtual ~TreeExecuteFilter()
TreeExecuteFilter()
Default constructor.
virtual bool match(const agxCollide::GeometryContact &contact) const override
Find contacts where one geometry is the Tree.
virtual bool match(const agxCollide::GeometryPair &pair) const override
Find contacts where one geometry is the Tree.
virtual ~TreeStepEventListener()
virtual void post(const agx::TimeStamp &) override
Called after a step is taken in the simulation Implement this method in the derived class to get call...
agx::observer_ptr< Tree > m_tree
virtual void pre(const agx::TimeStamp &) override
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
TreeStepEventListener(Tree *tree)
virtual void preCollide(const agx::TimeStamp &) override
Called before collision detection is performed in the simulation Implement this method in the derived...
Tree is a structure of Branch objects in a mathematical Tree structure where a Branch can have severa...
agx::Vector< BranchRef > BranchContainer
virtual void setBranchEventListener(agxModel::Tree::BranchEventListener *branchListener)
Assign branch event listener.
static void setDefaultParameters(agx::Material *material)
Sets default material parameters for a tree.
void copyParameters(const agx::Constraint *source, agx::Constraint *destination) const
Copy constraint parameters from source to destination.
agx::ref_ptr< agx::Referenced > m_customData
virtual Branch * split(agxCollide::Geometry *geometry, const agx::Vec3 &point, agx::Real minShapeHeight=agx::Real(1E-2))
Splits this tree given geometry and point in world.
void split(Branch *source, Branch *destination) const
Move from source to destination.
void removeGroupID(Branch *branch, agx::UInt32 id)
Removes the id from the branch geometries.
agx::UInt32 m_geometriesID
bool hasGroupID(agx::UInt32 id) const
agx::HashVector< agxCollide::Geometry *, agx::observer_ptr< agxCollide::Geometry > > DisabledCollisionsGeometryContainer
agx::MaterialRef m_material
virtual Tree * cut(agxCollide::Geometry *geometry, const agx::Vec3 &point, agx::Real minShapeHeight=agx::Real(1E-2))
Cut geometry (only one shape per geometry supported) given point in world and minimum shape height,...
TreeStepEventListenerRef m_stepListener
void add(Branch *branch)
Adds rigid body, constraint etc to this tree.
virtual void setMaterial(agx::Material *material)
Assign new material.
bool makeStatic(bool wakeOnContactEvent, agxModel::Tree::TreeExecuteFilter *filter=new agxModel::Tree::TreeExecuteFilter())
Simplify this tree.
virtual Tree * clone()
Clone call when new tree is needed from internal methods.
bool removeGroupID(agx::UInt32 id)
Removes group id from all geometries in this tree.
bool makeDynamic()
Make all rigid bodies dynamic and add all constraints to the simulation.
virtual void checkLoad(Branch *branch)
Checks current load.
virtual void clear()
Remove all branches from this tree.
virtual bool attach(agx::RigidBody *rb, agx::Frame *frame)
Attach bottom branch to an object given attachment frame.
agx::observer_ptr< Branch > BranchObs
virtual void post()
Post step event callback.
bool getEnableCollisions(const agxCollide::Geometry *geometry) const
BranchContainer::iterator BranchIterator
void setMaterial(Branch *branch, agx::Material *material)
Assign material to all geometries for branch.
virtual void preCollide()
Pre-collide event callback.
agx::ref_ptr< Branch > BranchRef
Tree()
Default constructor.
bool setEnableCollisions(agxCollide::Geometry *geometry, bool flag)
Enable or disable collisions between this tree and a geometry.
agx::UInt32 m_disabledCollisionsID
Tree(agxModel::Tree::Branch *root)
agx::Material * getMaterial() const
void remove(Branch *branch)
Removes rigid body, constraint etc associated to this tree.
virtual void addNotification(agxSDK::Simulation *simulation)
Called when this assembly is added to a simulation (given that it not already is in the simulation).
agx::ref_ptr< BranchEventListener > BranchEventListenerRef
bool addGroupID(agx::UInt32 id)
Add group id to all geometries in this tree.
static void setLinearVelocityDamping(agxModel::Tree::Branch *branch, const agx::Vec3 &linearVelocityDamping)
Utility method to set linear velocity damping for all branches.
void copyParameters(const Branch *source, Branch *destination) const
Copy branch parameters from source to destination.
void simplify(Branch *branch, bool flag, agxSDK::Simulation *simulation)
Changes motion control and adds/removes constraints depending on flag.
virtual void removeNotification(agxSDK::Simulation *simulation)
Called when this assembly is removed from a simulation.
void addGroupID(Branch *branch, agx::UInt32 id)
Adds the id to the branch geometries.
TreeContactEventListenerRef m_wakeOnContactListener
agx::ref_ptr< TreeExecuteFilter > TreeExecuteFilterRef
DisabledCollisionsGeometryContainer m_externalDisabledGeometries
BranchContainer::const_iterator BranchConstIterator
agx::Referenced * getCustomData() const
agx::SetVector< agx::UInt32 > GroupIdContainer
bool getEnableCollisions(const agx::RigidBody *rb) const
void setConstraintSolveType(Branch *branch, agx::Constraint::SolveType solveType)
Assign constraint solve type.
virtual void pre()
Pre event callback.
agx::ref_ptr< TreeStepEventListener > TreeStepEventListenerRef
bool wakeOnContact() const
static void setAngularVelocityDamping(agxModel::Tree::Branch *branch, const agx::Vec3 &angularVelocityDamping)
Utility method to set angular velocity damping for all branches.
BranchEventListenerRef m_branchListener
agx::ref_ptr< TreeContactEventListener > TreeContactEventListenerRef
void setCustomData(agx::Referenced *customData)
Assign custom data.
agxModel::Tree::BranchEventListener * getBranchEventListener() const
virtual Tree * cut(agxModel::Tree::Branch *branch)
Cut at branch and get a new tree.
virtual void setConstraintSolveType(agx::Constraint::SolveType solveType)
Set new solve type for the branch connections.
virtual bool initialize()
Explicit call to this method to check return value.
bool setEnableCollisions(agx::RigidBody *rb, bool flag)
Enable or disable collisions between this tree and a rigid body.
Branch * guessConnectingChild(Branch *branch) const
Searches branch children and examines orientation etc to "guess" which of the children that is along ...
Branch * findBranch(const agxModel::Tree::Branch *fromBranch, const agx::RigidBody *rb) const
Search the tree for rigid body rb given start branch (i.e., whole tree if root).
Branch * findBranch(const agx::RigidBody *rb) const
Search the tree for rigid body rb.
void configure(Branch *branch)
Traverse this tree and configures the branches.
GroupIdContainer m_geometryIDs
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
bool add(agx::Constraint *constraint)
Add a constraint to the assembly.
bool remove(agx::Constraint *constraint)
Remove a constraint from this assembly (does not recurse down in tree).
virtual void addNotification(agxSDK::Simulation *)
Called when this assembly is added to a simulation (given that it not already is in the simulation).
Abstract base class that implements a filter that selects which events should trigger a Listener.
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Derive from this class to implement a listener for simulation step events.
The base class for a constraint.
SolveType
Specifies in what solvers the constraint will be solved.
The object defining a frame of reference and providing transformations operations.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Main material class which acts as a holder of a Surface Material and a Bulk material.
Base class providing referencing counted objects.
The rigid body class, combining a geometric model and a frame of reference.
const BranchRef * const_iterator
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
agx::ref_ptr< Tree > TreeRef
T * cutShape(T *shape, agx::Real position, agx::Real &newBelowLength, agx::Real &newAboveLength)
AGXMODEL_EXPORT agx::Real getShapeRadius(const agxCollide::Shape *shape)
AGXMODEL_EXPORT agx::Real getShapeLength(const agxCollide::Shape *shape)
AGXCORE_EXPORT Component * root()
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)