Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void ConstraintAnimationLoop::correctiveMotion(const core::ExecParams* params, s
}
}

void ConstraintAnimationLoop::step ( const core::ExecParams* params, SReal dt )
void ConstraintAnimationLoop::doStep ( const core::ExecParams* params, SReal dt )
{
auto node = dynamic_cast<sofa::simulation::Node*>(this->l_node.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API ConstraintAnimationLoop : public sofa::si
protected:
ConstraintAnimationLoop();
~ConstraintAnimationLoop() override;
public:

void step(const core::ExecParams* params, SReal dt) override;
public:
void init() override;

Data<bool> d_displayTime; ///< Display time for each important step of ConstraintAnimationLoop.
Expand All @@ -118,6 +117,8 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API ConstraintAnimationLoop : public sofa::si
ConstraintProblem *getConstraintProblem() {return bufCP1 ? &CP1 : &CP2;}

protected:
void doStep(const core::ExecParams* params, SReal dt) override;

void launchCollisionDetection(const core::ExecParams* params);
void freeMotion(const core::ExecParams* params, simulation::Node *context, SReal &dt);
void setConstraintEquations(const core::ExecParams* params, simulation::Node *context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void FreeMotionAnimationLoop::init()
}


void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal dt)
void FreeMotionAnimationLoop::doStep(const sofa::core::ExecParams* params, SReal dt)
{
auto node = dynamic_cast<sofa::simulation::Node*>(this->l_node.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API FreeMotionAnimationLoop : public sofa::si
SOFA_CLASS(FreeMotionAnimationLoop, sofa::simulation::CollisionAnimationLoop);

public:
void step (const sofa::core::ExecParams* params, SReal dt) override;
void init() override;

Data<bool> d_solveVelocityConstraintFirst; ///< solve separately velocity constraint violations before position constraint violations
Expand All @@ -53,6 +52,8 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API FreeMotionAnimationLoop : public sofa::si
FreeMotionAnimationLoop();
~FreeMotionAnimationLoop() override ;

void doStep (const sofa::core::ExecParams* params, SReal dt) override;

///< The ConstraintSolver used in this animation loop (required)
SingleLink<FreeMotionAnimationLoop, sofa::core::behavior::ConstraintSolver, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_constraintSolver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MultiStepAnimationLoop::~MultiStepAnimationLoop()
{
}

void MultiStepAnimationLoop::step(const sofa::core::ExecParams* params, SReal dt)
void MultiStepAnimationLoop::doStep(const sofa::core::ExecParams* params, SReal dt)
{
auto node = dynamic_cast<sofa::simulation::Node*>(this->l_node.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API MultiStepAnimationLoop : public sofa::sim
MultiStepAnimationLoop();

~MultiStepAnimationLoop() override;

void doStep (const sofa::core::ExecParams* params, SReal dt) override;
public:
void step (const sofa::core::ExecParams* params, SReal dt) override;

Data<int> d_collisionSteps; ///< number of collision steps between each frame rendering
Data<int> d_integrationSteps; ///< number of integration steps between each collision detection
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void MultiTagAnimationLoop::init()



void MultiTagAnimationLoop::step(const sofa::core::ExecParams* params, SReal dt)
void MultiTagAnimationLoop::doStep(const sofa::core::ExecParams* params, SReal dt)
{
auto node = dynamic_cast<sofa::simulation::Node*>(this->l_node.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class SOFA_COMPONENT_ANIMATIONLOOP_API MultiTagAnimationLoop : public sofa::simu

~MultiTagAnimationLoop() override;

void step (const sofa::core::ExecParams* params, SReal dt) override;
protected:
void doStep (const sofa::core::ExecParams* params, SReal dt) override;

private:
sofa::core::objectmodel::TagSet tagList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ void BaseSubCollisionPipeline::bwdInit()
doBwdInit();
}

void BaseSubCollisionPipeline::computeCollisionReset()
{
//TODO (SPRINT SED 2025): Component state mechamism
if (!this->isComponentStateValid())
return;

doComputeCollisionReset();
}

void BaseSubCollisionPipeline::computeCollisionDetection()
{
//TODO (SPRINT SED 2025): Component state mechamism
if (!this->isComponentStateValid())
return;

doComputeCollisionDetection();
}

void BaseSubCollisionPipeline::computeCollisionResponse()
{
//TODO (SPRINT SED 2025): Component state mechamism
if (!this->isComponentStateValid())
return;

doComputeCollisionResponse();
}

/**
* @brief Queries all registered contact response types from the Contact factory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,28 @@ class SOFA_COMPONENT_COLLISION_DETECTION_ALGORITHM_API BaseSubCollisionPipeline
/// @brief Called during rendering. Default implementation is empty.
virtual void doDraw(const core::visual::VisualParams* vparams);

/// @brief Delegates collision reset
virtual void doComputeCollisionReset() = 0;

/// @brief Delegates collision detection
virtual void doComputeCollisionDetection() = 0;

/// @brief Delegates response creation
virtual void doComputeCollisionResponse() = 0;

public:
///@{
/// @name Collision Pipeline Interface
/// These methods define the three-phase collision workflow that derived classes must implement.

/// @brief Clears collision state from the previous time step (contacts, responses).
virtual void computeCollisionReset() = 0;
virtual void computeCollisionReset() final;

/// @brief Performs collision detection (bounding tree, broad phase, narrow phase).
virtual void computeCollisionDetection() = 0;
virtual void computeCollisionDetection() final;

/// @brief Creates collision responses based on detected contacts.
virtual void computeCollisionResponse() = 0;
virtual void computeCollisionResponse() final;

///@}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void CompositeCollisionPipeline::reset()
}

/// Delegates collision reset to all sub-pipelines sequentially.
void CompositeCollisionPipeline::doCollisionReset()
void CompositeCollisionPipeline::doComputeCollisionReset()
{
msg_info() << "CompositeCollisionPipeline::doCollisionReset" ;

Expand All @@ -158,7 +158,7 @@ void CompositeCollisionPipeline::doCollisionReset()
*
* @param collisionModels Ignored - each sub-pipeline uses its own linked collision models.
*/
void CompositeCollisionPipeline::doCollisionDetection(const type::vector<core::CollisionModel*>& collisionModels)
void CompositeCollisionPipeline::doComputeCollisionDetection(const type::vector<core::CollisionModel*>& collisionModels)
{
SOFA_UNUSED(collisionModels);

Expand Down Expand Up @@ -188,7 +188,7 @@ void CompositeCollisionPipeline::doCollisionDetection(const type::vector<core::C
}

/// Delegates collision response creation to all sub-pipelines sequentially.
void CompositeCollisionPipeline::doCollisionResponse()
void CompositeCollisionPipeline::doComputeCollisionResponse()
{
for (const auto& subPipeline : l_subCollisionPipelines)
{
Expand All @@ -202,35 +202,4 @@ std::set< std::string > CompositeCollisionPipeline::getResponseList() const
return BaseSubCollisionPipeline::getResponseList();
}

/// Entry point for collision reset phase, called by the simulation loop.
void CompositeCollisionPipeline::computeCollisionReset()
{
if(!this->isComponentStateValid())
return;

doCollisionReset();
}

/// Entry point for collision detection phase, called by the simulation loop.
void CompositeCollisionPipeline::computeCollisionDetection()
{
if(!this->isComponentStateValid())
return;

// The collision models parameter is not used by this pipeline
// since each sub-pipeline manages its own set of models
static std::vector<CollisionModel*> collisionModels{};

doCollisionDetection(collisionModels);
}

/// Entry point for collision response phase, called by the simulation loop.
void CompositeCollisionPipeline::computeCollisionResponse()
{
if(!this->isComponentStateValid())
return;

doCollisionResponse();
}

} // namespace sofa::component::collision::detection::algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,18 @@ class SOFA_COMPONENT_COLLISION_DETECTION_ALGORITHM_API CompositeCollisionPipelin
// -- Pipeline interface

/// @brief Delegates reset to all sub-pipelines to clear previous contacts.
void doCollisionReset() override;
void doComputeCollisionReset() override;

/// @brief Delegates collision detection to all sub-pipelines (optionally in parallel).
/// @note The collisionModels parameter is ignored; each sub-pipeline uses its own models.
void doCollisionDetection(const sofa::type::vector<sofa::core::CollisionModel*>& collisionModels) override;
void doComputeCollisionDetection(const sofa::type::vector<sofa::core::CollisionModel*>& collisionModels) override;

/// @brief Delegates response creation to all sub-pipelines.
void doCollisionResponse() override;
void doComputeCollisionResponse() override;

void bwdInit() override;
void reset() override;

/// @brief Entry point for collision reset, called by the simulation loop.
virtual void computeCollisionReset() override final;

/// @brief Entry point for collision detection, called by the simulation loop.
virtual void computeCollisionDetection() override final;

/// @brief Entry point for collision response, called by the simulation loop.
virtual void computeCollisionResponse() override final;

public:
/// When true, collision detection across sub-pipelines runs in parallel using the task scheduler.
sofa::Data<bool> d_parallelDetection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ void SubCollisionPipeline::doInit()
*
* This ensures a clean slate before new collisions are detected.
*/
void SubCollisionPipeline::computeCollisionReset()
void SubCollisionPipeline::doComputeCollisionReset()
{
if (!this->isComponentStateValid())
return;

msg_info() << "SubCollisionPipeline::doCollisionReset";

// Propagate the intersection method to all collision detection components
Expand All @@ -168,15 +165,12 @@ void SubCollisionPipeline::computeCollisionReset()
/**
* @brief Performs collision detection in two phases: broad phase and narrow phase.
*/
void SubCollisionPipeline::computeCollisionDetection()
void SubCollisionPipeline::doComputeCollisionDetection()
{
const std::string timerPrefix = formatComponentName(this->getName()) + " ";
const std::string globalTimerName = timerPrefix + "doCollisionDetection";
SCOPED_TIMER_VARNAME_DYN(docollisiontimer, globalTimerName.c_str());

if (!this->isComponentStateValid())
return;

msg_info() << "doCollisionDetection, compute Bounding Trees" ;

// Phase 1: Compute bounding volumes for all collision models
Expand Down Expand Up @@ -271,11 +265,8 @@ void SubCollisionPipeline::computeCollisionDetection()
/**
* @brief Creates collision responses based on detected contacts.
*/
void SubCollisionPipeline::computeCollisionResponse()
void SubCollisionPipeline::doComputeCollisionResponse()
{
if (!this->isComponentStateValid())
return;

core::objectmodel::BaseContext* scene = getContext();

msg_info() << "Create Contacts " << l_contactManager->getName() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class SOFA_COMPONENT_COLLISION_DETECTION_ALGORITHM_API SubCollisionPipeline : pu
void doHandleEvent(sofa::core::objectmodel::Event*) override {}

/// @brief Clears contact responses from the previous time step.
void computeCollisionReset() override;
void doComputeCollisionReset() override;

/// @brief Performs collision detection: computes bounding trees, runs broad and narrow phase detection.
void computeCollisionDetection() override;
void doComputeCollisionDetection() override;

/// @brief Creates contact responses based on detected collisions.
void computeCollisionResponse() override;
void doComputeCollisionResponse() override;

/// @brief Returns the list of collision models handled by this pipeline.
std::vector<sofa::core::CollisionModel*> getCollisionModels() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CubeCollisionModel::CubeCollisionModel()
enum_type = AABB_TYPE;
}

void CubeCollisionModel::resize(sofa::Size size)
void CubeCollisionModel::doResize(sofa::Size size)
{
const auto size0 = this->size;
if (size == size0) return;
Expand All @@ -54,7 +54,7 @@ void CubeCollisionModel::resize(sofa::Size size)
parent->resize(0);
parent = parent->getPrevious();
}
this->core::CollisionModel::resize(size);
this->core::CollisionModel::doResize(size);
this->elems.resize(size);
this->parentOf.resize(size);
// set additional indices
Expand Down Expand Up @@ -104,7 +104,7 @@ Index CubeCollisionModel::addCube(Cube subcellsBegin, Cube subcellsEnd)
{
const sofa::Index index = size;

this->core::CollisionModel::resize(index + 1);
this->core::CollisionModel::doResize(index + 1);
elems.resize(index + 1);

elems[index].subcells.first = subcellsBegin;
Expand Down Expand Up @@ -226,7 +226,7 @@ bool CubeCollisionModel::isLeaf(sofa::Index index ) const
return elems[index].children.first.valid();
}

void CubeCollisionModel::computeBoundingTree(int maxDepth)
void CubeCollisionModel::doComputeBoundingTree(int maxDepth)
{

dmsg_info() << ">CubeCollisionModel::computeBoundingTree(" << maxDepth << ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,22 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API CubeCollisionModel : public core::Co
CubeCollisionModel();

void drawCollisionModel(const core::visual::VisualParams* vparams) override;
void doResize(sofa::Size size) override;

// -- CollisionModel interface

/**
*Here we make up the hierarchy (a tree) of bounding boxes which contain final CollisionElements like Spheres or Triangles.
*The leafs of the tree contain final CollisionElements. This hierarchy is made up from the top to the bottom, i.e., we begin
*to compute a bounding box containing all CollisionElements, then we divide this big bounding box into two boxes.
*These new two boxes inherit from the root box and have depth 1. Then we can do the same operation for the new boxes.
*The division is done only if the box contains more than 4 final CollisionElements and if the depth doesn't exceed
*the max depth. The division is made along an axis. This axis corresponds to the biggest dimension of the current bounding box.
*Note : a bounding box is a Cube here.
*/
void doComputeBoundingTree(int maxDepth=0) override;

public:
void resize(sofa::Size size) override;

void setParentOf(sofa::Index childIndex, const sofa::type::Vec3& min, const sofa::type::Vec3& max);
void setParentOf(sofa::Index childIndex, const sofa::type::Vec3& min, const sofa::type::Vec3& max, const sofa::type::Vec3& normal, const SReal angle=0);
Expand Down Expand Up @@ -121,19 +135,6 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API CubeCollisionModel : public core::Co

const CubeData & getCubeData(sofa::Index index)const{return elems[index];}

// -- CollisionModel interface

/**
*Here we make up the hierarchy (a tree) of bounding boxes which contain final CollisionElements like Spheres or Triangles.
*The leafs of the tree contain final CollisionElements. This hierarchy is made up from the top to the bottom, i.e., we begin
*to compute a bounding box containing all CollisionElements, then we divide this big bounding box into two boxes.
*These new two boxes inherit from the root box and have depth 1. Then we can do the same operation for the new boxes.
*The division is done only if the box contains more than 4 final CollisionElements and if the depth doesn't exceed
*the max depth. The division is made along an axis. This axis corresponds to the biggest dimension of the current bounding box.
*Note : a bounding box is a Cube here.
*/
void computeBoundingTree(int maxDepth=0) override;

std::pair<core::CollisionElementIterator,core::CollisionElementIterator> getInternalChildren(sofa::Index index) const override;

std::pair<core::CollisionElementIterator,core::CollisionElementIterator> getExternalChildren(sofa::Index index) const override;
Expand Down
Loading
Loading