Scientific Visualization with OpenGL 22 February 2006.
-
Upload
sharon-parker -
Category
Documents
-
view
237 -
download
4
Transcript of Scientific Visualization with OpenGL 22 February 2006.
![Page 1: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/1.jpg)
Scientific Visualization with
OpenGL
22 February 2006
![Page 2: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/2.jpg)
Agenda• Wrap-up Project 1
• OpenGL
• Homework– Read Chapters 1 and 2 in Cunningham– Study for next week’s Quiz 3
• User Testing• Chapter 0 – Getting Started in Cunningham
![Page 3: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/3.jpg)
Computer Graphics• Definition
• producing pictures or images using a computer
• 40 years ago – drawing lines on a cathode ray tube
• Today– produce images indistinguishable from photos– produce “realistic” and animated dinosaurs– produce 3D worlds
![Page 4: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/4.jpg)
Computer Graphics Applications
• Display of Information
• Design
• Simulation
• User Interfaces
![Page 5: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/5.jpg)
Display of Information• Maps
– GIS– Spatial Resource Planning (SRP)
• Medicine– MRI– Ultrasound
• Scientific Visualization– “seeing the unseen”– Visual Human Project– biology– electrophysiology– mathematics
![Page 6: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/6.jpg)
GIS
Buncombe Co. GIS
![Page 7: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/7.jpg)
Spatial Resource Planning• Spatially-referenced data within engineering,
operations and distribution network management
• Analogous to what Enterprise Resource Planning (ERP) solutions do for data held in accounting, human resources, procurement and project management systems,
![Page 8: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/8.jpg)
Magnetic Resonance Imaging• Uses magnetism and radio waves to produce
images
![Page 9: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/9.jpg)
Ultrasound• Images are produced by very high frequency
sound waves of between 3.5 to 5.0 megahertz.
![Page 10: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/10.jpg)
Scientific VisualizationElectrophysiology
• Computed Potential Distribution on the Cardiac Surface during reentry: Spiral Tip Meandering, an arrhythmia model
![Page 11: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/11.jpg)
Design• “The evaluation of alternative solutions and
the specification of a solution”
• CAD
• VLSI design
• Generate a possible design, test, use solution as a basis for other solution
![Page 12: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/12.jpg)
Simulation• Flight Simulators
• Games
• Educational (edutainment) software
• Virtual Reality
![Page 13: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/13.jpg)
User Interfaces• Interaction with computers
– windows– icons– menus– a pointing device
![Page 14: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/14.jpg)
Frame Buffer• Depth -- number of bits used for each pixel
– full color systems• true color systems
• RGB color systems
• 24 or more bits per pixel
• Resolution -- number of pixels in the frame buffer
![Page 15: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/15.jpg)
Output Devices• Dominant type of display is the CRT
(cathode ray tube).
• CRT emits light for a short time -- a few milliseconds.
• For a human to see a steady image the path must be retraced or refreshed at least 50x/sec.
• How are pixels displayed?
![Page 16: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/16.jpg)
How Are Pixels Displayed?
• Noninterlaced– Displayed row by row
• Interlaced– Displayed every other row– 50-75X/second (50-75Hertz)– 60Hz display refreshes the entire screen 30x/sec– Commercial TV
![Page 17: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/17.jpg)
Color CRTs• 3 phosphors
• Arranged in (sometimes triangular) triads
• Shadow mask CRT
• Screen with small holes ensures only one phosphor is excited
![Page 18: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/18.jpg)
Other [Amazing] Raster Output Devices
• Liquid Crystal Displays (LCD)
• Printers
![Page 19: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/19.jpg)
Ways to Read an Input Device
• Sampling– What is its input right now ?
• Event-based– Wait until the user does something
![Page 20: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/20.jpg)
Objects and Viewers3d world
• Object is a constant
• Viewer forms the image– human viewing system - back of eye– camera - film plane– different viewers see the same object differently
![Page 21: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/21.jpg)
The Human Vision System• Resolution
– the measure of what size objects we can see– how close we can place two points and they remain
distinct
• Intensity– physical measure of light energy
• Brightness– measure of how intense we perceive the light to be.
![Page 22: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/22.jpg)
Programming with OpenGLPart 1: Background
Ed AngelProfessor of Computer Science, Electrical and Computer Engineering,
and Media Arts: University of New Mexico
![Page 23: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/23.jpg)
Objectives• Development of the OpenGL API
• OpenGL Architecture– OpenGL as a state machine
• Functions – Types– Formats
• Simple program
![Page 24: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/24.jpg)
Early History of APIs• IFIPS (1973) formed two committees to come up with
a standard graphics API– Graphical Kernel System (GKS)
• 2D but contained good workstation model– Core
• Both 2D and 3D– GKS adopted as IS0 and later ANSI standard
(1980s)• GKS not easily extended to 3D (GKS-3D)• Far behind hardware development
![Page 25: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/25.jpg)
PHIGS and X• Programmers Hierarchical Graphics System
(PHIGS)– Arose from CAD community– Database model with retained graphics
(structures)• X Window System
– DEC/MIT effort– Client-server architecture with graphics
• PEX combined the two– Not easy to use (all the defects of each)
![Page 26: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/26.jpg)
SGI and GL• Silicon Graphics (SGI) revolutionized the
graphics workstation by implementing the pipeline in hardware (1982)
• To use the system, application programmers used a library called GL
• With GL, it was relatively simple to program three dimensional interactive applications
![Page 27: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/27.jpg)
OpenGL• The success of GL lead to OpenGL (1992), a
platform-independent API that was – Easy to use– Close enough to the hardware to get excellent
performance– Focus on rendering– Omitted windowing and input to avoid window
system dependencies
![Page 28: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/28.jpg)
OpenGL Evolution• Controlled by an Architectural Review Board (ARB)
– Members include SGI, Microsoft, Nvidia, HP, 3DLabs,IBM,…….
– Relatively stable – Evolution reflects new hardware capabilities
–3D texture mapping and texture objects–Vertex programs
– Allows for platform specific features through extensions
![Page 29: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/29.jpg)
OpenGL Libraries• OpenGL core library
– OpenGL32 on Windows– GL on OS X/UNIX/Linux systems
• OpenGL Utility Library (GLU)– Provides functionality in OpenGL core but avoids
having to rewrite code• Links with window system
– OpenGl does not “do” windowing– Windowing is OS specific
![Page 30: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/30.jpg)
GLUT• OpenGL Utility Library (GLUT)
– Provides functionality common to all window systems
• Open a window• Get input from mouse and keyboard• Menus• Event-driven
– Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform
• Slide bars
![Page 31: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/31.jpg)
Software Organization
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar
![Page 32: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/32.jpg)
OpenGL ArchitectureImmediate Mode
DisplayList
PolynomialEvaluator
Per VertexOperations &
PrimitiveAssembly
RasterizationPer Fragment
Operations
TextureMemory
CPU
PixelOperations
FrameBuffer
Geometric pipeline
![Page 33: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/33.jpg)
OpenGL Functions• Primitives
– Points– Line Segments– Polygons
• Attributes• Transformations
– Viewing– Modeling
• Control• Input (GLUT)
![Page 34: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/34.jpg)
OpenGL State• OpenGL is a state machine
• OpenGL functions are of two types– Primitive generating
• Can cause output if primitive is visible• How vertices are processes and appearance of
primitive are controlled by the state
– State changing• Transformation functions• Attribute functions
![Page 35: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/35.jpg)
Lack of Object Orientation• OpenGL is not object oriented so that there
are multiple functions for a given logical function, e.g. glVertex3f, glVertex2i, glVertex3dv,…..
• Underlying storage mode is the same
• Easy to create overloaded functions in C++ but issue is efficiency
![Page 36: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/36.jpg)
OpenGL function format
glVertex3f(x,y,z)
belongs to GL library
function name
x,y,z are floats
glVertex3fv(p)
p is a pointer to an array
![Page 37: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/37.jpg)
OpenGL #defines• Most constants are defined in the include
files gl.h, glu.h and glut.h– Note #include <glut.h> should
automatically include the others– Examples– glBegin(GL_PLOYGON)– glClear(GL_COLOR_BUFFER_BIT)
• include files also define OpenGL data types: Glfloat, Gldouble,….
![Page 38: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/38.jpg)
A Simple ProgramGenerate a square on a solid background
![Page 39: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/39.jpg)
simple.c#include <glut.h>void mydisplay(){ glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5);
glEnd();glFlush();
}int main(int argc, char** argv){
glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop();
}
![Page 40: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/40.jpg)
Event Loop• Note that the program defines a display
callback function named mydisplay– Every glut program must have a display callback– The display callback is executed whenever
OpenGL decides the display must be refreshed, for example when the window is opened
– The main function ends with the program entering an event loop
![Page 41: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/41.jpg)
Graphics System as a Black Box
UserProgram
GraphicsSystem
Input/OutputDevices
Function Calls
Data
Output
Input
![Page 42: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/42.jpg)
Pipeline Architectures• Example
• Benefits– translates well to computer graphics– four steps to producing an image
• transforms (rotations, scale, translations)• clipper• projector (from 3d to 2d)• rasterizer (scan conversion process)
![Page 43: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/43.jpg)
Camera Analogy
(from the red book)
![Page 44: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/44.jpg)
Stages of Vertex Transformationin OpenGL
![Page 45: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/45.jpg)
The Geometry Pipeline: Stages and Mappings
![Page 46: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/46.jpg)
3D Coordinate Systems
LEFT HANDED RIGHT HANDED
X
Z
Y
Z
Y
X
![Page 47: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/47.jpg)
3D Geometry: Model Coordinate Systems
• modeling - The process of creating and defining this geometry is called– This is usually done by defining each object in terms of a
coordinate system that makes sense for that particular object.
– Ants vs Star Wars
![Page 48: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/48.jpg)
3D Geometry: Graphics Pipeline
• MIT graphics
![Page 49: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/49.jpg)
3D Geometry• Clipping
![Page 50: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/50.jpg)
3D Geometry• Projections
![Page 51: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/51.jpg)
3D Geometry• Projections – Parallel vs Orthographic
![Page 52: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/52.jpg)
Appearance• Color - RBG or RGBA
![Page 53: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/53.jpg)
Appearance
• Texture mapping
![Page 54: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/54.jpg)
Appearance• Depth buffering
![Page 55: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/55.jpg)
A Basic OpenGL Program• Download Heat Distribution Program• Open Xcode (Icon has blue rectangle with hammer)• File / New Project• Select Command Line Utility / C++ Tool• Name the project heatflow• Add heatflow.c to the project source files. • Add System/Library/Frameworks/Glut.framework
and System/Library/Frameworks/OpenGL.framework to the project.
![Page 56: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/56.jpg)
An OpenGL Program• Select Build and Run• Fix the errors
– For a Mac substitute <GLUT/glut.h> for “glut.h”– With c main() should return an int. Change the return
value of main().
• Build and Run
![Page 57: Scientific Visualization with OpenGL 22 February 2006.](https://reader035.fdocuments.in/reader035/viewer/2022062308/56649ede5503460f94bee648/html5/thumbnails/57.jpg)
Unique to C• Definitions precede code statements in
functions.• main() returns an int.• argv, argc