Skip to content
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

[SofaBaseCollision] CLEAN CylinderModel #847

Merged
merged 3 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions SofaKernel/modules/SofaBaseCollision/CylinderModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,28 @@ using namespace sofa::defaulttype;
using namespace sofa::core::collision;
using namespace helper;

int RigidCylinderModelClass = core::RegisterObject("Collision model which represents a set of rigid cylinders")
static int RigidCylinderModelClass = core::RegisterObject("Collision model which represents a set of rigid cylinders")
epernod marked this conversation as resolved.
Show resolved Hide resolved
#ifndef SOFA_FLOAT
.add< TCylinderModel<defaulttype::Rigid3dTypes> >()
.add< TCylinderModel<Rigid3dTypes> >()
#endif
#ifndef SOFA_DOUBLE
.add < TCylinderModel<defaulttype::Rigid3fTypes> >()
.add < TCylinderModel<Rigid3fTypes> >()
#endif
//TODO(dmarchal): Fix deprecated management...
.addAlias("Cylinder")
.addAlias("CylinderModel")
//.addAlias("CylinderMesh")
//.addAlias("CylinderSet")
;

#ifndef SOFA_FLOAT
template class SOFA_BASE_COLLISION_API TCylinder<defaulttype::Rigid3dTypes>;
template class SOFA_BASE_COLLISION_API TCylinderModel<defaulttype::Rigid3dTypes>;
template class SOFA_BASE_COLLISION_API TCylinder<Rigid3dTypes>;
template class SOFA_BASE_COLLISION_API TCylinderModel<Rigid3dTypes>;
#endif
#ifndef SOFA_DOUBLE
template class SOFA_BASE_COLLISION_API TCylinder<defaulttype::Rigid3fTypes>;
template class SOFA_BASE_COLLISION_API TCylinderModel<defaulttype::Rigid3fTypes>;
template class SOFA_BASE_COLLISION_API TCylinder<Rigid3fTypes>;
template class SOFA_BASE_COLLISION_API TCylinderModel<Rigid3fTypes>;
#endif




}
}
}
65 changes: 26 additions & 39 deletions SofaKernel/modules/SofaBaseCollision/CylinderModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class TCylinder;
*A Cylinder can be viewed as a segment with a radius, here the segment is
*defined by its apexes.
*/
template< class MyReal>
class TCylinder<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core::TCollisionElementIterator< TCylinderModel<sofa::defaulttype::StdRigidTypes<3,MyReal> > >
template< class TDataTypes>
class TCylinder: public core::TCollisionElementIterator< TCylinderModel< TDataTypes > >
{
public:
typedef sofa::defaulttype::StdRigidTypes<3,MyReal> DataTypes;
typedef TDataTypes DataTypes;
typedef typename DataTypes::Real Real;
typedef typename DataTypes::Deriv Deriv;
typedef typename DataTypes::CPos Coord;
typedef typename TDataTypes::CPos Coord;
typedef typename TDataTypes::Deriv Deriv;
typedef typename DataTypes::VecCoord VecCoord;

typedef TCylinderModel<DataTypes> ParentModel;
Expand All @@ -76,14 +76,13 @@ class TCylinder<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core::TCol
/**
*CylinderModel templated by RigidTypes (frames), direction is given by Y direction of the frame.
*/
template< class MyReal>
class TCylinderModel<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core::CollisionModel
template< class TDataTypes>
class TCylinderModel : public core::CollisionModel
{
public:
SOFA_CLASS(SOFA_TEMPLATE(TCylinderModel, SOFA_TEMPLATE2(sofa::defaulttype::StdRigidTypes, 3, MyReal)), core::CollisionModel);

SOFA_CLASS(SOFA_TEMPLATE(TCylinderModel, TDataTypes), core::CollisionModel);

typedef sofa::defaulttype::StdRigidTypes<3,MyReal> DataTypes;
typedef TDataTypes DataTypes;
typedef DataTypes InDataTypes;
typedef typename DataTypes::VecCoord VecCoord;
typedef typename DataTypes::VecDeriv VecDeriv;
Expand All @@ -95,34 +94,33 @@ class TCylinderModel<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core:

typedef TCylinder<DataTypes> Element;
friend class TCylinder<DataTypes>;
protected:
Data<VecReal> _cylinder_radii; ///< Radius of each cylinder
Data<VecReal> _cylinder_heights; ///< The cylinder heights
Data<VecAxisCoord> _cylinder_local_axes;

Data<Real> _default_radius; ///< The default radius
Data<Real> _default_height; ///< The default height
Data<Coord> _default_local_axis; ///< The default local axis cylinder is modeled around
Data<VecReal> d_cylinder_radii; ///< Radius of each cylinder
Data<VecReal> d_cylinder_heights; ///< The cylinder heights
Data<VecAxisCoord> d_cylinder_local_axes;

Data<Real> d_default_radius; ///< The default radius
Data<Real> d_default_height; ///< The default height
Data<Coord> d_default_local_axis; ///< The default local axis cylinder is modeled around

protected:
TCylinderModel();
TCylinderModel(core::behavior::MechanicalState<DataTypes>* mstate );

public:
virtual void init() override;

// -- CollisionModel interface

virtual void resize(int size) override;

virtual void computeBoundingTree(int maxDepth=0) override;

//virtual void computeContinuousBoundingTree(SReal dt, int maxDepth=0);

void draw(const core::visual::VisualParams* vparams,int index) override;

void draw(const core::visual::VisualParams* vparams) override;


core::behavior::MechanicalState<DataTypes>* getMechanicalState() { return _mstate; }
core::behavior::MechanicalState<DataTypes>* getMechanicalState() { return m_mstate; }

Real radius(int index) const;

Expand All @@ -145,17 +143,6 @@ class TCylinderModel<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core:

const Coord & velocity(int index)const;

/// Pre-construction check method called by ObjectFactory.
/// Check that DataTypes matches the MechanicalState.
template<class T>
static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
{
if (dynamic_cast<core::behavior::MechanicalState<DataTypes>*>(context->getMechanicalState()) == NULL && context->getMechanicalState() != NULL)
return false;

return BaseObject::canCreate(obj, context, arg);
}

virtual std::string getTemplateName() const override
{
return templateName(this);
Expand All @@ -171,25 +158,26 @@ class TCylinderModel<sofa::defaulttype::StdRigidTypes<3,MyReal> > : public core:
Data<VecAxisCoord>& writeLocalAxes();

protected:
core::behavior::MechanicalState<DataTypes>* _mstate;
core::behavior::MechanicalState<DataTypes>* m_mstate;
};


template<class MyReal>
inline TCylinder<sofa::defaulttype::StdRigidTypes<3,MyReal> >::TCylinder(ParentModel* model, int index)
template<class DataTypes>
inline TCylinder<DataTypes>::TCylinder(ParentModel* model, int index)
: core::TCollisionElementIterator<ParentModel>(model, index)
{}

template<class MyReal>
inline TCylinder<sofa::defaulttype::StdRigidTypes<3,MyReal> >::TCylinder(const core::CollisionElementIterator& i)
template<class DataTypes>
inline TCylinder<DataTypes>::TCylinder(const core::CollisionElementIterator& i)
: core::TCollisionElementIterator<ParentModel>(static_cast<ParentModel*>(i.getCollisionModel()), i.getIndex())
{
}


typedef TCylinderModel<sofa::defaulttype::Rigid3Types> CylinderModel;
typedef TCylinder<sofa::defaulttype::Rigid3Types> Cylinder;

#if !defined(SOFA_COMPONENT_COLLISION_CYLINDERMODEL_CPP)
#if !defined(SOFA_COMPONENT_COLLISION_CYLINDERMODEL_CPP)
#ifndef SOFA_FLOAT
extern template class SOFA_BASE_COLLISION_API TCylinder<defaulttype::Rigid3dTypes>;
extern template class SOFA_BASE_COLLISION_API TCylinderModel<defaulttype::Rigid3dTypes>;
Expand All @@ -199,7 +187,6 @@ extern template class SOFA_BASE_COLLISION_API TCylinder<defaulttype::Rigid3fType
extern template class SOFA_BASE_COLLISION_API TCylinderModel<defaulttype::Rigid3fTypes>;
#endif
#endif

} // namespace collision

} // namespace component
Expand Down
Loading