Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Excluded files
*.db
*.csv
*.json

# Excluded folders
.idea
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![logo](docs/src/_static/images/logo.svg)

The **SSD** project provides Python3 tools allowing users to easily develop **data storage** and **visualization**
strategies for their **numerical simulations** with az minimal lines of code.
strategies for their **numerical simulations** with a minimal lines of code.

This project has two main objectives:
* Easy **storage** management system for **any data** from a numerical simulation;
Expand Down
14 changes: 3 additions & 11 deletions docs/src/Core/Rendering/api.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
API
===

UserAPI
-------

.. autoclass:: SSD.Core.Rendering.UserAPI.UserAPI
.. autoclass:: SSD.Core.Rendering.user_api.UserAPI
:special-members: __init__
:members:


Visualizer
----------

.. autoclass:: SSD.Core.Rendering.Visualizer.Visualizer
.. autoclass:: SSD.Core.Rendering.visualizer.Visualizer
:special-members: __init__
:members:


Replay
------

.. autoclass:: SSD.Core.Rendering.Replay.Replay
.. autoclass:: SSD.Core.Rendering.replay.Replay
:special-members: __init__
:members:
4 changes: 1 addition & 3 deletions docs/src/Core/Storage/api.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
API
===

Database
--------

.. autoclass:: SSD.Core.Storage.Database.Database
.. autoclass:: SSD.Core.Storage.database.Database
:special-members: __init__
:members:

Expand Down
6 changes: 3 additions & 3 deletions docs/src/Core/Storage/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To create this file with a `.db` extension, a call to the ``new`` method is requ

.. code-block:: python

from SSD.Core import Database
from SSD.Core.Storage import Database

# Create a new Database object and a new storage file
db = Database(database_dir='my_directory',
Expand All @@ -28,7 +28,7 @@ Loading an existing *Database* is pretty similar as creating a new one, except t

.. code-block:: python

from SSD.Core import Database
from SSD.Core.Storage import Database

# Create a new Database object and load an exiting storage file
db = Database(database_dir='my_directory',
Expand Down Expand Up @@ -107,7 +107,7 @@ The following *Field* types are available:
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
| ``bool`` | :guilabel:`bool` | `BooleanField <http://docs.peewee-orm.com/en/latest/peewee/api.html#BooleanField>`_ |
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
| ``ndarray`` | :guilabel:`import numpy.ndarray` | See ``AdaptiveDB/ExtendedFields.py`` |
| ``ndarray`` | :guilabel:`import numpy.ndarray` | Field class for storing numpy arrays. |
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
| ``datetime`` | :guilabel:`import datetime.datetime` | `DateTimeField <http://docs.peewee-orm.com/en/latest/peewee/api.html#DateTimeField>`_ |
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
Expand Down
20 changes: 11 additions & 9 deletions docs/src/Core/Storage/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Each *Table* from all *Databases* will be duplicated in the new *Database*; in t

.. code-block:: python

from SSD.Core import merge
from SSD.Core.Storage import merge

merge(database_names=['my_Database1', 'my_Database2'],
new_database_name='my_MergedDatabase',
merge(database_files=['my_Database1', 'my_Database2'],
new_database_file='my_MergedDatabase',
remove_existing=True)
"""
>> DATABASE my_Database1.db
Expand Down Expand Up @@ -51,7 +51,9 @@ Each *Table* from all *Databases* will be duplicated in the new *Database*; in t
- _dt_ (DATETIME) (default)
- my_Data (FLOAT)

>> Confirm new Database architecture ? (y/n):
>> Confirm new Database architecture ? (y/n): y
Proceeding...
Merge complete.
"""


Expand All @@ -63,9 +65,9 @@ Both methods require tuples defines as :guilabel:`(current_name, new_name)`:

.. code-block:: python

from SSD.Core import rename_tables, rename_fields
from SSD.Core.Storage import rename_tables, rename_fields

rename_tables(database_name='my_Database',
rename_tables(database_file='my_Database',
renamed_tables=[('my_StoringTable', 'my_NewStoringTable'), ('my_ExchangeTable', 'my_NewExchangeTable')])
"""
>> DATABASE my_Database.db
Expand All @@ -80,7 +82,7 @@ Both methods require tuples defines as :guilabel:`(current_name, new_name)`:
- my_Data (FLOAT)
"""

rename_fields(database_name='my_Database',
rename_fields(database_file='my_Database',
table_name='my_NewStoringTable',
renamed_fields=('my_Condition', 'my_Test'))
"""
Expand All @@ -104,7 +106,7 @@ The ``remove_tables`` and ``remove_fields`` tools allows users to remove *Tables

.. code-block:: python

from SSD.Core import remove_tables, remove_fields
from SSD.Core.Storage import remove_tables, remove_fields

rename_tables(database_name='my_Database',
remove_tables='my_ExchangeTable')
Expand Down Expand Up @@ -135,7 +137,7 @@ The ``export`` tool allows users to export a *Database* either in CSV format eit

.. code-block:: python

from SSD.Core import export
from SSD.Core.Storage import export

export(database_name='my_Database',
exporter='csv',
Expand Down
18 changes: 4 additions & 14 deletions docs/src/SOFA/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,26 @@ API
Storage
-------

Database
""""""""

.. autoclass:: SSD.SOFA.Storage.Database.Database
.. autoclass:: SSD.SOFA.Storage.database.Database
:special-members: __init__
:members:


Rendering
---------

UserAPI
"""""""

.. autoclass:: SSD.SOFA.Rendering.UserAPI.UserAPI
.. autoclass:: SSD.SOFA.Rendering.user_api.UserAPI
:special-members: __init__
:members:


Visualizer
""""""""""

.. autoclass:: SSD.SOFA.Rendering.Visualizer.Visualizer
.. autoclass:: SSD.SOFA.Rendering.visualizer.Visualizer
:special-members: __init__
:members:


Replay
""""""

.. autoclass:: SSD.SOFA.Rendering.Replay.Replay
.. autoclass:: SSD.SOFA.Rendering.replay.Replay
:special-members: __init__
:members:
4 changes: 2 additions & 2 deletions docs/src/SOFA/rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ It is also possible to create and update objects manually such as in the ``Core`
.. code-block:: python

import Sofa
from SSD.SOFA import UserAPI
from SSD.SOFA.Rendering import UserAPI

# Create the root node
root = Sofa.Core.Node('root')
Expand Down Expand Up @@ -87,7 +87,7 @@ It is also possible to create and update objects manually such as in the ``Core`

.. code-block:: python

from SSD.SOFA import UserAPI
from SSD.SOFA.Rendering import UserAPI

def createScene(root):

Expand Down
4 changes: 2 additions & 2 deletions docs/src/SOFA/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Adding callbacks is very simple, since you only have to specify:
.. code-block:: python

import Sofa
from SSD.SOFA import Database
from SSD.SOFA.Storage import Database

# Create the root node
root = Sofa.Core.Node('root')
Expand Down Expand Up @@ -76,7 +76,7 @@ Adding callbacks is very simple, since you only have to specify:

.. code-block:: python

from SSD.SOFA import Database
from SSD.SOFA.Storage import Database

def createScene(root):

Expand Down
3 changes: 2 additions & 1 deletion examples/Core/rendering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ It is recommended to inspect and run the python scripts following this order:

* ``visualization.py``: discover all visual object types (how to create and update them).
* ``replay.py``: how to replay a simulation from a *Database*.
* ``<backend>_offscreen.py``: an example of offscreen rendering.
* ``offscreen.py``: an example of off-screen rendering.
* ``several_factories.py``: how to manage several *Factories* with a single *Visualizer*.
* ``several_factories_offsceen.py``: how to manage several *Factories* with a single *Visualizer* in off-screen mode.

Run the examples using ``python3 <example_name>.py <backend>`` with backend being either 'vedo' (by default) or 'open3d'.
25 changes: 14 additions & 11 deletions examples/Core/rendering/offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,51 @@
from numpy.random import random
from sys import argv

from SSD.Core import UserAPI, Replay
from SSD.Core.Rendering import UserAPI, Replay

# 1. Create the visualization API
factory = UserAPI(database_name='offscreen',
factory = UserAPI(database_dir='my_databases',
database_name='offscreen',
remove_existing=True)

# 2. Create the object to render
armadillo = Mesh('armadillo.obj')
mesh = Mesh('armadillo.obj').compute_normals()

# 3. Add objects to the Visualizer
# 3.1. Add a Mesh (object_id = 0)
factory.add_mesh(positions=armadillo.points(),
cells=armadillo.cells(),
factory.add_mesh(positions=mesh.vertices,
cells=mesh.cells,
at=0,
alpha=0.8,
c='orange6',
wireframe=False,
line_width=0.)
# 3.2. Add a PointCloud (object_id = 1)
factory.add_points(positions=armadillo.points(),
factory.add_points(positions=mesh.vertices,
at=1,
point_size=5,
scalar_field=armadillo.points()[:, 1])
scalar_field=mesh.vertices[:, 1])

# 4. Initialize the visualization
factory.launch_visualizer(offscreen=True)

# 5. Run a few steps
print('Running offscreen...')
for step in range(100):
updated_armadillo = armadillo.clone().points(armadillo.points() + 0.1 * random(armadillo.points().shape))
updated_mesh = mesh.clone()
updated_mesh.vertices = mesh.vertices + 0.1 * random(mesh.vertices.shape)
# 5.1. Update the Mesh
factory.update_mesh(object_id=0,
positions=updated_armadillo.points())
positions=updated_mesh.vertices)
# 5.2. Update the PointCloud
factory.update_points(object_id=1,
positions=updated_armadillo.points())
positions=updated_mesh.vertices)
# 5.3. Call a rendering step
factory.render()

# 6. Close the visualization, replay steps
print('...then replay.')
factory.close()
Replay(database_name='offscreen',
Replay(database_dir='my_databases',
database_name='offscreen',
backend='vedo' if len(argv) == 1 else argv[1]).launch()
10 changes: 6 additions & 4 deletions examples/Core/rendering/replay.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from os.path import exists
from os import system
from sys import argv

from SSD.Core import Replay
from SSD.Core.Rendering import Replay

# Check Database existence
if not exists('visualization.db'):
raise FileNotFoundError("You must create the Database using `python3 visualization.py` before to replay it.")
if not exists('my_databases/visualization.db'):
system('python3 visualization.py')

# Launch replay
Replay(database_name='visualization',
Replay(database_dir='my_databases',
database_name='visualization',
backend='vedo' if len(argv) == 1 else argv[1]).launch()
15 changes: 9 additions & 6 deletions examples/Core/rendering/several_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from threading import Thread
from sys import argv

from SSD.Core import Database, UserAPI, Visualizer
from SSD.Core.Storage import Database
from SSD.Core.Rendering import UserAPI, Visualizer


class Simulation:
Expand All @@ -13,12 +14,12 @@ def __init__(self,
idx_instance: int):

# Create the Mesh object
self.armadillo = Mesh('armadillo.obj')
self.mesh = Mesh('armadillo.obj')
# Create a Factory and add the Mesh object
self.factory = UserAPI(database=database,
idx_instance=idx_instance)
self.factory.add_mesh(positions=self.armadillo.points(),
cells=self.armadillo.cells(),
self.factory.add_mesh(positions=self.mesh.vertices,
cells=self.mesh.cells,
at=idx_instance,
c='orange3' if idx_instance == 0 else 'blue3')

Expand All @@ -30,7 +31,7 @@ def connect_to_visualizer(self):
def step(self):

# Update the Mesh positions
updated_positions = self.armadillo.points() + 0.1 * random(self.armadillo.points().shape)
updated_positions = self.mesh.vertices + 0.1 * random(self.mesh.vertices.shape)
self.factory.update_mesh(object_id=0,
positions=updated_positions)
self.factory.render()
Expand All @@ -44,7 +45,8 @@ def close(self):
if __name__ == '__main__':

# 1. Create a new Database
db = Database(database_name='several_factories').new(remove_existing=True)
db = Database(database_dir='my_databases',
database_name='several_factories').new(remove_existing=True)

# 2. Create several simulations
nb_simu = 2
Expand All @@ -54,6 +56,7 @@ def close(self):
# 3. Connect a single Visualizer to the Factories
# 3.1. Create a new Visualizer
Visualizer.launch(backend='vedo' if len(argv) == 1 else argv[1],
database_dir='my_databases',
database_name='several_factories',
nb_clients=nb_simu)
# 3.2. Connect each Factory to the Visualizer (must be launched in thread)
Expand Down
Loading