|
28 | 28 | #include <sofa/core/VecId.h> |
29 | 29 | #include <sofa/core/topology/BaseMeshTopology.h> |
30 | 30 | #include <sofa/core/behavior/MechanicalState.h> |
| 31 | +#include <sofa/core/behavior/SingleStateAccessor.h> |
| 32 | +#include <sofa/core/behavior/TopologyAccessor.h> |
31 | 33 |
|
32 | 34 | namespace sofa::component::collision::geometry |
33 | 35 | { |
@@ -102,10 +104,16 @@ using Triangle = TTriangle<sofa::defaulttype::Vec3Types>; |
102 | 104 | * The class \sa TTriangle is used to access specific triangle of this collision Model. |
103 | 105 | */ |
104 | 106 | template<class TDataTypes> |
105 | | -class TriangleCollisionModel : public core::CollisionModel |
| 107 | +class TriangleCollisionModel : |
| 108 | + public core::CollisionModel, |
| 109 | + public virtual core::behavior::SingleStateAccessor<TDataTypes>, |
| 110 | + public virtual core::behavior::TopologyAccessor |
106 | 111 | { |
107 | 112 | public: |
108 | | - SOFA_CLASS(SOFA_TEMPLATE(TriangleCollisionModel, TDataTypes), core::CollisionModel); |
| 113 | + SOFA_CLASS3(SOFA_TEMPLATE(TriangleCollisionModel, TDataTypes), |
| 114 | + core::CollisionModel, |
| 115 | + core::behavior::SingleStateAccessor<TDataTypes>, |
| 116 | + core::behavior::TopologyAccessor); |
109 | 117 |
|
110 | 118 | typedef TDataTypes DataTypes; |
111 | 119 | typedef DataTypes InDataTypes; |
@@ -138,13 +146,10 @@ class TriangleCollisionModel : public core::CollisionModel |
138 | 146 | Data<bool> d_bothSide; ///< activate collision on both side of the triangle model |
139 | 147 | Data<bool> d_computeNormals; ///< set to false to disable computation of triangles normal |
140 | 148 | Data<bool> d_useCurvature; ///< use the curvature of the mesh to avoid some self-intersection test |
141 | | - |
142 | | - /// Link to be set to the topology container in the component graph. |
143 | | - SingleLink<TriangleCollisionModel<DataTypes>, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology; |
144 | 149 |
|
145 | 150 | protected: |
146 | | - core::behavior::MechanicalState<DataTypes>* m_mstate; ///< Pointer to the corresponding MechanicalState |
147 | | - sofa::core::topology::BaseMeshTopology* m_topology; ///< Pointer to the corresponding Topology |
| 151 | + using sofa::core::behavior::SingleStateAccessor<TDataTypes>::mstate; |
| 152 | + using sofa::core::behavior::TopologyAccessor::l_topology; |
148 | 153 |
|
149 | 154 | VecDeriv m_normals; ///< Vector of normal direction per triangle. |
150 | 155 |
|
@@ -185,8 +190,8 @@ class TriangleCollisionModel : public core::CollisionModel |
185 | 190 |
|
186 | 191 | bool canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2) override; |
187 | 192 |
|
188 | | - core::behavior::MechanicalState<DataTypes>* getMechanicalState() { return m_mstate; } |
189 | | - const core::behavior::MechanicalState<DataTypes>* getMechanicalState() const { return m_mstate; } |
| 193 | + core::behavior::MechanicalState<DataTypes>* getMechanicalState() { return mstate; } |
| 194 | + const core::behavior::MechanicalState<DataTypes>* getMechanicalState() const { return mstate; } |
190 | 195 |
|
191 | 196 | const VecCoord& getX() const { return(getMechanicalState()->read(core::vec_id::read_access::position)->getValue()); } |
192 | 197 | const sofa::core::topology::BaseMeshTopology::SeqTriangles& getTriangles() const { return *m_triangles; } |
|
0 commit comments