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

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
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.1.4
Filename, size & hash File type Python version Upload date
sofatools-0.1.4-py3-none-any.whl (7.1 kB) View hashes Wheel py3
sofatools-0.1.4.tar.gz (5.5 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page