Sofa helper to build scenes
Project description
Easily build complex simulation graphs for SOFA
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
params
you choose for your component - the custom
kwargs
given 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sofacomponents-0.1.2.tar.gz
(114.0 kB
view details)
Built Distribution
File details
Details for the file sofacomponents-0.1.2.tar.gz
.
File metadata
- Download URL: sofacomponents-0.1.2.tar.gz
- Upload date:
- Size: 114.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5d6d90696994f052f9ae95199ffa7548e57b095fe0ba8cd766326ca937a0f23 |
|
MD5 | 3f1824cb622760927909ec4532d7e3eb |
|
BLAKE2b-256 | cd3b8b7ad7f7c735aac10c9f7e88ff1b5709a427ad8ef746849290a8cfba2925 |
Provenance
File details
Details for the file sofacomponents-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: sofacomponents-0.1.2-py3-none-any.whl
- Upload date:
- Size: 114.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e38f1ef6741bddab8544ef00406539e2236cd72f9f352d03d3c655abb6685d7 |
|
MD5 | 1f764b1dee02e9cf7d5e97bc66ddf2d8 |
|
BLAKE2b-256 | cd31e7d3a7cf08ab37cefb4a90afa9f6f178f476031e79215e788c3c42428bde |