Forum Replies Created
-
AuthorPosts
-
13 December 2021 at 14:58 in reply to: [SOLVED] Change point indices when using PartialLinearMovementConstraint #21137bayminBlocked
Hi @Hugo,
I found that I can solve this problem by defining multi-motion in the beginning.
self.motion1 = LiverFEM.createObject('PartialLinearMovementConstraint', indices='100', keyTimes='0', template='Vec3d', movements='0 0 0') self.motion2 = LiverFEM.createObject('PartialLinearMovementConstraint', indices='105', keyTimes='0', template='Vec3d', movements='0 0 0')
But if I just define one motion and just change the indices of motion, the second point will move from (0, 0, 0).
We use the liver demo and our animation function is as below
def onBeginAnimationStep(self, deltaTime): ## Please feel free to add an example for a simple usage in /home/trs/sofa/build/unstable//home/trs/sofa/src/sofa/applications/plugins/SofaPython/scn2python.py cT = self.LiverFEM.getTime() position1 = self.LiverFEM.getObject('dofs').position[100] position2 = self.LiverFEM.getObject('dofs').position[105] position = [position1, position2] movements = self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('movements').value keyTimes = self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('keyTimes').value indices = self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('indices').value self.control_point_index = self.control_point_index + 1 if self.control_point_index >= 200: self.control_point_index = 0 ind = self.control_point_index // 100 motion = [[0, 0, 0], [0, 0, 0]] T_dec = cT / deltaTime / 100 * 2 * 3.1415926 motion[ind] = [0.5*math.sin(T_dec), 0.5*math.sin(T_dec), 0] print('ind motion', ind, motion) self.motion1.findData('keyTimes').value = [[cT], [cT + 100]] self.motion1.findData('movements').value = motion[0] self.motion2.findData('keyTimes').value = [[cT], [cT + 100]] self.motion2.findData('movements').value = motion[1]
Best
baymin
31 May 2019 at 05:23 in reply to: [SOLVED] Using Python to move some points or parts of an object #13558bayminBlockedHi,
I have moved some points of an object in real-time success, by adding the below code into the function ‘onBeginAnimationStep’:
cT = self.LiverFEM.getTime() self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('keyTimes').value = [[cT], [cT + 100]] self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('movements').value = [0.5*math.sin(cT), 0.5*math.cos(cT), 0]
But what is the meaning of the keyTimes? If I set it too small, the simulation will illness. On the other hand, if I set it biger, it works well, but 1s, 10s and 100s has nothing different.
Best,
Baymin
29 May 2019 at 07:03 in reply to: [SOLVED] Using Python to move some points or parts of an object #13552bayminBlockedHi, @Hugo
How can I change the position of some points of an object in real-time.
I tried to use ‘PartialLinearMovementConstraint’ and set the properties: ‘movements’ and ‘keyTimes’:self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('keyTimes').value = [[0.0], [5.0], [10.0]] if self.count == t1: self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('movements').value = [[0, 0, 0], [0.1, -0.1, -0.1], [0.1, -0.1, -0.1]] elif self.count == t2: self.LiverFEM.getObject('PartialLinearMovementConstraint').findData('movements').value = [[0, 0, 0], [0.1, -0.1, -0.1], [-0.1, 0.1, 0.1]]
but the object in simulation changed suddenly and did not move smoothly as set it in the createGraph function/method:
LiverFEM.createObject('PartialLinearMovementConstraint', indices='100 105 110', keyTimes='0 5 10', template='Vec3d', movements='0 0 0 0.1 -0.1 -0.1 -0.1 0.1 0.1')
So how can I change the position of one point of an object such as one blue point on the surface in each AnimationStep?
https://drive.google.com/file/d/13wC1e5j2eSSdgBaMD8ywH4tSdkJlbSSY/view?usp=sharingBest,
Baymin
28 May 2019 at 15:38 in reply to: [SOLVED] Using Python to move some points or parts of an object #13547bayminBlockedDear Hugo,
Thank you very much for your help.
Both using ‘PartialLinearMovementConstraint’ and adding springs between nodes are work well.Best,
Baymin
bayminBlockedThank you, @Binesh.
I have read the SOFA documentation, and I want a detail documentation for the classes and structures. I think there should be a website which could list all the classes and the functions just likes the OpenCV.
Best,
Baymin.
5 April 2018 at 08:03 in reply to: add_executable cannot create target, another target with the same namea exist. #10759bayminBlockedHi,
I had put my plugin package into “sofa/applications/projects”, and then add “sofa_add_plugin” into the CMakeList.txt in “sofa/applications/projects”. By using “cmake-gui ../../src” and use “make” to build it.
The problems cannot find “*.h” files had been solved, but there are some new problems again:
In file included from sofa/applications/projects/MyPlugin/Main.cpp:17:0: sofa/SofaKernel/SofaCommon/../modules/SofaSimulationTree/GNode.h: In function ‘int main(int, char**)’: sofa/SofaKernel/SofaCommon/../modules/SofaSimulationTree/GNode.h:48:5: error: ‘sofa::simulation::tree::GNode::GNode(const string&, sofa::simulation::tree::GNode*)’ is protected GNode( const std::string& name="", GNode* parent=NULL ); ^ sofa/applications/projects/MyPlugin/Main.cpp:57:72: error: within this context sofa::simulation::tree::GNode* groot = new sofa::simulation::tree::GNode; ^ sofa/applications/projects/MyPlugin/Main.cpp:60:12: error: ‘class sofa::simulation::tree::GNode’ has no member named ‘setGravityInWorld’ groot->setGravityInWorld(g); ^ sofa/applications/projects/MyPlugin/Main.cpp:72:51: error: request for member ‘get’ in ‘groot’, which is of pointer type ‘sofa::simulation::tree::GNode*’ (maybe you meant to use ‘->’ ?) sofa::simulation::getSimulation()->init(groot.get());
I had use “grep” to find the function setGravityInWorld and could not find the definition of “setGravityInWorld”. So how can I build my own plugins and run them.
Thank you very much.
Best,
Baymin
4 April 2018 at 15:14 in reply to: add_executable cannot create target, another target with the same namea exist. #10758bayminBlockedHi,
I found my mistake about building my plugins from the tutorial. Build a package in sofa/applications/plugins, and then add “sofa_add_plugin” into the CMakeList.txt in plugins. By using “cmake-gui ../../src” I can select my plugin package, and use “make” to build it.
But there are some new problems:
SofaComponentAdvanced/initComponentAdvanced.h: No such file or directory
Then I copy the “sofa/modules” into “sofa/SofaKernel/modules” and new problems appear:
In function ‘int main(int, char**)’: error: ‘ExecParams’ has not been declared ExecParams::defaultInstance()->setAspectID(0); error: ‘GNode’ is not a member of ‘sofa::simulation::tree’ sofa::simulation::tree::GNode* groot = new sofa::simulation::tree::GNode; ...
I copied the Main.cpp from the docmetation:
So how can I build my own plugins.Thank you very much.
Best,
Baymin
bayminBlockedThank you, Hugo.
The ./bin/runSofa is ok.
And the Modeler in v17.06 is ok too, but it does not work in v17.12.
Best regards,
Baymin
bayminBlockedHi, Hugo
I found that I can add values in the properties section in the Modeler window.
Thank you very much.
Best,
Baymin
-
AuthorPosts