Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25



Similar documents
Visualizing Data: Scalable Interactivity

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

OpenGL & Delphi. Max Kleiner. 1/22

Getting more out of Matplotlib with GR

Lecture Notes, CEng 477

Introduction to Computer Graphics

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

INTRODUCTION TO RENDERING TECHNIQUES

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

Performance Optimization and Debug Tools for mobile games with PlayCanvas

DATA VISUALIZATION OF THE GRAPHICS PIPELINE: TRACKING STATE WITH THE STATEVIEWER

Python. Python. 1 Python. M.Ulvrova, L.Pouilloux (ENS LYON) Informatique L3 Automne / 25

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

Image Synthesis. Transparency. computer graphics & visualization

GR.jl Plotting for Julia based on GR

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Graphics Pipeline in a Nutshell

How To Teach Computer Graphics

3D Data visualization with Mayavi

Advanced Rendering for Engineering & Styling

GPU Architecture. Michael Doggett ATI

Material for tutorial. Twitter: prabhu_r. Slides: Demos:

L20: GPU Architecture and Models

Data Visualization Using Hardware Accelerated Spline Interpolation

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

ANSA and μeta as a CAE Software Development Platform

ACE: After Effects CS6

Radeon HD 2900 and Geometry Generation. Michael Doggett

The Future Of Animation Is Games

CMSC 427 Computer Graphics 1

Developer Tools. Tim Purcell NVIDIA

Introduction to Computer Graphics

GPU Shading and Rendering: Introduction & Graphics Hardware

Programming 3D Applications with HTML5 and WebGL

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

Graphics Cards and Graphics Processing Units. Ben Johnstone Russ Martin November 15, 2011

MACHINE LEARNING IN HIGH ENERGY PHYSICS

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Today's Topics. COMP 388/441: Human-Computer Interaction. simple 2D plotting. 1D techniques. Ancient plotting techniques. Data Visualization:

Computer Graphics. Anders Hast

Chaco: A Plotting Package for Scientists and Engineers. David C. Morrill Enthought, Inc.

Computer Graphics Hardware An Overview

UNIVERSITY OF CALICUT

Course Overview. CSCI 480 Computer Graphics Lecture 1. Administrative Issues Modeling Animation Rendering OpenGL Programming [Angel Ch.

CIS 192: Lecture 13 Scientific Computing and Unit Testing

Computer Graphics Labs

An Introduction to. Graphics Programming

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

Web Based 3D Visualization for COMSOL Multiphysics

A Short Introduction to Computer Graphics

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

NVIDIA workstation 3D graphics card upgrade options deliver productivity improvements and superior image quality

Water Flow in. Alex Vlachos, Valve July 28, 2010

Big Data Paradigms in Python

Introduction Computer stuff Pixels Line Drawing. Video Game World 2D 3D Puzzle Characters Camera Time steps

The Nile Programming Language: Declarative Stream Processing for Media Applications. Dan Amelang Viewpoints Research Institute UCSD PhD Student

Postprocessing with Python

Visualization with ParaView. Greg Johnson

Interactive visualization of big data

Lezione 4: Grafica 3D*(II)

MMGD0203 Multimedia Design MMGD0203 MULTIMEDIA DESIGN. Chapter 3 Graphics and Animations

Computer Graphics CS 543 Lecture 12 (Part 1) Curves. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Parallel Web Programming

Dynamic Resolution Rendering

Python for Scientific Computing.

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

SUNPY: PYTHON FOR SOLAR PHYSICS. AN IMPLEMENTATION FOR LOCAL CORRELATION TRACKING

Programming Languages & Tools

Assignment 2: Option Pricing and the Black-Scholes formula The University of British Columbia Science One CS Instructor: Michael Gelbart

Introduction to GPGPU. Tiziano Diamanti

Programmable Graphics Hardware

Anime Studio Debut vs. Pro

BCC Multi Stripe Wipe

NVIDIA IndeX Enabling Interactive and Scalable Visualization for Large Data Marc Nienhaus, NVIDIA IndeX Engineering Manager and Chief Architect

Interactive Computer Graphics

Touchstone -A Fresh Approach to Multimedia for the PC

Introduction Week 1, Lecture 1

PowerPoint: Graphics and SmartArt

Overview Motivation and applications Challenges. Dynamic Volume Computation and Visualization on the GPU. GPU feature requests Conclusions

Otis Photo Lab Inkjet Printing Demo

Visualization of 2D Domains

ART 170: Web Design 1

How to resize, rotate, and crop images

Visualization and Feature Extraction, FLOW Spring School 2016 Prof. Dr. Tino Weinkauf. Flow Visualization. Image-Based Methods (integration-based)

VisIt Visualization Tool

Advanced Graphics and Animations for ios Apps

QCD as a Video Game?

The Visualization Pipeline

GR Framework / MODBUS on Raspberry Pi

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

SCANNING, RESOLUTION, AND FILE FORMATS

Advanced Visual Effects with Direct3D

Transcription:

GRAPHICS AND ANIMATIONS IN PYTHON USING MATPLOTLIB AND OPENGL Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25

Graphics and Animations in Python Where do we start?

A Bit of Context The Python Scientific Stack Python, modern computing script language IPython, an advanced Python shell Numpy, powerful numerical arrays objects. Scipy, high-level data processing routines. Matplotlib, 2-D visualization plots IP[y]: [ 10 01] Σ dx SymPy SciPy IPython Python NumPy SciKits Matplotlib Versatile & beautiful (but a bit slow) Matplotlib is a python plotting library, primarily for 2-D plotting, but with some 3-D support, which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Antigrain geometry, High Fidelity 2D Graphics (www.antigrain.com) Matplotlib can draw virtually anything

Matplotlib Scientific visualization Matplotlib allows to draw any kind (plot, scatter, quiver, etc.) of visualization for virtually any scientific domain. 150,000 100,000 50,000 WOMEN MEN 50,000 100,000 150,000 200,000 NEW CASES DEATHS Lung Cancer Colorectal Cancer DEATHS NEW CASES Breast Cancer Leading Causes Of Cancer Deaths In 2007, there were more than 1.4 millions new cases of cancer in the United States. Pancreatic Cancer Prostate Cancer Leukemia Non-Hodgkin's lymphoma Liver Cancer Ovarian Cancer Esophageal Cancer Bladder Cancer Kidney Cancer From Ten Simple Rules for Better Figures N.P. Rougier, M.Droettboom, P.E. Bourne PLoS Computational Biology, Vol. 10, No. 9. Code at github.com/rougier/ten-rules

Matplotlib General graphics Matplotlib can also be used as a regular graphic package allowing to draw or animate anything. From Introduction à Matploltib N.P. Rougier, Linux Mag HS, August 2014 Code at github.com/rougier/linuxmag-hs-2014

Matplotlib Example: display an image import matplotlib.pyplot as plt from matplotlib._png import read_png RGB = read_png( lena.png ) height, width = RGB.shape[:2] dpi = 72.0 figsize= width/float(dpi), height/float(dpi) fig = plt.figure(figsize=figsize, dpi=dpi, facecolor="white") ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=false) ax.imshow(rgb) ax.set_xticks([]), ax.set_yticks([]) plt.show()

What about OpenGL? Powerful, fast but... ugly! No decent anti-aliasing Only two image filters No native text handling No markers, no arrows No paths, no curves But this can be fixed!

Python/OpenGL frameworks Rendering framework Pyglet www.pyglet.org PyOpenGL pyopengl.sourceforge.net Nodebox for OpenGL www.cityinabottle.org/nodebox PyProcessing code.google.com/p/pyprocessing Kivy (see tomorrow) http://kivy.org/ PyOpenGLng (see tomorrow) https://github.com/fabricesalvaire/pyopenglng Visualization framework mayavi 2 (Enthought) github.com/enthought/mayavi VTK (Kitware) www.vtk.org galry (Cyrille Rossant) rossant.github.io/galry/ visvis (Almar Klein) code.google.com/p/visvis/ glumpy (Nicolas Rougier) code.google.com/p/glumpy/ pyqtgraph (Luke Campagnola) www.pyqtgraph.org

OpenGL history ES 1.0 ES 1.1 ES 2.0 ES 3.0 3.3 3.1 4.0 1.0 1.1 1.2 1.3 1.4 1.5 2.0 2.1 3.0 3.2 4.1 4.2 4.3 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 Fixed pipeline (no shaders) Programmable pipeline (vertex/fragment/geometry shaders) Legacy OpenGL Core Profile (deprecation model) Doom (1993) Rage (2011)

OpenGL 4.2 pipeline overview (could have been worse...) Around 2000 constants and 1000 functions.

OpenGL ES 2.0 pipeline overview (openglinsights.com) Around 350 constants and 150 functions.

Pipeline overview Data centered CPU (python) GPU (shaders) Raw Data Baked Data Transformed Data Rendered Data Critical parts are the baking process and the transfer to GPU memory.

Baking process Ideal case: no baking Interpolation, colorization, leveling, gridding, scaling, lighting, aliasing, rendering entirely done on GPU. Hard case: baking depends on transformation Transparency implies lot of CPU processing (sorting) or multi-pass rendering.

Performance and Quality We do not have to (always) trade quality for speed 10,000 pts - 403 FPS 100,000 pts - 140 FPS 1,000,000 pts - 40 FPS 10,000,000 pts - 1.5 FPS AntiGrain Geometry (matplotlib agg backend) OpenGL AntiGrain (using dedicated shaders) AntiGrain Geometry (matplotlib agg backend) OpenGL AntiGrain (using dedicated shaders)

Application Programming Interface Raw GLUT import sys import OpenGL.GL as gl import OpenGL. GLUT as glut def display (): gl. glclear (gl. GL_COLOR_BUFFER_BIT gl. GL_DEPTH_BUFFER_BIT ) # draw something glut. glutswapbuffers () glut. glutinit ( sys. argv ) glut. glutinitdisplaymode ( glut. GLUT_DOUBLE glut. GLUT_RGBA glut. GLUT_DEPTH ) glut. glutcreatewindow ( sys. argv [0]) glut. glutdisplayfunc ( display ) gl. glclearcolor (1,1,1,1) glut. glutmainloop () Low-level (current) from vispy import app @app. connect def on_paint ( event ): # draw something app. run () High-level (future) import numpy as np import vispy as vp P = np. random. random ((1000,3)) vp. scatter (P), vp. show ()

Shaders What do they look like? Vertex shader attribute vec3 position ; void main () { gl_position = vec4 ( position,1.0); } Fragment shader uniform vec4 color ; void main () { gl_fragmentcolor = color ; } Scalable Vector Graphics (SVG) Starting from these basic shaders, we need to handle Text Paths Basic shapes Painting: Filling, Stroking and Marker Symbols Clipping, Masking and Compositing Filter Effects...

Text rendering Different techniques Bitmap, stroke, texture, sdf, vector... Nicolas P. Rougier, Higher Quality 2D Text Rendering, Journal of Computer Graphics Techniques (JCGT), vol. 2, no. 1, 50-64, 2013.

Higher quality text rendering Vertical vs Horizontal hinting No hinting Native hinting Auto hinting Vertical hinting Maxim Shemarev, Texts Rasterization Exposures, An attempt to improve text rasterization algorithms, 2007 Implementation (github.com/rougier/freetype-gl) Subpixel positioning & kerning Per pixel gamma correction Signed Distance Fields

Dashed stroked polyline GL line width (fixed pipeline) Limited in thickness No control over joins and caps Deprecated & ugly GL Stipple (fixed pipeline) Limited in pattern No control over dash caps Deprecated & ugly

Higher quality dashed stroked polyline Shader based approach A new method for rendering arbitrary dash patterns along any continuous polyline (smooth or broken). The proposed method does not tessellate individual dash patterns and allows for fast and accurate rendering of any user-defined dash pattern and caps Nicolas P. Rougier, Shader-Based Antialiased, Dashed, Stroked Polylines, Journal of Computer Graphics Techniques (JCGT), vol. 2, no. 2, 105 121, 2013.

Image interpolation & filters OpenGL offers only nearest and linear filters while much more are needed for scientific visualization (Hanning, Hamming, Hermite, Kaiser, Quadric, Bicubic, CatRom, Mitchell, Spline16, Spline36, Gaussian, Bessel, Sinc, Lanczos, Blackman, etc.) Kevin Bjorke, High-Quality Filtering in GPU gems 2 : programming techniques for high-performance graphics and general-purpose computation / edited by Matt Pharr ; Randima Fernando (2007).

Grids, markers and arrows Point based approach A new method for drawing grids, markers, and arrows using implicit functions such that it is possible draw pixel-perfect antialiased objects with very good performances. Nicolas P. Rougier, Shader Based Antialiased 2D Grids, Markers, and Arrows, Journal of Computer Graphics Techniques (JCGT), to appear, 2014.

Conclusion The code is spread in several projects but should be soon integrated in the master vispy project. Projects page Code repositories vispy.org vispy.org/gallery.html glumpy.github.io glumpy.github.io/gallery.html github.com/vispy/vispy github.com/glumpy/glumpy github.com/rougier/gl-agg github.com/rougier/freetype-gl And we should get soon WebGL backend... Questions?