diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp index 61ec57f65ca..0695a61feea 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp @@ -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(this->l_node.get()); diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.h b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.h index 43c65a90504..2c59fefd372 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.h +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.h @@ -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 d_displayTime; ///< Display time for each important step of ConstraintAnimationLoop. @@ -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); diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp index 9ef600d8d71..6dd3f1e47c9 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp @@ -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(this->l_node.get()); diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.h b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.h index c930a8b53b2..b966c2310ee 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.h +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.h @@ -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 d_solveVelocityConstraintFirst; ///< solve separately velocity constraint violations before position constraint violations @@ -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 l_constraintSolver; diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.cpp index fbb409c4dd5..7516e74d12d 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.cpp @@ -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(this->l_node.get()); diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.h b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.h index 1a71de83df1..5af77dacdb2 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.h +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiStepAnimationLoop.h @@ -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 d_collisionSteps; ///< number of collision steps between each frame rendering Data d_integrationSteps; ///< number of integration steps between each collision detection }; diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.cpp index 990eb77dd46..b482c3ae6c1 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.cpp @@ -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(this->l_node.get()); diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.h b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.h index 630e423adee..969471bb4dc 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.h +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/MultiTagAnimationLoop.h @@ -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; diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp index 6fb78d79921..d2c9ee3a93b 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.cpp @@ -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. * diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.h b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.h index 9e626ac2d2b..a2bee362bbe 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.h +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/BaseSubCollisionPipeline.h @@ -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; ///@} diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.cpp b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.cpp index a93bc56cda3..1774bf938f9 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.cpp +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.cpp @@ -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" ; @@ -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& collisionModels) +void CompositeCollisionPipeline::doComputeCollisionDetection(const type::vector& collisionModels) { SOFA_UNUSED(collisionModels); @@ -188,7 +188,7 @@ void CompositeCollisionPipeline::doCollisionDetection(const type::vector 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 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 diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.h b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.h index 706e6b8da4c..713f690b397 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.h +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/CompositeCollisionPipeline.h @@ -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& collisionModels) override; + void doComputeCollisionDetection(const sofa::type::vector& 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 d_parallelDetection; diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.cpp b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.cpp index 4743daf2221..e977cdfe6f9 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.cpp +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.cpp @@ -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 @@ -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 @@ -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() ; diff --git a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.h b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.h index 406d036b493..1604e2ed708 100644 --- a/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.h +++ b/Sofa/Component/Collision/Detection/Algorithm/src/sofa/component/collision/detection/algorithm/SubCollisionPipeline.h @@ -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 getCollisionModels() override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.cpp index 0e756637900..13a2959bba3 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.cpp @@ -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; @@ -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 @@ -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; @@ -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 << ")"; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.h index 511aad2d24d..9794922c20b 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CubeCollisionModel.h @@ -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); @@ -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 getInternalChildren(sofa::Index index) const override; std::pair getExternalChildren(sofa::Index index) const override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.h index ed1fbd88f95..15f4bdfa21c 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.h @@ -101,13 +101,13 @@ class CylinderCollisionModel : public core::CollisionModel CylinderCollisionModel(); CylinderCollisionModel(core::behavior::MechanicalState* mstate ); -public: - void init() override; - // -- CollisionModel interface - void resize(sofa::Size size) override; + void doResize(sofa::Size size) override; - void computeBoundingTree(int maxDepth=0) override; + void doComputeBoundingTree(int maxDepth=0) override; + +public: + void init() override; void draw(const core::visual::VisualParams* vparams,sofa::Index index) override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.inl index b73b1a0641e..1568538a060 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/CylinderCollisionModel.inl @@ -55,9 +55,9 @@ CylinderCollisionModel::CylinderCollisionModel(core::behavior::Mechan } template -void CylinderCollisionModel::resize(sofa::Size size) +void CylinderCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); VecReal & Cylinder_radii = *d_cylinder_radii.beginEdit(); VecReal & Cylinder_heights = *d_cylinder_heights.beginEdit(); @@ -115,7 +115,7 @@ void CylinderCollisionModel::init() template -void CylinderCollisionModel::computeBoundingTree(int maxDepth) +void CylinderCollisionModel::doComputeBoundingTree(int maxDepth) { using namespace sofa::type; using namespace sofa::defaulttype; @@ -125,6 +125,7 @@ void CylinderCollisionModel::computeBoundingTree(int maxDepth) bool updated = false; if (ncyl != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(ncyl); updated = true; cubeModel->resize(0); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.h index 374569733fa..41221a72bbf 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.h @@ -104,6 +104,21 @@ public : void drawCollisionModel(const core::visual::VisualParams* vparams) override; + // -- CollisionModel interface + + void doResize(sofa::Size size) override; + + void doComputeBoundingTree(int maxDepth=0) override; + + void doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth=0) override; + + bool doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; + + sofa::core::topology::BaseMeshTopology* doGetCollisionTopology() override + { + return l_topology.get(); + } + public: typedef TDataTypes DataTypes; typedef DataTypes InDataTypes; @@ -118,18 +133,8 @@ public : void init() override; - // -- CollisionModel interface - - void resize(sofa::Size size) override; - - void computeBoundingTree(int maxDepth=0) override; - - void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; - void handleTopologyChange() override; - bool canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; - core::behavior::MechanicalState* getMechanicalState() { return mstate; } Deriv velocity(sofa::Index index)const; @@ -154,11 +159,6 @@ public : return sofa::core::objectmodel::BaseComponent::canCreate(obj, context, arg); } - sofa::core::topology::BaseMeshTopology* getCollisionTopology() override - { - return l_topology.get(); - } - void computeBBox(const core::ExecParams* params, bool onlyVisible) override; Data d_displayFreePosition; ///< Display Collision Model Points free position(in green) diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.inl index dd485591a07..9f5959d0938 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/LineCollisionModel.inl @@ -47,9 +47,9 @@ LineCollisionModel::LineCollisionModel() template -void LineCollisionModel::resize(sofa::Size size) +void LineCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); elems.resize(size); } @@ -354,7 +354,7 @@ void LineCollisionModel::drawCollisionModel(const core::visual::Visua } template -bool LineCollisionModel::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) +bool LineCollisionModel::doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) { if (!this->bSelfCollision.getValue()) return true; if (this->getContext() != model2->getContext()) return true; @@ -458,7 +458,7 @@ bool LineCollisionModel::canCollideWithElement(sofa::Index index, Col } template -void LineCollisionModel::computeBoundingTree(int maxDepth) +void LineCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); updateFromTopology(); @@ -495,7 +495,7 @@ void LineCollisionModel::computeBoundingTree(int maxDepth) } template -void LineCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) +void LineCollisionModel::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); updateFromTopology(); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.h index e5ebbec02ba..53f16464340 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.h @@ -84,19 +84,9 @@ class PointCollisionModel : public core::CollisionModel public: void init() override; - - // -- CollisionModel interface - - void resize(sofa::Size size) override; - - void computeBoundingTree(int maxDepth=0) override; - - void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; - + void draw(const core::visual::VisualParams*, sofa::Index index) override; - bool canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; - core::behavior::MechanicalState* getMechanicalState() { return mstate; } Deriv getNormal(sofa::Index index){ return (normals.size()) ? normals[index] : Deriv();} @@ -122,11 +112,6 @@ class PointCollisionModel : public core::CollisionModel void computeBBox(const core::ExecParams* params, bool onlyVisible) override; void updateNormals(); - sofa::core::topology::BaseMeshTopology* getCollisionTopology() override - { - return l_topology.get(); - } - protected: core::behavior::MechanicalState* mstate; @@ -139,6 +124,18 @@ class PointCollisionModel : public core::CollisionModel /// Link to be set to the topology container in the component graph. SingleLink, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; + // -- CollisionModel interface + + void doComputeBoundingTree(int maxDepth=0) override; + + void doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; + + bool doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; + + sofa::core::topology::BaseMeshTopology* doGetCollisionTopology() override + { + return l_topology.get(); + } }; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.inl index 8a10d5227df..72d95d13a7a 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/PointCollisionModel.inl @@ -43,12 +43,6 @@ PointCollisionModel::PointCollisionModel() enum_type = POINT_TYPE; } -template -void PointCollisionModel::resize(sofa::Size size) -{ - this->core::CollisionModel::resize(size); -} - template void PointCollisionModel::init() { @@ -74,7 +68,7 @@ void PointCollisionModel::init() template -bool PointCollisionModel::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) +bool PointCollisionModel::doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) { if (!this->bSelfCollision.getValue()) return true; // we need to perform this verification process only for the selfcollision case. @@ -112,13 +106,14 @@ bool PointCollisionModel::canCollideWithElement(sofa::Index index, Co } template -void PointCollisionModel::computeBoundingTree(int maxDepth) +void PointCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); const auto npoints = mstate->getSize(); bool updated = false; if (npoints != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(npoints); updated = true; } @@ -143,13 +138,14 @@ void PointCollisionModel::computeBoundingTree(int maxDepth) } template -void PointCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag , int maxDepth) +void PointCollisionModel::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); const auto npoints = mstate->getSize(); bool updated = false; if (npoints != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(npoints); updated = true; } diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.cpp index 08ec23ec121..d6267f4af4f 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.cpp @@ -44,9 +44,9 @@ RayCollisionModel::RayCollisionModel(SReal length) this->contactResponse.setValue("RayContact"); // use RayContact response class } -void RayCollisionModel::resize(sofa::Size size) +void RayCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); if (length.size() < size) { @@ -110,7 +110,7 @@ void RayCollisionModel::draw(const core::visual::VisualParams* vparams, sofa::In } -void RayCollisionModel::computeBoundingTree(int maxDepth) +void RayCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.h index 5e492069de7..a48b3e23119 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/RayCollisionModel.h @@ -63,13 +63,14 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API RayCollisionModel : public core::Col friend class Ray; protected: RayCollisionModel(SReal defaultLength=1); -public: - void init() override; // -- CollisionModel interface - void resize(sofa::Size size) override; + void doResize(sofa::Size size) override; + + void doComputeBoundingTree(int maxDepth) override; - void computeBoundingTree(int maxDepth) override; +public: + void init() override; void draw(const core::visual::VisualParams*, sofa::Index index) override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.h index 6ba48175cde..9a810379d7b 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.h @@ -104,13 +104,14 @@ class SphereCollisionModel : public core::CollisionModel public: void init() override; + // -- CollisionModel interface - void resize(sofa::Size size) override; + void doResize(sofa::Size size) override; - void computeBoundingTree(int maxDepth=0) override; + void doComputeBoundingTree(int maxDepth=0) override; - void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; + void doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; void draw(const core::visual::VisualParams*, sofa::Index index) override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.inl index f1c9370aba8..76db9d25781 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/SphereCollisionModel.inl @@ -54,9 +54,9 @@ SphereCollisionModel::SphereCollisionModel(core::behavior::Mechanical template -void SphereCollisionModel::resize(sofa::Size size) +void SphereCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); helper::WriteAccessor< Data > r = d_radius; @@ -156,7 +156,7 @@ void SphereCollisionModel::drawCollisionModel(const core::visual::Vis } template -void SphereCollisionModel::computeBoundingTree(int maxDepth) +void SphereCollisionModel::doComputeBoundingTree(int maxDepth) { if(d_componentState.getValue() != ComponentState::Valid) return ; @@ -166,6 +166,7 @@ void SphereCollisionModel::computeBoundingTree(int maxDepth) bool updated = false; if (npoints != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(npoints); updated = true; cubeModel->resize(0); @@ -194,7 +195,7 @@ void SphereCollisionModel::computeBoundingTree(int maxDepth) template -void SphereCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) +void SphereCollisionModel::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { using sofa::type::Vec3 ; @@ -206,6 +207,7 @@ void SphereCollisionModel::computeContinuousBoundingTree(SReal dt, Co bool updated = false; if (npoints != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(npoints); updated = true; cubeModel->resize(0); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.cpp index ca88ef0f133..e9327cedef8 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.cpp @@ -50,9 +50,9 @@ TetrahedronCollisionModel::TetrahedronCollisionModel() enum_type = TETRAHEDRON_TYPE; } -void TetrahedronCollisionModel::resize(sofa::Size size) +void TetrahedronCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); elems.resize(size); if (getPrevious() != nullptr) getPrevious()->resize(0); // force recomputation of bounding tree } @@ -193,7 +193,7 @@ void TetrahedronCollisionModel::drawCollisionModel(const core::visual::VisualPar } } -void TetrahedronCollisionModel::computeBoundingTree(int maxDepth) +void TetrahedronCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); if (!mstate || !m_topology) return; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.h index 5c93d0fb484..efed38917c7 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TetrahedronCollisionModel.h @@ -111,13 +111,14 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API TetrahedronCollisionModel : public c public: void init() override; + // -- CollisionModel interface - void resize(sofa::Size size) override; + void doResize(sofa::Size size) override; - void computeBoundingTree(int maxDepth=0) override; + void doComputeBoundingTree(int maxDepth=0) override; - //virtual void computeContinuousBoundingTree(double dt, int maxDepth=0); + //virtual void doComputeContinuousBoundingTree(double dt, int maxDepth=0); void draw(const core::visual::VisualParams*, sofa::Index index) override; diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.h index 712c6db49f6..358332e082f 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.h @@ -170,20 +170,26 @@ class TriangleCollisionModel : public core::CollisionModel virtual void updateNormals(); void drawCollisionModel(const core::visual::VisualParams* vparams) override; -public: - void init() override; - // -- CollisionModel interface - void resize(sofa::Size size) override; + void doResize(sofa::Size size) override; - void computeBoundingTree(int maxDepth=0) override; + void doComputeBoundingTree(int maxDepth=0) override; - void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; + void doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; - void draw(const core::visual::VisualParams*, sofa::Index index) override; - bool canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; + bool doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; + + sofa::core::topology::BaseMeshTopology* doGetCollisionTopology() override + { + return l_topology.get(); + } + +public: + void init() override; + + void draw(const core::visual::VisualParams*, sofa::Index index) override; core::behavior::MechanicalState* getMechanicalState() { return m_mstate; } const core::behavior::MechanicalState* getMechanicalState() const { return m_mstate; } @@ -212,10 +218,6 @@ class TriangleCollisionModel : public core::CollisionModel void computeBBox(const core::ExecParams* params, bool onlyVisible=false) override; - sofa::core::topology::BaseMeshTopology* getCollisionTopology() override - { - return l_topology.get(); - } }; template diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.inl b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.inl index f2bc2b681ef..fbe193b777d 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.inl +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleCollisionModel.inl @@ -50,9 +50,9 @@ TriangleCollisionModel::TriangleCollisionModel() } template -void TriangleCollisionModel::resize(sofa::Size size) +void TriangleCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); m_normals.resize(size); } @@ -194,7 +194,7 @@ void TriangleCollisionModel::updateFromTopology() template -bool TriangleCollisionModel::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) +bool TriangleCollisionModel::doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) { if (!this->bSelfCollision.getValue()) return true; // we need to perform this verification process only for the selfcollision case. if (this->getContext() != model2->getContext()) return true; @@ -214,7 +214,7 @@ bool TriangleCollisionModel::canCollideWithElement(sofa::Index index, } template -void TriangleCollisionModel::computeBoundingTree(int maxDepth) +void TriangleCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); @@ -276,7 +276,7 @@ void TriangleCollisionModel::computeBoundingTree(int maxDepth) } template -void TriangleCollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) +void TriangleCollisionModel::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp index 31912c20506..75d9eddef96 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.cpp @@ -101,7 +101,7 @@ void TriangleModelInRegularGrid::init() } } -void TriangleModelInRegularGrid::computeBoundingTree ( int ) +void TriangleModelInRegularGrid::doComputeBoundingTree ( int ) { CubeCollisionModel* cubeModel = createPrevious(); updateFromTopology(); diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.h index 74319ab7d37..cb106163f28 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleModelInRegularGrid.h @@ -35,15 +35,17 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API TriangleModelInRegularGrid : public SOFA_CLASS(TriangleModelInRegularGrid, TriangleCollisionModel); void init() override; - void computeBoundingTree ( int maxDepth=0 ) override; sofa::core::topology::BaseMeshTopology* _topology; sofa::core::topology::BaseMeshTopology* _higher_topo; core::behavior::MechanicalState* _higher_mstate; + protected: TriangleModelInRegularGrid(); ~TriangleModelInRegularGrid(); + + void doComputeBoundingTree ( int maxDepth=0 ) override; }; } // namespace sofa::component::collision::geometry diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp index 62abb5bdc39..00432e41875 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.cpp @@ -71,7 +71,7 @@ void TriangleOctreeCollisionModel::drawCollisionModel (const core::visual::Visua } } -void TriangleOctreeCollisionModel::computeBoundingTree(int maxDepth) +void TriangleOctreeModel::doComputeBoundingTree(int maxDepth) { const type::vector& tri = *m_triangles; if(octreeRoot) @@ -129,9 +129,10 @@ void TriangleOctreeCollisionModel::computeBoundingTree(int maxDepth) } } -void TriangleOctreeCollisionModel::computeContinuousBoundingTree(SReal/* dt*/, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) + +void TriangleOctreeModel::doComputeContinuousBoundingTree(SReal/* dt*/, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { - computeBoundingTree(maxDepth); + doComputeBoundingTree(maxDepth); } void TriangleOctreeCollisionModel::buildOctree() diff --git a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.h b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.h index 1a36dfb96c9..00a171292ea 100644 --- a/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.h +++ b/Sofa/Component/Collision/Geometry/src/sofa/component/collision/geometry/TriangleOctreeCollisionModel.h @@ -40,13 +40,15 @@ class SOFA_COMPONENT_COLLISION_GEOMETRY_API TriangleOctreeCollisionModel : publi protected: TriangleOctreeCollisionModel(); void drawCollisionModel(const core::visual::VisualParams* vparams) override; + + + void doComputeBoundingTree(int maxDepth=0) override; + void doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; public: Data d_drawOctree; ///< draw the octree /// the normals for each point type::vector pNorms; - void computeBoundingTree(int maxDepth=0) override; - void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) override; /// init the octree creation void buildOctree (); }; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.h index be1b273b7ea..6b3fd5eba1f 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.h @@ -111,6 +111,9 @@ public : virtual ~AffineMovementProjectiveConstraint(); + // Implement projectMatrix for assembled solver of compliant + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; + public: //Add or clear constraints void clearConstraints(); @@ -135,9 +138,6 @@ public : /// Compute the theoretical final positions void getFinalPositions (VecCoord& finalPos, DataVecCoord& xData); - // Implement projectMatrix for assembled solver of compliant - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - /// Draw the constrained points (= border mesh points) void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl index e72a9e1f38d..937e13cfa0e 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AffineMovementProjectiveConstraint.inl @@ -198,7 +198,7 @@ void AffineMovementProjectiveConstraint::projectPosition(const core:: } template -void AffineMovementProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned /*offset*/ ) +void AffineMovementProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned /*offset*/ ) { // clears the rows and columns associated with constrained particles const unsigned blockSize = DataTypes::deriv_total_size; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.h index 427a9d276ba..78d979bb03d 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.h @@ -74,6 +74,17 @@ class AttachProjectiveConstraint : public core::behavior::PairInteractionProject AttachProjectiveConstraint(core::behavior::MechanicalState *mm1, core::behavior::MechanicalState *mm2); ~AttachProjectiveConstraint() override; + /// Inherited from Constraint + void doProjectJacobianMatrix(const core::MechanicalParams* mparams, core::MultiMatrixDerivId cId) override; + + /// Project the global Mechanical Matrix to constrained space using offset parameter + void doApplyConstraint(const core::MechanicalParams *mparams, + const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + /// Project the global Mechanical Vector to constrained space using offset parameter + void doApplyConstraint(const core::MechanicalParams *mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + public: /// Inherited from Base @@ -81,20 +92,10 @@ class AttachProjectiveConstraint : public core::behavior::PairInteractionProject void reinit() override; void draw(const core::visual::VisualParams* vparams) override; - /// Inherited from Constraint - void projectJacobianMatrix(const core::MechanicalParams* mparams, core::MultiMatrixDerivId cId) override; void projectResponse(const core::MechanicalParams *mparams, DataVecDeriv& dx1, DataVecDeriv& dx2) override; void projectVelocity(const core::MechanicalParams *mparams, DataVecDeriv& v1, DataVecDeriv& v2) override; void projectPosition(const core::MechanicalParams *mparams, DataVecCoord& x1, DataVecCoord& x2) override; - /// Project the global Mechanical Matrix to constrained space using offset parameter - void applyConstraint(const core::MechanicalParams *mparams, - const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - /// Project the global Mechanical Vector to constrained space using offset parameter - void applyConstraint(const core::MechanicalParams *mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - virtual void reinitIfChanged(); template diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.inl index aff77b5954d..17e2727f998 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/AttachProjectiveConstraint.inl @@ -285,7 +285,7 @@ template <> void AttachProjectiveConstraint::calcRestRotations(); template -void AttachProjectiveConstraint::projectJacobianMatrix(const core::MechanicalParams* mparams, core::MultiMatrixDerivId cId) +void AttachProjectiveConstraint::doProjectJacobianMatrix(const core::MechanicalParams* mparams, core::MultiMatrixDerivId cId) { SOFA_UNUSED(mparams); SOFA_UNUSED(cId); @@ -452,7 +452,7 @@ void AttachProjectiveConstraint::projectResponse(const core::Mechanic // Matrix Integration interface template -void AttachProjectiveConstraint::applyConstraint(const core::MechanicalParams * mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void AttachProjectiveConstraint::doApplyConstraint(const core::MechanicalParams * mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if (f_twoWay.getValue()) @@ -504,7 +504,7 @@ void AttachProjectiveConstraint::applyConstraint(const core::Mechanic template -void AttachProjectiveConstraint::applyConstraint(const core::MechanicalParams * mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void AttachProjectiveConstraint::doApplyConstraint(const core::MechanicalParams * mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if (f_twoWay.getValue()) @@ -546,7 +546,7 @@ void AttachProjectiveConstraint::applyConstraint(const core::Mechanic } template -void AttachProjectiveConstraint::applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) +void AttachProjectiveConstraint::doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) { if (f_twoWay.getValue()) return; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.h index 32fa61b897e..17afcf3fd50 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.h @@ -93,6 +93,11 @@ class DirectionProjectiveConstraint : public core::behavior::ProjectiveConstrain type::vector m_origin; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + /// Project the given matrix (Experimental API, see the spec in sofa::core::behavior::BaseProjectiveConstraintSet). + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; public: void clearConstraints(); @@ -108,13 +113,6 @@ class DirectionProjectiveConstraint : public core::behavior::ProjectiveConstrain void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - /// Project the given matrix (Experimental API, see the spec in sofa::core::behavior::BaseProjectiveConstraintSet). - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void draw(const core::visual::VisualParams* vparams) override; protected : diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl index eede78445e6..732f74a4d7d 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/DirectionProjectiveConstraint.inl @@ -171,7 +171,7 @@ void DirectionProjectiveConstraint::reinit() } template -void DirectionProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void DirectionProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { J.copy(jacobian, M->colSize(), offset); // projection matrix for an assembled state BaseSparseMatrix* E = dynamic_cast(M); @@ -222,13 +222,13 @@ void DirectionProjectiveConstraint::projectPosition(const core::Mecha } template -void DirectionProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void DirectionProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { msg_error() << "applyConstraint is not implemented"; } template -void DirectionProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void DirectionProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { dmsg_error() << "DirectionProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) is not implemented"; } diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.h index 79770550c4d..d635101807f 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.h @@ -84,20 +84,8 @@ class FixedPlaneProjectiveConstraint : public ProjectiveConstraintSet void projectResponse(const MechanicalParams* mparams, DataVecDeriv& resData) override; void projectVelocity(const MechanicalParams* mparams, DataVecDeriv& vData) override; void projectPosition(const MechanicalParams* mparams, DataVecCoord& xData) override; - - /// Implement projectMatrix for assembled solver of compliant - void projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset) override; void projectJacobianMatrix(const MechanicalParams* mparams, DataMatrixDeriv& cData) override; - /// Implement applyConstraint for direct solvers - void applyConstraint(const MechanicalParams* mparams, - const MultiMatrixAccessor* matrix) override; - - void applyConstraint(const MechanicalParams* mparams, BaseVector* vect, - const MultiMatrixAccessor* matrix) override; - - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - void setDirection (Coord dir); void selectVerticesAlongPlane(); void setDminAndDmax(const Real _dmin,const Real _dmax); @@ -124,6 +112,18 @@ class FixedPlaneProjectiveConstraint : public ProjectiveConstraintSet using ProjectiveConstraintSet::getContext; bool isPointInPlane(const Coord& p) const ; + + /// Implement applyConstraint for direct solvers + void doApplyConstraint(const MechanicalParams* mparams, + const MultiMatrixAccessor* matrix) override; + + void doApplyConstraint(const MechanicalParams* mparams, BaseVector* vect, + const MultiMatrixAccessor* matrix) override; + + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + + /// Implement projectMatrix for assembled solver of compliant + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset) override; }; #if !defined(SOFA_COMPONENT_PROJECTIVECONSTRAINTSET_FIXEDPLANEPROJECTIVECONSTRAINT_CPP) diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl index b6b151f6dd4..248ef2147d2 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedPlaneProjectiveConstraint.inl @@ -56,7 +56,7 @@ FixedPlaneProjectiveConstraint::~FixedPlaneProjectiveConstraint() /// Matrix Integration interface template -void FixedPlaneProjectiveConstraint::applyConstraint(const MechanicalParams* mparams, const MultiMatrixAccessor* matrix) +void FixedPlaneProjectiveConstraint::doApplyConstraint(const MechanicalParams* mparams, const MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(const MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(mstate.get())) @@ -81,7 +81,7 @@ void FixedPlaneProjectiveConstraint::applyConstraint(const Mechanical } template -void FixedPlaneProjectiveConstraint::applyConstraint(const MechanicalParams* mparams, +void FixedPlaneProjectiveConstraint::doApplyConstraint(const MechanicalParams* mparams, BaseVector* vect, const MultiMatrixAccessor* matrix) { @@ -106,7 +106,7 @@ void FixedPlaneProjectiveConstraint::applyConstraint(const Mechanical } template -void FixedPlaneProjectiveConstraint::applyConstraint( +void FixedPlaneProjectiveConstraint::doApplyConstraint( sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); @@ -194,7 +194,7 @@ void FixedPlaneProjectiveConstraint::projectPosition(const Mechanical } template -void FixedPlaneProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned /*offset*/ ) +void FixedPlaneProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned /*offset*/ ) { /// clears the rows and columns associated with constrained particles const unsigned blockSize = DataTypes::deriv_total_size; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.h index 5e72b7d5217..b46dc409845 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.h @@ -75,6 +75,11 @@ class FixedProjectiveConstraint : public core::behavior::ProjectiveConstraintSet virtual ~FixedProjectiveConstraint(); + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + public: SetIndex d_indices; Data d_fixAll; ///< filter all the DOF to implement a fixed object @@ -88,6 +93,10 @@ class FixedProjectiveConstraint : public core::behavior::ProjectiveConstraintSet std::unique_ptr > data { nullptr }; friend class FixedProjectiveConstraintInternalData; + /** Project the given matrix (Experimental API). + See doc in base parent class + */ + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; public: void clearConstraints(); @@ -104,16 +113,6 @@ class FixedProjectiveConstraint : public core::behavior::ProjectiveConstraintSet void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - /** Project the given matrix (Experimental API). - See doc in base parent class - */ - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - void computeBBox(const core::ExecParams* params, bool onlyVisible) override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl index 2c80a45edac..d3e1d5660f4 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/FixedProjectiveConstraint.inl @@ -157,7 +157,7 @@ void FixedProjectiveConstraint::checkIndices() } template -void FixedProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void FixedProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { static const unsigned blockSize = DataTypes::deriv_total_size; @@ -266,7 +266,7 @@ void FixedProjectiveConstraint::projectPosition(const core::Mechanica // Matrix Integration interface template -void FixedProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void FixedProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(const core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate.get())) @@ -304,7 +304,7 @@ void FixedProjectiveConstraint::applyConstraint(const core::Mechanica } template -void FixedProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void FixedProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vect, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const int o = matrix->getGlobalOffset(this->mstate.get()); @@ -334,7 +334,7 @@ void FixedProjectiveConstraint::applyConstraint(const core::Mechanica } template -void FixedProjectiveConstraint::applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) +void FixedProjectiveConstraint::doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.h index 61363e5aa80..0ddeb412727 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.h @@ -93,6 +93,12 @@ class LineProjectiveConstraint : public core::behavior::ProjectiveConstraintSet< std::unique_ptr> data { nullptr }; friend class LineProjectiveConstraintInternalData; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + /// Project the given matrix (Experimental API, see the spec in sofa::core::behavior::BaseProjectiveConstraintSet). + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; + public: void clearConstraints(); void addConstraint(Index index); @@ -107,12 +113,6 @@ class LineProjectiveConstraint : public core::behavior::ProjectiveConstraintSet< void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - /// Project the given matrix (Experimental API, see the spec in sofa::core::behavior::BaseProjectiveConstraintSet). - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl index de53dbb9571..bd5931102e4 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LineProjectiveConstraint.inl @@ -168,7 +168,7 @@ void LineProjectiveConstraint::updateJacobian() } template -void LineProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void LineProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { J.copy(jacobian, M->colSize(), offset); // projection matrix for an assembled state BaseSparseMatrix* E = dynamic_cast(M); @@ -228,13 +228,13 @@ void LineProjectiveConstraint::projectPosition(const core::Mechanical // Matrix Integration interface template -void LineProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void LineProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { msg_error() << "applyConstraint is not implemented "; } template -void LineProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void LineProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { msg_error() << "LineProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) is not implemented "; } diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.h index 6c61748846c..6bb8a5571d7 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.h @@ -104,6 +104,12 @@ public : LinearMovementProjectiveConstraint(); ~LinearMovementProjectiveConstraint() override; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; + public: ///methods to add/remove some indices, keyTimes, keyMovement void clearIndices(); @@ -127,12 +133,6 @@ public : void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - void draw(const core::visual::VisualParams* vparams) override; protected: diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl index db39905ef92..706e1e3bbc8 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearMovementProjectiveConstraint.inl @@ -331,7 +331,7 @@ void LinearMovementProjectiveConstraint::findKeyTimes() template -void LinearMovementProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void LinearMovementProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { static const unsigned blockSize = DataTypes::deriv_total_size; @@ -346,7 +346,7 @@ void LinearMovementProjectiveConstraint::projectMatrix( sofa::lineara // Matrix Integration interface template -void LinearMovementProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void LinearMovementProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(const core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate.get())) @@ -367,7 +367,7 @@ void LinearMovementProjectiveConstraint::applyConstraint(const core:: } template -void LinearMovementProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void LinearMovementProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const int o = matrix->getGlobalOffset(this->mstate.get()); @@ -386,7 +386,7 @@ void LinearMovementProjectiveConstraint::applyConstraint(const core:: } template -void LinearMovementProjectiveConstraint::applyConstraint( +void LinearMovementProjectiveConstraint::doApplyConstraint( sofa::core::behavior::ZeroDirichletCondition* matrix) { constexpr unsigned int N = Deriv::size(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.h index c75c97db7f1..daa114d559b 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.h @@ -90,6 +90,14 @@ public : LinearVelocityProjectiveConstraint(); virtual ~LinearVelocityProjectiveConstraint(); + + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; + public: ///methods to add/remove some indices, keyTimes, keyVelocity void clearIndices(); @@ -112,13 +120,6 @@ public : void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - void draw(const core::visual::VisualParams* vparams) override; private: diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.inl index c1cdacc363a..ae9406296d6 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/LinearVelocityProjectiveConstraint.inl @@ -335,7 +335,7 @@ void LinearVelocityProjectiveConstraint::projectJacobianMatrix(const } template -void LinearVelocityProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void LinearVelocityProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); @@ -360,7 +360,7 @@ void LinearVelocityProjectiveConstraint::applyConstraint(const core:: } template -void LinearVelocityProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void LinearVelocityProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(isConstraintActive()) @@ -389,7 +389,7 @@ void LinearVelocityProjectiveConstraint::applyConstraint(const core:: } template -void LinearVelocityProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void LinearVelocityProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { static const unsigned blockSize = DataTypes::deriv_total_size; @@ -407,7 +407,7 @@ void LinearVelocityProjectiveConstraint::projectMatrix( sofa::lineara } template -void LinearVelocityProjectiveConstraint::applyConstraint( +void LinearVelocityProjectiveConstraint::doApplyConstraint( sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.h index 89bc6dab2f3..872abbe20d4 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.h @@ -71,6 +71,12 @@ class PartialFixedProjectiveConstraint : public FixedProjectiveConstraint void projectResponseT(DataDeriv& dx, diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.inl index 32ddb3d3fab..cb724b40117 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialFixedProjectiveConstraint.inl @@ -166,7 +166,7 @@ void PartialFixedProjectiveConstraint::projectJacobianMatrix(const co } template -void PartialFixedProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PartialFixedProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const int o = matrix->getGlobalOffset(this->mstate.get()); @@ -208,7 +208,7 @@ void PartialFixedProjectiveConstraint::applyConstraint(const core::Me } template -void PartialFixedProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PartialFixedProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(const core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate.get())) @@ -266,7 +266,7 @@ void PartialFixedProjectiveConstraint::applyConstraint(const core::Me } template -void PartialFixedProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void PartialFixedProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { static const unsigned blockSize = DataTypes::deriv_total_size; @@ -303,7 +303,7 @@ void PartialFixedProjectiveConstraint::projectMatrix( sofa::linearalg } template -void PartialFixedProjectiveConstraint::applyConstraint( +void PartialFixedProjectiveConstraint::doApplyConstraint( sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.h index 19a1bf4b172..14178295438 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.h @@ -115,6 +115,10 @@ public : PartialLinearMovementProjectiveConstraint(); ~PartialLinearMovementProjectiveConstraint() override; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + public: ///methods to add/remove some indices, keyTimes, keyMovement void clearIndices(); @@ -138,10 +142,6 @@ public : void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - void draw(const core::visual::VisualParams*) override; protected: diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl index 340c6a1543d..834d2a586be 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PartialLinearMovementProjectiveConstraint.inl @@ -411,7 +411,7 @@ void PartialLinearMovementProjectiveConstraint::findKeyTimes() // Matrix Integration interface template -void PartialLinearMovementProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PartialLinearMovementProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const SetIndexArray & indices = d_indices.getValue(); @@ -436,7 +436,7 @@ void PartialLinearMovementProjectiveConstraint::applyConstraint(const } template -void PartialLinearMovementProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PartialLinearMovementProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const int o = matrix->getGlobalOffset(this->mstate.get()); @@ -459,7 +459,7 @@ void PartialLinearMovementProjectiveConstraint::applyConstraint(const template -void PartialLinearMovementProjectiveConstraint::applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) +void PartialLinearMovementProjectiveConstraint::doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); const SetIndexArray& indices = d_indices.getValue(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.h index cb6bc086ec3..92342900e89 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.h @@ -107,6 +107,9 @@ public : virtual ~PatchTestMovementProjectiveConstraint(); + // Implement projectMatrix for assembled solver of compliant + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; + public: //Add or clear constraints void clearConstraints(); @@ -122,8 +125,6 @@ public : void projectVelocity(const core::MechanicalParams* mparams, DataVecDeriv& vData) override; /// Apply the computed movements to the border mesh points between beginConstraintTime and endConstraintTime void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; - // Implement projectMatrix for assembled solver of compliant - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; void projectJacobianMatrix(const core::MechanicalParams* /*mparams*/, DataMatrixDeriv& /* cData */) override { diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl index d3443c96a0b..dbecd87fb77 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PatchTestMovementProjectiveConstraint.inl @@ -291,7 +291,7 @@ void PatchTestMovementProjectiveConstraint::projectPosition(const cor } template -void PatchTestMovementProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void PatchTestMovementProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { // clears the rows and columns associated with constrained particles const unsigned blockSize = DataTypes::deriv_total_size; diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.h index e997808db20..fb868e9e684 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.h @@ -92,6 +92,13 @@ class PlaneProjectiveConstraint : public core::behavior::ProjectiveConstraintSet std::unique_ptr> data { nullptr }; friend class PlaneProjectiveConstraintInternalData; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + /** Project the given matrix (Experimental API). + Replace M with PMP, where P is the projection matrix corresponding to the projectResponse method, shifted by the given offset, i.e. P is the identity matrix with a block on the diagonal replaced by the projection matrix. + */ + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; public: void clearConstraints(); @@ -107,15 +114,6 @@ class PlaneProjectiveConstraint : public core::behavior::ProjectiveConstraintSet void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - /** Project the given matrix (Experimental API). - Replace M with PMP, where P is the projection matrix corresponding to the projectResponse method, shifted by the given offset, i.e. P is the identity matrix with a block on the diagonal replaced by the projection matrix. - */ - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void draw(const core::visual::VisualParams* vparams) override; protected : diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl index e5ae59a1f2e..c9f3c0d3e4c 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PlaneProjectiveConstraint.inl @@ -171,7 +171,7 @@ void PlaneProjectiveConstraint::reinit() } template -void PlaneProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void PlaneProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { J.copy(jacobian, M->colSize(), offset); // projection matrix for an assembled state BaseSparseMatrix* E = dynamic_cast(M); @@ -223,13 +223,13 @@ void PlaneProjectiveConstraint::projectPosition(const core::Mechanica } template -void PlaneProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void PlaneProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { msg_error() << "applyConstraint is not implemented "; } template -void PlaneProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void PlaneProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { msg_error() << "PlaneProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) is not implemented "; } diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.h index 458d0ac9391..a7d4a729a4b 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.h @@ -85,6 +85,14 @@ class PointProjectiveConstraint : public core::behavior::ProjectiveConstraintSet std::unique_ptr> data; friend class PointProjectiveConstraintInternalData; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; + + /** Project the given matrix (Experimental API). + Replace M with PMP, where P is the projection matrix corresponding to the projectResponse method, shifted by the given offset, i.e. P is the identity matrix with a block on the diagonal replaced by the projection matrix. + */ + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; public: void clearConstraints(); @@ -100,16 +108,6 @@ class PointProjectiveConstraint : public core::behavior::ProjectiveConstraintSet void projectPosition(const core::MechanicalParams* mparams, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) override; - - /** Project the given matrix (Experimental API). - Replace M with PMP, where P is the projection matrix corresponding to the projectResponse method, shifted by the given offset, i.e. P is the identity matrix with a block on the diagonal replaced by the projection matrix. - */ - void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) override; - - void draw(const core::visual::VisualParams* vparams) override; bool fixAllDOFs() const { return d_fixAll.getValue(); } diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl index 1dd7663405c..ab0759c994e 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/PointProjectiveConstraint.inl @@ -129,7 +129,7 @@ void PointProjectiveConstraint::reinit() } template -void PointProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void PointProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { const unsigned blockSize = DataTypes::deriv_total_size; @@ -225,7 +225,7 @@ void PointProjectiveConstraint::projectPosition(const core::Mechanica } template -void PointProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PointProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); if(const core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate.get())) @@ -246,7 +246,7 @@ void PointProjectiveConstraint::applyConstraint(const core::Mechanica } template -void PointProjectiveConstraint::applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void PointProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) { SOFA_UNUSED(mparams); const int o = matrix->getGlobalOffset(this->mstate.get()); @@ -265,7 +265,7 @@ void PointProjectiveConstraint::applyConstraint(const core::Mechanica } template -void PointProjectiveConstraint::applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) +void PointProjectiveConstraint::doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) { static constexpr unsigned int N = Deriv::size(); const SetIndexArray& indices = d_indices.getValue(); diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.h b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.h index 96785a2b76f..5604cf53dab 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.h +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.h @@ -63,6 +63,11 @@ class SkeletalMotionProjectiveConstraint : public core::behavior::ProjectiveCons virtual ~SkeletalMotionProjectiveConstraint(); + void doApplyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doApplyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + + void doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) override; + public: void init() override; @@ -78,12 +83,6 @@ class SkeletalMotionProjectiveConstraint : public core::behavior::ProjectiveCons void projectPosition(const core::MechanicalParams* /*mparams*/, DataVecCoord& xData) override; void projectJacobianMatrix(const core::MechanicalParams* mparams, DataMatrixDeriv& cData) override; - using core::behavior::ProjectiveConstraintSet::applyConstraint; - void applyConstraint(const core::MechanicalParams* mparams, linearalgebra::BaseVector* vector, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void applyConstraint(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - - void projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) override; - void draw(const core::visual::VisualParams* vparams) override; template diff --git a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.inl b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.inl index 038d56f3435..67a1f260c6d 100644 --- a/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.inl +++ b/Sofa/Component/Constraint/Projective/src/sofa/component/constraint/projective/SkeletalMotionProjectiveConstraint.inl @@ -289,7 +289,7 @@ void SkeletalMotionProjectiveConstraint::addChannel(unsigned int join // Matrix Integration interface template -void SkeletalMotionProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void SkeletalMotionProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { if( !d_active.getValue() ) return; @@ -308,7 +308,7 @@ void SkeletalMotionProjectiveConstraint::applyConstraint(const core:: } template -void SkeletalMotionProjectiveConstraint::applyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void SkeletalMotionProjectiveConstraint::doApplyConstraint(const core::MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) { if( !d_active.getValue() ) return; @@ -323,7 +323,7 @@ void SkeletalMotionProjectiveConstraint::applyConstraint(const core:: } template -void SkeletalMotionProjectiveConstraint::projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) +void SkeletalMotionProjectiveConstraint::doProjectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) { const unsigned blockSize = DataTypes::deriv_total_size; const unsigned size = this->mstate->getSize(); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h index b9ad9aff559..1d254fad272 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.h @@ -90,7 +90,7 @@ class SOFA_COMPONENT_IO_MESH_API BlenderExporter: public sofa::simulation::BaseS void doInit() override; void doReInit() override; - bool write() override; + bool doWrite() override; void reset() override; diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl index 2fbdecc6330..b52fd55078e 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/BlenderExporter.inl @@ -75,7 +75,7 @@ void BlenderExporter::doReInit() } template -bool BlenderExporter::write() +bool BlenderExporter::doWrite() { if(!this->isComponentStateValid()) return false; diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp index cba3451fc06..0be1298fca5 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.cpp @@ -84,7 +84,7 @@ void MeshExporter::doReInit() d_componentState.setValue(ComponentState::Valid) ; } -bool MeshExporter::write() +bool MeshExporter::doWrite() { if(d_componentState.getValue() != ComponentState::Valid) return false; diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.h index f7f3f280d73..c90a407c2be 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/MeshExporter.h @@ -79,7 +79,7 @@ class SOFA_COMPONENT_IO_MESH_API MeshExporter : public BaseSimulationExporter void doInit() override ; void doReInit() override ; - bool write() override ; + bool doWrite() override ; bool writeMesh(); bool writeMeshVTKXML(); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp index 0ebbf79bab1..4b944df69f2 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.cpp @@ -96,7 +96,7 @@ void STLExporter::doReInit() d_componentState.setValue(ComponentState::Valid) ; } -bool STLExporter::write() +bool STLExporter::doWrite() { if(d_componentState.getValue() != ComponentState::Valid) return false ; diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.h index dfc573a1535..2f190e3754d 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/STLExporter.h @@ -66,7 +66,7 @@ class SOFA_COMPONENT_IO_MESH_API STLExporter : public BaseSimulationExporter void doReInit() override ; void handleEvent(Event *) override ; - bool write() override ; + bool doWrite() override ; bool writeSTL(bool autonumbering=true); bool writeSTLBinary(bool autonumbering=true); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp index 1b3b92ca982..b2cbe368db9 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.cpp @@ -350,7 +350,7 @@ std::string VTKExporter::segmentString(std::string str, unsigned int n) } -bool VTKExporter::write() +bool VTKExporter::doWrite() { if (!this->isComponentStateValid()) return false; diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.h index 58425e30e6c..7339c4f1d81 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VTKExporter.h @@ -47,7 +47,7 @@ class SOFA_COMPONENT_IO_MESH_API VTKExporter : public sofa::simulation::BaseSimu std::unique_ptr m_outfile; void fetchDataFields(const type::vector& strData, type::vector& objects, type::vector& fields, type::vector& names); - bool write() override; + bool doWrite() override; bool writeVTKSimple(); bool writeVTKXML(); void writeParallelFile(); diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp index 7713ac40d6a..dcb04c0e21c 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.cpp @@ -37,7 +37,7 @@ VisualModelOBJExporter::~VisualModelOBJExporter() } -bool VisualModelOBJExporter::write() +bool VisualModelOBJExporter::doWrite() { return writeOBJ() ; } diff --git a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.h b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.h index 19b16d9890d..0b96b5cfedf 100644 --- a/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.h +++ b/Sofa/Component/IO/Mesh/src/sofa/component/io/mesh/VisualModelOBJExporter.h @@ -39,7 +39,7 @@ class SOFA_COMPONENT_IO_MESH_API VisualModelOBJExporter : public BaseSimulationE public: SOFA_CLASS(VisualModelOBJExporter, BaseSimulationExporter); - bool write() override; + bool doWrite() override; bool writeOBJ(); protected: diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h index bf5cd2251dc..70a6edefcdf 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h @@ -145,7 +145,7 @@ class HexahedronFEMForceField : const Transformation& getElementRotation(const sofa::Index elemidx); void getNodeRotation(Transformation& R, sofa::Index nodeIdx) ; - void getRotations(linearalgebra::BaseMatrix * rotations,int offset = 0) override ; + void doGetRotations(linearalgebra::BaseMatrix * rotations,int offset = 0) override ; using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl index e08b2675fd2..00dab030075 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl @@ -973,7 +973,7 @@ void HexahedronFEMForceField::getNodeRotation(Transformation& R, unsi } template -void HexahedronFEMForceField::getRotations(linearalgebra::BaseMatrix * rotations,int offset) +void HexahedronFEMForceField::doGetRotations(linearalgebra::BaseMatrix * rotations,int offset) { auto nbdof = this->mstate->getSize(); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h index 8f9b3992c4b..7726b16372f 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h @@ -182,7 +182,7 @@ class TetrahedronFEMForceField : public BaseLinearElasticityFEMForceField API type::vector< Mat33 > m_rotations; const type::vector& getRotations() override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl index 266ca6f8612..48b9c6b1e89 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.inl @@ -2042,7 +2042,7 @@ void TetrahedronFEMForceField::getRotations(VecReal& vecR) } template -void TetrahedronFEMForceField::getRotations(linearalgebra::BaseMatrix * rotations,int offset) +void TetrahedronFEMForceField::doGetRotations(linearalgebra::BaseMatrix * rotations,int offset) { const std::size_t nbdof = this->mstate->getSize(); diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h index 1bb71b35590..05bb4969585 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/BaseMaterial.h @@ -45,23 +45,58 @@ class SOFA_COMPONENT_SOLIDMECHANICS_FEM_HYPERELASTIC_API BaseMaterial : public v this->core::objectmodel::BaseComponent::init(); } - //virtual VecN computeStress (VecN & strain,int idElement,int id_QP){return stress in the i-th quadrature point} //So here needed the shapefunctionvalue * , quadratureformular* (verifie if shapfunctionvalue compute with the local method) // The same principe for computing the strain given the displacement + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeStress (type::Vec3 & stress, type::Vec3 & strain, unsigned int & elementIndex) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeStress(stress, strain, elementIndex); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeDStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeDStress (type::Vec3 & dstress, type::Vec3 & dstrain) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeDStress(dstress, dstrain); + } - virtual void computeStress (type::Vec3 & ,type::Vec3 &,unsigned int &) {} - virtual void computeDStress (type::Vec3 & ,type::Vec3 &) {} + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doComputeStress" internally, + * which is the method to override from now on. + * + **/ + virtual void computeStress (unsigned int elementIndex) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeStress(elementIndex); + }; - virtual void computeStress (unsigned int /*iElement*/)=0;//to be pure virtual - +protected: + virtual void doComputeStress(type::Vec3 & stress, type::Vec3 & strain, unsigned int & idElement) = 0; + virtual void doComputeDStress(type::Vec3 & dstress, type::Vec3 & dstrain) = 0; + virtual void doComputeStress(unsigned int elementIndex) = 0; private: BaseMaterial(const BaseMaterial& n) ; BaseMaterial& operator=(const BaseMaterial& n) ; - }; } // namespace sofa::component::solidmechanics::fem::hyperelastic::material diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp index e6c5abb96bb..234e3a3eeca 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.cpp @@ -49,7 +49,7 @@ PlasticMaterial::PlasticMaterial() _sigma.push_back(Stress); } -void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex) +void PlasticMaterial::doComputeStress(Vec3& Stress, Vec3& Strain, unsigned int& elementIndex) { // Computes the Von Mises strain const SReal vonMisesStrain = computeVonMisesStrain(Strain); @@ -78,7 +78,7 @@ void PlasticMaterial::computeStress(Vec3& Stress, Vec3& Strain, unsigned int& el _previousVonMisesStrain.push_back(vonMisesStrain); } -void PlasticMaterial::computeDStress(Vec3& dStress, Vec3& dStrain) +void PlasticMaterial::doComputeDStress(Vec3& dStress, Vec3& dStrain) { dStress[0] = dStrain[0] + _poissonRatio.getValue() * dStrain[1]; dStress[1] = _poissonRatio.getValue() * dStrain[0] + dStrain[1]; diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h index 6158095ea3d..04dc3886abb 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/material/PlasticMaterial.h @@ -59,13 +59,14 @@ class PlasticMaterial : public BaseMaterial VecDouble _previousVonMisesStrain; PlasticMaterial(); - void computeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override; - void computeDStress (Vec3& dstress, Vec3& dstrain) override; SReal computeVonMisesStrain(Vec3 &strain); void computeStressOnSection(Vec3& Stress, Vec3 Strain, int section); // computes the stress on a given section of the piecewise function - void computeStress (unsigned int /*iElement*/) override {} +protected: + void doComputeStress (Vec3& stress, Vec3& strain, unsigned int& elementIndex) override; + void doComputeDStress (Vec3& dstress, Vec3& dstrain) override; + void doComputeStress (unsigned int /*elementIndex*/) override {} }; diff --git a/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp b/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp index b142ca06cda..ea6554f9c11 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp @@ -366,7 +366,7 @@ type::Vec2 BaseCamera::worldToScreenCoordinates(const type::Vec3& pos) return screenCoord + type::Vec2(viewport[0], viewport[1]); } -void BaseCamera::getModelViewMatrix(double mat[16]) +void BaseCamera::doGetModelViewMatrix(double mat[16]) { const sofa::type::Transform world_H_cam(d_position.getValue(), this->getOrientation()); Mat3 rot = world_H_cam.inversed().getRotationMatrix(); @@ -395,7 +395,7 @@ void BaseCamera::getOpenGLModelViewMatrix(double mat[16]) world_H_cam.inversed().writeOpenGlMatrix(mat); } -void BaseCamera::getProjectionMatrix(double mat[16]) +void BaseCamera::doGetProjectionMatrix(double mat[16]) { const double width = double(d_widthViewport.getValue()); const double height = double(d_heightViewport.getValue()); @@ -537,7 +537,8 @@ void BaseCamera::rotateCameraAroundPoint(Quat& rotation, const type::Vec3& point updateOutputData(); } -void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, Quat orientationCam, type::Vec3 positionCam) + +void BaseCamera::doRotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, Quat orientationCam, type::Vec3 positionCam) { type::Vec3 tempAxis; SReal tempAngle; @@ -566,7 +567,7 @@ void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, } -void BaseCamera::rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam) +void BaseCamera::doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam) { auto positionCam = sofa::helper::getReadAccessor(d_position); rotateWorldAroundPoint(rotation, point, orientationCam, positionCam); @@ -941,7 +942,7 @@ void BaseCamera::draw(const sofa::core::visual::VisualParams* /*params*/) { } -void BaseCamera::drawCamera(const core::visual::VisualParams* vparams) +void BaseCamera::doDrawCamera(const core::visual::VisualParams* vparams) { const auto dt = (vparams->drawTool()); dt->setPolygonMode(0, true); diff --git a/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.h b/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.h index 0b56c9506d4..f85a36dfc74 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.h +++ b/Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.h @@ -102,8 +102,34 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo void moveCamera(const type::Vec3 &p, const Quat &q); void rotateCameraAroundPoint( Quat& rotation, const type::Vec3& point); - virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam); - virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam); + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doRotateWorldAroundPoint" internally, + * which is the method to override from now on. + * + **/ + virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doRotateWorldAroundPoint(rotation, point, orientationCam); + } + + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doRotateWorldAroundPoint" internally, + * which is the method to override from now on. + * + **/ + virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doRotateWorldAroundPoint(rotation, point, orientationCam, positionCam); + } + type::Vec3 screenToViewportPoint(const type::Vec3& p) const; type::Vec3 screenToWorldPoint(const type::Vec3& p); @@ -191,8 +217,32 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo //be according to the gravity. void setDefaultView(const type::Vec3& gravity = type::Vec3(0, -9.81, 0)); - virtual void getModelViewMatrix(double mat[16]); - virtual void getProjectionMatrix(double mat[16]); + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetModelViewMatrix" internally, + * which is the method to override from now on. + * + **/ + virtual void getModelViewMatrix(double mat[16]) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doGetModelViewMatrix(mat); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetProjectionMatrix" internally, + * which is the method to override from now on. + * + **/ + virtual void getProjectionMatrix(double mat[16]) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doGetProjectionMatrix(mat); + } + void getOpenGLModelViewMatrix(double mat[16]); void getOpenGLProjectionMatrix(double mat[16]); @@ -200,8 +250,31 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo type::Vec3 getLookAtFromOrientation(const type::Vec3 &pos, const double &distance,const Quat & orientation); type::Vec3 getPositionFromOrientation(const type::Vec3 &lookAt, const double &distance, const Quat& orientation); - virtual void manageEvent(core::objectmodel::Event* event) = 0 ; - virtual void internalUpdate() {} + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doManageEvent" internally, + * which is the method to override from now on. + * + **/ + virtual void manageEvent(core::objectmodel::Event* event) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doManageEvent(event); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doInternalUpdate" internally, + * which is the method to override from now on. + * + **/ + virtual void internalUpdate() final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doInternalUpdate(); + } void handleEvent(sofa::core::objectmodel::Event* event) override; void computeZ(); @@ -254,13 +327,38 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo void draw(const core::visual::VisualParams*) override ; void computeClippingPlane(const core::visual::VisualParams* vp, double& zNear, double& zFar); - virtual void drawCamera(const core::visual::VisualParams*); + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doDrawCamera" internally, + * which is the method to override from now on. + * + **/ + virtual void drawCamera(const core::visual::VisualParams* vparams) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doDrawCamera(vparams); + } + protected: void updateOutputData(); + virtual void doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam); + virtual void doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam); + + virtual void doManageEvent(core::objectmodel::Event* event) = 0; + + virtual void doGetModelViewMatrix(double mat[16]); + virtual void doGetProjectionMatrix(double mat[16]); + + virtual void doInternalUpdate() {} + + virtual void doDrawCamera(const core::visual::VisualParams*); + type::Vec3 getSceneCenter() const; SReal getSceneRadius() const; - + bool b_setDefaultParameters; //need to keep "internal" lookAt and distance for updating Data diff --git a/Sofa/Component/Visual/src/sofa/component/visual/Camera.h b/Sofa/Component/Visual/src/sofa/component/visual/Camera.h index 0a0607903c7..58269e0baa2 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/Camera.h +++ b/Sofa/Component/Visual/src/sofa/component/visual/Camera.h @@ -37,7 +37,7 @@ class SOFA_COMPONENT_VISUAL_API Camera : public BaseCamera ~Camera() override; public: - void manageEvent(core::objectmodel::Event* e) override { SOFA_UNUSED(e); } + void doManageEvent(core::objectmodel::Event* e) override { SOFA_UNUSED(e); } private: diff --git a/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.cpp b/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.cpp index 9579ea80b7a..faea3e32416 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.cpp @@ -48,10 +48,6 @@ InteractiveCamera::~InteractiveCamera() { } -void InteractiveCamera::internalUpdate() -{ -} - void InteractiveCamera::moveCamera(int x, int y) { Quat newQuat; @@ -147,7 +143,7 @@ void InteractiveCamera::moveCamera(int x, int y) } -void InteractiveCamera::manageEvent(core::objectmodel::Event* e) +void InteractiveCamera::doManageEvent(core::objectmodel::Event* e) { diff --git a/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.h b/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.h index c4f9cca685f..dd82b554e74 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.h +++ b/Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.h @@ -59,10 +59,9 @@ class SOFA_COMPONENT_VISUAL_API InteractiveCamera : public BaseCamera sofa::type::Quatd m_startingCameraOrientation; sofa::type::Vec3 m_startingCameraPosition; - void internalUpdate() override; protected: void moveCamera(int x, int y); - void manageEvent(core::objectmodel::Event* e) override; + void doManageEvent(core::objectmodel::Event* e) override; void processMouseEvent(core::objectmodel::MouseEvent* me); void processKeyPressedEvent(core::objectmodel::KeypressedEvent* kpe); void processKeyReleasedEvent(core::objectmodel::KeyreleasedEvent* kre); diff --git a/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.cpp b/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.cpp index 6089325d4f0..cd6fc039edc 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.cpp @@ -391,7 +391,7 @@ void RecordedCamera::initializeViewUp() } } -void RecordedCamera::manageEvent(core::objectmodel::Event* e) +void RecordedCamera::doManageEvent(core::objectmodel::Event* e) { if(d_activated.getValue()) { diff --git a/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.h b/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.h index e69b028c133..823d66ba4ad 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.h +++ b/Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.h @@ -65,7 +65,7 @@ class SOFA_COMPONENT_VISUAL_API RecordedCamera : public BaseCamera // Kepp functions for mouse interaction (TODO: removed them and allow interactive and recorded camera in same scene) void moveCamera_mouse(int x, int y); - void manageEvent(core::objectmodel::Event* e) override; + void doManageEvent(core::objectmodel::Event* e) override; void processMouseEvent(core::objectmodel::MouseEvent* me); void configureRotation(); diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp index f8348acb19d..ab223fc899f 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.cpp @@ -70,13 +70,14 @@ void VisualStyle::bwdInit() applyBackupFlags(sofa::core::visual::VisualParams::defaultInstance()); } -void VisualStyle::updateVisualFlags(VisualParams* vparams) + +void VisualStyle::doUpdateVisualFlags(VisualParams* vparams) { backupFlags = vparams->displayFlags(); vparams->displayFlags() = sofa::core::visual::merge_displayFlags(backupFlags, d_displayFlags.getValue()); } -void VisualStyle::applyBackupFlags(VisualParams* vparams) +void VisualStyle::doApplyBackupFlags(VisualParams* vparams) { vparams->displayFlags() = backupFlags; } diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.h b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.h index fa16fd4bbdc..4aa9c54152f 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.h +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualStyle.h @@ -66,10 +66,10 @@ class SOFA_COMPONENT_VISUAL_API VisualStyle : public sofa::core::visual::BaseVis protected: VisualStyle(); public: + void doUpdateVisualFlags(VisualParams* ) override; + void doApplyBackupFlags(VisualParams* ) override; void init() override; void bwdInit() override; - void updateVisualFlags(VisualParams* ) override; - void applyBackupFlags(VisualParams* ) override; bool insertInNode(sofa::core::objectmodel::BaseNode* node) override; bool removeInNode(sofa::core::objectmodel::BaseNode* node) override; diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.cpp index 02c9c71c3b5..f668e98d891 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.cpp @@ -80,7 +80,7 @@ bool BaseMouseInteractor::removeInteractionPerformer( InteractionPerformer *i) } } -void BaseMouseInteractor::updatePosition(SReal ) +void BaseMouseInteractor::doUpdatePosition(SReal ) { for (const auto perf : performers) { diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.h index 0e389f9f050..0396e977f93 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/MouseInteractor.h @@ -66,7 +66,7 @@ class SOFA_GUI_COMPONENT_API BaseMouseInteractor : public core::BehaviorModel void addInteractionPerformer(InteractionPerformer *i); bool removeInteractionPerformer( InteractionPerformer *i); //Called at each time step: launch all the performers - void updatePosition( SReal dt) override; + void doUpdatePosition( SReal dt) override; //Propagate an event in case to all the performers void handleEvent(core::objectmodel::Event *e) override; diff --git a/Sofa/framework/Core/src/sofa/core/BehaviorModel.h b/Sofa/framework/Core/src/sofa/core/BehaviorModel.h index 5586394d854..042d3e725ff 100644 --- a/Sofa/framework/Core/src/sofa/core/BehaviorModel.h +++ b/Sofa/framework/Core/src/sofa/core/BehaviorModel.h @@ -48,17 +48,46 @@ class SOFA_CORE_API BehaviorModel : public virtual sofa::core::objectmodel::Base /// Destructor ~BehaviorModel() override {} + /// Computation of a new simulation step. + virtual void doUpdatePosition(SReal /*dt*/) = 0; + + virtual bool doAddBBox(SReal* /*minBBox*/, SReal* /*maxBBox*/) + { + return false; + } + private: BehaviorModel(const BehaviorModel& n) = delete; BehaviorModel& operator=(const BehaviorModel& n) = delete; public: - /// Computation of a new simulation step. - virtual void updatePosition(SReal dt) = 0; - virtual bool addBBox(SReal* /*minBBox*/, SReal* /*maxBBox*/) + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doUpdatePosition" internally, + * which is the method to override from now on. + * + **/ + virtual void updatePosition(SReal dt) final { - return false; + //TODO (SPRINT SED 2025): Component state mechamism + this->doUpdatePosition(dt); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddBBox" internally, + * which is the method to override from now on. + * + **/ + virtual bool addBBox(SReal* minBBox, SReal* maxBBox) final + { + //TODO (SPRINT SED 2025): Component state mechamism + return this->doAddBBox(minBBox, maxBBox); } bool insertInNode( objectmodel::BaseNode* node ) override; diff --git a/Sofa/framework/Core/src/sofa/core/CollisionModel.cpp b/Sofa/framework/Core/src/sofa/core/CollisionModel.cpp index 0bf883450e9..da281b5217f 100644 --- a/Sofa/framework/Core/src/sofa/core/CollisionModel.cpp +++ b/Sofa/framework/Core/src/sofa/core/CollisionModel.cpp @@ -145,7 +145,7 @@ void CollisionModel::setPrevious(CollisionModel::SPtr val) val->next.set(this); } -void CollisionModel::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) +void CollisionModel::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth) { SOFA_UNUSED(dt); SOFA_UNUSED(continuousIntersectionFlag); diff --git a/Sofa/framework/Core/src/sofa/core/CollisionModel.h b/Sofa/framework/Core/src/sofa/core/CollisionModel.h index 1fcce798dc4..f2d1aac0aba 100644 --- a/Sofa/framework/Core/src/sofa/core/CollisionModel.h +++ b/Sofa/framework/Core/src/sofa/core/CollisionModel.h @@ -113,6 +113,33 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent /// Destructor ~CollisionModel() override {} + /// Set the number of elements. + virtual void doResize(Size s) + { + size = s; + } + + /// Create or update the bounding volume hierarchy. + virtual void doComputeBoundingTree(int maxDepth=0) = 0; + + /// \brief Create or update the bounding volume hierarchy, accounting for motions + /// within the given timestep. + /// + /// Default to computeBoundingTree(). + virtual void doComputeContinuousBoundingTree(SReal /*dt*/, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0); + + /// \brief Test if two elements can collide with each other. + /// + /// This method should be implemented by models supporting + /// self-collisions to prune tests between adjacent elements. + /// + /// Default to true. Note that this method assumes that canCollideWith(model2) + /// was already used to test if the collision models can collide. + virtual bool doCanCollideWithElement(Index /*index*/, CollisionModel* /*model2*/, Index /*index2*/) { return true; } + + /// BaseMeshTopology associated to the collision model. TODO: epernod remove virtual pure method by l_topology.get as soons as new link will be available + virtual sofa::core::topology::BaseMeshTopology* doGetCollisionTopology() { return nullptr; } + public: void bwdInit() override; @@ -152,10 +179,19 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent d_numberOfContacts.setValue(i); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doResize" internally, + * which is the method to override from now on. + * + **/ /// Set the number of elements. - virtual void resize(Size s) + virtual void resize(Size s) final { - size = s; + //TODO (SPRINT SED 2025): Component state mechamism + this->doResize(s); } /// Return an iterator to the first element. @@ -213,14 +249,38 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent /// \brief Set true if this CollisionModel is attached to a simulation. virtual void setSimulated(bool val=true) { bSimulated.setValue(val); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// Create or update the bounding volume hierarchy. - virtual void computeBoundingTree(int maxDepth=0) = 0; + virtual void computeBoundingTree(int maxDepth=0) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeBoundingTree(maxDepth); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// \brief Create or update the bounding volume hierarchy, accounting for motions /// within the given timestep. /// /// Default to computeBoundingTree(). - virtual void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0); + + + virtual void computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag = ContinuousIntersectionTypeFlag::Inertia, int maxDepth=0) final { + //TODO (SPRINT SED 2025): Component state mechamism + this->doComputeContinuousBoundingTree(dt, continuousIntersectionFlag, maxDepth); + } /// \brief Return the list (as a pair of iterators) of internal children of /// an element. @@ -271,6 +331,14 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent /// If both models are included in a common "group", they won't collide virtual bool canCollideWith(CollisionModel* model) ; + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// \brief Test if two elements can collide with each other. /// /// This method should be implemented by models supporting @@ -278,7 +346,10 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent /// /// Default to true. Note that this method assumes that canCollideWith(model2) /// was already used to test if the collision models can collide. - virtual bool canCollideWithElement(Index /*index*/, CollisionModel* /*model2*/, Index /*index2*/) { return true; } + virtual bool canCollideWithElement(Index index, CollisionModel* model2, Index index2) final { + //TODO (SPRINT SED 2025): Component state mechamism + return this->doCanCollideWithElement(index, model2, index2); + } /// Render an collision element. virtual void draw(const core::visual::VisualParams* /*vparams*/, Index /*index*/) {} @@ -365,8 +436,19 @@ class SOFA_CORE_API CollisionModel : public virtual objectmodel::BaseComponent void setGroups(const std::set& ids) { group.setValue(ids); } /// @} + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetCollisionTopology" internally, + * which is the method to override from now on. + * + **/ /// BaseMeshTopology associated to the collision model. TODO: epernod remove virtual pure method by l_topology.get as soons as new link will be available - virtual sofa::core::topology::BaseMeshTopology* getCollisionTopology() { return nullptr; } + virtual sofa::core::topology::BaseMeshTopology* getCollisionTopology() final { + // TODO (SPRINT SED 2025): Component state mechamism + return this->doGetCollisionTopology(); + } /// Get a color that can be used to display this CollisionModel const float* getColor4f(); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseAnimationLoop.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseAnimationLoop.h index a10e4d51525..cca805a8753 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseAnimationLoop.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseAnimationLoop.h @@ -59,6 +59,8 @@ class SOFA_CORE_API BaseAnimationLoop : public virtual objectmodel::BaseComponen /// Save the initial state for later uses in reset() void storeResetState() override; + virtual void doStep(const core::ExecParams* params, SReal dt) = 0 ; + private: BaseAnimationLoop(const BaseAnimationLoop& n) = delete ; @@ -67,11 +69,22 @@ class SOFA_CORE_API BaseAnimationLoop : public virtual objectmodel::BaseComponen public: void init() override; - /// Main computation method. - /// - /// Specify and execute all computations for computing a timestep, such - /// as one or more collisions and integrations stages. - virtual void step(const core::ExecParams* params, SReal dt) = 0; + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doStep" internally, + * which is the method to override from now on. + * + * Main computation method. + * + * Specify and execute all computations for computing a timestep, such + * as one or more collisions and integrations stages. + **/ + virtual void step(const core::ExecParams* params, SReal dt) final { + //TODO (SPRINT SED 2025): Component state mechamism + doStep(params, dt); + }; /// Returns starting time of the simulation SReal getResetTime() const; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraintSet.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraintSet.h index fc1d62235e9..3114fe3e384 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraintSet.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraintSet.h @@ -45,7 +45,19 @@ class SOFA_CORE_API BaseConstraintSet : public virtual objectmodel::BaseComponen BaseConstraintSet& operator=(const BaseConstraintSet& n) = delete; public: - virtual void resetConstraint() {} + /** + * !!! WARNING since v26.06 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ + virtual void resetConstraint() final + { + //TODO (SPRINT SED 2025): Component state mechanism + doResetConstraint(); + } /// Set the id of the constraint (this id is build in the getConstraintViolation function) /// @@ -55,39 +67,93 @@ class SOFA_CORE_API BaseConstraintSet : public virtual objectmodel::BaseComponen d_constraintIndex.setValue(cId); } + /** + * !!! WARNING since v26.06 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// Process geometrical data. /// /// This function is called by the CollisionVisitor, it can be used to process a collision detection specific for the constraint - virtual void processGeometricalData() {} + virtual void processGeometricalData() final + { + //TODO (SPRINT SED 2025): Component state mechanism + doProcessGeometricalData(); + } + /** + * !!! WARNING since v26.06 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// Construct the Jacobian Matrix /// /// \param cId is the result constraint sparse matrix Id /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - virtual void buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) = 0; + virtual void buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) final + { + //TODO (SPRINT SED 2025): Component state mechanism + doBuildConstraintMatrix(cParams, cId, cIndex); + } + /** + * !!! WARNING since v26.06 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// Construct the Constraint violations vector /// /// \param v is the result vector that contains the whole constraints violations /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - virtual void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) + virtual void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) final { - getConstraintViolation(cParams, v, d_constraintIndex.getValue()); + //TODO (SPRINT SED 2025): Component state mechanism + doGetConstraintViolation(cParams, v); } + + /** + * !!! WARNING since v26.06 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doFunctionName" internally, + * which is the method to override from now on. + * + **/ /// Construct the Constraint violations vector /// /// \param v is the result vector that contains the whole constraints violations /// \param cIndex is the index of the next constraint equation /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - virtual void getConstraintViolation(const ConstraintParams* /*cParams*/, linearalgebra::BaseVector * /*v*/, unsigned int /*cIndex*/) { - dmsg_error() << "getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v, const unsigned int cIndex) is not implemented while it should"; + virtual void getConstraintViolation(const ConstraintParams* /*cParams*/, linearalgebra::BaseVector * /*v*/, unsigned int /*cIndex*/) final + { + } protected: - + virtual void doResetConstraint() {} + virtual void doProcessGeometricalData() {} + virtual void doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) = 0; + virtual void doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) + { + getConstraintViolation(cParams, v, d_constraintIndex.getValue()); + } + virtual void doGetConstraintViolation(const ConstraintParams* /*cParams*/, linearalgebra::BaseVector * /*v*/, unsigned int /*cIndex*/) + { + dmsg_error() << "getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v, const unsigned int cIndex) is not implemented while it should"; + } Data< int > group; ///< ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. + public: Data< sofa::Index > d_constraintIndex; ///< Constraint index (first index in the right hand term resolution vector) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionProjectiveConstraintSet.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionProjectiveConstraintSet.h index a0a3b9c3552..ddd1e7b3907 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionProjectiveConstraintSet.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionProjectiveConstraintSet.h @@ -50,7 +50,8 @@ class SOFA_CORE_API BaseInteractionProjectiveConstraintSet : public BaseProjecti virtual BaseMechanicalState* getMechModel2() { return l_mechanicalStates[1]; } - virtual type::vector< core::BaseState* > getModels() override +protected: + virtual type::vector< core::BaseState* > doGetModels() override { return {getMechModel1(), getMechModel2() }; } diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.cpp index 8ae2d4f9f37..a623638d438 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.cpp @@ -27,7 +27,7 @@ namespace sofa::core::behavior { -void BaseProjectiveConstraintSet::applyConstraint(sofa::core::behavior::ZeroDirichletCondition* zeroDirichletCondition) +void BaseProjectiveConstraintSet::doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* zeroDirichletCondition) { static std::set hasEmittedWarning; if (hasEmittedWarning.insert(this).second) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.h index 3303bee4f0f..1312b9e9fb2 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseProjectiveConstraintSet.h @@ -75,6 +75,20 @@ class SOFA_CORE_API BaseProjectiveConstraintSet : public virtual StateAccessor ~BaseProjectiveConstraintSet() override {} + virtual type::vector< core::BaseState* > doGetModels() = 0; + virtual void doProjectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) = 0; + virtual void doProjectResponse(const MechanicalParams* /*mparams*/, double **) { }; + virtual void doProjectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) = 0; + virtual void doProjectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) = 0; + virtual void doProjectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) = 0; + + virtual void doApplyConstraint(const MechanicalParams* /*mparams*/, const behavior::MultiMatrixAccessor* /*matrix*/) {} + virtual void doApplyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const behavior::MultiMatrixAccessor* /*matrix*/) {} + virtual void doProjectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) + { + msg_error() << "projectMatrix not implemented, projection will not be handled appropriately"; + } + virtual void doApplyConstraint(sofa::core::behavior::ZeroDirichletCondition* /*matrix*/); public: /// Get the ID of the group containing this constraint. /// This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. @@ -85,27 +99,82 @@ class SOFA_CORE_API BaseProjectiveConstraintSet : public virtual StateAccessor void setGroup(int g) { group.setValue(g); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetModels" internally, + * which is the method to override from now on. + * + **/ /// Return the lists of models this constraint applies to. - virtual type::vector< core::BaseState* > getModels() = 0; + virtual type::vector< core::BaseState* > getModels() final { + //TODO (SPRINT SED 2025): Component state mechanism + return this->doGetModels(); + } /// @name Vector operations /// @{ + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doProjectResponse" + * internally, which is the method to override from now on. + * + **/ /// Project dx to constrained space (dx models an acceleration). /// \param dxId output vector - virtual void projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) = 0; + virtual void projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectResponse(mparams, dxId); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doProjectJacobianMatrix" + * internally, which is the method to override from now on. + * + **/ /// Project the L matrix of the Lagrange Multiplier equation system. /// \param cId output vector - virtual void projectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) = 0; + virtual void projectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectJacobianMatrix(mparams, cId); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doProjectVelocity" + * internally, which is the method to override from now on. + * + **/ /// Project v to constrained space (v models a velocity). /// \param vId output vector - virtual void projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) = 0; + virtual void projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectVelocity(mparams, vId); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doProjectPosition" + * internally, which is the method to override from now on. + * + **/ /// Project x to constrained space (x models a position). /// \param xId output vector - virtual void projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) = 0; + virtual void projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectPosition(mparams, xId); + } /// @} @@ -113,28 +182,86 @@ class SOFA_CORE_API BaseProjectiveConstraintSet : public virtual StateAccessor /// @name Matrix operations /// @{ + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doProjectResponse" + * internally, which is the method to override from now on. + * + **/ /// Project the compliance Matrix to constrained space. - virtual void projectResponse(const MechanicalParams* /*mparams*/, double **) {} + virtual void projectResponse(const MechanicalParams* mparams, double ** W) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectResponse(mparams, W); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyConstraint" + * internally, which is the method to override from now on. + * + **/ /// Project the global Mechanical Matrix to constrained space using offset parameter - virtual void applyConstraint(const MechanicalParams* /*mparams*/, const behavior::MultiMatrixAccessor* /*matrix*/) {} + virtual void applyConstraint(const MechanicalParams* mparams, const behavior::MultiMatrixAccessor* matrix) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doApplyConstraint(mparams, matrix); + } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyConstraint" + * internally, which is the method to override from now on. + * + **/ /// Project the global Mechanical Vector to constrained space using offset parameter - virtual void applyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const behavior::MultiMatrixAccessor* /*matrix*/) {} - - /** Project the given matrix (Experimental API). - Replace M with PMP, where P is the projection matrix corresponding to the projectResponse method. Contrary to applyConstraint(), the diagonal blocks of the result are not reset to the identity. - Typically, M is the (generalized) mass matrix of the whole system, offset is the starting index of the local state in this global matrix, and P is the identity matrix with a block on the diagonal replaced by the projection matrix. - If M is the matrix of the local state, then offset should be 0. - */ - virtual void projectMatrix( sofa::linearalgebra::BaseMatrix* /*M*/, unsigned /*offset*/ ) + virtual void applyConstraint(const MechanicalParams* mparams, linearalgebra::BaseVector* vector, const behavior::MultiMatrixAccessor* matrix) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doApplyConstraint(mparams, vector, matrix); + } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyConstraint" + * internally, which is the method to override from now on. + * + **/ + /** + * Project the given matrix (Experimental API). Replace M with PMP, where P + * is the projection matrix corresponding to the projectResponse method. + * Contrary to applyConstraint(), the diagonal blocks of the result are not + * reset to the identity. Typically, M is the (generalized) mass matrix of + * the whole system, offset is the starting index of the local state in this + * global matrix, and P is the identity matrix with a block on the diagonal + * replaced by the projection matrix. If M is the matrix of the local state, + * then offset should be 0. + */ + virtual void projectMatrix( sofa::linearalgebra::BaseMatrix* M, unsigned offset ) final { - msg_error() << "projectMatrix not implemented, projection will not be handled appropriately"; + //TODO (SPRINT SED 2025): Component state mechanism + this->doProjectMatrix(M, offset); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyConstraint" + * internally, which is the method to override from now on. + * + **/ /// Project the global matrix to constrained space by using the ZeroDirichletCondition interface /// It allows to define what rows and columns to discard for the projection. - virtual void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* /*matrix*/); + virtual void applyConstraint(sofa::core::behavior::ZeroDirichletCondition* matrix) final { + //TODO (SPRINT SED 2025): Component state mechanism + this->doApplyConstraint(matrix); + } /// @} diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseRotationFinder.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseRotationFinder.h index ecdc5f89372..3b5757cdd1f 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseRotationFinder.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseRotationFinder.h @@ -32,7 +32,22 @@ class BaseRotationFinder : public virtual sofa::core::objectmodel::BaseComponent public: SOFA_ABSTRACT_CLASS(BaseRotationFinder, sofa::core::objectmodel::BaseComponent); - virtual void getRotations(linearalgebra::BaseMatrix * m, int offset = 0) = 0; + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetRotations" internally, + * which is the method to override from now on. + * + **/ + virtual void getRotations(linearalgebra::BaseMatrix * m, int offset = 0) final + { + //TODO (SPRINT SED 2025): Component state mechamism + doGetRotations(m,offset); + } + +protected: + virtual void doGetRotations(linearalgebra::BaseMatrix * m, int offset = 0) = 0; }; } // namespace sofa::core::behavior diff --git a/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.h index 8baf7bcba8b..9409b54d82c 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.h @@ -62,17 +62,27 @@ class LagrangianConstraint : public BaseLagrangianConstraint, public virtual Sin ~LagrangianConstraint() override; virtual void init() override; + + /// Construct the Constraint violations vector of each constraint + /// + /// \param v is the result vector that contains the whole constraints violations + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; + + /// Construct the Jacobian Matrix + /// + /// \param cId is the result constraint sparse matrix Id + /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; + + public: Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints virtual bool isActive() const; ///< if false, the constraint does nothing using BaseConstraintSet::getConstraintViolation; - /// Construct the Constraint violations vector of each constraint - /// - /// \param v is the result vector that contains the whole constraints violations - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; /// Construct the Constraint violations vector of each constraint /// @@ -85,13 +95,6 @@ class LagrangianConstraint : public BaseLagrangianConstraint, public virtual Sin virtual void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *resV, const DataVecCoord &x, const DataVecDeriv &v) = 0; - /// Construct the Jacobian Matrix - /// - /// \param cId is the result constraint sparse matrix Id - /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; - /// Construct the Jacobian Matrix /// /// \param c is the result constraint sparse matrix diff --git a/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.inl b/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.inl index 1a2f56a814b..08ba93ba588 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/LagrangianConstraint.inl @@ -55,7 +55,7 @@ void LagrangianConstraint::init() } template -void LagrangianConstraint::getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) +void LagrangianConstraint::doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) { if (cParams) { @@ -65,7 +65,7 @@ void LagrangianConstraint::getConstraintViolation(const ConstraintPar template -void LagrangianConstraint::buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) +void LagrangianConstraint::doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) { if (cParams) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h index 51b2322c62e..8c9589e52dc 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.h @@ -73,17 +73,24 @@ class MixedInteractionConstraint : public BaseInteractionConstraint, public Pair virtual type::vector getMixedInteractionIdentifiers(){ return {}; } + /// Construct the Constraint violations vector of each constraint + /// + /// \param v is the result vector that contains the whole constraints violations + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; + + /// Construct the Jacobian Matrix + /// + /// \param cId is the result constraint sparse matrix Id + /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; public: Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints virtual bool isActive() const; ///< if false, the constraint does nothing using BaseConstraintSet::getConstraintViolation; - /// Construct the Constraint violations vector of each constraint - /// - /// \param v is the result vector that contains the whole constraints violations - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; /// Construct the Constraint violations vector of each constraint /// @@ -96,13 +103,6 @@ class MixedInteractionConstraint : public BaseInteractionConstraint, public Pair virtual void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v, const DataVecCoord1 &x1, const DataVecCoord2 &x2 , const DataVecDeriv1 &v1, const DataVecDeriv2 &v2) = 0; - /// Construct the Jacobian Matrix - /// - /// \param cId is the result constraint sparse matrix Id - /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; - /// Construct the Jacobian Matrix /// /// \param c1 and c2 are the results constraint sparse matrix diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.inl b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.inl index a881ef7031a..9544b8aec59 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionConstraint.inl @@ -47,7 +47,7 @@ bool MixedInteractionConstraint::isActive() const } template -void MixedInteractionConstraint::getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) +void MixedInteractionConstraint::doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) { if (cParams) { @@ -57,7 +57,7 @@ void MixedInteractionConstraint::getConstraintViolation( } template -void MixedInteractionConstraint::buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) +void MixedInteractionConstraint::doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) { if (cParams) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.h index 1f494cb85aa..184748c4885 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.h @@ -62,11 +62,6 @@ class PairInteractionConstraint : public BaseInteractionConstraint, public PairS virtual bool isActive() const; ///< if false, the constraint does nothing using BaseConstraintSet::getConstraintViolation; - /// Construct the Constraint violations vector of each constraint - /// - /// \param v is the result vector that contains the whole constraints violations - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; /// Construct the Constraint violations vector of each constraint /// @@ -79,13 +74,6 @@ class PairInteractionConstraint : public BaseInteractionConstraint, public PairS virtual void getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v, const DataVecCoord &x1, const DataVecCoord &x2 , const DataVecDeriv &v1, const DataVecDeriv &v2) = 0; - /// Construct the Jacobian Matrix - /// - /// \param cId is the result constraint sparse matrix Id - /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) - void buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; - /// Construct the Jacobian Matrix /// /// \param c1 and c2 are the results constraint sparse matrix @@ -157,14 +145,28 @@ class PairInteractionConstraint : public BaseInteractionConstraint, public PairS protected: - virtual type::vector getInteractionIdentifiers() override final - { - type::vector ids = getPairInteractionIdentifiers(); - ids.push_back("Pair"); - return ids; - } + /// Construct the Constraint violations vector of each constraint + /// + /// \param v is the result vector that contains the whole constraints violations + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) override; + + /// Construct the Jacobian Matrix + /// + /// \param cId is the result constraint sparse matrix Id + /// \param cIndex is the index of the next constraint equation: when building the constraint matrix, you have to use this index, and then update it + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) + void doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) override; + + + virtual type::vector getInteractionIdentifiers() override final + { + type::vector ids = getPairInteractionIdentifiers(); + ids.push_back("Pair"); + return ids; + } - virtual type::vector getPairInteractionIdentifiers(){ return {}; } + virtual type::vector getPairInteractionIdentifiers(){ return {}; } void storeLambda(const ConstraintParams* cParams, Data& res1, Data& res2, const Data& j1, const Data& j2, const sofa::linearalgebra::BaseVector* lambda); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.inl index 7023b553922..f5e4bae8f4b 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionConstraint.inl @@ -50,7 +50,7 @@ bool PairInteractionConstraint::isActive() const template -void PairInteractionConstraint::getConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) +void PairInteractionConstraint::doGetConstraintViolation(const ConstraintParams* cParams, linearalgebra::BaseVector *v) { if (cParams) { @@ -60,7 +60,7 @@ void PairInteractionConstraint::getConstraintViolation(const Constrai template -void PairInteractionConstraint::buildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) +void PairInteractionConstraint::doBuildConstraintMatrix(const ConstraintParams* cParams, MultiMatrixDerivId cId, unsigned int &cIndex) { if (cParams) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.h index 3547b05f9da..db64fba2c9d 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.h @@ -55,13 +55,6 @@ class PairInteractionProjectiveConstraintSet : public BaseInteractionProjectiveC explicit PairInteractionProjectiveConstraintSet(MechanicalState *mm1 = nullptr, MechanicalState *mm2 = nullptr); ~PairInteractionProjectiveConstraintSet() override; -public: - Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints - virtual bool isActive() const; ///< if false, the constraint does nothing - - // to get rid of warnings - using BaseInteractionProjectiveConstraintSet::projectPosition; - using BaseInteractionProjectiveConstraintSet::projectResponse; /// @name Vector operations /// @{ @@ -71,28 +64,52 @@ class PairInteractionProjectiveConstraintSet : public BaseInteractionProjectiveC /// This method retrieves the dx vector from the MechanicalState and call /// the internal projectResponse(VecDeriv&,VecDeriv&) method implemented by /// the component. - void projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) override; + void doProjectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) override; /// Project the L matrix of the Lagrange Multiplier equation system. /// /// This method retrieves the lines of the Jacobian Matrix from the MechanicalState and call /// the internal projectResponse(MatrixDeriv&) method implemented by /// the component. - void projectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) override; + void doProjectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) override; /// Project v to constrained space (v models a velocity). /// /// This method retrieves the v vector from the MechanicalState and call /// the internal projectVelocity(VecDeriv&,VecDeriv&) method implemented by /// the component. - void projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) override; + void doProjectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) override; /// Project x to constrained space (x models a position). /// /// This method retrieves the x vector from the MechanicalState and call /// the internal projectPosition(VecCoord&,VecCoord&) method implemented by /// the component. - void projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) override; + void doProjectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) override; + + /// @} + + /// Project the global Mechanical Matrix to constrained space using offset parameter + void doApplyConstraint(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override + { + } + + /// Project the global Mechanical Vector to constrained space using offset parameter + void doApplyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override + { + } + +public: + Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints + virtual bool isActive() const; ///< if false, the constraint does nothing + + // to get rid of warnings + using BaseInteractionProjectiveConstraintSet::projectPosition; + using BaseInteractionProjectiveConstraintSet::projectResponse; + using BaseInteractionProjectiveConstraintSet::projectVelocity; + + /// @name Vector operations + /// @{ /// Project dx to constrained space (dx models an acceleration). virtual void projectResponse(const MechanicalParams* /*mparams*/, DataVecDeriv& dx1, DataVecDeriv& dx2) = 0; @@ -105,18 +122,6 @@ class PairInteractionProjectiveConstraintSet : public BaseInteractionProjectiveC /// @} - /// Project the global Mechanical Matrix to constrained space using offset parameter - void applyConstraint(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override - { - - } - - /// Project the global Mechanical Vector to constrained space using offset parameter - void applyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override - { - - } - /// Pre-construction check method called by ObjectFactory. /// Check that DataTypes matches the MechanicalState. template diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.inl index 6ff41998817..ca457be8ae7 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionProjectiveConstraintSet.inl @@ -51,7 +51,7 @@ bool PairInteractionProjectiveConstraintSet::isActive() const } template -void PairInteractionProjectiveConstraintSet::projectJacobianMatrix(const MechanicalParams* /*mparams*/, MultiMatrixDerivId /*cId*/) +void PairInteractionProjectiveConstraintSet::doProjectJacobianMatrix(const MechanicalParams* /*mparams*/, MultiMatrixDerivId /*cId*/) { msg_error()<< "NOT IMPLEMENTED YET"; } @@ -59,7 +59,7 @@ void PairInteractionProjectiveConstraintSet::projectJacobianMatrix(co template -void PairInteractionProjectiveConstraintSet::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) +void PairInteractionProjectiveConstraintSet::doProjectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) { if( !isActive() ) return; if (this->mstate1 && this->mstate2) @@ -69,7 +69,7 @@ void PairInteractionProjectiveConstraintSet::projectResponse(const Me } template -void PairInteractionProjectiveConstraintSet::projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) +void PairInteractionProjectiveConstraintSet::doProjectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) { if( !isActive() ) return; if (this->mstate1 && this->mstate2) @@ -79,7 +79,7 @@ void PairInteractionProjectiveConstraintSet::projectVelocity(const Me } template -void PairInteractionProjectiveConstraintSet::projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) +void PairInteractionProjectiveConstraintSet::doProjectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) { if( !isActive() ) return; if (this->mstate1 && this->mstate2) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.h b/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.h index 65092cdcaa1..c6d66c7fcba 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.h @@ -57,17 +57,8 @@ class ProjectiveConstraintSet : public BaseProjectiveConstraintSet, public virtu ProjectiveConstraintSet(MechanicalState *mm = nullptr); ~ProjectiveConstraintSet() override; -public: - - // to get rid of warnings - using BaseProjectiveConstraintSet::projectResponse; - - - Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints - virtual bool isActive() const; ///< if false, the constraint does nothing - - virtual type::vector< core::BaseState* > getModels() override + virtual type::vector< core::BaseState* > doGetModels() override { return { this->getMState() }; } @@ -80,30 +71,58 @@ class ProjectiveConstraintSet : public BaseProjectiveConstraintSet, public virtu /// This method retrieves the dxId vector from the MechanicalState and call /// the internal projectResponse(VecDeriv&) method implemented by /// the component. - void projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) override; + void doProjectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) override; /// Project the L matrix of the Lagrange Multiplier equation system. /// /// This method retrieves the lines of the Jacobian Matrix from the MechanicalState and call /// the internal projectResponse(MatrixDeriv&) method implemented by /// the component. - void projectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) override; + void doProjectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) override; /// Project v to constrained space (v models a velocity). /// /// This method retrieves the vId vector from the MechanicalState and call /// the internal projectVelocity(VecDeriv&) method implemented by /// the component. - void projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) override; + void doProjectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) override; /// Project x to constrained space (x models a position). /// /// This method retrieves the xId vector from the MechanicalState and call /// the internal projectPosition(VecCoord&) method implemented by /// the component. - void projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) override; + void doProjectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) override; + + /// @} + + /// Project the global Mechanical Matrix to constrained space using offset parameter + void doApplyConstraint(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override + { + msg_error() << "applyConstraint(mparams, matrix) not implemented."; + } + /// Project the global Mechanical Vector to constrained space using offset parameter + void doApplyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override + { + msg_error() << "applyConstraint(mparams, vector, matrix) not implemented."; + } + +public: + + // to get rid of warnings + using BaseProjectiveConstraintSet::projectResponse; + using BaseProjectiveConstraintSet::projectJacobianMatrix; + using BaseProjectiveConstraintSet::projectVelocity; + using BaseProjectiveConstraintSet::projectPosition; + + + Data endTime; ///< The constraint stops acting after the given value. Use a negative value for infinite constraints + virtual bool isActive() const; ///< if false, the constraint does nothing + + /// @name Vector operations + /// @{ /// Project dx to constrained space (dx models an acceleration). /// @@ -130,19 +149,6 @@ class ProjectiveConstraintSet : public BaseProjectiveConstraintSet, public virtu /// @} - /// Project the global Mechanical Matrix to constrained space using offset parameter - void applyConstraint(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override - { - msg_error() << "applyConstraint(mparams, matrix) not implemented."; - } - - - /// Project the global Mechanical Vector to constrained space using offset parameter - void applyConstraint(const MechanicalParams* /*mparams*/, linearalgebra::BaseVector* /*vector*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) override - { - msg_error() << "applyConstraint(mparams, vector, matrix) not implemented."; - } - /// Pre-construction check method called by ObjectFactory. /// Check that DataTypes matches the MechanicalState. template diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.inl b/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.inl index a40477528aa..762eb496893 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ProjectiveConstraintSet.inl @@ -48,7 +48,7 @@ bool ProjectiveConstraintSet::isActive() const } template -void ProjectiveConstraintSet::projectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) +void ProjectiveConstraintSet::doProjectJacobianMatrix(const MechanicalParams* mparams, MultiMatrixDerivId cId) { if (!isActive()) return; @@ -62,7 +62,7 @@ void ProjectiveConstraintSet::projectJacobianMatrix(const MechanicalP template -void ProjectiveConstraintSet::projectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) +void ProjectiveConstraintSet::doProjectResponse(const MechanicalParams* mparams, MultiVecDerivId dxId) { if (!isActive()) return; @@ -74,7 +74,7 @@ void ProjectiveConstraintSet::projectResponse(const MechanicalParams* } template -void ProjectiveConstraintSet::projectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) +void ProjectiveConstraintSet::doProjectVelocity(const MechanicalParams* mparams, MultiVecDerivId vId) { if (!isActive()) return; @@ -88,7 +88,7 @@ void ProjectiveConstraintSet::projectVelocity(const MechanicalParams* } template -void ProjectiveConstraintSet::projectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) +void ProjectiveConstraintSet::doProjectPosition(const MechanicalParams* mparams, MultiVecCoordId xId) { if (!isActive()) return; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/RotationFinder.h b/Sofa/framework/Core/src/sofa/core/behavior/RotationFinder.h index 7adde6580c2..36e894fdf9a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/RotationFinder.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/RotationFinder.h @@ -42,7 +42,7 @@ class RotationFinder : public BaseRotationFinder typedef typename Coord::value_type Real; typedef type::Mat< 3, 3, Real > Mat3x3; - using BaseRotationFinder::getRotations; + using BaseRotationFinder::doGetRotations; virtual const type::vector< Mat3x3 >& getRotations() = 0; }; diff --git a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.cpp b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.cpp index ad0a1790cd0..34f4b395743 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.cpp +++ b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.cpp @@ -65,5 +65,40 @@ bool Pipeline::removeInNode( objectmodel::BaseNode* node ) Inherit1::removeInNode(node); return true; } + +/// Entry point for collision reset, called by the simulation loop. It removes collision response from last step +void Pipeline::computeCollisionReset() +{ + //TODO (SPRINT SED 2025): Component state mechamism + if(!this->isComponentStateValid()) + return; + + doComputeCollisionReset(); +} + +/// Entry point for collision detection, called by the simulation loop. Note that this step must not modify the simulation graph +void Pipeline::computeCollisionDetection() +{ + //TODO (SPRINT SED 2025): Component state mechamism + 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 collisionModels{}; + + doComputeCollisionDetection(collisionModels); +} + +/// Entry point for collision response, called by the simulation loop. It adds the collision response in the simulation graph +void Pipeline::computeCollisionResponse() +{ + //TODO (SPRINT SED 2025): Component state mechamism + if(!this->isComponentStateValid()) + return; + + doComputeCollisionResponse(); +} + } // namespace sofa diff --git a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h index db8e4c89dec..7913686f6ec 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h +++ b/Sofa/framework/Core/src/sofa/core/collision/Pipeline.h @@ -68,11 +68,7 @@ class SOFA_CORE_API Pipeline : public virtual sofa::core::objectmodel::BaseCompo ContactManager* contactManager; CollisionGroupManager* groupManager; -public: -// typedef NarrowPhaseDetection::DetectionOutputMap DetectionOutputMap; -protected: Pipeline(); - ~Pipeline() override; private: @@ -84,13 +80,15 @@ class SOFA_CORE_API Pipeline : public virtual sofa::core::objectmodel::BaseCompo public: void reset() override = 0; - /// Remove collision response from last step - virtual void computeCollisionReset()=0; - /// Detect new collisions. Note that this step must not modify the simulation graph - virtual void computeCollisionDetection()=0; - /// Add collision response in the simulation graph - virtual void computeCollisionResponse()=0; + /// @brief Entry point for collision reset, called by the simulation loop. It removes collision response from last step + virtual void computeCollisionReset() final; + /// @brief Entry point for collision detection, called by the simulation loop. Note that this step must not modify the simulation graph + virtual void computeCollisionDetection() final; + + /// @brief Entry point for collision response, called by the simulation loop. It adds the collision response in the simulation graph + virtual void computeCollisionResponse() final; + void computeCollisions() { computeCollisionReset(); @@ -108,18 +106,19 @@ class SOFA_CORE_API Pipeline : public virtual sofa::core::objectmodel::BaseCompo /// get the set of response available with the current collision pipeline virtual std::set< std::string > getResponseList() const=0; -protected: - /// Remove collision response from last step - virtual void doCollisionReset() = 0; - /// Detect new collisions. Note that this step must not modify the simulation graph - virtual void doCollisionDetection(const sofa::type::vector& collisionModels) = 0; - /// Add collision response in the simulation graph - virtual void doCollisionResponse() = 0; - -public: bool insertInNode( objectmodel::BaseNode* node ) override; bool removeInNode( objectmodel::BaseNode* node ) override; + +protected: + /// @brief Delegates collision reset + virtual void doComputeCollisionReset() = 0; + + /// @brief Delegates collision detection + virtual void doComputeCollisionDetection(const sofa::type::vector& collisionModels) = 0; + + /// @brief Delegates response creation + virtual void doComputeCollisionResponse() = 0; }; } // namespace collision diff --git a/Sofa/framework/Core/src/sofa/core/visual/BaseVisualStyle.h b/Sofa/framework/Core/src/sofa/core/visual/BaseVisualStyle.h index a96702893ef..971f1647959 100644 --- a/Sofa/framework/Core/src/sofa/core/visual/BaseVisualStyle.h +++ b/Sofa/framework/Core/src/sofa/core/visual/BaseVisualStyle.h @@ -41,9 +41,35 @@ class SOFA_CORE_API BaseVisualStyle : public sofa::core::objectmodel::BaseCompon BaseVisualStyle() { } ~BaseVisualStyle() override { } + virtual void doUpdateVisualFlags(VisualParams* ) { }; + virtual void doApplyBackupFlags(VisualParams* ) { }; + public: - virtual void updateVisualFlags(VisualParams* ) { }; - virtual void applyBackupFlags(VisualParams* ) { }; + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doUpdateVisualFlags" internally, + * which is the method to override from now on. + * + **/ + virtual void updateVisualFlags(VisualParams* vparams) final { + //TODO (SPRINT SED 2025): Component state mechamism + return this->doUpdateVisualFlags(vparams); + }; + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyBackupFlags" internally, + * which is the method to override from now on. + * + **/ + virtual void applyBackupFlags(VisualParams* vparams) final { + //TODO (SPRINT SED 2025): Component state mechamism + return this->doApplyBackupFlags(vparams); + }; }; diff --git a/Sofa/framework/Core/test/collision/NarrowPhaseDetection_test.cpp b/Sofa/framework/Core/test/collision/NarrowPhaseDetection_test.cpp index 4e7693d6065..d7e817c9269 100644 --- a/Sofa/framework/Core/test/collision/NarrowPhaseDetection_test.cpp +++ b/Sofa/framework/Core/test/collision/NarrowPhaseDetection_test.cpp @@ -82,7 +82,7 @@ namespace sofa::core class DummyCollisionModel : public CollisionModel { public: - void computeBoundingTree(int /*maxDepth*/) override {} + void doComputeBoundingTree(int /*maxDepth*/) override {} }; } //namespace sofa::collision diff --git a/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.cpp b/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.cpp index 7e3cdca0178..fa064b24280 100644 --- a/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.cpp +++ b/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.cpp @@ -54,7 +54,7 @@ void MyBehaviorModel::reinit() { } -void MyBehaviorModel::updatePosition(double /*dt*/) +void MyBehaviorModel::doUpdatePosition(double /*dt*/) { } diff --git a/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.h b/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.h index 696047ef80b..fcfbb914eae 100644 --- a/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.h +++ b/Sofa/framework/Helper/test/system/TestPluginA/ComponentC.h @@ -52,7 +52,7 @@ class MyBehaviorModel : public sofa::core::BehaviorModel public: virtual void init(); virtual void reinit(); - virtual void updatePosition(double dt); + void doUpdatePosition(double dt) override; protected: Data customUnsignedData; ///< Example of unsigned data with custom widget diff --git a/Sofa/framework/Simulation/Core/CMakeLists.txt b/Sofa/framework/Simulation/Core/CMakeLists.txt index e16319d1d4e..c1d4465199f 100644 --- a/Sofa/framework/Simulation/Core/CMakeLists.txt +++ b/Sofa/framework/Simulation/Core/CMakeLists.txt @@ -35,7 +35,6 @@ set(HEADER_FILES ${SRC_ROOT}/Node.inl ${SRC_ROOT}/ParallelSparseMatrixProduct.h ${SRC_ROOT}/PauseEvent.h - ${SRC_ROOT}/PipelineImpl.h ${SRC_ROOT}/PositionEvent.h ${SRC_ROOT}/PrintVisitor.h ${SRC_ROOT}/PropagateEventVisitor.h @@ -176,7 +175,6 @@ set(SOURCE_FILES ${SRC_ROOT}/MutationListener.cpp ${SRC_ROOT}/Node.cpp ${SRC_ROOT}/PauseEvent.cpp - ${SRC_ROOT}/PipelineImpl.cpp ${SRC_ROOT}/PositionEvent.cpp ${SRC_ROOT}/PrintVisitor.cpp ${SRC_ROOT}/PropagateEventVisitor.cpp diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseSimulationExporter.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseSimulationExporter.h index 2db2245d9f5..140aa23b83b 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseSimulationExporter.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseSimulationExporter.h @@ -64,13 +64,26 @@ class SOFA_SIMULATION_CORE_API BaseSimulationExporter : public virtual sofa::cor virtual void doInit() {} virtual void doReInit() {} - virtual bool write() = 0; + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doWrite" internally, + * which is the method to override from now on. + * + **/ + virtual bool write() final { + //TODO (SPRINT SED 2025): Component state mechamism + return this->doWrite(); + } protected: BaseSimulationExporter() ; ~BaseSimulationExporter() override { } + virtual bool doWrite() = 0; const std::string getOrCreateTargetPath(const std::string& filename, bool autonumbering); void updateFromDataField(); unsigned int m_stepCounter {0}; diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp index 605062dedf9..36c8ea2fbb3 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.cpp @@ -296,7 +296,7 @@ void DefaultAnimationLoop::animate(const core::ExecParams* params, SReal dt) con endIntegration(params, dt); } -void DefaultAnimationLoop::step(const core::ExecParams* params, SReal dt) +void DefaultAnimationLoop::doStep(const core::ExecParams* params, SReal dt) { if (this->d_componentState.getValue() != sofa::core::objectmodel::ComponentState::Valid) { diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.h index f6f88c1db47..b200ad78f6d 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/DefaultAnimationLoop.h @@ -61,12 +61,12 @@ class SOFA_SIMULATION_CORE_API DefaultAnimationLoop : public sofa::core::behavio /// Set the simulation node this animation loop is controlling virtual void setNode(simulation::Node*); - /// perform one animation step - void step(const sofa::core::ExecParams* params, SReal dt) override; - protected : simulation::Node* m_node { nullptr }; + /// perform one animation step + void doStep(const sofa::core::ExecParams* params, SReal dt) override; + void behaviorUpdatePosition(const sofa::core::ExecParams* params, SReal dt) const; void updateInternalData(const sofa::core::ExecParams* params) const; void beginIntegration(const sofa::core::ExecParams* params, SReal dt) const; diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.cpp deleted file mode 100644 index eaa29c4737e..00000000000 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture * -* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by * -* the Free Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this program. If not, see . * -******************************************************************************* -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include - - -namespace sofa -{ - -namespace simulation -{ - - -using namespace sofa::core; -using namespace sofa::core::objectmodel; -using namespace sofa::core::behavior; -using namespace sofa::core::collision; - -PipelineImpl::PipelineImpl() -{ -} - -PipelineImpl::~PipelineImpl() -{ -} - -void PipelineImpl::init() -{ - simulation::Node* root = dynamic_cast(getContext()); - if(root == nullptr) return; - - intersectionMethods.clear(); - root->getTreeObjects(&intersectionMethods); - intersectionMethod = (intersectionMethods.empty() ? nullptr : intersectionMethods[0]); - - broadPhaseDetections.clear(); - root->getTreeObjects(&broadPhaseDetections); - broadPhaseDetection = (broadPhaseDetections.empty() ? nullptr : broadPhaseDetections[0]); - - narrowPhaseDetections.clear(); - root->getTreeObjects(&narrowPhaseDetections); - narrowPhaseDetection = (narrowPhaseDetections.empty() ? nullptr : narrowPhaseDetections[0]); - - contactManagers.clear(); - root->getTreeObjects(&contactManagers); - contactManager = (contactManagers.empty() ? nullptr : contactManagers[0]); - - groupManagers.clear(); - root->getTreeObjects(&groupManagers); - groupManager = (groupManagers.empty() ? nullptr : groupManagers[0]); - - if (intersectionMethod==nullptr) - { - msg_warning(this) <<"no intersection component defined. Switching to the DiscreteIntersection component. " << msgendl - "To remove this warning, you can add an intersection component to your scene. " << msgendl - "More details on the collision pipeline can be found at " - "[sofadoc::Collision](https://www.sofa-framework.org/community/doc/simulation-principles/multi-model-representation/collision/)."; - sofa::core::objectmodel::BaseObjectDescription discreteIntersectionDesc("Default Intersection","DiscreteIntersection"); - const sofa::core::objectmodel::BaseComponent::SPtr obj = sofa::core::ObjectFactory::CreateObject(getContext(), &discreteIntersectionDesc); - intersectionMethod = dynamic_cast(obj.get()); - } -} - -void PipelineImpl::reset() -{ - computeCollisionReset(); -} - -void PipelineImpl::computeCollisionReset() -{ - const simulation::Node* root = dynamic_cast(getContext()); - if(root == nullptr) return; - if (broadPhaseDetection!=nullptr && broadPhaseDetection->getIntersectionMethod()!=intersectionMethod) - broadPhaseDetection->setIntersectionMethod(intersectionMethod); - if (narrowPhaseDetection!=nullptr && narrowPhaseDetection->getIntersectionMethod()!=intersectionMethod) - narrowPhaseDetection->setIntersectionMethod(intersectionMethod); - if (contactManager!=nullptr && contactManager->getIntersectionMethod()!=intersectionMethod) - contactManager->setIntersectionMethod(intersectionMethod); - - doCollisionReset(); -} - -void PipelineImpl::computeCollisionDetection() -{ - simulation::Node* root = dynamic_cast(getContext()); - if(root == nullptr) return; - std::vector collisionModels; - root->getTreeObjects(&collisionModels); - doCollisionDetection(collisionModels); -} - -void PipelineImpl::computeCollisionResponse() -{ - const simulation::Node* root = dynamic_cast(getContext()); - if(root == nullptr) return; - - doCollisionResponse(); -} - -} // namespace simulation - -} // namespace sofa diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.h deleted file mode 100644 index 5d220d9e23c..00000000000 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/PipelineImpl.h +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture * -* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by * -* the Free Software Foundation; either version 2.1 of the License, or (at * -* your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this program. If not, see . * -******************************************************************************* -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_SIMULATION_PIPELINEIMPL_H -#define SOFA_SIMULATION_PIPELINEIMPL_H - -#include -#include - - -namespace sofa::simulation -{ - -class SOFA_SIMULATION_CORE_API PipelineImpl : public sofa::core::collision::Pipeline -{ - -protected: - PipelineImpl(); - - ~PipelineImpl() override; -public: - void init() override; - - void reset() override; - - /// Remove collision response from last step - void computeCollisionReset() override; - /// Detect new collisions. Note that this step must not modify the simulation graph - void computeCollisionDetection() override; - /// Add collision response in the simulation graph - void computeCollisionResponse() override; -}; - - -} // namespace sofa::simulation - - -#endif diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCapsuleModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCapsuleModel.h index 9e45c64e564..45616469610 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCapsuleModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCapsuleModel.h @@ -55,10 +55,6 @@ class TBulletCapsuleModel : public collisionobbcapsule::geometry::CapsuleCollisi virtual void initBullet(); virtual void updateBullet(); - inline virtual void computeBoundingTree(int/* maxDepth*/){ - _bt_cshape->recalculateLocalAabb(); - } - inline virtual ~TBulletCapsuleModel(); virtual void init(); @@ -79,6 +75,10 @@ class TBulletCapsuleModel : public collisionobbcapsule::geometry::CapsuleCollisi void cleanGarbage(); static void makeBtQuat(const Coord & dir,btQuaternion & quat); + + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { + _bt_cshape->recalculateLocalAabb(); + } }; typedef TBulletCapsuleModel BulletCapsuleModel; diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.h index 32e014742e0..d1265931e5d 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.h @@ -82,25 +82,10 @@ class TBulletConvexHullModel : public sofa::core::CollisionModel ,public BulletC virtual void reinit(); - // -- CollisionModel interface - - virtual void resize(int size); - //void draw(const core::visual::VisualParams*,int index); void draw(const core::visual::VisualParams* vparams); - inline virtual void computeBoundingTree(int/* maxDepth*/){ - _bt_cshape.recalculateLocalAabb(); - } - - virtual bool canCollideWithElement(int index, CollisionModel* model2, int index2){ - if(this == model2) - return false; - - return CollisionModel::canCollideWithElement(index,model2,index2); - } - core::behavior::MechanicalState* getMechanicalState() { return _mstate; } const core::behavior::MechanicalState* getMechanicalState() const { return _mstate; } @@ -148,6 +133,21 @@ class TBulletConvexHullModel : public sofa::core::CollisionModel ,public BulletC void draw_without_decomposition(const core::visual::VisualParams* vparams); void draw_decomposition(const core::visual::VisualParams* vparams); + // -- CollisionModel interface + + // virtual void doResize(int size) override; + + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { + _bt_cshape.recalculateLocalAabb(); + } + + virtual bool doCanCollideWithElement(int index, CollisionModel* model2, int index2) override { + if(this == model2) + return false; + + return CollisionModel::doCanCollideWithElement(index,model2,index2); + } + Coord _bary; btTransform _bt_trans; core::behavior::MechanicalState* _mstate; diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.inl b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.inl index cae6ed3906b..3cd321cb564 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.inl +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletConvexHullModel.inl @@ -30,13 +30,6 @@ TBulletConvexHullModel::TBulletConvexHullModel() } -template -void TBulletConvexHullModel::resize(int size) -{ - this->core::CollisionModel::resize(size); -} - - template void TBulletConvexHullModel::init(){ this->CollisionModel::init(); diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCylinderModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCylinderModel.h index 9d21fd9804f..988b44ea814 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCylinderModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletCylinderModel.h @@ -48,9 +48,7 @@ class TBulletCylinderModel : public sofa::component::collision::geometry::Cylind virtual void initBullet(); virtual void updateBullet(); - inline virtual void computeBoundingTree(int/* maxDepth*/){ - _bt_cshape->recalculateLocalAabb(); - } + inline virtual ~TBulletCylinderModel(); @@ -70,6 +68,10 @@ class TBulletCylinderModel : public sofa::component::collision::geometry::Cylind btCompoundShape * _bt_cshape;//or maybe something else ? void cleanGarbage(); + + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { + _bt_cshape->recalculateLocalAabb(); + } }; typedef TBulletCylinderModel BulletCylinderModel; diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletOBBModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletOBBModel.h index 0a10de66ec6..0f03652075c 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletOBBModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletOBBModel.h @@ -48,9 +48,7 @@ class TBulletOBBModel : public collisionobbcapsule::geometry::OBBCollisionModel< virtual void initBullet(); virtual void updateBullet(); - inline virtual void computeBoundingTree(int/* maxDepth*/){ - _bt_cshape->recalculateLocalAabb(); - } + inline virtual ~TBulletOBBModel(); @@ -69,6 +67,10 @@ class TBulletOBBModel : public collisionobbcapsule::geometry::OBBCollisionModel< std::stack _garbage; btCompoundShape * _bt_cshape; + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { + _bt_cshape->recalculateLocalAabb(); + } + void cleanGarbage(); }; diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletSphereModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletSphereModel.h index a06fb6a839d..fd4397d2b19 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletSphereModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletSphereModel.h @@ -39,10 +39,6 @@ class TBulletSphereModel : public sofa::component::collision::geometry::SphereCo virtual void initBullet(); virtual void updateBullet(); - inline virtual void computeBoundingTree(int/* maxDepth*/){ - _bt_cshape->recalculateLocalAabb(); - } - inline virtual ~TBulletSphereModel(); virtual void init(); @@ -60,6 +56,10 @@ class TBulletSphereModel : public sofa::component::collision::geometry::SphereCo std::stack _garbage; btCompoundShape * _bt_cshape; + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { + _bt_cshape->recalculateLocalAabb(); + } + void cleanGarbage(); }; diff --git a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletTriangleModel.h b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletTriangleModel.h index 5c7d2c80806..9fe28fa492f 100644 --- a/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletTriangleModel.h +++ b/applications/plugins/BulletCollisionDetection/src/BulletCollisionDetection/BulletTriangleModel.h @@ -38,14 +38,33 @@ class TBulletTriangleModel : public sofa::component::collision::geometry::Triang virtual void initBullet(); virtual void updateBullet(); - inline virtual void computeBoundingTree(int/* maxDepth*/){ + inline virtual ~TBulletTriangleModel(){ + delete _bt_mesh; + delete _bt_gmesh; + } + + virtual void init(); + + virtual void reinit(); + + void handleEvent(sofa::core::objectmodel::Event * ev); + + inline virtual void setMargin(SReal m){ *margin.beginEdit() = m; margin.endEdit(); } + + bool goodSofaBulletLink()const; + +protected: + template + void myFillFunc(const ToRead & pos,int numverts,ToFill vertexbase,int vertexStride); + + inline virtual void doComputeBoundingTree(int/* maxDepth*/) override { //_bt_collision_object _bt_gmesh->updateBound(); //_bt_gmesh->refitTree(); //_bt_gmesh->postUpdate(); } -// inline virtual void computeBoundingTree(int/* maxDepth*/){ +// inline virtual void doComputeBoundingTree(int/* maxDepth*/){ // //_bt_collision_object // //_bt_gmesh->updateBound(); // const Vector3 & min = this->mstate->f_bbox.getValue().minBBox(); @@ -61,27 +80,7 @@ class TBulletTriangleModel : public sofa::component::collision::geometry::Triang // //_bt_gmesh->postUpdate(); // } - //virtual void computeBoundingTree(int maxDepth=0); - - inline virtual ~TBulletTriangleModel(){ - delete _bt_mesh; - delete _bt_gmesh; - } - - virtual void init(); - - virtual void reinit(); - - void handleEvent(sofa::core::objectmodel::Event * ev); - - inline virtual void setMargin(SReal m){ *margin.beginEdit() = m; margin.endEdit(); } - - bool goodSofaBulletLink()const; - -protected: - template - void myFillFunc(const ToRead & pos,int numverts,ToFill vertexbase,int vertexStride); - + //virtual void doComputeBoundingTree(int maxDepth=0); btTriangleMesh * _bt_mesh; btGImpactMeshShape * _bt_gmesh; diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.h b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.h index 41d2553e9d7..d7ce2b7f109 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.h +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.h @@ -111,13 +111,6 @@ class CapsuleCollisionModel : public core::CollisionModel public: void init() override; - // -- CollisionModel interface - - void resize(sofa::Size size) override; - - void computeBoundingTree(int maxDepth=0) override; - - //virtual void computeContinuousBoundingTree(SReal dt, int maxDepth=0); void draw(const core::visual::VisualParams* vparams, Index index) override; @@ -168,11 +161,6 @@ class CapsuleCollisionModel : public core::CollisionModel return sofa::core::objectmodel::BaseComponent::canCreate(obj, context, arg); } - sofa::core::topology::BaseMeshTopology* getCollisionTopology() override - { - return l_topology.get(); - } - /** *Returns true if capsules at indexes i1 and i2 share the same vertex. */ @@ -185,6 +173,20 @@ class CapsuleCollisionModel : public core::CollisionModel protected: core::behavior::MechanicalState* _mstate; + + // -- CollisionModel interface + + void doResize(sofa::Size size) override; + + void doComputeBoundingTree(int maxDepth=0) override; + + //virtual void doComputeContinuousBoundingTree(SReal dt, int maxDepth=0); + + sofa::core::topology::BaseMeshTopology* doGetCollisionTopology() override + { + return l_topology.get(); + } + }; template diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.inl b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.inl index 3d018ecb681..14f5dccd91e 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.inl +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/CapsuleModel.inl @@ -52,9 +52,9 @@ CapsuleCollisionModel::~CapsuleCollisionModel() {} template -void CapsuleCollisionModel::resize(sofa::Size size) +void CapsuleCollisionModel::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); _capsule_points.resize(size); VecReal & capsule_radii = *_capsule_radii.beginEdit(); @@ -117,7 +117,7 @@ Size CapsuleCollisionModel::nbCap()const } template -void CapsuleCollisionModel::computeBoundingTree(int maxDepth) +void CapsuleCollisionModel::doComputeBoundingTree(int maxDepth) { using namespace sofa::type; using namespace sofa::defaulttype; @@ -126,6 +126,7 @@ void CapsuleCollisionModel::computeBoundingTree(int maxDepth) bool updated = false; if (ncap != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(ncap); updated = true; cubeModel->resize(0); diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.h b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.h index 1432c07738f..23c405d53f4 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.h +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.h @@ -151,14 +151,6 @@ class OBBCollisionModel : public core::CollisionModel public: void init() override; - // -- CollisionModel interface - - void resize(sofa::Size size) override; - - void computeBoundingTree(int maxDepth=0) override; - - //virtual void computeContinuousBoundingTree(SReal dt, int maxDepth=0); - void draw(const sofa::core::visual::VisualParams* vparams, sofa::Index index) override; sofa::core::behavior::MechanicalState* getMechanicalState() { return _mstate; } @@ -255,6 +247,14 @@ class OBBCollisionModel : public core::CollisionModel protected: sofa::core::behavior::MechanicalState* _mstate; + + // -- CollisionModel interface + + void doResize(sofa::Size size) override; + + void doComputeBoundingTree(int maxDepth=0) override; + + //virtual void doComputeContinuousBoundingTree(SReal dt, int maxDepth=0); }; template diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.inl b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.inl index d2d9fcc1b39..c7df5c34c97 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.inl +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/OBBModel.inl @@ -65,8 +65,8 @@ void OBBCollisionModel::init() template -void OBBCollisionModel::resize(sofa::Size size){ - this->core::CollisionModel::resize(size); +void OBBCollisionModel::doResize(sofa::Size size){ + this->core::CollisionModel::doResize(size); VecCoord & vext = *(ext.beginEdit()); @@ -85,12 +85,13 @@ void OBBCollisionModel::resize(sofa::Size size){ template -void OBBCollisionModel::computeBoundingTree(int maxDepth){ +void OBBCollisionModel::doComputeBoundingTree(int maxDepth){ sofa::component::collision::geometry::CubeCollisionModel* cubeModel = createPrevious(); const auto npoints = _mstate->getSize(); bool updated = false; if (npoints != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(npoints); updated = true; cubeModel->resize(0); diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.h b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.h index 46bfdd8e0c1..0625bc63107 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.h +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.h @@ -118,14 +118,6 @@ class CapsuleCollisionModel > : publi public: void init() override; - // -- CollisionModel interface - - void resize(sofa::Size size) override; - - void computeBoundingTree(int maxDepth=0) override; - - //virtual void computeContinuousBoundingTree(SReal dt, int maxDepth=0); - void draw(const core::visual::VisualParams* vparams, sofa::Index index) override; core::behavior::MechanicalState* getMechanicalState() { return _mstate; } @@ -169,6 +161,14 @@ class CapsuleCollisionModel > : publi Data & writeRadii(); protected: core::behavior::MechanicalState* _mstate; + + // -- CollisionModel interface + + void doResize(sofa::Size size) override; + + void doComputeBoundingTree(int maxDepth=0) override; + + //virtual void doComputeContinuousBoundingTree(SReal dt, int maxDepth=0); }; diff --git a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.inl b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.inl index 50e2101e7bc..43c127ea8cc 100644 --- a/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.inl +++ b/applications/plugins/CollisionOBBCapsule/src/CollisionOBBCapsule/geometry/RigidCapsuleModel.inl @@ -50,9 +50,9 @@ CapsuleCollisionModel >::CapsuleColli } template -void CapsuleCollisionModel >::resize(sofa::Size size) +void CapsuleCollisionModel >::doResize(sofa::Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); VecReal & capsule_radii = *d_capsule_radii.beginEdit(); VecReal & capsule_heights = *d_capsule_heights.beginEdit(); @@ -103,7 +103,7 @@ Size CapsuleCollisionModel >::nbCap() } template -void CapsuleCollisionModel >::computeBoundingTree(int maxDepth) +void CapsuleCollisionModel >::doComputeBoundingTree(int maxDepth) { sofa::component::collision::geometry::CubeCollisionModel* cubeModel = createPrevious(); const auto ncap = _mstate->getSize(); @@ -111,6 +111,7 @@ void CapsuleCollisionModel >::compute bool updated = false; if (ncap != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(ncap); updated = true; cubeModel->resize(0); diff --git a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.cpp b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.cpp index b12e4c33210..acd7edcdf63 100644 --- a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.cpp +++ b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.cpp @@ -75,7 +75,7 @@ void AnimationLoopParallelScheduler::cleanup() this->stopTaskSchduler(); } -void AnimationLoopParallelScheduler::step(const sofa::core::ExecParams* params, SReal dt) +void AnimationLoopParallelScheduler::doStep(const sofa::core::ExecParams* params, SReal dt) { if (dt == 0) dt = this->gnode->getDt(); diff --git a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h index 001224316ec..e3b35bd423e 100644 --- a/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h +++ b/applications/plugins/MultiThreading/src/MultiThreading/component/animationloop/AnimationLoopParallelScheduler.h @@ -53,6 +53,8 @@ class SOFA_MULTITHREADING_PLUGIN_API AnimationLoopParallelScheduler : ~AnimationLoopParallelScheduler() override; + void doStep(const sofa::core::ExecParams* params, SReal dt) override; + public: void init() override; @@ -64,8 +66,6 @@ class SOFA_MULTITHREADING_PLUGIN_API AnimationLoopParallelScheduler : void cleanup() override; - void step(const sofa::core::ExecParams* params, SReal dt) override; - private : sofa::simulation::Node* gnode; diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.cpp b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.cpp index 63471bb74ce..8a0ebb1ac52 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.cpp +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.cpp @@ -42,9 +42,9 @@ CudaPointCollisionModel::CudaPointCollisionModel() { } -void CudaPointCollisionModel::resize(Size size) +void CudaPointCollisionModel::doResize(Size size) { - this->core::CollisionModel::resize(size); + this->core::CollisionModel::doResize(size); } void CudaPointCollisionModel::init() @@ -105,7 +105,7 @@ void CudaPointCollisionModel::drawCollisionModel(const core::visual::VisualParam using sofa::component::collision::geometry::CubeCollisionModel; -void CudaPointCollisionModel::computeBoundingTree(int maxDepth) +void CudaPointCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = createPrevious(); const int npoints = mstate->getSize(); @@ -114,6 +114,7 @@ void CudaPointCollisionModel::computeBoundingTree(int maxDepth) bool updated = false; if (nelems != size) { + // TODO (SPRINT SED 2025 SUGGESTION): maybe we should use doResize (because of double state check) resize(nelems); updated = true; } diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.h b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.h index 5694402231a..d4a4f7f3b56 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.h +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/collision/geometry/CudaPointModel.h @@ -68,14 +68,6 @@ class SOFACUDA_COMPONENT_API CudaPointCollisionModel : public core::CollisionMod virtual void init() override; - // -- CollisionModel interface - - virtual void resize(Size size) override; - - virtual void computeBoundingTree(int maxDepth=0) override; - - //virtual void computeContinuousBoundingTree(double dt, int maxDepth=0); - void draw(const core::visual::VisualParams*,Index index) override; core::behavior::MechanicalState* getMechanicalState() { return mstate; } @@ -84,6 +76,14 @@ class SOFACUDA_COMPONENT_API CudaPointCollisionModel : public core::CollisionMod void drawCollisionModel(const core::visual::VisualParams*) override; core::behavior::MechanicalState* mstate; + + // -- CollisionModel interface + + virtual void doResize(Size size) override; + + virtual void doComputeBoundingTree(int maxDepth=0) override; + + //virtual void doComputeContinuousBoundingTree(double dt, int maxDepth=0); }; inline CudaPoint::CudaPoint(CudaPointCollisionModel* model, Index index) diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.h b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.h index 4703b6be20c..d59e89ba3b1 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.h +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.h @@ -353,7 +353,7 @@ class HexahedronFEMForceFieldInternalData< gpu::cuda::CudaVectorTypes void HexahedronFEMForceField< T >::reinit(); \ template<> void HexahedronFEMForceField< T >::addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v); \ template<> void HexahedronFEMForceField< T >::addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx); \ - template<> void HexahedronFEMForceField< T >::getRotations(linearalgebra::BaseMatrix* rotations, int offset); \ + template<> void HexahedronFEMForceField< T >::doGetRotations(linearalgebra::BaseMatrix* rotations, int offset); \ CudaHexahedronFEMForceField_DeclMethods(gpu::cuda::CudaVec3fTypes); diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.inl index c36d357b973..5fea0001e06 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaHexahedronFEMForceField.inl @@ -249,7 +249,7 @@ const HexahedronFEMForceField::Transformation& Hexahe } template<> -void HexahedronFEMForceField::getRotations(linearalgebra::BaseMatrix * rotations,int offset) +void HexahedronFEMForceField::doGetRotations(linearalgebra::BaseMatrix * rotations,int offset) { const auto nbdof = this->mstate->getSize(); diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.h b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.h index 2af9fdf1f33..aa969135275 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.h +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.h @@ -276,7 +276,7 @@ class TetrahedronFEMForceFieldInternalData< gpu::cuda::CudaVectorTypes void TetrahedronFEMForceField< T >::reinit(); \ template<> void TetrahedronFEMForceField< T >::addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v); \ template<> void TetrahedronFEMForceField< T >::getRotations(VecReal& vecR); \ - template<> void TetrahedronFEMForceField< T >::getRotations(linearalgebra::BaseMatrix * vecR,int offset); \ + template<> void TetrahedronFEMForceField< T >::doGetRotations(linearalgebra::BaseMatrix * vecR,int offset); \ template<> void TetrahedronFEMForceField< T >::addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx); \ template<> void TetrahedronFEMForceField< T >::addKToMatrix(sofa::linearalgebra::BaseMatrix* mat, SReal kFactor, unsigned int& offset); \ diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.inl index b84ec71db49..10b4ddd2ae9 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/solidmechanics/fem/elastic/CudaTetrahedronFEMForceField.inl @@ -634,7 +634,7 @@ void TetrahedronFEMForceFieldInternalData< gpu::cuda::CudaVectorTypes inline void TetrahedronFEMForceField< T >::getRotations(VecReal & rotations) \ { data.getRotations(this, rotations); } \ - template<> inline void TetrahedronFEMForceField< T >::getRotations(linearalgebra::BaseMatrix * rotations,int offset) \ + template<> inline void TetrahedronFEMForceField< T >::doGetRotations(linearalgebra::BaseMatrix * rotations,int offset) \ { data.getRotations(this, rotations,offset); } \ template<> inline void TetrahedronFEMForceField< T >::addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) \ { \ diff --git a/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.cpp b/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.cpp index 15b26d9b60e..bb6bc9e6c88 100644 --- a/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.cpp +++ b/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.cpp @@ -561,9 +561,9 @@ void CudaRigidDistanceGridCollisionModel::init() std::cout << "< CudaRigidDistanceGridCollisionModel::init()"<core::CollisionModel::resize(s); + this->core::CollisionModel::doResize(s); elems.resize(s); } @@ -599,7 +599,7 @@ void CudaRigidDistanceGridCollisionModel::setNewState(Index index, double dt, Cu using sofa::component::collision::geometry::CubeCollisionModel; /// Create or update the bounding volume hierarchy. -void CudaRigidDistanceGridCollisionModel::computeBoundingTree(int maxDepth) +void CudaRigidDistanceGridCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = this->createPrevious(); diff --git a/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.h b/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.h index 8da7b24b5d6..89f43f66405 100644 --- a/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.h +++ b/applications/plugins/SofaDistanceGrid/extensions/CUDA/src/SofaDistanceGrid/CUDA/CudaDistanceGridCollisionModel.h @@ -475,6 +475,11 @@ class CudaRigidDistanceGridCollisionModel : public core::CollisionModel void updateGrid(); void drawCollisionModel(const core::visual::VisualParams*) override; + // -- CollisionModel interface + void doResize(Size size) override; + + /// Create or update the bounding volume hierarchy. + void doComputeBoundingTree(int maxDepth=0) override; public: // Input data parameters @@ -546,13 +551,6 @@ class CudaRigidDistanceGridCollisionModel : public core::CollisionModel /// Set new grid and transform, keeping the old state to estimate velocity void setNewState(double dt, CudaDistanceGrid* grid, const Matrix3& rotation, const Vec3& translation); - // -- CollisionModel interface - - void resize(Size size) override; - - /// Create or update the bounding volume hierarchy. - void computeBoundingTree(int maxDepth=0) override; - void draw(const core::visual::VisualParams*, Index index) override; }; diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp index f10b376ac7c..c0e1932df0f 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp @@ -137,9 +137,9 @@ void RigidDistanceGridCollisionModel::init() msg_info() << "Initialisation done."; } -void RigidDistanceGridCollisionModel::resize(sofa::Size s) +void RigidDistanceGridCollisionModel::doResize(sofa::Size s) { - this->core::CollisionModel::resize(s); + this->core::CollisionModel::doResize(s); elems.resize(s); } @@ -199,7 +199,7 @@ void RigidDistanceGridCollisionModel::updateState() } /// Create or update the bounding volume hierarchy. -void RigidDistanceGridCollisionModel::computeBoundingTree(int maxDepth) +void RigidDistanceGridCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = this->createPrevious(); @@ -549,13 +549,13 @@ void FFDDistanceGridCollisionModel::init() msg_info() << c <<" active cubes."; } -void FFDDistanceGridCollisionModel::resize(sofa::Size s) +void FFDDistanceGridCollisionModel::doResize(sofa::Size s) { - this->core::CollisionModel::resize(s); + this->core::CollisionModel::doResize(s); elems.resize(s); } -bool FFDDistanceGridCollisionModel::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) +bool FFDDistanceGridCollisionModel::doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) { if (model2 != this) return true; if (!this->bSelfCollision.getValue()) return true; @@ -566,7 +566,7 @@ bool FFDDistanceGridCollisionModel::canCollideWithElement(sofa::Index index, Col } /// Create or update the bounding volume hierarchy. -void FFDDistanceGridCollisionModel::computeBoundingTree(int maxDepth) +void FFDDistanceGridCollisionModel::doComputeBoundingTree(int maxDepth) { CubeCollisionModel* cubeModel = this->createPrevious(); diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.h b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.h index 675094f8922..ce08eba0135 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.h +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.h @@ -145,6 +145,11 @@ class SOFA_SOFADISTANCEGRID_API RigidDistanceGridCollisionModel : public core::C ~RigidDistanceGridCollisionModel() override; void drawCollisionModel(const core::visual::VisualParams* vparams) override; + void doResize(sofa::Size size) override; + + /// Create or update the bounding volume hierarchy. + void doComputeBoundingTree(int maxDepth=0) override; + public: core::behavior::MechanicalState* getRigidModel() { return this->mstate ; } core::behavior::MechanicalState* getMechanicalState() { return this->mstate ; } @@ -217,11 +222,6 @@ class SOFA_SOFADISTANCEGRID_API RigidDistanceGridCollisionModel : public core::C /// Update transformation matrices from current rigid state void updateState(); - void resize(sofa::Size size) override; - - /// Create or update the bounding volume hierarchy. - void computeBoundingTree(int maxDepth=0) override; - void draw(const core::visual::VisualParams*, sofa::Index index) override; }; @@ -450,13 +450,23 @@ class SOFA_SOFADISTANCEGRID_API FFDDistanceGridCollisionModel : public core::Col ~FFDDistanceGridCollisionModel() override; void drawCollisionModel(const core::visual::VisualParams* vparams) override; + /// CollisionModel interface + void doResize(sofa::Size size) override; + + /// Create or update the bounding volume hierarchy. + void doComputeBoundingTree(int maxDepth=0) override; + + bool doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; + + core::topology::BaseMeshTopology* doGetCollisionTopology() override { return l_ffdMesh; } + public: core::behavior::MechanicalState* getDeformModel() { return this->mstate; } core::topology::BaseMeshTopology* getDeformGrid() { return l_ffdMesh; } /// alias used by ContactMapper core::behavior::MechanicalState* getMechanicalState() { return this->mstate; } - core::topology::BaseMeshTopology* getCollisionTopology() override { return l_ffdMesh; } + void init() override; @@ -470,14 +480,6 @@ class SOFA_SOFADISTANCEGRID_API FFDDistanceGridCollisionModel : public core::Col return elems[index]; } - /// CollisionModel interface - void resize(sofa::Size size) override; - - /// Create or update the bounding volume hierarchy. - void computeBoundingTree(int maxDepth=0) override; - - bool canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; - void draw(const core::visual::VisualParams*, sofa::Index index) override; }; diff --git a/applications/plugins/SofaEulerianFluid/Fluid2D.cpp b/applications/plugins/SofaEulerianFluid/Fluid2D.cpp index 08719220978..aba13fbc4d5 100644 --- a/applications/plugins/SofaEulerianFluid/Fluid2D.cpp +++ b/applications/plugins/SofaEulerianFluid/Fluid2D.cpp @@ -83,7 +83,7 @@ void Fluid2D::reset() init(); } -void Fluid2D::updatePosition(SReal dt) +void Fluid2D::doUpdatePosition(SReal dt) { fnext->step(fluid, ftemp, (real)dt); Grid2D* p = fluid; fluid=fnext; fnext=p; diff --git a/applications/plugins/SofaEulerianFluid/Fluid2D.h b/applications/plugins/SofaEulerianFluid/Fluid2D.h index c3c13645f76..dd4ab9a758d 100644 --- a/applications/plugins/SofaEulerianFluid/Fluid2D.h +++ b/applications/plugins/SofaEulerianFluid/Fluid2D.h @@ -68,7 +68,7 @@ class SOFA_EULERIAN_FLUID_API Fluid2D : public sofa::core::BehaviorModel void reset() override; - void updatePosition(SReal dt) override; + void doUpdatePosition(SReal dt) override; void draw(const sofa::core::visual::VisualParams* vparams) override; diff --git a/applications/plugins/SofaEulerianFluid/Fluid3D.cpp b/applications/plugins/SofaEulerianFluid/Fluid3D.cpp index 0b06ed462cd..3e543dbdfa3 100644 --- a/applications/plugins/SofaEulerianFluid/Fluid3D.cpp +++ b/applications/plugins/SofaEulerianFluid/Fluid3D.cpp @@ -91,7 +91,7 @@ void Fluid3D::reset() init(); } -void Fluid3D::updatePosition(SReal dt) +void Fluid3D::doUpdatePosition(SReal dt) { fnext->gravity = getContext()->getGravity()/f_cellwidth.getValue(); fnext->step(fluid, ftemp, (real)dt); diff --git a/applications/plugins/SofaEulerianFluid/Fluid3D.h b/applications/plugins/SofaEulerianFluid/Fluid3D.h index 95f351b5ec1..ec059846495 100644 --- a/applications/plugins/SofaEulerianFluid/Fluid3D.h +++ b/applications/plugins/SofaEulerianFluid/Fluid3D.h @@ -72,7 +72,7 @@ class SOFA_EULERIAN_FLUID_API Fluid3D : public sofa::core::BehaviorModel void reset() override; - void updatePosition(SReal dt) override; + void doUpdatePosition(SReal dt) override; void draw(const sofa::core::visual::VisualParams* vparams) override; diff --git a/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.cpp b/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.cpp index 161023261fc..f83c00e716a 100644 --- a/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.cpp +++ b/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.cpp @@ -60,7 +60,7 @@ void ComplianceMatrixExporter::doInit() } } -bool ComplianceMatrixExporter::write() +bool ComplianceMatrixExporter::doWrite() { if (l_constraintSolver) { diff --git a/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.h b/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.h index c66f6e032e8..2e9f6c75981 100644 --- a/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.h +++ b/applications/plugins/SofaMatrix/src/SofaMatrix/ComplianceMatrixExporter.h @@ -39,7 +39,7 @@ class SOFA_SOFAMATRIX_API ComplianceMatrixExporter : public sofa::simulation::Ba public: SOFA_CLASS(ComplianceMatrixExporter, sofa::simulation::BaseSimulationExporter); - bool write() override; + bool doWrite() override; void doInit() override; protected: diff --git a/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.cpp b/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.cpp index 6cb63aecfcc..e0655563eed 100644 --- a/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.cpp +++ b/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.cpp @@ -78,7 +78,7 @@ void GlobalSystemMatrixExporter::doInit() } } -bool GlobalSystemMatrixExporter::write() +bool GlobalSystemMatrixExporter::doWrite() { if (l_linearSystem) { diff --git a/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.h b/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.h index f695e0db89a..3518ac901d6 100644 --- a/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.h +++ b/applications/plugins/SofaMatrix/src/SofaMatrix/GlobalSystemMatrixExporter.h @@ -39,7 +39,7 @@ class SOFA_SOFAMATRIX_API GlobalSystemMatrixExporter : public sofa::simulation:: public: SOFA_CLASS(GlobalSystemMatrixExporter, sofa::simulation::BaseSimulationExporter); - bool write() override; + bool doWrite() override; void doInit() override; protected: