Skip to main content

Python package to ease the use of the Sofa-Framework and the creation of a scene.

Project description

SofaTools python package : ease the creation of a scene

See the documentation on readthedocs.

Install

pip install sofatools
# or python3 -m pip install --user sofatools

Sofa scene launcher

from sofatools import Launcher
import os

curDir = os.getcwd()

fmm = Launcher({
    "SOFA_PATH" : "path_to_sofa_build/bin/runSofa",
    "SCENE_PATH" : os.path.join(curDir, "scene.py"),
    "RESULT_DIR_PATH" : os.path.join(curDir, "Output"),
})

fmm["N_IT"] = 10
fmm.run()

Here are the implemented parameters :

Key Value
SOFA_PATH Path of runSofa : path_to_sofa/bin/runSofa
SCENE_PATH Path of the python scene
G_MODE batch or qglviewer (default batch)
RESULT_DIR_PATH Directory for output and log, will be created if doesn't exist
OUT_TO_FILE Write output in files or in terminal (default False)
STDOUT_PATH Path for standard output file (default RESULT_DIR_PATH/stdout.out)
STDERR_PATH Path for standard errors file (default RESULT_DIR_PATH/stdout.out)
DT Time step of the simulation (default 0.01)
GRAVITY Gravity (default "0 0 0")
N_IT Number of time iterations (default 100)

To launch the scene, run

python3 launch.py

VTK unstructured grid reader

from sofatools import MeshReader

m = MeshReader("mesh.vtk")
print(m)
# ** Class vtk unstructured grid reader **
# Filename : path_to_mesh.vtk
# Points : 189
# Cells : 1608
# Tetras : 480
# Triangles : 1128
# Vertices : 0
# Lines : 0
# Hexas : 0


m.positions[2] # Position of point 2
# (3.2, 5.932, 0.0)

m.tetras[3]
# ** Class Cell **
# Type : Tetrahedron (10)
# Id : 3
# Points : 50 12 150 51

m.tetras[3][0] # Id of the first point in tetrahedron 3
# 50

m.cells[0] # return cell 0
for cell in m.cells # iterate over the cells

m.positions[m.triangles[3][0]] # Position of the first point in triangle 3
m.triangles[3].id # Id in cells of the third triangle
# 483
m.triangles[3].points # List of points of the triangle
# [4, 12, 50]

data = m.getCellData("name")
for d in data # iterate over the data
data.size
# 150
data.range
# (0.0, 15.0)
data[3] # Get the value on the third cell
# 12

Display the graph of a scene

from sofatools import Graph

print(Graph("scene.py"))

If you add it to your bashrc :

affScene scene.py >> graph.txt

Example output :

rootNode
     VisualStyle
     DefaultAnimationLoop
     DefaultVisualManagerLoop
     RequiredPlugin
     RequiredPlugin
     EulerImplicitSolver
     CGLinearSolver
     -> Ellipsoid
          ZonesVTKLoader
          Mesh
          ZoneFMM
          PlaceOrientDOFs
          MechanicalObject
          ZoneShapeFunction
          MechanicalObject
          BarycentricShapeFunction
          -> behavior
               ZoneGaussPointSampler
               TopologyGaussPointSampler
               MechanicalObject
               MLSMapping
               -> E
                    MechanicalObject
                    GreenStrainMapping
                    HookeForceField
          -> visual
               MeshSTLLoader
               OglModel
               MLSMapping

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sofatools, version 0.2.14
Filename, size File type Python version Upload date Hashes
Filename, size sofatools-0.2.14-py3-none-any.whl (9.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sofatools-0.2.14.tar.gz (8.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page