Skip to content

Commit

Permalink
Add docstring for signed distance function's trimesh2sdf (#211)
Browse files Browse the repository at this point in the history
* Add docstring for signed distance function utilities

* [docs] Add document for sdf

* Enable padding_grid

* Raise ValueError for converting sdf
  • Loading branch information
iory committed Jan 8, 2021
1 parent 28dcbcf commit a90c31d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
14 changes: 13 additions & 1 deletion docs/source/reference/sdfs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Signed distance function (SDF)
==============================

SDF classes
-------------------
-----------
.. autosummary::
:toctree: generated/
:nosignatures:
Expand All @@ -11,3 +11,15 @@ SDF classes
skrobot.sdf.UnionSDF
skrobot.sdf.BoxSDF
skrobot.sdf.GridSDF
skrobot.sdf.CylinderSDF
skrobot.sdf.SphereSDF

SDF utilities
-------------

.. autosummary::
:toctree: generated/
:nosignatures:

skrobot.sdf.signed_distance_function.trimesh2sdf
skrobot.sdf.signed_distance_function.link2sdf
26 changes: 24 additions & 2 deletions skrobot/sdf/signed_distance_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@
logger = getLogger(__name__)


def trimesh2sdf(mesh, dim_grid):
def trimesh2sdf(mesh, dim_grid=100, padding_grid=5):
"""Convert trimesh to signed distance function.
Parameters
----------
mesh : trimesh.base.Trimesh
mesh object.
dim_grid : int
dimension of the GridSDF.
This value is used for a not primitive mesh.
padding_grid : int
number of padding.
Returns
-------
sdf : skrobot.sdf.SignedDistanceFunction
converted signed distance function.
"""
if not ('file_path' in mesh.metadata
or 'shape' in mesh.metadata):
raise ValueError("Input mesh doesn't contain valid metadata"
" for converting SDF.")
is_loaded_mesh = 'file_path' in mesh.metadata
if is_loaded_mesh:
file_path = mesh.metadata['file_path']
sdf = GridSDF.from_objfile(file_path, dim_grid=dim_grid)
sdf = GridSDF.from_objfile(file_path, dim_grid=dim_grid,
padding_grid=padding_grid)
else:
# process primtives
shape = mesh.metadata['shape']
Expand Down

0 comments on commit a90c31d

Please sign in to comment.