-
Notifications
You must be signed in to change notification settings - Fork 342
[Collision] Introduce multi-staged collision pipeline #5841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4ff09ae
8b7f411
21ed455
18cdb3b
e2bf69b
c292b34
90416bd
2a85d64
fed32d2
d1371d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /****************************************************************************** | ||
| * 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 <http://www.gnu.org/licenses/>. * | ||
| ******************************************************************************* | ||
| * Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
| * * | ||
| * Contact information: [email protected] * | ||
| ******************************************************************************/ | ||
| #pragma once | ||
| #include <sofa/component/collision/detection/algorithm/config.h> | ||
|
|
||
| #include <sofa/core/objectmodel/BaseObject.h> | ||
|
|
||
| #include <sofa/core/CollisionModel.h> | ||
| #include <sofa/core/collision/ContactManager.h> | ||
| #include <sofa/core/collision/Intersection.h> | ||
|
|
||
| #include <sofa/core/visual/VisualParams.h> | ||
|
|
||
| #include <set> | ||
| #include <string> | ||
|
|
||
| namespace sofa::component::collision::detection::algorithm | ||
| { | ||
|
|
||
| class SOFA_COMPONENT_COLLISION_DETECTION_ALGORITHM_API AbstractSubCollisionPipeline : public sofa::core::objectmodel::BaseObject | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to document this class? Also the main virtual functions. Thanks
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this class be named |
||
| { | ||
| public: | ||
| SOFA_ABSTRACT_CLASS(AbstractSubCollisionPipeline, sofa::core::objectmodel::BaseObject); | ||
|
|
||
| virtual void computeCollisionReset() = 0; | ||
| virtual void computeCollisionDetection() = 0; | ||
| virtual void computeCollisionResponse() = 0; | ||
| virtual void doInit() = 0; | ||
| virtual void doBwdInit() {} | ||
| virtual void doHandleEvent(sofa::core::objectmodel::Event* e) = 0; | ||
|
Comment on lines
+47
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be protected |
||
|
|
||
| virtual void doDraw(const core::visual::VisualParams*) {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be protected |
||
|
|
||
| AbstractSubCollisionPipeline() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be protected. |
||
| : sofa::core::objectmodel::BaseObject() | ||
| , l_collisionModels(initLink("collisionModels", "List of collision models to consider in this pipeline")) | ||
| , l_intersectionMethod(initLink("intersectionMethod", "Intersection method to use in this pipeline")) | ||
| , l_contactManager(initLink("contactManager", "Contact manager to use in this pipeline")) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| void init() override final | ||
| { | ||
| bool validity = true; | ||
|
|
||
| this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid); | ||
|
|
||
| //Check given parameters | ||
| if (l_collisionModels.size() == 0) | ||
| { | ||
| msg_warning() << "At least one CollisionModel is required to compute collision detection."; | ||
| validity = false; | ||
| } | ||
|
|
||
| if (!l_intersectionMethod) | ||
| { | ||
| msg_warning() << "An Intersection detection component is required to compute collision detection."; | ||
| validity = false; | ||
| } | ||
|
|
||
| if (!l_contactManager) | ||
| { | ||
| msg_warning() << "A contact manager component is required to compute collision detection."; | ||
| validity = false; | ||
| } | ||
|
|
||
| if (validity) | ||
| { | ||
| this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid); | ||
| } | ||
|
|
||
| doInit(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call |
||
| } | ||
|
|
||
| static std::set< std::string > getResponseList() | ||
| { | ||
| std::set< std::string > listResponse; | ||
| core::collision::Contact::Factory::iterator it; | ||
| for (it = core::collision::Contact::Factory::getInstance()->begin(); it != core::collision::Contact::Factory::getInstance()->end(); ++it) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A range-based for loop with structured bindings would be preferable here. |
||
| { | ||
| listResponse.insert(it->first); | ||
| } | ||
| return listResponse; | ||
| } | ||
|
|
||
| void draw(const core::visual::VisualParams* vparams) override final | ||
| { | ||
| const auto stateLifeCycle = vparams->drawTool()->makeStateLifeCycle(); | ||
|
|
||
| doDraw(vparams); | ||
| } | ||
|
|
||
| void handleEvent(sofa::core::objectmodel::Event* e) override final | ||
| { | ||
| doHandleEvent(e); | ||
| } | ||
|
|
||
| sofa::MultiLink < AbstractSubCollisionPipeline, sofa::core::CollisionModel, sofa::BaseLink::FLAG_DUPLICATE > l_collisionModels; | ||
| sofa::SingleLink< AbstractSubCollisionPipeline, sofa::core::collision::Intersection, sofa::BaseLink::FLAG_STOREPATH | sofa::BaseLink::FLAG_STRONGLINK > l_intersectionMethod; | ||
| sofa::SingleLink< AbstractSubCollisionPipeline, sofa::core::collision::ContactManager, sofa::BaseLink::FLAG_STOREPATH | sofa::BaseLink::FLAG_STRONGLINK > l_contactManager; | ||
| }; | ||
|
|
||
| } // namespace sofa::component::collision::detection::algorithm | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementations of the methods can be in a cpp file.