diff --git a/doc/AdaptiveBeamMapping_00000001.png b/doc/AdaptiveBeamMapping_00000001.png new file mode 100644 index 000000000..3137425a2 Binary files /dev/null and b/doc/AdaptiveBeamMapping_00000001.png differ diff --git a/src/BeamAdapter/component/BeamInterpolation.h b/src/BeamAdapter/component/BeamInterpolation.h index 448b2dd2b..e11519527 100644 --- a/src/BeamAdapter/component/BeamInterpolation.h +++ b/src/BeamAdapter/component/BeamInterpolation.h @@ -101,29 +101,10 @@ class BeamInterpolation : public BaseBeamInterpolation BeamInterpolation() ; virtual ~BeamInterpolation() override = default; - //////////////////////////////////// Exposing this object in the factory /////////////////////// - /// Pre-construction check method called by ObjectFactory. - /// Check that DataTypes matches the MechanicalState. - template - static bool canCreate(T* obj, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) - { - if (dynamic_cast*>(context->getMechanicalState()) == nullptr) - { - arg->logError(std::string("No mechanical state with the datatype '") + DataTypes::Name() + - "' found in the context node."); - return false; - } - return sofa::core::objectmodel::BaseObject::canCreate(obj, context, arg); - } - - //////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////// Inherited from Base /////////////////////////////////////// void init() override ; void bwdInit() override ; void reinit() override ; - void reset() override ; //TODO(dmarchal@cduriez) Ca me semble détourner l'API pour faire des choses par surprise. A mon avis la bonne solution //est d'implémenter un vrai binding Python pour BeamInterpolation. Avec une fonction updateInterpolation @@ -140,6 +121,8 @@ class BeamInterpolation : public BaseBeamInterpolation bool verifyTopology(); void computeCrossSectionInertiaMatrix(); + /// Given @param beamId will return the 2 PointID forming the given edge from the list @sa d_edgeList. Return true if found otherwise false. + bool getNodeIndices(const ElementID beamID, PointID &node0Idx, PointID &node1Idx) const; void getInterpolationParam(unsigned int edgeInList, Real &_L, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &J) override; diff --git a/src/BeamAdapter/component/BeamInterpolation.inl b/src/BeamAdapter/component/BeamInterpolation.inl index 396e53a4c..75333c98f 100644 --- a/src/BeamAdapter/component/BeamInterpolation.inl +++ b/src/BeamAdapter/component/BeamInterpolation.inl @@ -264,14 +264,6 @@ void BeamInterpolation::storeResetState() updateInterpolation(); } -template -void BeamInterpolation::reset() -{ - if(d_componentState.getValue()==ComponentState::Invalid) - return ; - - bwdInit(); -} template bool BeamInterpolation::interpolationIsAlreadyInitialized() @@ -485,6 +477,32 @@ void BeamInterpolation::getSplineRestTransform(unsigned int edgeInLis } +template +bool BeamInterpolation::getNodeIndices(const ElementID beamID, PointID& node0Idx, PointID& node1Idx) const +{ + if (m_topologyEdges == nullptr) + { + msg_error() <<"This object does not have edge topology defined (computation halted). " ; + return false; + } + + const VecElementID& edges = d_edgeList.getValue(); + if (beamID >= edges.size()) + { + msg_error() << "Given beamID: " << beamID << " in getNodeIndices is out of bounds: " << edges.size(); + return false; + } + + /// 1. Get the indices of element and nodes + const ElementID& e = edges[beamID] ; + const BaseMeshTopology::Edge& edge= (*m_topologyEdges)[e]; + node0Idx = edge[0]; + node1Idx = edge[1]; + + return true; +} + + template void BeamInterpolation::getInterpolationParam(unsigned int edgeInList, Real &_L, Real &_A, Real &_Iy , Real &_Iz, Real &_Asy, Real &_Asz, Real &_J) diff --git a/src/BeamAdapter/component/WireBeamInterpolation.h b/src/BeamAdapter/component/WireBeamInterpolation.h index a875a269a..485047f92 100644 --- a/src/BeamAdapter/component/WireBeamInterpolation.h +++ b/src/BeamAdapter/component/WireBeamInterpolation.h @@ -181,16 +181,6 @@ class WireBeamInterpolation : public BaseBeamInterpolation using BaseBeamInterpolation::d_componentState ; //////////////////////////////////////////////////////////////////////////// -public: - - template - static bool canCreate(T* obj, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) - { - return Inherited::canCreate(obj,context,arg); - } - - template - static typename T::SPtr create(T* tObj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) ; /////////////////////////// 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) diff --git a/src/BeamAdapter/component/WireBeamInterpolation.inl b/src/BeamAdapter/component/WireBeamInterpolation.inl index 13751a483..4f95124c6 100644 --- a/src/BeamAdapter/component/WireBeamInterpolation.inl +++ b/src/BeamAdapter/component/WireBeamInterpolation.inl @@ -253,45 +253,6 @@ bool WireBeamInterpolation::getApproximateCurvAbs(const Vec3& x_input -template -template -typename T::SPtr WireBeamInterpolation::create(T* tObj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) -{ - WireRestShape* _restShape = nullptr; - std::string _restShapePath; - bool pathOK = false; - - if(arg) - { - if (arg->getAttribute("WireRestShape",nullptr) != nullptr) - { - _restShapePath = arg->getAttribute("WireRestShape"); - context->findLinkDest(_restShape, _restShapePath, nullptr); - - if(_restShape == nullptr) - msg_warning(context) << " ("<< WireBeamInterpolation::GetClass()->className <<") : WireRestShape attribute not set correctly, WireBeamInterpolation will be constructed with a default WireRestShape" ; - else - pathOK = true; - } - else - msg_error(context) << " (" << WireBeamInterpolation::GetClass()->className <<") : WireRestShape attribute not used, WireBeamInterpolation will be constructed with a default WireRestShape" ; - - - if (!pathOK) - { - _restShapePath=" "; - _restShape = new WireRestShape(); - } - } - - typename T::SPtr obj = sofa::core::objectmodel::New(_restShape); - obj->setPathToRestShape(_restShapePath); - if (context) context->addObject(obj); - if (arg) obj->parse(arg); - return obj; -} - - } // namespace sofa::component::fem::_wirebeaminterpolation_ diff --git a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl index 21ef7a858..c355a771d 100644 --- a/src/BeamAdapter/component/controller/BeamAdapterActionController.inl +++ b/src/BeamAdapter/component/controller/BeamAdapterActionController.inl @@ -76,7 +76,7 @@ void BeamAdapterActionController::onKeyPressedEvent(core::objectmodel switch (kev->getKey()) { case 'E': - m_currAction = BeamAdapterAction::NO_ACTION; + m_currAction = BeamAdapterAction::EXPORT_ACTION; m_exportActions = !m_exportActions; break; case 'D': diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.h b/src/BeamAdapter/component/controller/InterventionalRadiologyController.h index 17bf4d0c8..8f59b46ad 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.h +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.h @@ -88,20 +88,18 @@ class InterventionalRadiologyController : public MechanicalStateController &x_point_list, type::vector &id_instrument_list, type::vector &removeEdge); diff --git a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl index 221e40a94..3533b1f66 100644 --- a/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl +++ b/src/BeamAdapter/component/controller/InterventionalRadiologyController.inl @@ -227,16 +227,6 @@ void InterventionalRadiologyController::bwdInit() } -/*! - * \todo fix the mouse event with better controls - */ -template -void InterventionalRadiologyController::onMouseEvent(MouseEvent * mev) -{ - SOFA_UNUSED(mev); -} - - template void InterventionalRadiologyController::onKeyPressedEvent(KeypressedEvent *kev) { @@ -1040,11 +1030,6 @@ void InterventionalRadiologyController::fixFirstNodesWithUntil(unsign d_indexFirstNode = firstSimulatedNode-1 ; } -template -bool InterventionalRadiologyController::modifyTopology(void) -{ - return false; -} template void InterventionalRadiologyController::getInstrumentList(type::vector*>& list) diff --git a/src/BeamAdapter/component/engine/WireRestShape.h b/src/BeamAdapter/component/engine/WireRestShape.h index d5b47a234..a2a78675a 100644 --- a/src/BeamAdapter/component/engine/WireRestShape.h +++ b/src/BeamAdapter/component/engine/WireRestShape.h @@ -110,9 +110,9 @@ class WireRestShape : public core::objectmodel::BaseObject void computeOrientation(const Vec3& AB, const Quat& Q, Quat &result); - Real getLength() ; + const Real& getLength() const; void getCollisionSampling(Real &dx, const Real &x_curv); - void getNumberOfCollisionSegment(Real &dx, unsigned int &numLines) ; + void getNumberOfCollisionSegment(Real &dx, unsigned int &numLines); diff --git a/src/BeamAdapter/component/engine/WireRestShape.inl b/src/BeamAdapter/component/engine/WireRestShape.inl index 667e36680..edeacc9af 100644 --- a/src/BeamAdapter/component/engine/WireRestShape.inl +++ b/src/BeamAdapter/component/engine/WireRestShape.inl @@ -318,7 +318,7 @@ const BeamSection& WireRestShape::getBeamSection(const Real& x_curv) template -typename WireRestShape::Real WireRestShape::getLength() +const typename WireRestShape::Real& WireRestShape::getLength() const { return d_keyPoints.getValue().back(); } diff --git a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h index 939a4f1aa..f50f0eaa4 100644 --- a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h +++ b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.h @@ -154,6 +154,8 @@ class AdaptiveBeamMapping : public Mapping Data> d_segmentsCurvAbs; /*!< (output) the abscissa of each created point on the collision model */ Data d_parallelMapping; /*!< flag to enable parallel internal computation of apply/applyJ */ + Data d_onlyVisual; + SingleLink, BInterpolation, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK> l_adaptativebeamInterpolation; diff --git a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl index b555475b0..6611f20c7 100644 --- a/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl +++ b/src/BeamAdapter/component/mapping/AdaptiveBeamMapping.inl @@ -76,6 +76,7 @@ AdaptiveBeamMapping::AdaptiveBeamMapping(State< In >* from, State< Out , d_nbPointsPerBeam(initData(&d_nbPointsPerBeam, 0.0, "nbPointsPerBeam", "if non zero, we will adapt the points depending on the discretization, with this num of points per beam (compatible with useCurvAbs)")) , d_segmentsCurvAbs(initData(&d_segmentsCurvAbs, "segmentsCurvAbs", "the abscissa of each point on the collision model", true, true)) , d_parallelMapping(initData(&d_parallelMapping, false, "parallelMapping", "flag to enable parallel internal computation")) + , d_onlyVisual(initData(&d_onlyVisual, (bool)false, "onlyVisual", "Really not mechanical mapping")) , l_adaptativebeamInterpolation(initLink("interpolation", "Path to the Interpolation component on scene"), interpolation) , m_inputMapping(nullptr) , m_isSubMapping(isSubMapping) @@ -291,6 +292,9 @@ void AdaptiveBeamMapping< TIn, TOut>::apply(const MechanicalParams* mparams, Dat template void AdaptiveBeamMapping< TIn, TOut>::applyJ(const core::MechanicalParams* mparams, Data& dOut, const Data& dIn) { + if (d_onlyVisual.getValue()) + return; + SOFA_UNUSED(mparams); SCOPED_TIMER("AdaptiveBeamMapping_applyJ"); @@ -376,6 +380,9 @@ void AdaptiveBeamMapping< TIn, TOut>::applyJ(const core::MechanicalParams* mpara template void AdaptiveBeamMapping< TIn, TOut>::applyJT(const core::MechanicalParams* mparams, Data& dOut, const Data& dIn) { + if (d_onlyVisual.getValue()) + return; + SOFA_UNUSED(mparams); SCOPED_TIMER("AdaptiveBeamMapping_applyJT"); diff --git a/src/BeamAdapter/utils/BeamActions.h b/src/BeamAdapter/utils/BeamActions.h index ea91418de..c82477857 100644 --- a/src/BeamAdapter/utils/BeamActions.h +++ b/src/BeamAdapter/utils/BeamActions.h @@ -38,6 +38,7 @@ namespace sofa::beamadapter USE_TOOL_0, USE_TOOL_1, USE_TOOL_2, + EXPORT_ACTION }; /// \brief map of action as string keyword instead of int for better clarity in scene scripting