Skip to content

Commit

Permalink
Merge branch 'BeamMaterial' into dev_LnRobotics
Browse files Browse the repository at this point in the history
  • Loading branch information
epernod committed Jun 30, 2023
2 parents 255d72c + c6c7d21 commit a424fa8
Show file tree
Hide file tree
Showing 22 changed files with 1,283 additions and 725 deletions.
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ set(HEADER_FILES
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.h
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.inl

${BEAMADAPTER_SRC}/component/model/BaseRodSectionMaterial.h
${BEAMADAPTER_SRC}/component/model/BaseRodSectionMaterial.inl
${BEAMADAPTER_SRC}/component/model/RodMeshSection.h
${BEAMADAPTER_SRC}/component/model/RodMeshSection.inl
${BEAMADAPTER_SRC}/component/model/RodSpireSection.h
${BEAMADAPTER_SRC}/component/model/RodSpireSection.inl
${BEAMADAPTER_SRC}/component/model/RodStraightSection.h
${BEAMADAPTER_SRC}/component/model/RodStraightSection.inl

${BEAMADAPTER_SRC}/utils/BeamSection.h
${BEAMADAPTER_SRC}/utils/BeamActions.h
${BEAMADAPTER_SRC}/utils/deprecatedcomponent.h
)
)

set(SOURCE_FILES
${BEAMADAPTER_SRC}/initBeamAdapter.cpp
Expand All @@ -86,7 +95,11 @@ set(SOURCE_FILES
${BEAMADAPTER_SRC}/component/mapping/AdaptiveBeamMapping.cpp
${BEAMADAPTER_SRC}/component/mapping/BeamLengthMapping.cpp
${BEAMADAPTER_SRC}/component/mapping/MultiAdaptiveBeamMapping.cpp
)

${BEAMADAPTER_SRC}/component/model/RodMeshSection.cpp
${BEAMADAPTER_SRC}/component/model/RodSpireSection.cpp
${BEAMADAPTER_SRC}/component/model/RodStraightSection.cpp
)

if(SofaImplicitField_FOUND)
set(HEADER_FILES ${HEADER_FILES}
Expand Down
23 changes: 16 additions & 7 deletions examples/3instruments.scn
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,34 @@
<!-- ------------------------- INTERVENTIONAL RADIOLOGY INSTRUMENTS (catheter, guidewire, coil) ------------------------------ -->

<Node name='topoLines_cath'>
<WireRestShape template='Rigid3d' printLog='0' name='catheterRestShape' length='1000.0' straightLength='600' spireDiameter='4000.0' spireHeight='0.0'
densityOfBeams='40 10' numEdges='200' numEdgesCollis='40 20' youngModulus='10000' youngModulusExtremity='10000'/> <!-- silicone -->
<RodStraightSection name="StraightSection" youngModulus="10000" nbEdgesCollis="40" nbEdgesVisu="120" length="600.0"/>
<RodSpireSection name="SpireSection" youngModulus="10000" nbEdgesCollis="20" nbEdgesVisu="80" length="400.0" spireDiameter="4000.0" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="catheterRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name='meshLinesCath' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
<MechanicalObject template='Rigid3d' name='dofTopo1' />
</Node>
<Node name='topoLines_guide'>
<WireRestShape template='Rigid3d' printLog='0' name='GuideRestShape' length='1000.0' straightLength='980.0' spireDiameter='25' spireHeight='0.0'
densityOfBeams='30 5' numEdges='200' numEdgesCollis='50 10' youngModulus='10000' youngModulusExtremity='10000'/>
<RodStraightSection name="StraightSection" youngModulus="10000" nbEdgesCollis="50" nbEdgesVisu="196" length="980.0"/>
<RodSpireSection name="SpireSection" youngModulus="10000" nbEdgesCollis="10" nbEdgesVisu="4" length="20.0" spireDiameter="25" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="GuideRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name='meshLinesGuide' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
<MechanicalObject template='Rigid3d' name='dofTopo2' />
</Node>
<Node name='topoLines_coils'>
<WireRestShape template='Rigid3d' printLog='0' name='CoilRestShape' length='600.0' straightLength='540.0' spireDiameter='7' spireHeight='5.0'
densityOfBeams='40 20' numEdges='400' numEdgesCollis='30 30' youngModulus='168000' youngModulusExtremity='168000'/>
<EdgeSetTopologyContainer name='meshLinesCoils' />
<RodStraightSection name="StraightSection" youngModulus="168000" nbEdgesCollis="30" nbEdgesVisu="360" length="540.0"/>
<RodSpireSection name="SpireSection" youngModulus="168000" nbEdgesCollis="30" nbEdgesVisu="40" length="60.0" spireDiameter="7" spireHeight="5.0"/>

<WireRestShape template="Rigid3d" name="CoilRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name='meshLinesCoils' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
<MechanicalObject template='Rigid3d' name='dofTopo3' />
Expand Down
21 changes: 15 additions & 6 deletions examples/3instruments_collis.scn
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,33 @@
<!-- ------------------------- INTERVENTIONAL RADIOLOGY INSTRUMENTS (catheter, guidewire, coil) ------------------------------ -->

<Node name='topoLines_cath'>
<WireRestShape template='Rigid3d' printLog='0' name='catheterRestShape' length='1000.0' straightLength='600' spireDiameter='4000.0' spireHeight='0.0'
densityOfBeams='40 10' numEdges='200' numEdgesCollis='40 20' youngModulus='10000' youngModulusExtremity='10000'/> <!-- silicone -->
<RodStraightSection name="StraightSection" youngModulus="10000" nbEdgesCollis="40" nbEdgesVisu="120" length="600.0"/>
<RodSpireSection name="SpireSection" youngModulus="10000" nbEdgesCollis="20" nbEdgesVisu="80" length="400.0" spireDiameter="4000.0" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="catheterRestShape" wireMaterials="@StraightSection @SpireSection"/> <!-- silicone -->

<EdgeSetTopologyContainer name='meshLinesCath' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
<MechanicalObject template='Rigid3d' name='dofTopo1' />
</Node>
<Node name='topoLines_guide'>
<WireRestShape template='Rigid3d' printLog='0' name='GuideRestShape' length='1000.0' straightLength='980.0' spireDiameter='25' spireHeight='0.0'
densityOfBeams='30 5' numEdges='200' numEdgesCollis='50 10' youngModulus='10000' youngModulusExtremity='10000'/>
<RodStraightSection name="StraightSection" youngModulus="10000" nbEdgesCollis="50" nbEdgesVisu="196" length="980.0"/>
<RodSpireSection name="SpireSection" youngModulus="10000" nbEdgesCollis="10" nbEdgesVisu="4" length="20.0" spireDiameter="25" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="GuideRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name='meshLinesGuide' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
<MechanicalObject template='Rigid3d' name='dofTopo2' />
</Node>
<Node name='topoLines_coils'>
<WireRestShape template='Rigid3d' printLog='0' name='CoilRestShape' length='600.0' straightLength='540.0' spireDiameter='7' spireHeight='5.0'
densityOfBeams='40 20' numEdges='400' numEdgesCollis='30 30' youngModulus='168000' youngModulusExtremity='168000'/>
<RodStraightSection name="StraightSection" youngModulus="168000" nbEdgesCollis="30" nbEdgesVisu="360" length="540.0"/>
<RodSpireSection name="SpireSection" youngModulus="168000" nbEdgesCollis="30" nbEdgesVisu="40" length="60.0" spireDiameter="7" spireHeight="5.0"/>

<WireRestShape template="Rigid3d" name="CoilRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name='meshLinesCoils' />
<EdgeSetTopologyModifier name='Modifier' />
<EdgeSetGeometryAlgorithms name='GeomAlgo' template='Rigid3d' />
Expand Down
9 changes: 4 additions & 5 deletions examples/SingleBeamDeployment.scn
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
<DefaultVisualManagerLoop />

<Node name="EdgeTopology">
<WireRestShape name="BeamRestShape" straightLength="980.0" length="1000.0"
numEdges="200" youngModulus="20000"
spireDiameter="25" numEdgesCollis="50 10"
printLog="1" template="Rigid3d" spireHeight="0.0"
densityOfBeams="30 5" youngModulusExtremity="20000" />
<RodStraightSection name="StraightSection" youngModulus="20000" radius="1" massDensity="0.1" poissonRatio="0.3" nbEdgesCollis="30" nbEdgesVisu="196" length="980.0"/>
<RodSpireSection name="SpireSection" youngModulus="20000" radius="1" massDensity="0.1" poissonRatio="0.3" nbEdgesCollis="5" nbEdgesVisu="4" length="20.0" spireDiameter="25" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="BeamRestShape" printLog="1" wireMaterials="@StraightSection @SpireSection"/>
<EdgeSetTopologyContainer name="meshLinesBeam"/>
<EdgeSetTopologyModifier name="Modifier"/>
<EdgeSetGeometryAlgorithms name="GeomAlgo" template="Rigid3d" />
Expand Down
10 changes: 5 additions & 5 deletions examples/SingleBeamDeploymentCollision.scn
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@


<Node name="EdgeTopology">
<WireRestShape name="BeamRestShape" straightLength="980.0" length="1000.0"
numEdges="200" youngModulus="20000"
spireDiameter="25" numEdgesCollis="50 10"
printLog="1" template="Rigid3d" spireHeight="0.0"
densityOfBeams="30 5" youngModulusExtremity="20000" />
<RodStraightSection name="StraightSection" youngModulus="20000" radius="1" massDensity="0.1" poissonRatio="0.3" nbEdgesCollis="50" nbEdgesVisu="200" length="980.0"/>
<RodSpireSection name="SpireSection" youngModulus="20000" radius="1" massDensity="0.1" poissonRatio="0.3" nbEdgesCollis="10" nbEdgesVisu="200" length="20.0" spireDiameter="25" spireHeight="0.0"/>

<WireRestShape template="Rigid3d" name="BeamRestShape" wireMaterials="@StraightSection @SpireSection"/>

<EdgeSetTopologyContainer name="meshLinesBeam"/>
<EdgeSetTopologyModifier name="Modifier"/>
<EdgeSetGeometryAlgorithms name="GeomAlgo" template="Rigid3d" />
Expand Down
11 changes: 6 additions & 5 deletions examples/Tool_from_loader.scn
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
<DefaultAnimationLoop />

<Node name="GuideCatheter">
<MeshObjLoader name="loader" filename="mesh/key_tip.obj" />
<WireRestShape template="Rigid3d" name="GC_RestShape" printLog="false" isAProceduralShape="false"
radius="10" massDensity="0.1" poissonRatio="0.3"
densityOfBeams="300" numEdgesCollis="300" numEdges='300'
youngModulus="1000000" youngModulusExtremity="1000000" />
<MeshOBJLoader name="loader" filename="mesh/key_tip.obj" />

<RodStraightSection name="StraightSection" youngModulus="1000000" poissonRatio="0.3" radius="10" massDensity="0.1" nbEdgesCollis="30" nbEdgesVisu="200" length="980.0"/>
<RodMeshSection name="MeshTipSection" loader="@loader" nbEdgesCollis="300" nbEdgesVisu="300" radius="10" massDensity="0.1" youngModulus="1000000" poissonRatio="0.3"/>

<WireRestShape template="Rigid3d" name="GC_RestShape" printLog="false" wireMaterials="@StraightSection @MeshTipSection" />

<EdgeSetTopologyContainer name="GC_mesh" />
<EdgeSetTopologyModifier />
Expand Down
7 changes: 4 additions & 3 deletions src/BeamAdapter/component/engine/SteerableCatheter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ class SteerableCatheter : public WireRestShape<DataTypes>
/// Bring inherited attributes and function in the current lookup context.
/// otherwise any access to the base::attribute would require
/// the "this->" approach.
using Inherit1::d_spireDiameter;
using Inherit1::d_length;
using Inherit1::d_straightLength;
Data<Real> d_length;
Data<Real> d_straightLength;
Data<Real> d_spireDiameter;
Data<Real> d_spireHeight;
///////////////////////////////////////////////////////////////////////////

};
Expand Down
2 changes: 1 addition & 1 deletion src/BeamAdapter/component/engine/WireRestShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using namespace sofa::defaulttype;
///
////////////////////////////////////////////////////////////////////////////////////////////////////

static int WireRestShapeClass = core::RegisterObject("Describe the shape functions on multiple segments using curvilinear abscissa")
const int WireRestShapeClass = core::RegisterObject("Describe the shape functions on multiple segments using curvilinear abscissa")
.add< WireRestShape<Rigid3Types> >(true)

;
Expand Down
104 changes: 35 additions & 69 deletions src/BeamAdapter/component/engine/WireRestShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@


#include <BeamAdapter/config.h>
#include <BeamAdapter/utils/BeamSection.h>
#include <BeamAdapter/component/model/BaseRodSectionMaterial.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/core/loader/MeshLoader.h>

namespace sofa::component::engine
Expand All @@ -48,14 +48,17 @@ 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;

using namespace sofa::beamadapter;

/**
* \class WireRestShape
* \brief Describe the shape functions on multiple segments
*
* Describe the shape functions on multiple segments using curvilinear abscissa
*
* Describe the full shape of a Wire with a given set of @sa BaseRodSectionMaterial. The wire is discretized by a set of beams (given by the keyPoints and the relatives Beam density)
* @sa d_keyPoints and @d_density are computed by method @sa initLengths using the set of rod sections description.
* This component compute the beam discretization and the shape functions on multiple segments using curvilinear abscissa.
*/
template <class DataTypes>
class WireRestShape : public core::objectmodel::BaseObject
Expand All @@ -69,8 +72,6 @@ class WireRestShape : public core::objectmodel::BaseObject
using Vec3 = sofa::type::Vec<3, Real>;
using Quat = sofa::type::Quat<Real>;

using BeamSection = sofa::beamadapter::BeamSection;

/**
* @brief Default Constructor.
*/
Expand All @@ -82,25 +83,19 @@ class WireRestShape : public core::objectmodel::BaseObject
virtual ~WireRestShape() = default;

/////////////////////////// Inherited from BaseObject //////////////////////////////////////////
void parse(core::objectmodel::BaseObjectDescription* arg) override;
void init() override ;

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


/////////////////////////// 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();}
/////////////////////////// Methods of WireRestShape //////////////////////////////////////////

/// 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);

/// This function gives the Young modulus and Poisson's coefficient of the beam depending on the beam position
void getYoungModulusAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson);
void getYoungModulusAtX(const Real& x_curv, Real& youngModulus, Real& cPoisson) const;

/// This function gives the mass density and the BeamSection data depending on the beam position
void getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J);
void getInterpolationParam(const Real& x_curv, Real &_rho, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) const;

/**
* This function provides a type::vector with the curviliar abscissa of the noticeable point(s)
Expand All @@ -110,77 +105,48 @@ class WireRestShape : public core::objectmodel::BaseObject


/// Functions enabling to load and use a geometry given from OBJ external file
void initRestConfig();
void getRestPosNonProcedural(Real& abs, Coord &p);
void computeOrientation(const Vec3& AB, const Quat& Q, Quat &result);
void initFromLoader();
bool checkTopology();

[[nodiscard]] bool fillTopology();


Real getLength() ;
void getCollisionSampling(Real &dx, const Real &x_curv) ;
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)
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;
}

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

protected:
/// Internal method to init Lengths vector @sa d_keyPoints using the length of each materials @sa l_sectionMaterials.
void initLengths();
/// Internal method to init Edge Topology @sa _topology using the list of materials @sa l_sectionMaterials. Returns false if init can't be performed.
bool initTopology();


public:
/// Analitical creation of wire shape...
Data<bool> d_isAProceduralShape;
Data<Real> d_nonProceduralScale;
Data<Real> d_length;
Data<Real> d_straightLength;
Data<Real> d_spireDiameter;
Data<Real> d_spireHeight;
Data<type::vector<int> > d_density;
Data<type::vector<Real> > d_keyPoints;
Data< int > d_numEdges;
Data<type::vector<int> > d_numEdgesCollis;

/// User Data about the Young modulus
Data<Real> d_poissonRatio;
Data<Real> d_youngModulus1;
Data<Real> d_youngModulus2;

/// Radius
Data<Real> d_radius1;
Data<Real> d_radius2;
Data<Real> d_innerRadius1;
Data<Real> d_innerRadius2;

Data<Real> d_massDensity1;
Data<Real> d_massDensity2;

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

private:
/// Data required for the File loading
type::vector<Vec3> m_localRestPositions;
type::vector<Transform> m_localRestTransforms;
type::vector<Real> m_curvAbs ;
double m_absOfGeometry {0};

BeamSection beamSection1;
BeamSection beamSection2;
/// Vector or links to the Wire section material. The order of the linked material will define the WireShape structure.
MultiLink<WireRestShape<DataTypes>, BaseRodSectionMaterial<DataTypes>, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_sectionMaterials;

private:
/// Link to be set to the topology container in the component graph.
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;
/// Pointer to the MeshLoader, should be set using @sa l_loader, otherwise will search for one in current Node.
MeshLoader* loader{ nullptr };
};


Expand Down
Loading

0 comments on commit a424fa8

Please sign in to comment.