[x3d-public] testing x3d python jupyter notebook

Andreas Plesch andreasplesch at gmail.com
Thu Sep 12 12:04:14 PDT 2019


Hi Don,

great progress. I had a chance to try out the XML serialization. It
starts to work:

https://github.com/andreasplesch/python-conda_pip/blob/master/index.ipynb

editable: https://mybinder.org/v2/gh/andreasplesch/python-conda_pip/master?filepath=index.ipynb

The particular issue is that the head statement is optional but the
serializer assumes it exists:

https://www.web3d.org/x3d/content/X3dTooltips.html#head

If fields and attributes such as DEF are treated the same, it
presumably limits the ability the validate a scene. For example,
routing a value to a DEF attribute may not be recognized as invalid.

Cheers,
-Andreas

On Tue, Sep 10, 2019 at 12:16 AM Brutzman, Donald (Don) (CIV)
<brutzman at nps.edu> wrote:
>
> Am happy to report that the x3d.py module again appears to be working.
>
> Also appear to have strict validation of all simple-type fields and toXML() output serialization working.
>
> Have also added leading sentence of all X3D Tooltips as docstring entries for all nodes and fields.
>
> Plenty more to test, and add, but this is encouraging.  We currently have an API that handles X3D data structures in a pythonic way and can output .x3d strings.
>
> Special thanks to Loren Peitso for unscrambling multiple difficulties.  The hardest source-code patterns seem to be sorted out, the rest of the goal functionality will follow in due course.
>
> Screenshot attached showing latest deployment working in Jupyter Notebook.
>
> This is all building against the X3Dv4 Unified Object Model (X3DUOM), which (as you noted earlier Andreas) indeed uses the term 'field' for all attributes of X3D nodes and statements.  This unified approach allows consistent typing throughout API handling of an X3D scene graph.
>
> Plenty more percolating but test reports are welcome if anyone wants to experiment.  Have fun with X3D Python!  8)
>
>    https://www.web3d.org/x3d/stylesheets/python/python.html
>
>    https://pypi.org/project/x3d
>
>    https://www.web3d.org/specifications/X3DUOM.html
>
>    https://www.web3d.org/specifications/X3dUnifiedObjectModel-4.0.xml
>
>    https://www.web3d.org/x3d/content/X3dTooltips.html
>    https://www.web3d.org/x3d/content/x3d-3.3.profile.xml
>
>
> On 8/27/2019 12:54 PM, Andreas Plesch wrote:
> > I was playing a bit more and noticed a few things.
> >
> > ROUTE has fields ?
> >
> > help(x3d.ROUTE)
> >
> > Help on class ROUTE in module x3d:
> >
> > class ROUTE(_X3DStatement)
> >   |  ROUTE(fromField='', fromNode='', toField='', toNode='')
> >   |
> >   |  ROUTE connects output fields of event-producing nodes to input fields of event-consuming nodes.
> >   |
> >   |  Method resolution order:
> >   |      ROUTE
> >   |      _X3DStatement
> >   |      builtins.object
> >   |
> >   |  Methods defined here:
> >   |
> >   |  __init__(self, fromField='', fromNode='', toField='', toNode='')
> >   |      Initialize self.  See help(type(self)) for accurate signature.
> >   |
> >   |  ----------------------------------------------------------------------
> >   |  Data and other attributes defined here:
> >   |
> >   |  FIELD_DECLARATIONS = [('fromField', '', 'SFString', 'inputOutput'), ('...
> >
> >
> > Probably for convenience. It may make sense to introduce X3DStatement 'parameters' or 'properties' although probably not a priority.
> >
> >
> > help(x3d.Scene().children)
> >
> > Help on list object:
> >
> > class list(object)
> >   |  list(iterable=(), /)
> >
> >
> > 'children' are just lists, eg. can contain anything rather than only X3DChildNodes.
> >
> > Perhaps introduce executioncontext to add routes to, ala SAI.
> >
> > DEF is a field ?
> >
> > Help on Shape in module x3d object:
> >
> > class Shape(_X3DShapeNode)
> >   |  Shape(DEF='', bboxCenter=(0, 0, 0), bboxSize=(-1, -1, -1), USE='', class_='', appearance=None, geometry=None, IS=None, metadata=None)
> >   |
> >   |  X3D element
> >   |
> >   |  Method resolution order:
> >   |      Shape
> >   |      _X3DShapeNode
> >   |      _X3DChildNode
> >   |      _X3DNode
> >   |      builtins.object
> >   |
> >   |  Methods defined here:
> >   |
> >   |  __init__(self, DEF='', bboxCenter=(0, 0, 0), bboxSize=(-1, -1, -1), USE='', class_='', appearance=None, geometry=None, IS=None, metadata=None)
> >   |      Initialize self.  See help(type(self)) for accurate signature.
> >   |
> >   |  ----------------------------------------------------------------------
> >   |  Data and other attributes defined here:
> >   |
> >   |  FIELD_DECLARATIONS = [('DEF', '', 'SFString', 'inputOutput'), ('bboxCe...
> >   |
> >
> > Probably for convenience. May lead to allowing routing to a DEF property.  Could be an extra name property/attribute.
> >
> > String fields can contain anything:
> > x3d.Shape(DEF=x3d.Scene()).DEF
> >
> > -Andreas
> >
> > On Tue, Aug 27, 2019 at 11:39 AM Andreas Plesch <andreasplesch at gmail.com <mailto:andreasplesch at gmail.com>> wrote:
> >
> >     Mybinder.org lets you run live notebooks using a docker image on a server.
> >
> >     Here is a live notebook which has x3d.py (v 0.11)  available in the (automatically built) docker image, and exercises the module a bit:
> >
> >     https://mybinder.org/v2/gh/andreasplesch/python-conda_pip/master?filepath=index.ipynb
> >
> >     It may take a while to load the interactive page. Feel to use that to experiment with x3d.py, or fork to preserve notebooks in a repo.
> >
> >     The pip install did not work fully. It installed but then could not find/access the module, only the __init__.py file. I had to manually provide the x3d.py .
> >
> >     Here is the non-interactive notebook via nbviewer:
> >
> >     https://nbviewer.jupyter.org/github/andreasplesch/python-conda_pip/blob/master/index.ipynb
> >
> >     It all works well. Of course, sofar one cannot really do anything with the created scene, such as displaying it.
> >
> >     [Some observations:
> >     If you look at the end, I was expecting to access routes from the scene object. But it only accepts children.
> >     Can one add the same child multiple times to the children array ? How would this be different or the same as DEF/USE ?
> >     ].
> >
> >     I did not try Mayavi but looking at the project it appears they rely on the vtk xml x3dexporter. It looks like they use x3dom for jupyter and wrap the x3d xml string as html. Unfortunately, this probably leads to problems with singletons, and jupyter cannot use xhtml. There was a note on the list previously on how to use python standard xml libraries to generate full closing tags. If I find some time I may try some things and make suggestions to Mayavi.
> >
> >     -Andreas
> >
> >         Message: 2
> >         Date: Tue, 27 Aug 2019 05:39:26 +0000
> >         From: "Brutzman, Donald (Don) (CIV)" <brutzman at nps.edu <mailto:brutzman at nps.edu>>
> >         To: Masaki Aono <aono at tut.jp <mailto:aono at tut.jp>>
> >         Cc: Kwan-Hee Yoo <khyoo at chungbuk.ac.kr <mailto:khyoo at chungbuk.ac.kr>>, Myeong Won Lee
> >                  <mwlee at suwon.ac.kr <mailto:mwlee at suwon.ac.kr>>, X3D Graphics public mailing list
> >                  <x3d-public at web3d.org <mailto:x3d-public at web3d.org>>, "Peitso, Loren (CIV)" <lepeitso at nps.edu <mailto:lepeitso at nps.edu>>, John
> >                  Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>>
> >         Subject: [x3d-public] testing x3d python jupyter notebook #0
> >         Message-ID: <622f0a4b-2cff-af29-2613-f8b090ec068c at nps.edu <mailto:622f0a4b-2cff-af29-2613-f8b090ec068c at nps.edu>>
> >         Content-Type: text/plain; charset="utf-8"
> >
> >         Hello Masaki, thanks for your help with setting up Jupyter notebook on my system.
> >
> >         https://test-jupyter.readthedocs.io/en/latest/install.html
> >
> >         Attached please find my first Jupyter notebook that includes an x3d scene.  Also available as
> >
> >         https://www.web3d.org/x3d/stylesheets/python/jupyter/HelloJupyterNotebook0.ipynb
> >
> >         As discussed, it assumes that x3d.py has already been downloaded and is available in a PYTHONPATH directory.
> >
> >         https://www.web3d.org/x3d/stylesheets/python/python.html
> >
> >         Please let me know if this notebook works for you.
> >
> >         It is also viewable via jupyter's nbviewer service at
> >
> >         https://nbviewer.jupyter.org/urls/www.web3d.org/x3d/stylesheets/python/jupyter/HelloJupyterNotebook0.ipynb
> >
> >         Interestingly, at first this copied notebook appears to load the x3d.py package on the jupyter nbviewer server without prior configuration incantations, since the forced "error" is displayed.  However by looking at the source, it appears that the TypeError markup is saved in the JSON source.  So the shared nbviewer version of the notebook must be a published version that has been run, earlier, saved/shared and is later re-runnable. (Hence "viewer" in the name nbviewer.)
> >
> >         I am next trying to configure my mailer to launch such notebooks.  Not sure it is possible.
> >
> >         Onward we go... having fun with Python X3D!  Domo arigato  8)
> >
> >         all the best, Don
> >         --
> >         Don Brutzman  Naval Postgraduate School, Code USW/Br brutzman at nps.edu <mailto:brutzman at nps.edu>
> >         Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> >         X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
> >         -------------- next part --------------
> >         An embedded and charset-unspecified text was scrubbed...
> >         Name: HelloJupyterNotebook0.ipynb
> >         URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190827/0a1cf52f/attachment.ksh>
> >         -------------- next part --------------
> >         A non-text attachment was scrubbed...
> >         Name: HelloJupyterNotebook0.ipynb.pdf
> >         Type: application/pdf
> >         Size: 458205 bytes
> >         Desc: HelloJupyterNotebook0.ipynb.pdf
> >         URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190827/0a1cf52f/attachment.pdf>
> >
> >         ------------------------------
> >
> >         Subject: Digest Footer
> >
> >         _______________________________________________
> >         x3d-public mailing list
> >         x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> >         http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> >
> >
> >         ------------------------------
> >
> >         End of x3d-public Digest, Vol 125, Issue 40
> >         *******************************************
> >
> >
> >
> >     --
> >     Andreas Plesch
> >     Waltham, MA 02453
> >
> >
> >
> > --
> > Andreas Plesch
> > Waltham, MA 02453
> >
> > _______________________________________________
> > x3d-public mailing list
> > x3d-public at web3d.org
> > http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> >
>
>
> all the best, Don
> --
> Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list