.. comment https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst Parallel session 2B : Latest developments on visualization drivers Tuesday 30/09 16:00-17:30 (maximum of 20min, including 5 min discussion) - Joseph Perl: « Improving vis performances in MT » - Akinori Kimura: « Updates of the gMocren driver » - Simon Blyth (invited as a contributor for this session) : « Collada geometry exporter G4DAE» - Laurent Garnier: « Updates on OpenGL (Qt and Wt) drivers » - space for discussion Laurent TODO: * Need page regarding g4daeview.py implementation techniques * need cuts 00: G4DAE : Export Geant4 Geometry to COLLADA/DAE XML files 1: https://bitbucket.org/simoncblyth/g4dae 2: COLLADA : Standard for 3D Digital Asset Exchange (DAE) 3: Compare DAE Exports to GDML and VRML2(WRL) 4: Tested G4DAE reading applications and frameworks 5: G4DAE export view/edit with OSX Xcode.app (1) 6: G4DAE export view/edit with OSX Xcode.app (2) 7: G4DAE export in OSX Sketchup 8: G4DAE export in OSX Finder, Interactive Quicklook (1) 9: G4DAE export in OSX 10.8+ Finder, Rotate/Pan/Zoom 10: G4DAE export in OSX 10.8+ Preview : Daya Bay Antineutrino Detector 11: My Modules/Applications using G4DAE exports (OSX/Linux) 12: g4daeserver.py : View exported geometry in web browser 13: g4daeserver.py : View exported geometry in web browser, details 14: G4DAE Exporter Status : almost feature complete .. include:: .. s5_background_image:: # # slide titles and background image urls, # including server relative urls like /env/geant4/geometry/collada/daeview/20140419-170713.png # and protocol relative urls like //localhost/env/test/LANS_AD3_CoverGas_Humidity.png # # NB1 slide titles here must match those in body precisely, # NB2 also ensure all slide titles are unique # # first slide id is exceptionally: slide0, not the mangled title slide0 /env/geant4/geometry/collada/g4daeview/20140419-170713.png auto_auto 0px_0px g4daeview.py : Fast OpenGL 3D viewer for G4DAE files /env/geant4/geometry/collada/g4daeview/20140419-170713.png ====================================================================== G4DAE : Export Geant4 Geometry to COLLADA/DAE XML files ====================================================================== .. class:: small http://simoncblyth.bitbucket.org/env/presentation/g4dae_geometry_exporter.html http://simoncblyth.bitbucket.org/env/presentation/gpu_optical_photon_simulation.html .. sidebar:: Why export into DAE ? Ubiquitous geometry visualization for Geant4 users and outreach. Facilitate innovative use of geometry data. .. class:: small * Exporter details * What is COLLADA/DAE ? * Validating exports * General viewing of exports * Custom use: :red:`bridging to GPU` * OpenGL Viewer implementation * Optical Photon Data handling * Introducing *Chroma* * *Chroma* raycasting * *Chroma* photon propagation * *G4DAE* Exporter status * Conclusion | Simon C Blyth, Daya Bay Collaboration, National Taiwan University | **19th Geant4 Collaboration Meeting, Okinawa, Sept 2014, Parallel Session B2, Visualization Group (Invited Speaker)** https://bitbucket.org/simoncblyth/g4dae --------------------------------------------------------------------------- .. class:: small Exports *Geant4* Geometry into COLLADA/DAE standard 3D files, based on *GDML writer* code, same *XercesC* dependency for XML handling. Export includes: * volume tree: solid/physical volume/logical volume heirarchy * geometry: vertices, triangles+quads (triangulation from *G4Polyhedron*) * materials and surfaces with properties as function of wavelength (using DAE *extra* XML elements) .. image:: /env/geant4/geometry/collada/g4dae/g4dae_bitbucket.png :width: 700px :align: center :small:`COLLADA : Standard for 3D Digital Asset Exchange (DAE)` ----------------------------------------------------------------- .. class:: small * https://www.khronos.org/collada/ .. image:: /env/graphics/collada/collada_khronos.png :width: 900px :align: center :small:`Compare DAE Exports to GDML and VRML2(WRL)` ---------------------------------------------------- .. class:: small Export validation: * Comparison of all vertices/faces reveals :red:`boolean solids are discrepant`. * Perfect [#perfect]_ DAE WRL agreement achieved by *cheating* : :blue:`perform triangulation once and reuse`. * Boolean solid triangulation sensitivity must be kept in mind as a potential systematic for computational uses * **DAE not much bigger than GDML**, despite including all triangles/vertices [#not-repeating]_ .. class:: small ==================== ================= ============== ================== ================= Qty DayaBay Lingao Far Juno x0.5 ==================== ================= ============== ================== ================= Volumes 12,229 12,229 18,903 25,000 Triangles 2,448,064 2,448,064 4,189,680 21,886,158 Vertices 1,245,996 1,245,996 2,128,208 10,993,079 DAE/GDML/WRL (MB) **6.9**/4.0/98 **6.9**/4.0/96 **8.6**/6.0/167 **6.1**/-/- ==================== ================= ============== ================== ================= .. class:: tiny ``VGDX_20140414`` counts using ``g4daeview.py -g 0: --with-chroma``, Juno geometry truncated .. class:: tiny .. [#perfect] Maximum DAE WRL offset < 0.13 mm, after patching VRML2 export precision bug (fixed in current G4). Details: http://simoncblyth.bitbucket.org/env/notes/geant4/geometry/collada/dae_cf_wrl/ .. [#not-repeating] Geometry is not repeated, instead the COLLADA format uses geometry instancing and a tree of transforms, just like GDML :small:`Tested G4DAE reading applications and frameworks` ----------------------------------------------------------- .. sidebar:: G4DAE Usage Many commercial, open source apps/libs can view/edit G4DAE files. .. class:: small Commercial: * *Finder/Quicklook/Preview/Xcode* (standard OSX 10.8+) * :blue:`Xcode : useful effect tweaking interface` * :blue:`Preview : set black background for visibility` * *Sketchup 8* free (OSX) [also Windows] * *ESKO Studio Viewer* free (iOS on iPad) Open source: * *Meshlab* (OSX/Linux), slow DAE loading, OK interface [also Windows] * *Blender* (OSX), painful GUI [also Windows/Linux] Frameworks: * *pycollada*, Python COLLADA parsing/construction, :red:`lxml + numpy powered fast parsing` * *threejs*, Javascript COLLADA loading, renders HTML canvas with WebGL * *SceneKit*, Objective C Framework used by OSX apps Many more applications and frameworks listed http://en.wikipedia.org/wiki/COLLADA .. class:: tiny http://meshlab.sourceforge.net https://bitbucket.org/simoncblyth/meshlab (fork improves COLLADA loading speed) :small:`G4DAE export in OSX Finder, Interactive Quicklook (1)` ----------------------------------------------------------------- .. class:: small Coverflow through geometries: .. image:: /env/geant4/geometry/collada/osx_finder/g4dae_osx_finder.png :width: 900px :align: center :small:`G4DAE export in OSX 10.8+ Finder, Rotate/Pan/Zoom` ------------------------------------------------------------ .. class:: small Rotate/Pan/Zoom in the Finder: .. image:: /env/geant4/geometry/collada/osx_finder/g4dae_osx_finder_2.png :width: 900px :align: center :small:`G4DAE export view/edit with OSX Xcode.app (1)` ------------------------------------------------------- .. class:: small Deep tree makes choice of default appearance problematic. Useful editing. .. image:: /env/geant4/geometry/collada/xcode/g4dae_xcode.png :width: 900px :align: center :small:`G4DAE export view/edit with OSX Xcode.app (2)` ------------------------------------------------------- .. class:: small Bialkali PMT cathode highlighted by Xcode effect edit. .. image:: /env/geant4/geometry/collada/xcode/g4dae_xcode_2.png :width: 900px :align: center :small:`G4DAE export in OSX 10.8+ Preview : Daya Bay Antineutrino Detector` --------------------------------------------------------------------------------------- .. class:: tiny * Set black background for visibility ``Preview > Preferences... > General [Window Background]`` * Control with iOS-like gestures, pinch/rotate etc.. .. image:: /env/geant4/geometry/collada/osx_preview/g4dae_osx_preview.png :width: 900px :align: center :small:`G4DAE export in OSX Sketchup` ------------------------------------------------ .. class:: tiny Available for Windows too. .. image:: /env/geant4/geometry/collada/sketchup/g4dae_sketchup.png :width: 900px :align: center :small:`My Modules/Applications using G4DAE exports (OSX/Linux)` ------------------------------------------------------------------- .. sidebar:: Custom Benefits General purpose OS/app support useful, but custom development needed to really benefit. Availability of frameworks allows high level approach. .. class:: small :red:`g4daenode.py` *pycollada* based G4DAE parser * reconstructs Geant4 volume tree from raw tree * parses **extra** material/surface properties * provides partial geometry tree creation :red:`g4daeserver.py` *threejs/WebGL* (client) and *pycollada/webpy* (server) based webapp: * 3D geometry viewer in the browser, **NO client installation** * useful for debugging single volumes * did not pursue as python development more flexible than Javascript in browser :red:`g4daeview.py` *pyopengl/pycollada/numpy* based 3D viewer app * many interactive features detailed later * integrates with GPU/CUDA based **Chroma** project * live link to Geant4 (via StackAction sending optical photons over *ZeroMQ* message queue) .. class:: tiny https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/collada/g4daenode.py https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/g4daeserver/ https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/collada/g4daeview/g4daeview.py :small:`g4daeview.py : Fast OpenGL 3D viewer for G4DAE files` ----------------------------------------------------------------------------- .. class:: small G4DAE visualization [#g4daeview_usage]_ implemented with PyCollada, PyOpenGL and Glumpy * very fast/responsive 3D OpenGL visualization [#vbo]_ * flexible tree/list based partial geometry loading * intuitive virtual trackball translate/rotate * parallel or perspective projections * interactive fov and near/far plane clipping * persistent viewpoint bookmarks * animation by interpolation between bookmarks or orbiting * numerical control via UDP remote messaging * live Geant4 connection, photon visualization, single stepping * easily extensible python implementation [#g4daeview_code]_ * photon picking interface, with property inspection Also used for testing GPU photon propagation with Chroma project * interactive raycasting, including animated * propagation visualization, with time slider .. class:: tiny .. [#g4daeview_usage] http://simoncblyth.bitbucket.org/env/notes/geant4/geometry/collada/g4daeview/g4daeview_usage/ .. [#vbo] Implemented with single OpenGL Vertex Buffer Object (VBO) for entire geometry .. [#g4daeview_code] https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/collada/g4daeview/ :small:`g4daeview.py : Initial Photon Positions` ------------------------------------------------------------------------------- .. class:: tiny Initial photon positions of a Geant4 simulated muon that crosses between the Dayabay Near hall ADs. Colors represent photon wavelengths. Optical photons: collected in G4 StackAction, serialized, sent over ZeroMQ, deserialized, presented using OpenGL GLSL shaders. .. image:: /env/geant4/geometry/collada/g4daeview/20140518-174941.png :height: 650px :align: center :small:`g4daeview.py : Implementation` ----------------------------------------------------------------------------- .. comment http://dayabay.phys.ntu.edu.tw/tracs/env/browser/trunk/geant4/geometry/collada/daeviewgl.py?rev=4344 .. class:: small Based on *glumpy* [#glumpy]_ and *pyopengl* [#pyopengl]_ .. class:: small * started from .obj viewer [#glumpy-obj-viewer]_ * added vertices, triangles from **G4DAE** export * entire geometry in :red:`single VBO` * only **one** OpenGL command needed to draw * immediately (few hrs): :red:`shockingly fast graphics` * smoothly slinging around ~2.5M triangles, no stuttering .. class:: tiny .. [#glumpy] https://code.google.com/p/glumpy/ many useful examples of pyopengl usage .. [#pyopengl] http://pyopengl.sourceforge.net cross platform Python binding to OpenGL and related APIs .. [#glumpy-obj-viewer] http://bitbucket.org/simoncblyth/env/src/tip/graphics/glumpy/glumpy_examples/obj-viewer-structured.py :small:`g4daeview.py : Optical Photon (OP) Data Handling` ----------------------------------------------------------------------------- .. class:: small Photon data flow: * OP collected in *StackAction::ClassifyNewTrack* and killed [#alt]_ * *NewStage* send OP lists [#mqtransport]_ to *CUDA/Chroma* process, propagated on GPU * reply back to *NewStage* to form hits .. sidebar:: CUDA/OpenGL interop Same GPU resident data structure accessible to computation and presentation .. class:: small When visualizing/debugging: * populate OpenGL VBO data structure * on load, propagate, saving steps into VBO slots * presentation, every frame: * photon styles, GLSL shaders: spagetti, confetti, noodles, ... * simple CUDA *presenter* kernel to interpolate between steps based on an input time .. class:: tiny .. [#alt] Would be more efficient to collect OP inside Cerenkov and Scintillation processes, avoiding creating and stacking only to immediately kill. .. [#mqtransport] ROOT TObject (de)serialization, network message queue ZeroMQ :small:`g4daeview.py : Status` ----------------------------------------------------------------------------- .. class:: small Not mature, but intend to facilitate usage anyhow. **Plan:** * break out into separate bitbucket repository * https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/collada/g4daeview/ .. class:: small * degrade to OpenGL only features, when CUDA not available * *glumpy/pyopengl/numpy/pycollada* : visualization/navigation/bookmarks * *Chroma/PyCUDA/Chroma* : photon propagation, raycasting .. class:: small * document installation and usage :small:`Chroma : Ultra-fast Photon MC, Developed by Stan Seibert, University of Pennsylvania` ----------------------------------------------------------------------------------------------- .. class:: small * http://chroma.bitbucket.org Chroma tracks photons through a :red:`triangle-mesh detector geometry`, simulating processes like diffuse and specular reflections, refraction, Rayleigh scattering and absorption. Using triangle meshes eliminate geometry code as :red:`just one code path`. .. sidebar:: Original Motivation for G4DAE exporter Allow use of Chroma GPU accelerated optical photon propagation with existing DayaBay Geant4 geometry. .. class:: small 200x performance claim: *With a CUDA GPU Chroma has propagated 2.5M photons per second in a detector with 29k photomultiplier tubes. This is 200x faster than GEANT4.* .. class:: small **BUT** Chroma needs : :red:`triangles + inside/outside materials` .. class:: tiny http://on-demand.gputechconf.com/gtc/2013/presentations/S3304-Particle-Physics-With-PyCUDA.pdf :small:`Chroma Raycasting : exercises geometry intersection` ------------------------------------------------------------- .. class:: small Raycasting exercises slowest part of optical photon propagation: :red:`geometry intersection`. .. image:: /env/chroma/chroma_camera/chroma_raycast_illustration.png :width: 600px :align: center .. class:: small * Shoot rays thru every pixel out into geometry, 1 CUDA thread for each, typically >1M rays * Find triangle intersections using BVH [#bvh]_ acceleration structure * Determine color based on ray to triangle normal angle * Alpha blend nearest 10 surfaces, providing transparency effect .. class:: tiny .. [#bvh] Boundary Volume Heirarchy, a tree of bounding boxes with triangles inside leaf nodes :small:`Chroma Raycast with entire geometry in view` ---------------------------------------------------------------- .. class:: small Render Split into 3x3 CUDA kernel launches, 1 thread per pixel, ~1.8s for 1.23M pixels, 2.4M tris (with [#hw]_) .. image:: /env/chroma/chroma_camera/20140423-162109.png :width: 800px :align: center .. class:: tiny .. [#hw] MacBook Pro (2013), NVIDIA GeForce GT 750M 2048 MB ; Workstation GPUs such as NVIDIA Kepler K20 expected at least ~3x faster :small:`g4daeview.py : Dayabay Chroma Photon Propagation (1)` ------------------------------------------------------------------------------- .. class:: tiny Chroma GPU photon propagation at 12 nanoseconds. The photons are generated by Geant4 simulation of a 100 GeV muon travelling from right to left. Photon colors indicate reemission (green), absorption(red), specular reflection (magenta), scattering(blue), no history (white). .. image:: /env/geant4/geometry/collada/g4daeview/20140716-161445.png :height: 600px :align: center :small:`g4daeview.py : Dayabay Chroma Photon Propagation (2)` ------------------------------------------------------------------------------- .. class:: tiny Chroma GPU photon propagation at 14 nanoseconds. The interface provides interactive control of the propagation time allowing any stage of the propagation to be viewed by scrubbing time backwards/forwards. The speed of this visualization is achieved by interoperation of CUDA kernels and OpenGL shaders accessing the same GPU resident photon propagation data. .. image:: /env/geant4/geometry/collada/g4daeview/20140716-163403.png :height: 600px :align: center :small:`G4DAE Exporter Status : almost feature complete` --------------------------------------------------------------- .. class:: small Development started with GDML from **geant4.10.00.p01** * made minor backports to work with **geant4.9.2.p01** * patched old version to give access to material property tables **Remaining tasks:** .. class:: small * test with newer and latest versions of Geant4 .. class:: small * implement parametrized/replica geometry handling, following GDML * confirm issue (inherited from GDML) of edge case skipped **G4LogicalBorderSurface** where a volume is shared between multiple volume pairs. .. class:: small * test on more geometries, currently mainly DayaBay and JUNO .. class:: small * export appearance adjustments * current uniform translucent white, invisible when white background * too many parameters, unclear what to use for defaults * investigate propagating from **G4VisAttributes** .. class:: small * review code: * remove: unused parsing inherited from GDML :small:`G4DAE : Conclusion` ------------------------------------------------------------------------------- * https://bitbucket.org/simoncblyth/g4dae I propose to contribute the COLLADA/DAE geometry exporter to the Geant4 collaboration, as I believe this can be useful for facilitating: * fast/flexible/ubiquitous visualization * external computation using geometry data such as * GPU raycasting * GPU optical photon simulation .. class:: small Links for this presentation and another on GPU optical photon propagation: * http://simoncblyth.bitbucket.org/env/presentation/g4dae_geometry_exporter.html * http://simoncblyth.bitbucket.org/env/presentation/gpu_optical_photon_simulation.html :small:`Extra slides` -------------------------------------------------------------------------- .. class:: small * g4daeserver.py : View exported geometry in web browser * g4daeserver.py : View exported geometry in web browser, details * g4daeview.py : Photon Selection Interface * g4daeview.py : Propagation Step Selection Interface :small:`g4daeserver.py : View exported geometry in web browser` -------------------------------------------------------------------------- .. image:: /env/geant4/geometry/collada/webgl_safari_daeserver/webgl_safari_daeserver.png :width: 900px :align: center :small:`g4daeserver.py : View exported geometry in web browser, details` -------------------------------------------------------------------------- .. sidebar:: Instant web access to any volume Very useful for single volume debugging, did not pursue as prefer Python development over Javascript. .. class:: small Select volume subtree by name or index and recursion depth * http://belle7.nuu.edu.tw/g4dae/tree/3150___1.html Client in browser based on: * **threejs**, Javascript 3D library * reads DAE geometry subtrees from server * parses DAE and renders with **WebGL** (**OpenGL** GPU accelerated) Server: * **g4daenode.py**, reconstructs Geant4 tree from G4DAE export using **pycollada** parser * **webpy**, serve .html and .dae subtrees at each request, running under apache mod_fcgi Command line access to DAE subtrees:: curl -O http://belle7.nuu.edu.tw/g4dae/tree/3155___2.dae .. class:: tiny http://threejs.org http://pycollada.github.io http://webpy.org https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/g4daeserver/ https://bitbucket.org/simoncblyth/env/src/tip/geant4/geometry/collada/g4daenode.py :small:`g4daeview.py : Photon Selection Interface` ------------------------------------------------------------------------------- .. class:: tiny Propagation steps OR photons can be selected by materials, propagation history, or special selection by photon identifier. Photons can be selected by clicking their 3D representations allowing inspection of the propagation history of individual photons. .. image:: /env/geant4/geometry/collada/g4daeview/grab_glut_menu.png :height: 650px :align: center :small:`g4daeview.py : Propagation Step Selection Interface` ------------------------------------------------------------------------------- .. class:: tiny Photon propagation steps with material pair GdDopedLS,Acrylic. The larger squares represent selected photons, providing access to numerical details of propagation history. .. image:: /env/geant4/geometry/collada/g4daeview/20140716-183318.png :height: 650px :align: center