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

[WireRestShape] Clean code related to brokenIn2 and EdgeSetTopologyModifier #116

Merged
merged 5 commits into from
Nov 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions BeamAdapter_test/component/model/WireRestShape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ void WireRestShape_test::testParameterInit()
Real fullLength = wire->getLength();
EXPECT_EQ(fullLength, 100.0);

Real straightLength = wire->getReleaseCurvAbs();
EXPECT_EQ(straightLength, 95.0);

Real straightLength = 95.0;
vector<Real> keysPoints, keysPoints_ref = { 0, straightLength, fullLength };
Real ratio = straightLength / fullLength;
vector<int> nbP_density, nbP_density_ref = { int(floor(5.0 * ratio)), int(floor(20.0 * (1 - ratio))) };
Expand Down Expand Up @@ -243,7 +241,7 @@ void WireRestShape_test::testTransformMethods()
EXPECT_NE(wire, nullptr);

Real fullLength = wire->getLength();
Real straightLength = wire->getReleaseCurvAbs();
Real straightLength = 95.0;
Real middHook = (fullLength + straightLength) / 2;

Transform transfo_0, transfo_1, transfo_2, transfo_3;
Expand Down
30 changes: 15 additions & 15 deletions src/BeamAdapter/component/engine/WireRestShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
#include <BeamAdapter/utils/BeamSection.h>
#include <sofa/defaulttype/SolidTypes.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/component/topology/container/dynamic/EdgeSetTopologyModifier.h>
#include <sofa/component/topology/mapping/Edge2QuadTopologicalMapping.h>
#include <sofa/component/topology/container/dynamic/EdgeSetTopologyContainer.h>
#include <sofa/core/loader/MeshLoader.h>

namespace sofa::component::engine
Expand All @@ -47,8 +46,6 @@ namespace _wirerestshape_
{

using sofa::core::topology::TopologyContainer;
using sofa::component::topology::container::dynamic::EdgeSetTopologyModifier;
using sofa::component::topology::mapping::Edge2QuadTopologicalMapping;
using sofa::core::loader::MeshLoader;

/**
Expand Down Expand Up @@ -90,9 +87,6 @@ class WireRestShape : public core::objectmodel::BaseObject

/////////////////////////// Methods of WireRestShape //////////////////////////////////////////

/// For coils: a part of the coil instrument can be brokenIn2 (by default the point of release is the end of the straight length)
Real getReleaseCurvAbs() const {return d_straightLength.getValue();}

/// This function is called by the force field to evaluate the rest position of each beam
void getRestTransformOnX(Transform &global_H_local, const Real &x);

Expand Down Expand Up @@ -121,14 +115,23 @@ class WireRestShape : public core::objectmodel::BaseObject
void getCollisionSampling(Real &dx, const Real &x_curv) ;
void getNumberOfCollisionSegment(Real &dx, unsigned int &numLines) ;

//TODO(dmarchal 2017-05-17) Please specify who and when it will be done either a time after wich
//we can remove the todo.
// todo => topological change !
void releaseWirePart();

void rotateFrameForAlignX(const Quat &input, Vec3 &x, Quat &output);


/////////////////////////// Deprecated Methods //////////////////////////////////////////

/// For coils: a part of the coil instrument can be brokenIn2 (by default the point of release is the end of the straight length)
[[deprecated("Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06")]]
Real getReleaseCurvAbs() const {
msg_warning() << "Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06";
return 0.0;
}

[[deprecated("Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06")]]
void releaseWirePart() {
msg_warning() << "Releasing catheter or brokenIn2 mode is not anymore supported. Feature has been removed after release v23.06";
}

public:
/// Analitical creation of wire shape...
Data<bool> d_isAProceduralShape;
Expand Down Expand Up @@ -157,7 +160,6 @@ class WireRestShape : public core::objectmodel::BaseObject
Data<Real> d_massDensity2;

/// broken in 2 case
Data<bool> d_brokenIn2;
Data<bool> d_drawRestShape;

private:
Expand All @@ -174,8 +176,6 @@ class WireRestShape : public core::objectmodel::BaseObject
SingleLink<WireRestShape<DataTypes>, TopologyContainer, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_topology;
/// Pointer to the topology container, should be set using @sa l_topology, otherwise will search for one in current Node.
TopologyContainer* _topology{ nullptr };
/// Pointer to the topology modifier. Will be set at init by searching one in @sa _topology context.
EdgeSetTopologyModifier* edgeMod{ nullptr };

/// Link to be set to the topology container in the component graph.
SingleLink<WireRestShape<DataTypes>, MeshLoader, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_loader;
Expand Down
76 changes: 4 additions & 72 deletions src/BeamAdapter/component/engine/WireRestShape.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <BeamAdapter/component/engine/WireRestShape.h>

#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/component/topology/container/dynamic/QuadSetTopologyModifier.h>
#include <sofa/component/topology/mapping/Edge2QuadTopologicalMapping.h>

#include <sofa/simulation/TopologyChangeVisitor.h>
#include <sofa/core/visual/VisualParams.h>
Expand Down Expand Up @@ -79,7 +77,6 @@ WireRestShape<DataTypes>::WireRestShape() :
, d_innerRadius2(initData(&d_innerRadius2,(Real)0.0f,"innerRadiusExtremity","inner radius for beams at the extremity\nonly if not straight"))
, d_massDensity1(initData(&d_massDensity1,(Real)1.0,"massDensity", "Density of the mass (usually in kg/m^3)" ))
, d_massDensity2(initData(&d_massDensity2,(Real)1.0,"massDensityExtremity", "Density of the mass at the extremity\nonly if not straight" ))
, d_brokenIn2(initData(&d_brokenIn2, (bool)false, "brokenIn2", ""))
, d_drawRestShape(initData(&d_drawRestShape, (bool)false, "draw", "draw rest shape"))
, l_topology(initLink("topology", "link to the topology container"))
, l_loader(initLink("loader", "link to the MeshLoader"))
Expand Down Expand Up @@ -189,16 +186,7 @@ void WireRestShape<DataTypes>::init()
return;
}
}

// Get pointer to the topology Modifier (for topological changes)
_topology->getContext()->get(edgeMod);

if (edgeMod == nullptr)
{
msg_warning() << "No EdgeSetTopologyModifier found in the same node as the topology container: " << _topology->getName() << ". This wire won't support topological changes.";
}




////////////////////////////////////////////////////////
////////// keyPoint list and Density Assignement ///////
Expand Down Expand Up @@ -272,65 +260,12 @@ void WireRestShape<DataTypes>::init()
}


template <class DataTypes>
void WireRestShape<DataTypes>::releaseWirePart(){

d_brokenIn2.setValue(true);

if ( edgeMod == nullptr )
{
msg_error() << "no edgeSetModifier in the node -> cannot do the topological change";
return;
}
///////// remove the edge that is cut //////
for ( sofa::Size i=0; i<_topology->getNbPoints(); i++)
{
if( _topology->getPX(i) > this->getReleaseCurvAbs() + EPSILON )
{
type::vector<sofa::core::topology::BaseMeshTopology::EdgeID> edge_remove;
edge_remove.push_back( i-1 );

msg_info() << "releaseWirePart() -> remove edge number "<< i ;

edgeMod->removeEdges(edge_remove,false); // remove the single edge and do not remove any point...

msg_info() << "WireRestShape _topology name="<<_topology->getName()<<" - numEdges ="<<_topology->getNbEdges() ;

return;
}
}

dmsg_info() <<" Wire Part is brokenIn2... should implement a topo change !" ;
}


template <class DataTypes>
void WireRestShape<DataTypes>::getSamplingParameters(type::vector<Real>& xP_noticeable,
type::vector<int>& nbP_density) const
{

xP_noticeable.clear();
nbP_density.clear();

if (d_brokenIn2.getValue())
{
for (unsigned int i=0; i<d_keyPoints.getValue().size(); i++)
{
Real x=d_keyPoints.getValue()[i];
if( x + EPSILON > getReleaseCurvAbs() )
break;
xP_noticeable.push_back(x);
nbP_density.push_back(d_density.getValue()[i]);
}
xP_noticeable.push_back( getReleaseCurvAbs());

dmsg_info() <<"getSamplingParameters brokenIn2 detected - return xP_noticeable ="<<xP_noticeable<<" and nbP_density ="<<nbP_density ;
}
else
{
xP_noticeable = d_keyPoints.getValue();
nbP_density = d_density.getValue();
}
xP_noticeable = d_keyPoints.getValue();
nbP_density = d_density.getValue();
}

template <class DataTypes>
Expand Down Expand Up @@ -775,10 +710,7 @@ void WireRestShape<DataTypes>::getRestPosNonProcedural(Real& abs, Coord &p)
template <class DataTypes>
typename WireRestShape<DataTypes>::Real WireRestShape<DataTypes>::getLength()
{
if(d_brokenIn2.getValue())
return d_straightLength.getValue();
else
return d_length.getValue();
return d_length.getValue();
}

template <class DataTypes>
Expand Down