Easily build complex simulation graphs for SOFA
Install
pip install sofacomponents
Quick start
from sofacomponents import Node, SofaFactory
# build the factory
fa = SofaFactory(debug=False)
# create the root node
root = Node()
# add attributes
root.attrs(dt=0.05, gravity=[0, -1, 0])
# add sofa components from the factory
root.add(
fa.VisualStyle(displayFlags="showVisual"),
fa.DefaultAnimationLoop(),
fa.RequiredPlugin(pluginName="SofaOpenglVisual SofaPython"),
)
# add child node
childNode = root.child("childNode").add(
fa.MeshVTKLoader(filename="mesh.vtk"),
# add components not from the factory
fa.UnknownComponent(data="foo"),
)
# display the scene
print(root)
# Export the scene
root.write_scene_to("scene.py")
# Export the graph
root.write_graph_to("graph.txt")
Output:
root
└ VisualStyle (displayFlags=showVisual)
└ DefaultAnimationLoop ()
└ RequiredPlugin (pluginName=SofaOpenglVisual SofaPython)
└ childNode
└ MeshVTKLoader (filename=mesh.vtk)
└ UnknownComponent (data=foo)
Python generated scene:
import Sofa
class SceneElectroMechanical(Sofa.PythonScriptController):
def __init__(self, node):
self.createGraph(node)
def createGraph(self, root):
# root
root.dt = 0.05
root.gravity = [0, -1, 0]
root.createObject("VisualStyle", displayFlags="showVisual")
root.createObject("DefaultAnimationLoop",)
root.createObject("RequiredPlugin", pluginName="SofaOpenglVisual SofaPython")
# root/childNode
childNode = root.createChild("childNode")
childNode.createObject("MeshVTKLoader", filename="mesh.vtk")
childNode.createObject("UnknownComponent", data="foo")
def createScene(root_node):
SceneElectroMechanical(root_node)
Extend
Create a factory instanciating the SofaFactory class.
The sofa_component decorator allows to update the parameters directory with:
- the general default parameters (See
SofaFactory._defaults) - the
paramsyou choose for your component - the custom
kwargsgiven by the user
from sofacomponents import SofaFactory, sofa_component
class MyFactory(SofaFactory):
def __init__(self, debug=False):
super().__init__(debug)
@sofa_component
def MyComponentNoParams(self, **kwargs):
""" Minimum signature to register the component to the factory """
return "MyComponentName"
@sofa_component
def MyComponent(self, **kwargs):
params = dict(
data="foo",
# ...
)
return "MyComponentName", params
And then
# build the factory
fa = MyFactory()
Embeded documentation
Metadata
Release files for sofacomponents 0.1.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sofacomponents-0.1.17.tar.gz | 252.8 kB | Without provenance | Details for sofacomponents-0.1.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sofacomponents-0.1.17-py3-none-any.whl | Python 3 | none | any | Details for sofacomponents-0.1.17-py3-none-any.whl |
Total release size: 898.8 kB
Release files / sofacomponents-0.1.17.tar.gz
| Download URL | sofacomponents-0.1.17.tar.gz |
|---|---|
| Size | 252.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5d58a7e0c2fa445e8ca116e09be76b1be95382fdbe220d5d04c2baf587d7ff3
|
|
BLAKE2b-256 checksum How to use checksums |
8b86f7d3a0ea7884a14e3cb509167882eda3fc84464f6d027c2d58f63a9efd04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0
|
Release files / sofacomponents-0.1.17-py3-none-any.whl
| Download URL | sofacomponents-0.1.17-py3-none-any.whl |
|---|---|
| Size | 646.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59cd12677915ee573fbc734eeb8fb3759b45adf55b87c11de778f906028df665
|
|
BLAKE2b-256 checksum How to use checksums |
efc4d875c027eb35a0a7aef18452a4cc8694dd9cfe43435a3f16121d7b3546a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0
|
Security for sofacomponents 0.1.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.