|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <sofa/collisionAlgorithm/BaseElement.h> |
| 4 | +#include <sofa/collisionAlgorithm/BaseOperation.h> |
| 5 | + |
| 6 | +namespace sofa::collisionAlgorithm::Operations::ContainsPointInElement |
| 7 | +{ |
| 8 | + |
| 9 | +typedef bool Result; |
| 10 | + |
| 11 | +class Operation : public GenericOperation<Operation, // Type of the operation |
| 12 | + Result, // Default return type |
| 13 | + const type::Vec3&, const BaseElement::SPtr& // Parameters |
| 14 | + > |
| 15 | +{ |
| 16 | + public: |
| 17 | + Result defaultFunc(const type::Vec3&, const BaseElement::SPtr&) const override { return false; } |
| 18 | + |
| 19 | + void notFound(const std::type_info& id) const override |
| 20 | + { |
| 21 | + msg_error("ContainsPointInElement") |
| 22 | + << "The operation ContainsPointInElementOperation is not registered with for type = " |
| 23 | + << sofa::helper::NameDecoder::decodeFullName(id); |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +typedef Operation::FUNC FUNC; |
| 28 | + |
| 29 | +} // namespace sofa::collisionAlgorithm::Operations::ContainsPointInElement |
| 30 | + |
| 31 | +namespace sofa::collisionAlgorithm::Operations::ContainsPointInProximity |
| 32 | +{ |
| 33 | + |
| 34 | +typedef bool Result; |
| 35 | + |
| 36 | +class Operation |
| 37 | + : public GenericOperation<Operation, // Type of the operation |
| 38 | + Result, // Default return type |
| 39 | + const type::Vec3&, const BaseProximity::SPtr& // Parameters |
| 40 | + > |
| 41 | +{ |
| 42 | + public: |
| 43 | + Result defaultFunc(const type::Vec3&, const BaseProximity::SPtr&) const override |
| 44 | + { |
| 45 | + return false; |
| 46 | + } |
| 47 | + |
| 48 | + void notFound(const std::type_info& id) const override |
| 49 | + { |
| 50 | + msg_error("ContainsPointInProximity") |
| 51 | + << "The operation ContainsPointInProximityOperation is not registered with for type = " |
| 52 | + << sofa::helper::NameDecoder::decodeFullName(id); |
| 53 | + } |
| 54 | +}; |
| 55 | + |
| 56 | +template <typename PROX> |
| 57 | +Result containsPoint(const type::Vec3& P, const typename std::shared_ptr<PROX>& prox) |
| 58 | +{ |
| 59 | + if (!prox) |
| 60 | + { |
| 61 | + msg_warning("ContainsPointInProximity") << "Null proximity pointer in containsPoint" |
| 62 | + << "Operation is disabled; returning false"; |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + auto elem = prox->element(); |
| 67 | + auto containsPointInElem = |
| 68 | + sofa::collisionAlgorithm::Operations::ContainsPointInElement::Operation::get(elem); |
| 69 | + return containsPointInElem(P, elem); |
| 70 | +} |
| 71 | + |
| 72 | +typedef Operation::FUNC FUNC; |
| 73 | + |
| 74 | +} // namespace sofa::collisionAlgorithm::Operations::ContainsPointInProximity |
0 commit comments