scientific visualization with opengl 22 february 2006

Post on 02-Jan-2016

236 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Scientific Visualization with

OpenGL

22 February 2006

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

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

Computer Graphics Applications

• Display of Information

• Design

• Simulation

• User Interfaces

Display of Information• Maps

– GIS– Spatial Resource Planning (SRP)

• Medicine– MRI– Ultrasound

• Scientific Visualization– “seeing the unseen”– Visual Human Project– biology– electrophysiology– mathematics

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,

Magnetic Resonance Imaging• Uses magnetism and radio waves to produce

images

Ultrasound• Images are produced by very high frequency

sound waves of between 3.5 to 5.0 megahertz.

Scientific VisualizationElectrophysiology

• Computed Potential Distribution on the Cardiac Surface during reentry: Spiral Tip Meandering, an arrhythmia model

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

Simulation• Flight Simulators

• Games

• Educational (edutainment) software

• Virtual Reality

User Interfaces• Interaction with computers

– windows– icons– menus– a pointing device

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

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?

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

Color CRTs• 3 phosphors

• Arranged in (sometimes triangular) triads

• Shadow mask CRT

• Screen with small holes ensures only one phosphor is excited

Other [Amazing] Raster Output Devices

• Liquid Crystal Displays (LCD)

• Printers

Ways to Read an Input Device

• Sampling– What is its input right now ?

• Event-based– Wait until the user does something

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

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.

Programming with OpenGLPart 1: Background

Ed AngelProfessor of Computer Science, Electrical and Computer Engineering,

and Media Arts: University of New Mexico

Objectives• Development of the OpenGL API

• OpenGL Architecture– OpenGL as a state machine

• Functions – Types– Formats

• Simple program

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

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)

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

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

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

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

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

Software Organization

GLUT

GLU

GL

GLX, AGLor WGL

X, Win32, Mac O/S

software and/or hardware

application program

OpenGL Motifwidget or similar

OpenGL ArchitectureImmediate Mode

DisplayList

PolynomialEvaluator

Per VertexOperations &

PrimitiveAssembly

RasterizationPer Fragment

Operations

TextureMemory

CPU

PixelOperations

FrameBuffer

Geometric pipeline

OpenGL Functions• Primitives

– Points– Line Segments– Polygons

• Attributes• Transformations

– Viewing– Modeling

• Control• Input (GLUT)

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

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

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

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,….

A Simple ProgramGenerate a square on a solid background

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();

}

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

Graphics System as a Black Box

UserProgram

GraphicsSystem

Input/OutputDevices

Function Calls

Data

Output

Input

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)

Camera Analogy

(from the red book)

Stages of Vertex Transformationin OpenGL

The Geometry Pipeline: Stages and Mappings

3D Coordinate Systems

LEFT HANDED RIGHT HANDED

X

Z

Y

Z

Y

X

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

3D Geometry: Graphics Pipeline

• MIT graphics

3D Geometry• Clipping

3D Geometry• Projections

3D Geometry• Projections – Parallel vs Orthographic

Appearance• Color - RBG or RGBA

Appearance

• Texture mapping

Appearance• Depth buffering

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.

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

Unique to C• Definitions precede code statements in

functions.• main() returns an int.• argv, argc

top related