diff --git a/examples/python3/NeedleInsertion.py b/examples/python3/NeedleInsertion.py index 391914a8..9d614381 100644 --- a/examples/python3/NeedleInsertion.py +++ b/examples/python3/NeedleInsertion.py @@ -9,7 +9,7 @@ from cosserat.usefulFunctions import pluginList from cosserat.createFemRegularGrid import createFemCubeWithParams from cosserat.cosseratObject import Cosserat -from cosserat.utils import addConstraintPoint +from useful.utils import addConstraintPoint import sys # params = NeedleParameters() @@ -57,10 +57,9 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") solverNode.addObject('GenericConstraintCorrection') - needle = solverNode.addChild( - Cosserat(parent=solverNode, cosseratGeometry=needleGeometryConfig, radius=GeometryParams.radius, - name="needle", youngModulus=PhysicsParams.youngModulus, poissonRatio=PhysicsParams.poissonRatio, - rayleighStiffness=PhysicsParams.rayleighStiffness)) + needle = Cosserat(parent=solverNode, cosseratGeometry=needleGeometryConfig, radius=GeometryParams.radius, + name="needle", youngModulus=PhysicsParams.youngModulus, poissonRatio=PhysicsParams.poissonRatio, + rayleighStiffness=PhysicsParams.rayleighStiffness) needleCollisionModel = needle.addPointCollisionModel("needleCollision") # These state is mapped on the needle and used to compute the distance between the needle and the diff --git a/examples/python3/PCS_Example2.py b/examples/python3/PCS_Example2.py index c6dd3df7..2570242c 100644 --- a/examples/python3/PCS_Example2.py +++ b/examples/python3/PCS_Example2.py @@ -52,11 +52,11 @@ def __init__(self, *args, **kwargs): position = self.frames.position[self.size] # get the last rigid of the cosserat frame orientation = Quat(position[3], position[4], position[5], position[6]) # get the orientation # Get the force direction in order to remain orthogonal to the last section of beam - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = orientation.rotate([0., self.forceCoeff, 0.]) # print(f' The new vec is : {vec}') for count in range(3): - force[count] = vec[count] + force[0][count] = vec[count] if self.forceCoeff < 13.1e4: self.forceCoeff += 100 else: @@ -88,15 +88,14 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - PCS_Cosserat = solverNode.addChild( - Cosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, - inertialParams=inertialParams, name="cosserat", radius=Rb, youngModulus=YM)) + PCS_Cosserat = Cosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, + inertialParams=inertialParams, name="cosserat", radius=Rb, youngModulus=YM, showObject="1") beamFrame = PCS_Cosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=0.0, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) - solverNode.addObject(ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) + solverNode.addObject(ForceController(parent=solverNode, name='forceController', cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) return rootNode diff --git a/examples/python3/PNLS_Example1.py b/examples/python3/PNLS_Example1.py index 016785b3..b2541a11 100644 --- a/examples/python3/PNLS_Example1.py +++ b/examples/python3/PNLS_Example1.py @@ -52,10 +52,10 @@ def __init__(self, *args, **kwargs): def onAnimateEndEvent(self, event): if self.applyForce: - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = [0., 0., 0., 0., (self.forceCoeff * 1.) / sqrt(2), (self.forceCoeff * 1.) / sqrt(2)] for i, v in enumerate(vec): - force[i] = v + force[0][i] = v # print(f' The new force: {force}') def onKeypressedEvent(self, event): @@ -85,18 +85,17 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - nonLinearCosserat = solverNode.addChild( - nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, inertialParams=inertialParams, + nonLinearCosserat = nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, inertialParams=inertialParams, useCollisionModel=needCollisionModel, name="cosserat", radius=Rb, youngModulus=YM, legendreControlPoints=initialStrain, poissonRatio=PR,order=LegendrePolyOrder, rayleighStiffness=rayleighStiffness, - activatedMMM=False)) + activatedMMM=False) cosseratNode = nonLinearCosserat.legendreControlPointsNode beamFrame = nonLinearCosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-8, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) diff --git a/examples/python3/PNLS_Example2.py b/examples/python3/PNLS_Example2.py index edc4cfe2..91d9f0d6 100644 --- a/examples/python3/PNLS_Example2.py +++ b/examples/python3/PNLS_Example2.py @@ -52,11 +52,11 @@ def onAnimateEndEvent(self, event): position = self.frames.position[self.size] # get the last rigid of the cosserat frame orientation = Quat(position[3], position[4], position[5], position[6]) # get the orientation # Get the force direction in order to remain orthogonal to the last section of beam - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = orientation.rotate([0., self.forceCoeff, 0.]) # print(f' The new vec is : {vec}') for count in range(3): - force[count] = vec[count] + force[0][count] = vec[count] if self.forceCoeff < 13.1e4: self.forceCoeff += 100 else: @@ -87,17 +87,16 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - nonLinearCosserat = solverNode.addChild( - nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, + nonLinearCosserat = nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, name="cosserat", radius=Rb, youngModulus=YM, legendreControlPoints=initialStrain, order=LegendrePolyOrder, inertialParams=inertialParams, - activatedMMM=True)) + activatedMMM=True, showObject="1") cosseratNode = nonLinearCosserat.legendreControlPointsNode beamFrame = nonLinearCosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-5, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) diff --git a/examples/python3/PNLS_Example3.py b/examples/python3/PNLS_Example3.py index 6493cfe1..2aab3f4d 100644 --- a/examples/python3/PNLS_Example3.py +++ b/examples/python3/PNLS_Example3.py @@ -124,7 +124,7 @@ def createScene(rootNode): cosseratNode = nonLinearCosserat.legendreControlPointsNode constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-9, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, controller=controlMo)) diff --git a/examples/python3/cosserat/cosseratObject.py b/examples/python3/cosserat/cosseratObject.py index cae788e8..619e82c1 100644 --- a/examples/python3/cosserat/cosseratObject.py +++ b/examples/python3/cosserat/cosseratObject.py @@ -348,10 +348,7 @@ def createScene(rootNode): rootNode.addObject( "RequiredPlugin", name="plugins", - pluginName=[ - pluginList, - ["SofaEngine", "SofaLoader", "SofaSimpleFem", "SofaExporter"], - ], + pluginName=pluginList, ) rootNode.addObject( "VisualStyle", @@ -376,13 +373,11 @@ def createScene(rootNode): ) solverNode.addObject("GenericConstraintCorrection") - cosserat = solverNode.addChild( - Cosserat( - parent=solverNode, - cosseratGeometry=cosserat_config, - name="cosserat", - radius=0.15, - ) + cosserat = Cosserat( + parent=solverNode, + cosseratGeometry=cosserat_config, + name="cosserat", + radius=0.15, ) # use this to add the collision if the beam will interact with another object diff --git a/examples/python3/cosserat/needle/needleController.py b/examples/python3/cosserat/needle/needleController.py index 648573ee..0c029391 100644 --- a/examples/python3/cosserat/needle/needleController.py +++ b/examples/python3/cosserat/needle/needleController.py @@ -10,7 +10,7 @@ import Sofa import Cosserat from cosserat.needle.params import ConstraintsParams -from cosserat.utils import computePositiveAlongXDistanceBetweenPoints, computeNegativeAlongXDistanceBetweenPoints +from useful.utils import computePositiveAlongXDistanceBetweenPoints, computeNegativeAlongXDistanceBetweenPoints class Animation(Sofa.Core.Controller): diff --git a/examples/python3/cosserat/nonLinearCosserat.py b/examples/python3/cosserat/nonLinearCosserat.py index 901bb273..90e3022e 100644 --- a/examples/python3/cosserat/nonLinearCosserat.py +++ b/examples/python3/cosserat/nonLinearCosserat.py @@ -51,7 +51,7 @@ class NonLinearCosserat(Sofa.Prefab): Cosserat Mapping // it allow the transfer from the local to the global frame } """ - properties = [ + prefabParameters = [ {'name': 'name', 'type': 'string', 'help': 'Node name', 'default': 'Cosserat'}, {'name': 'position', 'type': 'Rigid3d::VecCoord', 'help': 'Cosserat base position', 'default': [[0., 0., 0., 0, 0, 0, 1.]]}, @@ -67,7 +67,7 @@ class NonLinearCosserat(Sofa.Prefab): 'default': 0.0}, {'name': 'attachingToLink', 'type': 'string', 'help': 'a rest shape force field will constraint the object ' 'to follow arm position', 'default': '1'}, - {'name': 'showObject', 'type': 'string', 'help': ' Draw object arrow ', 'default': '0'}] + {'name': 'showObject', 'type': 'string', 'help': ' Draw object arrow ', 'default': '1'}] def __init__(self, *args, **kwargs): Sofa.Prefab.__init__(self, *args, **kwargs) @@ -193,11 +193,11 @@ def addCosseratFrame(self, framesF, curv_abs_inputS, curv_abs_outputF): def createScene(rootNode): rootNode.addObject('RequiredPlugin', name='plugins', pluginName=[pluginList, - ['SofaEngine', 'SofaLoader', 'SofaSimpleFem', - 'SofaExporter']]) + ['Sofa.Component.Visual']]) rootNode.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels hideCollisionModels ' - 'hideBoundingCollisionModels hireForceFields ' + 'hideBoundingCollisionModels hideForceFields ' 'hideInteractionForceFields hideWireframe') + rootNode.addObject('DefaultAnimationLoop') rootNode.findData('dt').value = 0.01 # rootNode.findData('gravity').value = [0., -9.81, 0.] rootNode.findData('gravity').value = [0., 0., 0.] @@ -213,12 +213,11 @@ def createScene(rootNode): # solverNode.addObject('CGLinearSolver', tolerance=1.e-12, iterations=1000, threshold=1.e-18) needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - nonLinearCosserat = solverNode.addChild( - NonLinearCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, - name="cosserat", radius=0.1, legendreControlPoints=initialStrain, order=3)) + nonLinearCosserat = NonLinearCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, + useCollisionModel=needCollisionModel, name="cosserat", radius=0.1, legendreControlPoints=initialStrain, order=3) beamFrame = nonLinearCosserat.cosseratFrame beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-8, indices=12, - force=[0., 0., 0., 0., 0., 450.]) + forces=[0., 0., 0., 0., 0., 450.]) return rootNode diff --git a/src/Cosserat/mapping/LegendrePolynomialsMapping.inl b/src/Cosserat/mapping/LegendrePolynomialsMapping.inl index 276463db..727cecb5 100644 --- a/src/Cosserat/mapping/LegendrePolynomialsMapping.inl +++ b/src/Cosserat/mapping/LegendrePolynomialsMapping.inl @@ -42,14 +42,12 @@ namespace sofa::component::mapping { m_matOfCoeffs.clear(); auto curvAbs = d_vectorOfCurvilinearAbscissa.getValue(); auto sz = curvAbs.size(); - // std::cout << " curvAbs :" << curvAbs << std::endl; for (unsigned int i = 1; i < sz; i++){ type::vector coeffsOf_i; coeffsOf_i.clear(); for (unsigned int order = 0; order < d_order.getValue(); order++) coeffsOf_i.push_back(legendrePoly(order, curvAbs[i])); - // std::cout << " = = = >coeffsOf_i: " << coeffsOf_i << std::endl; m_matOfCoeffs.push_back(coeffsOf_i); } } @@ -58,10 +56,10 @@ namespace sofa::component::mapping { template void LegendrePolynomialsMapping::init() { - Inherit1::init(); - //Compute the coefficients for each curv_abs at all orders of the polynomials reinit(); + + Inherit1::init(); } @@ -73,16 +71,13 @@ namespace sofa::component::mapping { const auto sz = d_vectorOfCurvilinearAbscissa.getValue().size(); out.resize(sz-1); - // std::cout<< "Apply : in " << in[0] <