Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 << ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<core::CollisionElementIterator,core::CollisionElementIterator> getInternalChildren(sofa::Index index) const override;

std::pair<core::CollisionElementIterator,core::CollisionElementIterator> getExternalChildren(sofa::Index index) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class CylinderCollisionModel : public core::CollisionModel
CylinderCollisionModel();
CylinderCollisionModel(core::behavior::MechanicalState<DataTypes>* 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ CylinderCollisionModel<DataTypes>::CylinderCollisionModel(core::behavior::Mechan
}

template<class DataTypes>
void CylinderCollisionModel<DataTypes>::resize(sofa::Size size)
void CylinderCollisionModel<DataTypes>::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();
Expand Down Expand Up @@ -115,7 +115,7 @@ void CylinderCollisionModel<DataTypes>::init()


template<class DataTypes>
void CylinderCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
void CylinderCollisionModel<DataTypes>::doComputeBoundingTree(int maxDepth)
{
using namespace sofa::type;
using namespace sofa::defaulttype;
Expand All @@ -125,6 +125,7 @@ void CylinderCollisionModel<DataTypes>::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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DataTypes>* getMechanicalState() { return mstate; }

Deriv velocity(sofa::Index index)const;
Expand All @@ -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<bool> d_displayFreePosition; ///< Display Collision Model Points free position(in green)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ LineCollisionModel<DataTypes>::LineCollisionModel()


template<class DataTypes>
void LineCollisionModel<DataTypes>::resize(sofa::Size size)
void LineCollisionModel<DataTypes>::doResize(sofa::Size size)
{
this->core::CollisionModel::resize(size);
this->core::CollisionModel::doResize(size);
elems.resize(size);
}

Expand Down Expand Up @@ -354,7 +354,7 @@ void LineCollisionModel<DataTypes>::drawCollisionModel(const core::visual::Visua
}

template<class DataTypes>
bool LineCollisionModel<DataTypes>::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2)
bool LineCollisionModel<DataTypes>::doCanCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2)
{
if (!this->bSelfCollision.getValue()) return true;
if (this->getContext() != model2->getContext()) return true;
Expand Down Expand Up @@ -458,7 +458,7 @@ bool LineCollisionModel<DataTypes>::canCollideWithElement(sofa::Index index, Col
}

template<class DataTypes>
void LineCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
void LineCollisionModel<DataTypes>::doComputeBoundingTree(int maxDepth)
{
CubeCollisionModel* cubeModel = createPrevious<CubeCollisionModel>();
updateFromTopology();
Expand Down Expand Up @@ -495,7 +495,7 @@ void LineCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
}

template<class DataTypes>
void LineCollisionModel<DataTypes>::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth)
void LineCollisionModel<DataTypes>::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth)
{
CubeCollisionModel* cubeModel = createPrevious<CubeCollisionModel>();
updateFromTopology();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataTypes>* getMechanicalState() { return mstate; }

Deriv getNormal(sofa::Index index){ return (normals.size()) ? normals[index] : Deriv();}
Expand All @@ -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<DataTypes>* mstate;
Expand All @@ -139,6 +124,18 @@ class PointCollisionModel : public core::CollisionModel
/// Link to be set to the topology container in the component graph.
SingleLink<PointCollisionModel<DataTypes>, 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();
}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ PointCollisionModel<DataTypes>::PointCollisionModel()
enum_type = POINT_TYPE;
}

template<class DataTypes>
void PointCollisionModel<DataTypes>::resize(sofa::Size size)
{
this->core::CollisionModel::resize(size);
}

template<class DataTypes>
void PointCollisionModel<DataTypes>::init()
{
Expand All @@ -74,7 +68,7 @@ void PointCollisionModel<DataTypes>::init()


template<class DataTypes>
bool PointCollisionModel<DataTypes>::canCollideWithElement(sofa::Index index, CollisionModel* model2, sofa::Index index2)
bool PointCollisionModel<DataTypes>::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.
Expand Down Expand Up @@ -112,13 +106,14 @@ bool PointCollisionModel<DataTypes>::canCollideWithElement(sofa::Index index, Co
}

template<class DataTypes>
void PointCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
void PointCollisionModel<DataTypes>::doComputeBoundingTree(int maxDepth)
{
CubeCollisionModel* cubeModel = createPrevious<CubeCollisionModel>();
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;
}
Expand All @@ -143,13 +138,14 @@ void PointCollisionModel<DataTypes>::computeBoundingTree(int maxDepth)
}

template<class DataTypes>
void PointCollisionModel<DataTypes>::computeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag , int maxDepth)
void PointCollisionModel<DataTypes>::doComputeContinuousBoundingTree(SReal dt, ContinuousIntersectionTypeFlag continuousIntersectionFlag, int maxDepth)
{
CubeCollisionModel* cubeModel = createPrevious<CubeCollisionModel>();
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<CubeCollisionModel>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading
Loading