Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[SofaPython] PythonScriptDataEngine (PSDE) #583
The PSDE works similar to a function block in Simulink or comparable software. The user can define a block (a PSDE) declaring its Inputs, Outputs (I/Os) and its behavior using Python alone. It has some similarities with the "PythonScriptController" (PSC). The two main differences are:
You can think of the PSDE as a possibility of subclassing the Sofa 'DataEngine' in a scripted way. In the second example provided it is shown how a versatile ROI functionality can be implemented with the help of the PSDE.
Two examples with some documentation are provided in:
Example of use (01-basic/PSDEBasic.pyscn):
#!/usr/bin/env python # -*- coding: utf-8 -*- import Sofa import os path = os.path.dirname(os.path.abspath(__file__))+'/../../../../../../share/mesh/' def createScene(rootNode): rootNode.createObject("MeshVTKLoader", name="loader", filename=path+'liver.vtk') rootNode.createObject('PythonScriptDataEngine', name='PSDE', filename="DataEngine.py", classname="MyDataEngine")
Example for DataEngine class in Python (01-basic/DataEngine.py):
class MyDataEngine(Sofa.PythonScriptDataEngine): def parse(self): # this is the correct place to define inputs and outputs! (linking will not work in init() for instance) self.addNewInput('Positions',datatype='p',firstname.lastname@example.org') self.addNewOutput('NumPoints',datatype='d', value='0') def init(self): pass def update(self): self.NumPoints = len(self.Positions)
What it does NOT provide: A new form of parsing from Python data to Sofa data. It uses the available mechanism that uses string conversion and parsing. Also, the type of the Data has to be declared/selected with a parameter in Python, because there is no logic to automatically derive the type desired by the user (could be future work).
Reviewers will merge only if all these checks are true.
Hi guys, I made the changes concerning your feedback and now the PR is ready for review from my side!
The main changes are: