From e2a8d65a045f7161210b6e5aeeb17107e76566b1 Mon Sep 17 00:00:00 2001
From: Alexis Durgnat <alexis.durgnat@hesge.ch>
Date: Mon, 1 Nov 2021 16:05:20 +0100
Subject: [PATCH] Add sphinx doc

---
 .gitignore                   |  4 ++-
 README.md                    | 12 +++++++-
 docs/Makefile                | 20 ++++++++++++
 docs/ar_sandbox.examples.rst | 21 +++++++++++++
 docs/ar_sandbox.rst          | 30 ++++++++++++++++++
 docs/ar_sandbox.wrapper.rst  | 21 +++++++++++++
 docs/conf.py                 | 60 ++++++++++++++++++++++++++++++++++++
 docs/howto/howto.rst         | 10 ++++++
 docs/howto/sandbox.rst       | 35 +++++++++++++++++++++
 docs/howto/wrapper.rst       | 51 ++++++++++++++++++++++++++++++
 docs/index.rst               | 21 +++++++++++++
 docs/make.bat                | 35 +++++++++++++++++++++
 docs/modules.rst             |  7 +++++
 13 files changed, 325 insertions(+), 2 deletions(-)
 create mode 100644 docs/Makefile
 create mode 100644 docs/ar_sandbox.examples.rst
 create mode 100644 docs/ar_sandbox.rst
 create mode 100644 docs/ar_sandbox.wrapper.rst
 create mode 100644 docs/conf.py
 create mode 100644 docs/howto/howto.rst
 create mode 100644 docs/howto/sandbox.rst
 create mode 100644 docs/howto/wrapper.rst
 create mode 100644 docs/index.rst
 create mode 100644 docs/make.bat
 create mode 100644 docs/modules.rst

diff --git a/.gitignore b/.gitignore
index e6cf7a9..7f474dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -182,4 +182,6 @@ dmypy.json
 # Cython debug symbols
 cython_debug/
 
-.vscode/
\ No newline at end of file
+.vscode/
+
+!docs/Makefile
\ No newline at end of file
diff --git a/README.md b/README.md
index b75baf9..017443f 100644
--- a/README.md
+++ b/README.md
@@ -18,4 +18,14 @@ box = Sandbox(refresh=250)
 box.init("config.yaml")
 box.func = my_function
 box.start()
-```
\ No newline at end of file
+```
+
+See the documentation for more information.
+
+To make the documentation :
+
+```bash
+python3 -m pip install sphinx sphinx_rtd_theme
+cd ./docs
+make html
+```
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..d4bb2cb
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS    ?=
+SPHINXBUILD   ?= sphinx-build
+SOURCEDIR     = .
+BUILDDIR      = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/docs/ar_sandbox.examples.rst b/docs/ar_sandbox.examples.rst
new file mode 100644
index 0000000..b764a34
--- /dev/null
+++ b/docs/ar_sandbox.examples.rst
@@ -0,0 +1,21 @@
+ar\_sandbox.examples package
+============================
+
+Submodules
+----------
+
+ar\_sandbox.examples.examples module
+------------------------------------
+
+.. automodule:: ar_sandbox.examples.examples
+   :members:
+   :undoc-members:
+   :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: ar_sandbox.examples
+   :members:
+   :undoc-members:
+   :show-inheritance:
diff --git a/docs/ar_sandbox.rst b/docs/ar_sandbox.rst
new file mode 100644
index 0000000..81003ba
--- /dev/null
+++ b/docs/ar_sandbox.rst
@@ -0,0 +1,30 @@
+ar\_sandbox package
+===================
+
+Subpackages
+-----------
+
+.. toctree::
+   :maxdepth: 4
+
+   ar_sandbox.examples
+   ar_sandbox.wrapper
+
+Submodules
+----------
+
+ar\_sandbox.sandbox module
+--------------------------
+
+.. automodule:: ar_sandbox.sandbox
+   :members:
+   :undoc-members:
+   :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: ar_sandbox
+   :members:
+   :undoc-members:
+   :show-inheritance:
diff --git a/docs/ar_sandbox.wrapper.rst b/docs/ar_sandbox.wrapper.rst
new file mode 100644
index 0000000..34b954e
--- /dev/null
+++ b/docs/ar_sandbox.wrapper.rst
@@ -0,0 +1,21 @@
+ar\_sandbox.wrapper package
+===========================
+
+Submodules
+----------
+
+ar\_sandbox.wrapper.sandbox\_wrapper module
+-------------------------------------------
+
+.. automodule:: ar_sandbox.wrapper.sandbox_wrapper
+   :members:
+   :undoc-members:
+   :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: ar_sandbox.wrapper
+   :members:
+   :undoc-members:
+   :show-inheritance:
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..82f9d40
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,60 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+import os
+import sys
+sys.path.insert(0, os.path.abspath('../src/'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'AR_Sandbox Python Wrapper'
+copyright = '2021, HEPIA'
+author = 'Alexis Durgnat'
+
+# The full version, including alpha/beta/rc tags
+release = '0.0.1'
+
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+    "sphinx.ext.autodoc",
+    "sphinx.ext.viewcode",
+    "sphinx_rtd_theme"
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'sphinx_rtd_theme'
+# or maybe you love
+# html_theme = 'alabaster'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
\ No newline at end of file
diff --git a/docs/howto/howto.rst b/docs/howto/howto.rst
new file mode 100644
index 0000000..1b91ec4
--- /dev/null
+++ b/docs/howto/howto.rst
@@ -0,0 +1,10 @@
+How to use
+===================
+
+It's possible to use the provided class (easier), or the wrapper directly
+
+.. toctree::
+   :maxdepth: 2
+
+   sandbox
+   wrapper
\ No newline at end of file
diff --git a/docs/howto/sandbox.rst b/docs/howto/sandbox.rst
new file mode 100644
index 0000000..b532d64
--- /dev/null
+++ b/docs/howto/sandbox.rst
@@ -0,0 +1,35 @@
+Using the Sandbox class
+=======================
+
+Using the Sandbox class is pretty simple
+
+.. code-block:: python
+
+    # Import the class
+    from ar_sandbox import Sandbox
+
+    # Define a function, taking the depth and the frame as parameters
+    # and returning a 3-channel BGR frame of the same size as depth.
+    # It's possible to pass aditionnal arguments
+
+    def my_awesome_function(depth, frame, my_arg="Hello"):
+        # Do something with the arguments
+        return new_frame
+
+
+    # Instantiate the sandbox, and load the configuration :
+    box = Sandbox(refresh_rate=20) # in [ms]
+    box.init("./sandbox_conf.yaml")
+
+    # Define the on_frame function of the sandbox to yours
+    box.on_frame = my_awesome_function
+
+    # Run the sandbox with 'box.start()'
+    # You may pass aditionnal arguments to the on_frame call by passing them
+    # to the start function.
+    try:
+        box.start(my_arg="something") 
+    except:
+        box.stop()
+        exit(1)
+    
\ No newline at end of file
diff --git a/docs/howto/wrapper.rst b/docs/howto/wrapper.rst
new file mode 100644
index 0000000..db38364
--- /dev/null
+++ b/docs/howto/wrapper.rst
@@ -0,0 +1,51 @@
+Using the wrapper
+===================
+
+It is also possible to directly use the wrapper.
+
+
+.. code-block:: python       
+        
+
+        # Import the wrapper
+        from ar_sandbox.wrapper import sandbox_wrapper as wrapper
+
+        import cv2 # For displaying the result
+        import numpy as np # For matrix manipulation
+
+        WINDOW_NAME = "MyWindow"
+
+        sandbox = wrapper.Sandbox() # Instantiate a new C++ Sandbox
+
+        # Create a cv2 window
+        cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN)
+        cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
+
+        # Load the configuration file
+        sandbox.load_config('./sandbox_conf.yaml')
+        
+        # initialize the sandbox
+        sandbox.init_sandbox()
+
+        while (True):
+            sandbox.capture_frame() # Update camera buffers
+                                   
+            curr_depth = sandbox.get_depth_frame() # Get the depth frame
+
+            # Convert it to a readable numpy array :
+            curr_depth = np.array(curr_depth, copy = False)
+                
+            frame = ... # A 3 channel frame of the same size as the depth (BGR)
+
+            # Adjust the projection according to the sandbox parameter.
+            # The numpy array should be converted back to cvMat
+            frame = np.array(sandbox.adjust_projection(wrapper.cvMat3b(frame), wrapper.cvMatf(curr_depth)), copy=False)
+
+
+            cv2.imshow(winname=WINDOW_NAME, mat=frame)
+
+            # Wait for a key for 20 [ms] to exit
+            if cv2.waitKey(20) == 27: # Wait for 'Esc' key to stop
+                break
+
+        cv2.destroyAllWindows()
\ No newline at end of file
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..548a281
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,21 @@
+.. AR_Sandbox Python Wrapper documentation master file, created by
+   sphinx-quickstart on Mon Nov  1 13:24:38 2021.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to AR_Sandbox Python Wrapper's documentation!
+=====================================================
+
+.. toctree::
+   :maxdepth: 2
+   :caption: Contents:
+
+   howto/howto
+   modules
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 0000000..8084272
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=_build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+	echo.
+	echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+	echo.installed, then set the SPHINXBUILD environment variable to point
+	echo.to the full path of the 'sphinx-build' executable. Alternatively you
+	echo.may add the Sphinx directory to PATH.
+	echo.
+	echo.If you don't have Sphinx installed, grab it from
+	echo.https://www.sphinx-doc.org/
+	exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/docs/modules.rst b/docs/modules.rst
new file mode 100644
index 0000000..a347541
--- /dev/null
+++ b/docs/modules.rst
@@ -0,0 +1,7 @@
+ar_sandbox
+==========
+
+.. toctree::
+   :maxdepth: 4
+
+   ar_sandbox
-- 
GitLab